feat(schedule): introduce run-level option#546
Conversation
WalkthroughA 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Assessment against linked issues
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 detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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-levelparameter. 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
📒 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
RunLevelfield 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
RunLevelfield 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
RunLevelfield 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
RunLevelfield 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
ScheduleRunLevelfield 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 othersThe implementation preserves existing behaviour whilst adding the new functionality.
config/schedule.go (4)
38-38: LGTM! Well-structured configuration field definition.The
RunLevelfield 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
applyOverridesmethod correctly includes the newRunLevelfield, ensuring it participates in the configuration override mechanism.
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@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? |
|
There's no definite rule for new releases. Usually:
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. |
|
To be honest I'll be a bit busy for the next few days so I might come back to it early next week 😉 |
BTW it's not me publishing to winget, there's a nice guy doing it regularly 😆 |
I thought goreleaser takes care of it. |
|
It looks like it's automated 🤔 https://github.com/microsoft/winget-pkgs/tree/master/manifests/c/creativeprojects/resticprofile/ |
creativeprojects
left a comment
There was a problem hiding this comment.
Apart from the minor comment, it looks good to me 👍🏻
|
It needs a quick fix on a test that checks the output of the ... and we're good to go 👍🏻 |
|
I wasn't aware of that command. :) Fixed now. |
|
Looks good, thanks for this PR 👍🏻 |
f98a2f5
into
creativeprojects:master
Resolves #475
Introducing new
run-leveloption 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.