From e7609093bfe6eb89855b4a3a0b4742d47fcf5ece Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Thu, 29 Oct 2026 11:02:06 -0700 Subject: [PATCH 1/3] perf(cursor-approve): drop the full-history clone from the checkout axes Both PR-head checkouts in cursor-axis-base.yml (the Cursor `axis` job and `axis-direct`) cloned every branch and tag with fetch-depth: 0, which took 1.5-10 minutes per axis on a large monorepo caller, often longer than the review itself. Only the merge base needs history. - Check out commit_sha at depth 1, then run the shared scripts/check-pr-size/fetch-history.sh (already used by cursor-review's diff-size job and pr-size.yml) to fetch BASE_SHA and commit_sha back to a merge base it can vouch for, failing the job with an ::error:: otherwise. - Render prompt resolves merge-base(BASE_SHA, commit_sha) with no fallback, instead of merge-base(origin/, commit_sha) falling back to BASE_SHA. origin/ no longer exists in a narrowed checkout; the result is the same commit unless the base branch has since absorbed the PR's own commits, and it now matches the compare API the no-checkout axes use. - New test_axis_checkout.py pins depth 1, the fetch step's order and inputs, and the no-fallback merge base. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_axis_checkout.py | 72 +++++++++++++++++++ .github/workflows/cursor-axis-base.yml | 30 ++++++-- docs/callers/cursor-approve.md | 2 +- scripts/check-pr-size/fetch-history.sh | 4 +- 4 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 .github/cursor-approve/tests/test_axis_checkout.py diff --git a/.github/cursor-approve/tests/test_axis_checkout.py b/.github/cursor-approve/tests/test_axis_checkout.py new file mode 100644 index 00000000..73a86200 --- /dev/null +++ b/.github/cursor-approve/tests/test_axis_checkout.py @@ -0,0 +1,72 @@ +"""The checkout axes clone narrowly and fail closed on the merge base. + +Both PR-head checkouts in cursor-axis-base.yml (the Cursor `axis` job and +`axis-direct`) are depth 1, followed by the shared fetch-history.sh, which +fetches back to the merge base of BASE_SHA and commit_sha or fails the job. +A full-history clone took minutes per axis on a large monorepo. + +Run: python3 -m unittest discover -s .github/cursor-approve/tests -p 'test_*.py' +""" + +import os +import re +import unittest + +HERE = os.path.dirname(os.path.abspath(__file__)) +ROOT = os.path.normpath(os.path.join(HERE, "..", "..", "..")) +with open(os.path.join(ROOT, ".github", "workflows", "cursor-axis-base.yml"), encoding="utf-8") as f: + BASE = f.read() + +CHECKOUT = "Check out the PR head (read-only)" +FETCH = "Fetch the merge-base history" +RENDER = "Render prompt" +SCRIPT = ('run: bash "$GITHUB_WORKSPACE/_cursor_approve_assets/' + 'scripts/check-pr-size/fetch-history.sh"') + + +def job(name): + start = BASE.index(f"\n {name}:\n") + nxt = re.search(r"\n [A-Za-z0-9_-]+:\n", BASE[start + 1:]) + return BASE[start:start + 1 + nxt.start()] if nxt else BASE[start:] + + +def steps(text): + """[(name, text)] in order.""" + parts = re.split(r"\n - name: ", text) + return [(p.split("\n", 1)[0].strip(), p) for p in parts[1:]] + + +class NarrowCheckout(unittest.TestCase): + def test_no_full_history_clone(self): + self.assertNotRegex(BASE, r"fetch-depth:\s*0\b") + + def test_each_checkout_job_fetches_the_merge_base_before_rendering(self): + for name, gate in (("axis", "if: inputs.checkout"), ("axis-direct", None)): + with self.subTest(job=name): + st = steps(job(name)) + names = [n for n, _ in st] + self.assertLess(names.index(CHECKOUT), names.index(FETCH)) + self.assertLess(names.index(FETCH), names.index(RENDER)) + checkout, fetch = dict(st)[CHECKOUT], dict(st)[FETCH] + self.assertIn("fetch-depth: 1\n", checkout) + self.assertIn("ref: ${{ inputs.commit_sha }}", checkout) + self.assertIn(SCRIPT, fetch) + self.assertIn("working-directory: pr\n", fetch) + self.assertIn("HEAD_SHA: ${{ inputs.commit_sha }}", fetch) + self.assertIn("BASE_SHA: ${{ github.event.pull_request.base.sha }}", fetch) + self.assertIn("FETCH_TOKEN: ${{ github.token }}", fetch) + if gate: + self.assertIn(gate + "\n", fetch) + + def test_render_reads_the_vouched_merge_base_with_no_fallback(self): + # A silent fallback to BASE_SHA would show every base-branch commit + # since the fork point as reverted by the PR. + for name in ("axis", "axis-direct"): + with self.subTest(job=name): + render = dict(steps(job(name)))[RENDER] + self.assertIn('merge_base="$(git -C pr merge-base "$BASE_SHA" "$COMMIT_SHA")"', render) + self.assertNotIn("origin/$BASE_REF", render) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/cursor-axis-base.yml b/.github/workflows/cursor-axis-base.yml index 0d73a248..84030cea 100644 --- a/.github/workflows/cursor-axis-base.yml +++ b/.github/workflows/cursor-axis-base.yml @@ -467,9 +467,22 @@ jobs: with: ref: ${{ inputs.commit_sha }} path: pr - fetch-depth: 0 + # Depth 1 plus the next step instead of a full clone: only the merge + # base needs history, and a full clone takes minutes on a monorepo. + fetch-depth: 1 persist-credentials: false + - name: Fetch the merge-base history + # The shared script cursor-review.yml's diff-size job uses. Fails the + # axis when no trustworthy merge base of BASE_SHA and commit_sha exists. + if: inputs.checkout + working-directory: pr + env: + FETCH_TOKEN: ${{ github.token }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ inputs.commit_sha }} + run: bash "$GITHUB_WORKSPACE/_cursor_approve_assets/scripts/check-pr-size/fetch-history.sh" + - name: Fetch the change (no checkout) if: ${{ !inputs.checkout && (inputs.axis == 'business' || inputs.axis == 'design') }} env: @@ -542,7 +555,7 @@ jobs: { printf '# %s\n\n' "$PR_TITLE"; printf '%s\n' "$PR_BODY"; } > "$ctx" merge_base="$BASE_SHA" if [ "$CHECKOUT" = "true" ]; then - merge_base="$(git -C pr merge-base "origin/$BASE_REF" "$COMMIT_SHA" 2>/dev/null || printf '%s' "$BASE_SHA")" + merge_base="$(git -C pr merge-base "$BASE_SHA" "$COMMIT_SHA")" fi { python3 "$CURSOR_APPROVE_ASSETS/aggregate.py" render \ @@ -858,9 +871,18 @@ jobs: with: ref: ${{ inputs.commit_sha }} path: pr - fetch-depth: 0 + fetch-depth: 1 persist-credentials: false + - name: Fetch the merge-base history + # As the Cursor job. + working-directory: pr + env: + FETCH_TOKEN: ${{ github.token }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ inputs.commit_sha }} + run: bash "$GITHUB_WORKSPACE/_cursor_approve_assets/scripts/check-pr-size/fetch-history.sh" + - name: Download the prior verdicts if: inputs.prior_rounds > 0 continue-on-error: true @@ -890,7 +912,7 @@ jobs: ctx_dir="pr/.git" ctx="$ctx_dir/cursor-approve-context.md" { printf '# %s\n\n' "$PR_TITLE"; printf '%s\n' "$PR_BODY"; } > "$ctx" - merge_base="$(git -C pr merge-base "origin/$BASE_REF" "$COMMIT_SHA" 2>/dev/null || printf '%s' "$BASE_SHA")" + merge_base="$(git -C pr merge-base "$BASE_SHA" "$COMMIT_SHA")" # Rule 1's exact diff. `--text --no-textconv --no-ext-diff`: the # checkout's own .gitattributes (`-diff`, `binary`, a textconv # driver) must not shrink a file's change to "Binary files differ" diff --git a/docs/callers/cursor-approve.md b/docs/callers/cursor-approve.md index 97e66265..b80e9bd0 100644 --- a/docs/callers/cursor-approve.md +++ b/docs/callers/cursor-approve.md @@ -687,7 +687,7 @@ diff the workflow fetches from the GitHub API.) | Input | Default | Meaning | |---|---|---| -| `commit_sha` | — (required) | The PR head to judge; checked out read-only with full history. | +| `commit_sha` | — (required) | The PR head to judge; checked out read-only with the history back to its merge base. | | `model` | `claude-opus-5-5-xhigh` | Cursor model id (cursor-review's judge model). | | `runs_on` | `"ubuntu-latest"` | JSON-encoded `runs-on`, as in cursor-review. | | `prior_rounds` | `0` | 0–3, passed to the base: the same value as `cursor-approve.yml`'s. See [Prior rounds](#prior-rounds). | diff --git a/scripts/check-pr-size/fetch-history.sh b/scripts/check-pr-size/fetch-history.sh index 5aa3a3d6..7b93013e 100755 --- a/scripts/check-pr-size/fetch-history.sh +++ b/scripts/check-pr-size/fetch-history.sh @@ -2,8 +2,8 @@ # Fetch the base commit, the head commit and their merge-base history into a # `fetch-depth: 1`, `persist-credentials: false` PR checkout — instead of the # `fetch-depth: 0` clone of every branch and tag that used to sit in front of -# check-pr-size. Shared by pr-size.yml and cursor-review.yml's `diff-size` job, -# so the two workflows that run the tool cannot drift on how its history is +# check-pr-size. Shared by pr-size.yml, cursor-review.yml's `diff-size` job and +# cursor-axis-base.yml's checkout axes, so they cannot drift on how history is # narrowed. (BE-8940 for pr-size; cursor-review adopted it to take the clone off # its review round's critical path.) # From e96859a755c57c16c55aceb09a02fcca8da04b74 Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Thu, 29 Oct 2026 11:07:59 -0700 Subject: [PATCH 2/3] docs(check-pr-size): drop a tracker reference from the fetch-history header Co-Authored-By: Claude Opus 5.5 --- scripts/check-pr-size/fetch-history.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/check-pr-size/fetch-history.sh b/scripts/check-pr-size/fetch-history.sh index 7b93013e..cfb732b7 100755 --- a/scripts/check-pr-size/fetch-history.sh +++ b/scripts/check-pr-size/fetch-history.sh @@ -4,8 +4,8 @@ # `fetch-depth: 0` clone of every branch and tag that used to sit in front of # check-pr-size. Shared by pr-size.yml, cursor-review.yml's `diff-size` job and # cursor-axis-base.yml's checkout axes, so they cannot drift on how history is -# narrowed. (BE-8940 for pr-size; cursor-review adopted it to take the clone off -# its review round's critical path.) +# narrowed. (cursor-review adopted it to take the clone off its review round's +# critical path.) # # Run from the root of the PR checkout. Inputs: # env FETCH_TOKEN the job's read-only token (`permissions: contents: read`) From 4c42879b258a591bf4a7caf435af639d571fc802 Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Thu, 29 Oct 2026 11:18:58 -0700 Subject: [PATCH 3/3] docs(cursor-approve): warn the axes that blame stops at a shallow boundary Co-Authored-By: Claude Opus 5.5 --- .github/cursor-approve/prompt-common.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/cursor-approve/prompt-common.md b/.github/cursor-approve/prompt-common.md index ba347323..7d672b62 100644 --- a/.github/cursor-approve/prompt-common.md +++ b/.github/cursor-approve/prompt-common.md @@ -30,9 +30,11 @@ the merge base. work, you are looking at that artifact, not at the PR. 2. **Read; do not run.** Read the changed code, the code around it, and its - history (`git log`, `git blame`, `git show`). Do not build the project, run - its tests, or execute anything it contains. CI runs elsewhere, and its result - is not your question. + history (`git log`, `git blame`, `git show`). The checkout's history ends a + little past the merge base: a line `git blame` credits to a `^`-prefixed + boundary commit was written earlier, not there, so do not rest a verdict on + who added it or when. Do not build the project, run its tests, or execute + anything it contains. CI runs elsewhere, and its result is not your question. 3. **Pick a verdict by what the evidence supports.** - `red` — you found evidence of a blocker on your axis. Name it.