Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/cursor-approve/prompt-common.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
72 changes: 72 additions & 0 deletions .github/cursor-approve/tests/test_axis_checkout.py
Original file line number Diff line number Diff line change
@@ -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()
30 changes: 26 additions & 4 deletions .github/workflows/cursor-axis-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
wei-hai marked this conversation as resolved.
Resolved
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:
Expand Down Expand Up @@ -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")"
Comment thread
wei-hai marked this conversation as resolved.
Resolved
fi
{
python3 "$CURSOR_APPROVE_ASSETS/aggregate.py" render \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docs/callers/cursor-approve.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |
Expand Down
8 changes: 4 additions & 4 deletions scripts/check-pr-size/fetch-history.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# 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
# narrowed. (BE-8940 for pr-size; cursor-review adopted it to take the clone off
# its review round's critical path.)
# 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. (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`)
Expand Down
Loading