@@ -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+
321341function 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