Skip to content

fix(#1159): diff scripts/dev against the install target, not the running bundle - #1161

Merged
admarble merged 6 commits into
mainfrom
feature/1159-fix-sync-scripts-dev-never-converges-when-node-mod
Sep 25, 2026
Merged

admarble merged 6 commits into
mainfrom
feature/1159-fix-sync-scripts-dev-never-converges-when-node-mod

Conversation

@admarble

@admarble admarble commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

computeTemplateChanges diffed every destination against the running CLI's bundled template — including scripts/dev/*.sh, which copyTemplates does not install from the bundle. Since #991 the writers link (or copy) scripts/dev from resolveScriptsSymlinkTarget().scriptsDir, which prefers <project>/node_modules/sequant/templates/scripts. With an older sequant installed there, the diff and the apply read different files and never agreed:

  • every sync exited 1 with Version current, but N file(s) differ from bundled content, and sync --force could not clear it;
  • sync --dry-run printed overwrite: scripts/dev/<name>.sh for a write the apply never made.

It stayed invisible because templates/scripts/*.sh had not changed since 2.16.0. #1145 / PR #1156 is the first PR to change one, and it turns the required canary check red.

Per the owner decision on the issue (option 1), the #991 targeting is untouched. Only the comparison moves: scripts/dev is now diffed against the target it is actually installed from.

  • symlink mode — compare the link target string symlinkDir would write. Content cannot tell a correct link from a stale one (a link into an evicted npx cache resolves to identical bytes, fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053), and symlinkDir relinks any target that differs, so the target string is the only signal that keeps preview and apply in step.
  • copy mode (Windows / --no-symlinks / an unlinkable target) — compare the target file's bytes, rendered with the project's variables.
  • a script only the newer bundle ships — neither writer walks the bundle's file list, so it is never written; reporting it would be drift no sync --force could clear either.

One edit fixes all four consumers of the count: sync's version-current fast path, sync --dry-run, checkAndWarnSkillsOutdated and getSkillsInstallStatus. resolveScriptsSymlinkTarget, copyTemplates, previewScriptsSymlinkTargets, sync.ts and version-preflight.ts are unchanged.

One deliberate departure from the plan

The spec's step 3 said to drop processTemplate on the scripts/dev branch because "neither symlinkDir nor copyDir renders scripts". That holds for symlinkDir, but copyDir does render every file it copies (templates.ts, inside the file branch), scripts included. Following the letter would have re-created this exact non-converging loop the moment a .sh template grew a {{TOKEN}}: the apply would write rendered bytes while the diff compared raw ones. So the symlink arm does not render (it compares link targets, not content) and the copy arm does — each matching its writer. The spec's underlying concern is satisfied; only its premise about copyDir was inaccurate.

AC verification

AC Source Description Status Evidence
AC-1 Original a second sync exits 0 with no differ from bundled content line ✅ Implemented canary A/B below — 4 passed with the fix, 2 failed without
AC-2 Original sync --dry-run lists scripts/dev/<name>.sh only when the apply changes it ✅ Implemented canary dry-run equals apply passes; it failed on the same tree without the fix
AC-3 Original resolveScriptsSymlinkTarget still prefers node_modules/sequant/templates/scripts ✅ Implemented function untouched (git diff shows no edit); asserted on disk by the new converges: case
AC-4 Derived a permanent test reproduces the skew without the registry ✅ Implemented src/lib/templates.test.ts, converges: and does not report a bundled script the installed copy lacks
AC-5 Derived a scripts/dev symlink pointing anywhere else is still reported as drift ✅ Implemented src/lib/templates.test.ts, still reports a link pointing anywhere else as modified
AC-6 Derived (runner, from QA round 1) update converges on a symlink-mode scripts/dev entry: a second run reports nothing to do ✅ Implemented src/commands/update.integration.test.ts 1159: case; writer matrix re-pinned (update columns T→= on the link route)

Canary A/B (AC-1, AC-2)

Both runs in this worktree, same machine, minutes apart. #1156 (f2f9dbf4) merged in each time, since it is the branch that changes a script template.

Before — origin/main + #1156, npx vitest run --project canary:

Tests  2 failed | 2 passed (4)

with sync printing, verbatim:

!  Version current, but 1 file(s) differ from bundled content

dry-run equals apply failed on scripts/dev/new-feature.sh being predicted but not changed; customizations survive sync, init --agent codex --yes and update failed on that exit 1.

After — this branch + #1156, same command:

Tests  4 passed (4)

Mutation record

Each mutation applied alone, on a clean tree, then reverted. Named test ran via npx vitest run src/lib/templates.test.ts.

AC Mutation Result
AC-3 deleted the node_modules/sequant/templates/scripts preference from resolveScriptsSymlinkTarget 5 failed — the new converges: case plus the three existing #990 cases
AC-4 pointed SCRIPTS_TEMPLATE_PREFIX at a prefix no template matches, so scripts/dev fell back to the bundle diff 4 failed — exactly the four new cases, no others
AC-5 dropped the link-target comparison, so any symlink at the destination counted as unchanged 1 failed — exactly the AC-5 case
AC-6 made update's linkTarget filter a no-op (… || true) 1 failed — exactly the 1159: update case (npx vitest run src/commands/update.integration.test.ts)

Two further arms were mutation-checked the same way, each failing exactly one case: returning new instead of unchanged when the install target lacks the script (does not report a bundled script the installed copy lacks), and deleting the copy-mode symlink arm (reports a symlink as modified in copy mode).

Mutation-verified: AC-6 — made update.ts's linkTarget filter a no-op; src/commands/update.integration.test.ts 1159 case failed (1 failed | 7 passed); restored.

Runner fixes after QA round 1 (AC_NOT_MET)

QA found that the shared computeTemplateChanges change made sequant update loop. update wrote scripts/dev as a regular file, and the symlink-mode comparison never classifies a regular file as unchanged, so every run reported Updated 1 files. Fixed in c8c3732a and b3777a63:

  • Symlink-mode scripts/dev entries carry linkTarget, including new ones, and update drops them. This matches its own dry-run note ("update does not manage … scripts/dev link targets"). Copy mode is unchanged.
  • The comment that implied symlinkDir unconditionally replaces a regular file is corrected: that holds only under force, which sync passes.
  • The writer matrix is re-pinned: update/update --force on the link route go from T to =, and their printed decision from o to -.
  • Real-project probe ([email protected] + init, bundled new-feature.sh changed): update --yes twice → Modified: 6, then Modified: 0. sync twice → exit 0 both times, no differ lines. The link still points into node_modules/sequant.

Test plan

  • npx vitest run src/lib/templates.test.ts — 68 passed (64 before, 4 new)
  • npx vitest run --project canary on a scratch merge with fix(#1145): new-feature.sh derives the branch name with the slugify() rule #1156 — 4 passed (2 failed | 2 passed without the fix)
  • npm run build, npm run lint — clean
  • npm test — 337 files, 8397 passed | 1 expected fail | 3 skipped, 0 failures (564s). No pre-existing failures to settle.

Closes #1159

🤖 Generated with Claude Code

…ing bundle

computeTemplateChanges walked the running CLI's bundle for every destination, but copyTemplates installs scripts/dev from resolveScriptsSymlinkTarget() — node_modules/sequant/templates/scripts when a real install is there (#991). With an older sequant installed the two never agreed: sync exited 1 with 'N file(s) differ from bundled content' on every run and --dry-run predicted an overwrite the apply never made.

Entire-Checkpoint: d2262d667299
@admarble
admarble merged commit 702105b into main Sep 25, 2026
7 checks passed
@admarble
admarble deleted the feature/1159-fix-sync-scripts-dev-never-converges-when-node-mod branch September 25, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant