Skip to content

fix(#1123): --yes init no longer replaces an unparseable .mcp.json - #1142

Merged
admarble merged 2 commits into
mainfrom
feature/1123-fix-init-yes-init-replaces-a-user-modified-agents-
Sep 24, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/1123-fix-init-yes-init-replaces-a-user-modified-agents-

Conversation

@admarble

@admarble admarble commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • createProjectMcpJson caught the JSON.parse failure on an unparseable .mcp.json and silently started fresh, overwriting the file while reporting "Added Sequant to existing .mcp.json" — even though .mcp.json is a merge destination that syncSequantMcpPin already leaves alone on the same failure. It now returns corrupt: true without writing, and init reports the file was left untouched.
  • The AGENTS.md half of this issue was already fixed by ci(canary): downstream fixture project on every PR — older install, customized files, init-on-initialized, MCP handshake — plus an npm next-tag soak before latest #1098 (verified: init.ts already routes through decideAgentsMdSync) — this PR closes the remaining .mcp.json half.
  • As a side effect, init no longer crashes with EISDIR when .mcp.json is a directory, since the same early-return guard now runs before any write is attempted. Updated the writer-state matrix (src/lib/__tests__/writer-state-matrix.test.ts) accordingly: removed the now-empty #1123 tracked-defect entry and reduced the #1124 (directory-crashes-writer) count from 34 to 32 for the two .mcp.json/directory cells that no longer crash.

Pre-PR AC Verification

Requirement (from issue body) Status Evidence
init routes AGENTS.md through decideAgentsMdSync the way sync does ✅ Already implemented src/commands/init.ts:1132-1139 (landed via #1098/#1127, prior to this branch)
An unparseable .mcp.json is left alone and reported ✅ Implemented src/lib/mcp-config.ts createProjectMcpJson early-returns corrupt: true; src/commands/init.ts reports "left untouched" instead of "Added Sequant"

Pre-PR Confidence Check

  • Weakest part: The catch block now treats both "unparseable JSON" and "unreadable because it's a directory" (EISDIR) the same way (corrupt: true, leave alone). That's the right behavior for both cases, but the corrupt field name is a slight misnomer for the directory case.
  • Coverage gaps: None known — both the mcp-config.ts unit test and an init.ts reporting test cover the new path, and the writer-state matrix's real-filesystem init run against a directory-shaped .mcp.json covers the EISDIR side effect.

Test Coverage Analysis

Changed File Tier Has Tests?
src/lib/mcp-config.ts Standard ✅ Yes (src/lib/mcp-config.test.ts)
src/commands/init.ts Standard ✅ Yes (src/commands/init.test.ts)
src/lib/__tests__/writer-state-matrix.test.ts Test-only N/A
CHANGELOG.md Docs N/A

Lint / Build / Test Results

  • npm run build — ✅ passed
  • npm run lint — ✅ passed (0 errors, 0 warnings)
  • npm test — 8335 passed, 1 expected fail, 3 skipped, 5 failed — all 5 in __tests__/evals-fixture-commit.test.ts, none in a file this diff touches.

Settled against base

Ref Result
Head feature/1123-fix-init-yes-init-replaces-a-user-modified-agents- @ 751035f FAIL (exit 1)
Base origin/main @ 35d7bbc FAIL (exit 1)

Test: __tests__/evals-fixture-commit.test.ts
Verdict: Pre-existing — red at origin/main too, identically (5 of 16 fixture_commit is an ancestor of HEAD cases). Root cause: this sandbox checkout is a shallow clone (git rev-parse --is-shallow-repository → true), so the referenced fixture commits aren't in the fetched history window and isAncestor() false-negatives regardless of any diff. Filed as sequant-io/sequant#1140.

CHANGELOG: entry added under [Unreleased] → Fixed.

Closes #1123

🤖 Generated with Claude Code


Generated by Claude Code

createProjectMcpJson caught the JSON.parse failure and started fresh,
silently overwriting the file while reporting "Added Sequant to
existing .mcp.json" — even though .mcp.json is a merge destination
that syncSequantMcpPin already leaves alone on the same failure. It
now returns corrupt: true without writing, and init reports the file
was left untouched instead of claiming it was updated.

The AGENTS.md half of this issue was already fixed by #1098; this
closes the remaining .mcp.json half, so the writer-state matrix's
tracked-defect entry for #1123 is removed. That fix also stops init
crashing with EISDIR when .mcp.json is a directory, since the same
early-return guard now applies before any write is attempted.

Claude-Session: https://claude.ai/code/session_01W6MSXo6CpVP1WmyNMwxWVz
@admarble
admarble merged commit 28bc074 into main Sep 24, 2026
9 checks passed
@admarble
admarble deleted the feature/1123-fix-init-yes-init-replaces-a-user-modified-agents- branch September 24, 2026 18:07
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(init): --yes init replaces a user-modified AGENTS.md and an unparseable .mcp.json that sync would preserve

2 participants