@@ -182,6 +182,109 @@ process.stdout.write(readFileSync(process.env.ARCHIVE));
182182 } ) ;
183183} ) ;
184184
185+ function runParentJobLogProbe ( shimBody : string ) {
186+ const root = mkdtempSync ( join ( tmpdir ( ) , "release-ci-job-log-" ) ) ;
187+ const shimLog = join ( root , "shim.log" ) ;
188+ const shimGh = join ( root , "gh" ) ;
189+ writeFileSync (
190+ shimGh ,
191+ `#!/usr/bin/env node
192+ import { appendFileSync } from "node:fs";
193+ const args = process.argv.slice(2);
194+ appendFileSync(process.env.SHIM_LOG, JSON.stringify(args) + "\\n");
195+ ${ shimBody }
196+ ` ,
197+ ) ;
198+ chmodSync ( shimGh , 0o755 ) ;
199+
200+ try {
201+ const result = spawnSync (
202+ process . execPath ,
203+ [
204+ "--input-type=module" ,
205+ "--eval" ,
206+ `import { createReleaseEvidenceClient } from ${ JSON . stringify ( pathToFileURL ( resolve ( SCRIPT ) ) . href ) } ;
207+ try {
208+ process.stdout.write(createReleaseEvidenceClient("owner/repo").getJobLog("123"));
209+ } catch (error) {
210+ process.stdout.write(JSON.stringify({
211+ message: error instanceof Error ? error.message : String(error),
212+ stderr: typeof error === "object" && error !== null && "stderr" in error
213+ ? String(error.stderr)
214+ : "",
215+ }));
216+ process.exitCode = 17;
217+ }` ,
218+ ] ,
219+ {
220+ encoding : "utf8" ,
221+ env : {
222+ ...process . env ,
223+ PATH : `${ root } :${ process . env . PATH ?? "" } ` ,
224+ SHIM_LOG : shimLog ,
225+ } ,
226+ } ,
227+ ) ;
228+ return {
229+ calls : readFileSync ( shimLog , "utf8" )
230+ . trim ( )
231+ . split ( "\n" )
232+ . map ( ( line ) => JSON . parse ( line ) ) ,
233+ result,
234+ } ;
235+ } finally {
236+ rmSync ( root , { force : true , recursive : true } ) ;
237+ }
238+ }
239+
240+ describe ( "parent job log compatibility" , ( ) => {
241+ const flaggedArgs = [ "api" , "repos/owner/repo/actions/jobs/123/logs" , "--allow-escape-sequences" ] ;
242+ const legacyArgs = [ "api" , "repos/owner/repo/actions/jobs/123/logs" ] ;
243+
244+ it ( "uses one flagged call when gh supports raw escape-sequence output" , ( ) => {
245+ const { calls, result } = runParentJobLogProbe (
246+ 'process.stdout.write("\\u001b[31mlog\\u001b[0m");' ,
247+ ) ;
248+
249+ expect ( result . status ) . toBe ( 0 ) ;
250+ expect ( result . stderr ) . toBe ( "" ) ;
251+ expect ( result . stdout ) . toBe ( "\u001b[31mlog\u001b[0m" ) ;
252+ expect ( calls ) . toEqual ( [ flaggedArgs ] ) ;
253+ } ) ;
254+
255+ it ( "retries once without the flag for the exact legacy gh error" , ( ) => {
256+ const { calls, result } = runParentJobLogProbe ( `
257+ if (args.includes("--allow-escape-sequences")) {
258+ process.stderr.write("unknown flag: --allow-escape-sequences\\n\\nUsage: gh api <endpoint> [flags]\\n");
259+ process.exit(1);
260+ }
261+ process.stdout.write("\\u001b[31mlegacy log\\u001b[0m");
262+ ` ) ;
263+
264+ expect ( result . status ) . toBe ( 0 ) ;
265+ expect ( result . stderr ) . toBe ( "" ) ;
266+ expect ( result . stdout ) . toBe ( "\u001b[31mlegacy log\u001b[0m" ) ;
267+ expect ( calls ) . toEqual ( [ flaggedArgs , legacyArgs ] ) ;
268+ } ) ;
269+
270+ it ( "propagates unrelated errors without retrying" , ( ) => {
271+ const { calls, result } = runParentJobLogProbe ( `
272+ process.stderr.write("error: unknown flag: --allow-escape-sequences\\n");
273+ process.exit(1);
274+ ` ) ;
275+
276+ expect ( result . status ) . toBe ( 17 ) ;
277+ expect ( result . stderr ) . toBe ( "" ) ;
278+ expect ( JSON . parse ( result . stdout ) ) . toEqual (
279+ expect . objectContaining ( {
280+ message : expect . stringContaining ( "Command failed: gh" ) ,
281+ stderr : "error: unknown flag: --allow-escape-sequences\n" ,
282+ } ) ,
283+ ) ;
284+ expect ( calls ) . toEqual ( [ flaggedArgs ] ) ;
285+ } ) ;
286+ } ) ;
287+
185288describe ( "runReleaseCiGh" , ( ) => {
186289 it ( "bounds each GitHub lookup with a timeout and SIGKILL" , ( ) => {
187290 const execFileSyncImpl = vi . fn ( ( ) => "result" ) ;
0 commit comments