()
| 4 | 'Run exactly this command and do not summarize until it finishes: sleep 8 && echo "done". After it finishes, reply with exactly "done".' |
| 5 | |
| 6 | async function main() { |
| 7 | const firstStartRequestId = `start-a-${Date.now()}` |
| 8 | const secondStartRequestId = `start-b-${Date.now()}` |
| 9 | const shutdownRequestId = `shutdown-${Date.now()}` |
| 10 | |
| 11 | let initSeen = false |
| 12 | let firstStartAccepted = false |
| 13 | let secondStartSent = false |
| 14 | let sawTaskBusyError = false |
| 15 | let sentShutdown = false |
| 16 | |
| 17 | await runStreamCase({ |
| 18 | onEvent(event: StreamEvent, context) { |
| 19 | if (event.type === "system" && event.subtype === "init" && !initSeen) { |
| 20 | initSeen = true |
| 21 | context.sendCommand({ |
| 22 | command: "start", |
| 23 | requestId: firstStartRequestId, |
| 24 | prompt: LONG_PROMPT, |
| 25 | }) |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | if ( |
| 30 | event.type === "control" && |
| 31 | event.subtype === "ack" && |
| 32 | event.command === "start" && |
| 33 | event.requestId === firstStartRequestId && |
| 34 | !firstStartAccepted |
| 35 | ) { |
| 36 | firstStartAccepted = true |
| 37 | context.sendCommand({ |
| 38 | command: "start", |
| 39 | requestId: secondStartRequestId, |
| 40 | prompt: "What is 1+1? Reply with only 2.", |
| 41 | }) |
| 42 | secondStartSent = true |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | if ( |
| 47 | event.type === "control" && |
| 48 | event.subtype === "error" && |
| 49 | event.command === "start" && |
| 50 | event.requestId === secondStartRequestId && |
| 51 | event.code === "task_busy" |
| 52 | ) { |
| 53 | sawTaskBusyError = true |
| 54 | if (!sentShutdown) { |
| 55 | context.sendCommand({ |
| 56 | command: "shutdown", |
| 57 | requestId: shutdownRequestId, |
| 58 | }) |
| 59 | sentShutdown = true |
| 60 | } |
| 61 | return |
| 62 | } |
| 63 | }, |
no test coverage detected