Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(test-guard): follow clock readings and wait results [C7]

Corey Olson75e66bffce75
diff --git a/test/wall-clock-budgets.js b/test/wall-clock-budgets.js
index 06a882f5..7ed40fdb 100644
--- a/test/wall-clock-budgets.js
+++ b/test/wall-clock-budgets.js
@@ -66,6 +66,12 @@ function observesTime(expression, aliases) {
|| [...aliases].some(name => new RegExp(`\\b${name}\\b`, 'u').test(expression));
}
+/** Recognize elapsed arithmetic using a separately captured clock observation. */
+function clockDifference(expression, clocks) {
+ return expression.includes('-')
+ && [...clocks].some(name => new RegExp(`\\b${name}\\b`, 'u').test(expression));
+}
+
/** Split a call at its own commas, never at a nested assertion, callback or argument. */
function argumentsOf(call) {
const args = [];
@@ -92,10 +98,18 @@ function literalWait(expression, literals) {
export function fixedWallMargins(source, file) {
const { code, comments } = codeOnly(source);
const lines = source.split('\n');
- const aliases = new Set(), literals = new Set();
- for (const match of code.matchAll(/\b(?:const|let|var)\s+(\w+)\s*=\s*([^;\n]+)/gu)) {
- if (observesTime(match[2], aliases) && /\b(?:Date|performance)\s*\.\s*now\s*\([^)]*\)\s*-/u.test(match[2])) aliases.add(match[1]);
+ const aliases = new Set(), literals = new Set(), clocks = new Set(), waitResults = new Set();
+ const declarations = [...code.matchAll(/\b(?:const|let|var)\s+(\w+)\s*=\s*([^;\n]+)/gu)];
+ for (const match of declarations) {
if (/^\s*[1-9][0-9_]*\s*$/u.test(match[2])) literals.add(match[1]);
+ if (/^\s*(?:Date|performance)\s*\.\s*now\s*\(/u.test(match[2])) clocks.add(match[1]);
+ }
+ for (const match of declarations) {
+ if (observesTime(match[2], aliases) && /\b(?:Date|performance)\s*\.\s*now\s*\([^)]*\)\s*-/u.test(match[2])
+ || clockDifference(match[2], clocks)) aliases.add(match[1]);
+ const waited = /^\s*await\s+(?:\w+\s*\.\s*)*(\w+)\s*\(/u.exec(match[2])?.[1];
+ if (waited && /^(?:\w*wait\w*|event|\w*ClosesWithin|\w*Healthy|\w*Ready)$/iu.test(waited)
+ && literalWait(match[2], literals)) waitResults.add(match[1]);
}
const found = new Map();
/** Require a same-line reason, including an explicit approved-spec promise that cannot be relaxed. */
@@ -110,9 +124,10 @@ export function fixedWallMargins(source, file) {
const call = parenthesized(code, match.index + match[0].lastIndexOf('('));
const args = argumentsOf(call), expression = args[0];
const fixedAlias = [...literals].some(name => new RegExp(`[<>]=?\\s*${name}\\s*$|^\\s*${name}\\s*[<>]=?`, 'u').test(expression));
- if (observesTime(expression, aliases) && (margin.test(expression) || fixedAlias || /^(equal|strictEqual)$/u.test(match[1] ?? '') && new RegExp(`^\\s*${literal}\\s*$`, 'u').test(args[1] ?? ''))) {
+ if ((observesTime(expression, aliases) || clockDifference(expression, clocks)) && (margin.test(expression) || fixedAlias || /^(equal|strictEqual)$/u.test(match[1] ?? '') && new RegExp(`^\\s*${literal}\\s*$`, 'u').test(args[1] ?? ''))) {
record(match.index, 'literal elapsed-time margin');
}
+ if (waitResults.has(expression.trim().replace(/^[(!\s]+|[)\s]+$/gu, ''))) record(match.index, 'literal wait result judged by an assertion');
if ((['rejects', 'doesNotReject'].includes(match[1]) || /\bawait\s+/u.test(expression)) && literalWait(expression, literals)) record(match.index, 'literal wait judged by an assertion');
}
for (const match of code.matchAll(/\bawait\s+(?:\w+\s*\.\s*)*\w*waitFor\w*\s*\(/giu)) {
diff --git a/test/wall-clock-budgets.test.js b/test/wall-clock-budgets.test.js
index edf20ec8..67e6e3e6 100644
--- a/test/wall-clock-budgets.test.js
+++ b/test/wall-clock-budgets.test.js
@@ -7,6 +7,36 @@ import { fileURLToPath } from 'node:url';
import { test } from 'node:test';
import { wallClockViolations } from './wall-clock-budgets.js';
+test('the clock-margin guard follows separately captured clock readings [C7]', () => {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-clock-readings-'));
+ try {
+ const file = join(root, 'readings.test.js');
+ const source = 'const startedAt = Date.now();\nconst finishedAt = Date.now();\nassert.ok(finishedAt - startedAt < 30_000);\n';
+ writeFileSync(file, source);
+ assert.match(wallClockViolations(root).join('\n'), /readings\.test\.js:3: literal elapsed-time margin/u);
+ writeFileSync(file, source.replace('< 30_000);', '< 30_000); // budget: declared observation window is 30000ms.'));
+ assert.deepEqual(wallClockViolations(root), [], 'the asserted margin accepts its same-line reason');
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+});
+
+test('the clock-margin guard follows a fixed wait result into a later assertion [C7]', () => {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-wait-result-'));
+ try {
+ const file = join(root, 'wait-result.test.js');
+ const source = '/** Return false when the child-close deadline wins. */\nfunction childClosesWithin(child, timeoutMs) { return new Promise(resolve => { child.once("close", () => resolve(true)); setTimeout(() => resolve(false), timeoutMs); }); }\nconst closed = await childClosesWithin(child, 1500);\nassert.equal(closed, true);\n';
+ writeFileSync(file, source);
+ assert.match(wallClockViolations(root).join('\n'), /wait-result\.test\.js:4: literal wait result judged by an assertion/u);
+ writeFileSync(file, source.replace('assert.equal(closed, true);', 'assert.equal(closed, true); // budget: hang ceiling for the child-close handshake.'));
+ assert.deepEqual(wallClockViolations(root), [], 'the later judgment accepts its same-line reason');
+ writeFileSync(file, source.replace('assert.equal(closed, true);', ''));
+ assert.deepEqual(wallClockViolations(root), [], 'an unasserted cleanup result is not a timing judgment');
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+});
+
test('no test judges work by a fixed wall-clock margin [C7]', () => {
assert.deepEqual(wallClockViolations(fileURLToPath(new URL('..', import.meta.url))), []);
});