Skip to content

Commit 5aaf5fd

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(pi): follow replacement update PRs
1 parent 364ed55 commit 5aaf5fd

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

apps/sim/executor/handlers/pi/cloud-backend.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ function branchParams(overrides: Partial<PiCloudBranchRunParams> = {}): PiCloudB
8181
}
8282
}
8383

84-
function existingPullRequestOutput() {
84+
function existingPullRequestOutput(pullNumber = 7) {
8585
return {
8686
success: true,
8787
output: {
8888
title: 'Feature',
8989
body: '',
90-
html_url: 'https://github.com/octo/demo/pull/7',
90+
html_url: `https://github.com/octo/demo/pull/${pullNumber}`,
9191
state: 'open',
9292
merged: false,
9393
mergeable: true,
@@ -849,6 +849,28 @@ describe('runCloudPi', () => {
849849
expect(result.prUrl).toBe('https://github.com/octo/demo/pull/1')
850850
})
851851

852+
it('updates the one replacement PR found after authoring', async () => {
853+
mockExecuteTool
854+
.mockResolvedValueOnce({
855+
success: true,
856+
output: { items: [{ number: 7 }], count: 1 },
857+
})
858+
.mockResolvedValueOnce(existingPullRequestOutput())
859+
.mockResolvedValueOnce({
860+
success: true,
861+
output: { items: [{ number: 8 }], count: 1 },
862+
})
863+
.mockResolvedValueOnce(existingPullRequestOutput(8))
864+
.mockResolvedValueOnce(existingPullRequestOutput(8))
865+
866+
const result = await runCloudBranchPi(branchParams(), { onEvent: vi.fn() })
867+
868+
expect(result.prUrl).toBe('https://github.com/octo/demo/pull/8')
869+
expect(
870+
mockExecuteTool.mock.calls.some(([tool]: [string]) => tool === 'github_create_pr')
871+
).toBe(false)
872+
})
873+
852874
it('does not claim a push happened when no-op authoring is followed by a PR error', async () => {
853875
mockRun.mockImplementation((command: string) => {
854876
if (command.includes('git clone')) {

apps/sim/executor/handlers/pi/cloud-backend.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ async function updatePullRequest(
291291
async function ensureUpdatePullRequest(
292292
params: PiCloudBranchRunParams,
293293
branch: string,
294-
existingPullRequest: BranchPullRequest | undefined,
295294
totals: PiRunTotals,
296295
secrets: readonly string[],
297296
signal?: AbortSignal
@@ -305,11 +304,6 @@ async function ensureUpdatePullRequest(
305304
},
306305
signal
307306
)
308-
if (existingPullRequest) {
309-
if (currentPullRequest && currentPullRequest.pullNumber !== existingPullRequest.pullNumber) {
310-
throw new Error(`The open pull request for branch ${branch} changed during authoring`)
311-
}
312-
}
313307
if (currentPullRequest) {
314308
return updatePullRequest(params, currentPullRequest, secrets, signal)
315309
}
@@ -421,10 +415,9 @@ async function runCloudAuthoringPi(
421415
)
422416
const totals = createPiTotals()
423417
const thinking = mapThinkingLevel(params.thinkingLevel) ?? 'medium'
424-
let existingPullRequest: BranchPullRequest | undefined
425418
if (params.mode === 'cloud_branch') {
426419
try {
427-
existingPullRequest = await findOpenPrForBranch(
420+
await findOpenPrForBranch(
428421
{
429422
owner: params.owner,
430423
repo: params.repo,
@@ -599,14 +592,7 @@ async function runCloudAuthoringPi(
599592

600593
let pullRequest: OpenedPullRequest
601594
if (params.mode === 'cloud_branch') {
602-
pullRequest = await ensureUpdatePullRequest(
603-
params,
604-
branch,
605-
existingPullRequest,
606-
totals,
607-
secrets,
608-
context.signal
609-
)
595+
pullRequest = await ensureUpdatePullRequest(params, branch, totals, secrets, context.signal)
610596
} else {
611597
const base = params.baseBranch?.trim() || detectedBase
612598
if (!base) {

0 commit comments

Comments
 (0)