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): inspect both compared clock arguments [C7]

Corey Olson7e129d89e3fb
diff --git a/test/wall-clock-budgets.js b/test/wall-clock-budgets.js
index f6d7b3a7..eccba96a 100644
--- a/test/wall-clock-budgets.js
+++ b/test/wall-clock-budgets.js
@@ -129,12 +129,17 @@ export function fixedWallMargins(source, file) {
for (const match of code.matchAll(/\bassert(?:\s*\.\s*(\w+))?\s*\(/gu)) {
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) || 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');
- }
const judged = /^(?:equal|notEqual|strictEqual|notStrictEqual|deepEqual|notDeepEqual|deepStrictEqual|notDeepStrictEqual|partialDeepStrictEqual)$/u.test(match[1] ?? '')
? args.slice(0, 2) : args.slice(0, 1);
+ for (let index = 0; index < judged.length; index++) {
+ const argument = judged[index];
+ const fixedAlias = [...literals].some(name => new RegExp(`[<>]=?\\s*${name}\\s*$|^\\s*${name}\\s*[<>]=?`, 'u').test(argument));
+ const literalPeer = /^(equal|strictEqual)$/u.test(match[1] ?? '')
+ && new RegExp(`^\\s*${literal}\\s*$`, 'u').test(judged[1 - index] ?? '');
+ if ((observesTime(argument, aliases) || clockDifference(argument, clocks)) && (margin.test(argument) || fixedAlias || literalPeer)) {
+ record(match.index, 'literal elapsed-time margin');
+ }
+ }
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');
}
diff --git a/test/wall-clock-budgets.test.js b/test/wall-clock-budgets.test.js
index 68753e4a..7a0ddd79 100644
--- a/test/wall-clock-budgets.test.js
+++ b/test/wall-clock-budgets.test.js
@@ -60,6 +60,29 @@ test('the clock-margin guard follows waited results through boolean assertions [
}
});
+test('the clock-margin guard checks both compared assertion arguments [C7]', () => {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-compared-clock-'));
+ try {
+ const file = join(root, 'compared-clock.test.js');
+ const prefix = 'const startedAt = Date.now();\n';
+ for (const judgment of ['assert.strictEqual(true, Date.now() - startedAt < 10)',
+ 'assert.equal(true, Date.now() - startedAt < 10)', 'assert.strictEqual(Date.now() - startedAt < 10, true)',
+ 'assert.strictEqual(10, Date.now() - startedAt)', 'assert.equal(Date.now() - startedAt, 10)']) {
+ writeFileSync(file, prefix + judgment + ';\n');
+ assert.match(wallClockViolations(root).join('\n'), /compared-clock\.test\.js:2: literal elapsed-time margin/u, judgment);
+ writeFileSync(file, prefix + judgment + '; // budget: declared fixture delay is 10ms.\n');
+ assert.deepEqual(wallClockViolations(root), [], 'either compared argument accepts its same-line reason');
+ }
+ for (const judgment of ['assert.strictEqual(true, true, Date.now() - startedAt < 10)',
+ 'assert.ok(true, Date.now() - startedAt < 10)', 'assert.strictEqual(true, "Date.now() - startedAt < 10")']) {
+ writeFileSync(file, prefix + judgment + ';\n');
+ assert.deepEqual(wallClockViolations(root), [], 'diagnostic arguments and quoted fixtures are excluded');
+ }
+ } 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))), []);
});