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(tests): retain discovery outside git worktrees [C7]

Corey Olsonfcc257f5761b
diff --git a/bin/run-tests.js b/bin/run-tests.js
index 13a53d0b..aa4b1be0 100644
--- a/bin/run-tests.js
+++ b/bin/run-tests.js
@@ -310,9 +310,20 @@ function typeScriptTestDiscovery(args, env) {
return !['false', 'undefined', ''].includes(result.stdout.trim());
}
+/** Preserve native discovery outside Git, but never hide a repository access failure. */
+function isGitWorkTree(cwd, env) {
+ const result = spawnSync('git', ['rev-parse', '--is-inside-work-tree'], {
+ cwd, env: { ...env, LC_ALL: 'C' }, encoding: 'utf8',
+ });
+ if (result.error) throw result.error;
+ if (result.status === 0) return result.stdout.trim() === 'true';
+ if (result.status === 128 && /fatal: not a git repository\b/u.test(result.stderr)) return false;
+ throw new Error(result.stderr.trim() || `git rev-parse failed (status ${result.status})`);
+}
+
/** List tracked files matching Node's runtime default patterns, excluding worktree copies. */
-function trackedDefaultTestFiles(cwd = process.cwd(), includeTypeScript = false) {
- const output = execFileSync('git', ['ls-files', '-z'], { cwd, encoding: 'utf8' });
+function trackedDefaultTestFiles(cwd, includeTypeScript, env) {
+ const output = execFileSync('git', ['ls-files', '-z'], { cwd, env, encoding: 'utf8' });
return output.split('\0').filter(path => path && isDefaultTestFile(path, includeTypeScript)).sort()
.map(path => `./${path}`);
}
@@ -352,18 +363,22 @@ function executeTests(args, sandbox, gateSlotHeld, fullSuite) {
let selectedArgs = args;
if (fullSuite) {
let files;
- try { files = trackedDefaultTestFiles(process.cwd(), typeScriptTestDiscovery(args, env)); }
+ try {
+ files = isGitWorkTree(process.cwd(), env)
+ ? trackedDefaultTestFiles(process.cwd(), typeScriptTestDiscovery(args, env), env)
+ : null;
+ }
catch (error) {
process.stderr.write(`run-tests: could not list tracked test files: ${error.message}\n`);
process.exitCode = 1;
return { status: 1, signal: null };
}
- if (files.length === 0) {
+ if (files?.length === 0) {
process.stderr.write('run-tests: no tracked Node test files found; refusing filesystem discovery\n');
process.exitCode = 1;
return { status: 1, signal: null };
}
- selectedArgs = [...args, ...files];
+ if (files) selectedArgs = [...args, ...files];
}
const result = runTests(selectedArgs, env);
if (result.error) throw result.error;
diff --git a/test/run-tests.test.js b/test/run-tests.test.js
index acb8c8d9..00e8e913 100644
--- a/test/run-tests.test.js
+++ b/test/run-tests.test.js
@@ -198,6 +198,17 @@ function shardsSplitTest(t) {
test('shards split the test files with none twice and none missing [C7]', shardsSplitTest);
+/** Keep plain temporary projects runnable without requiring a Git index. */
+function outsideGitDiscoveryTest(t) {
+ const fixture = makeShardFixture(t);
+ rmSync(join(fixture.root, '.git'), { recursive: true, force: true });
+ const selected = runShardFixture(fixture, null);
+ assert.deepEqual([...selected].sort(), fixture.expected,
+ 'without a Git work tree Node still discovers and executes every fixture test');
+}
+
+test('the runner keeps native discovery outside a Git work tree [C7]', outsideGitDiscoveryTest);
+
/** Assert the production runner names malformed shard ranges and their expected form. */
function badShardTest() {
const badValues = ['0/3', '4/3', '2', 'a/b'];