From 5f68c8b0bc4ed3650702453360854058bc7b5969 Mon Sep 17 00:00:00 2001 From: Baker B Date: Tue, 5 May 2026 21:58:26 -0400 Subject: [PATCH] fix(integration-tests): use spawnSync to capture both stdout+stderr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The execSync(cmd 2>&1) approach didn't work in GitHub Actions runners — gh --help still produced empty output even with stderr merged. Switch to spawnSync which gives separate stdout/stderr buffers we can concatenate. Also unset PAGER vars to defeat any pager-detection short-circuiting (some gh versions check terminal capabilities and suppress --help output if pagination is unavailable). This is a follow-up to the prior captureHelp commit on this branch. --- tests/integration/cli-flag-shapes.test.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/integration/cli-flag-shapes.test.ts b/tests/integration/cli-flag-shapes.test.ts index a0fc9c4..6c33544 100644 --- a/tests/integration/cli-flag-shapes.test.ts +++ b/tests/integration/cli-flag-shapes.test.ts @@ -10,15 +10,24 @@ */ import { describe, test, expect } from 'bun:test'; -import { execSync } from 'child_process'; +import { execSync, spawnSync } from 'child_process'; // --- Helper ---------------------------------------------------------------- -// `gh` and `glab` write `--help` output to stderr in some environments -// (notably GitHub Actions runners); locally they write to stdout. We need -// both. `2>&1` merges stderr into stdout so `execSync`'s captured output -// contains the help text regardless of where the CLI sent it. +// `gh` and `glab` may write `--help` output to either stdout or stderr +// depending on environment, version, and whether a TTY is attached. On +// GitHub Actions runners, gh writes --help to a stream that bash's `2>&1` +// redirection through execSync doesn't capture reliably (likely related +// to gh's pager/TTY detection). +// +// Use spawnSync — it separates stdout and stderr buffers and we concatenate +// them — to get the help text regardless of where the CLI sent it. function captureHelp(cmd: string): string { - return execSync(`${cmd} 2>&1`, { encoding: 'utf8' }); + const tokens = cmd.split(/\s+/); + const result = spawnSync(tokens[0]!, tokens.slice(1), { + encoding: 'utf8', + env: { ...process.env, GH_PAGER: '', PAGER: 'cat', GLAB_PAGER: '' }, + }); + return (result.stdout ?? '') + (result.stderr ?? ''); } // --- CLI Availability Guards -----------------------------------------------