@@ -152,35 +152,6 @@ function expectWriteContains(mock: unknown, fragment: string): void {
152152 ) . toBe ( true ) ;
153153}
154154
155- async function withProcessEnv < T > (
156- values : Record < string , string | undefined > ,
157- run : ( ) => Promise < T > ,
158- ) : Promise < T > {
159- const previous = new Map (
160- Object . keys ( values ) . map (
161- ( key ) => [ key , process . env [ key ] ] satisfies [ string , string | undefined ] ,
162- ) ,
163- ) ;
164- for ( const [ key , value ] of Object . entries ( values ) ) {
165- if ( value === undefined ) {
166- delete process . env [ key ] ;
167- } else {
168- process . env [ key ] = value ;
169- }
170- }
171- try {
172- return await run ( ) ;
173- } finally {
174- for ( const [ key , value ] of previous ) {
175- if ( value === undefined ) {
176- delete process . env [ key ] ;
177- } else {
178- process . env [ key ] = value ;
179- }
180- }
181- }
182- }
183-
184155function makeQaEvidence ( entries : unknown [ ] = [ ] ) {
185156 return {
186157 kind : "openclaw.qa.evidence-summary" ,
@@ -390,6 +361,7 @@ describe("qa cli runtime", () => {
390361 afterEach ( async ( ) => {
391362 stdoutWrite . mockRestore ( ) ;
392363 stderrWrite . mockRestore ( ) ;
364+ vi . unstubAllEnvs ( ) ;
393365 vi . clearAllMocks ( ) ;
394366 await fs . rm ( suiteArtifactsDir , { recursive : true , force : true } ) ;
395367 await fs . rm ( telegramArtifactsDir , { recursive : true , force : true } ) ;
@@ -1039,24 +1011,18 @@ describe("qa cli runtime", () => {
10391011 await fs . writeFile ( launcherPath , "#!/bin/sh\nexit 0\n" , { mode : 0o700 } ) ;
10401012 await fs . writeFile ( preloadPath , "export {};\n" , { mode : 0o600 } ) ;
10411013 await fs . writeFile ( runtimeEntryPath , "export {};\n" , { mode : 0o600 } ) ;
1042- await withProcessEnv (
1043- {
1044- OPENCLAW_QA_TELEGRAM_SUT_FORWARDED_ENV_KEYS : "HOME,PATH" ,
1045- OPENCLAW_QA_TELEGRAM_SUT_CLEANUP_TIMEOUT_MS : "60000" ,
1046- OPENCLAW_QA_TELEGRAM_SUT_GID : "1002" ,
1047- OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND : launcherPath ,
1048- OPENCLAW_QA_TELEGRAM_SUT_PRELOAD_PATH : preloadPath ,
1049- OPENCLAW_QA_TELEGRAM_SUT_PROCESS_BOUNDARY_DIR : boundaryDir ,
1050- OPENCLAW_QA_TELEGRAM_SUT_RUNTIME_EXECUTABLE : process . execPath ,
1051- OPENCLAW_QA_TELEGRAM_SUT_UID : "1001" ,
1052- } ,
1053- async ( ) => {
1054- await runQaTelegramCommand ( {
1055- repoRoot : candidateRoot ,
1056- scenarioIds : [ "telegram-help-command" , "telegram-stream-final-single-message" ] ,
1057- } ) ;
1058- } ,
1059- ) ;
1014+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_FORWARDED_ENV_KEYS" , "HOME,PATH" ) ;
1015+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_CLEANUP_TIMEOUT_MS" , "60000" ) ;
1016+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_GID" , "1002" ) ;
1017+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND" , launcherPath ) ;
1018+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_PRELOAD_PATH" , preloadPath ) ;
1019+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_PROCESS_BOUNDARY_DIR" , boundaryDir ) ;
1020+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_RUNTIME_EXECUTABLE" , process . execPath ) ;
1021+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_UID" , "1001" ) ;
1022+ await runQaTelegramCommand ( {
1023+ repoRoot : candidateRoot ,
1024+ scenarioIds : [ "telegram-help-command" , "telegram-stream-final-single-message" ] ,
1025+ } ) ;
10601026
10611027 const sutOpenClawCommand = {
10621028 executablePath : launcherPath ,
@@ -1081,21 +1047,13 @@ describe("qa cli runtime", () => {
10811047 } ) ;
10821048
10831049 it ( "rejects relative Telegram launcher paths before starting a gateway" , async ( ) => {
1084- await withProcessEnv (
1085- {
1086- OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND : "relative-launcher" ,
1087- } ,
1088- async ( ) => {
1089- await expect (
1090- runQaTelegramCommand ( {
1091- repoRoot : "/tmp/openclaw-repo" ,
1092- scenarioIds : [ "telegram-help-command" ] ,
1093- } ) ,
1094- ) . rejects . toThrow (
1095- "OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND must be an absolute file path." ,
1096- ) ;
1097- } ,
1098- ) ;
1050+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND" , "relative-launcher" ) ;
1051+ await expect (
1052+ runQaTelegramCommand ( {
1053+ repoRoot : "/tmp/openclaw-repo" ,
1054+ scenarioIds : [ "telegram-help-command" ] ,
1055+ } ) ,
1056+ ) . rejects . toThrow ( "OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND must be an absolute file path." ) ;
10991057
11001058 expect ( runCanonicalLiveScenarios ) . not . toHaveBeenCalled ( ) ;
11011059 expect ( runTelegramQaLive ) . not . toHaveBeenCalled ( ) ;
@@ -1104,58 +1062,40 @@ describe("qa cli runtime", () => {
11041062 it ( "rejects non-executable Telegram launcher files before starting a gateway" , async ( ) => {
11051063 const launcherPath = path . join ( telegramArtifactsDir , "non-executable-launcher" ) ;
11061064 await fs . writeFile ( launcherPath , "#!/bin/sh\nexit 0\n" , { mode : 0o600 } ) ;
1107- await withProcessEnv (
1108- {
1109- OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND : launcherPath ,
1110- } ,
1111- async ( ) => {
1112- await expect (
1113- runQaTelegramCommand ( {
1114- repoRoot : "/tmp/openclaw-repo" ,
1115- scenarioIds : [ "telegram-help-command" ] ,
1116- } ) ,
1117- ) . rejects . toThrow (
1118- `OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND must point to an executable regular file: ${ launcherPath } ` ,
1119- ) ;
1120- } ,
1065+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND" , launcherPath ) ;
1066+ await expect (
1067+ runQaTelegramCommand ( {
1068+ repoRoot : "/tmp/openclaw-repo" ,
1069+ scenarioIds : [ "telegram-help-command" ] ,
1070+ } ) ,
1071+ ) . rejects . toThrow (
1072+ `OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND must point to an executable regular file: ${ launcherPath } ` ,
11211073 ) ;
11221074
11231075 expect ( runCanonicalLiveScenarios ) . not . toHaveBeenCalled ( ) ;
11241076 expect ( runTelegramQaLive ) . not . toHaveBeenCalled ( ) ;
11251077 } ) ;
11261078
11271079 it ( "rejects unknown mixed Telegram selections before resolving the SUT launcher" , async ( ) => {
1128- await withProcessEnv (
1129- {
1130- OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND : "relative-launcher" ,
1131- } ,
1132- async ( ) => {
1133- await expect (
1134- runQaTelegramCommand ( {
1135- repoRoot : "/tmp/openclaw-repo" ,
1136- scenarioIds : [ "telegram-help-command" , "missing-telegram-scenario" ] ,
1137- } ) ,
1138- ) . rejects . toThrow ( "unknown Telegram QA scenario id(s): missing-telegram-scenario" ) ;
1139- } ,
1140- ) ;
1080+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND" , "relative-launcher" ) ;
1081+ await expect (
1082+ runQaTelegramCommand ( {
1083+ repoRoot : "/tmp/openclaw-repo" ,
1084+ scenarioIds : [ "telegram-help-command" , "missing-telegram-scenario" ] ,
1085+ } ) ,
1086+ ) . rejects . toThrow ( "unknown Telegram QA scenario id(s): missing-telegram-scenario" ) ;
11411087
11421088 expect ( runCanonicalLiveScenarios ) . not . toHaveBeenCalled ( ) ;
11431089 expect ( runTelegramQaLive ) . not . toHaveBeenCalled ( ) ;
11441090 } ) ;
11451091
11461092 it ( "prints telegram scenario catalog without resolving the SUT launcher" , async ( ) => {
1147- await withProcessEnv (
1148- {
1149- OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND : "relative-launcher" ,
1150- } ,
1151- async ( ) => {
1152- await runQaTelegramCommand ( {
1153- repoRoot : "/tmp/openclaw-repo" ,
1154- providerMode : "mock-openai" ,
1155- listScenarios : true ,
1156- } ) ;
1157- } ,
1158- ) ;
1093+ vi . stubEnv ( "OPENCLAW_QA_TELEGRAM_SUT_OPENCLAW_COMMAND" , "relative-launcher" ) ;
1094+ await runQaTelegramCommand ( {
1095+ repoRoot : "/tmp/openclaw-repo" ,
1096+ providerMode : "mock-openai" ,
1097+ listScenarios : true ,
1098+ } ) ;
11591099
11601100 expect ( listTelegramQaScenarioCatalog ) . toHaveBeenCalledWith ( "mock-openai" ) ;
11611101 expect ( runCanonicalLiveScenarios ) . not . toHaveBeenCalled ( ) ;
0 commit comments