The rule editor drops a key it does not know at the top of the rules file when it saves

Closed
#200 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

A pull request for this has already been merged.

  • #237 by @JWhite212 — merged

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
macos, swift
Domain
desktop

Research direction

Start with RulesDocument.load in Sources/NotificationCore/RulesDocument.swift and the existing ReadOnlyReason cases in Sources/NotificationCore/EditorText.swift; follow compiler-reported exhaustive switches such as SetupPlan.swift. Add tests for files with unknown top-level keys and document the editor behavior in docs/rules-format.md, then update CHANGELOG.md. Verify the issue’s pins and stop if any stated stop condition applies; done means existing tests pass unchanged and the new read-only behavior is covered.

Written by the indexing model from the issue text.

Description

bug

Audit row: B21, Defects (added by #193). Line numbers are those of 4553590. Find the code by what it says, and re-run every pin command on the branch point.

What is wrong. The codec reads only rules from the file's top level (RuleSetCodec.swift:511-519). RulesDocument.load calls such a file editable, and Save writes back only version and rules, so a "_comment" beside them is gone; rules.previous.json keeps one save. RulesDocument.swift:18-19 says a file the editor cannot represent in full is not offered for saving. A scratch program: a file with "_comment" loads, opens as editable, and has no "_comment" after Save.

Behaviour that must survive. The loader accepts such a file as it does now; only the editor changes.

The change. RulesDocument.load returns .readOnly with a new reason when the top level holds any key besides version and rules. Its words go beside the other reasons in EditorText.readOnly, naming the keys and saying the file can be edited by hand. Owner after: RulesDocument.load.

In scope: Sources/NotificationCore/RulesDocument.swift, Sources/NotificationCore/EditorText.swift, every exhaustive switch over ReadOnlyReason the compiler names (SetupPlan.swift among them), new tests, docs/rules-format.md (what the editor does with such a file), CHANGELOG.md.

Out of scope, however tempting: Refusing such a file at load, and keeping unknown keys through a save.

Frozen side: the tests. Every existing test passes unchanged; new tests are added.

Pins (counts at 4553590):

  • grep -rn 'ReadOnlyReason' Tests | wc -l → 14.
  • grep -rn 'ReadOnlyReason' Sources lists the switches the new case reaches.

Check, on the branch:

  • swift build --build-tests -Xswiftc -warnings-as-errors: no warning.
  • swift test --skip-build: 0 failures, at the branch point's count plus the new tests (state both in the pull request).
  • Each new test is seen to fail once against the code as it was.

Stop, and say so here before going on, if: the code cited has already changed; a pin appears that is not listed; a file outside the scope is needed; or any existing test would have to change.

Hold: not merged before v1.1.0 is tagged (owner, 2026-11-06). It changes the app's code, and a code change restarts the go/no-go bar's two weeks.

Prevention: Guard added: a test that a file with an unknown top-level key opens read-only with that reason.

Size: S.

Dominant language
Swift
Stars
2
Forks
0
Avg merge
1h 7m
Merged PRs (30d)
152

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JWhite212/SignalLadder

All issues in JWhite212/SignalLadder

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.