Skip to content

fix: accept unlimited for the keep-* options in the JSON schema - #717

Closed
lbarrosby wants to merge 1 commit into
creativeprojects:masterfrom
lbarrosby:fix-keep-unlimited-schema
Closed

lbarrosby wants to merge 1 commit into
creativeprojects:masterfrom
lbarrosby:fix-keep-unlimited-schema

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

Fixes #449

restic's help for --keep-last, --keep-hourly, --keep-daily, --keep-weekly, --keep-monthly and --keep-yearly says "use 'unlimited' to keep all ...". The default for each of these options is 0, so newResticPropertyInfo types them as integer only. Both the v1 and v2 schemas then reject keep-last: unlimited in the forget and retention sections.

This adds a property customizer, next to the existing one for verbose. A restic option whose description offers 'unlimited' may also be a string, and the string must match ^unlimited$. The flags are passed to restic unchanged, so only the schema changes. keep-last in the v2 schema:

# before
{"type": "integer"}
# after
{"oneOf": [{"type": "integer"}, {"type": "string", "minLength": 0, "pattern": "^unlimited$"}]}

This is the oneOf proposed in the issue.

Checks:

  • TestResticKeepUnlimitedProperty in config/info_customizer_test.go: before the customizer runs, the option is numeric only; after it runs, it is numeric or string with the pattern. An option without 'unlimited' in its description is left alone.
  • End to end: I ran resticprofile generate --json-schema v2 on master and on this branch, then validated {"forget": {"keep-last": "unlimited", "keep-daily": 7}} with Python jsonschema (Draft 2020-12). Master reports 'unlimited' is not of type 'integer', and this branch reports it valid.
  • go test -short ./config/... and go vet ./config/ pass.

restic accepts "unlimited" for --keep-last, --keep-daily and the other
keep-* options, and says so in their help, but their default is 0, so
the schema typed them as integer only and editors flagged
keep-last: unlimited as invalid. Let the options whose description
offers 'unlimited' also be a string matching ^unlimited$.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The property customizer now accepts the exact string unlimited for restic options whose descriptions contain use 'unlimited'. A test checks the validation pattern for keep-last and the absence of a pattern for max-unused.

Changes

Retention option values

Layer / File(s) Summary
Customize unlimited values and verify properties
config/info_customizer.go, config/info_customizer_test.go
The customizer enables string values with the exact pattern ^unlimited$ when an option description contains use 'unlimited'. Tests check keep-last and confirm that max-unused has no validation pattern.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: creativeprojects

Merge Risk: Minimal · up to 0c9b7

The change lets the schema accept "unlimited" for restic keep-* options alongside integers. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: restic keep-* options in the JSON schema now accept 'unlimited'. It matches the objectives and the raw summary, which describes a property customizer for options whose…
Description check Passed The description states the problem (restic's keep-* help text says 'use unlimited', but the schema types them as integer only), the fix (a property customizer next to the verbose one), the schema befo…
Linked Issues check Passed [#449] Requires that the v1 and v2 JSON schemas accept "unlimited" for the --keep-* options in the retention and forget sections, alongside integers. At head 0c9b71d, config/info_customizer.go adds a …
Out of Scope Changes check Passed The change set has two parts: a customizer in config/info_customizer.go (+9 lines) and TestResticKeepUnlimitedProperty in config/info_customizer_test.go (+19 lines). Both directly implement the #449 o…
Full details: Title check

Explanation

The title names the main change: restic keep-* options in the JSON schema now accept 'unlimited'. It matches the objectives and the raw summary, which describes a property customizer for options whose descriptions mention 'unlimited'. The title uses the 'fix:' prefix and is specific.

Full details: Description check

Explanation

The description states the problem (restic's keep-* help text says 'use unlimited', but the schema types them as integer only), the fix (a property customizer next to the verbose one), the schema before and after, the test, and an end-to-end validation. It relates directly to the changeset.

Full details: Linked Issues check

Explanation

[#449] Requires that the v1 and v2 JSON schemas accept "unlimited" for the --keep-* options in the retention and forget sections, alongside integers. At head 0c9b71d, config/info_customizer.go adds a customizer. When an option description contains "use 'unlimited'", the customizer sets info.mayString = true and info.pattern = ^unlimited$. The keep-* options use this description, so their schema type becomes integer or string, and a string must match ^unlimited$. The type is an integer-or-string union, so the integer and string branches are disjoint and a oneOf is valid. The issue proposes enum ["unlimited"]. The pattern form accepts the same value and is an accepted alternative to the proposed enum. The customizer runs on the shared property information used by schema generation. The author reports an end-to-end check of the v2 schema (master rejects keep-last: "unlimited"; this branch accepts it). The v1 schema is not checked end to end in the PR description. The shared code path covers v1 by design, but this was not verified directly. The unit test TestResticKeepUnlimitedProperty covers the customizer behaviour, including an option without 'unlimited' left unchanged. No non-coding requirement applies.

Full details: Out of Scope Changes check

Explanation

The change set has two parts: a customizer in config/info_customizer.go (+9 lines) and TestResticKeepUnlimitedProperty in config/info_customizer_test.go (+19 lines). Both directly implement the #449 objective. The customizer applies only to options whose description contains "use 'unlimited'", so it does not alter other schema properties. The test covers both the affected option and an unaffected option. No unrelated change was found in the reviewed diff of config/info_customizer.go.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6a2476c3-c85d-480c-a5b9-4f74a63168c8
Commits

Reviewing files that changed from the base of the PR and between cce8511 and 0c9b71d.

Files selected for processing: 2

  • config/info_customizer.go
  • config/info_customizer_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.42%. Comparing base (cce8511) to head (0c9b71d).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #717      +/-   ##
==========================================
+ Coverage   85.41%   85.42%   +0.01%     
==========================================
  Files         161      161              
  Lines       10336    10341       +5     
==========================================
+ Hits         8828     8833       +5     
  Misses       1508     1508              
Flag Coverage Δ
unittests 83.33% <100.00%> (+0.01%) ⬆️

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

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

@creativeprojects creativeprojects added the duplicate This issue or pull request already exists label Nov 18, 2026
@creativeprojects

Copy link
Copy Markdown
Owner

Thank you for this PR!

This looks good, but actually someone else did open a PR for the same fix a couple of weeks ago, and actually I slightly prefer the other one, sorry 😉 #683

Keep the good work coming though 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON schema missing unlimited option for --keep-* flags in the retention and forget profile sections

2 participants