From d1c9b02fabf4305cb65b171b6e9a817e5d084788 Mon Sep 17 00:00:00 2001 From: Alexzhu Date: Wed, 3 Jun 2026 06:29:27 +0800 Subject: [PATCH] fix(scripts): add short help to GitHub test map (#3223) --- .../build-github-test-map-help.test.mjs | 44 +++++++++++++++++++ .../test-planning/build-github-test-map.mjs | 4 +- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 scripts/__tests__/build-github-test-map-help.test.mjs diff --git a/scripts/__tests__/build-github-test-map-help.test.mjs b/scripts/__tests__/build-github-test-map-help.test.mjs new file mode 100644 index 000000000..7eb198b11 --- /dev/null +++ b/scripts/__tests__/build-github-test-map-help.test.mjs @@ -0,0 +1,44 @@ +import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import fs from 'node:fs'; +import os from 'node:os'; +import { dirname, join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { test } from 'node:test'; + +const HERE = dirname(fileURLToPath(import.meta.url)); +const SCRIPT = resolve(HERE, '..', 'test-planning', 'build-github-test-map.mjs'); + +function writeFailingStub(binDir, name) { + fs.writeFileSync( + join(binDir, name), + `#!/usr/bin/env sh\necho "${name} should not run for help" >&2\nexit 99\n`, + { mode: 0o755 }, + ); +} + +function runHelp(flag) { + const binDir = fs.mkdtempSync(join(os.tmpdir(), 'openhuman-test-map-stub-')); + for (const name of ['gh', 'codex', 'claude']) { + writeFailingStub(binDir, name); + } + + return spawnSync(process.execPath, [SCRIPT, flag], { + encoding: 'utf8', + env: { + ...process.env, + PATH: `${binDir}${process.platform === 'win32' ? ';' : ':'}${process.env.PATH ?? ''}`, + }, + }); +} + +test('build-github-test-map help exits before fetch or synthesis work', () => { + for (const flag of ['--help', '-h']) { + const result = runHelp(flag); + + assert.equal(result.status, 0, result.stderr); + assert.match(result.stdout, /Usage: build-github-test-map\.mjs \[options\]/); + assert.match(result.stdout, /-h, --help\s+Show this message/); + assert.equal(result.stderr, ''); + } +}); diff --git a/scripts/test-planning/build-github-test-map.mjs b/scripts/test-planning/build-github-test-map.mjs index 5304ed9ae..86b1f007c 100644 --- a/scripts/test-planning/build-github-test-map.mjs +++ b/scripts/test-planning/build-github-test-map.mjs @@ -29,7 +29,7 @@ Options: --prompt-body-chars Max body chars per item sent to the LLM (default: ${DEFAULT_PROMPT_BODY_CHARS}) --llm Non-interactive CLI to use for synthesis (default: ${DEFAULT_LLM}) --model Optional model override for the LLM CLI - --help Show this message + -h, --help Show this message Examples: node scripts/test-planning/build-github-test-map.mjs --max-prs 50 --max-issues 50 @@ -63,7 +63,7 @@ function parseArgs(argv) { if (arg === '--') { continue; } - if (arg === '--help') { + if (arg === '--help' || arg === '-h') { printUsage(); process.exit(0); }