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
The pre-commit test lint refuses a merge of origin/main, linting main's own lines as added #1456
What happens. On a branch whose base predates a change to `src/contract/`, `git merge origin/main` cannot be committed: the pre-commit `tests` step fails on lines that are already on `main` and that the branch never touched. The tool guard (`.agents/scripts/tool-guard.mjs`) refuses a non-fast-forward push and says to "merge the remote branch in and push again", so the two together leave no path for a branch that has fallen behind.
Where. `lefthook.yml:33` runs `node .agents/scripts/test-lint.mjs --base HEAD {staged_files}`. During a merge, the staged files include every `src/contract/*.ts` file main changed, and `--base HEAD` (the branch's old tip) counts all of main's lines in them as added (`.agents/scripts/test-lint.mjs:221`). Lines that predate the always-in-scope 8 check, or that a file split moved (`2dfd3ba7`, #1345), then fail it.
Seen. Merging `origin/main` (`14163a99`) into `bug/1103-repro` (base `944d2549`): 41 findings, all in `src/contract/{status,config,device,report,lease}-schemas.ts`, for example `src/contract/config-schemas.ts:62: bound this wire input with .max(), .length() or .regex() ...`. The only file the branch changes, `src/agent-device/gateway-front.test.ts`, was not flagged, and the same change cherry-picked onto `origin/main` committed cleanly.
Defect, confirmed as reported. src/test-lint.test.ts, "in a merge the commit hook judges only the lines the merge adds, not those the merged branch brings" (branch bug/1456-repro). The fixture merges a branch that adds an unbounded z.string() in src/contract/a.ts and an it.skip in src/a/old.test.ts. The merge itself adds an it.only. The test runs the hook's command, --base HEAD <staged files>, before the merge is committed. Only the it.only should be flagged. All three are flagged:
pnpm exec vitest run --project unit src/test-lint.test.ts
"src/a/mine.test.ts:2: never skip, focus or defer a test ... (testing 5)",
+ "src/a/old.test.ts:2: never skip, focus or defer a test ... (testing 5)",
+ "src/contract/a.ts:2: bound this wire input with .max() ... (always-in-scope 8)",
Root cause
.agents/scripts/comments.mjs:36 (changedFiles, which test-lint.mjs imports) computes merge-base(HEAD, HEAD) = HEAD and diffs it against the working tree, so it never looks at MERGE_HEAD. While a merge is in progress, every line the merged branch brings shows up as added. Main's older lines then fail whatever checks they predate. The symptom shows in test-lint.mjs. movedContractDeclarations (test-lint.mjs:221) uses the same base, but it only excuses lines, so it cannot add a finding.
Simplest fix
In changedFiles, when no --head is given and MERGE_HEAD exists, keep only the lines that are added against HEAD and also against MERGE_HEAD:
constadded=addedLines(path,lines.length,range,head);// why: in a merge, a line the merged branch already holds is not one this commit adds.if(head===undefined&&mergeHead()!==null){consttheirs=addedLines(path,lines.length,[mergeHead()],head);for(constnofadded)if(!theirs.has(n))added.delete(n);}
mergeHead() is git rev-parse -q --verify MERGE_HEAD, or null when no merge is in progress. Tried it:
pnpm exec vitest run --project unit src/test-lint.test.ts src/comment-lint.test.ts src/comments.test.ts
Test Files 3 passed (3) Tests 30 passed (30)
Alternatives rejected
skip: [merge] on the lefthook tests step: then lines the merge itself adds, such as conflict resolutions, are never linted. Nothing else runs this lint.
A merge-specific --base in lefthook.yml: this needs shell logic in the hook, and the comment lint would stay broken.
Risk
The comment lint also uses changedFiles, so it stops judging the merged branch's comments too. This is intended.
A merge whose resolution reformats a line counts that line as added. This is correct, and the same as a normal commit.
Fast track
Defect: yes
Fix tried: yes
Nothing public added or broken: yes
No ADR or rule changed: yes
One fix: no — skipping the step in merges is a choice with different output
Activity
V3RON commentedon Nov 10, 2026
Reproduction
Defect, confirmed as reported.
src/test-lint.test.ts, "in a merge the commit hook judges only the lines the merge adds, not those the merged branch brings" (branchbug/1456-repro). The fixture merges a branch that adds an unboundedz.string()insrc/contract/a.tsand anit.skipinsrc/a/old.test.ts. The merge itself adds anit.only. The test runs the hook's command,--base HEAD <staged files>, before the merge is committed. Only theit.onlyshould be flagged. All three are flagged:Root cause
.agents/scripts/comments.mjs:36(changedFiles, whichtest-lint.mjsimports) computesmerge-base(HEAD, HEAD)=HEADand diffs it against the working tree, so it never looks atMERGE_HEAD. While a merge is in progress, every line the merged branch brings shows up as added. Main's older lines then fail whatever checks they predate. The symptom shows intest-lint.mjs.movedContractDeclarations(test-lint.mjs:221) uses the same base, but it only excuses lines, so it cannot add a finding.Simplest fix
In
changedFiles, when no--headis given andMERGE_HEADexists, keep only the lines that are added againstHEADand also againstMERGE_HEAD:mergeHead()isgit rev-parse -q --verify MERGE_HEAD, ornullwhen no merge is in progress. Tried it:Alternatives rejected
skip: [merge]on the lefthooktestsstep: then lines the merge itself adds, such as conflict resolutions, are never linted. Nothing else runs this lint.--baseinlefthook.yml: this needs shell logic in the hook, and the comment lint would stay broken.Risk
changedFiles, so it stops judging the merged branch's comments too. This is intended.Fast track
Written by an agent.
test(lint): the merge test commits a violation on the branch and expe…
fix(lint): in a merge the commit hook judges only the lines the merge…