Skip to content

Commit eef857f

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(pi): follow replacement update PRs
1 parent 9261847 commit eef857f

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
@@ -84,13 +84,13 @@ function branchParams(overrides: Partial<PiCloudBranchRunParams> = {}): PiCloudB
8484
}
8585
}
8686

87-
function existingPullRequestOutput() {
87+
function existingPullRequestOutput(pullNumber = 7) {
8888
return {
8989
success: true,
9090
output: {
9191
title: 'Feature',
9292
body: '',
93-
html_url: 'https://github.com/octo/demo/pull/7',
93+
html_url: `https://github.com/octo/demo/pull/${pullNumber}`,
9494
state: 'open',
9595
merged: false,
9696
mergeable: true,
@@ -852,6 +852,28 @@ describe('runCloudPi', () => {
852852
expect(result.prUrl).toBe('https://github.com/octo/demo/pull/1')
853853
})
854854

855+
it('updates the one replacement PR found after authoring', async () => {
856+
mockExecuteTool
857+
.mockResolvedValueOnce({
858+
success: true,
859+
output: { items: [{ number: 7 }], count: 1 },
860+
})
861+
.mockResolvedValueOnce(existingPullRequestOutput())
862+
.mockResolvedValueOnce({
863+
success: true,
864+
output: { items: [{ number: 8 }], count: 1 },
865+
})
866+
.mockResolvedValueOnce(existingPullRequestOutput(8))
867+
.mockResolvedValueOnce(existingPullRequestOutput(8))
868+
869+
const result = await runCloudBranchPi(branchParams(), { onEvent: vi.fn() })
870+
871+
expect(result.prUrl).toBe('https://github.com/octo/demo/pull/8')
872+
expect(
873+
mockExecuteTool.mock.calls.some(([tool]: [string]) => tool === 'github_create_pr')
874+
).toBe(false)
875+
})
876+
855877
it('does not claim a push happened when no-op authoring is followed by a PR error', async () => {
856878
mockRun.mockImplementation((command: string) => {
857879
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
@@ -294,7 +294,6 @@ async function updatePullRequest(
294294
async function ensureUpdatePullRequest(
295295
params: PiCloudBranchRunParams,
296296
branch: string,
297-
existingPullRequest: BranchPullRequest | undefined,
298297
totals: PiRunTotals,
299298
secrets: readonly string[],
300299
signal?: AbortSignal
@@ -308,11 +307,6 @@ async function ensureUpdatePullRequest(
308307
},
309308
signal
310309
)
311-
if (existingPullRequest) {
312-
if (currentPullRequest && currentPullRequest.pullNumber !== existingPullRequest.pullNumber) {
313-
throw new Error(`The open pull request for branch ${branch} changed during authoring`)
314-
}
315-
}
316310
if (currentPullRequest) {
317311
return updatePullRequest(params, currentPullRequest, secrets, signal)
318312
}
@@ -431,10 +425,9 @@ async function runCloudAuthoringPi(
431425
)
432426
const totals = createPiTotals()
433427
const thinking = mapThinkingLevel(params.thinkingLevel) ?? 'medium'
434-
let existingPullRequest: BranchPullRequest | undefined
435428
if (params.mode === 'cloud_branch') {
436429
try {
437-
existingPullRequest = await findOpenPrForBranch(
430+
await findOpenPrForBranch(
438431
{
439432
owner: params.owner,
440433
repo: params.repo,
@@ -614,14 +607,7 @@ async function runCloudAuthoringPi(
614607

615608
let pullRequest: OpenedPullRequest
616609
if (params.mode === 'cloud_branch') {
617-
pullRequest = await ensureUpdatePullRequest(
618-
params,
619-
branch,
620-
existingPullRequest,
621-
totals,
622-
secrets,
623-
context.signal
624-
)
610+
pullRequest = await ensureUpdatePullRequest(params, branch, totals, secrets, context.signal)
625611
} else {
626612
const base = params.baseBranch?.trim() || detectedBase
627613
if (!base) {

0 commit comments

Comments
 (0)