Skip to content

Commit 5a451f9

Browse files
authored
test(qa): accept structured gateway restart outcomes (#103681)
1 parent 40dc7e5 commit 5a451f9

4 files changed

Lines changed: 28 additions & 13 deletions

File tree

extensions/qa-lab/src/scenario-catalog.test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,20 @@ describe("qa scenario catalog", () => {
435435
expect(readQaScenarioById("long-context-progress-watchdog").sourcePath).toBe(
436436
"qa/scenarios/runtime/long-context-progress-watchdog.yaml",
437437
);
438-
expect(
439-
JSON.stringify(readQaScenarioById("gateway-restart-inflight-run").execution.flow),
440-
).toContain("EmbeddedAttemptSessionTakeoverError");
441-
expect(
442-
JSON.stringify(readQaScenarioById("gateway-restart-inflight-run").execution.flow),
443-
).toContain("AbortError");
444-
expect(
445-
JSON.stringify(readQaScenarioById("gateway-restart-inflight-run").execution.flow),
446-
).toContain("This operation was aborted");
447-
expect(
448-
JSON.stringify(readQaScenarioById("gateway-restart-inflight-run").execution.flow),
449-
).toContain("liveTurnTimeoutMs(env, 180000)");
438+
const gatewayRestartFlow = readQaScenarioById("gateway-restart-inflight-run").execution.flow;
439+
const interruptedStatusAssertion = gatewayRestartFlow?.steps
440+
.flatMap((step) => step.actions)
441+
.find((action) =>
442+
JSON.stringify(action).includes("interrupted agent run ended with unexpected status"),
443+
);
444+
expect(interruptedStatusAssertion).toBeDefined();
445+
const interruptedStatusContract = JSON.stringify(interruptedStatusAssertion);
446+
expect(interruptedStatusContract).toContain("waited.stopReason === 'restart'");
447+
expect(interruptedStatusContract).toContain("waited.stopReason === 'aborted'");
448+
expect(interruptedStatusContract).toContain("EmbeddedAttemptSessionTakeoverError");
449+
expect(interruptedStatusContract).toContain("AbortError");
450+
expect(interruptedStatusContract).toContain("This operation was aborted");
451+
expect(JSON.stringify(gatewayRestartFlow)).toContain("liveTurnTimeoutMs(env, 180000)");
450452
const longContextFlow = JSON.stringify(
451453
readQaScenarioById("long-context-progress-watchdog").execution.flow,
452454
);

extensions/qa-lab/src/suite-runtime-agent-process.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,18 @@ describe("qa suite runtime agent process helpers", () => {
779779
);
780780
});
781781

782+
it.each(["restart", "aborted"])(
783+
"preserves the %s stop reason from agent.wait",
784+
async (stopReason) => {
785+
const result = { status: "error", stopReason };
786+
const gatewayCall = vi.fn(async () => result);
787+
788+
await expect(
789+
waitForAgentRun({ gateway: { call: gatewayCall } } as never, "run-interrupted"),
790+
).resolves.toEqual(result);
791+
},
792+
);
793+
782794
it("caps the gateway client timeout when waiting for oversized agent runs", async () => {
783795
const gatewayCall = vi.fn(async () => ({ status: "ok" }));
784796

extensions/qa-lab/src/suite-runtime-agent-process.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type QaChatHistoryResponse = {
4646
type QaAgentWaitResult = {
4747
status?: string;
4848
error?: string;
49+
stopReason?: string;
4950
};
5051

5152
const ANSI_ESCAPE_PATTERN = new RegExp(String.raw`\x1B\[[0-?]*[ -/]*[@-~]`, "g");

qa/scenarios/runtime/gateway-restart-inflight-run.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ flow:
9696
- expr: started.runId
9797
- expr: liveTurnTimeoutMs(env, 180000)
9898
- assert:
99-
expr: "waited.status === 'ok' || waited.status === 'timeout' || (waited.status === 'error' && (String(waited.error ?? '').includes('EmbeddedAttemptSessionTakeoverError') || String(waited.error ?? '').includes('AbortError') || String(waited.error ?? '').includes('This operation was aborted')))"
99+
expr: "waited.status === 'ok' || waited.status === 'timeout' || (waited.status === 'error' && (waited.stopReason === 'restart' || waited.stopReason === 'aborted' || String(waited.error ?? '').includes('EmbeddedAttemptSessionTakeoverError') || String(waited.error ?? '').includes('AbortError') || String(waited.error ?? '').includes('This operation was aborted')))"
100100
message:
101101
expr: "`interrupted agent run ended with unexpected status: ${JSON.stringify(waited)}`"
102102
- set: interruptedMatches

0 commit comments

Comments
 (0)