Repository navigation
Description
Blocked by: #1053, #1106 Tier: mechanical Doc: guard plan 2026-09-18 (16-bug classification)
Why
Four of the recent sync/init bugs share one test gap: the writer was tested from a single starting state. #1053's copy mode was tested from an empty scripts/dev, so "foreign symlink present" was never exercised. #1071's init was tested on a fresh repo, never on an initialized one. #1078's sync was tested against an unmodified .claude/settings.json. #1030's template walk was never tested against a destination that a different writer owns. The ownership rule in #1090 decides what each writer should do per state; this issue makes every writer prove it does that for every state.
Change
src/lib/__tests__/writer-state-matrix.test.ts: a table-driven suite over
- writers:
init,init --agent <x>on an initialized repo,sync,sync --dry-run,update, each with and without--force - destination states: absent · sequant-owned file (byte-identical to template) · user-modified file · file with the sequant marker and a changed body · local symlink (
node_modules/sequant/...) · foreign symlink (~/.npm/_npx/...or a sibling checkout) · directory in the file's place - one representative destination per ownership policy as landed by fix(sync/init/update): one ownership rule for project files — the clobbering class fixed file-by-file in #708/#814/#990/#1042/#1071/#1078 #1090 in
src/lib/templates.tsOWNERSHIP_RULES:sequant-owned→.claude/settings.jsonand.claude/skills/<x>/SKILL.md;user-owned→.claude/memory/constitution.md,.sequant/settings.json,AGENTS.md;merge→.mcp.json,.gitignore; plusscripts/dev/<x>.sh(symlink/copy route). Read the table fromorigin/main; the matrix asserts the landed policies, not the pre-fix(sync/init/update): one ownership rule for project files — the clobbering class fixed file-by-file in #708/#814/#990/#1042/#1071/#1078 #1090 draft.
Each cell asserts the post-state (content, symlink-ness, target), the printed decision (overwrite / preserved / merged / replaced), and that --dry-run's listed decision equals what the apply run did. Real filesystem in a temp dir, no mocks of fs.
Release-graph plan — guard-2026-09 (2026-09-20)
Graph: guard-2026-09 Tier: mechanical Wave: 2
May touch: src/lib/__tests__/writer-state-matrix.test.ts (new); read-only on src/lib/templates.ts, src/commands/init.ts, src/commands/sync.ts, src/commands/update.ts; CHANGELOG.md
- Blocked by: fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053
- Blocked by: test(ownership-gate): register writeFile sites individually — per-function keying, await-only match and arrow-const writers let a new destination through (#1090 follow-up) #1106
The npm run build && npm test AC is verified by the runner from a clean shell after the PR opens (PLAN I-1); the agent runs only the test files its ACs name. Mutation markers use failedTest starting with the test file path (I-4). Real filesystem in a temp dir, no fs mocks (I-6). AC-3 depends on #1053's fix; AC-1 uses the per-site gate from #1106 to enumerate writers. A cell that finds a writer doing the wrong thing is a new bug issue, not a scope expansion here.
Acceptance criteria
- AC-1: the matrix covers every (writer × state × policy) cell with no
todoorskip— Verify:npx vitest run src/lib/__tests__/writer-state-matrix.test.ts→ green andgrep -c "it.todo\|it.skip" src/lib/__tests__/writer-state-matrix.test.ts→ 0. - AC-2:
--dry-runand apply agree in every cell — Verify:-t "dry-run matches apply"→ green. Mutation-verified per CLAUDE.md §Testing: make dry-run list amergefile asoverwrite→ the cell fails; restore. - AC-3: the fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053 cell (copy mode, foreign symlink present) ends as a regular file with template content — Verify:
-t "foreign symlink"→ green. - AC-4: the bug(init): init --agent <name> on an initialized repo overwrites .sequant/settings.json with defaults #1071 cell (
init --agent codexon an initialized repo with a tuned.sequant/settings.json) preserves every tuned key and sets onlyrun.agent— Verify:-t "init on initialized"→ green. - AC-5: the sync overwrites .claude/settings.json wholesale, deleting project-owned hook matcher groups #1078 cell under the fix(sync/init/update): one ownership rule for project files — the clobbering class fixed file-by-file in #708/#814/#990/#1042/#1071/#1078 #1090 D-1 decision: the project's own
PreToolUsehook lives in.claude/settings.local.jsonand survivessyncandupdatebyte-for-byte;.claude/settings.json(sequant-owned) is overwritten with the template andsync --dry-runlists it asoverwrite— Verify:-t "settings.local.json survives"→ green. Mutation-verified per CLAUDE.md §Testing: makesyncalso writesettings.local.json→ the cell fails; restore. - AC-6:
npm run build && npm testgreen.
Not in scope
The ownership policy itself (#1090). If #1090 lands a different decision for a cell, the cell's expected value changes; the matrix does not.
Activity
admarble commentedon Sep 20, 2026
Runner context — guard-2026-09 wave 2 launch, 2026-09-20. Base:
origin/mainatbef0ac98(all seven wave-1 PRs merged: #1086 scrub, #1104 marker docs, #1053, #1106 ownership gate, #1095 parsers, #1096 conformance suite, #1070 failing verdicts post). These rules override the exec AND qa skills' defaults for this run:npm testin the worktree — this applies to the qa phase too. Under concurrent phase agents that one call exceeds the 30-minute no-progress wall and the phase is killed (three wave-1 phases died this way). Verify each AC by its own command; run only the test files the ACs name. The runner runs the full suite once per PR from a clean shell and records it on the PR.<!-- SEQUANT_MUTATION: {"ac":"AC-N","mutation":"<what you deleted>","failedTest":"<test file path> > <describe> > <case>"} -->in the PR body.failedTestMUST start with the test file path. RunparseMutationMarkerson your body before opening the PR. Commit before mutating.timeout.git commit -m "...", noCo-Authored-By. Push the branch and open the PR yourself (one wave-1 exec forgot). Never rebase or force-push after pushing. One AC per line in the PR body, idsAC-Nonly.Issue-specific: New file only (
src/lib/__tests__/writer-state-matrix.test.ts); the writers are read-only. Real filesystem in a temp dir, nofsmocks. Never create or remove anything under the real repo (process.cwd()); a wave-1 fixture did and was fixed. AC-3 asserts #1053's behavior by the merged code; AC-1 enumerates writers via the per-site gate from #1106 (src/lib/ownership-gate.ts).admarble commentedon Sep 20, 2026
Complexity: Standard (6 ACs, 1 directory)
AC Quality Check
Warnings only. All six ACs are single-line and carry a
Verify:command.syncnever touches.gitignore;inithas no--dry-run). The plan defines the cell set explicitly (Open Question 1).-t "<phrase>". vitest-tis a substring match, so test titles must contain exactly these phrases.-t "foreign symlink"also matches every other foreign-symlink cell, and all of them must be green.npm run build && npm testis run by the runner from a clean shell after the PR opens (runner context comment). The agent runs only this file.Scope Assessment
Non-Goals: "Not in scope": the ownership policy itself (#1090). A cell that finds a writer misbehaving becomes a new bug issue, not a fix here. The writers are read-only.
src/lib/__tests__/)Verdict: ✅ SCOPE_OK
Acceptance Criteria
AC-1: matrix covers every cell, no
todo/skipVerification: Unit Test (real filesystem, temp dir).
vitest rungreen andgrep -c "it.todo\|it.skip"→ 0.Scenario: Given the writer × state × destination table → When vitest runs → Then every cell is a real
itand none is skipped.Assumptions: Cell set is defined per Open Question 1. #1090/#1106 are merged on
origin/main(OWNERSHIP_RULESandownership-gate.tsare present).AC-2: dry-run and apply agree in every cell
Verification: Unit Test,
-t "dry-run matches apply", plus a recorded mutation.Scenario: Given each cell → When
sync --dry-runandupdate --dry-runrun, then the apply run → Then the printed decision line (overwrite/preserved/merged) for that path is equal.Mutation: in
resolveOwnershipDecisions(src/commands/sync.ts), change the.mcp.jsonmergedpush tooverwrite. The.mcp.jsondry-run cell must fail. Commit first, restore after.AC-3: #1053 cell, copy mode + foreign symlink → regular file with template content
Verification: Unit Test,
-t "foreign symlink".Scenario: Given
scripts/dev/<x>.shis a symlink into a directory outside the project → Wheninit/sync/updaterun → Thenlstatsays regular file and the bytes equal the template.Assumptions: Templates resolved from the sequant checkout are outside the temp project, so
resolveScriptsSymlinkTargetpicks copy mode. The local-symlink cell needs anode_modules/sequant/templates/scriptsfixture to reach symlink mode.AC-4: #1071 cell,
init --agent codexon an initialized repoVerification: Unit Test,
-t "init on initialized".Scenario: Given
.sequant/settings.jsonwith tuned non-default keys → Wheninit --agent codex→ Then a deep diff shows onlyrun.agentchanged.AC-5: #1078 cell,
settings.local.jsonsurvives,settings.jsonoverwrittenVerification: Unit Test,
-t "settings.local.json survives", plus a recorded mutation.Scenario: Given a project
PreToolUsehook in.claude/settings.local.jsonand a hand-edited.claude/settings.json→ Whensyncandupdaterun → Thensettings.local.jsonis byte-identical,settings.jsonequals the template, andsync --dry-runlists.claude/settings.jsonasoverwrite.Mutation: make
syncalso writesettings.local.json; the cell must fail. Commit first, restore after.AC-6:
npm run build && npm testgreenVerification: runner-verified (see AC Quality Check).
Implementation Plan
Phase 1: Spike (gates the rest)
sync× user-modified ×AGENTS.md). Usemkdtempandprocess.chdir(tmp)inbeforeEach, restore inafterEach. Assertprocess.cwd() !== repoRootbefore every writer call. Never spyprocess.cwd;sync.test.ts:55shows what an unmocked cwd does to the real repo. Time it: the file has no.integration.in its name, so it runs in theunitproject on the 5 s default timeout (fix(test): tsx-spawning integration tests blow vitest's 5s default — phase-registry should use the prebuilt dist like its five siblings #842). Set an explicit per-test ordescribetimeout if a cell takes more than about 1 s; do not rename the file, the ACVerify:commands name this path.init(interactiveinquirerprompts atinit.ts:690-1362) andupdate(package-manager and version preflight,update.ts:95) run non-interactively. Preferforce/yesandSEQUANT_TEMPLATES_DIR; mockinginquireris acceptable (the "no mocks" rule is aboutfs).Phase 2: State table and writers
it.each) over 7 states (absent, byte-identical, user-modified, marker + changed body, local symlink, foreign symlink, directory) × the destinations: sequant-owned =.claude/settings.json,.claude/skills/<x>/SKILL.md; user-owned = constitution,.sequant/settings.json,AGENTS.md; merge =.mcp.json,.gitignore; plusscripts/dev/<x>.sh. Read policies viaownershipPolicy()so the expected value comes from the landed table.lstatsymlink-ness, target) and the printed decision by capturingconsole.log. Match the<verb>: <path>line, not chalk colours.Phase 3: dry-run parity and named cells
dry-run matches applycells forsyncandupdate.inithas no dry-run, so it is not in that set.-tphrase.Phase 4: Evidence
<!-- SEQUANT_MUTATION: {"ac":"AC-2","mutation":"...","failedTest":"src/lib/__tests__/writer-state-matrix.test.ts > <describe> > <case>"} -->in the PR body.failedTestmust start with the file path. Add aCHANGELOG.mdline.Design Review
src/lib/__tests__/. The issue fixes the path. Writers are read-only.initCommand/syncCommand/updateCommandin-process on a temp cwd (the pattern inupdate.integration.test.ts). Rejected: spawning the CLI per cell (about 10x slower, no need); mockingfs(forbidden by the issue).templates.test.ts"ownership policy covers…" for reading the policy table;update.integration.test.tsfor the chdir + temp templates dir setup.ownershipPolicy(). Then the matrix cannot restate the table and always agree with it.Feature Quality Planning
EISDIR). Assert the observed behaviour. If it is a bug, file an issue and keep the test as the documented current behaviour; do not fix it here.isNativeWindows()the way the source does.Open Questions
itasserting the destination is byte-identical after the run. That keeps AC-1's "no todo/skip" literal and avoids empty cells. Impact if wrong: the count and the reviewer's expectations differ..claude/settings.jsonand one skill, so the assertion is "equals the template" for real. UseSEQUANT_TEMPLATES_DIRonly if the spike shows the timing is unworkable.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: The deliverable is a test file, so
testgenwould stub the thing being built. No UI. Two gate ACs (2 and 5) need mutation records, which/qa§6i parses. Runner rules apply: run only this file, commit before mutating, stop at the PR.Label Review
Current: enhancement, cli
Recommended: enhancement, cli (add
planned)Reason: no change to the type or area.
Quality Loop: won't auto-enable (SCOPE_OK).
admarble commentedon Sep 20, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 0/4 met
Gaps:
src/lib/__tests__/writer-state-matrix.test.ts:942—it("every tracked defect names an open issue")asserts onlyexpect(v.issue).toMatch(/^#\d+$/). It never checks the issue exists, and never checks it is open, despite the name. The assertion passes for#0or#999999. (I verified manually that fix(writers): update/init/sync write through an existing symlink at a sequant-owned destination (#1053 class) #1122/fix(init): --yes init replaces a user-modified AGENTS.md and an unparseable .mcp.json that sync would preserve #1123/fix(writers): a directory at a template destination crashes every writer with a raw EISDIR, dry-runs included #1124 are all genuinely OPEN, so the claim holds today — but the test does not gate it.)matrix shapetest pins the policy of the 9 chosen destinations but never asserts those 9 exhaustOWNERSHIP_RULES.src/lib/templates.tshas 10 rules onorigin/main; four have no matrix representative:.opencode/opencode.json(merge, exact),.opencode/(sequant-owned, prefix),.codex/(sequant-owned, prefix),.sequant/settings.reference.md(sequant-owned). Nothing fails when a new rule lands, so the matrix can go stale silently. The first of those is notable on its own:.opencode/opencode.jsonis amergeexact-match nested inside the.opencode/sequant-ownedprefix — a precedence-sensitive pair, exactly the kind of cell this matrix exists to pin.Suggestions:
expect(new Set(DESTS.map(d => d.path))).toEqual(…)or an assertion that everyOWNERSHIP_RULESentry has ≥1 representative destination (or an explicit documented exclusion list), so a new writer destination cannot land uncovered.names a well-formed issue reference) or make it check openness via a static allowlist.Vletter (replaced, but the symlink's old target was modified on the way) is documented in the header and implemented inclassify(), but occurs in 0 grid cells. Harmless, worth a one-word note that it is a tripwire-only code.test(#1097): writer state-matrix — init/sync/update × every destinati…