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.

feat(tests): the test runner names itself to its tests [C7]

Corey Olson2021a484339f
diff --git a/bin/run-tests.js b/bin/run-tests.js
index c4b5bfd0..2a4a4410 100644
--- a/bin/run-tests.js
+++ b/bin/run-tests.js
@@ -222,6 +222,8 @@ function testEnvironment(sandbox, gateMarkers = {}) {
env.PULLBOARD_HOME = home;
env.PULLBOARD_MODEL = 'Test Model';
env.PULLBOARD_MACHINE_HOME = join(sandbox, 'machine');
+ // A test finds its runner by this pid, never by parsing ps text; a nested runner sets its own (#1073).
+ env.PULLBOARD_TEST_RUNNER_PID = String(process.pid);
isolateTestMachine(env, sandbox); // #1068: no settings, resources, runners or host markers of the real machine.
// init and resume start a background view by default; a test opts back in by deleting this.
env.PULLBOARD_VIEW_BACKGROUND = '0';
diff --git a/test/run-tests.test.js b/test/run-tests.test.js
index efabffe9..169becbc 100644
--- a/test/run-tests.test.js
+++ b/test/run-tests.test.js
@@ -1698,3 +1698,37 @@ test('a test name pattern after the file selects only its case [C7]', () => {
assert.match(result.stdout, /ok [0-9]+ - alpha case runs[\s\S]*# tests 1\b/u, `${args.join(' ')} selects one case`); assert.doesNotMatch(result.stdout, /beta case runs/u, `${args.join(' ')} ran the unselected case`); }
} finally { rmSync(root, { recursive: true, force: true }); }
});
+
+test('the test runner names itself to the tests it starts [C7]', async (t) => {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-runner-pid-')));
+ t.after(() => rmSync(dir, { recursive: true, force: true }));
+ const seen = join(dir, 'seen.jsonl');
+ const inner = join(dir, 'inner.test.js');
+ const outer = join(dir, 'outer.test.js');
+ writeFileSync(inner, `import { appendFileSync } from 'node:fs';
+import { test } from 'node:test';
+test('inner', () => { appendFileSync(${JSON.stringify(seen)}, JSON.stringify({ who: 'inner', runner: process.env.PULLBOARD_TEST_RUNNER_PID }) + '\\n'); });
+`);
+ writeFileSync(outer, `import { appendFileSync } from 'node:fs';
+import { spawn } from 'node:child_process';
+import { test } from 'node:test';
+test('outer', async () => {
+ appendFileSync(${JSON.stringify(seen)}, JSON.stringify({ who: 'outer', runner: process.env.PULLBOARD_TEST_RUNNER_PID }) + '\\n');
+ const nested = spawn(process.execPath, [${JSON.stringify(runner)}, ${JSON.stringify(inner)}], { stdio: 'ignore' });
+ appendFileSync(${JSON.stringify(seen)}, JSON.stringify({ who: 'nested runner', pid: String(nested.pid) }) + '\\n');
+ const code = await new Promise((done) => nested.once('close', done));
+ if (code !== 0) throw new Error('the nested run failed with ' + code);
+});
+`);
+ const child = spawn(process.execPath, [runner, outer], { stdio: ['ignore', 'pipe', 'pipe'] });
+ let output = '';
+ child.stdout.setEncoding('utf8').on('data', (part) => { output += part; });
+ child.stderr.setEncoding('utf8').on('data', (part) => { output += part; });
+ const code = await new Promise((done) => child.once('close', done));
+ assert.equal(code, 0, output);
+ const records = readFileSync(seen, 'utf8').trim().split('\n').map((line) => JSON.parse(line));
+ const by = (who) => records.find((record) => record.who === who);
+ assert.equal(by('outer').runner, String(child.pid), 'a test file reads its runner pid');
+ assert.equal(by('inner').runner, by('nested runner').pid, 'a nested run sees the nested runner pid, not the outer one');
+ assert.notEqual(by('inner').runner, by('outer').runner);
+});