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(runners): prove declared CPU test placement [C7]

Corey Olson50a5d02af489
diff --git a/test/cpu-load-test-fixture.js b/test/cpu-load-test-fixture.js
new file mode 100644
index 00000000..98d1cd3e
--- /dev/null
+++ b/test/cpu-load-test-fixture.js
@@ -0,0 +1,61 @@
+/** Exercise CPU-test placement with a real committed repo, SSH worker, and private machine leases [C7]. */
+import assert from 'node:assert/strict';
+import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { join, resolve } from 'node:path';
+import { awaitNestedRun } from '../src/test-file-pool.js';
+import { runFixtureChildAsync } from './fixture-child.js';
+import { HOST, installSshStandIn } from './runner-ssh-fixture.js';
+
+const SOURCE = resolve(import.meta.dirname, '..');
+
+/** Build an ordinary CLI fixture whose declared test reports its actual checkout and live holder. */
+export function cpuLoadFixture(e2e) {
+ const box = e2e.project('node bin/run-tests.js test/cpu-probe.test.js');
+ const bin = join(box.dir, 'ssh-bin');
+ const remoteHome = join(box.dir, 'runner-home');
+ const remoteMachineHome = join(remoteHome, '.pullboard');
+ const requests = join(box.dir, 'ssh-requests.jsonl');
+ for (const path of [bin, remoteMachineHome, join(box.repo, 'test')]) mkdirSync(path, { recursive: true });
+ cpSync(join(SOURCE, 'src'), join(box.repo, 'src'), { recursive: true });
+ cpSync(join(SOURCE, 'bin'), join(box.repo, 'bin'), { recursive: true });
+ writeFileSync(join(box.repo, 'package.json'), JSON.stringify({ name: 'cpu-placement-fixture', version: '1.0.0', type: 'module' }) + '\n');
+ writeFileSync(join(box.repo, 'test', 'cpu-probe.test.js'), `import { test } from 'node:test';
+import { DatabaseSync } from 'node:sqlite';
+test('declared load stand-in', { cpuLoad: true }, () => {
+ const db = new DatabaseSync(process.env.PULLBOARD_GATE_SLOT_POOL, { readOnly: true });
+ const row = db.prepare('SELECT * FROM holder WHERE token=?').get(process.env.PULLBOARD_GATE_SLOT_TOKEN);
+ db.close();
+ console.log('CPU_LOAD_EXECUTOR ' + JSON.stringify({ cwd: process.cwd(), home: process.env.HOME,
+ machineHome: process.env.PULLBOARD_MACHINE_HOME, liveLease: Boolean(row), runnerExecution: row?.runner_execution === 1 }));
+});
+`);
+ box.git(box.repo, 'add', '-A');
+ box.git(box.repo, 'commit', '-q', '-m', 'test: commit declared CPU placement probe');
+ installSshStandIn({ bin, worker: join(box.dir, 'worker'), home: remoteHome, machineHome: remoteMachineHome, requests });
+ const env = { ...box.env, PATH: `${bin}:${box.env.PATH}` };
+ for (const key of Object.keys(env)) if (/^PULLBOARD_(GATE|BROWSER|TEST|LANDING)_/u.test(key) || key === 'NODE_OPTIONS' || key === 'NODE_TEST_CONTEXT') delete env[key];
+ /** Use the ordinary fixture CLI to configure its own genuine runner registration and policy. */
+ function command(...args) {
+ const result = box.run(box.repo, ...args, '--json');
+ assert.equal(result.code, 0, result.err || result.out);
+ return JSON.parse(result.out);
+ }
+ command('runner', 'add', HOST, '--slots', '1', '--browser', '0');
+ command('settings', 'gate.runnersFirst', 'off');
+ command('settings', 'gate.browserByLaunch', 'on');
+ command('settings', 'gateSlots', '1');
+ const cli = join(SOURCE, 'bin', 'pullboard.js');
+ return {
+ ...box, env, requests, remoteHome, remoteMachineHome, command,
+ /** Count real completed SSH requests without treating a configured host as execution proof. */
+ requestsMade() { return existsSync(requests) ? readFileSync(requests, 'utf8').trim().split('\n').filter(Boolean).map(JSON.parse) : []; },
+ /** Run the public landing gate under its ordinary lease and wait on its original child promise. */
+ async runGate() {
+ const result = await awaitNestedRun(runFixtureChildAsync(process.execPath, [cli, 'gate', '--landing', '--json'],
+ { cwd: box.repo, env, encoding: 'utf8' }));
+ const log = readFileSync(join(box.repo, '.git', 'pullboard-gate.log'), 'utf8');
+ const match = /^# CPU_LOAD_EXECUTOR (.+)$/mu.exec(log);
+ return { result, log, executor: match ? JSON.parse(match[1]) : null };
+ },
+ };
+}
diff --git a/test/cpu-load-tests.test.js b/test/cpu-load-tests.test.js
new file mode 100644
index 00000000..d9493f7d
--- /dev/null
+++ b/test/cpu-load-tests.test.js
@@ -0,0 +1,30 @@
+/** Declared load is placed by the real runner road, never by a forged host flag [C7]. */
+/** @pullboard-test-input source-tree */
+import assert from 'node:assert/strict';
+import { join, relative, sep } from 'node:path';
+import { after, test } from 'node:test';
+import { createE2eHelpers } from './e2e-helpers.js';
+import { cpuLoadFixture } from './cpu-load-test-fixture.js';
+
+const e2e = createE2eHelpers();
+after(e2e.cleanup);
+
+test('a declared CPU-load test runs only on a runner when one is registered [C7]', async () => {
+ const box = cpuLoadFixture(e2e);
+ const remote = await box.runGate();
+ assert.equal(remote.result.status, 0, remote.result.context);
+ assert.equal(box.requestsMade().length, 1, 'the declared CPU-load test dispatches to the registered runner even when local-first has a free slot');
+ assert.ok(remote.executor?.liveLease, 'the test body reports an actual private resource holder');
+ assert.equal(remote.executor.runnerExecution, true, 'worker execution is bound to the genuine inherited lease');
+ assert.notEqual(remote.executor.cwd, box.repo, 'the declared test body never starts in the coordinator checkout');
+ const withinRunner = relative(join(box.remoteHome, '.pullboard-runner', 'jobs'), remote.executor.cwd);
+ assert.ok(withinRunner && withinRunner !== '..' && !withinRunner.startsWith(`..${sep}`));
+ assert.equal(remote.executor.machineHome, box.remoteMachineHome);
+ box.command('runner', 'remove', 'fixture-host');
+ const local = await box.runGate();
+ assert.equal(local.result.status, 0, local.result.context);
+ assert.equal(box.requestsMade().length, 1, 'no unregistered executor is used for the fallback');
+ assert.equal(local.executor?.cwd, box.repo);
+ assert.match(local.log + local.result.stderr, /CPU.load[\s\S]*no (?:registered )?runners|no runners are registered/iu,
+ 'the no-runner local fallback explains why it is local');
+});