Skip to content

fix(ci): fetch the base ref with full history so the scope check has a merge base - #2554

Closed
kyle-sexton wants to merge 1 commit into
mainfrom
fix/security-review-evidence-merge-base
Closed

fix(ci): fetch the base ref with full history so the scope check has a merge base#2554
kyle-sexton wants to merge 1 commit into
mainfrom
fix/security-review-evidence-merge-base

Conversation

@kyle-sexton

Copy link
Copy Markdown
Contributor

Summary

scripts/verify-security-review-evidence.sh fetched the base ref shallow and then asked for a
three-dot diff against it:

git fetch origin "$base_ref" --depth=1 >/dev/null 2>&1 || true
# ...
git diff --name-only origin/<base>...HEAD

A three-dot diff needs a merge base. --depth=1 truncates the base ref to a lone commit, so any
branch not sitting on the base's current tip dies with fatal: origin/main...HEAD: no merge base
before the scope check can run. At this repo's merge rate that is most PRs more than a few minutes
old.

Observed on #2539: deterministic across two independent runs (31655807987, jobs 94310219602 and
94312908610), branch seven commits behind main.

The failure is fail-closed — correct, and clearly deliberate in the script's comments — but the guard
never reaches the evidence check it exists to perform, and goes red on PRs it has nothing to say
about.

Fix: drop --depth=1. .github/workflows/claude-security-review.yml already checks out with
fetch-depth: 0, so this is a normal fetch against an already-complete clone, not a cost regression.
Nothing about the fail-closed posture changes.

Not done here: defending against being called from a genuinely shallow clone
(--is-shallow-repository--unshallow). The only caller checks out full history, so that would
be scaffolding for a case that does not exist. Raised as a question in #2553 rather than built.

Test plan

  • scripts/verify-security-review-evidence.sh.test.sh — all checks pass, including two new ones:
    • a static guard that fails if a --depth fetch of the base ref is reintroduced;
    • a behavioural test building a behind-main fixture repo and asserting both directions — the
      full fetch yields a working three-dot diff, and the shallow fetch breaks it. The second
      assertion fails loudly if the regression ever stops being real, so the test cannot start passing
      vacuously and leave the static guard unexamined.
  • scripts/affected-tests.sh --run — 1 suite selected, passes.
  • shellcheck with the repo's .shellcheckrc: exit 0, matching the pre-change baseline
    (verified by stashing and re-running). The fixture chains with && rather than set -e because
    enabling errexit anywhere in that file switches on SC2310 for every pre-existing
    function-in-a-condition above it; the one new SC2016 carries the same disable directive and
    rationale the file already uses two blocks earlier.
  • editorconfig-checker clean; no file-mode changes.

Related

Closes #2553

Found while shipping #2539, where this gate went red on a docs-only change with no finding of its
own.

…a merge base

The guard fetched the base ref with --depth=1, then asked for a three-dot diff
against it. A three-dot diff needs a merge base, and a shallow fetch truncates
the base ref to a lone commit, so any branch not sitting on the base's current
tip died with "fatal: origin/main...HEAD: no merge base" before the scope check
could run. Reproduced deterministically on #2539 across two runs with the branch
seven commits behind main.

The workflow already checks out with fetch-depth: 0, so dropping --depth=1 costs
nothing — it is a normal fetch against an already-complete clone. The guard's
fail-closed posture is untouched; it just gets a usable merge base and evaluates
scope as designed instead of erroring.

Covered two ways: a static guard against reintroducing the shallow fetch, and a
behavioural test that builds a behind-main fixture and asserts both directions —
full fetch yields a working three-dot diff, shallow fetch breaks it. The second
assertion means the test reports if the regression it pins ever stops being real
rather than passing vacuously.

The fixture chains with && instead of set -e: enabling errexit anywhere in that
file switches on SC2310 for every pre-existing function-in-a-condition above it.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 13, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@kyle-sexton

Copy link
Copy Markdown
Contributor Author

Closing as superseded: #2548 (merged to main as 04f9cee8) removed the local scope check and git fetch --depth=1 path entirely — the guard now reads the lane's declared LANE_RELEVANT output instead of running its own three-dot diff. The shallow-fetch defect this PR targeted no longer exists on main.

@kyle-sexton

Copy link
Copy Markdown
Contributor Author

Superseded by #2548 — the shallow-fetch scope check this PR patched was removed from the guard entirely.

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.

verify-security-review-evidence.sh shallows the base ref, so the guard fails with 'no merge base' on any branch behind main

1 participant