enhance(#3907): gates report no-input instead of a verdict they never reached (#3932)

* feat(#3907): gates report no-input instead of asserting a verdict they never reached

The three stdin-reading gates bound 2 to a stdin read error only, with no arm for stdin closed at zero bytes - so empty input flowed into the detector, found nothing, and exited 1, which each module's own comment defines as a negative verdict. An unset PHASE_SECTION made the UI gate assert the phase has no UI. Empty and whitespace-only input now exit NO_INPUT, and a read error exits UNAVAILABLE rather than a locally-invented 2, both resolved through the registry and delivered by terminateNow.

The exit code was only half of it: under --json the same input emitted {detected:false}, byte-identical to the fabricated payload #3909 exists to fix, and the blocking coverage gate reads that payload. Empty input now emits the in-tree {skipped:true,reason} form with no detected key at all.

teams-status is excluded: it never reads stdin and has no invented 2, so the four-module framing in the issue and ADR is wrong. The dead root bin/lib/ui-safety-gate.cjs is deleted - no installer reference, no workflow invocation, and the live fallback chains are for other modules. Its removal restores the unit tests to the module that actually ships; they had been asserting the stale copy's two-field shape, which is why it drifted unnoticed.

* fix(#3907): drive gate tests through the process seam, and make removed-but-needed basename-precise

CONTRIBUTING requires every subprocess go through tests/helpers/process-seam.cjs; two of the three gate suites hand-rolled spawnSync while the third, added in the same change, used runNode correctly for the identical injection case. Converted the blocks this change added, leaving pre-existing ones alone.

Deleting one of two files sharing a basename made lint-removed-but-needed report 14 references that were all to the surviving canonical module - the false-positive class its own docstring names. It now matches on the deleted file's full path when a surviving file shares its basename, which is more precise rather than weaker: a genuine full-path reference still fails, and behaviour is unchanged when no basename collides. It immediately caught a docstring on this branch that spelled the deleted path.

* test(#3907): update the one existing assertion that pinned the old empty-stdin verdict

A pre-existing test asserted exit 1 on empty stdin - the defect this phase removes - and was missed because the change added new blocks without auditing existing ones pinning the old contract. Audited the rest: the other three status-1 assertions in that file all feed real input and are the genuine-negative controls that must keep returning 1, so exactly one was stale. The retired 2 is gone from the describe's contract comment too.

* chore(#3907): backfill changeset pr number

---------

Co-authored-by: sim <sim@local>
This commit is contained in:
Tom Boucher
2026-08-27 11:37:31 -04:00
committed by GitHub
parent ad6abc8965
commit c5f2b94b27
16 changed files with 838 additions and 177 deletions

View File

@@ -6,13 +6,15 @@
* rendered prose — per RULESET.TESTS (no raw text matching on outputs).
*
* The detector mirrors ui-safety-gate.cts: a pure function plus a STDIN-reading
* CLI (exit 0 = signal detected, 1 = none, 2 = usage error).
* CLI (exit 0 = signal detected, 1 = none; NO_INPUT/UNAVAILABLE registry codes
* for empty/whitespace-only stdin and a stdin read error, per ADR-3889 Phase 3).
*/
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const { spawnSync } = require('node:child_process');
const path = require('node:path');
const { exitCodeFor } = require('../gsd-core/bin/lib/exit-code-registry.cjs');
const MODULE_PATH = path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'assumption-delta.cjs');
@@ -174,7 +176,10 @@ describe('detectAssumptionDelta — pure detector (#1561)', () => {
});
describe('assumption-delta CLI — STDIN exit codes (mirrors ui-safety-gate)', () => {
// Exit code contract: 0 = signal detected, 1 = none, 2 = usage/startup error.
// Exit code contract: 0 = signal detected, 1 = genuine negative (real input,
// no signal). Empty/whitespace-only stdin and a stdin read error are NOT
// "1" — nothing was examined, so they resolve NO_INPUT / UNAVAILABLE via
// the exit-code registry (see the ADR-3889 Phase 3 describe block below).
function runCli(stdin) {
const res = spawnSync(process.execPath, [MODULE_PATH], {
input: stdin,
@@ -194,9 +199,13 @@ describe('assumption-delta CLI — STDIN exit codes (mirrors ui-safety-gate)', (
assert.strictEqual(r.status, 1);
});
test('exit 1 on empty stdin (no signal)', () => {
// Empty stdin is NOT a "no signal" verdict — nothing was examined, so it
// must be distinct from the genuine-negative case directly above (real
// input, no cue found). Per ADR-3889 Phase 3 (#3907), it resolves the
// registry's NO_INPUT code, never a hardcoded exit status.
test('exit NO_INPUT on empty stdin (nothing examined, not a genuine negative)', () => {
const r = runCli('');
assert.strictEqual(r.status, 1);
assert.strictEqual(r.status, exitCodeFor('NO_INPUT'));
});
test('--json emits typed IR with detected field on stdout (exit 0)', () => {
@@ -249,6 +258,115 @@ describe('assumption-delta CLI — STDIN exit codes (mirrors ui-safety-gate)', (
});
});
// ──────────────────────────────────────────────────────────────────────────────
// ADR-3889 Phase 3 (#3907): NO_INPUT / UNAVAILABLE — empty/whitespace-only
// stdin and a stdin read error must not be reported as the authoritative
// "no signal" verdict (exit 1). Spawns the REAL module and asserts on the
// child's exit status + parsed stdout, per RULESET.TESTS.
// ──────────────────────────────────────────────────────────────────────────────
describe('assumption-delta CLI — NO_INPUT / UNAVAILABLE (ADR-3889 Phase 3, #3907)', () => {
const INJECT_STDIN_ERROR = path.join(__dirname, 'helpers', 'inject-stdin-error.cjs');
const { runNode } = require('./helpers/process-seam.cjs');
const { PROBE_TIMEOUT_MS } = require('./helpers/timeouts.cjs');
function runCliJson(stdin, extraArgs = [], extraEnv = {}) {
const r = runNode([MODULE_PATH, '--json', ...extraArgs], {
input: stdin,
timeoutMs: PROBE_TIMEOUT_MS,
env: { ...process.env, ...extraEnv },
});
return { exitCode: r.exitCode, stdout: r.stdout, stderr: r.stderr };
}
// ── The controls (load-bearing): without these, "always return NO_INPUT"
// would satisfy the empty/whitespace-only assertions below. ──────────────
test('control: detected input still exits 0 with unchanged --json payload', () => {
const r = runCliJson('This phase adds a second platform alongside the existing one.');
assert.strictEqual(r.exitCode, 0);
const body = JSON.parse(r.stdout);
assert.strictEqual(body.detected, true);
assert.ok(!('skipped' in body));
});
test('control: genuine-negative (real input, no signal) still exits 1, not NO_INPUT', () => {
const r = runCliJson('Refactor the login function to be smaller.');
assert.strictEqual(r.exitCode, 1);
const body = JSON.parse(r.stdout);
assert.strictEqual(body.detected, false);
assert.deepStrictEqual(body.signals, []);
assert.ok(!('skipped' in body));
});
test('empty stdin exits NO_INPUT (registry integer, never hardcoded)', () => {
const r = runCliJson('');
assert.strictEqual(r.exitCode, exitCodeFor('NO_INPUT'));
});
test('whitespace-only stdin (spaces / newlines / tabs / CRLF) exits NO_INPUT', () => {
for (const ws of [' ', '\n\n\n', '\t\t\t', '\r\n\r\n', ' \n\t\r\n ']) {
const r = runCliJson(ws);
assert.strictEqual(r.exitCode, exitCodeFor('NO_INPUT'), `ws=${JSON.stringify(ws)}`);
}
});
test('"x" and " x " are REAL input — must NOT be NO_INPUT', () => {
const bare = runCliJson('x');
assert.notStrictEqual(bare.exitCode, exitCodeFor('NO_INPUT'));
assert.strictEqual(bare.exitCode, 1);
const padded = runCliJson(' x ');
assert.notStrictEqual(padded.exitCode, exitCodeFor('NO_INPUT'));
assert.strictEqual(padded.exitCode, 1);
});
test('a NUL byte is real input (not stripped by whitespace trimming)', () => {
const r = runCliJson('\0');
assert.notStrictEqual(r.exitCode, exitCodeFor('NO_INPUT'));
assert.strictEqual(r.exitCode, 1);
});
test('--json empty stdin: {"skipped":true,"reason":"no_input"} with NO detected key', () => {
const r = runCliJson('');
const body = JSON.parse(r.stdout);
assert.deepStrictEqual(body, { skipped: true, reason: 'no_input' });
assert.ok(!('detected' in body));
});
test('--terms foo with empty stdin is still NO_INPUT (flag does not bypass the input check)', () => {
const r = runCliJson('', ['--terms', 'foo']);
assert.strictEqual(r.exitCode, exitCodeFor('NO_INPUT'));
});
test('empty --terms value still restores curated defaults (unrelated to stdin gating)', () => {
const r = runCliJson('adds a second platform', ['--terms', '']);
assert.strictEqual(r.exitCode, 0, 'empty --terms must fall back to defaults → still detects');
const body = JSON.parse(r.stdout);
assert.strictEqual(body.detected, true);
});
test('a stdin read error exits UNAVAILABLE (injected via monkeypatched process.stdin, not chmod)', () => {
const r = runNode(['-r', INJECT_STDIN_ERROR, MODULE_PATH, '--json'], { timeoutMs: PROBE_TIMEOUT_MS });
assert.strictEqual(r.exitCode, exitCodeFor('UNAVAILABLE'));
const body = JSON.parse(r.stdout);
assert.deepStrictEqual(body, { skipped: true, reason: 'stdin_error' });
assert.ok(!('detected' in body));
assert.notStrictEqual(body.reason, 'no_input', 'stdin_error must be distinguishable from no_input');
});
test('NO_INPUT / UNAVAILABLE codes are identical under GSD_EXIT_CONTRACT=v1 and v2', () => {
for (const version of ['v1', 'v2']) {
const emptyResult = runCliJson('', [], { GSD_EXIT_CONTRACT: version });
assert.strictEqual(emptyResult.exitCode, exitCodeFor('NO_INPUT'), `NO_INPUT under ${version}`);
const errResult = runNode(['-r', INJECT_STDIN_ERROR, MODULE_PATH, '--json'], {
timeoutMs: PROBE_TIMEOUT_MS,
env: { ...process.env, GSD_EXIT_CONTRACT: version },
});
assert.strictEqual(errResult.exitCode, exitCodeFor('UNAVAILABLE'), `UNAVAILABLE under ${version}`);
}
});
});
// ─── Hardening (Codex Step-4 review fixes) ────────────────────────────────────
describe('assumption-delta hardening (Codex review)', () => {
const { detectAssumptionDelta } = require(MODULE_PATH);