Skip to content

fix(merge): sequant merge --check hard-codes origin/main in four places, so a master-default repo gets empty diffs and a clean report #1484

Closed

Description

@admarble

Epic: graph-2026-10-freeze-c Tier: mechanical Execution: sequant_run

Problem

sequant merge --check hard-codes origin/main as the base in four places in src/lib/merge-check/:

Site Use
combined-branch-test.ts:57 const BASE_REF = "origin/main": the combined branch is cut from it (:264), and the lockfile check compares against it (:364)
index.ts:170 git diff --name-only origin/main...origin/<branch>: each batch branch's filesModified
overlap-detection.ts:38 git diff --unified=0 origin/main...<branch> -- <file>: hunk ranges for overlap
residual-pattern-scan.ts:61 git diff origin/main...<branch> --unified=0: residual pattern scan

On a repo whose default branch is master (or anything other than main), origin/main doesn't exist. The combined-branch test can't create its branch. The three diffs fail, and their callers read the empty stdout as "no changes". At index.ts:170, filesModified silently becomes [], so the overlap checks, including #1454's external-PR overlap, see nothing and report clean. That's wrong output with no error.

Found by QA on #1460 (PR #1483), whose document finding named combined-branch-test.ts:57. A repo-wide git grep found the other three.

Prior fixes / producers

Acceptance Criteria

  • AC-1: No string literal origin/main remains in non-test code under src/lib/merge-check/, and every base ref there comes from one resolver call per merge --check run, passed to all four former sites. Evidence: git grep -nE "origin/main" -- 'src/lib/merge-check/*.ts' ':!*.test.ts' prints nothing (comments rewritten too), and AC-2's test covers all four sites.
  • AC-2: On a temp repo whose default branch is master (bare origin, origin/HEAD → master, no origin/main) with one feature branch that changes a file, each of the four sites uses origin/master: runMergeChecks reports that branch's filesModified as the changed file, the combined-branch test creates its temp branch from origin/master, the overlap check reads the branch's hunk ranges, and the residual pattern scan reads its diff. Evidence: npx vitest run src/lib/merge-check/merge-check-base.integration.test.ts -t "master-default" reports ≥ 4 passed and 0 failed (a filter that matches nothing reports all skipped and exits 0), mutation-verified by restoring the origin/main literal at index.ts's filesModified diff (exactly the filesModified case fails).
  • AC-3: When the filesModified diff command fails, filesModified isn't silently []: the report carries an error finding for that branch naming the failed git command. Evidence: npx vitest run src/lib/merge-check/merge-check.test.ts -t "base ref does not resolve" reports ≥ 1 passed and 0 failed (a filter that matches nothing reports all skipped and exits 0), mutation-verified by restoring the silent [] fallback.

May touch

src/lib/merge-check/ (combined-branch-test.ts, index.ts, overlap-detection.ts, residual-pattern-scan.ts, types.ts) and their tests, including merge-check-base.integration.test.ts (new), docs/reference/merge-command.md, CHANGELOG.md.

Non-Goals

  • Base resolution outside src/lib/merge-check/ (detectDefaultBranch and the other resolvers are used as they are).
  • A --base flag for merge --check. Batches with a non-default base are a separate question.
  • Any edit under plugin/, .claude/skills/ or templates/skills/ (plugin freeze).

