Skip to content

Change history: config-level diff, a record of every apply, rollback N as a normal change (#12, part 1) - #59

Merged
Cd1s merged 1 commit into
mainfrom
feat/change-history
Sep 25, 2026
Merged

Cd1s merged 1 commit into
mainfrom
feat/change-history

Conversation

@Cd1s

@Cd1s Cd1s commented Sep 25, 2026

Copy link
Copy Markdown
Owner

What (part 1 of #12)

Config-level diff. The config last applied is recorded as gen/applied.yaml (canonical form) and gen/applied-secrets (sha256 per secret, mode 0600) — bookkeeping files the plan writes and every rollback restores; they are not listed among the plan's files. mr plan, mr apply and the web UI's apply dialog now start with what changes in config terms:

changes:
  ~ wifi.radios[phy1].htmode: HE80 → HE160
  + firewall.forwards[nas-ssh]
  - dhcp.hosts[old-tv]
  ~ firewall.forwards: order a, b → b, a
  ~ secrets.wifi_key: (changed)
plan:
  write   /etc/hostapd/hostapd-phy1.conf
  restart mr-hostapd

List items are identified by name (radios by phy, SSIDs by ssid); values switched back to their default show as (default). mr plan -v / mr apply -v add every generated file's diff with all secret values masked.

A record of every apply. Each snapshot gets a <snapshot>.json: revision number, time, origin (mr apply, web UI + client address, restore, rollback), comment (mr apply -m "…", a field in the web UI dialog), mr version, the diff above and the result — applying → applied, or pending → confirmed, or rolled back: … (verification failed, not confirmed in time, reverted, at boot). mr history [--json]. system.history (5–200, default 20) sets how many snapshots are kept; pruning removes their records too.

Rollback as a normal change. mr rollback N (CLI, --confirm default 120 s) and 回滚到此前 in the web UI put the config from before change #N back through validate → plan → apply with the confirm window, as a new revision (origin rollback); the web UI password stays the current one (the snapshot's saved hash is not restored). Snapshots taken before this change remain listed and can still be rolled back to. mr rollback without a number keeps its immediate behaviour (undo the pending change / restore a snapshot file).

Web UI. The page 备份与回滚 becomes 变更历史: time, origin, comment, result tag, the list of changes, 对比现在 (config before that change → now) and 回滚到此前; the apply dialog shows the config changes and takes a comment; apply and rollback share one progress / confirm view.

Left for part 2 (same issue): risk levels from the admin's own connection, automatic confirm of low-risk changes, mr apply --wait.

Why

A plan used to list only generated files and services — not what changed in router.yaml terms — and the history was a list of anonymous tar files whose "roll back" restarted services directly, without verification or a confirm window.

Verification

  • New tests (mr/history_test.go): config diff (named items, radios by phy, inline lists, defaults, reordering, identical configs → nothing); secret diff never contains values; the applied record and the plan hiding it; revisions numbered, results recorded, pruned with their snapshots; staging a rollback takes the snapshot's router.yaml and secrets but today's web UI password; masked file diffs. Existing apply / confirm / boot-rollback tests updated.
  • Web UI checked in the mock UI (synthetic history).
  • tools/ci.sh passes (private and public trees).

Part of #12

https://claude.ai/code/session_01HWeUjo1dmS7gBkCYHrVjCr

…ply, rollback N as a normal change

Part 1 of #12 (risk levels and automatic confirm follow).

- `mr plan` / `mr apply` / the web UI's apply dialog show what changes in config terms
  ("~ wifi.radios[phy1].htmode: HE80 → HE160", "+ firewall.forwards[web]", secrets only as
  "(changed)"), against gen/applied.yaml + gen/applied-secrets (bookkeeping the plan writes and a
  rollback restores). `-v`: each generated file's diff, secret values masked.
- Every apply records a revision next to its snapshot: rev, time, origin, comment (`mr apply -m`,
  web UI field), version, the diff and the result. `mr history`; `system.history` (default 20).
- `mr rollback N` / 回滚到此前: the config from before change #N applied as a new change (verify +
  confirm window), the web UI password kept.
- Web UI 变更历史 page; tests; mock data.

Part of #12
@Cd1s
Cd1s merged commit 4760c3f into main Sep 25, 2026
2 checks passed
@Cd1s
Cd1s deleted the feat/change-history branch September 25, 2026 17:41
@Cd1s Cd1s mentioned this pull request Sep 25, 2026
52 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant