fix(cli): mds init writes through atomic_write_file — a symlink at the target is refused, --force replaces by rename (#386) - #391
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mds initnow writes the starter file through the same replace-by-rename primitive as every other CLI write (output::atomic_write_file,Durability::RenameOnly). A symlink at the target path — live under--force, or dangling without it — is refused withcannot write <path>: refusing to replace a symlink(exit 1) and neither the link nor its target is touched. Previously a dangling link was written through (creating its target) and--forcetruncated a live link's target in place. Theinitentry is gone from thetests/write_funnel.rsallow-list, so the CLI's only remaining raw write is the test-only readiness marker inwatch.rs.RenameOnlybecause the starter is a fixed public template a re-run reproduces; exit stays 1 because every existingatomic_write_filecaller's refusal already exits 1 (build -o,fmt,lint --fix).Behaviour contract
--force--force0666 & !umask(unchanged).mds-tmp-residue, exit 0exists()follows → "already exists", exit 1, nothing touched (unchanged)cannot write <p>: refusing to replace a symlink, exit 1; link and target untouched (was: target truncated)cannot create temp file for <p>: No such file or directory (os error 2) …The parent-dir-missing wording change is recorded here deliberately; it is not a CHANGELOG item.
Commits
test(cli): RED— three#[cfg(unix)]tests intests/cli_commands.rs(live symlink under--force, dangling symlink without it,--forceon a 0o600 regular file as a pin). RED evidence:6 tests run: 4 passed, 2 failed(exitSome(0)vs expectedSome(1)).fix(cli)—run_initwrites viaoutput::atomic_write_file(&filename, starter, output::Durability::RenameOnly); the..check and theexists() && !forcecheck are byte-identical. Intermediate positive control with the allow-list entry still present:allow-list expects 1 raw \fs::write(` in main.rs, found 0` (2 of 3 write_funnel tests failed); after deleting the tuple: 3 passed.docs— CHANGELOG### Fixedbullet, "two justified sites" → "one justified site", spec §7.2 writer list + §7.6, SECURITY.md writer list, KB site counts (mds-fmt, mds-lint).Gates (local, on
a65fa99)cargo fmt --all -- --checkclean;cargo clippy --workspace --all-targets -- -D warningsclean;cargo clippy -p mds-cli --all-targets --features startup-race-probe -- -D warningscleancargo nextest run -p mds-core -p mds-cli: 2355 passed (mds-core 1465, mds-cli 890; +3 vs main)cargo test --doc -p mds-core: 53 passed;cargo +1.88 check -p mds-core -p mds-clicleannpm run test:gates: 212 pass / 0 fail;node scripts/verify-no-control-bytes.mjs✓ (563 files)git grep -c 'fs::write(' crates/mds-cli/src/main.rs→ 0Snyk code scan unavailable (MCP ENOENT); the
security/snykCI check is SCA-only.Not a release-surface PR (no
release.yml,.github/actions/**,crates/mds-napi/**,crates/mds-python/**,verify-napi-names.mjs, ormusl-load-probe.cjschanges).Related Issues
Closes #386