Activity

  1. added
    bug
    graph-2026-10-freeze-c
    on Oct 16, 2026
  2. admarble commented on Oct 18, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (3 ACs, 1 directory)

    AC Quality Check

    All three ACs are single-line, carry Evidence:, and are measurable. Notes:

    • AC-1's grep fails today (4 code hits) and passes only once the literals are gone, so it is not vacuous. Its second clause, "one resolver call per run", is not covered by the grep. AC-2's test covers it only indirectly. See Open Question 2.
    • AC-2 and AC-3 both guard against the "filter matches nothing" case with a ≥ N passed clause. Good.
    • AC-3's "a failed git command" has no defined failure mode: how does the finding reach the report? See Plan step 3.

    Scope Assessment

    Non-Goals: present (base resolution outside merge-check/, --base flag, plugin/skill dirs).

    Metric Value Status
    Feature count 1 ✅
    AC items 3 ✅
    Directory spread 1 (src/lib/merge-check/) ✅

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC-1: No origin/main literal in non-test merge-check/; one resolver call per run

    Verification: Integration Test (the AC-2 test) plus the grep in Evidence
    Scenario: Given the merge-check sources → When the grep runs → Then no output; and a single resolution is threaded to all four sites.

    AC-2: master-default repo uses origin/master at all four sites

    Verification: Integration Test (merge-check-base.integration.test.ts, -t "master-default", ≥4 cases)
    Scenario: Given a temp repo with a bare origin, origin/HEAD → master, no origin/main, one feature branch changing one file → When each site runs → Then filesModified = [that file], the temp branch is cut from origin/master, overlap reads its hunks, the residual scan reads its diff.
    Assumptions: combined-branch-test.integration.test.ts:201 already builds a bare origin + clone fixture. Reuse it with a master default.

    AC-3: A failed filesModified diff is not silently []

    Verification: Unit Test (merge-check.test.ts, -t "base ref does not resolve")
    Scenario: Given the diff command exits non-zero → When resolveBranches / runMergeChecks runs → Then the report has an error finding for that branch naming the git command.


    Implementation Plan

    Phase 1: One resolver

    1. In runMergeChecks (index.ts), resolve once: const baseRef = origin/${detectDefaultBranch(false, repoRoot)}`` (worktree-manager.ts:242, cwd-aware since fix(run): phase agents never get SEQUANT_BASE_BRANCH — skills fall back to main on master-default repos #1460). Not `resolveBaseRef(cwd)`: it prefers a per-branch recorded `sequantBase`, which is wrong for a repo-root batch check.
    2. Thread baseRef as a required parameter into resolveBranches, runCombinedBranchTest, runOverlapDetection (→ getChangedLineRanges) and runResidualPatternScan (→ extractPatternsFromDiff). Delete BASE_REF in combined-branch-test.ts (:57, used at :264, :364). Required, so a future caller can't silently reintroduce a default.
    3. Rewrite the comments that mention origin/main (AC-1 greps comments too).

    Phase 2: Surface the failure (AC-3)

    1. At index.ts:166-176, check diffResult.status. On failure, record the failure on BranchInfo (new optional field in types.ts, e.g. filesModifiedError: string holding the command) and emit an error CheckFinding for that branch from runMergeChecks. Keep filesModified = [] only as the payload, never as the signal.
    2. Also fix the worktree path: getGitDiffStats(worktreePath) at index.ts:160 uses the default baseBranch = "main", and resolveDiffBase returns it verbatim when unresolvable. That's the same silent-empty bug on a master repo. Pass the resolved base (branch name without origin/). It sits inside merge-check/, so it is in scope, but the AC-1 grep can't see it. See Open Question 1.

    Phase 3: Tests and docs

    1. Add merge-check-base.integration.test.ts (4+ cases under a master-default describe) and the AC-3 case in merge-check.test.ts. Update the existing callers (merge-check.test.ts:158-232, combined-branch-test*.test.ts) for the new parameter, and the origin/main command strings mocked at combined-branch-test.test.ts:123,597.
    2. Mutation-verify per CLAUDE.md. Restore the literal at index.ts's filesModified diff and confirm only the filesModified case fails. Restore the silent [] fallback and confirm the AC-3 test fails. Record Mutation-verified: markers in the PR body with the file path first (src/lib/merge-check/merge-check-base.integration.test.ts > …). Update docs/reference/merge-command.md and CHANGELOG.md.

    Design Review

    1. Where does this logic belong? runMergeChecks resolves once, and each check receives the ref. The resolvers stay where they are (Non-Goal).
    2. Simplest correct approach? A required baseRef parameter. Rejected: a module-level resolveBase() called in each file (four resolutions can disagree mid-run, and the AC wants one call). Rejected: resolveBaseRef(cwd), which reads a per-branch recorded base.
    3. Existing pattern and recurrence? The base-ref cluster: fix(chain): --chain successors branch from main, not predecessor's committed work (up-front worktree provisioning) #748, fix(observability): phase diff stats compare against the local base ref while worktrees branch from origin/<base> — phantom filesModified + base tip logged as the phase commit #878, fix(observability): remaining bare main...HEAD consumers after #878 — qa-cache diff hash, worktree-manager summaries, aider file-context, non-qa skill gates #890, bug(qa): the qa phase rebases an already-pushed branch onto main, forcing a force-push to land it #1069, bug(exec): sequant run worktrees never record sequantBase, so the zero-diff/uncommitted guard compares against origin/main and a --base ahead of main disables it #1234, fix(run): --base creates the worktree from the branch but opens the PR against the repo default branch #1386, ensureWorktree "recreating fresh" rebuilds a PR branch from base and drops its commits; qa re-run reviews the wrong tree #1380, fix(worktree): a non-default bare --base is cut from local <base> but counted against origin/<base> (#1380 follow-up, #1234/#1386 class) #1406, fix(run): phase agents never get SEQUANT_BASE_BRANCH — skills fall back to main on master-default repos #1460, which is ≥2 prior fix issues. The class is "a consumer hard-codes the base instead of calling the resolver". Here the fix is the class for merge-check/, which is the last unadopted consumer. Residual risk is a new hard-coded consumer. A git grep lint across src/ (not only merge-check/) would close the class. See Open Question 3.
    4. What would a senior reviewer challenge? "Why not default the parameter?" A default is what let this recur. "Why not also handle --base?" It's a Non-Goal.
    5. Producers and consumers. git grep origin/main src/ finds the four sites plus tests. Consumers of BranchInfo.filesModified are runOverlapDetection, runExternalPrOverlap and runMirroringCheck. They all read the field populated at index.ts, so one fix point covers all of them. detectDefaultBranch has a single producer. Its fallback to "main" when origin/HEAD can't be read remains. A master repo with origin/HEAD unset still gets origin/main, which is a Non-Goal and should be mentioned in the docs.

    No divergence from the prescribed lever.


    Feature Quality Planning

    All standard checks pass. Notable items:

    • Latent fifth site: getGitDiffStats default "main" (Plan step 5).
    • Error finding for AC-3 must change the verdict: an error finding should push the branch to BLOCKED, not READY. Confirm with computeIssueVerdicts (report.ts:22) and assert it in the test.
    • Existing mocks pin the exact command string, so they shift with the change (ordered-mock queue).

    Derived ACs

    Source Derived AC Priority
    Error handling AC-4: the worktree-path diff (getGitDiffStats) uses the resolved base on a master-default repo High

    Open Questions

    1. Cover the worktree-path getGitDiffStats default? — Recommendation: yes, add as AC-4 (owner edits the AC lines). Impact: if skipped, a master repo with worktrees still reports empty filesModified, and AC-2's runMergeChecks case passes only on the remote-branch path.
    2. Tighten AC-1's "one resolver call per run"? — Recommendation: assert in a unit test that detectDefaultBranch is called once per runMergeChecks. Impact: otherwise unenforced.
    3. Repo-wide lint against origin/main literals? — Recommendation: separate follow-up issue, not this one. Impact: the class can recur.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: one directory, bug fix, mechanical. testgen skipped: the label is bug only. The ACs declare their own test files, and the integration fixture exists.


    Label Review

    Current: bug, graph-2026-10-freeze-c
    Recommended: no change
    Reason: n/a
    Quality Loop: won't auto-enable (SCOPE_OK).

  3. added
    planned
    on Oct 18, 2026
  4. admarble commented on Oct 18, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 3/3 met

    Gaps:

    • Gate-test ACs AC-2 and AC-3 lack recorded mutation markers; add them to exec's final Summary
    • Worktree-path filesModified still silently empties on diff failure, the same defect AC-3 fixed for the remote path
    • Cleanup restore falls back to main, which fails on a master-default repo when rev-parse of the original branch fails
    • Required CI checks test and canary still pending at QA time
  5. added a commit that references this issue on Oct 18, 2026
  6. admarble commented on Oct 18, 2026

    @admarble
    ContributorAuthor

    Runner verification (graph-2026-10-freeze-c W3, node F). I ran this after QA's AC_MET_BUT_NOT_A_PLUS (3/3) on PR #1500.

    Fixed in dd4ca291f. QA marked both findings "document", but both were this issue's own defect:

    • A failed diff for a branch held by a worktree still returned a silent []. That path used getGitDiffStats, which fails open. AC-3 covers every filesModified diff, so both paths now share one checked git diff --name-only. New test added.
    • Cleanup's restore fell back to the literal main. It now falls back to the resolved base. New test added.

    Evidence commands, run verbatim on dd4ca291f:

    AC Result
    AC-1 the grep prints nothing
    AC-2 4 passed, 0 failed
    AC-3 2 passed, 0 failed

    src/lib/merge-check passes 133/133. tsc and eslint are clean. The freeze grep prints nothing, and the branch is 0 commits behind main.

    Mutations, each failing only its target test, then restored:

    • AC-2: the origin/main literal is back at the filesModified diff.
    • AC-3: the silent [] is back.
    • The worktree path treats a failed diff as success.
    • The restore fallback is main again.

    The records are in the PR body.

    Follow-up ledger: the spec's open question 3 (a repo-wide lint against origin/main literals) is dropped. After this PR, no non-test code under src/ contains the literal. The 6 remaining mentions are comments, and the earlier instances were fixed in #343 and #1460. Nothing else was deferred.

    PR #1500 waits on CI and then on the owner's merge decision.

  7. added a commit that references this issue on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggraph-2026-10-freeze-cplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions