Skip to content

fix(sync): exclude templates/opencode from the generic diff/copy engine (#1030) - #1042

Merged
admarble merged 5 commits into
mainfrom
feature/1030-fix-sync-dry-run-lists-files-apply-never-writes-th
Sep 11, 2026
Merged

admarble merged 5 commits into
mainfrom
feature/1030-fix-sync-dry-run-lists-files-apply-never-writes-th

Conversation

@admarble

@admarble admarble commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • templateDestination() now excludes templates/opencode/** from the generic diff/copy engine (same pattern as mcp.json/relay/) — the engine never reported phantom drift on a tree it never writes.
  • init.ts exports decideOpencodeShimSync/refreshOpencodeShim; sync/update reuse them to preview (--dry-run: opencode shim: refresh) and apply the same shim refresh init --agent opencode performs, gated on an existing .opencode/ directory so neither command creates one on a project that never opted in.
  • update --dry-run now states explicitly it doesn't manage AGENTS.md/scripts/dev (stays sync-only), resolving the fix(sync): never rewrite a user-owned AGENTS.md or write a machine-specific scripts/dev symlink (absorbs #991) #990 scope-addition comment's open question with the "state explicitly" option rather than reconciling full AGENTS.md/scripts-dev behavior into update.
  • Design (a) from the spec: reuse init's renderer (not exclude-only design (b)) — this actually resolves symptom 4 ("shim drifts silently") rather than leaving it open.

AC Verification

AC Description Status Evidence
AC-1 dry-run lists exactly what sync then writes ✅ Implemented sync.test.ts "opencode shim (AC-1, AC-3)" — dry-run matches apply: previews 'refresh' and apply actually refreshes it
AC-2 no .claude/opencode/ path produced by the generic engine ✅ Implemented src/lib/templates.ts:templateDestination — templates.test.ts "returns null for templates/opencode/** (#1030)" + "excludes templates/opencode/** from the opencode-shim diff entirely (#1030)"
AC-3 shim has one producer, refreshed by sync AND update when .opencode/ exists ✅ Implemented sync.test.ts + update.test.ts "opencode shim (AC-3)" describe blocks
AC-4 no phantom "differ from bundled content" warning on a plain init project ✅ Implemented sync-source-invocation.integration.test.ts "no phantom opencode drift after a plain init (#1030)"
AC-5 no unrendered {{...}} placeholder ✅ Implemented templates.test.ts "writeOpencodeCommands leaves no unrendered placeholders (#1030)"
AC-6 suite green ✅ npm run build && npm test — see Test plan

Mutation verification

Mutation-verified: AC-2 — removed the templates/opencode/ case from templateDestination; src/lib/templates.test.ts > templates > templateDestination > returns null for templates/opencode/** (#1030) failed; restored.

Mutation-verified: AC-3 — removed the refreshOpencodeShim() call from sync.ts's apply path; src/commands/sync.test.ts > sync command > syncCommand > opencode shim (AC-1, AC-3) > dry-run matches apply: previews 'refresh' and apply actually refreshes it, on a project with .opencode/ failed; restored.

Second-pass fix (first QA: AC_MET_BUT_NOT_A_PLUS, 3fce881)

QA's two real gaps were a regression for opencode projects: the shim decision was presence-based, so .opencode/ could never resolve to "nothing to do" — sync --dry-run exited non-zero forever (breaking the #709 CI-gating contract) and a non-interactive update refused to run with nothing to apply. decideOpencodeShimSync is now content-aware: it renders the shim with the same writers into a scratch directory and compares file-by-file (MCP config: sequant's entry present and equal; user-added entries ignored). Result current reads like none for the exit code and the apply path while staying visible in the preview. Real-filesystem tests in src/commands/init.opencode-shim.test.ts (5 cases: none / current / drifted command / missing plugin file / MCP entry lost vs user entry added) plus current/refresh cases in sync.test.ts and update.test.ts.

Not changed: the second templates→.claude mapping QA flagged as harmless duplication (noted for a follow-up), the Updated 0 files tally wording, and the double decideOpencodeShimSync() call in sync.ts (mutually exclusive paths).

Mutation-verified: AC-1 — removed the templates/opencode/ exclusion line from templateDestination; src/commands/sync-source-invocation.integration.test.ts > reports no phantom drift on a plain (no --agent opencode) project failed (the motivating "3 file(s) differ from bundled content" reappeared); restored.

Mutation-verified: AC-4 — same mutation: removed the templates/opencode/ exclusion line from templateDestination; src/commands/sync-source-invocation.integration.test.ts > reports no phantom drift on a plain (no --agent opencode) project failed; restored.

Mutation-verified: AC-3 — made decideOpencodeShimSync return 'refresh' whenever .opencode/ exists (the presence-only decision); src/commands/init.opencode-shim.test.ts > is 'current' right after the writers ran, and stays so on a second look failed (with two sibling cases); restored.

Third pass (second QA: AC_NOT_MET on AC-3, 48047fb)

QA reproduced that sync's version-current fast path (sync.ts ~:330) returned before the shim decision, so a drifted shim on an up-to-date project was invisible to sync and sync --dry-run; only update / sync --force repaired it. The fast path is report-only by design (#708 — it never overwrites in-place customizations), so a stale shim is now treated like every other drift there: printed as opencode shim: refresh, named in the Version current, but … the opencode shim is stale — run update or sync --force line, exit 1, no mutation. A matching shim still reads "already up to date" with exit 0. Two sync.test.ts cases cover the version-current path, which no shim test exercised before.

Not changed: the duplicated templates→.claude mapping in computeDriftFingerprint (sync.ts ~:130, stat-only cache key) — QA classed it document; worth folding into templateDestination in a follow-up.

Mutation-verified: AC-3 — removed the && fastPathShim !== "refresh" clause from sync's version-current fast path; src/commands/sync.test.ts > version-current fast path: a stale shim is reported with exit 1 and the repair hint, never silently skipped (second-pass QA) failed; restored.

Pre-PR Confidence Check

  • Weakest part: decideOpencodeShimSync detects intent to refresh purely via .opencode/ directory presence, not by re-reading whether the project was ever initialized with --agent opencode. A project that manually created .opencode/ for unrelated reasons would get an (idempotent, harmless) refresh — an edge case the spec's own design note calls out as the accepted tradeoff of design (a).
  • Coverage gaps: none known for the changed source files — all four (init.ts, sync.ts, update.ts, templates.ts) have direct test coverage exercising the new code paths, including two mutation-verified gate tests above.

Test plan

  • npm run build — passes
  • npm run lint — passes (0 errors, 0 warnings)
  • npm test — 6285 passed / 3 failed / 4 skipped / 1 expected fail. The 3 failures (relay-hook.integration.test.ts, prompt-wait.test.ts, batch-executor.test.ts) are in files this PR never touches (relay hook, prompt --wait, activity-hook wiring) and are pre-existing/unrelated to the opencode-shim change.

Closes #1030

t and others added 4 commits September 10, 2026 18:49
Entire-Checkpoint: 3b4d69cae5da
…ne; sync/update refresh the shim in place (#1030)

- templateDestination() routes templates/opencode/** to null, matching the
  mcp.json/relay/ precedent — the generic engine never diffs or copies it.
- init.ts exports decideOpencodeShimSync/refreshOpencodeShim so sync/update
  can preview and apply the same opencode shim refresh init performs, gated
  on an existing .opencode/ directory.
- sync --dry-run previews 'opencode shim: refresh' alongside the AGENTS.md/
  scripts/dev decisions; the apply path refreshes the shim after copyTemplates.
- update mirrors the same preview/refresh and states explicitly that it still
  does not manage AGENTS.md or scripts/dev (sync-only).
- Fixes the phantom serve/preflight 'differ from bundled content' warning on
  every project that predates the opencode shim, and update no longer plants
  unrendered {{PHASE}} placeholder files.

Entire-Checkpoint: 364e5007d2d5
…ng to do

Second-pass QA found the presence-based decision made every opencode
project permanently "pending": sync --dry-run exited non-zero forever
(breaking the #709 CI-gating contract) and a non-interactive update
refused to run with nothing to do. decideOpencodeShimSync now renders the
shim with the same writers into a scratch dir and compares file-by-file
(MCP config: sequant's entry present and equal, user entries ignored);
'current' reads like 'none' for the exit code and the apply path while
staying visible in the dry-run preview.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_0147heJNRw8wBBujPGMqxDpR
…im instead of skipping it

Second-pass QA: sync's report-only fast path returned before the shim
decision, so on a version-current project a drifted shim was invisible to
sync and sync --dry-run (only update / sync --force repaired it). The fast
path now consults decideOpencodeShimSync and treats a stale shim like any
other drift on that path: reported, exit 1, same repair hint, no mutation
(#708 contract). Tests cover both the stale and the current case.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_0147heJNRw8wBBujPGMqxDpR
…-dry-run-lists-files-apply-never-writes-th
@admarble
admarble merged commit ac9afc3 into main Sep 11, 2026
8 checks passed
@admarble
admarble deleted the feature/1030-fix-sync-dry-run-lists-files-apply-never-writes-th branch September 11, 2026 01:43
admarble added a commit that referenced this pull request Sep 20, 2026
…s outside the diff need an issue number (#1101)

* chore(hooks): allow anchored env|grep in the env-dump guard; red tests outside the diff need an issue number

pre-tool.sh (all three copies): a bare env/printenv piped into a grep whose pattern starts with ^ is a prefix-scoped listing, not a dump. It is how a phase checks for the orchestrator's own SEQUANT_* vars leaking into the suite (#1086). Bare env, printenv, export and an unanchored env | grep TOKEN still block. 8 new cases per hook copy in the integration test.

exec and qa skills (all three copies): a failing test in a file the diff never touched must be re-run with the SEQUANT_* vars unset, settled against base in the same worktree, and named in the PR body with an issue number. PRs #1036, #1042 and #1048 wrote 'pre-existing, unrelated' for the same three failures; none filed, and the same failures stopped the #1060 gate a week later.

Entire-Checkpoint: 2ebe233c071c

* chore(skills): unset every SEQUANT_* var generically so the exec skill passes the relay isolation guard (AC-16)

Entire-Checkpoint: 02360586d1fc
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