You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(mcp-config): .mcp.json writes still follow an existing symlink (#1122 follow-up) #1160
#1122 (PR #1157) routes template writers through a writeFile that replaces an existing symlink instead of following it. src/lib/mcp-config.ts:243,356,471 still write .mcp.json with fs.writeFileSync directly, so a .mcp.json symlink is still written through to its target. This is the same data-loss class as #1053 and #1122, and PR #1157's QA flagged it (risk_gap). #1122 scoped it out deliberately, and no issue tracked it.
Tier: mechanical
AC-1: no writer writes through a .mcp.json symlink. The matrix pins it today: mcpJsonlocalSymlink/foreignSymlink are M for init, init --yes via the before.target === after.target arm of classify (the link survives and its target is merged into). The fix re-pins those cells to a replaced-link letter, with the target byte-identical — Evidence: npx vitest run src/lib/__tests__/writer-state-matrix.test.ts green with the re-pinned mcpJson rows
AC-2: a named case writes .mcp.json as a symlink to a file outside the project, runs the writer, and asserts the outside file's bytes are unchanged — Evidence: npx vitest run src/lib/mcp-config.test.ts -t "1160" passes, mutation-verified per AC-3
AC-3: AC-2's case is mutation-verified: restoring a direct fs.writeFileSync at the config write fails exactly that case — Evidence: SEQUANT_MUTATION marker for AC-2 in the PR body, with failedTest starting src/lib/mcp-config.test.ts >
AC-4: mcp-config.ts no longer writes the config with fs.writeFileSync (the three sites at :243, :356, :471 on 2026-09-25) — Evidence: grep -n "fs.writeFileSync" src/lib/mcp-config.ts prints nothing
Non-Goals
Other merged-policy destinations (.gitignore, .claude/settings.json merges): this issue fixes .mcp.json only. If the matrix shows the same M-through-a-link shape elsewhere, file it separately.
Changing the merge semantics of .mcp.json (which entries are kept or re-pinned). Only the write path changes.
AC-1 re-pins the mcpJsonlocalSymlink/foreignSymlink rows of src/lib/__tests__/writer-state-matrix.test.ts. Today they're M via the same-target-link arm of classify, which is write-through. After the fix, the link should be replaced and its target byte-identical. Use the writeFile symlink guard fix(writers): update/init/sync write through an existing symlink at a sequant-owned destination (#1053 class) #1122 added in src/lib/fs.ts rather than a second mechanism.
qa phase: don't run the full npm test. Run the named test files only; the runner runs the suite once. exec phase: commit WIP before any long command, run the suite at most once in the foreground with a timeout, and never run_in_background.
All four ACs are single-line, carry Evidence:, and are measurable. Notes:
AC-3's failedTest must start with the file path src/lib/mcp-config.test.ts >, per the runner context.
AC-1 says "a replaced-link letter" without naming it. The plan pins T: the link is replaced by a regular file, and classify maps that to T only if the bytes equal the owned template. A merged .mcp.json is not template bytes, so it may classify as M (after.kind === "file", dest.merged). Exec should read the actual classify result and pin whatever it reports, provided the link is gone and the target is byte-identical (no V, no W).
Verification: Integration Test (writer-state-matrix.test.ts) Scenario: Given .mcp.json is a local or foreign symlink → When init / init --yes run → Then the link is replaced by a regular file and the target is byte-identical; the mcpJsonlocalSymlink/foreignSymlink cells stop being link-preserving. Assumptions: the exact letter follows classify output (see above). Only the two mcpJson rows change. The gitignore rows at ~line 342 are also M M and are out of scope per Non-Goals.
AC-2: Named 1160 case
Verification: Unit Test (src/lib/mcp-config.test.ts, test title contains 1160) Scenario: Given .mcp.json is a symlink to a file outside the project → When createProjectMcpJson and syncSequantMcpPin run → Then the outside file's bytes are unchanged and .mcp.json is a regular file.
AC-3: Mutation verification
Verification: Manual (recorded in PR body) Scenario: Restore a direct fs.writeFileSync at the config write → only AC-2's case fails → restore. Record the SEQUANT_MUTATION marker with failedTest = src/lib/mcp-config.test.ts > <describe> > <case>. Commit before mutating.
AC-4: No fs.writeFileSync in mcp-config.ts
Verification: Unit Test / grep (grep -n "fs.writeFileSync" src/lib/mcp-config.ts prints nothing)
Implementation Plan
Phase 1: Sync-safe symlink-aware write
writeFile in src/lib/fs.ts is async, but addSequantToMcpConfig (:243), createProjectMcpJson (:356) and syncSequantMcpPin (:471) are sync, with callers in commands/init.ts:1192,1251, update.ts:184 and sync.ts:436. Add writeFileSync to fs.ts beside writeFile, with the same rule: lstatSync for a symlink, unlinkSync it, then write. Route the async writeFile and the new sync one through one small shared predicate so the rule lives in one place (this is the fix(writers): update/init/sync write through an existing symlink at a sequant-owned destination (#1053 class) #1122 "rule lives here" intent).
Replace the three fs.writeFileSync calls in mcp-config.ts with the new helper. Keep mkdir behaviour: addSequantToMcpConfig may write to a client config path whose parent may not exist. Check that the current code creates the dir before writing, and have the helper mkdirSync recursive only if the existing code does.
Phase 2: Tests (parallel-safe after Phase 1)
Add the 1160 case(s) to src/lib/mcp-config.test.ts: symlink to an outside temp file, run the writer, assert the outside bytes are unchanged and .mcp.json is no longer a link.
Re-pin the mcpJsonlocalSymlink/foreignSymlink rows in writer-state-matrix.test.ts. Run it first to see the new classify letters, then pin them. Add a unit test for the sync helper in the fs tests.
Mutation-verify AC-2 (commit first), record the marker.
Simplest correct approach? Add a sync twin. Rejected: making the three functions async, which ripples into init/update/sync and their tests for no gain. Also rejected: a local lstat/unlink inline in mcp-config.ts, which is the second mechanism the runner context forbids.
Senior reviewer challenge? "Why not async?" (see above). "Line 243 is a client config, not .mcp.json." AC-4 covers it, and replacing a symlink at e.g. ~/.claude.json is a behaviour change for dotfile-managed users. Flagged as an open question.
Feature Quality Planning
All standard checks pass. Notable items:
Sibling scan: fs.ts async writeFile and mcp-config.ts are the only writers of this class in scope. .gitignore and settings.json are excluded by Non-Goals. No sibling fs.writeFileSync sites elsewhere in mcp-config.ts beyond the three.
Rule Touchpoints: no AC triggers the behaviour-rule heuristic, so the section is omitted.
No dependencies or in-flight overlap were detected in the issue. I did not run the worktree diff scan.
Open Questions
Should addSequantToMcpConfig (:243, user-level client configs) also replace a symlink? Recommendation: yes. AC-4 requires it, and a link to a dotfiles repo gets its target rewritten today. Impact if wrong: a dotfiles-managed user's link becomes a plain file and the dotfiles copy stops updating. Consider a note in the CHANGELOG line.
Recommended Workflow
Phases: exec → qa Quality Loop: disabled Reasoning: AC-1 and AC-2 declare npx vitest run evidence (unit/integration), so testgen could apply, but they are small and mechanical, so stubs add nothing. Tier is mechanical with 4 ACs.
AC-1's declared evidence (the writer-state matrix) does not gate the fix — the matrix passes with the fix fully reverted, so the mcpJson symlink cells pin nothing about replaced-link vs write-through.
A dotfiles-managed client MCP config that is a symlink is silently converted to a regular file with no runtime notice; the behavior change is recorded only in the CHANGELOG.
The writer-state matrix no longer gates this fix (verified empirically). I reverted the three writeFileSync calls back to fs.writeFileSync and re-ran npx vitest run src/lib/__tests__/writer-state-matrix.test.ts: 649/649 passed. The mcpJson symlink rows read M M = = = = whether the writer replaces the link or writes through it, because classify returns M from two different arms — the file arm (mcp-config.ts:698-707) and the write-through symlink arm (:726-731). The diff added a comment asserting the M now comes from the file arm, but nothing tests that claim. By CLAUDE.md's own standing rule ("delete the thing it asserts, confirm exactly that test fails"), AC-1's declared evidence does not count as coverage for AC-1's claim. The fix is still protected — by AC-2's test, which does fail under the same mutation — but the matrix's header prose ("a regression that reintroduces either fails the invariant test rather than quietly re-pinning itself") is false for this cell.
Related, broader: W (write-through) only fires when after.bytes === owned, so a write-through at any merge destination collapses to M. The W regression guard has never covered merge destinations. Out of scope per Non-Goals, but the letter fix would incidentally close it.
Suggestions:
Add a distinct legend letter for "symlink replaced, merged content, target intact" in the file arm of classify (when before.kind === "symlink"), re-pin the two mcpJson rows to it, and update the invariant counts. That is what AC-1 asked for and it makes the mutation fail. This touches a shared matrix file's legend, so it is worth a deliberate decision rather than an unattended loop fix.
Runner verification (PR #1168): QA returned AC_MET_BUT_NOT_A_PLUS. Its fix-now gap was that AC-1's matrix evidence passed with the fix reverted. Fixed in 0addb27e: a merge written through a link now classifies as W, and reverting the fix fails exactly the four .mcp.json symlink cells. The mutation record is in the PR body. CI at 0addb27e is green (test, canary). The remaining QA notes (the symlink-to-file conversion is silent at runtime; W coverage for other merge destinations) are documented and not changed here.
Activity
docs(#1159): graph w3 — #1145 blocked by #1159 not #1122; #1160 filed
docs(#1153): graph 2026-09-w3 plan for #1145, #1153, #1122 and #1141 (#…
admarble commentedon Sep 25, 2026
Runner context (2026-09-25): these rules apply to the spec, exec AND qa phases.
Evidence:(docs(skills): /spec states the AC format inline; /verify shows output before asking; /exec scopes formatting and staging #1165). AC-2 is a gate test, so the PR body must carry<!-- SEQUANT_MUTATION: {...} -->withfailedTeststarting withsrc/lib/mcp-config.test.ts > …, plus theMutation-verified:line.mcpJsonlocalSymlink/foreignSymlinkrows ofsrc/lib/__tests__/writer-state-matrix.test.ts. Today they'reMvia the same-target-link arm ofclassify, which is write-through. After the fix, the link should be replaced and its target byte-identical. Use thewriteFilesymlink guard fix(writers): update/init/sync write through an existing symlink at a sequant-owned destination (#1053 class) #1122 added insrc/lib/fs.tsrather than a second mechanism.npm test. Run the named test files only; the runner runs the suite once. exec phase: commit WIP before any long command, run the suite at most once in the foreground with atimeout, and neverrun_in_background.[Unreleased]line. Stop at the PR.admarble commentedon Sep 25, 2026
Complexity: Standard (4 ACs, 3 directories)
AC Quality Check
All four ACs are single-line, carry
Evidence:, and are measurable. Notes:failedTestmust start with the file pathsrc/lib/mcp-config.test.ts >, per the runner context.T: the link is replaced by a regular file, andclassifymaps that toTonly if the bytes equal the owned template. A merged.mcp.jsonis not template bytes, so it may classify asM(after.kind === "file",dest.merged). Exec should read the actualclassifyresult and pin whatever it reports, provided the link is gone and the target is byte-identical (noV, noW).Scope Assessment
Non-Goals: present (other merged-policy destinations, merge semantics, directory-at-destination).
src/lib,src/lib/__tests__, CHANGELOG)Verdict: ✅ SCOPE_OK
Acceptance Criteria
AC-1: Matrix re-pinned
Verification: Integration Test (
writer-state-matrix.test.ts)Scenario: Given
.mcp.jsonis a local or foreign symlink → Wheninit/init --yesrun → Then the link is replaced by a regular file and the target is byte-identical; themcpJsonlocalSymlink/foreignSymlinkcells stop being link-preserving.Assumptions: the exact letter follows
classifyoutput (see above). Only the twomcpJsonrows change. Thegitignorerows at ~line 342 are alsoM Mand are out of scope per Non-Goals.AC-2: Named 1160 case
Verification: Unit Test (
src/lib/mcp-config.test.ts, test title contains1160)Scenario: Given
.mcp.jsonis a symlink to a file outside the project → WhencreateProjectMcpJsonandsyncSequantMcpPinrun → Then the outside file's bytes are unchanged and.mcp.jsonis a regular file.AC-3: Mutation verification
Verification: Manual (recorded in PR body)
Scenario: Restore a direct
fs.writeFileSyncat the config write → only AC-2's case fails → restore. Record theSEQUANT_MUTATIONmarker withfailedTest=src/lib/mcp-config.test.ts > <describe> > <case>. Commit before mutating.AC-4: No
fs.writeFileSyncin mcp-config.tsVerification: Unit Test / grep (
grep -n "fs.writeFileSync" src/lib/mcp-config.tsprints nothing)Implementation Plan
Phase 1: Sync-safe symlink-aware write
writeFileinsrc/lib/fs.tsis async, butaddSequantToMcpConfig(:243),createProjectMcpJson(:356) andsyncSequantMcpPin(:471) are sync, with callers incommands/init.ts:1192,1251,update.ts:184andsync.ts:436. AddwriteFileSynctofs.tsbesidewriteFile, with the same rule:lstatSyncfor a symlink,unlinkSyncit, then write. Route the asyncwriteFileand the new sync one through one small shared predicate so the rule lives in one place (this is the fix(writers): update/init/sync write through an existing symlink at a sequant-owned destination (#1053 class) #1122 "rule lives here" intent).fs.writeFileSynccalls inmcp-config.tswith the new helper. Keepmkdirbehaviour:addSequantToMcpConfigmay write to a client config path whose parent may not exist. Check that the current code creates the dir before writing, and have the helpermkdirSyncrecursive only if the existing code does.Phase 2: Tests (parallel-safe after Phase 1)
1160case(s) tosrc/lib/mcp-config.test.ts: symlink to an outside temp file, run the writer, assert the outside bytes are unchanged and.mcp.jsonis no longer a link.mcpJsonlocalSymlink/foreignSymlinkrows inwriter-state-matrix.test.ts. Run it first to see the newclassifyletters, then pin them. Add a unit test for the sync helper in thefstests.[Unreleased]line.Design Review
src/lib/fs.ts, next to the fix(writers): update/init/sync write through an existing symlink at a sequant-owned destination (#1053 class) #1122 guard, not a second mechanism inmcp-config.ts.init/update/syncand their tests for no gain. Also rejected: a locallstat/unlinkinline inmcp-config.ts, which is the second mechanism the runner context forbids.writeFilereplace-a-link rule and fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053'scopyDir..mcp.json." AC-4 covers it, and replacing a symlink at e.g.~/.claude.jsonis a behaviour change for dotfile-managed users. Flagged as an open question.Feature Quality Planning
All standard checks pass. Notable items:
fs.tsasyncwriteFileandmcp-config.tsare the only writers of this class in scope..gitignoreandsettings.jsonare excluded by Non-Goals. No siblingfs.writeFileSyncsites elsewhere inmcp-config.tsbeyond the three.Open Questions
addSequantToMcpConfig(:243, user-level client configs) also replace a symlink? Recommendation: yes. AC-4 requires it, and a link to a dotfiles repo gets its target rewritten today. Impact if wrong: a dotfiles-managed user's link becomes a plain file and the dotfiles copy stops updating. Consider a note in the CHANGELOG line.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: AC-1 and AC-2 declare
npx vitest runevidence (unit/integration), so testgen could apply, but they are small and mechanical, so stubs add nothing. Tier is mechanical with 4 ACs.Label Review
Current: bug
Recommended: bug (no change)
Quality Loop: won't auto-enable (SCOPE_OK)
admarble commentedon Sep 25, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
Gaps:
writeFileSynccalls back tofs.writeFileSyncand re-rannpx vitest run src/lib/__tests__/writer-state-matrix.test.ts: 649/649 passed. ThemcpJsonsymlink rows readM M = = = =whether the writer replaces the link or writes through it, becauseclassifyreturnsMfrom two different arms — the file arm (mcp-config.ts:698-707) and the write-through symlink arm (:726-731). The diff added a comment asserting theMnow comes from the file arm, but nothing tests that claim. By CLAUDE.md's own standing rule ("delete the thing it asserts, confirm exactly that test fails"), AC-1's declared evidence does not count as coverage for AC-1's claim. The fix is still protected — by AC-2's test, which does fail under the same mutation — but the matrix's header prose ("a regression that reintroduces either fails the invariant test rather than quietly re-pinning itself") is false for this cell.W(write-through) only fires whenafter.bytes === owned, so a write-through at any merge destination collapses toM. TheWregression guard has never covered merge destinations. Out of scope per Non-Goals, but the letter fix would incidentally close it.Suggestions:
classify(whenbefore.kind === "symlink"), re-pin the twomcpJsonrows to it, and update the invariant counts. That is what AC-1 asked for and it makes the mutation fail. This touches a shared matrix file's legend, so it is worth a deliberate decision rather than an unattended loop fix.test(#1160): classify a merge written through a link as W, so the mcp…
admarble commentedon Sep 25, 2026
Runner verification (PR #1168): QA returned AC_MET_BUT_NOT_A_PLUS. Its fix-now gap was that AC-1's matrix evidence passed with the fix reverted. Fixed in
0addb27e: a merge written through a link now classifies asW, and reverting the fix fails exactly the four.mcp.jsonsymlink cells. The mutation record is in the PR body. CI at0addb27eis green (test,canary). The remaining QA notes (the symlink-to-file conversion is silent at runtime;Wcoverage for other merge destinations) are documented and not changed here.fix(#1160): mcp-config writes replace a .mcp.json symlink (#1168)