test(#4517): migrate hook/guard invocation batch to named timeout constants (#4608)

Batch 6 of 17 in the ad hoc timeout literal migration (epic #4445).
Replaces every bare numeric timeout/timeoutMs object-literal property in
tests/read-guard.test.cjs, tests/feat-2483-review-claude-mds-guard.test.cjs,
tests/gsd-write-guard.test.cjs, tests/gsd-secret-read-guard.test.cjs, and
tests/hooks-crash-policy.test.cjs with a named constant, per
eslint-rules/no-adhoc-timeout-literal.cjs. Removes the 5 files from the
rule's allowlist.

Reuses existing tests/helpers/timeouts.cjs class norms where the shape
matches (QUICK_SPAWN_TIMEOUT_MS x2, PROBE_TIMEOUT_MS x1). Adds two
file-local constants for classes not shared across files:
READ_GUARD_HOOK_TIMEOUT_MS (read-guard.test.cjs's 4 sites, a tighter
no-fan-out bound than QUICK_SPAWN_TIMEOUT_MS with no bench data to widen
it) and FIXTURE_PROBE_CAPABILITY_TIMEOUT_MS (fixture data, not a real
spawn timeout).

The fifth site (feat-2483-review-claude-mds-guard.test.cjs's review-lane
invoke spawn) was initially classified onto HOOK_FANOUT_TIMEOUT_MS;
isolated Spec-axis review caught that this call is one nested spawn, not
the multi-spawn git-hook fan-out shape that constant's own doc comment
defines. Corrected to a new file-local REVIEW_LANE_INVOKE_TIMEOUT_MS
holding the exact pre-existing 60000ms value under an honest name,
rather than narrowing to PROBE_TIMEOUT_MS with no bench justification.

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:
Tom Boucher
2026-09-10 15:36:43 -04:00
committed by GitHub
parent 93ba63aeff
commit 138e70d734
6 changed files with 60 additions and 18 deletions

View File

@@ -28,6 +28,12 @@ const { createTempDir, cleanup } = require('./helpers.cjs');
const HOOK_PATH = path.join(__dirname, '..', 'hooks', 'gsd-read-guard.js');
// Bounds a single direct invocation of the advisory-only, no-subprocess
// gsd-read-guard.js hook; tighter than the shared QUICK_SPAWN_TIMEOUT_MS norm
// (10000ms) despite a similar "no fan-out" class — kept as its own constant
// since this migration never widens a bound without a fresh bench citation.
const READ_GUARD_HOOK_TIMEOUT_MS = 5000;
/**
* Run the read guard hook with a given tool input payload.
* Returns { exitCode, stdout, stderr }.
@@ -45,7 +51,7 @@ function runHook(payload, envOverrides = {}) {
CLAUDE_PROJECT_DIR: '',
...envOverrides,
};
const r = runHookSeam(HOOK_PATH, [], { input, env, timeoutMs: 5000 });
const r = runHookSeam(HOOK_PATH, [], { input, env, timeoutMs: READ_GUARD_HOOK_TIMEOUT_MS });
if (r.exitCode === 0) {
return { exitCode: 0, stdout: r.stdout.trim(), stderr: '' };
}
@@ -152,7 +158,7 @@ describe('gsd-read-guard hook', () => {
const stdout = execFileSync(process.execPath, [HOOK_PATH], {
input: 'not json',
encoding: 'utf-8',
timeout: 5000,
timeout: READ_GUARD_HOOK_TIMEOUT_MS,
stdio: ['pipe', 'pipe', 'pipe'],
});
// Should exit 0 silently
@@ -284,6 +290,12 @@ const { createTempDir, cleanup } = require('./helpers.cjs');
const HOOK_PATH = path.join(__dirname, '..', 'hooks', 'gsd-read-guard.js');
// Bounds a single direct invocation of the advisory-only, no-subprocess
// gsd-read-guard.js hook; tighter than the shared QUICK_SPAWN_TIMEOUT_MS norm
// (10000ms) despite a similar "no fan-out" class — kept as its own constant
// since this migration never widens a bound without a fresh bench citation.
const READ_GUARD_HOOK_TIMEOUT_MS = 5000;
function runHook(payload, envOverrides = {}) {
const input = JSON.stringify(payload);
const env = {
@@ -295,7 +307,7 @@ function runHook(payload, envOverrides = {}) {
CLAUDE_PROJECT_DIR: '',
...envOverrides,
};
const r = runHookSeam(HOOK_PATH, [], { input, env, timeoutMs: 5000 });
const r = runHookSeam(HOOK_PATH, [], { input, env, timeoutMs: READ_GUARD_HOOK_TIMEOUT_MS });
if (r.exitCode === 0) {
return { exitCode: 0, stdout: r.stdout.trim(), stderr: '' };
}
@@ -394,6 +406,12 @@ const { createTempDir, cleanup } = require('./helpers.cjs');
const HOOK_PATH = path.join(__dirname, '..', 'hooks', 'gsd-read-guard.js');
// Bounds a single direct invocation of the advisory-only, no-subprocess
// gsd-read-guard.js hook; tighter than the shared QUICK_SPAWN_TIMEOUT_MS norm
// (10000ms) despite a similar "no fan-out" class — kept as its own constant
// since this migration never widens a bound without a fresh bench citation.
const READ_GUARD_HOOK_TIMEOUT_MS = 5000;
/**
* Spawn the hook with an env that mirrors the actual Claude Code hook
* subprocess env: CLAUDECODE and CLAUDE_SESSION_ID are stripped, only
@@ -419,7 +437,7 @@ function runHookInClaudeCodeSubprocess(payload, envOverrides = {}) {
const stdout = execFileSync(process.execPath, [HOOK_PATH], {
input,
encoding: 'utf-8',
timeout: 5000,
timeout: READ_GUARD_HOOK_TIMEOUT_MS,
stdio: ['pipe', 'pipe', 'pipe'],
env,
});