Part 1 of 2 of the n/no-process-exit cleanup (umbrella #738): convert every process.exit() call in standalone scripts/** CLIs to the rule-compliant pattern. - New shared helper scripts/lib/cli-exit.cjs: ExitError(code,message) + runMain() which translates a thrown ExitError / returned number into process.exitCode (never process.exit()), flushing output and still firing process.on('exit'). - main()-based entrypoints: throw new ExitError(code) for errors, return <code> for verdicts; invoked via runMain(main). Child exit codes preserved via return. - top-level-only scripts: imperative body extracted into main() so mid-flow aborts (throw ExitError) actually halt; pure consts/helpers stay at module scope. - diff-touches-shipped-paths.cjs: stdin event handling restructured to an async read so the whole flow runs under runMain; uncaughtException/unhandledRejection nets replaced by an in-band catch that preserves EXIT_ERROR=2. Exit codes verified unchanged for every converted script (success/error/help and the 0/1/2 semantic codes in diff-touches). Rule stays warn here; flipped to error in part 2 (#738) once gsd-core/bin/** is also clean. Refs #739 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
'use strict';
|
|
// ci-prepare-test-scope.cjs — Write .ci-selected-tests.txt for scoped CI runs.
|
|
// Replaces the inline bash "Prepare scoped test list" step.
|
|
// Shell-agnostic: invoked as `node scripts/ci-prepare-test-scope.cjs` from any shell.
|
|
//
|
|
// Required environment variables (set by the workflow step's `env:` block):
|
|
// TEST_SCOPE — "windows" | "targeted"
|
|
// TARGETED_TESTS — space-separated test file list (from ci-test-scope.cjs output)
|
|
// WINDOWS_TESTS — space-separated test file list for the windows lane
|
|
//
|
|
// Writes: .ci-selected-tests.txt (one file per line, no blanks)
|
|
// Exit 0 = success; exit 1 = unknown scope.
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const { ExitError, runMain } = require('./lib/cli-exit.cjs');
|
|
|
|
const scope = process.env.TEST_SCOPE || '';
|
|
const targeted = process.env.TARGETED_TESTS || '';
|
|
const windows = process.env.WINDOWS_TESTS || '';
|
|
|
|
const FALLBACK = 'tests/command-contract.test.cjs tests/commands.test.cjs tests/core.test.cjs tests/package-manifest.test.cjs';
|
|
|
|
function main() {
|
|
let selected;
|
|
if (scope === 'windows') {
|
|
selected = windows;
|
|
} else if (scope === 'targeted') {
|
|
selected = targeted;
|
|
} else {
|
|
throw new ExitError(1, `::error::Unknown test scope: ${scope}`);
|
|
}
|
|
|
|
// Trim and fall back to default set if empty.
|
|
if (!selected.trim()) {
|
|
selected = FALLBACK;
|
|
}
|
|
|
|
// Split on whitespace, filter blanks, join with newlines.
|
|
const lines = selected.split(/\s+/).filter(Boolean);
|
|
const content = lines.join('\n') + '\n';
|
|
|
|
const outPath = path.join(process.cwd(), '.ci-selected-tests.txt');
|
|
fs.writeFileSync(outPath, content, 'utf-8');
|
|
|
|
process.stdout.write('Scoped tests:\n');
|
|
process.stdout.write(content);
|
|
}
|
|
|
|
runMain(main);
|