Skip to content

Commit 8ff71e4

Browse files
committed
guard to prevent prs on error
1 parent bac9331 commit 8ff71e4

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,29 @@ describe('runCloudPi', () => {
206206
expect(mockExecuteTool).not.toHaveBeenCalled()
207207
})
208208

209+
it('does not commit, push, or open a PR when the run reports an error on a zero exit', async () => {
210+
mockRun.mockImplementation(
211+
(command: string, options: { onStdout?: (chunk: string) => void }) => {
212+
if (command.includes('git clone')) {
213+
return Promise.resolve({ stdout: '__BASE_SHA__=abc', stderr: '', exitCode: 0 })
214+
}
215+
if (command.includes('pi -p')) {
216+
options.onStdout?.('{"type":"error","error":"model exploded"}\n')
217+
return Promise.resolve({ stdout: '', stderr: '', exitCode: 0 })
218+
}
219+
return Promise.resolve({
220+
stdout: '__CHANGED__=src/x.ts\n__NEEDS_PUSH__=1',
221+
stderr: '',
222+
exitCode: 0,
223+
})
224+
}
225+
)
226+
227+
await expect(runCloudPi(baseParams(), { onEvent: vi.fn() })).rejects.toThrow(/model exploded/)
228+
expect(mockExecuteTool).not.toHaveBeenCalled()
229+
expect(mockRun.mock.calls.some(([cmd]: [string]) => cmd.includes('push'))).toBe(false)
230+
})
231+
209232
it('surfaces the real git push error when the push fails, with the token scrubbed', async () => {
210233
mockRun.mockImplementation((command: string) => {
211234
if (command.includes('git clone')) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ export const runCloudPi: PiBackendRun<PiCloudRunParams> = async (params, context
258258
)
259259
}
260260

261+
if (totals.errorMessage) {
262+
throw new Error(`Pi agent failed: ${totals.errorMessage}`)
263+
}
264+
261265
// Same rationale as the prompt: keep the commit message off the command line.
262266
await runner.writeFile(COMMIT_MSG_PATH, commitMessage)
263267

0 commit comments

Comments
 (0)