* test(#3314): backfill deterministic clock-seam coverage (failing-first) Replaces loose regex/range assertions with exact-value and boundary tests for the CLI-subprocess and in-process clock-touching call sites identified by H2's audit (epic #3053): cmdCurrentTimestamp, _wsParseRetryAfter (commands.cts), cmdInitManager's is_active gate and cmdInitQuick's quick_id generation (init.cts), and reapStaleTempFiles (io.cts). The CLI-subprocess-pinned tests are expected RED until a follow-up commit routes those call sites through realClock so GSD_TEST_MODE+GSD_NOW_MS can reach them. * refactor(#3314): route CLI-subprocess clock reads through realClock cmdCurrentTimestamp, cmdInitManager's is_active gate, and cmdInitQuick's quick_id generation read Date directly, which the GSD_TEST_MODE+GSD_NOW_MS subprocess pin cannot reach (it only fires inside realClock.now()). Behavior-preserving: realClock.now() falls through to Date.now() whenever GSD_TEST_MODE is unset, which is every real invocation. * docs(#3314): amend ADR-456 with reachability-based clock-control rule ADR-456 §(a) documented one mechanism (injected {clock=Date} + t.mock.timers). Adds the two this repo already relies on: t.mock.timers for in-process direct-Date reads, and the GSD_TEST_MODE+GSD_NOW_MS subprocess pin (routed through realClock) for CLI-spawned code. Updates TESTING-STANDARDS.md's matching passages, which already referenced this issue by number as the no-elapsed-assertion promotion precondition. * fix(#3314): address orthogonal review findings Spec-axis findings: file and link the no-elapsed-assertion promotion follow-up (#3331) instead of leaving TESTING-STANDARDS.md pointing at a dead #1885, and ship the module-by-module audit table in the ADR itself rather than only in a gitignored phase artifact. Standards-axis finding: pin the "hour-old file = not active" test via GSD_TEST_MODE+GSD_NOW_MS for consistency with the reachability rule this PR's own ADR amendment now documents. --------- Co-authored-by: sim <sim@local>
This commit is contained in:
@@ -311,6 +311,45 @@ describe('reapStaleTempFiles (via io)', () => {
|
||||
io.reapStaleTempFiles('gsd-io-nonexistent-prefix-xyz-', { maxAgeMs: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
// #3314 — ADR-456 in-process reachability: t.mock.timers patches the
|
||||
// process-global Date, so it controls `now` inside reapStaleTempFiles with
|
||||
// no production code change needed. Both sides of the comparison (mocked
|
||||
// "now" and the fs.utimesSync mtime) use second-aligned epoch values to
|
||||
// avoid filesystem mtime sub-second-precision truncation on filesystems
|
||||
// that round mtime to the nearest second.
|
||||
describe('boundary: age exactly at maxAgeMs (condition is strictly-greater)', () => {
|
||||
const MTIME_MS = 1_700_000_000_000; // second-aligned
|
||||
const MAX_AGE_MS = 5000;
|
||||
|
||||
function plantFileAtAge(t, ageMs) {
|
||||
fs.mkdirSync(io.GSD_TEMP_DIR, { recursive: true });
|
||||
const p = path.join(io.GSD_TEMP_DIR, TEST_PREFIX + `boundary-${ageMs}.json`);
|
||||
fs.writeFileSync(p, '{}');
|
||||
fs.utimesSync(p, new Date(MTIME_MS), new Date(MTIME_MS));
|
||||
t.mock.timers.enable(['Date']);
|
||||
t.mock.timers.setTime(MTIME_MS + ageMs);
|
||||
return p;
|
||||
}
|
||||
|
||||
test('boundary: age exactly maxAgeMs-1 is kept', (t) => {
|
||||
const p = plantFileAtAge(t, MAX_AGE_MS - 1);
|
||||
io.reapStaleTempFiles(TEST_PREFIX, { maxAgeMs: MAX_AGE_MS });
|
||||
assert.ok(fs.existsSync(p), 'file at maxAgeMs-1 must be kept');
|
||||
});
|
||||
|
||||
test('boundary: age exactly maxAgeMs is kept (condition is strictly-greater)', (t) => {
|
||||
const p = plantFileAtAge(t, MAX_AGE_MS);
|
||||
io.reapStaleTempFiles(TEST_PREFIX, { maxAgeMs: MAX_AGE_MS });
|
||||
assert.ok(fs.existsSync(p), 'file at exactly maxAgeMs must be kept — condition is strictly-greater, not >=');
|
||||
});
|
||||
|
||||
test('boundary: age exactly maxAgeMs+1 is removed', (t) => {
|
||||
const p = plantFileAtAge(t, MAX_AGE_MS + 1);
|
||||
io.reapStaleTempFiles(TEST_PREFIX, { maxAgeMs: MAX_AGE_MS });
|
||||
assert.ok(!fs.existsSync(p), 'file at maxAgeMs+1 must be removed');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user