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.

test(ci): scan tracked tests only [C7]

Corey Olson7d873dfb2249
diff --git a/test/wall-clock-budgets.js b/test/wall-clock-budgets.js
index eccba96a..64a1f623 100644
--- a/test/wall-clock-budgets.js
+++ b/test/wall-clock-budgets.js
@@ -1,6 +1,7 @@
/** Find unexplained wall-clock judgments in test source, without executing it [C7]. */
-import { readdirSync, readFileSync } from 'node:fs';
-import { join, relative } from 'node:path';
+import { execFileSync } from 'node:child_process';
+import { existsSync, lstatSync, readFileSync } from 'node:fs';
+import { join } from 'node:path';
/** Mask comments and quoted fixture text while retaining exact offsets and comment lines. */
function codeOnly(source) {
@@ -161,21 +162,25 @@ export function fixedWallMargins(source, file) {
return [...found.values()];
}
-/** Scan every test file under a checkout, including nested tests and documentation tests. */
+/** Scan every tracked test file under a checkout, including nested and documentation tests. */
export function wallClockViolations(root) {
const found = [];
- /** Walk source directories without visiting generated artifacts, dependencies or preserved work. */
- function visit(directory, underTestDirectory = false) {
- for (const entry of readdirSync(directory, { withFileTypes: true })) {
- const path = join(directory, entry.name);
- if (entry.isDirectory()) {
- if (!['.git', 'node_modules', 'work'].includes(entry.name)) visit(path, underTestDirectory || entry.name === 'test');
- } else if (entry.isFile() && /\.[cm]?js$/u.test(entry.name)
- && (underTestDirectory || /^(?:test|test[-_.].+|.+[-_.]test)\.[cm]?js$/u.test(entry.name))) {
- found.push(...fixedWallMargins(readFileSync(path, 'utf8'), relative(root, path).replaceAll('\\', '/')));
- }
+ const tracked = execFileSync('git', ['ls-files', '-z'], { cwd: root, encoding: 'utf8' }).split('\0').filter(Boolean);
+ for (const file of tracked) {
+ const parts = file.split('/');
+ const name = parts.at(-1);
+ const underTestDirectory = parts.slice(0, -1).includes('test');
+ if (parts.some(part => ['.git', 'node_modules', 'work'].includes(part)) || !/\.[cm]?js$/u.test(name)
+ || (!underTestDirectory && !/^(?:test|test[-_.].+|.+[-_.]test)\.[cm]?js$/u.test(name))) continue;
+ let path = root;
+ let regularFile = true;
+ for (const [index, part] of parts.entries()) {
+ path = join(path, part);
+ if (!existsSync(path)) { regularFile = false; break; }
+ const entry = lstatSync(path);
+ if (index < parts.length - 1 ? !entry.isDirectory() : !entry.isFile()) { regularFile = false; break; }
}
+ if (regularFile) found.push(...fixedWallMargins(readFileSync(path, 'utf8'), file));
}
- visit(root);
return found.sort();
}
diff --git a/test/wall-clock-budgets.test.js b/test/wall-clock-budgets.test.js
index 7a0ddd79..a4b7fa38 100644
--- a/test/wall-clock-budgets.test.js
+++ b/test/wall-clock-budgets.test.js
@@ -1,5 +1,6 @@
/** Keep test timing judgments accountable to their actual work [C7]. */
import assert from 'node:assert/strict';
+import { execFileSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
@@ -7,12 +8,24 @@ import { fileURLToPath } from 'node:url';
import { test } from 'node:test';
import { wallClockViolations } from './wall-clock-budgets.js';
+/** Initialize a private repository so scanner fixtures exercise git's tracked-file list. */
+function initFixtureRepo(root) {
+ execFileSync('git', ['init', '-q', root]);
+}
+
+/** Stage named scanner inputs while leaving later files available as untracked controls. */
+function trackFixtureFiles(root, ...files) {
+ execFileSync('git', ['add', '--', ...files], { cwd: root });
+}
+
test('the clock-margin guard follows separately captured clock readings [C7]', () => {
const root = mkdtempSync(join(tmpdir(), 'pullboard-clock-readings-'));
try {
+ initFixtureRepo(root);
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);
+ trackFixtureFiles(root, 'readings.test.js');
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');
@@ -24,9 +37,11 @@ test('the clock-margin guard follows separately captured clock readings [C7]', (
test('the clock-margin guard follows a fixed wait result into a later assertion [C7]', () => {
const root = mkdtempSync(join(tmpdir(), 'pullboard-wait-result-'));
try {
+ initFixtureRepo(root);
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);
+ trackFixtureFiles(root, 'wait-result.test.js');
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');
@@ -40,11 +55,13 @@ 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 {
+ initFixtureRepo(root);
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.ok(true ? closed : false)', 'assert.strictEqual(true, closed)', 'assert.deepEqual({closed}, {closed: true})']) {
writeFileSync(file, prefix + judgment + ';\n');
+ trackFixtureFiles(root, 'wait-boolean.test.js');
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');
@@ -63,12 +80,14 @@ 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 {
+ initFixtureRepo(root);
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');
+ trackFixtureFiles(root, 'compared-clock.test.js');
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');
@@ -83,6 +102,27 @@ test('the clock-margin guard checks both compared assertion arguments [C7]', ()
}
});
+test('the wall-clock scanner skips ignored worktrees [C7]', () => {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-wall-clock-tracked-'));
+ try {
+ initFixtureRepo(root);
+ writeFileSync(join(root, '.gitignore'), '.claude/worktrees/\n');
+ mkdirSync(join(root, 'test'));
+ writeFileSync(join(root, 'test', 'tracked.test.js'), 'const startedAt = Date.now();\nassert.ok(Date.now() - startedAt < 30_000);\n');
+ trackFixtureFiles(root, '.gitignore', 'test/tracked.test.js');
+ const ignored = join(root, '.claude', 'worktrees', 'copy', 'test');
+ mkdirSync(ignored, { recursive: true });
+ writeFileSync(join(ignored, 'ignored.test.js'), 'const startedAt = Date.now();\nassert.ok(Date.now() - startedAt < 30_000);\n');
+ writeFileSync(join(root, 'test', 'untracked.test.js'), 'const startedAt = Date.now();\nassert.ok(Date.now() - startedAt < 30_000);\n');
+
+ assert.deepEqual(wallClockViolations(root), [
+ 'test/tracked.test.js:2: literal elapsed-time margin: assert.ok(Date.now() - startedAt < 30_000);',
+ ]);
+ } 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))), []);
});
@@ -90,10 +130,12 @@ test('no test judges work by a fixed wall-clock margin [C7]', () => {
test('the clock-margin guard catches planted source and names its file and line [C7]', () => {
const root = mkdtempSync(join(tmpdir(), 'pullboard-wall-clock-'));
try {
+ initFixtureRepo(root);
mkdirSync(join(root, 'nested'));
const file = join(root, 'nested', 'planted.test.mjs');
const bare = 'const start = Date.now();\nassert.ok(Date.now() - start < 30_000);\n';
writeFileSync(file, bare);
+ trackFixtureFiles(root, 'nested/planted.test.mjs');
assert.match(wallClockViolations(root).join('\n'), /nested\/planted\.test\.mjs:2: literal elapsed-time margin/u);
assert.throws(() => assert.deepEqual(wallClockViolations(root), []), error =>
error.code === 'ERR_ASSERTION' && /nested\/planted\.test\.mjs:2/u.test(error.message), 'a planted bare clock margin makes the real guard red');
@@ -117,6 +159,7 @@ test('the clock-margin guard catches planted source and names its file and line
mkdirSync(join(root, 'test'));
writeFileSync(join(root, 'test', 'helper.js'), bare);
writeFileSync(join(root, 'test.js'), bare);
+ trackFixtureFiles(root, 'test/helper.js', 'test.js');
assert.deepEqual(wallClockViolations(root).map(line => line.split(':')[0]).sort(), ['test.js', 'test/helper.js'],
'plain test.js and every JavaScript file under test/ are part of native discovery');
} finally {