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.

chore(core): refresh timing profiles from main [V10]

Corey Olson45f15820e434
diff --cc src/gate.js
index 43c8c2c0,8183da45..952b9d72
--- a/src/gate.js
+++ b/src/gate.js
@@@ -95,105 -92,35 +95,123 @@@ export function isStampedGreen(root)
*
* @param {string} root
* @param {string} command
- * @param {{ env?: NodeJS.ProcessEnv }} [options] - Additional child environment values.
- * @param {{ pipefail?: boolean }} [options] - Enable every-stage failures only for the configured repo gate.
++ * @param {{ pipefail?: boolean, env?: NodeJS.ProcessEnv }} [options] - Gate-only pipefail and additional child environment values.
* @returns {{ isGreen: boolean, output: string, seconds: number }}
*/
- export function runShell(root, command, { env = {} } = {}) {
-export function runShell(root, command, { pipefail = false } = {}) {
++export function runShell(root, command, { pipefail = false, env = {} } = {}) {
const started = Date.now();
- const options = { cwd: root, env: gitChildEnv(root), shell: true, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', maxBuffer: 2 ** 30 };
++ const options = { cwd: root, env: { ...gitChildEnv(root), ...env }, shell: true, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', maxBuffer: 2 ** 30 };
+ let prefix = '';
+ if (pipefail) {
+ // Probe the same shell as the command, with no load-sensitive deadline or alternate shell.
+ const probe = spawnSync('set -o pipefail', options);
+ if (probe.status === 0) prefix = 'set -o pipefail\n';
+ else if (hasPipeline(command)) {
+ throw new Refused('PIPEFAIL_UNAVAILABLE', 'the repo gate shell cannot enable pipefail; rewrite the gate without a pipe');
+ }
+ }
// Newlines, not spaces, around the command, so a trailing comment in it cannot swallow the `)`.
- const result = spawnSync(`(\n${command}\n) 2>&1`, { cwd: root, env: { ...gitChildEnv(root), ...env }, shell: true, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', maxBuffer: 2 ** 30 });
+ const result = spawnSync(`${prefix}(\n${command}\n) 2>&1`, options);
invalidateGitFacts();
return { isGreen: result.status === 0, output: `${result.stdout ?? ''}${result.stderr ?? ''}`, seconds: Math.round((Date.now() - started) / 1000) };
}
+/** Replace a possible secret-bearing line before persisting a direct item-check log. */
+function safeLog(output) {
+ return output.split('\n').map((line, index) => {
+ if (Buffer.byteLength(line, 'utf8') > 64 * 1024) return '[redacted output line exceeds 64 KiB safe-scan limit]';
+ const findings = secretsIn([{ path: 'item check output', line: index + 1, text: line }]);
+ return findings.length ? `[redacted ${findings.map(finding => finding.slice(0, finding.lastIndexOf(' at '))).join(', ')}]` : line;
+ }).join('\n');
+}
+
+/** Run a command with Node's event reporter and persist its timing profile beside its log.
+ * @param {string} root
+ * @param {string} command
- * @param {{ waitMs?: number, artifactDirectory?: string, artifactPrefix?: string, persistLog?: boolean, profileFile?: string }} [options]
++ * @param {{ waitMs?: number, artifactDirectory?: string, artifactPrefix?: string, persistLog?: boolean, profileFile?: string, pipefail?: boolean }} [options]
+ * @returns {{ isGreen: boolean, output: string, seconds: number, profile: object, profilePath: string, logPath: string|null }}
+ */
- export function runProfiledShell(root, command, { waitMs = 0, artifactDirectory, artifactPrefix = 'pullboard-gate', persistLog = false, profileFile } = {}) {
++export function runProfiledShell(root, command, { waitMs = 0, artifactDirectory, artifactPrefix = 'pullboard-gate', persistLog = false, profileFile, pipefail = false } = {}) {
+ const directory = artifactDirectory ?? dirname(gitPath(root, LOG));
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
+ const id = randomUUID();
+ const eventsDirectory = join(directory, `.${artifactPrefix}-${id}.timings`);
+ mkdirSync(eventsDirectory, { mode: 0o700 });
+ const eventsPath = join(eventsDirectory, 'events.json');
+ const profilePath = profileFile ?? join(directory, `${artifactPrefix}-${id}.profile.json`);
+ const logPath = persistLog ? join(directory, `${artifactPrefix}-${id}.log`) : null;
+ const started = Date.now();
+ try {
- const run = runShell(root, command, { env: { PULLBOARD_TEST_TIMING_PROFILE: eventsPath } });
++ const run = runShell(root, command, { env: { PULLBOARD_TEST_TIMING_PROFILE: eventsPath }, pipefail });
+ const events = readTimingProfiles(eventsPath);
+ const profile = writeTimingProfile(profilePath, {
+ version: 1,
+ waitMs: Math.max(0, Math.round(waitMs)),
+ wallMs: Math.max(0, Date.now() - started),
+ files: events.files,
+ tests: events.tests,
+ });
+ if (logPath) writeFileSync(logPath, safeLog(run.output), { mode: 0o600 });
+ return { ...run, profile, profilePath, logPath };
+ } finally { rmSync(eventsDirectory, { recursive: true, force: true }); }
+}
+
+/** Persist one sanitized timing profile as a private artifact.
+ * @param {string} path
+ * @param {{ files?: Array<object>, tests?: Array<object>, [key: string]: any }} profile
+ * @returns {object} The sanitized profile written to disk.
+ */
+export function writeTimingProfile(path, profile) {
+ /** Sanitize one reporter-controlled string before persistence or display.
+ * @param {unknown} value
+ * @param {string} label
+ * @returns {unknown}
+ */
+ const sanitize = (value, label) => {
+ if (typeof value !== 'string') return value;
+ if (Buffer.byteLength(value, 'utf8') > 64 * 1024) return '[redacted profile field exceeds 64 KiB safe-scan limit]';
+ const findings = secretsIn([{ path: `timing profile ${label}`, line: 1, text: value }]);
+ return findings.length ? `[redacted ${findings.map(finding => finding.slice(0, finding.lastIndexOf(' at '))).join(', ')}]` : value;
+ };
+ /** Accept only measured, nonnegative durations from reporter events. */
+ const validDuration = value => Number.isFinite(value) && value >= 0;
+ const files = (profile.files ?? []).filter(file => typeof file?.path === 'string' && validDuration(file.durationMs))
+ .map(file => ({ path: sanitize(file.path, 'file path'), durationMs: file.durationMs }));
+ const tests = (profile.tests ?? []).filter(test => typeof test?.file === 'string' && typeof test?.name === 'string' && validDuration(test.durationMs))
+ .map(test => ({ file: sanitize(test.file, 'test file'), name: sanitize(test.name, 'test name'), durationMs: test.durationMs, passed: test.passed === true }));
+ const sanitized = {
+ version: 1,
+ waitMs: validDuration(profile.waitMs) ? profile.waitMs : 0,
+ wallMs: validDuration(profile.wallMs) ? profile.wallMs : null,
+ files,
+ tests,
+ };
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
+ writeFileSync(path, `${JSON.stringify(sanitized, null, 2)}\n`, { mode: 0o600 });
+ return sanitized;
+}
+
+/** Combine distinct Node reporter invocations whose names share a private per-run prefix. */
+function readTimingProfiles(prefix) {
+ const directory = dirname(prefix);
+ const base = `${basename(prefix)}.`;
+ const profiles = [];
+ let names = [];
+ try { names = readdirSync(directory).filter(name => name.startsWith(base) && name.endsWith('.json')); } catch { return { files: [], tests: [] }; }
+ for (const name of names) {
+ try { profiles.push(JSON.parse(readFileSync(join(directory, name), 'utf8'))); } catch { /* Ignore incomplete reporters from a killed test process. */ }
+ }
+ return { files: profiles.flatMap(profile => Array.isArray(profile.files) ? profile.files : []), tests: profiles.flatMap(profile => Array.isArray(profile.tests) ? profile.tests : []) };
+}
+
+ /** Conservatively detect a pipe when the configured gate shell cannot enforce every stage's status. */
+ function hasPipeline(command) {
+ for (let index = 0; index < command.length; index += 1) {
+ if (command[index] === '|' && command[index + 1] !== '|' && command[index - 1] !== '|') return true;
+ }
+ return false;
+ }
+
/** Run work under the machine gate queue, keeping landing gates ahead of ordinary gates and item checks last.
*
* @param {string} root - Checkout used to locate the machine resource database.
@@@ -244,13 -171,14 +262,13 @@@ export async function runGate(root, con
}
/** Run a full gate while its caller owns the queue lease; only a full run may stamp its tree. */
-function fullGateRun(root, config, trustStamp = false) {
+function fullGateRun(root, config, trustStamp = false, { waitMs = 0, log = gitPath(root, LOG) } = {}) {
if (trustStamp && isStampedGreen(root)) return { isGreen: true, isCached: true, output: '', seconds: 0, log: '' };
const before = committedTree(root);
- const { isGreen, output, seconds, profile, profilePath } = runProfiledShell(root, config.gate, { waitMs, profileFile: `${log}.profile.json` });
- const { isGreen, output, seconds } = runShell(root, config.gate, { pipefail: true });
- const log = gitPath(root, LOG);
++ const { isGreen, output, seconds, profile, profilePath } = runProfiledShell(root, config.gate, { waitMs, pipefail: true, profileFile: `${log}.profile.json` });
writeFileSync(log, output);
if (isGreen && before !== null && committedTree(root) === before) writeFileSync(gitPath(root, STAMP), `${before}\n`);
- return { isGreen, isCached: false, output, seconds, log };
+ return { isGreen, isCached: false, output, seconds, log, profile, profilePath };
}
/** Quote a fixed executable or selected path without permitting shell expansion. */
@@@ -269,46 -197,26 +287,47 @@@ function commandWord(value)
*/
export async function runSubmitGate(root, config, { base, trunk, changed, check, onWait }) {
if (!config.gate.trim()) throw new Refused('NO_GATE', 'no gate configured; set "gate" in pullboard.json, e.g. "npm test"');
- const selection = selectAffectedTests(root, { base, trunk, changed });
+ const selection = config.affectedTests
+ ? selectAffectedTests(root, { base, trunk, changed })
+ : { full: true, reason: 'affected-test selection is not enabled for this project', files: [] };
- return await withGateSlot(root, () => {
- const criterion = check ? runShell(root, check) : { isGreen: true, output: '', seconds: 0 };
- const receipt = { command: check, green: criterion.isGreen, seconds: criterion.seconds, checked: Boolean(check) };
+ return await withGateSlot(root, (lease) => {
+ const startedAt = Date.now();
const log = gitPath(root, 'pullboard-submit.log');
+ const checkLog = `${log}.check.log`;
+ const proofLog = `${log}.proof.log`;
+ const criterion = check ? runProfiledShell(root, check, {
+ waitMs: lease.waitMs, profileFile: `${checkLog}.profile.json`,
+ }) : { isGreen: true, output: '', seconds: 0 };
+ if (check) writeFileSync(checkLog, safeLog(criterion.output), { mode: 0o600 });
+ const receipt = { command: check, green: criterion.isGreen, seconds: criterion.seconds, checked: Boolean(check),
+ ...(check ? { log: checkLog, profilePath: criterion.profilePath, profile: criterion.profile } : {}) };
+ /** Persist the whole submission's wall time and queue wait once, alongside its combined raw log. */
+ const finish = (proof) => {
+ const profilePath = `${log}.profile.json`;
+ const profiles = [criterion.profile, proof.profile].filter(Boolean);
+ const profile = writeTimingProfile(profilePath, {
+ waitMs: lease.waitMs, wallMs: Math.max(0, Date.now() - startedAt),
+ files: profiles.flatMap(value => value.files), tests: profiles.flatMap(value => value.tests),
+ });
+ return { ...proof, log, seconds: criterion.seconds + proof.seconds, ...selection, check: receipt,
+ profile, profilePath, proofProfilePath: proof.profilePath, proofLog: proof.log };
+ };
if (!criterion.isGreen) {
writeFileSync(log, criterion.output);
- return { isGreen: false, isCached: false, output: criterion.output, seconds: criterion.seconds, log, ...selection, check: receipt };
+ return finish({ isGreen: false, isCached: false, output: criterion.output, seconds: 0, log: '' });
}
+ // The proof already owns this lease: its phase profile has no additional queue wait.
+ const proofWait = check ? 0 : lease.waitMs;
let proof;
- if (selection.full) proof = fullGateRun(root, config);
- else if (!selection.files.length) proof = { isGreen: true, output: '', seconds: 0, isCached: false, log };
+ if (selection.full) proof = fullGateRun(root, config, false, { waitMs: proofWait, log: proofLog });
+ else if (!selection.files.length) proof = { isGreen: true, output: '', seconds: 0, isCached: false, log: '' };
else {
- const runner = existsSync(join(root, 'bin/run-tests.js')) ? [process.execPath, 'bin/run-tests.js'] : [process.execPath, '--test'];
- const command = [...runner, ...selection.files.map(path => './' + path)].map(commandWord).join(' ');
+ const command = `${config.affectedTests.trimEnd()} ${selection.files.map(path => commandWord('./' + path)).join(' ')}`;
- proof = { ...runShell(root, command), isCached: false, log };
+ proof = { ...runProfiledShell(root, command, { waitMs: proofWait, profileFile: `${proofLog}.profile.json` }), isCached: false, log: proofLog };
+ writeFileSync(proofLog, proof.output);
}
writeFileSync(log, `item check:\n${criterion.output}\n${selection.full ? 'full gate' : 'affected tests'}:\n${proof.output}`);
- return { ...proof, log, seconds: criterion.seconds + proof.seconds, ...selection, check: receipt };
+ return finish(proof);
}, { onWait });
}