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(runners): pin tooling transfers and repair live fixtures [C7,A1,I1]

Corey Olsona5ec4aa0ddeb
diff --git a/src/gate.js b/src/gate.js
index ba319294..65bdbd58 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -241,7 +241,7 @@ function runTiming(run, command) {
const suffix = relative(run.executionRoot, path);
return suffix && suffix !== '..' && !suffix.startsWith(`..${sep}`) && !isAbsolute(suffix) ? suffix : original;
};
- return { ...profile, executionRunner: run.executionRunner,
+ return { ...profile, executionRunner: run.executionRunner, executionSource: run.executionSource,
files: (profile.files ?? []).map(file => ({ ...file, path: localPath(file.path) })),
tests: (profile.tests ?? []).map(test => ({ ...test, file: localPath(test.file) })) };
}
@@ -279,6 +279,13 @@ export function writeTimingProfile(path, profile) {
format: sanitize(profile.format ?? 'none', 'format'),
unavailable: sanitize(profile.unavailable ?? null, 'availability'),
...(profile.executionRunner ? { executionRunner: sanitize(profile.executionRunner, 'execution runner') } : {}),
+ ...(profile.executionSource ? { executionSource: {
+ commit: sanitize(profile.executionSource.commit, 'execution commit'),
+ tree: sanitize(profile.executionSource.tree, 'execution tree'),
+ tooling: Object.fromEntries(Object.entries(profile.executionSource.tooling ?? {})
+ .filter(([key]) => ['kind', 'name', 'version', 'commit', 'tree', 'sha256'].includes(key))
+ .map(([key, value]) => [key, sanitize(value, `execution tooling ${key}`)])),
+ } } : {}),
};
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
writeFileSync(path, `${JSON.stringify(sanitized, null, 2)}\n`, { mode: 0o600 });
@@ -419,7 +426,8 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
runner: [...new Set(profiles.map(value => value.runner))].join(', '),
format: [...new Set(profiles.map(value => value.format))].join('+'),
unavailable: profiles.some(value => value.unavailable) ? 'per-test timing unavailable: output was not TAP or JUnit (one or more phases)' : null,
- ...(lease.runner ? { executionRunner: lease.runner.host } : {}),
+ ...(lease.runner ? { executionRunner: lease.runner.host,
+ executionSource: profiles.find(value => value.executionSource)?.executionSource } : {}),
});
return { ...proof, log, seconds: criterion.seconds + proof.seconds, ...selection, check: receipt,
profile, profilePath, proofProfilePath: proof.profilePath, proofLog: proof.log };
diff --git a/src/runner-worker.js b/src/runner-worker.js
index 6f4adf37..5f8a41e7 100644
--- a/src/runner-worker.js
+++ b/src/runner-worker.js
@@ -73,6 +73,14 @@ async function readSpec() {
if (Object.keys(value.runtime.files).length !== runtimeNames.length
|| runtimeNames.some(name => typeof value.runtime.files[name] !== 'string')) throw new Error('invalid work specification');
if (createHash('sha256').update(JSON.stringify(value.runtime.files)).digest('hex') !== value.runtime.sha256) throw new Error('invalid trusted runtime');
+ const workerFlag = process.execArgv.indexOf('-e');
+ const workerSource = workerFlag >= 0 ? process.execArgv[workerFlag + 1] : null;
+ const toolingFiles = { ...value.runtime.files, 'runner-worker.js': workerSource };
+ if (!workerSource || !value.tooling || !['git-checkout', 'installed-package'].includes(value.tooling.kind)
+ || value.tooling.name !== 'pullboard' || typeof value.tooling.version !== 'string'
+ || createHash('sha256').update(JSON.stringify(toolingFiles)).digest('hex') !== value.tooling.sha256) {
+ throw new Error('invalid trusted tooling identity');
+ }
for (const field of ['landing', 'itemCheck', 'diagnostic']) {
if (value[field] !== undefined && typeof value[field] !== 'boolean') throw new Error('invalid work specification');
}
@@ -412,7 +420,7 @@ async function runCommand(spec, root, env, sink) {
async function receipt(spec, fields, sink) {
await flushStdout();
const body = { id: spec.id, commit: spec.commit, tree: spec.tree, code: fields.code, signal: fields.signal,
- runtimeSha256: spec.runtime.sha256, root: fields.root ?? '', outputSha256: sink.hash.digest('hex'), wallMs: Math.max(0, Date.now() - sink.wallStart) };
+ runtimeSha256: spec.runtime.sha256, toolingSha256: spec.tooling.sha256, root: fields.root ?? '', outputSha256: sink.hash.digest('hex'), wallMs: Math.max(0, Date.now() - sink.wallStart) };
const encoded = Buffer.from(JSON.stringify(body)).toString('base64');
await new Promise((resolveWrite, rejectWrite) => process.stderr.write(`${RECEIPT} ${spec.id} ${encoded}\n`, error => error ? rejectWrite(error) : resolveWrite()));
}
diff --git a/src/runners.js b/src/runners.js
index d5aa3661..70502976 100644
--- a/src/runners.js
+++ b/src/runners.js
@@ -1,7 +1,7 @@
/** Exact committed source and bounded, credential-free SSH execution for machine runners [C7]. */
import { spawn, spawnSync } from 'node:child_process';
import { createHash, randomUUID } from 'node:crypto';
-import { closeSync, mkdtempSync, openSync, readFileSync, rmSync, writeSync } from 'node:fs';
+import { closeSync, existsSync, mkdtempSync, openSync, readFileSync, rmSync, writeSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -12,6 +12,8 @@ import { Refused } from './refused.js';
const MAX_OUTPUT_BYTES = 1024 ** 3;
const MAX_BLOB_BYTES = 8 * 1024 ** 2;
+const TOOL_ROOT = fileURLToPath(new URL('../', import.meta.url));
+const RUNTIME_NAMES = ['resources.js', 'git.js', 'machine-home.js', 'refused.js'];
/** Validate an SSH destination as one argument, never a command or an SSH option. */
export function validateRunner(value) {
@@ -102,6 +104,34 @@ function sshEnvironment() {
return { ...env, LC_ALL: 'C', LANG: 'C', TZ: 'UTC' };
}
+/** Snapshot, scan and pin the actual tooling bytes independently of the project being tested. */
+function trustedTooling() {
+ const files = Object.fromEntries([...RUNTIME_NAMES, 'runner-worker.js']
+ .map(name => [name, readFileSync(fileURLToPath(new URL(`./${name}`, import.meta.url)), 'utf8')]));
+ for (const [name, source] of Object.entries(files)) {
+ if (Buffer.byteLength(source) > MAX_BLOB_BYTES
+ || secretsIn(source.split(/\r?\n/u).map((text, index) => ({ path: `tooling/${name}`, line: index + 1, text }))).length) {
+ throw new Refused('RUNNER_TOOLING_SECRET', 'the selected runner tooling failed its transfer scan; restore a trusted Pullboard installation');
+ }
+ }
+ const manifest = JSON.parse(readFileSync(join(TOOL_ROOT, 'package.json'), 'utf8'));
+ if (manifest.name !== 'pullboard' || typeof manifest.version !== 'string') {
+ throw new Refused('RUNNER_TOOLING_IDENTITY', 'runner tooling must come from a named Pullboard installation; reinstall Pullboard');
+ }
+ let provenance = { kind: 'installed-package', name: manifest.name, version: manifest.version };
+ if (existsSync(join(TOOL_ROOT, '.git'))) {
+ const selected = runnerSource(TOOL_ROOT);
+ if (!selected || Object.entries(files).some(([name, source]) => sourceGit(TOOL_ROOT, ['show', `${selected.commit}:src/${name}`]) !== source)) {
+ throw new Refused('RUNNER_TOOLING_CHANGED', 'runner tooling differs from its selected committed revision; restore or commit the tooling before remote execution');
+ }
+ provenance = { ...provenance, kind: 'git-checkout', ...selected };
+ }
+ const tooling = { ...provenance, sha256: createHash('sha256').update(JSON.stringify(files)).digest('hex') };
+ const runtimeFiles = Object.fromEntries(RUNTIME_NAMES.map(name => [name, files[name]]));
+ return { worker: files['runner-worker.js'], tooling,
+ runtime: { files: runtimeFiles, sha256: createHash('sha256').update(JSON.stringify(runtimeFiles)).digest('hex') } };
+}
+
/** Prepare a single shallow object pack and an explicit worker request; cleanup owns only its scratch directory. */
function requestFor(root, command, { runner, source, browser = false, pipefail = false, metadata = {} }) {
runner = validateRunner(runner);
@@ -116,14 +146,11 @@ function requestFor(root, command, { runner, source, browser = false, pipefail =
const directory = mkdtempSync(join(tmpdir(), 'pullboard-runner-send-'));
let descriptor;
try {
- const runtimeFiles = Object.fromEntries(['resources.js', 'git.js', 'machine-home.js', 'refused.js']
- .map(name => [name, readFileSync(fileURLToPath(new URL(`./${name}`, import.meta.url)), 'utf8')]));
- const runtime = { files: runtimeFiles, sha256: createHash('sha256').update(JSON.stringify(runtimeFiles)).digest('hex') };
- const spec = { version: 1, id: randomUUID(), runtime, ...current, command, pipefail, slots: runner.slots,
+ const { worker, tooling, runtime } = trustedTooling();
+ const spec = { version: 1, id: randomUUID(), runtime, tooling, ...current, command, pipefail, slots: runner.slots,
browser: runner.browser, browserRequired: browser, landing: metadata.landing === true,
itemCheck: metadata.itemCheck === true, diagnostic: metadata.diagnostic === true,
item: String(metadata.item ?? ''), kind: String(metadata.kind ?? ''), ...(runner.root ? { root: runner.root } : {}) };
- const worker = readFileSync(fileURLToPath(new URL('./runner-worker.js', import.meta.url)), 'utf8');
const encodedSpec = Buffer.from(JSON.stringify(spec));
if (encodedSpec.length > 1024 ** 2) throw new Refused('RUNNER_REQUEST_LIMIT', 'runner tooling request exceeds its safe transfer limit; keep this run local');
const framed = join(directory, 'request.bin');
@@ -159,14 +186,15 @@ function resultFrom(request, result) {
receipt = JSON.parse(Buffer.from(receipts[0].slice(prefix.length), 'base64').toString('utf8'));
} catch { throw new RunnerDropped(request.runner.host); }
if (result.error || result.status !== 0 || receipt.id !== request.spec.id || receipt.commit !== request.spec.commit
- || receipt.tree !== request.spec.tree || receipt.runtimeSha256 !== request.spec.runtime.sha256 || !Number.isInteger(receipt.code) || receipt.code < 0 || receipt.code > 255
+ || receipt.tree !== request.spec.tree || receipt.runtimeSha256 !== request.spec.runtime.sha256 || receipt.toolingSha256 !== request.spec.tooling.sha256 || !Number.isInteger(receipt.code) || receipt.code < 0 || receipt.code > 255
|| typeof receipt.root !== 'string' || !Number.isFinite(receipt.wallMs) || receipt.wallMs < 0
|| receipt.outputSha256 !== createHash('sha256').update(output).digest('hex')) {
throw new RunnerDropped(request.runner.host);
}
return { isGreen: receipt.code === 0 && !receipt.signal, output: output.toString('utf8'),
seconds: Math.round(receipt.wallMs / 1000), exitCode: receipt.code,
- executionRunner: request.runner.host, executionRoot: receipt.root, remoteWallMs: receipt.wallMs };
+ executionRunner: request.runner.host, executionRoot: receipt.root, remoteWallMs: receipt.wallMs,
+ executionSource: { commit: receipt.commit, tree: receipt.tree, tooling: request.spec.tooling } };
}
/** Execute one committed command over SSH; an authentic test failure remains a test failure. */
diff --git a/test/runners.test.js b/test/runners.test.js
index c2fc5ca1..43198647 100644
--- a/test/runners.test.js
+++ b/test/runners.test.js
@@ -290,6 +290,7 @@ function startQueueController(repo, env, command, { item, queueMarker, firstItem
const { runProfiledShell, withGateSlot } = await import(${JSON.stringify(gateUrl)});
const root = ${JSON.stringify(repo)};
const command = ${JSON.stringify(command)};
+const queueMarker = ${JSON.stringify(queueMarker)};
const firstItem = ${JSON.stringify(firstItem)};
const result = await withGateSlot(root, async lease => {
const run = await runProfiledShell(root, command, { gateLease: lease });
@@ -393,7 +394,7 @@ test('a queued run executes on a registered runner and its result comes back [C7
try {
held = await takeResource({ name: 'gate', capacity: 1, scope: 'machine', root: repo,
agent: 'fixture-local-holder', item: 'runner-local-holder', kind: 'force-registered-runner' });
- const successful = runThroughGate(repo, env, 'node --test runner-probe.test.js');
+ const successful = runThroughGate(repo, env, 'node --test --test-reporter=tap runner-probe.test.js');
assert.equal(successful.status, 0, successful.context);
assert.match(successful.stdout, /TAP version 13/);
assert.match(successful.stdout, /RUNNER_FACT /);
@@ -412,6 +413,13 @@ test('a queued run executes on a registered runner and its result comes back [C7
assert.equal(result.runner, HOST);
assert.equal(result.profile.executionRunner, HOST);
assert.equal(result.profile.tests.length, 1, 'TAP results are retained in the ordinary profile');
+ const source = result.profile.executionSource;
+ assert.equal(source.commit, selectedCommit);
+ assert.equal(source.tree, selectedTree);
+ assert.equal(source.tooling.name, 'pullboard');
+ assert.equal(source.tooling.kind, 'git-checkout');
+ assert.match(source.tooling.sha256, /^[a-f0-9]{64}$/u);
+ assert.notEqual(source.tooling.commit, selectedCommit, 'the tooling checkout has provenance separate from the tiny fixture project');
const request = JSON.parse(readFileSync(requests, 'utf8').trim().split('\n')[0]);
assert.equal(request.host, HOST);
assert.equal(request.framed, true);
@@ -745,7 +753,7 @@ appendFileSync(${JSON.stringify(installWitnesses)}, 'postinstall\\n');
try {
held = await takeResource({ name: 'gate', capacity: 1, scope: 'machine', root: repo,
agent: 'fixture-cache-local-holder', item: 'cache-local-holder', kind: 'force-registered-runner' });
- const command = 'node --test runner-cache-probe.test.js';
+ const command = 'node --test --test-reporter=tap runner-cache-probe.test.js';
writeCacheProbe(repo, { remoteStateRoot, nodePath: process.execPath });
git(repo, env, 'add', 'runner-cache-probe.test.js');
git(repo, env, 'commit', '-q', '-m', 'test: assert cache symlink stays job-local');