Skip to content

fix(plugins): never silently rewrite an unparsable source registry (niubash#178) - #246

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/registry-consent
Oct 10, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/registry-consent

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #178

Problem

A registry.toml line that fails to parse made every read see an empty view (only a RUST_LOG warning), and the next successful niu plugin sync rewrote the file without it — silently dropping the persisted pin commit/checksum/trust state.

Fix — corrupt bytes are user data

  • Reads: an unparsable registry is snapshotted byte-for-byte to registry.toml.corrupt next to the file, and a visible warning (stderr, not just RUST_LOG) is emitted exactly once per distinct content.
  • Writes: write_source_registry refuses while the on-disk file fails to parse — sync surfaces a failed row naming the parse error instead of rewriting; the corrupt file (pins included) survives untouched.
  • Install: install_or_adopt refuses before any fetch/promotion, so no half-installed tree or misleading retry.
  • Doctor: niu doctor shows an explicit UNPARSABLE row (parse error's line + sidecar path) instead of the misleading "none installed".

Consent = the human repairs (fixes or removes) the file; writes and normal sync then resume and the records round-trip.

Regression tests

  • corrupt_registry_is_preserved_and_never_silently_rewritten (sources): failed line + pin survive byte-for-byte; warn-once; write refused; post-repair write/read round-trips trust + commit pin.
  • sync_never_rewrites_a_corrupt_registry (sync): end-to-end sync refuses with a failed row, registry + sidecar survive, post-repair sync adopts the pinned record and activates.

Full niubash-runtime lib suite: 394 passed; the only 3 failures (plugins::distros::tests::apply_*) reproduce identically on clean HEAD (bundled niugit cannot clone the MSYS-style local mirror path in this environment) and are unrelated.

…iubash#178)

A registry.toml that fails to parse used to read as an empty view with
only a RUST_LOG warning, and the next successful sync rewrote the file
without the corrupt line — silently dropping the persisted pin commit,
checksum and trust state riding in it.

Now the corrupt bytes are treated as user data:
- reads snapshot the file byte-for-byte to registry.toml.corrupt and
  warn once per distinct content (visible on stderr, not just RUST_LOG);
- registry writes are REFUSED while the on-disk file fails to parse —
  sync and install fail loudly as 'failed' rows instead of rewriting;
  the pin/trust records survive until a human repairs the file;
- install refuses before any fetch/promotion (no half-installed tree);
- 'niu doctor' surfaces the corruption explicitly, naming the parse
  error's line and the preserved sidecar, instead of 'none installed'.

Consent is the human repair: once the file parses again, writes and
normal sync resume and the records round-trip.

Closes niubash#178
@caomengxuan666
caomengxuan666 merged commit 75956a0 into master Oct 10, 2026
3 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/registry-consent branch October 10, 2026 05:07
caomengxuan666 added a commit that referenced this pull request Oct 10, 2026
…notes draft (#254)

- Version 1.3.4 -> 1.4.0 (workspace root + crates/niubash-runtime;
  Cargo.lock synced; internal niubash-runtime dep requirement aligned
  1.2.5 -> 1.4.0). The rubash engine requirement stays 1.3.4: it is
  semver-open (^1.3.4 admits the engine's 1.4.0), and the committed
  [patch] resolves it to the local ../rubash worktree, whose Cargo.toml
  still says 1.3.4 until the engine cuts its own release.
- CHANGELOG: the Unreleased section becomes [1.4.0] - 2026-10-10. Also
  repairs the committed merge damage from #243 (stray conflict marker
  and the #241 doctor-advice entry glued onto the carapace entry) and
  folds in the merged cycle: #235 #239 #246 #247 #250 #251 #252 #253
  plus a compact rubash 1.4.0 engine summary. #240's P2-batch content
  stays under [1.3.4] where the file already records it (no dup).
- docs/release-notes-1.4.0-draft.md: zh+en draft release notes
  (Added / Fixed / Performance), winuxcmd #1151/#1154-#1157 marked as
  in-flight for the coordinator, plus the local verification log:
  release build PASS (niu.exe 10.6 MB), MSIX packed unsigned with a
  placeholder identity (5.1 MB), wpm-source main carries all four
  preinstall packages, and cargo publish --dry-run chain findings
  (rubash -> niubash-runtime -> niubash, blocked on the engine's
  crates.io release).

No tag, no release workflow trigger, no in-flight PRs merged.
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.

[P1] registry 解析失败行被下一次 sync 无 consent 重写丢弃(钉扎/信任记录丢失)— M2

1 participant