Repository navigation
fix(plugin): validate ledger migration render and preserve alias defaults (#2576) - #2614
Conversation
…defaults F1: capability sets now wrap one entry per line when the inline form would approach the parser's 1024-byte line bound. Migration re-parses the rendered Lua and requires the same records before the atomic commit; a rejected render is a hard StateInvalid error that leaves the legacy TOML and writes no Lua ledger. Regression: two 500-byte fs.read grants migrate, parse on the next command, keep both grants, and retain the .bak. F2: generated defaults resolve the short-alias path instead of passing a None discovered set, so an existing <name>.lua user file is never shadowed by a newly created canonical file. Regression covers install with cfg.lua present and config show selecting the alias value. F3: plugin doctor --repair leaves an already-current ledger byte-identical and no longer replaces .bak on every run. Manual docs now state that read-only doctor writes nothing. Also: parser control-character docs corrected, .bak mode documented, special-file legacy source and invalid settings schema tests added, and a safe-mode test proves a present ledger is never opened. Candidate tests now write/read bitty-plugins.lua. Refs #2576 Task: CTX-1487
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 13 minutes. View limit details
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. Comment |
Xuepoo
left a comment
There was a problem hiding this comment.
Independent review (guard tick, separate agent) — PASS
Reviewed head a3070d5a (ctx-1487/fix-ledger-migration-alias), 6 files, +425/−73.
Checks performed:
gh pr checks 2614on heada3070d5a: 18 SUCCESS / 2 SKIPPED / 0 fail / 0 pending — Quality gates (1)+(2), Linux X11, Linux Wayland, Windows, macOS ARM64, MSRV 1.85, Supply chain, CodeQL (actions+rust), VM tier (PR), compat matrices, Extension pin drift all green.- Diff scope matches the stated intent:
bitty-config/src/plugin_ledger.rs(render/validate),bitty-terminal/src/{plugin,runtime_inspect,candidates}.rs,tests/cli_plugin.rs,CHANGELOG.md. No dependency-edge, no lockfile, no CI-config change. - Root-cause confirmation: the main-branch red (
candidates::tests::plugins_union_state_and_store_sorted,candidates.rs:415,left = ["aaa.installed","middle.installed"]) is caused by the test fixture still writing the legacy TOML ledger after the Lua-ledger migration (5a8f8b71). This PR rewrites the fixture to emit a validbitty-plugins.luaviaPluginState::render()and keeps the malformed/oversized fail-soft cases on the Lua path — i.e. it fixes the production-vs-fixture mismatch without weakening the assertions. - Production reader behaviour unchanged for the legacy path: legacy TOML fallback assertions are retained in the same test module, so the migration stays backwards compatible.
Verdict: PASS. This PR is the unblock for main's red and for the four code PRs currently inheriting the same failing test (2611/2599/2588/2567, plus 2615/2616).
Priority: P1 | Area: config/plugin | Labels: fix,P1,area:config,area:plugin | Milestone: v0.0.28 | Task: CTX-1487 | Refs #2576
Summary
Follow-up to merged #2600 (commit
5a8f8b71) for the defects found inindependent review. The feature stays; this hardens migration and generated
defaults.
F1 (P1) — migration could commit a ledger the parser rejects
PluginState::rendernow wraps a capability set one entry per line when theinline form would approach the parser's 1024-byte line bound. A capability
id is closed at 512 bytes, so every wrapped line fits.
migrate_legacy_ledgernow calls the same pre-commit guard assave_state:it re-parses the rendered bytes and requires the same records back. A
rejected render is a hard
StateInvaliderror; no Lua ledger is written andbitty-plugins.tomlis not moved.validate_rendered_ledger), so asave_staterenderdrift now also fails closed instead of only syntax-checking.
Exact pre-fix repro (now a regression test):
legacy TOML with two 500-byte
fs.read:grants rendered a 1049-bytegranted = [...]line; migration exited 0 and moved the TOML, the next commandexited 4
StateInvalid, anddoctor --repairquarantined the ledger. Afterthe fix the same fixture migrates, every line is
<= 1024bytes, the nextlistsucceeds, both grants survive,.bakmatches the original bytes, anddoctordoes not quarantine.F2 (P2) — generated defaults shadowed a short-alias settings file
ensure_generated_plugin_confignow passes the plugin as a discovered-idclaimant, so
plugin_config_pathsresolves the<name>.luaalias path andthe existing alias guard is live. An existing alias (or canonical/legacy
file) means no canonical file is generated.
plugins/cfg.luapresent, install creates noplugins/xuepoo.cfg.lua, andconfig showstill selectslua-aliaswiththe user's
show = false.F3 (P3 docs + behavior)
bitty-manual: read-onlyplugin doctorwrites nothing; the nextstate-loading command or
doctor --repairmigrates..bakmode and theno-shadow rule are documented. Docs-only PR:
docs(plugins): correct legacy-ledger migration trigger (#2576) bitty-manual#76 (merged).
doctor --repairnow skips the write when the Lua ledger is current and hasno stale records, so it no longer churns
.bakor rewrites healthy bytes.Minor hardening
rejected;
\n/\r/\tescapes decode but identifier grammars reject them).(directory), and safe mode with a present invalid ledger (proves the file
is never opened).
bitty-plugins.lua; they were writing alegacy TOML at the Lua path and silently returning only store candidates.
Validation
cargo fmt --all -- --checkcargo clippy -p bitty-config -p bitty-terminal --all-targets -- -D warningscargo test -p bitty-config— 499 passedcargo test -p bitty-terminal --bin bitty— 1232 passedcargo test -p bitty-terminal --test cli_plugin— 53 passedbitty-manualjust check— prettier, markdownlint, schema verification,package build passed
commit, alias no-shadow, doctor repair no-op, invalid schema, special-file
legacy source, safe mode with a present ledger.
Residual risks
the legacy ledger stays readable and migration retries on later commands.
Only a rejected render is a hard failure.
fallback; this PR does not change it.