Skip to content

Commit d85ef46

Browse files
committed
test(qa-lab): bind teardown order to production plan
1 parent b654ca6 commit d85ef46

2 files changed

Lines changed: 65 additions & 44 deletions

File tree

‎extensions/qa-lab/src/suite.test.ts‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,33 @@ function makeQaSuiteTestLabHandle(): QaLabServerHandle {
3737
}
3838

3939
describe("qa suite", () => {
40-
it("continues transport-before-gateway cleanup after a resource reports failure", async () => {
40+
it("runs the production cleanup plan in dependency order after a failure", async () => {
4141
const calls: string[] = [];
4242
const failure = new Error("transport close failed");
43+
const step = (name: string, error?: Error) => async () => {
44+
calls.push(name);
45+
if (error) {
46+
throw error;
47+
}
48+
};
4349

44-
const errors = await qaSuiteProgressTesting.runQaSuiteCleanupSteps([
45-
async () => {
46-
calls.push("transport");
47-
throw failure;
48-
},
49-
async () => {
50-
calls.push("gateway");
51-
},
52-
async () => {
53-
calls.push("lab");
54-
},
55-
]);
50+
const errors = await qaSuiteProgressTesting.runQaFlowSuiteCleanupPlan({
51+
closeWebSessions: step("web sessions"),
52+
cleanupTransport: step("transport", failure),
53+
stopGateway: step("gateway"),
54+
disposeAgentHarnesses: step("agent harnesses"),
55+
stopProvider: step("provider"),
56+
finishLab: step("lab"),
57+
});
5658

57-
expect(calls).toEqual(["transport", "gateway", "lab"]);
59+
expect(calls).toEqual([
60+
"web sessions",
61+
"transport",
62+
"gateway",
63+
"agent harnesses",
64+
"provider",
65+
"lab",
66+
]);
5867
expect(errors).toEqual([failure]);
5968
});
6069

‎extensions/qa-lab/src/suite.ts‎

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,26 @@ async function runQaSuiteCleanupSteps(steps: ReadonlyArray<() => Promise<void>>)
318318
return errors;
319319
}
320320

321+
async function runQaFlowSuiteCleanupPlan(params: {
322+
closeWebSessions?: () => Promise<void>;
323+
cleanupTransport: () => Promise<void>;
324+
stopGateway?: () => Promise<void>;
325+
disposeAgentHarnesses: () => Promise<void>;
326+
stopProvider?: () => Promise<void>;
327+
finishLab: () => Promise<void>;
328+
}) {
329+
return await runQaSuiteCleanupSteps([
330+
...(params.closeWebSessions ? [params.closeWebSessions] : []),
331+
// Drain transport HTTP work before stopping the gateway; otherwise a completed suite can
332+
// emit an unhandled response-close rejection during delivery.
333+
params.cleanupTransport,
334+
...(params.stopGateway ? [params.stopGateway] : []),
335+
params.disposeAgentHarnesses,
336+
...(params.stopProvider ? [params.stopProvider] : []),
337+
params.finishLab,
338+
]);
339+
}
340+
321341
function throwQaSuiteCleanupErrors(params: {
322342
cleanupErrors: unknown[];
323343
runFailed: boolean;
@@ -2000,40 +2020,31 @@ export async function runQaFlowSuite(params?: QaSuiteRunParams): Promise<QaSuite
20002020
preserveGatewayRuntimeDir = path.join(outputDir, "artifacts", "gateway-runtime");
20012021
throw error;
20022022
} finally {
2003-
const cleanupSteps: Array<() => Promise<void>> = [];
20042023
const activeEnv = env;
2005-
if (activeEnv) {
2006-
cleanupSteps.push(() => closeQaWebSessions(activeEnv.webSessionIds));
2007-
}
2008-
// Drain transport HTTP work before stopping the gateway; otherwise a completed suite can
2009-
// emit an unhandled response-close rejection during delivery.
2010-
cleanupSteps.push(() => transportFactoryResult.cleanup());
20112024
const keepTemp = process.env.OPENCLAW_QA_KEEP_TEMP === "1" || false;
20122025
const activeGateway = gateway;
2013-
if (activeGateway) {
2014-
cleanupSteps.push(() =>
2015-
activeGateway.stop({
2016-
keepTemp,
2017-
preserveToDir: keepTemp ? undefined : preserveGatewayRuntimeDir,
2018-
}),
2019-
);
2020-
}
2021-
cleanupSteps.push(() => disposeRegisteredAgentHarnesses());
20222026
const activeMock = mock;
2023-
if (activeMock) {
2024-
cleanupSteps.push(() => activeMock.stop());
2025-
}
2026-
if (ownsLab) {
2027-
cleanupSteps.push(() => lab.stop());
2028-
} else {
2029-
cleanupSteps.push(async () => {
2030-
lab.setControlUi({
2031-
controlUiUrl: null,
2032-
controlUiProxyTarget: null,
2033-
});
2034-
});
2035-
}
2036-
const cleanupErrors = await runQaSuiteCleanupSteps(cleanupSteps);
2027+
const cleanupErrors = await runQaFlowSuiteCleanupPlan({
2028+
closeWebSessions: activeEnv ? () => closeQaWebSessions(activeEnv.webSessionIds) : undefined,
2029+
cleanupTransport: () => transportFactoryResult.cleanup(),
2030+
stopGateway: activeGateway
2031+
? () =>
2032+
activeGateway.stop({
2033+
keepTemp,
2034+
preserveToDir: keepTemp ? undefined : preserveGatewayRuntimeDir,
2035+
})
2036+
: undefined,
2037+
disposeAgentHarnesses: () => disposeRegisteredAgentHarnesses(),
2038+
stopProvider: activeMock ? () => activeMock.stop() : undefined,
2039+
finishLab: ownsLab
2040+
? () => lab.stop()
2041+
: async () => {
2042+
lab.setControlUi({
2043+
controlUiUrl: null,
2044+
controlUiProxyTarget: null,
2045+
});
2046+
},
2047+
});
20372048
throwQaSuiteCleanupErrors({ cleanupErrors, runFailed, runError });
20382049
}
20392050
}
@@ -2050,6 +2061,7 @@ export const qaSuiteProgressTesting = {
20502061
mergeQaRuntimeEnvPatches,
20512062
parseQaSuiteBooleanEnv,
20522063
remapModelRefForForcedRuntime,
2064+
runQaFlowSuiteCleanupPlan,
20532065
runQaSuiteCleanupSteps,
20542066
throwQaSuiteCleanupErrors,
20552067
resolveQaSuiteControlUiEnabled,

0 commit comments

Comments
 (0)