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(tests): the runner-pid case gets its own file [C7]

Corey Olson1042bbab3b50
diff --git a/test/run-tests.test.js b/test/run-tests.test.js
index 169becbc..efabffe9 100644
--- a/test/run-tests.test.js
+++ b/test/run-tests.test.js
@@ -1698,37 +1698,3 @@ 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);
-});
diff --git a/test/runner-pid.test.js b/test/runner-pid.test.js
new file mode 100644
index 00000000..e9b79564
--- /dev/null
+++ b/test/runner-pid.test.js
@@ -0,0 +1,44 @@
+/** The test runner names itself to the tests it starts, so a test finds its runner without parsing ps text [C7]. */
+import assert from 'node:assert/strict';
+import { spawn } from 'node:child_process';
+import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { test } from 'node:test';
+
+const runner = fileURLToPath(new URL('../bin/run-tests.js', import.meta.url));
+
+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);
+});