Skip to content

Add headCommitSha to waitForReview - #58

Open
canakyildz wants to merge 1 commit into
prooflinedev:mainfrom
canakyildz:wait-for-review-head-commit
Open

canakyildz wants to merge 1 commit into
prooflinedev:mainfrom
canakyildz:wait-for-review-head-commit

Conversation

@canakyildz

Copy link
Copy Markdown

Suhas Guruprasad added head_commit_sha to the Python SDK's wait_for_review in prooflinedev/sdk-python#49. This gives waitForReview the matching option, headCommitSha, with the same reason codes: once it is set, a review of any other commit can't come back COMPLETED.

requestReview takes a pull request number, not a commit, and the review runs on whatever the head is when the request lands. A force-push or a bot commit in between can produce COMPLETED for code you aren't shipping, with no sign of it in the outcome. ci review in the CLI already refuses that case. My work runs as parallel agent tasks, one worktree and branch each, and what matters is that the check I'm reading ran on that branch's commit.

Where TypeScript makes its own call

  • Bad input throws a TypeError before any request, as timeoutMs already does here (Python raises ValueError). Only 40 or 64 hex characters pass, upper or lower case. The type is checked before the pattern, since RegExp.test stringifies its argument and a Buffer holding the right text would get through.
  • null throws, undefined turns the check off. null isn't in the option's type, and in practice it comes from data, a JSON field or a database column with no commit in it. That caller believes they have a commit and don't, so the call should fail loudly rather than run unchecked. undefined, like leaving the option out, matches Python's None, so the runtime and the type agree both ways.
  • A timeout keeps its own reason, "the review did not finish before timeoutMs", because that is what happened. The head gap still appears in gaps. Python reports the head reason there. Statuses and reason codes are the same in both SDKs.
  • A head that is missing, empty or not a string counts as no head, not as a malformed response. With the option set, such a review can't complete. Without it, the field is ignored as before.

Gap ordering. Both SDKs append the head gap after every other gap, but neither had a test for it. Test 3 now checks it: a review with an incomplete assessment history, pinned to another commit, must list ASSESSMENT_HISTORY_UNAVAILABLE first and HEAD_COMMIT_MISMATCH last. Moving the head gap to the front fails that check and nothing else.

Review's head_commit_sha Result with headCommitSha set
same commit, any case unchanged
another commit INCOMPLETE on that read, even if the review is still running. Last gap HEAD_COMMIT_MISMATCH
missing, review finished never COMPLETED, while FAILED and STOPPED stay. Last gap HEAD_COMMIT_UNAVAILABLE
missing, review pending or running keeps polling
missing at the deadline TIMED_OUT with the timeout reason, head gap in gaps

A mismatch stops the wait straight away: a review's head never changes, so more polling would only use up the caller's timeout.

current_head_commit_sha is left out. It asks whether the pull request has moved since, which is a separate question. #44 proposed two new methods to find and wait for a review by commit, and was closed as out of scope. This adds no method, only an optional field on waitForReview, and callers who don't set it see no change. #33 and #35 also add a field to WaitOptions, and the overlap is adjacent lines.

Checks. At a82cef8 I ran CI's steps in order on a clean install, with Node 22.23.5 where CI pins 22.23.2. All 109 tests pass, 104 of them from main. pnpm generate leaves no diff, and lint, typecheck, the claims check, build and npm pack pass. Reverting src/index.ts alone fails all 5 new tests and nothing else. Each of 11 single-rule changes to the source fails at least one test. GitHub Actions hasn't run this yet, and I haven't called the live API.

Tests and mutation runs

The tests port the five from prooflinedev/sdk-python#49 and run against a local HTTP server. A held clock records the wait's sleeps and skips them, so they assert the same schedule as Python: 5,000 then 10,000 ms before the third read, and 5,000 then 7,000 ms up to a 12-second timeout.

  1. headCommitSha accepts only a review of that commit. Also: headCommitSha: undefined changes nothing.
  2. headCommitSha stops polling as soon as a read shows another commit
  3. a review of another commit is INCOMPLETE even if it failed or stopped, with the head gap last
  4. a review with no head commit cannot complete while headCommitSha is set
  5. headCommitSha refuses anything but a full SHA before sending a request. Also refuses null, with a Buffer in place of Python's bytes.
Change to the source Failing tests
a mismatch does not end the wait 2, 3
a missing head ends the wait too 2, 4
a timeout takes the head reason, as Python does 4
the head gap goes first 3
a review with a head gap can still be COMPLETED 4
heads compared case-sensitively 1, 5
no typeof check on the option 5
null turns the check off 5
a non-string head is a protocol error 4
a present undefined throws 1
the head checked without the option 6 existing wait tests, the shared outcome contract among them

🤖 Generated with Claude Code

A review request targets a pull request, so the review runs on whatever
the head is when the request lands. If the branch moves first, the wait
can report COMPLETED for a commit that will never ship. With
headCommitSha set, a read that shows a different commit stops polling
and returns INCOMPLETE, and a finished review with no recorded head is
never COMPLETED. The reason codes match the Python SDK's head_commit_sha
from Suhas Guruprasad (prooflinedev/sdk-python#49).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant