GeezerVison is showing github.com — test(server): assert automatic background cleanup after provider exit · pingdotgg/t3code@83f34b6
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2 stop_background_work_after_failed_turn
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts +9-17Lines changed: 9 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4168,7 +4168,7 @@ describe("CodexAdapterV2 post-settle continuation", () => { | 4168 | 4168 | ); | 4169 | 4169 | }); | 4170 | 4170 |
| 4171 | | - it.effect("Stop ends a background command no Codex process tracks any more", () => | | 4171 | + it.effect("settles a background command automatically after the Codex process exits", () => | 4172 | 4172 | Effect.scoped( | 4173 | 4173 | Effect.gen(function* () { | 4174 | 4174 | const fs = yield* FileSystem.FileSystem; | @@ -4244,27 +4244,19 @@ describe("CodexAdapterV2 post-settle continuation", () => { | 4244 | 4244 | yield* worker.drain(); | 4245 | 4245 | yield* Fiber.join(settled); | 4246 | 4246 | yield* worker.drain(); | 4247 | | - const before = yield* orchestrator.getThreadShell(threadId); | 4248 | | - assert.deepEqual( | 4249 | | - before?.pendingBackgroundTasks?.map((task) => task.kind), | 4250 | | - ["command"], | 4251 | | - "the thread still shows the command the gone process never finished", | 4252 | | - ); | 4253 | | - const run = (yield* orchestrator.getThreadProjection(threadId)).runs.at(-1)!; | 4254 | | - yield* orchestrator.dispatch({ | 4255 | | - type: "run.interrupt", | 4256 | | - commandId: CommandId.make("stop-background-untracked"), | 4257 | | - threadId, | 4258 | | - runId: run.id, | 4259 | | - holdQueue: true, | 4260 | | - }); | 4261 | | - yield* worker.drain(); | 4262 | 4247 | const projection = yield* orchestrator.getThreadProjection(threadId); | 4263 | 4248 | assert.deepEqual( | 4264 | 4249 | projection.turnItems.flatMap((item) => | 4265 | 4250 | item.type === "command_execution" ? [item.status] : [], | 4266 | 4251 | ), | 4267 | | - ["interrupted"], | | 4252 | + ["failed"], | | 4253 | + ); | | 4254 | + const command = projection.turnItems.find((item) => item.type === "command_execution"); | | 4255 | + assert.isDefined(command); | | 4256 | + assert.isNotNull(command?.completedAt); | | 4257 | + assert.notInclude( | | 4258 | + projection.turnItems.map((item) => item.type), | | 4259 | + "run_interrupt_request", | 4268 | 4260 | ); | 4269 | 4261 | assert.equal(projection.runs.at(-1)?.status, "completed"); | 4270 | 4262 | assert.deepEqual( | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/testkit/fixtures/index.ts +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1798,7 +1798,7 @@ export const ORCHESTRATOR_REPLAY_FIXTURES: ReadonlyArray<OrchestratorReplayFixtu | 1798 | 1798 | ], | 1799 | 1799 | }, | 1800 | 1800 | { | 1801 | | - name: "stop_background_work_after_failed_turn", | | 1801 | + name: "background_work_settles_after_failed_turn", | 1802 | 1802 | buildInput: stopBackgroundWorkAfterFailedTurnInput, | 1803 | 1803 | providers: [ | 1804 | 1804 | { | @@ -1807,13 +1807,14 @@ export const ORCHESTRATOR_REPLAY_FIXTURES: ReadonlyArray<OrchestratorReplayFixtu | 1807 | 1807 | "./stop_background_work_after_failed_turn/registry_transcript.ndjson", | 1808 | 1808 | import.meta.url, | 1809 | 1809 | ), | | 1810 | + recordedScenario: "stop_background_work_after_failed_turn", | 1810 | 1811 | modelSelection: ACP_REGISTRY_MODEL_SELECTION, | 1811 | 1812 | assertOutput: assertStopBackgroundWorkAfterFailedTurnOutput, | 1812 | 1813 | }, | 1813 | 1814 | ], | 1814 | 1815 | }, | 1815 | 1816 | { | 1816 | | - name: "stop_background_work_after_release", | | 1817 | + name: "background_work_stays_settled_after_release", | 1817 | 1818 | buildInput: stopBackgroundWorkAfterReleaseInput, | 1818 | 1819 | providers: [ | 1819 | 1820 | { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/testkit/fixtures/stop_background_work_after_failed_turn/input.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ export function stopBackgroundWorkAfterFailedTurnInput(): OrchestratorFixtureInp | 7 | 7 | return { | 8 | 8 | steps: [ | 9 | 9 | { type: "message", text: STOP_BACKGROUND_WORK_AFTER_FAILED_TURN_PROMPT }, | 10 | | - { type: "stop_background_work", targetRunIndex: 1 }, | | 10 | + { type: "capture_shell_snapshot", key: "after-exit" }, | 11 | 11 | ], | 12 | 12 | }; | 13 | 13 | } | @@ -17,7 +17,7 @@ export function stopBackgroundWorkAfterReleaseInput(): OrchestratorFixtureInput | 17 | 17 | steps: [ | 18 | 18 | { type: "message", text: STOP_BACKGROUND_WORK_AFTER_FAILED_TURN_PROMPT }, | 19 | 19 | { type: "advance_clock", duration: "31 minutes" }, | 20 | | - { type: "stop_background_work", targetRunIndex: 1 }, | | 20 | + { type: "capture_shell_snapshot", key: "after-exit" }, | 21 | 21 | ], | 22 | 22 | }; | 23 | 23 | } |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/testkit/fixtures/stop_background_work_after_failed_turn/output.ts +8-7Lines changed: 8 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,21 +19,22 @@ export function assertStopBackgroundWorkAfterFailedTurnOutput( | 19 | 19 | assertSemanticProjectionIntegrity(projection); | 20 | 20 | assertUserMessagesInclude(projection, [STOP_BACKGROUND_WORK_AFTER_FAILED_TURN_PROMPT]); | 21 | 21 |
| 22 | | - const before = result.capturedShellSnapshots | 23 | | - .get("before-stop") | | 22 | + const afterExit = result.capturedShellSnapshots | | 23 | + .get("after-exit") | 24 | 24 | ?.threads.find((thread) => thread.id === projection.thread.id); | 25 | 25 | assert.deepEqual( | 26 | | - before?.pendingBackgroundTasks?.map((task) => task.kind), | 27 | | - ["command"], | 28 | | - "the failed turn leaves its command on the Waiting strip", | | 26 | + afterExit?.pendingBackgroundTasks, | | 27 | + [], | | 28 | + "provider exit settles the failed turn's background command", | 29 | 29 | ); | 30 | 30 |
| 31 | 31 | const command = projection.turnItems.find((item) => item.type === "command_execution"); | 32 | | - assert.equal(command?.status, "interrupted"); | | 32 | + assert.isDefined(command); | | 33 | + assert.equal(command?.status, "failed"); | 33 | 34 | assert.isNotNull(command?.completedAt); | 34 | 35 | const shell = result.shellSnapshot.threads.find((thread) => thread.id === projection.thread.id); | 35 | 36 | assert.deepEqual(shell?.pendingBackgroundTasks ?? [], []); | 36 | | - assert.include( | | 37 | + assert.notInclude( | 37 | 38 | projection.turnItems.map((item) => item.type), | 38 | 39 | "run_interrupt_request", | 39 | 40 | ); | |
|