Batch 15 of the ad hoc timeout literal migration (epic #4445). Replaces every bare numeric timeout/timeoutMs object-literal property in tests/check-predicate.test.cjs, tests/gate-predicate-evaluator.test.cjs, tests/policy-160-route0-resume.test.cjs, tests/phase6-capstone-conformance.test.cjs, and tests/prohibition-enforcement.test.cjs with a named constant, per eslint-rules/no-adhoc-timeout-literal.cjs. Removes these 5 files from the rule's allowlist. Ground truth via eslint found 17 sites, not the issue's stated 16 -- prohibition-enforcement.test.cjs has 2 sites, not 1 -- disclosed in the PR body. Reuses QUICK_SPAWN_TIMEOUT_MS and LOOP_HOOK_POINT_CLI_TIMEOUT_MS across 1 file; no new shared constants needed. Adds file-local constants for a real bounded-shell subprocess class (including one deliberately non-generous value to force a timeout), a predicate's own declarative timeout FIELD as fixture/validation data (including a deliberately-invalid zero/negative pair proving rejection), a heavier gsd-tools.cjs check CLI dispatch tier, and two distinct deliberately-short enforcement bounds forcing a fast hang-timeout path. No src/bin file touched, no numeric value changed anywhere. Co-authored-by: sim <sim@local> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,21 @@ const { evaluatePredicate } = require('../gsd-core/bin/lib/gate-predicate-evalua
|
||||
const { buildPredicateDeps, parsePredicateFlags } = require('../gsd-core/bin/lib/check-command-router.cjs');
|
||||
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
||||
|
||||
/**
|
||||
* A real, bounded `sh -c` subprocess spawned via the production
|
||||
* runBoundedShell dependency -- the describe block's own name is "real
|
||||
* bounded sh -c subprocess."
|
||||
*/
|
||||
const BOUNDED_SHELL_PROBE_TIMEOUT_MS = 5000;
|
||||
|
||||
/**
|
||||
* The same runBoundedShell call as BOUNDED_SHELL_PROBE_TIMEOUT_MS, but
|
||||
* deliberately tiny (not generous headroom) to force a `sleep 1` command
|
||||
* past the bound within this test's own lifetime, proving "timeout kills
|
||||
* the subprocess (SIGTERM => timedOut:true)."
|
||||
*/
|
||||
const BOUNDED_SHELL_FORCED_TIMEOUT_MS = 100;
|
||||
|
||||
// ─── buildPredicateDeps: real subprocess exit mapping ─────────────────────────
|
||||
|
||||
describe('buildPredicateDeps — real bounded sh -c subprocess', () => {
|
||||
@@ -30,30 +45,30 @@ describe('buildPredicateDeps — real bounded sh -c subprocess', () => {
|
||||
const cwd = process.cwd();
|
||||
|
||||
test('`true` => exitCode 0, not timed out', () => {
|
||||
const r = deps.runBoundedShell({ command: 'true', cwd, timeoutMs: 5000 });
|
||||
const r = deps.runBoundedShell({ command: 'true', cwd, timeoutMs: BOUNDED_SHELL_PROBE_TIMEOUT_MS });
|
||||
assert.equal(r.exitCode, 0);
|
||||
assert.equal(r.timedOut, false);
|
||||
});
|
||||
|
||||
test('`false` => exitCode 1, not timed out', () => {
|
||||
const r = deps.runBoundedShell({ command: 'false', cwd, timeoutMs: 5000 });
|
||||
const r = deps.runBoundedShell({ command: 'false', cwd, timeoutMs: BOUNDED_SHELL_PROBE_TIMEOUT_MS });
|
||||
assert.equal(r.exitCode, 1);
|
||||
assert.equal(r.timedOut, false);
|
||||
});
|
||||
|
||||
test('`exit 3` => exitCode 3', () => {
|
||||
const r = deps.runBoundedShell({ command: 'exit 3', cwd, timeoutMs: 5000 });
|
||||
const r = deps.runBoundedShell({ command: 'exit 3', cwd, timeoutMs: BOUNDED_SHELL_PROBE_TIMEOUT_MS });
|
||||
assert.equal(r.exitCode, 3);
|
||||
});
|
||||
|
||||
test('stderr is captured from the subprocess', () => {
|
||||
const r = deps.runBoundedShell({ command: 'echo oops >&2; exit 4', cwd, timeoutMs: 5000 });
|
||||
const r = deps.runBoundedShell({ command: 'echo oops >&2; exit 4', cwd, timeoutMs: BOUNDED_SHELL_PROBE_TIMEOUT_MS });
|
||||
assert.equal(r.exitCode, 4);
|
||||
assert.match(r.stderr, /oops/);
|
||||
});
|
||||
|
||||
test('timeout kills the subprocess (SIGTERM => timedOut:true)', () => {
|
||||
const r = deps.runBoundedShell({ command: 'sleep 1', cwd, timeoutMs: 100 });
|
||||
const r = deps.runBoundedShell({ command: 'sleep 1', cwd, timeoutMs: BOUNDED_SHELL_FORCED_TIMEOUT_MS });
|
||||
assert.equal(r.timedOut, true);
|
||||
assert.equal(r.signal, 'SIGTERM');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user