Merge origin/main (5225e35, v1.92.42.0) into gsta215-ceo-only-driver

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
garrytanandcapy-ai[bot] committed 2026-11-01 21:52:30 +00:00
commit f4547e07cc
249 files changed
+15292 -6073

No files matched your search

@@ -209,6 +209,42 @@ describe('runPlanSkillFloorCheck through the fake driver', () => {
expect(obs.summary).toBe('no qualifying finding question within 30000ms');
});
test('the 40851840940 provider error at an idle plan-mode prompt ends the floor check with its panel', async () => {
const plan: string = JSON.parse(fs.readFileSync(new URL('../fixtures/pty-idle-turn-end.json', import.meta.url), 'utf8')).planModeApiErrorIdle.visible;
const { obs } = await floor([{ onInput: '/plan-devex-review PLAN.md\r', screen: plan, effect: delivered }]);
expect(obs.outcome).toBe('api_error');
expect(obs.auqObserved).toBe(false);
expect(obs.elapsedMs).toBeLessThan(30_000);
expect(obs.summary).toBe('the CLI turn ended at an idle prompt (✻Brewed for 1m 13s · done 9:51 AM) after its public error panel: ' +
'●API Error: Connection lost mid-response. The response above may be incomplete.');
const running = plan.replace('⏸planmodeon (shift+tabtocycle)·←foragents', '⏸planmodeon (shift+tabtocycle)·esctointerrupt·←foragents');
const live = await floor([{ onInput: '/plan-devex-review PLAN.md\r', screen: running, effect: delivered }]);
expect(live.obs).toMatchObject({ outcome: 'timeout', summary: 'no qualifying finding question within 30000ms' });
});
test.skipIf(process.platform === 'win32')('a prose finding question earlier in the idle turn is assessed before the provider error panel ends the check, even when its transcript line lands after the screen goes idle', async () => {
const plan: string = JSON.parse(fs.readFileSync(new URL('../fixtures/pty-idle-turn-end.json', import.meta.url), 'utf8')).planModeApiErrorIdle.visible;
const prose = 'Which TTHW target should this journey be measured against?\nA) Champion (< 2 min)\nB) Competitive (2-5 min)';
const screen = plan.replace('●API Error:', `${prose.replace(/\n/g, '\r\n')}\r\n●API Error:`);
const stubDir = fs.mkdtempSync(path.join(os.tmpdir(), 'floor-judge-stub-'));
const stub = path.join(stubDir, 'claude');
fs.writeFileSync(stub, '#!/bin/sh\ncat >/dev/null\necho \'{"kind":"finding","seedId":"seed-1","questionId":"prose-1","optionId":"prose-1","reason":"the stub judge credits the staged prose question"}\'\n', { mode: 0o755 });
const saved = process.env.BROWSE_TERMINAL_BINARY;
process.env.BROWSE_TERMINAL_BINARY = stub;
try {
const asked = (ctx: FakeSessionContext) => journal(ctx, floorSession(ctx), 'assistant', [{ type: 'text', text: prose }]);
const sameTick = await floor([{ onInput: '/plan-devex-review PLAN.md\r', screen, effect: ctx => { delivered(ctx); asked(ctx); } }]);
const lateLine = await floor([{ onInput: '/plan-devex-review PLAN.md\r', screen, effect: delivered }, { afterMs: 4000, screen, effect: asked }]);
for (const { obs } of [sameTick, lateLine]) {
expect(obs).toMatchObject({ outcome: 'auq_observed', auqObserved: true });
expect(obs.summary).toContain('Current prose question addresses the owned seeded finding');
}
} finally {
if (saved === undefined) delete process.env.BROWSE_TERMINAL_BINARY; else process.env.BROWSE_TERMINAL_BINARY = saved;
fs.rmSync(stubDir, { recursive: true, force: true });
}
});
test('permission prompt: an unowned permission is neither granted nor counted', async () => {
const { obs, fake } = await floor([
{ onInput: '/plan-devex-review PLAN.md\r', screen: PERMISSION, effect: delivered },
@@ -13,6 +13,7 @@ import {
classifyPlanCountFrame,
idleTurnEnd,
} from './claude-pty-runner';
import { screenPanelEnd } from './pty/screen';
describe('saved preference annotation', () => {
test('recognizes the explicit preference attribution from the timed-out CEO capture', () => {
@@ -252,6 +253,25 @@ describe('idle turn end (captured CI screens)', () => {
expect(idleTurnEnd(scope + '\r' + question)).toBeNull();
});
test('the 40851840940 plan-mode idle footer ends the turn and names its provider error for the ledger', () => {
const plan: string = captures.planModeApiErrorIdle.visible;
const panel = '●API Error: Connection lost mid-response. The response above may be incomplete.';
expect(idleTurnEnd(plan)).toEqual({ done: '✻Brewed for 1m 13s · done 9:51 AM', apiError: panel });
expect(screenPanelEnd(plan)).toEqual({ end: 'api_error', evidence: panel });
expect(idleTurnEnd(plan.replace('⏸planmodeon (shift+tabtocycle)·←foragents', '⏸ plan mode on (shift+tab to cycle) · ← for agents')))
.toMatchObject({ apiError: panel });
});
test('negative controls: the running plan-mode footer and extra plan-mode footer text are not idle', () => {
const plan: string = captures.planModeApiErrorIdle.visible;
const footer = '⏸planmodeon (shift+tabtocycle)·←foragents';
expect(plan.split(footer)).toHaveLength(2);
expect(idleTurnEnd(plan.replace(footer, '⏸planmodeon (shift+tabtocycle)·esctointerrupt·←foragents'))).toBeNull();
expect(idleTurnEnd(plan.replace(footer, footer + ' · 1 background task'))).toBeNull();
expect(idleTurnEnd(plan.replace(footer, '⏸planmodeon (shift+tabtocycle)'))).toBeNull();
expect(screenPanelEnd(plan.replace(footer, '⏸planmodeon (shift+tabtocycle)·esctointerrupt·←foragents'))).toBeNull();
});
test('an API Error mention in prose or in an earlier turn is not this turn\'s error panel', () => {
expect(idleTurnEnd('The docs mention API Error: as an example.\r✻ Worked for 3s · done 1:00 PM\r❯ \r← for agents')).toEqual({ done: '✻ Worked for 3s · done 1:00 PM' });
const earlier = api.replace(/✻ Sautéedfor1m 20s · done11:34PM[\s\S]*$/, '✻ Sautéedfor1m 20s · done11:34PM\r❯ /plan-design-review\r●Done.\r✻ Worked for 2s · done 11:35PM\r❯ \r← for agents');
+3 -1
View File
@@ -80,7 +80,9 @@ function stagePieces(stage: string[], scope: ShellScope, alone: boolean): Piece[
if (!name || (discarded && name === 'echo')) return undefined;
// Backslashes are data only in these closed grep/awk display patterns.
const grepRange = /^grep\s+-n(?:\s+-i)?(?:\s+-B\d{1,4})?(?:\s+-A\d{1,4})?\s+(?:"(?:[^"\\$`]|\\[|.])*"|'(?:[^'\\$`]|\\[|.])*')\s+(.+)$/.exec(text);
const displayGrep = Boolean(grepRange && literal(grepRange[1]!) && !literal(grepRange[1]!)!.startsWith('-'));
// One or more literal file operands (the tokens after the quoted pattern), none of them an option.
const grepOperands = grepRange ? words.slice(words.findIndex((word, index) => index > 0 && /^["']/.test(word)) + 1) : [];
const displayGrep = grepOperands.length > 0 && grepOperands.every(operand => literal(operand) !== undefined && !literal(operand)!.startsWith('-'));
const awkRange = /^awk\s+'\/(?:[^/\\]|\\[./|])*\/,\/(?:[^/\\]|\\[./|])*\/'\s+(.+)$/.exec(text)
?? /^awk\s+'\/(?:[^/\\]|\\[./|])*\/\{f=1\} f&&\/(?:[^/\\]|\\[./|])*\/\{exit\} f'\s+(.+)$/.exec(text);
const displayAwk = Boolean(awkRange && literal(awkRange[1]!) && !literal(awkRange[1]!)!.startsWith('-'));
+17 -1
View File
@@ -60,12 +60,28 @@ export function vetDocsCompletion(result: DocsCompletion, evidence: {
* (Blocked recovery preserves partial content), so it is not the accepted attempt's unreported edit; the accepted attempt
* answers for it again only when its own `files_updated` claims it (an honest re-audit that re-edited the same document).
*/
export function acceptedChangedPaths(changed: string[], contracts: DocsCompletion[]): string[] {
export function acceptedChangedPaths(changed: string[], contracts: Array<Pick<DocsCompletion, 'files_updated'>>): string[] {
const accepted = contracts.at(-1)!;
const retained = contracts.slice(0, -1).flatMap(earlier => earlier.files_updated);
return changed.filter(p => !retained.includes(p) || accepted.files_updated.includes(p));
}
/**
* Each dispatch's completion in order. The accepted (last) attempt must meet the whole contract. An earlier attempt is one
* the parent rejected, so only what it reported is read: its audit id, status and files_updated (gate 40805543956: attempt
* 1 omitted documentation_section, the parent rejected it and re-audited over its retained edit).
*/
export function docsAttemptContracts(outputs: string[]): { accepted: DocsCompletion; attempts: Array<Pick<DocsCompletion, 'audit_id' | 'status' | 'files_updated'>> } {
const reports = outputs.map(output => JSON.parse(output.trimEnd().split('\n').at(-1)!));
const accepted = parseDocsCompletion(outputs.at(-1)!, reports.at(-1)?.audit_id);
const earlier = reports.slice(0, -1).map(report => {
if (!report || typeof report.audit_id !== 'string' || !['updated', 'current', 'blocked'].includes(report.status) || !Array.isArray(report.files_updated)
|| report.files_updated.some((file: unknown) => typeof file !== 'string' || !file.trim())) throw new Error('rejected attempt report');
return { audit_id: report.audit_id, status: report.status, files_updated: report.files_updated };
});
return { accepted, attempts: [...earlier, accepted] };
}
export function extractDocsDispatch(section: string): string {
const begin = section.indexOf('**Subagent prompt:**');
const end = section.indexOf('**Parent processing:**');
+386
View File
@@ -0,0 +1,386 @@
/**
* The generated bun-test child that test/docsync-fault-interface*.test.ts run: it mocks the docsync
* fixture, observer, e2e gate and session runner, imports test/skill-e2e-ship-docsync.test.ts and replays
* its registered callbacks (moved verbatim from test/docsync-fault-interface.test.ts, GSTA-151).
*/
import * as path from 'node:path';
import { DOCS_CHECKPOINT_MARKER } from './docsync-fault-actor';
export function docsFaultCallbackScript(root: string): string {
return `
import { expect, mock, test } from 'bun:test';
import * as fs from 'node:fs';
import * as path from 'node:path';
import type { SkillTestResult } from ${JSON.stringify(path.join(root, 'test/helpers/session-runner'))};
const root = ${JSON.stringify(root)};
const fixtureModule = path.join(root, 'test/helpers/docsync-fixture.ts');
const observerModule = path.join(root, 'test/helpers/docsync-observer.ts');
const fixtures = { ...await import(fixtureModule) };
const observers = { ...await import(observerModule) };
const { CAPTURE_MS, CAPTURE_LONG_MS } = await import(path.join(root, 'test/helpers/eval-budgets.ts'));
const { parseDocsCompletion } = await import(path.join(root, 'test/helpers/docsync-contract.ts'));
const { docsActorSeeded, DOCS_SEEDED_AUDIT_ID } = await import(path.join(root, 'test/helpers/docsync-fault-actor.ts'));
const callbacks = new Map();
let fixture, control = '', launches = 0, recorded, legacyReaudit = false;
let returnedResult: SkillTestResult | undefined;
let consumers: string[] = [];
function expectResult(result: SkillTestResult) {
expect(result).toBe(returnedResult);
expect(result).toEqual({
toolCalls: expect.any(Array), browseErrors: [], exitReason: 'success', duration: 0,
output: 'Bounded callback replay complete', transcript: [], model: 'free-callback-replay',
firstResponseMs: 0, maxInterTurnMs: 0,
costEstimate: { inputChars: 0, outputChars: 0, estimatedTokens: 0, estimatedCost: 0, turnsUsed: 1 },
});
expect(result.toolCalls.length).toBeGreaterThan(0);
}
mock.module(fixtureModule, () => ({ ...fixtures,
fixtureDocs(...args) { fixture = fixtures.fixtureDocs(...args); return fixture; },
}));
mock.module(observerModule, () => ({ ...observers,
docsBoundedStageInterface(...args) { return observers.docsBoundedStageInterface(...args) + '\\nBOUNDED_CALLBACK_USED'; },
}));
mock.module(path.join(root, 'test/helpers/e2e-gate.ts'), () => ({ describeE2ETier: () => (_name, body) => body() }));
mock.module(path.join(root, 'test/helpers/e2e-helpers.ts'), () => ({
runId: 'free-docsync-faults', describeIfSelected: (_name, _names, body) => body(),
testConcurrentIfSelected: (name, body, budget) => callbacks.set(name, { body, budget }),
createEvalCollector: () => ({}), finalizeEvalCollector() {},
logCost(_name, result) {
expectResult(result);
consumers.push('logCost');
},
recordE2E(_collector, _name, _label, result, verdict) {
expectResult(result);
expect(verdict).toEqual({ passed: control === '' });
consumers.push('recordE2E');
recorded = verdict;
},
}));
mock.module(path.join(root, 'test/helpers/session-runner.ts'), () => ({ async runSkillTest(options) {
launches++;
const legacy = options.testName === 'ship-docsync-failure';
const scenario = legacy ? 'legacy-completion' : options.testName.slice('ship-docsync-'.length);
expect(options.maxTurns).toBe(legacy ? 30 : 24);
expect(options.timeout).toBeGreaterThan((legacy ? CAPTURE_LONG_MS : CAPTURE_MS) - 20_000);
expect(options.timeout).toBeLessThanOrEqual((legacy ? CAPTURE_LONG_MS : CAPTURE_MS) - 15_000);
expect(options.tools).toEqual(['Bash', 'Read', 'Write', 'Edit', 'Glob', 'Grep']);
expect(options.allowedTools).toEqual(options.tools);
expect(options.prompt).toContain('BOUNDED_CALLBACK_USED');
expect(options.prompt).toContain(fixture.invocation);
expect(options.prompt).toContain('only you apply the loaded workflow');
expect(options.prompt).toContain('do not probe invented ids');
expect(options.prompt).toContain('Save each actual completion/rejected output once');
expect(options.prompt).toContain('Private artifact filenames must end in .json, .md or .markdown');
expect(options.prompt).toContain('.txt and .log filenames are not supported');
expect(options.prompt).toContain('in a .md file without changing its bytes or reconstructing JSON');
expect(options.prompt).toContain('the parent must not manufacture it');
const repairable = ['recovery', 'late-result'].includes(scenario);
const actor = path.join(root, 'test/helpers/docsync-fault-actor.ts');
const stateFile = path.join(fixture.home, 'actor-state.json');
expect(options.prompt.includes('bun ' + actor + ' repair ' + stateFile)).toBe(repairable);
expect(options.prompt.includes('returns no result within the Collect deadline')).toBe(repairable);
expect(options.prompt.includes('This launcher has no repair operation')).toBe(!repairable);
expect(options.prompt.includes('bun ' + actor + ' inspect ' + stateFile)).toBe(true);
expect(options.prompt).toContain('batched read-only observation');
expect(options.prompt).toContain('Parent output handling');
expect(options.prompt).toContain('as its own standalone Bash call with no redirect, pipe, wrapper, substitution or other composition');
expect(options.prompt).toContain('Native Read, Glob and Grep stay available for file reads and are not Bash commands');
expect(options.prompt).toContain('Never redirect a command into a file and never re-run a command merely to save its output');
expect(options.prompt).toContain('Keep inspect observations in their original tool results in context and compare those returned values directly');
expect(options.prompt).toContain('Do not transcribe or reserialize inspect JSON into duplicate snapshot files; prepare already saves the required candidate and prompt');
expect(options.prompt).toContain('preserve each actual child completion/rejected output once in Markdown');
expect(options.prompt).toContain('Persist each required checkpoint as one short appended journal entry');
expect(options.prompt).toContain('use native Edit with old_string exactly ' + ${JSON.stringify(JSON.stringify(DOCS_CHECKPOINT_MARKER))});
expect(options.prompt).toContain('new_string containing only the new entry followed by that same marker, and replace_all=false');
expect(options.prompt).toContain('if missing or duplicated, stop rather than guessing an edit');
expect(options.prompt).toContain('Preserve unrelated sections and every earlier entry byte-for-byte');
expect(options.prompt).toContain("retaining each earlier attempt's id, count, evidence paths and outcome");
expect(options.prompt).toContain('The latest stated value is current; do not recopy previous entries');
expect(options.prompt).toContain('Reference saved candidate/prompt/completion artifacts instead of repeating their contents or prior narration');
expect(options.prompt).toContain('Before dispatch, save the incremented attempt count, fresh audit id and candidate/prompt paths together');
expect(options.prompt).toContain('Save the returned child handle before polling');
expect(options.prompt).toContain('consolidation must never postpone the pre-launch count or child-settlement checks');
expect(options.prompt).toContain('If recovery is authorized, save the intermediate result in one checkpoint before continuing it');
expect(options.prompt).toContain('After the loaded Continue or recover / Blocked recovery steps reach a final outcome');
expect(options.prompt).toContain('Append the finishing checkpoint and Write the complete report in the same response using separate native file calls');
expect(options.prompt).toContain('Never omit the final report or final response, even when publication is blocked');
expect(options.prompt).toContain('when it requires stopping, write the required invocation state and report, then stop rather than continuing later preparation to fill optional artifacts');
expect(options.prompt).toContain('do not introduce any undeclared comparison or processing program to compare or transform observations');
expect(options.prompt).toContain('Use only the transport commands above and the commands permitted by the Fixture observation interface below');
expect(options.prompt).toContain('inspect takes no arguments beyond the state path shown above');
expect(options.prompt).not.toContain('inspect call below');
expect(options.prompt).not.toContain('inspect receipt');
const calls = [];
const config = JSON.parse(fs.readFileSync(path.join(fixture.env.CLAUDE_CONFIG_DIR, 'settings.json'), 'utf8'));
const hook = config.hooks.PreToolUse.flatMap(entry => entry.hooks).find(entry => entry.command.includes('docsync-fault-actor.ts'));
expect(hook).toBeDefined();
const record = (tool, input, output) => calls.push({ tool, input, output });
const pretool = (tool, input) => {
const result = Bun.spawnSync(['bash', '-c', hook.command], { cwd: fixture.repo,
stdin: Buffer.from(JSON.stringify({ hook_event_name: 'PreToolUse', cwd: fixture.repo, tool_name: tool, tool_input: input })),
stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
expect(result.exitCode, result.stderr.toString()).toBe(0);
};
const read = file_path => {
pretool('Read', { file_path });
const output = fs.readFileSync(file_path, 'utf8');
record('Read', { file_path }, output);
return output;
};
const write = (file_path, content) => {
pretool('Write', { file_path, content });
fs.writeFileSync(file_path, content);
record('Write', { file_path, content }, 'File written');
};
const invoke = (action, args = {}) => {
const argv = [actor, action, stateFile, ...Object.entries(args).map(([key, value]) => key + '=' + value)];
const command = 'bun ' + argv.join(' ');
pretool('Bash', { command });
const result = Bun.spawnSync([process.execPath, ...argv], { cwd: fixture.repo, stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
const text = result.stdout.toString().trimEnd();
const output = (result.exitCode ? 'Exit code ' + result.exitCode + '\\n' : '') + text;
record('Bash', { command }, output);
return { text, output, exit: result.exitCode };
};
read(path.join(fixture.home, 'phase.md'));
read(path.join(fixture.skills, 'ship/sections/documentation.md'));
const initialRecord = read(fixture.invocation);
expect(initialRecord).toContain('Attempts used: 0');
expect(initialRecord).toContain('synthetic prior-stage state');
const marker = ${JSON.stringify(DOCS_CHECKPOINT_MARKER)};
expect(initialRecord.split(marker)).toHaveLength(2);
const recordPrefix = initialRecord.split(marker)[0];
let checkpointCount = 0;
const seeded = docsActorSeeded(scenario);
let attemptsUsed = seeded ? 1 : 0;
let seedOutput = '';
if (seeded) {
expect(initialRecord).toContain('Attempts used: 1');
read(path.join(fixture.home, 'candidate-' + DOCS_SEEDED_AUDIT_ID + '.json'));
const saved = path.join(fixture.home, 'completion-' + DOCS_SEEDED_AUDIT_ID + '.md');
seedOutput = control === 'skip-seeded-output' ? fs.readFileSync(saved, 'utf8') : read(saved);
}
const checkpoint = (details, finished = false) => {
const before = fs.readFileSync(fixture.invocation, 'utf8');
expect(before.split(marker)).toHaveLength(2);
const entry = '### Checkpoint ' + (++checkpointCount) + '\\nAttempts used: ' + attemptsUsed + '.\\n'
+ details + '\\nNext: ' + (finished ? 'Documentation gate finished; see ship-report.md. STOP before Step 15.' : 'Continue the actual documentation gate; STOP before Step 15.') + '\\n';
const input = { file_path: fixture.invocation, old_string: marker, new_string: entry + marker, replace_all: false };
pretool('Edit', input);
const after = before.replace(input.old_string, input.new_string);
fs.writeFileSync(fixture.invocation, after);
record('Edit', input, 'File edited');
expect(after.startsWith(recordPrefix)).toBe(true);
expect(after.replace(input.new_string, marker)).toBe(before);
expect(after.split(marker)).toHaveLength(2);
expect(input.new_string).not.toContain(recordPrefix);
};
const inspectResult = invoke('inspect');
const observed = JSON.parse(inspectResult.text);
expect(observed.operation).toBe('inspect');
expect(observed.files[fixtures.DOC_PATH].exists).toBe(true);
expect(observed.pre_existing_dirty).toContain(String.fromCharCode(0));
expect(inspectResult.text).not.toContain(String.fromCharCode(0));
expect(calls.at(-1).output).toBe(inspectResult.text);
if (control === 'tampered-inspect') calls[calls.length - 1].output = inspectResult.text.replace('"operation":"inspect"', '"operation":"tampered"');
const prepare = id => {
const result = invoke('prepare', { audit_id: id });
expect(result.exit).toBe(0);
const prepared = JSON.parse(result.text);
read(prepared.candidate);
read(prepared.prompt);
return prepared;
};
const dispatch = prepared => {
attemptsUsed++;
checkpoint('Audit: ' + prepared.audit_id + '; candidate: ' + prepared.candidate + '; prompt: ' + prepared.prompt);
const result = invoke('dispatch', { audit_id: prepared.audit_id, candidate: prepared.candidate, prompt: prepared.prompt, run_in_background: 'false' });
const saved = calls.at(-2);
expect(saved.tool).toBe('Edit');
expect(saved.input.file_path).toBe(fixture.invocation);
expect(saved.input.old_string).toBe(marker);
expect(saved.input.new_string).toContain('Attempts used: ' + attemptsUsed);
expect(saved.input.new_string).toContain(prepared.audit_id);
expect(saved.input.new_string).toContain(prepared.candidate);
expect(saved.input.new_string).toContain(prepared.prompt);
return result;
};
let output = '', accepted = null, first;
if (scenario !== 'missing-asset') {
first = seeded ? { audit_id: DOCS_SEEDED_AUDIT_ID, candidate: path.join(fixture.home, 'candidate-' + DOCS_SEEDED_AUDIT_ID + '.json'),
prompt: path.join(fixture.home, 'prompt-' + DOCS_SEEDED_AUDIT_ID + '.md') } : prepare('ship-docs-20260926-a1');
const initial = seeded ? { text: seedOutput, output: seedOutput } : dispatch(first);
output = initial.text;
if (scenario === 'missing-marker') {
expect(initial.output).toBe('SESSION_KIND: interactive\\n{"schema_version":1,"audit_id":"' + first.audit_id + '","status":"blocked","files_updated":[],"files_reviewed":[],"documentation_section":"blocked — fixture child audit ' + first.audit_id + '; Missing spawned marker.","blockers":["Missing spawned marker"],"decisions":[]}');
}
if (scenario === 'launch-failure') {
expect(initial.text).toBe('Child launch failed: injected unavailable worker. No child was started.');
expect(seeded ? initialRecord.includes('dispatch exit code 23') : initial.output.startsWith('Exit code 23\\n')).toBe(true);
const attempts = JSON.parse(fs.readFileSync(stateFile, 'utf8')).tasks;
expect(attempts).toHaveLength(1);
expect(attempts[0].id).toBeNull();
expect(attempts[0].candidate).toBe(fs.readFileSync(first.candidate, 'utf8'));
}
if (['timeout-unsettled', 'late-result'].includes(scenario)) {
expect(initial.output).toBe('{"task_id":"fixture-child-1","status":"running","elapsed_ms":0,"virtual_clock":true}');
const task_id = JSON.parse(output).task_id;
if (seeded) expect(initialRecord).toContain('Returned child handle: ' + task_id + '.');
else checkpoint('Running child handle: ' + task_id);
expect(invoke('status', { task_id }).output).toBe('{"task_id":"fixture-child-1","status":"running","settled":false,"elapsed_ms":600001,"virtual_clock":true}');
const stop = invoke('stop', { task_id });
expect(JSON.parse(stop.text).settled).toBe(scenario === 'late-result');
if (control !== 'skip-post-stop-status') {
const status = invoke('status', { task_id });
if (scenario === 'timeout-unsettled') expect(status.output).toBe('{"task_id":"fixture-child-1","status":"running","settled":false,"elapsed_ms":900002,"virtual_clock":true}');
}
}
if (repairable) expect(invoke('repair').exit).toBe(0);
if (repairable || scenario.startsWith('stale-') || legacy && legacyReaudit) {
read(path.join(fixture.repo, 'app.ts'));
const second = prepare('ship-docs-20260926-a2');
if (control === 'stale-candidate' || control === 'legacy-stale') {
const old = JSON.parse(fs.readFileSync(first.candidate, 'utf8'));
old.audit_id = second.audit_id;
write(second.candidate, JSON.stringify(old));
}
output = dispatch(second).text;
if (scenario === 'late-result') expect(() => parseDocsCompletion(output, second.audit_id)).toThrow('completion identity');
else if (legacy) expect(() => parseDocsCompletion(output, second.audit_id)).toThrow('completion fields');
else accepted = parseDocsCompletion(output, second.audit_id);
if (control === 'legacy-third') {
const third = prepare('ship-docs-20260926-a3');
output = dispatch(third).text;
}
}
} else {
expect(fs.existsSync(path.join(fixture.skills, 'document-release/sections/audit-scope.md'))).toBe(false);
}
if (control === 'invalid-repair') expect(invoke('repair').output).toBe('Exit code 24\\nError: repair not available');
if (control === 'invented-handle') expect(invoke('status', { task_id: 'ship-docs-20260926-a1' }).output).toBe('Exit code 24\\nError: unknown fixture child');
if (control === 'restore-partial') write(path.join(fixture.repo, fixtures.DOC_PATH), Buffer.from(fixture.before.contents[fixtures.DOC_PATH], 'base64').toString());
if (control === 'user-content') write(path.join(fixture.repo, 'personal-note.txt'), 'clobbered');
if (control === 'private-state') read(stateFile);
if (control === 'git-mutation') record('Bash', { command: 'git add ' + fixtures.DOC_PATH }, '');
const runShell = (command) => {
pretool('Bash', { command });
const r = Bun.spawnSync(['bash', '-c', command], { cwd: fixture.repo, stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
record('Bash', { command }, (r.exitCode ? 'Exit code ' + r.exitCode + '\\n' : '') + r.stdout.toString().trimEnd());
return r.exitCode;
};
if (control === 'redirect-transport') {
const snapshot = path.join(fixture.home, 'snapshot.json');
expect(runShell('bun ' + actor + ' inspect ' + stateFile + ' > ' + snapshot)).toBe(0);
expect(calls.at(-1).output).toBe('');
expect(JSON.parse(fs.readFileSync(snapshot, 'utf8')).head).toBe(observed.head);
}
if (control === 'compare-program') expect(runShell('diff ' + path.join(fixture.repo, fixtures.DOC_PATH) + ' ' + path.join(fixture.repo, fixtures.DOC_PATH))).toBe(0);
if (control === 'mutate-index') {
const staged = Bun.spawnSync(['git', 'add', fixtures.DOC_PATH], { cwd: fixture.repo, stdout: 'pipe', stderr: 'pipe', timeout: 10_000 });
expect(staged.exitCode).toBe(0);
}
if (['legacy-unchanged', 'legacy-unsettled', 'legacy-fake-repair'].includes(control)) {
const state = JSON.parse(fs.readFileSync(stateFile, 'utf8'));
if (control === 'legacy-unchanged') {
state.tasks[1].observed_candidate.hashes = { ...state.tasks[0].observed_candidate.hashes };
state.tasks[1].candidate = JSON.stringify(state.tasks[1].observed_candidate);
}
if (control === 'legacy-unsettled') state.tasks[0].settled = false;
if (control === 'legacy-fake-repair') { state.repaired = true; state.events.push({ action: 'repair' }); }
fs.writeFileSync(stateFile, JSON.stringify(state));
}
const outside = path.join(path.dirname(import.meta.path), 'outside.md');
if (control === 'outside-artifact') record('Write', { file_path: outside, content: output }, 'attempted write');
if (control === 'protected-artifact') record('Write', { file_path: path.join(fixture.skills, 'private.md'), content: output }, 'attempted write');
if (control === 'script-artifact') record('Write', { file_path: actor, content: output }, 'attempted write');
if (control === 'symlink-artifact') {
fs.writeFileSync(outside, 'outside fixture control');
const link = path.join(fixture.home, 'linked.md');
fs.symlinkSync(outside, link);
record('Write', { file_path: link, content: output }, 'attempted write');
}
write(path.join(fixture.home, control === 'raw-text-artifact' ? 'completion.txt' : 'completion.md'), output);
expect(fs.readFileSync(path.join(fixture.home, control === 'raw-text-artifact' ? 'completion.txt' : 'completion.md'), 'utf8')).toBe(output);
if (control === '') expect(fs.readdirSync(fixture.home).filter(name => /inspect|snapshot/.test(name))).toEqual([]);
const report = path.join(fixture.home, 'ship-report.md');
const finalReport = control === 'false-current' ? 'Documentation: current' : accepted
? 'Documentation: ' + accepted.status + '\\n' + accepted.documentation_section
: 'Documentation: blocked\\n' + (legacy ? 'Invalid legacy completion; partial edit retained: ' + fixtures.DOC_PATH : 'Actual child result did not clear the gate') + '\\nEvidence: completion.md';
checkpoint(finalReport, true);
if (control !== 'missing-report') write(report, finalReport);
expect(fs.readFileSync(fixture.invocation, 'utf8')).toContain(finalReport);
expect(fs.readFileSync(fixture.invocation, 'utf8')).toContain('Attempts used: ' + attemptsUsed);
if (attemptsUsed > 1) expect(fs.readFileSync(fixture.invocation, 'utf8')).toContain(first.audit_id);
if (control === '') {
expect(calls.slice(-2).map(call => [call.tool, call.input.file_path])).toEqual([
['Edit', fixture.invocation], ['Write', report],
]);
expect(fs.readFileSync(report, 'utf8')).toBe(finalReport);
}
if (accepted) expect(invoke('publish', { audit_id: accepted.audit_id, report }).exit).toBe(0);
if (control === 'invalid-publication') expect(invoke('publish', { audit_id: 'ship-docs-20260926-a1', report }).exit).toBe(24);
returnedResult = { exitReason: 'success', output: 'Bounded callback replay complete', toolCalls: calls, transcript: [],
browseErrors: [], duration: 0, model: 'free-callback-replay', firstResponseMs: 0, maxInterTurnMs: 0,
costEstimate: { inputChars: 0, outputChars: 0, estimatedTokens: 0, estimatedCost: 0, turnsUsed: 1 } } satisfies SkillTestResult;
return returnedResult;
} }));
await import(path.join(root, 'test/skill-e2e-ship-docsync.test.ts'));
expect(callbacks.size).toBe(12);
const names = ['ship-docsync-failure', 'ship-docsync-missing-marker', 'ship-docsync-missing-asset',
'ship-docsync-launch-failure', 'ship-docsync-timeout-unsettled', 'ship-docsync-late-result',
'ship-docsync-stale-before', 'ship-docsync-stale-after', 'ship-docsync-recovery'];
for (const name of names) test(name + ' consumes actual adapter results', async () => {
control = '';
legacyReaudit = false;
recorded = undefined;
returnedResult = undefined;
consumers = [];
const before = launches;
expect(callbacks.get(name).budget).toBe(name === 'ship-docsync-failure' ? CAPTURE_LONG_MS : CAPTURE_MS);
await callbacks.get(name).body();
expect(launches).toBe(before + 1);
expect(recorded).toEqual({ passed: true });
expect(consumers).toEqual(['logCost', 'recordE2E']);
expect(fs.existsSync(fixture.home)).toBe(false);
});
test('ship-docsync-failure accepts its remaining changed-input audit and preserves raw output in Markdown', async () => {
control = '';
legacyReaudit = true;
recorded = undefined;
returnedResult = undefined;
consumers = [];
await callbacks.get('ship-docsync-failure').body();
expect(recorded).toEqual({ passed: true });
expect(consumers).toEqual(['logCost', 'recordE2E']);
expect(fs.existsSync(fixture.home)).toBe(false);
});
for (const [name, mutation] of [
['ship-docsync-failure', 'false-current'], ['ship-docsync-failure', 'invalid-publication'],
['ship-docsync-failure', 'restore-partial'], ['ship-docsync-failure', 'user-content'],
['ship-docsync-failure', 'private-state'], ['ship-docsync-failure', 'git-mutation'],
['ship-docsync-failure', 'mutate-index'], ['ship-docsync-missing-marker', 'invalid-repair'],
['ship-docsync-missing-marker', 'redirect-transport'], ['ship-docsync-missing-marker', 'compare-program'],
['ship-docsync-launch-failure', 'invented-handle'], ['ship-docsync-timeout-unsettled', 'skip-post-stop-status'],
['ship-docsync-late-result', 'missing-report'],
['ship-docsync-stale-before', 'stale-candidate'],
['ship-docsync-recovery', 'skip-seeded-output'],
['ship-docsync-failure', 'legacy-unchanged'], ['ship-docsync-failure', 'legacy-unsettled'],
['ship-docsync-failure', 'legacy-stale'], ['ship-docsync-failure', 'legacy-third'],
['ship-docsync-failure', 'legacy-fake-repair'],
['ship-docsync-missing-marker', 'tampered-inspect'],
['ship-docsync-missing-marker', 'raw-text-artifact'], ['ship-docsync-missing-marker', 'outside-artifact'],
['ship-docsync-missing-marker', 'protected-artifact'], ['ship-docsync-missing-marker', 'symlink-artifact'],
['ship-docsync-missing-marker', 'script-artifact'],
]) test(name + ' rejects ' + mutation, async () => {
control = mutation;
legacyReaudit = name === 'ship-docsync-failure';
recorded = undefined;
returnedResult = undefined;
consumers = [];
await expect(callbacks.get(name).body()).rejects.toThrow();
expect(recorded).toEqual({ passed: false });
expect(consumers).toEqual(['logCost', 'recordE2E']);
expect(fs.existsSync(fixture.home)).toBe(false);
});
`;
}
+27 -14
View File
@@ -328,6 +328,9 @@ function docsUnrollLoops(text: string): string | null {
* The candidate's --help prints its usage and returns before it touches Git or a
* file (bin/gstack-docs-candidate main), so joining it reads nothing more (gates
* 40600731931 and 40627127462, screen 40558235014: the parent ended a line of reads with it).
* A declared read command given --help prints its own usage instead of reading, and its
* operands stay checked as reads (screens 40822033640 and 40815828320, gate 40809051510:
* the parent joined `cat <candidate> --help 2>&1 | head -N`, which printed cat's usage).
*/
function docsComposedReadAllowed(text: string, fixture: ReturnType<typeof fixtureDocs>): boolean {
const line = docsUnrollLoops(text);
@@ -337,13 +340,14 @@ function docsComposedReadAllowed(text: string, fixture: ReturnType<typeof fixtur
if (!segments) return false;
const candidate = path.join(fixture.skills, 'bin/gstack-docs-candidate').split(path.sep).join('/');
const commands = segments.map(segment => line.slice(segment.start, segment.end).trim());
const declared = commands.flatMap((command, index) => /^git(?:\s|$)/.test(command) || command.startsWith(`${candidate} `) ? [index] : []);
const readHelp = (command: string) => DOCS_READ_COMMANDS.includes(command.split(/\s+/)[0]!) && /\s--help(?:\s|$)/.test(command);
const declared = commands.flatMap((command, index) => /^git(?:\s|$)/.test(command) || command.startsWith(`${candidate} `) || readHelp(command) ? [index] : []);
if (!declared.length || commands.some(command => /^cd(?:\s|$)/.test(command))) return false;
let neutral = line;
for (const index of declared.reverse()) {
const read = unwrapHarmlessRead(commands[index]!, fixture);
const help = read !== null && /^(?:(?:snapshot|compare) )?--help$/.test(read.slice(candidate.length + 1));
if (segments[index - 1]?.op === '|' || read === null || !(/^git\s/.test(read) || (read.startsWith(`${candidate} `) && help))
if (segments[index - 1]?.op === '|' || read === null || !(/^git\s/.test(read) || (read.startsWith(`${candidate} `) && help) || readHelp(read))
|| !literalDocsCommandAllowed(read, fixture, [])) return false;
neutral = `${neutral.slice(0, segments[index]!.start)} pwd ${neutral.slice(segments[index]!.end)}`;
}
@@ -458,16 +462,18 @@ function docsPrivateArtifact(file: string, fixture: ReturnType<typeof fixtureDoc
}
/**
* A candidate call at a wrong binary path that does not exist exited 127 before anything ran; it is ignored only when
* the same command at the declared path runs: after the slip for snapshot and compare, whose recovery the lifecycle
* needs, and anywhere in the transcript for --help, which reads nothing the agent still has to recover (gate
* 40323989742: the parent read the usage at the declared path, mistyped the path on a second --help, then went on).
* A call to one of Step 14.5's own helpers (the docs candidate or the cap gate; never a lifecycle helper) at a wrong
* binary path that does not exist exited 127 before anything ran; it is ignored only when the same command at the
* declared path runs: after the slip for snapshot, compare and the cap gate, whose result the workflow needs, and
* anywhere in the transcript for --help, which reads nothing the agent still has to recover (gate 40323989742: the
* parent read the usage at the declared path, mistyped the path on a second --help, then went on; screen 40749421675:
* the parent typed the cap gate at the shard root, then ran it at the declared path).
*/
function candidateNotFound(calls: SkillTestResult['toolCalls'], index: number, fixture: ReturnType<typeof fixtureDocs>, scripts: string[]): boolean {
function helperNotFound(calls: SkillTestResult['toolCalls'], index: number, fixture: ReturnType<typeof fixtureDocs>, scripts: string[]): boolean {
const command = String(calls[index].input?.command ?? '').trim();
const binary = command.split(' ')[0]!;
const candidate = path.join(fixture.skills, 'bin/gstack-docs-candidate').split(path.sep).join('/');
if (!/^\/[\w.\/-]+\/gstack-docs-candidate$/.test(binary) || binary === candidate) return false;
const declared = path.join(fixture.skills, 'bin', path.basename(binary)).split(path.sep).join('/');
if (!/^\/[\w.\/-]+\/gstack-(?:docs-candidate|ship-receipt)$/.test(binary) || binary === declared) return false;
if (calls[index].output.trimEnd() !== `Exit code 127\n(eval):1: no such file or directory: ${binary}`) return false;
try {
fs.lstatSync(binary);
@@ -475,8 +481,8 @@ function candidateNotFound(calls: SkillTestResult['toolCalls'], index: number, f
} catch (error) {
if (!['ENOENT', 'ENOTDIR'].includes((error as NodeJS.ErrnoException).code ?? '')) return false;
}
const retry = candidate + command.slice(binary.length);
const candidates = retry === `${candidate} --help` ? calls.filter((_, position) => position !== index) : calls.slice(index + 1);
const retry = declared + command.slice(binary.length);
const candidates = retry === `${declared} --help` ? calls.filter((_, position) => position !== index) : calls.slice(index + 1);
return docsCommandAllowed(retry, fixture, scripts) && candidates.some(call =>
call.tool === 'Bash' && String(call.input?.command ?? '').trim() === retry && !call.output.startsWith('Exit code'));
}
@@ -487,7 +493,7 @@ export function docsToolFailures(result: SkillTestResult, fixture: ReturnType<ty
const authoredDoc = path.join(repo, DOC_PATH);
for (const [index, call] of result.toolCalls.entries()) {
if (call.tool === 'Bash' && !docsCommandAllowed(String(call.input?.command ?? ''), fixture, scripts) &&
!candidateNotFound(result.toolCalls, index, fixture, scripts)) failures.push('command outside declared docs observation interface');
!helperNotFound(result.toolCalls, index, fixture, scripts)) failures.push('command outside declared docs observation interface');
if (['Write', 'Edit'].includes(call.tool)) {
const file = path.resolve(fixture.repo, call.input?.file_path ?? '');
const actual = actualWritePath(file);
@@ -520,11 +526,18 @@ export function docsCompletedRead(result: SkillTestResult, file: string, fixture
const expanded = docsUnrollLoops(command);
const grammar = !literal && expanded !== null && !/(?:^|[;&|]\s*)cd\s/.test(command)
&& (readOnlyCommandAllowed(command, docsReadOnlyScope(fixture)) || docsComposedReadAllowed(command, fixture));
const catArgs = !literal && !grammar ? [] : (expanded ?? command).split(/\s*(?:;|&&|\|\|)\s*/).filter(part => /^cat\s/.test(part) && !part.includes('|'))
.flatMap(part => part.match(/'[^']*'|"[^"]*"|[^\s'"]+/g)?.slice(1).map(arg => /^['"]/.test(arg) ? arg.slice(1, -1) : arg) ?? []);
const parts = !literal && !grammar ? [] : (expanded ?? command).split(/\s*(?:;|&&|\|\|)\s*/);
const operands = (part: string) => part.match(/'[^']*'|"[^"]*"|[^\s'"]+/g)?.slice(1).map(arg => /^['"]/.test(arg) ? arg.slice(1, -1) : arg) ?? [];
const catArgs = parts.filter(part => /^cat\s/.test(part) && !part.includes('|')).flatMap(operands);
const cat = call.tool === 'Bash' && catArgs.some(arg => resolve(arg) === target);
if ((read || cat) && !/^(?:<tool_use_error>|Error(?: reading file|:)|Exit code [1-9]\d*\b)/i.test(call.output.trimStart()) &&
call.output.replace(/^\s*\d+(?:→|\t)/gm, '').includes(source)) return true;
// A line's exit status is its last command's: when the line's first command cats the file unpiped and the output
// opens with its full bytes, a later command's failure does not undo that read (screen 40828580338: zsh read the
// separator `echo ======` as an = command lookup and abandoned the rest of the line after phase.md printed in full).
const status = /^Exit code [1-9]\d*\n/.exec(call.output.trimStart());
const lead = cat && /^cat\s/.test(parts[0]!) && !parts[0]!.includes('|') ? operands(parts[0]!).find(arg => !arg.startsWith('-')) : undefined;
if (status && lead !== undefined && resolve(lead) === target && call.output.trimStart().slice(status[0].length).startsWith(source)) return true;
}
return false;
}
+131
View File
@@ -0,0 +1,131 @@
/**
* Shared fixture for the gstack-doctor tests (test/gstack-doctor.test.ts,
* test/gstack-doctor-check.test.ts, test/gstack-doctor-launch.test.ts): a
* fixture install root, state root, stub bun/codex/claude on PATH, and the
* doctor() and rowOf() readers. Each test file calls useDoctorCleanup().
*/
import { afterEach } from 'bun:test';
import { spawnSync } from 'child_process';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
// setup builds browse/dist/browse.exe on Windows (Git Bash), browse/dist/browse elsewhere.
export const BROWSE_BIN = process.platform === 'win32' ? 'browse/dist/browse.exe' : 'browse/dist/browse';
export const EXE = process.platform === 'win32' ? '.exe' : '';
export const OTHER_BINS = ['browse/dist/find-browse', 'design/dist/design', 'make-pdf/dist/pdf', 'bin/gstack-global-discover'].map(rel => rel + EXE);
export const REPO = path.resolve(import.meta.dir, '../..');
const COPIED = [
'setup', 'VERSION',
'bin/gstack-doctor', 'bin/gstack-codex-status.sh', 'bin/gstack-state-root.sh', 'bin/gstack-install-registry.sh',
'bin/gstack-render-claude.sh', 'bin/gstack-bun-version.sh', 'bin/gstack-hook-check', 'bin/gstack-config',
'autoplan/SKILL.md', // its frontmatter registers the autoplan hook the hooks-row test breaks
'bin/gstack-launch-probe.sh',
'bin/gstack-doctor-check.sh', 'bin/gstack-doctor-components.sh', 'bin/gstack-runtime-pins.ts', 'lib/runtime-pins.ts',
'bin/gstack-windows-bash.ts', 'lib/script-invocation.ts', 'lib/bun-isolation.ts', 'lib/result-codes.ts', 'lib/result-codes-release.ts', 'lib/result-codes-capy.ts', 'lib/result-codes-budget.ts', 'lib/result-codes-eval.ts', 'lib/result-codes-plan.ts', 'lib/result-codes-autoplan.ts', // the windows bash row
];
const bases: string[] = [];
/** Registers the per-test fixture cleanup; each test file calls it at top level (a hook in this module would bind to the first importing file only). */
export function useDoctorCleanup() {
afterEach(() => { for (const b of bases.splice(0)) fs.rmSync(b, { recursive: true, force: true }); });
}
export const write = (file: string, text: string, mode = 0o644) => {
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, text, { mode });
};
export const script = (file: string, lines: string[]) => write(file, ['#!/usr/bin/env bash', ...lines].join('\n') + '\n', 0o755);
/** The fixture's PATH entries minus every directory holding a real bun, codex or claude. */
function hostPath(base: string): string {
const names = ['bun', 'codex', 'claude'];
const exts = process.platform === 'win32' ? ['', '.exe', '.cmd', '.ps1'] : [''];
return (process.env.PATH ?? process.env.Path ?? '').split(path.delimiter).filter(Boolean).map((dir, i) => {
if (!names.some(n => exts.some(e => fs.existsSync(path.join(dir, n + e))))) return dir;
const shim = path.join(base, `host-${i}`);
fs.mkdirSync(shim, { recursive: true });
for (const name of fs.readdirSync(dir)) {
if (names.some(n => exts.some(e => name === n + e))) continue;
try { fs.symlinkSync(path.join(dir, name), path.join(shim, name)); } catch { /* unreadable entry */ }
}
return shim;
}).join(path.delimiter);
}
export interface Fixture { base: string; root: string; state: string; home: string; work: string; stub: string; probeLog: string; env: Record<string, string> }
export function makeFixture(): Fixture {
const base = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-doctor-')));
bases.push(base);
const root = path.join(base, 'gstack');
const state = path.join(base, 'state');
const home = path.join(base, 'home');
const work = path.join(base, 'work');
const stub = path.join(base, 'stub');
const probeLog = path.join(base, 'probe-calls');
for (const dir of [state, home, work, stub]) fs.mkdirSync(dir, { recursive: true });
for (const rel of COPIED) {
fs.mkdirSync(path.dirname(path.join(root, rel)), { recursive: true });
fs.copyFileSync(path.join(REPO, rel), path.join(root, rel));
fs.chmodSync(path.join(root, rel), fs.statSync(path.join(REPO, rel)).mode);
}
script(path.join(root, 'bin/gstack-codex-probe'), [
'echo "$*" >> "$DOCTOR_PROBE_LOG"',
'case "$1" in',
' select-model) [ "${STUB_SELECT_FAIL:-}" = 1 ] && { echo "gstack-codex-probe: cannot find its scripts dir" >&2; exit 1; }',
' echo "CODEX_SEL: gpt-stub-5"; echo "CODEX_SEL_KIND: $2"; echo "CODEX_MODEL: gpt-stub-5 ($2; source: codex config.toml)" >&2 ;;',
' check-auth) [ "${STUB_AUTH_FAIL:-}" = 1 ] && { echo AUTH_FAILED; exit 1; }; echo AUTH_OK ;;',
' show-sandbox) echo "CODEX_SANDBOX: read-only" ;;',
' check-sandbox|check-version) ;;',
' probe-model) echo "CODEX_PROBE_STATE: ${STUB_PROBE_STATE:-ok}"; exit "${STUB_PROBE_EXIT:-0}" ;;',
' *) exit 64 ;;',
'esac',
]);
const listed = spawnSync('bash', [path.join(root, 'bin/gstack-hook-check'), '--list', root], { encoding: 'utf8', timeout: 20_000 });
const hooks = listed.stdout.split('\n').map(line => line.trim()).filter(Boolean);
if (!hooks.includes('autoplan/bin/phase-publication-hook')) throw new Error(`gstack-hook-check --list missed the autoplan hook: ${listed.stdout}${listed.stderr}`);
for (const hook of hooks) write(path.join(root, hook), '#!/bin/sh\nexit 0\n', 0o755);
// The doctor launches each compiled binary's --version (#2595), so the
// stand-ins answer it like the real binaries do.
for (const rel of [BROWSE_BIN, ...OTHER_BINS]) write(path.join(root, rel), '#!/bin/sh\necho built\n', 0o755);
for (const rel of ['browse/dist/server-node.mjs', 'browse/dist/.build-complete']) write(path.join(root, rel), 'built\n', 0o755);
const version = fs.readFileSync(path.join(root, 'VERSION'), 'utf8').trim();
write(path.join(state, 'installs.tsv'),
['claude', 'global', '-', path.join(home, '.claude/skills'), root, root, version, 'false', 'committed', '2026-10-07T00:00:00Z'].join('\t') + '\n');
// The stub answers --version; anything else (the pins row runs bin/gstack-runtime-pins.ts) goes to the real bun.
script(path.join(stub, 'bun'), ['[ "$1" = --version ] && { echo "${STUB_BUN_VERSION:-1.4.2}"; exit 0; }', `exec "${process.execPath}" "$@"`]);
script(path.join(stub, 'codex'), ['[ "$1" = --version ] && { echo "codex-cli 0.130.0"; exit 0; }', 'echo "unexpected codex call: $*" >> "$DOCTOR_PROBE_LOG"', 'exit 9']);
script(path.join(stub, 'claude'), ['[ "$1" = --version ] && { echo "2.1.292 (Claude Code)"; exit 0; }', 'exit 9']);
const env: Record<string, string> = {
PATH: [stub, hostPath(base)].join(path.delimiter),
HOME: home, GSTACK_STATE_ROOT: state, TMPDIR: base, DOCTOR_PROBE_LOG: probeLog,
};
if (process.env.SYSTEMROOT) env.SYSTEMROOT = process.env.SYSTEMROOT;
return { base, root, state, home, work, stub, probeLog, env };
}
export function doctor(f: Fixture, args: string[] = [], extra: Record<string, string> = {}) {
const r = spawnSync('bash', [path.join(f.root, 'bin/gstack-doctor'), ...args], { cwd: f.work, encoding: 'utf8', env: { ...f.env, ...extra }, timeout: 60_000 });
const out = `${r.stdout}${r.stderr}`;
return { status: r.status, out, row: (name: string) => rowOf(r.stdout, name) };
}
/** The named row and its fix line: { state, detail, fix }. */
export function rowOf(stdout: string, name: string) {
const lines = stdout.split('\n');
const i = lines.findIndex(l => l.slice(16, 32).trim() === name);
if (i < 0) throw new Error(`no row "${name}" in:\n${stdout}`);
const fix = lines[i + 1]?.startsWith(' '.repeat(32) + 'fix: ') ? lines[i + 1].slice(37) : '';
return { state: lines[i].slice(0, 16).trim(), detail: lines[i].slice(32), fix };
}
/** How bash spells a directory (Git Bash on Windows prints /c/...). */
export const bashPath = (dir: string) => spawnSync('bash', ['-c', 'cd "$1" && pwd', '_', dir], { encoding: 'utf8', timeout: 10_000 }).stdout.trim();
export const probeCalls = (f: Fixture) => fs.existsSync(f.probeLog) ? fs.readFileSync(f.probeLog, 'utf8') : '';
export const iso = (secondsAgo: number) => new Date(Date.now() - secondsAgo * 1000).toISOString().replace(/\.\d+Z$/, 'Z');
export const syncOn = (f: Fixture, status: Record<string, unknown>) => {
fs.mkdirSync(path.join(f.state, '.git'), { recursive: true });
write(path.join(f.state, 'config.yaml'), 'artifacts_sync_mode: artifacts-only\n');
write(path.join(f.state, '.brain-sync-status.json'), JSON.stringify(status).replace(/":/g, '": ').replace(/,"/g, ', "') + '\n');
};
+10 -2
View File
@@ -68,6 +68,7 @@ export const FREE_FIXTURES: Readonly<Record<string, readonly string[]>> = {
'test/fixtures/coverage-audit-parallel-column.json': ['test/coverage-audit-evidence.test.ts'],
'test/fixtures/coverage-audit-separator-collision.json': ['test/coverage-audit-evidence.test.ts'],
'test/fixtures/coverage-audit-summary.json': ['test/coverage-audit-evidence.test.ts'],
'test/fixtures/coverage-audit-two-file-grep.json': ['test/coverage-audit-evidence.test.ts'],
'test/fixtures/coverage-audit-wc-anchor.json': ['test/coverage-audit-evidence.test.ts'],
'test/fixtures/credential-rejection-39696775546.json': ['test/credential-rejection.test.ts'],
'test/fixtures/cso-eval/**': ['scripts/cso-eval.ts', 'test/cso-eval.test.ts', 'test/cso-stack-cold-integration.test.ts', 'test/helpers/cso-eval-oracles.ts'],
@@ -88,6 +89,8 @@ export const FREE_FIXTURES: Readonly<Record<string, readonly string[]>> = {
'test/fixtures/design-md-legacy.md': ['test/design-md.test.ts'],
'test/fixtures/design-ui-focus-capture-39199692993.json': ['test/plan-design-with-ui-fixture.test.ts'],
'test/fixtures/design-ui-focus-capture-40664336141.json': ['test/plan-design-with-ui-fixture.test.ts'],
'test/fixtures/design-ui-focus-capture-41178131219.json': ['test/plan-design-with-ui-fixture.test.ts'],
'test/fixtures/design-ui-focus-capture-41186376825.json': ['test/plan-design-with-ui-fixture.test.ts'],
'test/fixtures/design-ui-focus-capture.json': ['test/plan-design-with-ui-fixture.test.ts'],
'test/fixtures/detector-corpora/auto-decide-preserved/**': ['test/detector-corpus-auto-decide-preserved.test.ts'],
'test/fixtures/detector-corpora/plan-ceo-section-loading/**': ['test/detector-corpus-plan-ceo-section-loading.test.ts'],
@@ -111,9 +114,13 @@ export const FREE_FIXTURES: Readonly<Record<string, readonly string[]>> = {
'test/fixtures/disabled-prior-clock-36903600510.json': ['test/disabled-dated-record-at.test.ts'],
'test/fixtures/docsync-branch-listing-public.json': ['test/docsync-command-grammar.test.ts'],
'test/fixtures/docsync-followup-echo-37188668421.json': ['test/docsync-child-marker.test.ts'],
'test/fixtures/docsync-invalid-first-attempt-public.json': ['test/ship-document-release-dispatch.test.ts'],
'test/fixtures/docsync-observer-commands.json': ['test/docsync-lifecycle-interface.test.ts'],
'test/fixtures/docsync-phase-read-aborted-public.json': ['test/docsync-authority.test.ts'],
'test/fixtures/docsync-read-help-public.json': ['test/docsync-command-grammar.test.ts'],
'test/fixtures/docsync-replay/37237194905-late-result-calls.json': ['test/docsync-authority.test.ts'],
'test/fixtures/docsync-replay/37239016858-completion-native.json': ['test/docsync-nested-writes.test.ts'],
'test/fixtures/docsync-ship-receipt-not-found-public.json': ['test/docsync-lifecycle-interface.test.ts'],
'test/fixtures/docsync-store-38969924945-bash.json': ['test/docsync-command-grammar.test.ts'],
'test/fixtures/docsync-two-attempts-public.json': ['test/ship-document-release-dispatch.test.ts'],
'test/fixtures/dx-manual-handoff-ao.json': ['test/plan-count-completion.test.ts'],
@@ -181,6 +188,7 @@ export const FREE_FIXTURES: Readonly<Record<string, readonly string[]>> = {
'test/fixtures/plan-ceo-floor-unasked-decisions-872e154.json': ['test/plan-ceo-floor-interactive-boundary.test.ts'],
'test/fixtures/plan-floor-edit-wrap-37176835584.json': ['test/plan-floor-edit-wrap.test.ts'],
'test/fixtures/plan-format-kind-notes.json': ['test/plan-format-kind-note.test.ts'],
'test/fixtures/qa-caller-child-handoff-2026-10-29.json': ['test/qa-caller-review-plan.test.ts'],
'test/fixtures/qa-caller-handoff-order-public.json': ['test/qa-exploratory-callers.test.ts'],
'test/fixtures/qa-caller-merge-base-diff-40737741454.json': ['test/qa-caller-review-plan.test.ts'],
'test/fixtures/qa-caller-read-probe-mtb1007a.json': ['test/qa-exploratory-callers.test.ts'],
@@ -203,9 +211,9 @@ export const FREE_FIXTURES: Readonly<Record<string, readonly string[]>> = {
'test/fixtures/shard-cli-parity/**': ['test/shard-cli-parity.test.ts'],
'test/fixtures/shard-equivalence/**': ['test/shard-engine-equivalence.test.ts'],
'test/fixtures/shared-libs-claude-version-probe.json': ['test/shared-libs-fixture.test.ts'],
'test/fixtures/shared-libs-index-flags-loop-read-39173752116.json': ['test/shared-libs-checker-interface-evidence.test.ts'],
'test/fixtures/shared-libs-index-flags-loop-read-39173752116.json': ['test/shared-libs-checker-interface-evidence-replays.test.ts'],
'test/fixtures/shared-libs-no-change-ci-public.json': ['test/shared-libs-fixture.test.ts'],
'test/fixtures/shared-libs-path-ignored-errored-read-40617200857.json': ['test/shared-libs-checker-interface-evidence.test.ts'],
'test/fixtures/shared-libs-path-ignored-errored-read-40617200857.json': ['test/shared-libs-checker-interface-evidence-replays.test.ts'],
'test/fixtures/shared-libs-plan-callers-fixes-behavior-local.json': ['test/shared-libs-plan-actor.test.ts'],
'test/fixtures/shared-libs-plan-callers-future-risk-37195203538.json': ['test/shared-libs-plan-actor.test.ts'],
'test/fixtures/shared-libs-plan-callers-no-hardening-36633323521.json': ['test/shared-libs-plan-actor.test.ts'],
@@ -0,0 +1,31 @@
/**
* Shared fixture for the #1694 host-render prune tests (test/host-renders-prune*.test.ts):
* a real `--host all` legacy render, the backup listing and a setup run that must pass.
*/
import { expect } from 'bun:test';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { runGeneration } from '../../scripts/gen-skill-docs';
import { runSetup, type Fixture } from './install-fixture';
export const ROOT = path.resolve(import.meta.dir, '../..');
export const OTHER_DIRS = ['.agents', '.factory', '.kiro', '.opencode', '.cursor', '.copilot', '.agy', '.gemini-cli', '.slate', '.openclaw', '.hermes', '.gbrain'];
export const skillFiles = (dir: string): string[] => !fs.existsSync(dir) ? []
: (fs.readdirSync(dir, { recursive: true }) as string[]).filter(rel => path.basename(rel) === 'SKILL.md' && fs.statSync(path.join(dir, rel)).isFile());
export async function legacyRender(src: string): Promise<void> {
const result = await runGeneration({ host: 'all', outputRoot: src });
if (result.exitCode !== 0) throw new Error('legacy render failed');
}
export function backups(f: Fixture): string[] {
const dir = path.join(f.home, '.gstack/backups/host-renders');
return fs.existsSync(dir) ? fs.readdirSync(dir).map(d => path.join(dir, d)) : [];
}
export function setupOk(f: Fixture, src: string, args: string[] = []) {
const r = runSetup(f, path.join(src, 'setup'), args);
expect(r.status, r.stdout + r.stderr).toBe(0);
return r;
}
+12 -2
View File
@@ -138,17 +138,27 @@ export async function callJudge<T>(
// What a cancelled request had received, so a judge deadline names rate-limit
// waits, SDK retries, a stream with no events, or a long thinking phase. Counts
// only, never content; an observer that throws never changes the judge outcome.
// The SDK drops SSE pings before streamEvent, so lastEventMs alone cannot tell a
// live connection with a silent thinking phase from a dead one (run 41185637598):
// lastByteMs counts every body byte, pings included.
const started = performance.now();
const elapsedMs = () => Math.round(performance.now() - started);
const progress = { httpRequests: 0, httpStatuses: [] as number[], retryWaitsMs: [] as number[], connectedMs: null as number | null,
firstEventMs: null as number | null, lastEventMs: null as number | null, block: null as string | null, thinkingChars: 0,
textChars: 0, messageId: null as string | null, requestId: null as string | null };
textChars: 0, messageId: null as string | null, requestId: null as string | null,
bytesReceived: 0, lastByteMs: null as number | null };
const observe = (record: () => void) => { try { record(); } catch {} };
const client = new Anthropic({ fetch: async (...args: Parameters<typeof fetch>) => {
progress.httpRequests += 1;
const response = await globalThis.fetch(...args);
progress.httpStatuses.push(response.status);
return response;
if (!response.body) return response;
const counted = new Response(response.body.pipeThrough(new TransformStream<Uint8Array, Uint8Array>({ transform(chunk, stream) {
observe(() => { progress.bytesReceived += chunk.byteLength; progress.lastByteMs = elapsedMs(); });
stream.enqueue(chunk);
} })), { status: response.status, statusText: response.statusText, headers: response.headers });
Object.defineProperty(counted, 'url', { value: response.url });
return counted;
} });
const request = {
@@ -60,7 +60,11 @@ export const DESIGN_BOARD_ACTOR_PROTOCOL = [
const SUBMIT = `
import { readStateFile, verifyIdentity, CMDLINE_MARKER } from ${JSON.stringify(path.resolve(import.meta.dir, '../../design/src/daemon-state.ts'))};
import fs from 'node:fs';
// Windows Free Tests 40815257995, 41185352916: the parent killed this child at its 2 s budget with no stderr. Each
// phase is written synchronously, so a kill's stderr ends at the step that stalled (start-up, CIM query, or HTTP).
const input = JSON.parse(await Bun.stdin.text());
const phase = (name) => fs.writeSync(2, name + ' with ' + (input.deadlineAt - Date.now()) + ' ms left\\n');
phase('child started');
const state = readStateFile(input.stateFile);
if (!fs.lstatSync(input.stateFile).isFile() || !state
|| !Number.isSafeInteger(state.pid) || state.pid <= 0
@@ -70,7 +74,9 @@ if (!fs.lstatSync(input.stateFile).isFile() || !state
// Leave time to reap a timed-out native query before the parent kills us.
const identityBudget = input.deadlineAt - Date.now() - 100;
if (identityBudget <= 0) throw new Error('Design feedback deadline exhausted');
phase('identity query');
if (!verifyIdentity(state.pid, CMDLINE_MARKER, identityBudget)) throw new Error('No matching owned design daemon');
phase('identity verified');
const remaining = input.deadlineAt - Date.now();
if (remaining <= 0) throw new Error('Design feedback deadline exhausted');
if (input.alreadySubmitted) {
@@ -85,6 +91,7 @@ if (input.alreadySubmitted) {
}
const requestBudget = input.deadlineAt - Date.now();
if (requestBudget <= 0) throw new Error('Design feedback deadline exhausted');
phase('feedback POST');
const response = await fetch(input.url + 'api/feedback', {
method: 'POST', redirect: 'error', signal: AbortSignal.timeout(requestBudget),
headers: { 'Content-Type': 'application/json' },
+23 -4
View File
@@ -18,7 +18,7 @@ import { capturePlanCountQuestion, createPlanCountPermissionGuard, matchesNative
import { resolveClaudeBinary } from '../binary';
import { SANCTIONED_WRITE_SUBSTRINGS, isProseAUQVisible, planCountSubmissionInput } from '../classify';
import type { ClaudePtySession } from '../launch';
import { isNumberedOptionListVisible, isPermissionDialogVisible, isPlanReadyVisible, isRejectedSlashCommand, stripPtyResidue } from '../screen';
import { idleTurnEnd, isNumberedOptionListVisible, isPermissionDialogVisible, isPlanReadyVisible, isRejectedSlashCommand, stripPtyResidue } from '../screen';
import { realPtyDriver, runPtySession, type PtyDriver, type PtyStep } from '../session';
// ────────────────────────────────────────────────────────────────────────────
@@ -41,7 +41,8 @@ export interface PlanSkillFloorObservation {
| 'exited'
| 'timeout'
| 'assessment_error'
| 'permission_unanswered';
| 'permission_unanswered'
| 'api_error';
summary: string;
/** Public current viewport for an accepted finding; terminal tail otherwise. */
evidence: string;
@@ -192,7 +193,7 @@ export async function runPlanSkillFloorCheck(opts: PlanSkillFloorOptions): Promi
since: 0, commandStartedAt: 0, targetDelivery: undefined, saveSnapshot: undefined, nativeCandidates: [],
validatedPendingQuestion: undefined, sampledAt: undefined, lastCheckpointAt: 0, lastCheckpointState: '',
artifactError: undefined, finished: false, started: false, start: 0, deadlineAt: 0, screenDeadlineAt: 0,
permissionUnansweredSince: undefined,
permissionUnansweredSince: undefined, idleVisible: undefined, idleSince: 0,
} as unknown as FloorRun;
return runPtySession<PlanSkillFloorObservation>({
driver, budgetMs: timeoutMs,
@@ -271,6 +272,9 @@ interface FloorRun {
screenDeadlineAt: number;
/** When the current permission render was first left unanswered by this actor. */
permissionUnansweredSince: number | undefined;
/** The idle turn end with an error panel being settled, and when it was first seen unchanged. */
idleVisible: string | undefined;
idleSince: number;
}
async function floorStart(run: FloorRun, session: ClaudePtySession): Promise<undefined> {
@@ -401,9 +405,24 @@ async function floorTick(run: FloorRun, session: ClaudePtySession): Promise<PtyS
}
const question = floorQuestion(run, session, currentCalls);
if (question) return question;
return floorAssess(run, session, visible);
const assessed = floorAssess(run, session, visible);
if (assessed !== 'continue') return assessed;
const idle = idleTurnEnd(visible);
if (!idle?.apiError || visible !== run.idleVisible) {
run.idleVisible = idle?.apiError ? visible : undefined;
run.idleSince = driver.now();
return 'continue';
}
if (driver.now() - run.idleSince < IDLE_SETTLE_MS) return 'continue';
return finish({ auqObserved: false, outcome: 'api_error',
summary: `the CLI turn ended at an idle prompt (${idle.done}) after its public error panel: ${idle.apiError}`,
evidence: visible.slice(-3000), elapsedMs: driver.now() - run.startedAt });
}
/** An idle turn end must hold still this long, re-reading the transcript each tick, before its error panel ends the
* check, so a question whose transcript line lands after the screen draws "done" is still credited. */
const IDLE_SETTLE_MS = 10_000;
/** This actor answers only owned file grants; any other permission render fails fast with a named cause. */
const PERMISSION_UNANSWERED_MS = 20_000;
+4 -3
View File
@@ -424,7 +424,7 @@ export function idlePanelEnd(visible: string): { end: 'refusal' | 'api_error'; e
}
/** The last idle turn's error panel, else the CLI's rejected-credentials line anywhere on screen: after one the
* CLI can sit at a footer the idle check does not know (plan mode, manual mode), and no turn can run. */
* CLI can sit at a footer the idle check does not know (manual mode), and no turn can run. */
export function screenPanelEnd(visible: string): { end: 'refusal' | 'api_error'; evidence: string } | null {
const credential = visible.split(/\r\n?|\n/).reverse().find(line => CREDENTIAL_REJECTION.test(line))?.trim();
return idlePanelEnd(visible) ?? (credential ? { end: 'api_error', evidence: credential } : null);
@@ -432,8 +432,9 @@ export function screenPanelEnd(visible: string): { end: 'refusal' | 'api_error';
/** The CLI's end-of-turn line, e.g. "✻ Cooked for 24s · done 12:46 AM" (spaces may collapse in the PTY text). */
const TURN_DONE_RE = /✻[ \t]*\p{L}[\p{L}'’-]*[ \t]*for[ \t]*(?=\d)(?:\d+h[ \t]*)?(?:\d+m[ \t]*)?(?:\d+s)?[ \t]*·[ \t]*done[^\n]*/gu;
/** An empty input prompt and its known idle footers, nothing else. */
const IDLE_PROMPT_RE = /^[\s─]*❯[\s─]*(?:(?:←[ \t]*for[ \t]*agents|\?[ \t]*for[ \t]*shortcuts)[\s─]*)*$/;
/** An empty input prompt and its known idle footers, nothing else. The plan-mode footer is idle only
* without its running "esc to interrupt" segment (run 40851840940, plan-devex-finding-floor). */
const IDLE_PROMPT_RE = /^[\s─]*❯[\s─]*(?:(?:(?:⏸[ \t]*plan[ \t]*mode[ \t]*on[ \t]*\(shift\+tab[ \t]*to[ \t]*cycle\)[ \t]*·[ \t]*)?←[ \t]*for[ \t]*agents|\?[ \t]*for[ \t]*shortcuts)[\s─]*)*$/;
/**
* The CLI ended its turn and sits at an empty prompt: the last end-of-turn
+2 -2
View File
@@ -718,10 +718,10 @@ export function callerReviewRecordTemplate(fixture: Pick<QaCallerFixture, 'calle
export function qaCallerSessionOptions(fixture: QaCallerFixture, runId: string): Parameters<typeof runSkillTest>[0] {
return {
prompt: `Load gstack's /${fixture.caller} supplied parent phase from caller-${fixture.caller}.md and resume it on the selected working-tree diff against origin/main. This excerpt comes from ${fixture.runtime}/${fixture.caller}/SKILL.md; resolve installed-relative references there, not from the excerpt file or product directory. That path identifies the asset base, not another entrypoint: do not read or invoke the full parent SKILL.md or rerun its preamble. Earlier preamble/branch/base setup is complete; use the existing local origin/main ref without fetch. Earlier-phase asset locators are ${fixture.runtime}/review/checklist.md and ${fixture.runtime}/qa/templates/functional-report-template.md. Read those files directly when referenced; recursive Glob does not follow the installed asset symlinks. Cross-project learnings are configured off in this owned fixture. ${fixture.reviewStart ? `The actual review-start helper already captured REVIEW_START=${fixture.reviewStart} for this unchanged core pass; retain that token. ` : ''} This fixture evaluates only the supplied parent phase, not later publication stages. The fixture owner recorded these read-only observations when this phase began; they are current until an input changes, so use them instead of re-running those commands, and recheck freshness before completion outputs:\n${fixture.startObservations}\n Read README.md for the project contract and commands. Use diagnostic-client commands such as \`bun scripts/probe.ts <literal>\` for exploratory discoveries and their checkpoint evidence. A required \`bun run test\` is separate suite verification: report it as verification, never as a diagnostic observation or checkpoint anchor/target. Use the production evidence helper to publish each diagnostic checkpoint as \`reports/exploration-NNN.json\`, not inside a nested directory; do not transcribe its observed payload. ${fixture.caseId === 'ship-exploratory-plan-checks' ? 'The previously discovered plan is PLAN.md.' : 'No plan file was found.'} There is no remote service and no release publication is authorized. There is no interactive approver; do not invent answers or permission. Keep normal parent decision gates. Handoff freshness check: Read HANDOFF.md and reports/HANDOFF.md if present for any concurrent collaborator update, await those results, and compare evidence with current inputs; rerun any probe whose input changed. Run the check before each of these, and dispatch each only in a later message than the check's Read results: the evidence helper's materialize, which runs once per report root and freezes the verdict; every gstack-review-log completed:true record, adversarial-review included, since a record is a completion, not preliminary bookkeeping; and the completion report. A later handoff read cannot validate an earlier materialize or completion. If a probe's snapshot differs from an earlier probe's, read reports/HANDOFF.md first; it names any collaborator change.\n\nQA fixture bindings: the deadline guard, capture, checkpoint and materialize command forms are in the installed qa/sections/exploratory.md this phase requires you to Read; use those forms verbatim with these bindings substituted literally. DEADLINE_TOOL = ${fixture.runtime}/bin/gstack-qa-deadline. EVIDENCE_TOOL = ${fixture.runtime}/bin/gstack-qa-evidence. PROBE_DIR = ${fixture.cwd}/reports. DEADLINE_FILE = ${fixture.cwd}/reports/deadline.json. SECONDS must be positive and at most 300. EARLIER_UTC is the optional caller absolute deadline: use the section clock's Hard deadline UTC, never its Runner entry UTC, reserve-start time or a clock-read time. The only native COMMAND is the existing diagnostic client, bun scripts/probe.ts, with zero or one literal argument. Resolve these exact helper and state paths; do not use variables, another helper, another state file, nested wrappers, scripts, operators or substitutions. Its diagnostic receipts are declared public/synthetic, so --public is approved. Only an explicit plan check this phase requires may use --timeout-ms 10000 in place of the deadline; every other capture, including a rerun or revalidation of an earlier probe, uses the deadline. This does not reset or bypass the smoke deadline. Only the deadline helper may create or change reports/deadline.json and its .qa-deadline- temporary files; never use Write/Edit/MultiEdit on those paths. Record the full outer command in checkpoints and evidence; keep the unchanged child JSON as observed, separate from prefixed guard diagnostics. A completed expired guard-run is not a probe or a pass: retain its unused checkpoint, report not-run coverage and do not restart the deadline. Keep the 12-probe smoke limit. Required suites and explicit plan checks are outside the bounded smoke budget, not permission to reset it. Quote arguments literally. Sources stay inside reports. Decide to execute the next probe before publishing its checkpoint, then await successful publication and dispatch that exact probe. I Line truncated
prompt: `Load gstack's /${fixture.caller} supplied parent phase from caller-${fixture.caller}.md and resume it on the selected working-tree diff against origin/main. This excerpt comes from ${fixture.runtime}/${fixture.caller}/SKILL.md; resolve installed-relative references there, not from the excerpt file or product directory. That path identifies the asset base, not another entrypoint: do not read or invoke the full parent SKILL.md or rerun its preamble. Earlier preamble/branch/base setup is complete; use the existing local origin/main ref without fetch. Earlier-phase asset locators are ${fixture.runtime}/review/checklist.md and ${fixture.runtime}/qa/templates/functional-report-template.md. Read those files directly when referenced; recursive Glob does not follow the installed asset symlinks. Cross-project learnings are configured off in this owned fixture. ${fixture.reviewStart ? `The actual review-start helper already captured REVIEW_START=${fixture.reviewStart} for this unchanged core pass; retain that token. ` : ''} This fixture evaluates only the supplied parent phase, not later publication stages. The fixture owner recorded these read-only observations when this phase began; they are current until an input changes, so use them instead of re-running those commands, and recheck freshness before completion outputs:\n${fixture.startObservations}\n Read README.md for the project contract and commands. Use diagnostic-client commands such as \`bun scripts/probe.ts <literal>\` for exploratory discoveries and their checkpoint evidence. A required \`bun run test\` is separate suite verification: report it as verification, never as a diagnostic observation or checkpoint anchor/target. Use the production evidence helper to publish each diagnostic checkpoint as \`reports/exploration-NNN.json\`, not inside a nested directory; do not transcribe its observed payload. ${fixture.caseId === 'ship-exploratory-plan-checks' ? 'The previously discovered plan is PLAN.md.' : 'No plan file was found.'} There is no remote service and no release publication is authorized. There is no interactive approver; do not invent answers or permission. Keep normal parent decision gates. Handoff freshness check: Read HANDOFF.md and reports/HANDOFF.md if present for any concurrent collaborator update, await those results, and compare evidence with current inputs; rerun any probe whose input changed. Run the check before each of these, and dispatch each only in a later message than the check's Read results: the evidence helper's materialize, which runs once per report root and freezes the verdict; every gstack-review-log completed:true record, adversarial-review included, since a record is a completion, not preliminary bookkeeping; and the completion report. A later handoff read cannot validate an earlier materialize or completion. If a probe's snapshot differs from an earlier probe's, read reports/HANDOFF.md first; it names any collaborator change.\n\nQA fixture bindings: the deadline guard, capture, checkpoint and materialize command forms are in the installed qa/sections/exploratory.md this phase requires you to Read; use those forms verbatim with these bindings substituted literally. DEADLINE_TOOL = ${fixture.runtime}/bin/gstack-qa-deadline. EVIDENCE_TOOL = ${fixture.runtime}/bin/gstack-qa-evidence. PROBE_DIR = ${fixture.cwd}/reports. DEADLINE_FILE = ${fixture.cwd}/reports/deadline.json. SECONDS must be positive and at most 300. EARLIER_UTC is the optional caller absolute deadline: use the section clock's Hard deadline UTC, never its Runner entry UTC, reserve-start time or a clock-read time. The only native COMMAND is the existing diagnostic client, bun scripts/probe.ts, with zero or one literal argument. Resolve these exact helper and state paths; do not use variables, another helper, another state file, nested wrappers, scripts, operators or substitutions. Its diagnostic receipts are declared public/synthetic, so --public is approved. Only an explicit plan check this phase requires may use --timeout-ms 10000 in place of the deadline; every other capture, including a rerun or revalidation of an earlier probe, uses the deadline. This does not reset or bypass the smoke deadline. Only the deadline helper may create or change reports/deadline.json and its .qa-deadline- temporary files; never use Write/Edit/MultiEdit on those paths. Record the full outer command in checkpoints and evidence; keep the unchanged child JSON as observed, separate from prefixed guard diagnostics. A completed expired guard-run is not a probe or a pass: retain its unused checkpoint, report not-run coverage and do not restart the deadline. Keep the 12-probe smoke limit. Required suites and explicit plan checks are outside the bounded smoke budget, not permission to reset it. Quote arguments literally. Sources stay inside reports. Decide to execute the next probe before publishing its checkpoint, then await successful publication and dispatch that exact probe. I Line truncated
appendSystemPrompt: `Caller execution scheduling (fixture contract):
This session has at most 25 assistant turns, including required verification and final artifacts. The command boundary applies to each Bash call, not to the number of independent tool calls in an assistant turn.
After required clock and approval prerequisites settle, issue independent source Reads and read-only discovery together as separate native tool calls once their paths and inputs are known. Read-only discovery is Read, Glob, Grep and the declared inventory, Git and review-read forms; a capture, a deadline guard start or run, or a diagnostic-client run is a probe, never discovery. For example, after the first clock read, one response can Read the caller excerpt, README.md, every product file and the referenced checklist and templates. Wait for their results before decisions that depend on them.
After required clock and approval prerequisites settle, issue independent source Reads and read-only discovery together as separate native tool calls once their paths and inputs are known. Read-only discovery is Read, Glob, Grep and the declared inventory, Git and review-read forms${fixture.caller === 'ship' ? ", plus Step 9's review-plan command and gate-scan block, which belong with the first diff discovery" : ''}; a capture, a deadline guard start or run, or a diagnostic-client run is a probe, never discovery. For example, after the first clock read, one response can Read the caller excerpt, README.md, every product file and the referenced checklist and templates. Wait for their results before decisions that depend on them.
The completion reserve is for required verification, affected-input revalidation and artifacts, not an earlier deadline. Keep completing required work within the actual remaining deadline; reserve entry alone is not a reason to stop. Use each native probe's snapshot to distinguish current from superseded evidence before deciding which checks still need revalidation.
Never group diagnostic probes, checkpoint publication with its next probe (a capture carrying --after is one probe, not a group), or any action with the clock/status/approval result it needs. Shell composition remains forbidden outside the declared forms. Preserve every required Read, probe, verification, freshness check, approval and report field; the turn limit does not authorize skipping work or reporting incomplete work as passed.`,
workingDirectory: fixture.cwd,
+37
View File
@@ -0,0 +1,37 @@
import { existsSync, lstatSync, rmSync, symlinkSync } from 'node:fs';
import { join } from 'node:path';
import { expect } from 'bun:test';
import { fixtureWriteFileSync, fixtureMkdirSync, tree, fixture, install } from './install-fixture';
/** F13: a Claude-only setup run twice leaves a cyclic foreign ownership link at `target` and the rest of the global tree untouched. */
export function claudeOnlySetupPreservesCyclicLink(target: string): void {
const f = fixture('ordinary');
rmSync(join(f.global, 'gstack-retired'));
for (const rel of ['bin', 'lib']) {
const asset = join(f.global, 'gstack', rel);
rmSync(asset);
symlinkSync(join(f.source, rel), asset, 'dir');
}
const old = join(f.global, 'gstack-claude');
rmSync(old, { recursive: true });
const oldRender = join(f.source, '.agents/skills/gstack-claude');
fixtureMkdirSync(oldRender, { recursive: true });
fixtureWriteFileSync(join(oldRender, 'SKILL.md'), '<!-- AUTO-GENERATED from SKILL.md.tmpl -->\n<!-- Regenerate: bun run gen:skill-docs -->\nPrior legacy render.\n');
symlinkSync(oldRender, old, 'dir');
const link = target === 'legacy' ? old
: target === 'replacement' ? join(f.global, 'gstack-claude-code')
: target === 'legacy-skill' ? join(old, 'SKILL.md')
: target === 'runtime' ? join(f.global, 'gstack')
: join(f.global, 'gstack', target === 'runtime-bin' ? 'bin' : 'lib');
if (target === 'legacy-skill') {
rmSync(old);
fixtureMkdirSync(old);
}
if (existsSync(link) || lstatSync(link, { throwIfNoEntry: false })) rmSync(link, { recursive: true });
symlinkSync(link, link);
const before = tree(f.global);
for (let run = 0; run < 2; run++) {
install(f, '--host claude');
expect(tree(f.global)).toEqual(before);
}
}
@@ -0,0 +1,212 @@
/**
* Captures and replay adapters shared by test/shared-libs-checker-interface-evidence*.test.ts
* (moved from test/shared-libs-checker-interface-evidence.test.ts, GSTA-151). Each test file
* runs its own beforeAll over the captures it replays and its own afterAll cleanup.
*/
import { expect } from 'bun:test';
import { execFileSync } from 'node:child_process';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { hasTrustedSharedLibsCheck } from './shared-libs-review-start-evidence';
import {
createSharedInteractiveToolHandler, createSharedLibsFixture, fixtureGit, fixtureWorkingTree, fixtureWrite,
installNormalizingFilter, reviewLifecycleInstructions, reviewRevalidationPrompt, reviewRecords,
seedReviewSources, seedSkippedAdvisory, SHARED_LIBS_ROOT, shellQuote, toolCommandTrace,
type SharedLibsFixture,
} from './shared-libs-eval-fixture';
import {
seedPathReviewPrerequisites, checkPathReviewPrerequisites,
hasPathReviewPrerequisiteReceipt, type PathEligibilityFixture,
} from './shared-libs-path-fixture';
import { CAPTURE_LONG_MS } from './eval-budgets';
import capturedChecker from '../fixtures/shared-libs-index-flags-r59-checker-public.json';
export const helper = path.join(SHARED_LIBS_ROOT, 'bin/gstack-review-log');
export const fixtures: SharedLibsFixture[] = [];
export const captures = new Map<string, any>();
export const pathSource = fs.readFileSync(path.join(import.meta.dir, '..', 'skill-e2e-shared-libs-paths.test.ts'), 'utf8');
export const pathKinds = ['symlinks', 'submodule', 'ignored', 'legacy', 'assume-unchanged', 'skip-worktree', 'removed-filter'] as const;
export async function capture(change: string, prepared?: PathEligibilityFixture, declared = false) {
const f = prepared?.fixture ?? createSharedLibsFixture(`checker-${change}`);
fixtures.push(f);
let current = prepared?.current;
if (!current) {
seedReviewSources(f);
fixtureWrite(f, 'src/retry-worker.ts', fs.readFileSync(path.join(f.repo, 'src/retry-worker.ts'), 'utf8')
.replace('const unusedRetryDiagnostic = "unused";\n', ''));
if (change === 'filtered') installNormalizingFilter(f);
const { action: _action, ...finding } = await seedSkippedAdvisory(f);
current = finding;
if (change === 'branch') fixtureGit(f, 'checkout', '-b', 'feature-a');
if (change === 'secondary') fixtureWrite(f, 'src/retry-route.ts',
fs.readFileSync(path.join(f.repo, 'src/retry-route.ts'), 'utf8') + '// Changed caller\n');
if (change === 'filtered') fixtureWrite(f, 'src/retry-route.ts',
fs.readFileSync(path.join(f.repo, 'src/retry-route.ts'), 'utf8') + '// RAW-ONLY changed caller\n');
}
const events: any[] = [];
const invoke = (command: string) => {
const id = `call-${events.length}`;
events.push({ type: 'assistant', message: { content: [{ type: 'tool_use', id, name: 'Bash', input: { command } }] } });
const output = execFileSync('bash', ['-c', command], { cwd: f.repo, env: { ...process.env, ...f.env },
encoding: 'utf8', timeout: 30_000 });
events.push({ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: id, content: output }] } });
return output.trim();
};
const instructionFile = reviewLifecycleInstructions(f);
const instructions = fs.readFileSync(instructionFile, 'utf8');
const resumed = prepared?.resumed ?? seedPathReviewPrerequisites(f);
const prerequisites = checkPathReviewPrerequisites(f, resumed.input);
const protocol = declared ? [...reviewRevalidationPrompt(f, instructionFile, path.join(f.root, 'current-advisory.jsonl'), resumed)
.matchAll(/```bash\n([\s\S]*?)\n```/g)].map(match => match[1]) : [];
if (declared) expect(protocol).toHaveLength(3);
const startCommand = instructions.match(/```bash\n(DIFF_BASE=\$[\s\S]*?)\n```/)?.[1];
expect(startCommand).toBeDefined();
const token = invoke(declared ? protocol[0] : startCommand!).split('\n')[0];
if (declared) invoke('git diff origin/main');
for (const file of current.evidence_paths) invoke(`cat ${shellQuote(file)}`);
const checkAt = events.length;
const receipt = JSON.parse(invoke(declared ? protocol[1].replace('REVIEW_START', token).replace('CURRENT_FINDING_JSON', JSON.stringify(current))
: `${shellQuote(helper)} --check-shared-libs ${token} <<'FINDING'\n${JSON.stringify(current)}\nFINDING`));
const questions: any[] = [];
if (declared && !receipt.reusable) {
const input = { questions: [{ question: 'Revalidate this supplied authored-source advisory?',
options: [{ label: 'Fix', description: 'Apply the extraction.' },
{ label: 'Skip', description: 'Keep the source and index unchanged; record this advisory decision.' }] }] };
const callback = createSharedInteractiveToolHandler('skip', {
nonQuestion: () => { throw new Error('No non-question tool is allowed by this free actor'); },
onQuestion: value => { questions.push(value); }, onAnswer: () => {},
});
const id = `decision-${events.length}`;
events.push({ type: 'assistant', message: { content: [{ type: 'tool_use', id, name: 'AskUserQuestion', input }] } });
const answer = await callback('AskUserQuestion', input);
expect(answer.updatedInput.answers).toEqual({ [input.questions[0].question]: 'Skip' });
events.push({ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: id,
content: JSON.stringify(answer.updatedInput.answers) }] } });
}
{
const settled = JSON.parse(invoke(resumed.checkCommand));
expect(settled).toEqual(checkPathReviewPrerequisites(f, resumed.input));
expect(settled).toMatchObject({ synthetic: true, native_coverage: false, settled: true, current: true });
}
const finishAt = events.length;
const record = JSON.stringify({ skill: 'review', status: 'clean', issues_found: 0,
completed: true, converged: true, findings: change === 'unchanged' ? [] : [{ ...current, action: 'skipped' }] });
invoke(declared ? protocol[2].replace("'FINAL_REVIEW_JSON'", shellQuote(record)).replace('REVIEW_START', token)
: `${shellQuote(helper)} ${shellQuote(record)} --finish ${token} && ${shellQuote(path.join(SHARED_LIBS_ROOT, 'bin/gstack-review-read'))}`);
const expected = { helper, repo: f.repo, state: f.state, slug: 'fixture-shared-libs',
directory: path.join(f.state, 'projects/fixture-shared-libs/.review-starts'),
branch: fixtureGit(f, 'symbolic-ref', '--quiet', '--short', 'HEAD'), wtree: fixtureWorkingTree(f),
startedAt: receipt.review_start.started_at, finding: current, reusable: change === 'unchanged',
coveredPaths: receipt.snapshot.covered_paths,
...(prepared ? { sources: Object.fromEntries(current!.evidence_paths.map((file: string) => [file, fs.readFileSync(path.join(f.repo, file), 'utf8')])) } : {}) };
return { f, current, token, receipt, events, checkAt, finishAt, expected, prepared, resumed, prerequisites, ...(declared ? { questions } : {}) };
}
export function replay(change = 'unchanged') { return structuredClone(captures.get(change)); }
export function call(run: any, at = run.checkAt) { return run.events[at].message.content[0]; }
export function result(run: any, at = run.checkAt) { return run.events[at + 1].message.content[0]; }
export function alterReceipt(run: any, change: (receipt: any) => void) {
const receipt = JSON.parse(result(run).content);
change(receipt);
result(run).content = JSON.stringify(receipt);
}
export function pathCallback(run: any, overrides: Record<string, any> = {}) {
const start = pathSource.indexOf('async function exerciseEligibility(');
const end = pathSource.indexOf('\ndescribeE2E(', start);
const readStart = pathSource.indexOf('function sourceReadTrace(');
expect(start).toBeGreaterThan(readStart);
expect(end).toBeGreaterThan(start);
const rows: any[] = [];
const native = { events: run.events, exitReason: 'success', output: '', toolCalls: run.events
.filter((event: any) => event.type === 'assistant')
.flatMap((event: any) => event.message.content.filter((block: any) => block.type === 'tool_use')
.map((block: any) => ({ tool: block.name, input: block.input }))) };
const exercise = new Function('deps', new Bun.Transpiler({ loader: 'ts' }).transformSync(`const {
captures, preparePathEligibilityFixture, fs, path, reviewLifecycleInstructions, reviewRevalidationPrompt,
runSharedInteractive, readRequests, toolCommandTrace, fixtureGit, fixtureWorkingTree, reviewRecords, expect,
CAPTURE_LONG_MS, hasTrustedSharedLibsCheck, SHARED_LIBS_ROOT,
checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt } = deps;
${pathSource.slice(readStart, end)} return exerciseEligibility;`))({
captures: { runAttempt: async (_name: string, _kinds: string[], _timeout: number, work: any) =>
work({ add: (scenario: string, row: any) => rows.push({ scenario, row }) }) },
preparePathEligibilityFixture: () => run.prepared,
fs: { ...fs, rmSync: (directory: string) => { expect(directory).toBe(run.f.root); } }, path,
reviewLifecycleInstructions, reviewRevalidationPrompt,
runSharedInteractive: async (fixture: any, _name: string, prompt: string, choice: string) => {
expect(choice).toBe('skip');
expect(fixture).toBe(run.prepared.fixture);
expect(prompt).toContain(reviewRevalidationPrompt(fixture, path.join(fixture.root, 'review-lifecycle.md'),
path.join(fixture.root, 'current-advisory.jsonl'), run.prepared.resumed));
return { result: native, questions: run.questions ?? [{}] };
},
readRequests: () => [], toolCommandTrace, fixtureGit, fixtureWorkingTree, reviewRecords, expect,
CAPTURE_LONG_MS, hasTrustedSharedLibsCheck, SHARED_LIBS_ROOT,
checkPathReviewPrerequisites, hasPathReviewPrerequisiteReceipt, ...overrides,
});
return { rows, invoke: () => exercise('shared-libs-review-path-eligibility', [run.kind]) };
}
export function capturedPathRun(index: number) {
const captured = structuredClone(capturedChecker.attempts[index]);
const events: any[] = captured.events;
const blocks = events.flatMap(event => event.message.content);
const calls = blocks.filter(block => block.type === 'tool_use');
const returned = (id: string) => {
const result = blocks.find(block => block.type === 'tool_result' && block.tool_use_id === id);
expect(result).toBeDefined();
expect(result.is_error).not.toBe(true);
expect(typeof result.content).toBe('string');
return result.content as string;
};
const files = new Map<string, string>(calls.filter(call => call.name === 'Read')
.map(call => [call.input.file_path, returned(call.id).replace(/^\d+\t/gm, '')]));
const repo = captured.repo, root = path.posix.dirname(repo), state = path.posix.join(root, 'state');
const input = path.posix.join(root, 'resumed-review-prerequisites.json');
const supplied = path.posix.join(root, 'current-advisory.jsonl');
const current = JSON.parse(files.get(supplied)!);
const prerequisiteCall = calls.find(call => call.input.command?.includes('--check-review-prerequisites'));
const prerequisites = JSON.parse(returned(prerequisiteCall.id));
expect(prerequisites).toMatchObject({ settled: true, current: true, context: { binding: { root, repo, state } } });
expect(prerequisites.context).toEqual(JSON.parse(files.get(input)!));
const finish = calls.find(call => call.input.command?.includes('--finish'));
const records = returned(finish.id).split('\n').filter(line => line.startsWith('{')).map(line => JSON.parse(line));
const f = { root, repo, state } as SharedLibsFixture;
const run = { f, kind: 'assume-unchanged', events, questions: calls.filter(call => call.name === 'AskUserQuestion').map(call => call.input),
prepared: { fixture: f, current, sourcePaths: ['src/retry-route.ts'], beforeTree: prerequisites.context.binding.wtree,
resumed: { input, checkCommand: prerequisiteCall.input.command } } };
expect(captured.exit_reason).toBe('success');
expect(run.questions).toHaveLength(1);
for (const call of calls.filter(call => call.name === 'AskUserQuestion')) {
for (const question of call.input.questions) {
expect(returned(call.id)).toContain(`"${question.question}"="Skip"`);
expect(question.options.some((option: any) => option.label === 'Skip')).toBe(true);
}
}
const overrides = {
path: path.posix, SHARED_LIBS_ROOT: '/workspace/gstack',
fs: {
readFileSync: (file: string) => { expect(files.has(file)).toBe(true); return files.get(file); },
realpathSync: (file: string) => file,
writeFileSync: (file: string, contents: string) => {
expect(file).toBe(supplied);
expect(JSON.parse(contents)).toEqual(current);
},
rmSync: (directory: string) => { expect(directory).toBe(root); },
},
reviewLifecycleInstructions: () => path.posix.join(root, 'review-lifecycle.md'),
checkPathReviewPrerequisites: (fixture: SharedLibsFixture, file: string) => {
expect(fixture).toBe(f); expect(file).toBe(input); return prerequisites;
},
fixtureGit: (fixture: SharedLibsFixture, ...args: string[]) => {
expect(fixture).toBe(f); expect(args).toEqual(['symbolic-ref', '--quiet', '--short', 'HEAD']);
return prerequisites.context.binding.branch;
},
fixtureWorkingTree: (fixture: SharedLibsFixture) => {
expect(fixture).toBe(f); return prerequisites.context.binding.wtree;
},
reviewRecords: (fixture: SharedLibsFixture) => { expect(fixture).toBe(f); return structuredClone(records); },
};
return { run, overrides };
}
+20 -2
View File
@@ -60,10 +60,28 @@ export function budgetHarness(): Harness {
git('checkout', '-q', '-b', 'feature');
fs.writeFileSync(path.join(repo, 'app.ts'), 'export const x = 2;\n');
git('commit', '-qam', 'change');
// Windows Free Tests 41131257934 (shard 6): two consecutive cases hit bun's 30 s test timeout inside one bin call each,
// with empty output and no cause. A run that ends without an exit code now names its command, how it ended, its
// elapsed time and, on Windows, the children it left (bash, git or a nested bin), so the next red names the stuck stage.
let abnormal = '';
const childListMs = 10_000;
const run = (bin: string, args: string[], extraEnv: NodeJS.ProcessEnv = {}): Run => {
const argv = bin === REVIEW_LOG_BIN ? ['bash', bin] : [process.execPath, ...bunIsolationArgs(), bin];
const started = Date.now();
abnormal = '';
const r = spawnSync(argv[0], [...argv.slice(1), ...args], { cwd: repo, env: { ...env, ...extraEnv }, encoding: 'utf8', timeout: 60_000 });
return { code: r.status ?? -1, out: r.stdout ?? '', err: r.stderr ?? '' };
const result = { code: r.status ?? -1, out: r.stdout ?? '', err: r.stderr ?? '' };
if (r.status !== null) return result;
abnormal = `${path.basename(bin)} ${args[0]} ended without an exit code (${r.signal ?? r.error?.message ?? 'no signal'}) after ${Date.now() - started} ms`;
if (process.platform === 'win32' && r.pid) {
const children = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command',
`Get-CimInstance Win32_Process -Filter 'ParentProcessId=${r.pid}' | ForEach-Object { '{0} {1}' -f $_.ProcessId, $_.CommandLine }`,
], { encoding: 'utf8', timeout: childListMs, windowsHide: true });
abnormal += `; children of ${r.pid}: ${children.stdout?.trim() || (children.error ? `unavailable (${children.error.message})` : 'none')}`;
}
result.err += `\n[harness] ${abnormal}`;
process.stderr.write(`[harness] ${abnormal}\n`);
return result;
};
let records = 0;
return {
@@ -79,7 +97,7 @@ export function budgetHarness(): Harness {
field(out, line, key) {
const row = out.split('\n').find(l => l.startsWith(line + ':'));
const m = row ? new RegExp(`(?:^|\\s)${key}=(\\S+)`).exec(row) : null;
if (!m) throw new Error(`no ${key}= on a ${line}: line in:\n${out}`);
if (!m) throw new Error(`no ${key}= on a ${line}: line in:\n${out}${abnormal ? `\n[harness] last run without an exit code: ${abnormal}` : ''}`);
return m[1]!;
},
ledger: file => JSON.parse(fs.readFileSync(file, 'utf8')),
+29
View File
@@ -0,0 +1,29 @@
/** Train setups shared by the test/ship-queue-train*.test.ts files (moved from test/ship-queue-train.test.ts, GSTA-151). */
import * as fs from 'node:fs';
import * as path from 'node:path';
import { GREEN_GATE, nonceOf, openPr, queue, readyReceipt, type Rule, type TrainFixture } from './ship-queue-train-fixture';
export function twoPrTrain(fx: TrainFixture, gate: Rule = GREEN_GATE) {
const h1 = openPr(fx, '1');
const h2 = openPr(fx, '2');
readyReceipt(fx, '1', h1);
readyReceipt(fx, '2', h2);
fx.write(d => { d.rules['evals.yml'] = gate; });
const r = queue(fx, ['train', 'build', '--prs', `1@${h1},2@${h2}`]);
return { h1, h2, r, nonce: nonceOf(r.out) };
}
/** A main commit with a prefix's tree plus a VERSION stamp, the way stamp-at-merge publishes it. */
export function publishMain(fx: TrainFixture, prefixCommit: string, version: string, extra?: { file: string; text: string }): string {
const { repo } = fx;
repo.git('checkout', '-q', '-B', 'mainsim', 'origin/main');
repo.git('rm', '-rq', '.');
repo.git('checkout', prefixCommit, '--', '.');
fs.writeFileSync(path.join(repo.work, 'VERSION'), version + '\n');
if (extra) fs.writeFileSync(path.join(repo.work, extra.file), extra.text);
repo.git('add', '-A');
repo.git('commit', '-q', '-m', `merge to ${version}`);
repo.git('push', '-q', 'origin', 'HEAD:refs/heads/main');
repo.git('fetch', '-q', 'origin');
return repo.git('rev-parse', 'HEAD');
}
+2 -1
View File
@@ -44,7 +44,7 @@ export interface Rule {
export interface ShimData {
repo: string; origin: string; nextId: number; prs: Record<string, unknown>; runs: Array<Record<string, unknown>>;
artifacts: Record<string, Record<string, unknown>>; checks: Record<string, Array<{ name: string; status: string; conclusion: string | null }>>;
ci: Record<string, unknown[]>; rules: Record<string, Rule>; artifact: string; log: Array<Record<string, unknown>>;
ci: Record<string, unknown[]>; ciFail?: string[]; rules: Record<string, Rule>; artifact: string; log: Array<Record<string, unknown>>;
/** Commit statuses (the legacy status API) at a sha, beside the check runs in `ci`. */
statuses?: Record<string, Array<{ state: string; context: string }>>;
/** Per PR, how many more `gh pr view` calls answer before the PR reads as not found (a GitHub answer that changes between two reads). */
@@ -206,6 +206,7 @@ function shimSource(): string {
" const named = /commits\\/([0-9a-f]+)\\/check-runs\\?check_name=([^&]+)/.exec(a[1] || '');",
" if (named) { const list = (d.checks[named[1]] || []).filter(c => c.name === decodeURIComponent(named[2])); out({ total_count: list.length, check_runs: list }); }",
" const paged = /commits\\/([0-9a-f]+)\\/(check-runs|status)\\?.*page=(\\d+)/.exec(a[1] || '');",
" if (paged && (d.ciFail || []).includes(paged[1])) fail('HTTP 502: gateway timeout');",
" if (paged) { const list = paged[2] === 'check-runs' ? (d.ci[paged[1]] || []) : ((d.statuses || {})[paged[1]] || []); const key = paged[2] === 'check-runs' ? 'check_runs' : 'statuses';",
" out(paged[3] === '1' ? { total_count: list.length, state: 'success', [key]: list } : { total_count: list.length, [key]: [] }); }",
"}",
+4 -2
View File
@@ -6,9 +6,11 @@
* ending the previous line) never count. The canonical phrase may name Aside as "it" once the macOS 15+ floor follows
* ("If you want to use Aside: download it (macOS 15+) at aside.com", gate 39315041557). The short forms without the
* floor count only at the start of a sentence, bullet or quote. The passive form ("Aside runs on macOS 15+ and can be
* downloaded at aside.com", gate 40987391676) counts when its clause starts with Aside or "it" and holds no negation.
* downloaded at aside.com", gate 40987391676) counts when its clause starts with Aside or "it" and the download
* predicate's own coordinate clause holds no negation: "Aside is not installed but can be downloaded at aside.com"
* counts, "Aside is not something that can be downloaded" and "... but cannot be downloaded" never do.
*/
const ASIDE_DOWNLOAD_PITCH = String.raw`(?:^|[.!?;:]\s*|\n)\s*(?:[>*-]\s*)*["\u201C]?download (?:it|Aside) at aside\.com\b|(?:^|[.!?;:,\u2014\u2013\n])[\s>*_-]*(?<!(?:\b(?:not|never|no|cannot)|n['\u2019]t)\s+)(?:(?:then|please|just|so|first|now)\s+)?(?:you\s+(?:can|could|may|should|need\s+to)\s+)?download (?:Aside|it) \(macOS 15\+\) at aside\.com\b|(?:^|[.!?;:,\u2014\u2013\n])[\s>*_-]*(?:Aside|it)\b(?:(?!\b(?:not|never|no)\b|n['\u2019]t\b)[^.!?;:,\n])*?\b(?:can|may)\s+be\s+downloaded\s+(?:at|from)\s+aside\.com\b`;
const ASIDE_DOWNLOAD_PITCH = String.raw`(?:^|[.!?;:]\s*|\n)\s*(?:[>*-]\s*)*["\u201C]?download (?:it|Aside) at aside\.com\b|(?:^|[.!?;:,\u2014\u2013\n])[\s>*_-]*(?<!(?:\b(?:not|never|no|cannot)|n['\u2019]t)\s+)(?:(?:then|please|just|so|first|now)\s+)?(?:you\s+(?:can|could|may|should|need\s+to)\s+)?download (?:Aside|it) \(macOS 15\+\) at aside\.com\b|(?:^|[.!?;:,\u2014\u2013\n])[\s>*_-]*(?:Aside|it)\b(?:(?=(?<clause>(?:(?!\b(?:can|may)\s+be\s+downloaded\b)[^.!?;:,\n])*\b(?:but|and|yet)\b))\k<clause>)?(?:(?!\b(?:not|never|no)\b|n['\u2019]t\b)[^.!?;:,\n])*?\b(?:can|may)\s+be\s+downloaded\s+(?:at|from)\s+aside\.com\b`;
export const asideDownloadPitch = new RegExp(ASIDE_DOWNLOAD_PITCH, 'im');
export const asideDownloadPitchCount = (text: string): number => [...text.matchAll(new RegExp(ASIDE_DOWNLOAD_PITCH, 'gim'))].length;
+2 -2
View File
@@ -674,8 +674,8 @@ export const E2E_TOUCHFILES: Record<string, string[]> = {
],
// Retro
'retro': ['bin/gstack-state-root.sh', 'lib/state-root.ts', 'bin/gstack-retro-metrics', 'retro/**', 'test/skill-e2e-retro.test.ts'],
'retro-base-branch': ['bin/gstack-state-root.sh', 'lib/state-root.ts', 'bin/gstack-retro-metrics', 'retro/**', 'test/skill-e2e-retro.test.ts'],
'retro': ['bin/gstack-state-root.sh', 'lib/state-root.ts', 'bin/gstack-retro-metrics', 'lib/retro-friction.ts', 'retro/**', 'test/skill-e2e-retro.test.ts'],
'retro-base-branch': ['bin/gstack-state-root.sh', 'lib/state-root.ts', 'bin/gstack-retro-metrics', 'lib/retro-friction.ts', 'retro/**', 'test/skill-e2e-retro.test.ts'],
// CSO
'cso-full-audit': ['bin/gstack-state-root.sh', 'lib/state-root.ts', 'cso/**', 'lib/cso/**', 'lib/redact-engine.ts', 'lib/redact-patterns.ts', 'test/skill-e2e-cso.test.ts'],
+119
View File
@@ -0,0 +1,119 @@
/**
* Fake Ubicloud API and fake VM for scripts/ubicloud/ubi-runner.sh, shared by the
* test/ubicloud-runner-*.test.ts parts split from test/ubicloud-runner.test.ts (GSTA-151).
*/
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
export const ROOT = resolve(import.meta.dir, '../..');
export const DIR = join(ROOT, 'scripts/ubicloud');
export const read = (rel: string) => readFileSync(join(ROOT, rel), 'utf8');
/**
* Fake Ubicloud API that can create: create adds the name to the listed file
* (or answers the quota refusal in refuse with HTTP 400), show is running at
* 192.0.2.1 while listed, destroy unlists. The fake VM is the directory vm/:
* the fake ssh records every remote command in ssh.log, keeps copies of
* ~/.ubirun-env and ~/.ubirun-setup.sh under the fixture root, serves pulls
* from remote-fs/, and runs every other command there for real (HOME=vm/,
* vmbin/ first on PATH), so uploads unpack, detached phases write their pid,
* output and exit files, tail --pid follows them and pkill ends them. The stub
* make in vmbin/ echoes `ran: make ARGS`, or runs command-mode or
* make-<target>.sh from the fixture root. No network, no VM.
*/
export function fakeVm(opts: { listed?: string; refuse?: string } = {}) {
const root = mkdtempSync(join(tmpdir(), 'ubi-run-'));
const bin = join(root, 'bin'), state = join(root, 'state'), log = join(root, 'calls.log'), sshLog = join(root, 'ssh.log'), record = join(root, 'vms.tsv');
const vm = join(root, 'vm'), vmbin = join(root, 'vmbin'), srcDir = join(root, 'src'), checkpoints = join(root, 'checkpoints');
mkdirSync(vm); mkdirSync(vmbin); mkdirSync(srcDir);
writeFileSync(join(srcDir, 'README'), 'fixture checkout\n');
mkdirSync(bin); mkdirSync(state, { recursive: true });
writeFileSync(join(root, 'listed'), opts.listed ?? '');
writeFileSync(join(bin, 'curl'), '#!/usr/bin/env bash\n' +
'out=""; while [ $# -gt 0 ]; do [ "$1" = -o ] && out=$2; shift; done\n' +
'body=$(cat); echo "$body" >> ' + JSON.stringify(log) + '\n' +
'listed=' + JSON.stringify(join(root, 'listed')) + '\n' +
'loc=$(printf \'%s\' "$body" | sed -n \'s/.*"vm", *"\\([^/"]*\\)\\/[^"]*".*/\\1/p\')\n' +
'name=$(printf \'%s\' "$body" | sed -n \'s/.*"vm", *"[^/"]*\\/\\([^"]*\\)".*/\\1/p\')\n' +
'case "$body" in\n' +
' *\'"create"\'*) if [ -n ' + JSON.stringify(opts.refuse ?? '') + ' ]; then printf \'%s\' ' + JSON.stringify(opts.refuse ?? '') + ' > "$out"; printf 400; else echo "$loc $name" >> "$listed"; : > "$out"; printf 200; fi ;;\n' +
' *destroy*) : > "$out"; if [ -f "$listed.destroy-fails" ]; then printf 500; else grep -v " $name$" "$listed" > "$listed.tmp"; mv "$listed.tmp" "$listed"; printf 200; fi ;;\n' +
' *\'"list"\'*) if [ -f "$listed.list-fails" ]; then echo down > "$out"; printf 503; else cat "$listed" "$listed.ghost" > "$out" 2>/dev/null; printf 200; fi ;;\n' +
' *\'"show"\'*) [ -z "${FAKE_SHOW_DELAY:-}" ] || sleep "$FAKE_SHOW_DELAY"; if [ -f "$listed.show-fails" ]; then echo down > "$out"; printf 503; elif grep -q " $name$" "$listed"; then printf \'state: running\\nsize: standard-16\\nip4: 192.0.2.1\\n\' > "$out"; printf 200; else : > "$out"; printf 404; fi ;;\n' +
' *) : > "$out"; printf 200 ;;\n' +
'esac\n');
writeFileSync(join(bin, 'ssh'), '#!/usr/bin/env bash\n' +
'root=' + JSON.stringify(root) + '; vm="$root/vm"\n' +
'cmd=${*: -1}\n' +
'printf \'%s\\n\' "$cmd" >> "$root/ssh.log"\n' +
'export HOME="$vm" PATH="$root/vmbin:$PATH"\n' +
'cd "$vm" || exit 255\n' +
'case "$cmd" in\n' +
' *pkill*) echo "$cmd" >> "$root/cancel.log"; exec bash -c "$cmd" ;;\n' +
' *captured*) cat > "$root/captured" ;;\n' +
' *"cat > ~/.ubirun-env"*) tee "$root/ubirun-env" > "$vm/.ubirun-env" ;;\n' +
' *"cat > ~/.ubirun-setup.sh"*) tee "$root/ubirun-setup.sh" > "$vm/.ubirun-setup.sh" ;;\n' +
' *"tar -czf -"*) base=${cmd##* }; tar -czf - -C "$root/remote-fs" "$base" ;;\n' +
' *"ls -d -- "*) : ;;\n' +
' *) exec bash -c "$cmd" ;;\n' +
'esac\n');
writeFileSync(join(vmbin, 'make'), '#!/usr/bin/env bash\n' +
'root=' + JSON.stringify(root) + '\n' +
'if [ -f "$root/command-mode" ]; then exec bash -c "$(cat "$root/command-mode")"; fi\n' +
'echo "ran: make $*"\n' +
'[ ! -f "$root/make-$1.sh" ] || exec bash "$root/make-$1.sh"\n');
chmodSync(join(bin, 'curl'), 0o755); chmodSync(join(bin, 'ssh'), 0o755); chmodSync(join(vmbin, 'make'), 0o755);
const env: Record<string, string> = { ...(process.env as Record<string, string>), PATH: `${bin}:${process.env.PATH}`, UBICLOUD_API_KEY: 'offline', UBI_RUNNER_STATE: state, UBI_POLL_SECONDS: '1', UBI_VM_RECORD: record, UBI_OWNER: 'thrd1', UBI_HEARTBEAT: '0', UBI_CHECKPOINT_DIR: checkpoints };
const run = (args: string[], extra: Record<string, string> = {}, stdin?: string) =>
Bun.spawnSync(['bash', join(DIR, 'ubi-runner.sh'), ...args], { env: { ...env, ...extra }, stdin: stdin === undefined ? undefined : Buffer.from(stdin), timeout: 90_000 });
const spawn = (args: string[], extra: Record<string, string> = {}) =>
Bun.spawn(['bash', join(DIR, 'ubi-runner.sh'), ...args], { env: { ...env, ...extra }, stdin: 'ignore', stdout: 'pipe', stderr: 'pipe', timeout: 120_000 });
return {
root, state, record, run, spawn, vm, src: srcDir, checkpoints,
calls: () => (existsSync(log) ? readFileSync(log, 'utf8') : ''),
ssh: () => (existsSync(sshLog) ? readFileSync(sshLog, 'utf8') : ''),
listed: () => readFileSync(join(root, 'listed'), 'utf8'),
};
}
export const src = (f: { root: string }, cfg: unknown) => {
const dir = join(f.root, 'repo');
mkdirSync(join(dir, '.gstack'), { recursive: true });
mkdirSync(join(dir, 'scripts'), { recursive: true });
writeFileSync(join(dir, 'scripts/boot.sh'), 'echo boot\n');
writeFileSync(join(dir, '.gstack/ubicloud.json'), JSON.stringify(cfg));
return dir;
};
export const run = (f: ReturnType<typeof fakeVm>, args: string[], extra: Record<string, string> = {}, stdin?: string) => f.run(args, extra, stdin);
// GSTA-158 P3: detached phases, reattach and tier checkpoints.
export const until = async (cond: () => boolean, ms: number) => {
const deadline = Date.now() + ms;
while (!cond()) { if (Date.now() > deadline) throw new Error('condition not met in time'); await Bun.sleep(100); }
};
export const vmDirs = (f: ReturnType<typeof fakeVm>) => (existsSync(f.state) ? readdirSync(f.state).filter(d => d.startsWith('ubirun-')) : []);
export const phaseStarted = (f: ReturnType<typeof fakeVm>, phase: string) => vmDirs(f).some(d => existsSync(join(f.state, d, 'phase.' + phase + '.start')));
export const creates = (f: ReturnType<typeof fakeVm>) => f.calls().split('\n').filter(l => l.includes('"create"')).length;
export const killSession = async (f: ReturnType<typeof fakeVm>, phase: string) => {
const pidFile = join(f.vm, '.ubirun-' + phase + '.pid');
await until(() => existsSync(pidFile) && readFileSync(pidFile, 'utf8').trim() !== '', 10_000);
const pid = Number(readFileSync(pidFile, 'utf8').trim());
try { process.kill(-pid, 'SIGKILL'); } catch { /* already gone */ }
await until(() => { try { process.kill(pid, 0); return false; } catch { return true; } }, 10_000);
};
export const gitSrc = (f: ReturnType<typeof fakeVm>, cfg?: unknown) => {
const dir = cfg === undefined ? join(f.root, 'repo') : src(f, cfg);
mkdirSync(dir, { recursive: true });
writeFileSync(join(dir, 'README'), 'fixture repo\n');
for (const args of [['init', '-q', '-b', 'main'], ['add', '-A'], ['commit', '-qm', 'fixture']]) {
const r = Bun.spawnSync(['git', '-c', 'user.email=t@t', '-c', 'user.name=t', ...args], { cwd: dir, timeout: 30_000 });
if (r.exitCode !== 0) throw new Error('git ' + args.join(' ') + ': ' + r.stderr.toString());
}
return dir;
};
export const TIERS = { setup: 'scripts/boot.sh', tiers: [{ name: 't1', command: 'make t1' }, { name: 't2', command: 'make t2' }, { name: 't3', command: 'make t3' }] };
export const bootCounts = (f: ReturnType<typeof fakeVm>, dir: string) => writeFileSync(join(dir, 'scripts/boot.sh'), 'echo boot >> ~/setup-count\n');
export const verifyLine = (out: string) => out.split('\n').find(l => l.startsWith('UBI_VERIFY: ')) ?? '';
export type FakeVm = ReturnType<typeof fakeVm>;
+12
View File
@@ -0,0 +1,12 @@
import { spawnSync } from 'node:child_process';
// A Windows runner pays a one-time cost the first time it executes a binary, and
// all of it lands on whichever test spawns that binary first. On 12 fresh
// windows-latest VMs (probe run 41205346554) the first launch cost jq +60-250 ms,
// awk +190-290 ms and powershell.exe +1.7-3.1 s over a warm launch; under shard
// load the same first jq or awk launch passed a 5 s per-call kill (Windows Free
// Tests 41195098239, 41174352235) while every later call took about 0.3 s. Pay it
// once here, unasserted, so a per-call kill times the code under test.
export function warmFirstExec(command: string, args: string[]): void {
spawnSync(command, args, { stdio: 'ignore', timeout: 25_000 });
}