Skip to content

fix(#1122): writers replace a symlink and skip a directory at a template destination - #1157

Merged
admarble merged 4 commits into
mainfrom
feature/1122-fix-writers-update-init-sync-write-through-an-exis
Sep 25, 2026
Merged

admarble merged 4 commits into
mainfrom
feature/1122-fix-writers-update-init-sync-write-through-an-exis

Conversation

@admarble

@admarble admarble commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two writer defects the #1097 writer-state matrix pinned, both at template destinations:

KNOWN_DEFECTS in the matrix is now empty — these were its last two entries.

Design notes

  • Why fs.writeFile and not a helper at the two call sites. The 24 cells span two unrelated writers (copyTemplates' direct .claude/settings.json write, outside copyDir; update's bare-writeFile applySet loop), and the class already recurred once after fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053 fixed it locally. A local fix leaves .sequant/settings.json, AGENTS.md and the constitution still writing through links. All 36 writeFile call sites inherit the rule; a regular file is still overwritten in place, so nothing changes where no link exists.
  • Skip, not throw, for the directory case. AC-2 offers "named error or documented skip", but only the skip branch is reachable: the matrix asserts dry.threw === null matches apply.threw === null, and classify returns X whenever a writer threw with a directory before and after — so throwing keeps all 32 cells at X and directory-crashes-writer could not be removed. Follows fix(init): --yes init replaces a user-modified AGENTS.md and an unparseable .mcp.json that sync would preserve #1123's precedent (createProjectMcpJson returns without writing and reports the file untouched), which is why .mcp.json's directory row already read = = = = = =.
  • A collision is its own report block, not an ownership verb. Nothing is overwritten, preserved or merged at those paths, so listing them under overwrite: would promise a write that never happens — and printedDecision would read it as o and break the DECISIONS rows.
  • copyDir keeps its own pre-unlink. writeFile now guarantees the same thing, but that branch is what stops keepExistingFiles from treating a link as "an existing file" and leaving it in place (the fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053 init case).
  • violations() now returns only non-zero counts. The old initializer had to name every key in advance, and the one key it missed (user-owned-not-preserved-without-force) incremented undefined into NaN instead of failing legibly. Required anyway: with KNOWN_DEFECTS empty, a zero-valued key would not match {}.

Out of scope

.mcp.json writes through fs.writeFileSync directly (mcp-config.ts:243,356,471), so its M cells at symlink states remain write-throughs. It is a merge destination, outside AC-1's literal scope, and no invariant counts it — follow-up issue rather than widening this PR.

Pre-PR AC Verification

AC Source Description Status Evidence
AC-1 Original No writer writes through an existing symlink at a sequant-owned destination; link replaced, target byte-identical ✅ Implemented src/lib/fs.ts:64 unlinks before writing; symlink-written-through-at-sequant-owned removed from KNOWN_DEFECTS (writer-state-matrix.test.ts:456); settings/skill/scriptsCopy symlink rows → T, scriptsLink → L L L L T T. classify returns V (not T) if the old target changed, so "target stays byte-identical" is asserted, not assumed.
AC-2 Original Directory at a destination yields <path> is a directory; move it aside, no partial write, both dry-runs report instead of throwing ✅ Implemented directoryCollisionMessage (src/lib/fs.ts:94) is the single source; guards in computeTemplateChanges, copyDir, symlinkDir, the direct .claude/settings.json write, updateGitignore and createDefaultSettings. directory-crashes-writer removed from KNOWN_DEFECTS; all 9 directory rows → = = = = = = with DECISIONS unchanged at - - - -.
AC-3 Original The foreign-symlink repro leaves the outside file's content unchanged ✅ Implemented New describe("#1122: foreign symlink at .claude/settings.json") — 4 named cases (sync, sync --force, update, update --force) asserting the outside file's bytes survive and the destination ends a regular file with template content.
AC-4 Original Build and full suite green ✅ Implemented npm run build ✅, npm run lint ✅ (0 errors, 0 warnings), full suite ✅ — 337 test files, 8393 passed, 1 expected fail, 3 skipped, 0 failures (table under Test results). CI test + canary both SUCCESS on this head.
Derived
AC-5 Gate-test discipline PR body carries a SEQUANT_MUTATION marker for AC-3, failedTest starting with the test file path ✅ Implemented Three markers below; each prints valid through parseMutationMarkers.

Mutation verification

Mutation-verified: AC-1 — restored the bare fsWriteFile in src/lib/fs.ts:writeFile; 32 grid cells failed; restored.
Mutation-verified: AC-2 — deleted the isDirectory directory-collision guard in computeTemplateChanges; the directory cells for settings, skill, constitution, scriptsCopy and scriptsLink failed; restored.
Mutation-verified: AC-3 — restored the bare fsWriteFile in src/lib/fs.ts:writeFile; all 4 named foreign-symlink cases failed on the foreign file's bytes; restored.

Test results

  • npx vitest run src/lib/__tests__/writer-state-matrix.test.ts — 649 passed (645 grid/decision cells + 4 new named cases), first run, no grid cell re-derived after observation.

  • npm run build ✅ · npm run lint ✅ (0 errors, 0 warnings)

  • npm test (full suite, run as 3 foreground shards to stay under the 600s tool cap — npx vitest run --project unit --project integration --shard=N/3):

    Shard Test files Tests Result
    1/3 113 passed 3304 passed, 1 expected fail, 1 skipped ✅
    2/3 112 passed 2169 passed, 2 skipped ✅
    3/3 112 passed 2920 passed ✅
    Total 337 passed 8393 passed, 1 expected fail, 3 skipped ✅ 0 failures

    No red tests inside or outside the diff, so there is no "pre-existing failure" claim to settle against base.

  • CI on this head: test ✅, canary ✅, typecheck ✅, validate-skills ✅, validate-plugin ✅, node-floor-guard ✅, structural ✅, tautology-advisory ✅.

Test coverage

Changed file Tier Tests
src/lib/fs.ts Critical (every writer) ✅ src/lib/fs.test.ts — 10 new cases for writeFile/isDirectory/directoryCollisionMessage
src/lib/templates.ts Critical ✅ writer-state-matrix.test.ts (all 6 writers × 7 states), src/lib/templates.test.ts
src/commands/sync.ts Standard ✅ writer-state-matrix.test.ts, src/commands/sync.test.ts
src/commands/update.ts Standard ✅ writer-state-matrix.test.ts, src/commands/update.test.ts
src/commands/init.ts Standard ✅ writer-state-matrix.test.ts, src/commands/init.test.ts
src/lib/settings.ts Standard ✅ writer-state-matrix.test.ts (sequantSettings rows)

docs/troubleshooting.md gains an entry under Update Issues for the new skip message, since it is a user-facing string with a prescribed action.

src/commands/init.test.ts and src/commands/sync.test.ts now spread the real fs.js through importOriginal instead of listing four exports, so an export added to fs.ts later cannot silently break every case in those files (it broke 52 of them here).

Closes #1122

(#1124 was folded into #1122 and is already closed; its directory-crashes-writer cells are the 32 fixed here.)

🤖 Generated with Claude Code

…ate destination

writeFile now unlinks an existing symlink before writing, so init/sync/update no longer overwrite what a link points at (#1053 class, all destinations). Every writer skips a directory at a destination with a named message instead of aborting on EISDIR/EEXIST; computeTemplateChanges reports it as directory-collision so both dry-runs preview it. Re-pins the writer-state matrix and empties KNOWN_DEFECTS.

Entire-Checkpoint: d9eef630c0aa
@admarble
admarble merged commit 104f324 into main Sep 25, 2026
9 checks passed
@admarble
admarble deleted the feature/1122-fix-writers-update-init-sync-write-through-an-exis branch September 25, 2026 12:31
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.

fix(writers): update/init/sync write through an existing symlink at a sequant-owned destination (#1053 class)

1 participant