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): preserve wait diagnostics and real watch ownership [C7]

Corey Olson3caf6ad5f269
diff --git a/src/test-file-pool.js b/src/test-file-pool.js
index 25fe49e6..35d6ad8d 100644
--- a/src/test-file-pool.js
+++ b/src/test-file-pool.js
@@ -279,9 +279,15 @@ export async function reserveTestFileToken(env, signal) {
try {
signal?.throwIfAborted();
immediate(db, () => db.prepare('INSERT INTO file_waiter(pid) VALUES (?)').run(process.pid));
+ let reported = false;
while (!reserved) {
signal?.throwIfAborted();
reserved = admit(db, pool.cores, pool.lender, pool.call) !== false;
+ if (!reserved && !reported && pool.call?.startsWith('async:') && pool.lender &&
+ db.prepare('SELECT 1 FROM file_holder h WHERE h.pid = ? AND NOT EXISTS (SELECT 1 FROM file_call WHERE lender = h.pid)').get(pool.lender)) {
+ process.stderr.write(`test-file-pool: parent ${pool.lender} is holding its token while nested files wait; use awaitNestedRun(child) only while yielding.\n`);
+ reported = true;
+ }
if (!reserved) await new Promise(done => setTimeout(done, POLL_MS));
}
db.prepare('UPDATE file_holder SET dispatch = ? WHERE pid = ?').run(nonce, process.pid);
diff --git a/test/run-tests-reporter.test.js b/test/run-tests-reporter.test.js
index f07e3461..64aeb82d 100644
--- a/test/run-tests-reporter.test.js
+++ b/test/run-tests-reporter.test.js
@@ -174,14 +174,23 @@ test('watch and aggregate coverage retain their single native orchestrator [C7]'
assert.match(result.stdout, /shared\.mjs/u);
});
await t.test('watch executes its first real case and stops through its observed owner', async () => {
- writeFileSync(join(root, 'watch.test.mjs'), "import { test } from 'node:test';\ntest('watch cell passed', () => {});\n");
+ writeFileSync(join(root, 'watch.test.mjs'), `import { test } from 'node:test';\nimport { writeFileSync } from 'node:fs';\nwriteFileSync(${JSON.stringify(watch)}, JSON.stringify({ pid: process.ppid, workerPid: process.pid }));\ntest('watch cell passed', () => {});\n`);
const run = runFixtureChildAsync(process.execPath, [runner, '--watch', 'watch.test.mjs'], { cwd: root, env });
let stopped = false;
/** Signal only the observed watcher while its current parent is this exact owned live runner. */
const stop = () => {
- if (stopped || !existsSync(watch)) return;
- const owned = JSON.parse(readFileSync(watch, 'utf8'));
- assert.equal(owned.parentPid, run.child.pid);
+ if (stopped) return;
+ let owned;
+ if (existsSync(watch)) owned = JSON.parse(readFileSync(watch, 'utf8'));
+ else {
+ // Failure cleanup still targets only an actual native watcher of this live owned runner.
+ const census = spawnSync('ps', ['-axo', 'pid=,ppid=,command='], { encoding: 'utf8' });
+ const children = census.stdout.split('\n').map(line => line.match(/^\s*(\d+)\s+(\d+)\s+(.*)$/u))
+ .filter(row => row && Number(row[2]) === run.child.pid && row[3].includes('--watch') && row[3].includes('watch.test.mjs'));
+ assert.equal(children.length, 1, 'one owned native watcher is available for normal termination');
+ owned = { pid: Number(children[0][1]) };
+ }
+ assert.ok(Number.isSafeInteger(owned.pid) && owned.pid > 0);
const current = spawnSync('ps', ['-p', String(owned.pid), '-o', 'ppid=,command='], { encoding: 'utf8' });
if (current.status !== 0) return;
assert.match(current.stdout, new RegExp(`^\\s*${run.child.pid}\\s+`), 'the watcher still belongs to our runner');
@@ -204,8 +213,11 @@ test('watch and aggregate coverage retain their single native orchestrator [C7]'
});
});
control.catch(() => {});
- const result = await awaitNestedRun(run);
- await control;
+ const waiting = awaitNestedRun(run);
+ let controlError;
+ try { await control; } catch (error) { controlError = error; stop(); }
+ const result = await waiting;
+ if (controlError) throw controlError;
assert.ok(stopped, 'normal termination targeted the observed native watcher');
assert.ok(result.status === 0 || result.signal === 'SIGTERM', 'only normal owned watch termination is accepted');
assert.match(result.stdout, /watch cell passed/u);