Skip to content

feat(schedule): introduce run-level option#546

Merged
creativeprojects merged 3 commits into
creativeprojects:masterfrom
zumm:feat/schtasks-run-level
Aug 28, 2025
Merged

feat(schedule): introduce run-level option#546
creativeprojects merged 3 commits into
creativeprojects:masterfrom
zumm:feat/schtasks-run-level

Conversation

@zumm
Copy link
Copy Markdown
Contributor

@zumm zumm commented Jul 31, 2025

Resolves #475

Introducing new run-level option to control schedule run level in Windows Task Scheduler.

Note: there is a problem - we can't test this option due to lack of information about task run level in schtasks csv output. Such information is present in xml output tho. This may be another reason to switch to xml output, see related #545.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 31, 2025

Walkthrough

A new RunLevel / schedule-run-level configuration option was added and propagated through profile/config structs, schedule-to-config mapping, Windows handler and schtasks task creation logic; documentation was added and a placeholder test was included.

Changes

Cohort / File(s) Change Summary
Config Struct Extensions
config/profile.go, config/schedule.go, schedule/config.go, schtasks/config.go
Added ScheduleRunLevel / RunLevel string fields to profile/config/schedule/schtasks structs with default auto and enum values (auto;lowest;highest).
Config Defaults & Overrides
config/schedule.go
Added default value for RunLevel, init logic to apply defaults, and override application from profile section.
Schedule Mapping
schedule_jobs.go
Included RunLevel when converting a config.Schedule into a schedule.Config.
Windows Handler Integration
schedule/handler_windows.go
Passed RunLevel from job to jobConfig used for creating Windows tasks.
Task Scheduler Logic
schtasks/taskscheduler.go
Added run-level selection logic to set task principal run level according to config.RunLevel (handles lowest, highest, auto / permission-based fallback).
Documentation
docs/content/schedules/configuration.md
Documented new schedule-run-level option and value semantics for Windows Task Scheduler.
Tests / Output Expectations
schtasks/taskscheduler_test.go, commands_test.go
Added placeholder TestRunLevelOption (TODO) and updated CLI output test to expect run-level: auto lines for schedules.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConfigLoader
    participant Scheduler
    participant WinHandler
    participant Schtasks

    User->>ConfigLoader: Load profile (may include schedule-run-level)
    ConfigLoader->>Scheduler: Provide schedule config (RunLevel included)
    Scheduler->>WinHandler: CreateJob(schedule.Config)
    WinHandler->>Schtasks: Create(task.Config with RunLevel)
    Schtasks->>Schtasks: Determine Principal RunLevel (lowest/highest/auto -> permission fallback)
    Schtasks-->>WinHandler: Return task creation result
    WinHandler-->>Scheduler: Return job result
    Scheduler-->>User: Report schedule created
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Add a configuration option to set the "Run with highest privileges" (run level) for Windows tasks (#475)
Propagate the run level option through configuration and scheduling logic (#475)
Update documentation to describe the new run level option (#475)
Add or prepare for testing of the run level option (#475) Test added is a placeholder with comments; no functional test validating run-level behaviour exists.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8cdab1a and fddb92f.

📒 Files selected for processing (1)
  • commands_test.go (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • commands_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Build and test (1.24, ubuntu-latest)
  • GitHub Check: Build and test (1.24, windows-latest)
  • GitHub Check: Build and test (1.24, macos-latest)
  • GitHub Check: build
  • GitHub Check: Analyze (go)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/content/schedules/configuration.md (1)

94-101: Fix list formatting to maintain consistency.

The documentation content is excellent and clearly explains the new schedule-run-level parameter. However, the bullet points should use asterisks instead of dashes to maintain consistency with the rest of the document.

-The `schedule-run-level` parameter accepts three values:
-- `lowest`: Runs the task with the least user privileges.
-- `highest`: Runs the task with the highest user privileges available.
-- `auto`: Uses `highest` if `schedule-permission` is set to `system`. Otherwise, defaults to `lowest`.
+The `schedule-run-level` parameter accepts three values:
+* `lowest`: Runs the task with the least user privileges.
+* `highest`: Runs the task with the highest user privileges available.
+* `auto`: Uses `highest` if `schedule-permission` is set to `system`. Otherwise, defaults to `lowest`.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7e87a1 and c6fbd50.

📒 Files selected for processing (9)
  • config/profile.go (1 hunks)
  • config/schedule.go (4 hunks)
  • docs/content/schedules/configuration.md (1 hunks)
  • schedule/config.go (1 hunks)
  • schedule/handler_windows.go (1 hunks)
  • schedule_jobs.go (1 hunks)
  • schtasks/config.go (1 hunks)
  • schtasks/taskscheduler.go (1 hunks)
  • schtasks/taskscheduler_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
schedule/handler_windows.go (1)

Learnt from: creativeprojects
PR: #459
File: schtasks/schtasks.go:29-30
Timestamp: 2025-02-14T22:53:42.689Z
Learning: In the schtasks package, tasksPath is defined as a constant with value \resticprofile backup\ in taskscheduler.go. It's used as a prefix for managing task paths in the Windows Task Scheduler.

schedule/config.go (1)

Learnt from: creativeprojects
PR: #425
File: schedule/handler_windows.go:97-118
Timestamp: 2025-02-04T14:38:07.701Z
Learning: The shell.SplitArguments function in the resticprofile project returns only []string and does not return any error.

schtasks/taskscheduler.go (1)

Learnt from: creativeprojects
PR: #459
File: schtasks/schtasks.go:29-30
Timestamp: 2025-02-14T22:53:42.689Z
Learning: In the schtasks package, tasksPath is defined as a constant with value \resticprofile backup\ in taskscheduler.go. It's used as a prefix for managing task paths in the Windows Task Scheduler.

schtasks/taskscheduler_test.go (1)

Learnt from: creativeprojects
PR: #459
File: schtasks/schtasks.go:29-30
Timestamp: 2025-02-14T22:53:42.689Z
Learning: In the schtasks package, tasksPath is defined as a constant with value \resticprofile backup\ in taskscheduler.go. It's used as a prefix for managing task paths in the Windows Task Scheduler.

config/schedule.go (1)

Learnt from: creativeprojects
PR: #459
File: schtasks/schtasks.go:29-30
Timestamp: 2025-02-14T22:53:42.689Z
Learning: In the schtasks package, tasksPath is defined as a constant with value \resticprofile backup\ in taskscheduler.go. It's used as a prefix for managing task paths in the Windows Task Scheduler.

🧬 Code Graph Analysis (6)
schedule/handler_windows.go (1)
schtasks/principal.go (1)
  • RunLevel (30-30)
schedule/config.go (1)
schtasks/principal.go (1)
  • RunLevel (30-30)
schedule_jobs.go (1)
schtasks/principal.go (1)
  • RunLevel (30-30)
schtasks/taskscheduler.go (2)
schtasks/principal.go (6)
  • RunLevel (30-30)
  • Principals (7-9)
  • Principal (11-16)
  • RunLevelLeastPrivilege (34-34)
  • RunLevelHighest (35-35)
  • RunLevelDefault (33-33)
schtasks/permission.go (1)
  • SystemAccount (18-18)
schtasks/config.go (1)
schtasks/principal.go (1)
  • RunLevel (30-30)
config/schedule.go (1)
schtasks/principal.go (1)
  • RunLevel (30-30)
🪛 LanguageTool
docs/content/schedules/configuration.md

[uncategorized] ~100-~100: Loose punctuation mark.
Context: ...h the least user privileges. - highest: Runs the task with the highest user pri...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~101-~101: Loose punctuation mark.
Context: ...hest user privileges available. - auto: Uses highest if schedule-permission...

(UNLIKELY_OPENING_PUNCTUATION)

🪛 markdownlint-cli2 (0.17.2)
docs/content/schedules/configuration.md

99-99: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


100-100: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)


101-101: Unordered list style
Expected: asterisk; Actual: dash

(MD004, ul-style)

🔇 Additional comments (11)
schedule/config.go (1)

15-15: LGTM: Clean addition of RunLevel field.

The new RunLevel field is properly positioned in the Config struct and follows Go naming conventions. This field will carry the run level configuration through the scheduling system.

schtasks/config.go (1)

12-12: LGTM: Appropriate addition for Windows Task Scheduler configuration.

The RunLevel field is correctly added to the schtasks Config struct, which will be used to control Windows Task Scheduler privilege levels.

schedule/handler_windows.go (1)

65-65: LGTM: Correct propagation of RunLevel to Windows scheduler.

The RunLevel field is properly assigned from the job parameter to the jobConfig struct, ensuring the run level configuration is passed to the underlying Windows Task Scheduler creation logic.

schedule_jobs.go (1)

229-229: LGTM: Proper mapping of RunLevel in configuration conversion.

The RunLevel field is correctly mapped from the input Schedule configuration to the schedule.Config struct, maintaining the run level setting throughout the scheduling pipeline.

config/profile.go (1)

315-315: LGTM: Well-structured configuration field with proper validation.

The ScheduleRunLevel field is properly configured with:

  • Appropriate mapstructure tag (schedule-run-level)
  • Sensible default value (auto)
  • Clear enum constraints (auto;lowest;highest)
  • Descriptive documentation indicating Windows-specific functionality

The field follows established patterns for schedule configuration options.

schtasks/taskscheduler_test.go (1)

283-289: LGTM! Appropriate placeholder for future testing.

The placeholder test function correctly documents the current limitation where run-level information is only available in XML format, not the CSV format currently used by the codebase. The TODO comment provides clear guidance for future implementation.

schtasks/taskscheduler.go (1)

57-70: LGTM! Clean implementation of the run-level logic.

The switch block correctly handles the three run-level options:

  • "lowest" maps to least privilege
  • "highest" maps to highest available privilege
  • "auto" (default) maintains backwards compatibility by using highest privilege for system accounts and default for others

The implementation preserves existing behaviour whilst adding the new functionality.

config/schedule.go (4)

38-38: LGTM! Well-structured configuration field definition.

The RunLevel field is properly defined with appropriate metadata tags, default value, and enum constraints that match the implementation in the scheduler.


54-54: LGTM! Consistent default value.

The default value "auto" aligns with the documented behaviour and scheduler implementation.


69-71: LGTM! Proper initialization pattern.

The initialization logic follows the established pattern used by other configuration fields in this struct.


106-106: LGTM! Complete override integration.

The applyOverrides method correctly includes the new RunLevel field, ensuring it participates in the configuration override mechanism.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 52.94118% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.49%. Comparing base (c7e87a1) to head (fddb92f).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
schtasks/taskscheduler.go 36.36% 5 Missing and 2 partials ⚠️
schedule/handler_windows.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #546      +/-   ##
==========================================
+ Coverage   79.36%   79.49%   +0.13%     
==========================================
  Files         136      137       +1     
  Lines       13334    13441     +107     
==========================================
+ Hits        10582    10684     +102     
- Misses       2333     2336       +3     
- Partials      419      421       +2     
Flag Coverage Δ
unittests 79.49% <52.94%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zumm
Copy link
Copy Markdown
Contributor Author

zumm commented Jul 31, 2025

@creativeprojects I don't know where to ask, so i will do here. When is new release? Any chance it happens after merging 541, 544 and 546?

@creativeprojects
Copy link
Copy Markdown
Owner

creativeprojects commented Jul 31, 2025

There's no definite rule for new releases.

Usually:

  • previous release was a few months ago
  • there's enough new material to release
  • it's been running for a few days on all my servers

I was thinking about releasing soon anyway, we have enough material waiting in the queue (but yeah we can wait for these 3 PR)

@zumm
Copy link
Copy Markdown
Contributor Author

zumm commented Jul 31, 2025

I was thinking about releasing soon anyway, we have enough material waiting in the queue (but yeah we can wait for these 3 PR)

Nice! I would like to just install resticprofile from winget instead of building from source on my new machine.
Let me know if i can do anything to speed up the merging process.

@creativeprojects
Copy link
Copy Markdown
Owner

To be honest I'll be a bit busy for the next few days so I might come back to it early next week 😉

@creativeprojects
Copy link
Copy Markdown
Owner

I would like to just install resticprofile from winget instead of building from source on my new machine.

BTW it's not me publishing to winget, there's a nice guy doing it regularly 😆

@zumm
Copy link
Copy Markdown
Contributor Author

zumm commented Jul 31, 2025

BTW it's not me publishing to winget, there's a nice guy doing it regularly 😆

I thought goreleaser takes care of it.

@creativeprojects
Copy link
Copy Markdown
Owner

Copy link
Copy Markdown
Owner

@creativeprojects creativeprojects left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the minor comment, it looks good to me 👍🏻

Comment thread config/schedule.go Outdated
@creativeprojects
Copy link
Copy Markdown
Owner

It needs a quick fix on a test that checks the output of the show command (with the new parameter): https://github.com/creativeprojects/resticprofile/actions/runs/16730518468/job/47357195404?pr=546#step:6:322

... and we're good to go 👍🏻

@zumm
Copy link
Copy Markdown
Contributor Author

zumm commented Aug 26, 2025

I wasn't aware of that command. :) Fixed now.

@creativeprojects
Copy link
Copy Markdown
Owner

Looks good, thanks for this PR 👍🏻

@creativeprojects creativeprojects merged commit f98a2f5 into creativeprojects:master Aug 28, 2025
9 of 10 checks passed
@creativeprojects creativeprojects added the enhancement New feature or request label Aug 28, 2025
@creativeprojects creativeprojects added this to the v0.32.0 milestone Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Runlevel option for schedule on Windows

2 participants