-
Notifications
You must be signed in to change notification settings - Fork 37
fix(code-review): use stable GitHub PR checkout refs #2852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alex-alecu
wants to merge
4
commits into
main
Choose a base branch
from
fix/code-review-pr-ref-checkout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c8022b1
fix(code-review): use stable GitHub PR checkout refs
alex-alecu ae457a7
fix(code-review): disable GitHub pull-ref session reuse
alex-alecu 7ac37bf
Merge remote-tracking branch 'origin/main' into fix/code-review-pr-re…
alex-alecu 0265949
Merge branch 'main' into fix/code-review-pr-ref-checkout
alex-alecu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
apps/web/src/lib/code-reviews/triggers/prepare-review-payload.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import { db } from '@/lib/drizzle'; | ||
| import type { CodeReviewAgentConfig } from '@/lib/agent-config/core/types'; | ||
| import { insertTestUser } from '@/tests/helpers/user.helper'; | ||
| import { cloud_agent_code_reviews, kilocode_users, type User } from '@kilocode/db/schema'; | ||
| import { eq } from 'drizzle-orm'; | ||
| import { prepareReviewPayload } from './prepare-review-payload'; | ||
|
|
||
| const REPO = `test-org/prepare-review-payload-${Date.now()}`; | ||
|
|
||
| const codeReviewConfig = { | ||
| review_style: 'balanced', | ||
| focus_areas: ['bugs'], | ||
| custom_instructions: null, | ||
| max_review_time_minutes: 20, | ||
| model_slug: 'anthropic/claude-sonnet-4.5', | ||
| repository_selection_mode: 'all', | ||
| gate_threshold: 'off', | ||
| } satisfies CodeReviewAgentConfig; | ||
|
|
||
| describe('prepareReviewPayload', () => { | ||
| let testUser: User; | ||
|
|
||
| beforeAll(async () => { | ||
| testUser = await insertTestUser(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await db | ||
| .delete(cloud_agent_code_reviews) | ||
| .where(eq(cloud_agent_code_reviews.owned_by_user_id, testUser.id)); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await db.delete(kilocode_users).where(eq(kilocode_users.id, testUser.id)); | ||
| }); | ||
|
|
||
| it('uses the stable GitHub pull ref for agent checkout when the stored head_ref is a branch name', async () => { | ||
| const prNumber = 1234; | ||
| const [review] = await db | ||
| .insert(cloud_agent_code_reviews) | ||
| .values({ | ||
| owned_by_user_id: testUser.id, | ||
| repo_full_name: REPO, | ||
| pr_number: prNumber, | ||
| pr_url: `https://github.com/${REPO}/pull/${prNumber}`, | ||
| pr_title: 'Test PR with deleted source branch', | ||
| pr_author: 'octocat', | ||
| base_ref: 'main', | ||
| head_ref: 'feature/deleted-after-merge', | ||
| head_sha: 'sha-current', | ||
| platform: 'github', | ||
| status: 'pending', | ||
| }) | ||
| .returning({ id: cloud_agent_code_reviews.id }); | ||
|
|
||
| if (!review) { | ||
| throw new Error('Expected inserted review'); | ||
| } | ||
|
|
||
| const payload = await prepareReviewPayload({ | ||
| reviewId: review.id, | ||
| owner: { | ||
| type: 'user', | ||
| id: testUser.id, | ||
| userId: testUser.id, | ||
| }, | ||
| agentConfig: { | ||
| config: codeReviewConfig, | ||
| }, | ||
| platform: 'github', | ||
| }); | ||
|
|
||
| expect(payload.sessionInput).toMatchObject({ | ||
| githubRepo: REPO, | ||
| platform: 'github', | ||
| upstreamBranch: 'refs/pull/1234/head', | ||
| }); | ||
| }); | ||
|
|
||
| it('does not continue previous cloud-agent sessions for GitHub pull-ref reviews', async () => { | ||
| const prNumber = 1235; | ||
| const repo = `${REPO}-session-continuation`; | ||
|
|
||
| await db.insert(cloud_agent_code_reviews).values({ | ||
| owned_by_user_id: testUser.id, | ||
| repo_full_name: repo, | ||
| pr_number: prNumber, | ||
| pr_url: `https://github.com/${repo}/pull/${prNumber}`, | ||
| pr_title: 'Previous completed review', | ||
| pr_author: 'octocat', | ||
| base_ref: 'main', | ||
| head_ref: 'feature/old-head', | ||
| head_sha: 'sha-previous', | ||
| platform: 'github', | ||
| status: 'completed', | ||
| session_id: 'previous-cloud-agent-session', | ||
| }); | ||
|
|
||
| const [review] = await db | ||
| .insert(cloud_agent_code_reviews) | ||
| .values({ | ||
| owned_by_user_id: testUser.id, | ||
| repo_full_name: repo, | ||
| pr_number: prNumber, | ||
| pr_url: `https://github.com/${repo}/pull/${prNumber}`, | ||
| pr_title: 'Current review', | ||
| pr_author: 'octocat', | ||
| base_ref: 'main', | ||
| head_ref: 'feature/current-head', | ||
| head_sha: 'sha-current', | ||
| platform: 'github', | ||
| status: 'pending', | ||
| }) | ||
| .returning({ id: cloud_agent_code_reviews.id }); | ||
|
|
||
| if (!review) { | ||
| throw new Error('Expected inserted review'); | ||
| } | ||
|
|
||
| const payload = await prepareReviewPayload({ | ||
| reviewId: review.id, | ||
| owner: { | ||
| type: 'user', | ||
| id: testUser.id, | ||
| userId: testUser.id, | ||
| }, | ||
| agentConfig: { | ||
| config: codeReviewConfig, | ||
| }, | ||
| platform: 'github', | ||
| }); | ||
|
|
||
| expect(payload.previousCloudAgentSessionId).toBeUndefined(); | ||
| expect(payload.sessionInput).toMatchObject({ | ||
| githubRepo: repo, | ||
| platform: 'github', | ||
| upstreamBranch: 'refs/pull/1235/head', | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Follow-up reviews can run against a stale checkout
upstreamBranchis now the syntheticrefs/pull/<number>/headref. The cloud-agent checkout path fetches that ref into a local branch without configuring an upstream, while v2 incremental reviews reusepreviousCloudAgentSessionIdand only send a follow-up message. On a later push, the incremental prompt'sgit pullcannot update this branch, so the agent can read files from the previous commit while reviewing the current PR diff. Please make the follow-up path fetch/checkout this pull ref again, or pin the checkout tohead_sha, before starting the review.