Repository navigation
feat(plugins): the generated loader replaces managed rc blocks — user rc read-only (niubash#359 case A, 1.4.2) - #421
Conversation
… rc read-only (niubash#359 case A, 1.4.2) Case A of the #359 design (promotion-drafts/design/rc-readonly-redesign.md): the control plane (plugins.toml + sources/registry.toml) drives a derived activation plane, and the user rc is never written by plugin management. - plugins::loader: ~/.niubash/generated/plugins.niu — deterministic render (sections sorted by id, no timestamps), structural validation, validate-then-atomic publish (niubash#304 swap; a failed generation keeps the last good one), superseded-marker record for the double-execution guard, $NIU_PLUGIN_LOADER_PATH override. - Host loading: run_startup_files sources the loader BEFORE the user rc (user overrides win); startup_decision skips on the rollback switch (NIU_PLUGIN_LOADER=off) or a superseded managed-block marker in the rc (exactly one live activation path), with a one-time migrate-rc hint (config-dir marker, fail-open; the only startup write, and only in the legacy-block situation). #180 in-session re-apply re-sources it too. - W1-W5 retired: enable/disable/sync/trust/restore/theme picks write the sidecar manifest only; materialize_spec_selection becomes compute_spec_selection + one publish_loader_generation per pass (keep-current carry-over for skipped ids; drop_silent for the undeclared pass). The rc writers stay as an UNWIRED rollback zone (design §4.3); gate 359.12's structure ratchet pins them unreachable from any verb. - niu plugin migrate-rc [--diff]: read-only diagnostic — scans exact + near markers (malformed begin-without-end reported, never fatal), publishes the candidate generation, records the superseded pairs, writes the suggested post-migration rc ONLY under ~/.niubash/candidates/. Never touches the rc. - Wizard: generate_rc embeds no activation content (the pick lands in the spec via record_theme_pick_in_spec, which now publishes the generation); W6's whole-file write converges to create-only in 1.4.3. - Doctor: read-only plugin-loader / legacy-block / #324-debris rows. - spec/registry writers atomic (design §4.4). - Tests: tests/rc_readonly_loader.rs pins gate cases 359.4 (verbs never write the rc, success and failure), 359.6 (#324 corrupt rc preserved byte-identically), 359.7 (byte-stable idempotent generation), 359.8 (double-execution guard + hand removal), 359.9 (order/override + rollback switch, zero writes), 359.12 (structure ratchet), migrate-rc and the doctor rows. Existing plugin/wizard/theme suites flipped to the loader + rc-untouched contract; startup/paste/host regression sets match the pre-change baseline two-way (--test-threads=1). Refs: niubash#359 (case A, owner-approved). Not closing: 359.5/359.10 (setup create-only, config writer) land in 1.4.3 per schedule.
…cate, tree-wide structure ratchet, regeneration keep-current CR findings (all verified fixed): - F1: the 359.12 ratchet now walks the ENTIRE production source tree (both crates' src/ and the binary src/, no closed file list), with zero-tolerance absence checks outside the rollback zone — the compile-passing mutation (pub deactivate_block reached from setup_wizard.rs) is closed twice: deactivate_block demoted to private (pub restoration is part of the rollback itself) and the tree-wide scan. Mutation-verified: a pub-again + cross-module-call variant now fails the ratchet by name. - F2: the double-execution guard, migrate-rc and the doctor share ONE predicate (guard_trip_lines): the loader is held off exactly when a marker pair (exact/near/any-id, plus recorded superseded lines) wraps executable content. Marker-shaped remarks — a single-line '# >>> niu source blocks were removed by hand ... <<<', lone markers, comment-only pairs — are inert and never hold the loader off; and when the guard DOES trip (an id-less pair the id-anchored scan cannot attribute), migrate-rc names the trip lines instead of printing 'clean' (MigrateReport::guard_trips + loader_held_off; the doctor row triggers on the same evidence). New gate test migrate_rc_names_guard_trips_the_scan_cannot_attribute. - F3: regenerate_loader_generation keeps the current section for spec entries that resolve to an id but have no registry record yet (a regeneration on migrate-rc must never silently de-activate); only never-resolvable entries are omitted, which is a no-op. - Nits: build_theme_block doc refreshed (preview renderer, no write path); migrate-rc second-run assertion formats its own output; the 359.9 self-comparison removed; the in-session setup re-apply now sources the loader BEFORE setting NIU_REPL_STARTUP, same order as run_startup_files. Refs: niubash#359, PR #421 CR round 1.
CR round 1 — all three findings fixed (ff171fc, rebased onto master b3c9c52)F1 (structure ratchet) — fixed, mutation-verified
F2 (guard/diagnostics vocabulary) — fixed via your option (b) + (a)
F3 (regeneration doc vs code) — fixed
Nits — all taken
Rebase + test evidence
Ready for re-review — focus areas per your note: F1 mutation re-verification (the tree walk + the private demotion) and F2 predicate sharing. |
7aad5e0 to
ff171fc
Compare
CR round 2 — verdict: REQUEST-CHANGES (one blocking finding; F1/F3/nits verified fixed)Independent re-verification on ✅ F1 (structure ratchet) — fixed, mutation re-verified both ways
✅ F3 (regeneration keep-current) — fixed
✅ Nits — all four verified (build_theme_block doc,
|
…ntent holds the loader off (F2-prime) The pairing requirement made the write era's end_missing state fail open: both markers are bash comments, so the block body below an unpaired begin executes unconditionally — the CR measured the double execution on ff171fc. Fix, per the CR's direction (359.8 fail-safe, CASE-1 preserved): - guard_trip_lines rule 2: an unpaired begin with ANY executable line below it trips the guard (niu cannot attribute the following lines — rather off than double-execute). Inert stays inert: the single-line remark, a lone marker followed only by comments/blanks, and comment-only pairs never trip. - doctor: the 'stays OFF' claim is keyed on the guard's verdict (guard_trips), not on the block scan — an inert legacy pair is now reported as 'comments only, loader unaffected' instead of being claimed to hold the loader off (the self-contradiction the CR measured). - Gate tests, both sides: lone_begin_with_executable_content_holds_the_ loader_off (end_missing rc → loader OFF, migrate-rc refuses 'clean', doctor says 'stays OFF', hand removal releases the loader) and lone_begin_with_only_comments_keeps_the_loader_on (inert stray → loader ON, migrate-rc reads clean). Unit tests cover both directions in the shared predicate. Refs: niubash#359, PR #421 CR round 2.
CR round 2 — F2-prime fixed (d5ee41c)The rule:
Inert stays inert (CASE-1 not regressed): the single-line remark Doctor self-contradiction fixed: the "stays OFF" claim is now keyed on the guard's verdict ( Gate tests, both sides (the two you asked for):
Unit tests in the shared predicate cover both directions plus the boundary (lone begin + comments-only below → inert). Evidence: runtime lib 550 passed / 0 failed (the upstream 8dc298f setopt fix cleared the last baseline lib failure); gate file 13/13; plugin_assets / plugin_spec_sync / plugin_anyplug / smoke_1_3_0 / defaults_floor / startup_files / issue359_startup_pty / plugin_bootstrap_read_only all green; Ready for your one-look merge pass — the lone-begin gate pair and the new predicate tests are the verification surface. |
What
niubash#359 case A (owner-approved), 1.4.2 slice per the design doc (
promotion-drafts/design/rc-readonly-redesign.md§6): the sidecar manifest drives a generated loader, plugin management stops writing the user rc entirely, andniu plugin migrate-rcis the read-only migration diagnostic. The typed-writer half (config writer,startup.rc-policy, setup create-only) stays in 1.4.3 per schedule.Design doc:
D:/repo/promotion-drafts/design/rc-readonly-redesign.md— this PR implements its §3 案 A / §4 / §5 within the 1.4.2 row.The loader (activation plane)
~/.niubash/generated/plugins.niu(plugins::loader,$NIU_PLUGIN_LOADER_PATHoverrides): rendered fromplugins.toml+sources/registry.toml, deterministic (sections keyed/sorted by id, no timestamps — identical manifest state ⇒ byte-identical file), validate-then-atomic-publish (structural validation; the [rc][P3] .niubashrc rewrite is not atomic (concurrent readers can see it missing) #304 temp+rename swap; a failed generation keeps the last good one; a byte-identical regeneration is a no-op and does not churn mtime).Host loading (read-only, ordered, guarded)
run_startup_filessources the loader before the user rc (user PS1/alias/function overrides win), in the interactive rc branch only — login chains and-c/BASH_ENV paths are untouched.startup_decision:NIU_PLUGIN_LOADER=off|false|0|no→ skip (the rollback switch; load-only, zero writes, unset rolls forward);migrate-rchint (config-dir marker, fail-open; the only startup write, and only in the legacy-block situation — clean homes stay byte-for-byte untouched);W1–W5 retired, rollback kept
enable/disable/sync/update/restore/trust+ theme picks write the sidecar manifest only:materialize_spec_selectionsplits intocompute_spec_selection(pure selection + tree-sideenabled/effects) and onepublish_loader_generationper pass (keep-current carry-over for skipped ids — awaiting-trust/degraded/drifted; silent drop for the undeclared pass).write_managed_block/remove_managed_block/apply_block/write_block_report/deactivate_blockremain inassets.rsas an unwired rollback zone (design §4.3: code-level rollback = small diff). Gate 359.12's structure ratchet (intests/rc_readonly_loader.rs) pins their call-syntax count to the zone-internal shape and fails if any verb re-attaches them.niu setupstops embedding managed blocks (the pick lands in the spec;record_theme_pick_in_specpublishes the generation). W6's whole-file rc write converges to create-only in 1.4.3 — noted in the ratchet as out-of-scope-for-now.niu plugin migrate-rc [--diff]— never writes the rcScans exact + near markers (line ranges, ownership vs the spec, begin-without-end reported — never fatal), publishes the candidate generation from the current manifest, records the superseded pairs, and with
--diffwrites the suggested post-migration rc only under~/.niubash/candidates/. Removal of old blocks is always the user's own edit.Adjacent hardening (design §4.4)
save_specandwrite_source_registryswap whole files atomically (#304 semantics generalized to the control plane).Gate coverage (rubash#746 ratchet format)
New
tests/rc_readonly_loader.rs:plugins::loader)startup_files.rs,plugin_bootstrap_read_only.rs,issue359_startup_pty.rs) — all greenExisting suites flipped to the new contract (design §6: "rc 不变" replaces "rc 含块"): in-crate
plugins::assets/plugins::sync/setup_wizardtests,plugin_assets,plugin_spec_sync,plugin_anyplug,defaults_floor,smoke_1_3_0.Test evidence
--test-threads=1(--no-fail-fast), two-way failure comparison against a pre-change baseline run on pristineorigin/master(d60276e):host_contract::rubash_setopt_is_visible_when_sourcing_startup_rc,interactive×5 (continuation_*,ctrl_c_*,ctrl_d_*,gitbash_factory_*),niubash-runtimelibcompletion::command::tests::test_get_builtin_commands— identical set before and after; no new failures.cargo fmt --check -p niubashclean;cargo build --lockedclean; zero compiler warnings in the runtime crate.Not in this PR (1.4.3, per the design schedule)
setupcreate-only + candidate file/diff for W6,config.rswriter rework →startup.rc-policy, gate 359.5/359.10, TRUST UX sub-item. Do not merge before the 1.4.1 release window closes — this branch rebases weekly ontoorigin/master.Refs: niubash#359 · #324 · #304 · #413 (activation-timing CR that informed the startup-file placement)