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): follow waited results through boolean judgments [C7]

Corey Olsonc6fd15fb2022
diff --git a/test/wall-clock-budgets.js b/test/wall-clock-budgets.js
index 7ed40fdb..ae0f31af 100644
--- a/test/wall-clock-budgets.js
+++ b/test/wall-clock-budgets.js
@@ -94,6 +94,12 @@ function literalWait(expression, literals) {
return false;
}
+/** Recognize tracked wait-result references while excluding property names and object keys. */
+function judgesWaitResult(expression, waitResults) {
+ const values = expression.replace(/\.\s*\w+|\b\w+\s*:/gu, ' ');
+ return [...values.matchAll(/\b\w+\b/gu)].some(match => waitResults.has(match[0]));
+}
+
/** Find every literal timing judgment and return its original file, line and source text. */
export function fixedWallMargins(source, file) {
const { code, comments } = codeOnly(source);
@@ -127,7 +133,9 @@ export function fixedWallMargins(source, file) {
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');
+ const judged = /^(?:equal|notEqual|strictEqual|notStrictEqual|deepEqual|notDeepEqual|deepStrictEqual|notDeepStrictEqual|partialDeepStrictEqual)$/u.test(match[1] ?? '')
+ ? args.slice(0, 2) : args.slice(0, 1);
+ if (judged.some(argument => judgesWaitResult(argument, waitResults))) 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 67e6e3e6..e120d5be 100644
--- a/test/wall-clock-budgets.test.js
+++ b/test/wall-clock-budgets.test.js
@@ -37,6 +37,29 @@ test('the clock-margin guard follows a fixed wait result into a later assertion
}
});
+test('the clock-margin guard follows waited results through boolean assertions [C7]', () => {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-wait-boolean-'));
+ try {
+ const file = join(root, 'wait-boolean.test.js');
+ const prefix = '/** 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);\n';
+ for (const judgment of ['assert.ok(closed === true)', 'assert.ok(closed !== false)', 'assert(closed && true)',
+ 'assert.ok(Boolean(closed))', 'assert.strictEqual(true, closed)', 'assert.deepEqual({closed}, {closed: true})']) {
+ writeFileSync(file, prefix + judgment + ';\n');
+ assert.match(wallClockViolations(root).join('\n'), /wait-boolean\.test\.js:4: literal wait result judged by an assertion/u, judgment);
+ writeFileSync(file, prefix + judgment + '; // budget: hang ceiling for the child-close handshake.\n');
+ assert.deepEqual(wallClockViolations(root), [], 'the boolean judgment accepts its same-line reason');
+ }
+ for (const judgment of ['assert.ok(response.closed === true)', 'assert.equal(true, true, closed)',
+ 'assert.ok(true, closed === false)', 'assert.deepEqual({closed: true}, {closed: true})',
+ 'assert.ok("closed === true")', 'console.log(closed)']) {
+ writeFileSync(file, prefix + judgment + ';\n');
+ assert.deepEqual(wallClockViolations(root), [], judgment + ' does not judge the waited result');
+ }
+ } 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))), []);
});