mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-16 18:05:31 +02:00
* feat: add a restricted and supervised Claude Code runner Preserve configured authentication and models while enforcing tool access, strict completion JSON, bounded output and process cleanup. Cover argv, failure handling, session metadata and Windows process containment. * feat: route outside reviews by harness and migrate wrapper installs Use Claude Code from Codex and Codex from other supported hosts, with shared invocation rendering, positive gate validation and per-phase provenance. Rename /claude to /claude-code, repair managed shared and copied installations safely, and generate native Kiro skills. Add installed-workflow, failure-injection and live cross-harness regression coverage. * test: recognize CEO mode labels without terminal spacing The paid workflow rendered SCOPEEXPANSION at option 4, but its driver required a literal space. Match the leading mode title without cursor-spacing artifacts and ignore adjacent preview text. Preserve missing-target failures and downstream posture assertions. * test: isolate plan-count fixtures before starting review workflows Seed the complete test plan in a private git repository before launching Claude, so a bare slash command cannot review the live workspace while a delayed fixture message remains queued. Preserve count thresholds, parsers and budgets. Add initial-context and installed-discovery tests, and retain startup/terminal diagnostics on failed evaluations. * test: stabilize review fixtures and Claude eval startup Preserve source boundaries in workflow judge inputs, isolate CEO mode plans, and wait for interactive trust input readiness. Keep startup failure evidence and retain existing models, budgets, and assertions. Co-Authored-By: OpenAI Codex <noreply@openai.com> * test: classify collapsed review modes and isolate seeded findings Keep review questions out of the setup count when terminal cursor positioning removes spaces. State existing webhook safeguards so the five-finding control measures its seeded defects without accidental extra security and concurrency gaps. Preserve question bands and the paired control. Co-Authored-By: OpenAI Codex <noreply@openai.com> * test: isolate browser daemon state across free shards Co-Authored-By: OpenAI Codex <noreply@openai.com> * test: stabilize native review counting and interactive navigation Co-Authored-By: OpenAI Codex <noreply@openai.com> * chore: prepare v1.82.0.0 release Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: eliminate browser and process-cleanup test flakes Pin every CI surface to Bun 1.4.0 to avoid extra-stdio finalizers closing reused live sockets. Add an isolated GC/listener regression that fails on Bun 1.3.13, and prevent coordinated rollback to an affected CI runtime. Check renderer cleanup against the render's own staging directory so concurrent renders cannot invalidate the assertion. Make the no-pgrep process-tree walk tolerate disappearing /proc entries, and synchronize its test fixture through child readiness and pipe EOF instead of sleeps. Validation: 9,157 passed, 31 skipped, zero failures across 556 files with retries disabled. Build, all-host generation freshness, and skill checks passed. All three races have failing-before/passing-after regressions. * fix: count completed native review questions in evals * fix: drive review navigation from confirmed native choices * fix: require complete section-loading eval reports * test: isolate telemetry HTTP transport from local assertions * fix: keep review input on the active native question * test: let tunnel revocation daemon choose an available port * test: allocate available ports for pairing and watchdog fixtures * fix: stabilize planning eval navigation and phase reporting * test: isolate installed runtime paths in planning evals * test: stabilize review evidence and concurrent refresh fixtures * fix: resolve design findings before editing the plan * fix: honor and persist disabled outside plan reviews * fix: preserve planning decisions and terminal evidence Load installed host reviews at autoplan phase entry and wait for completed reviewers and saved artifacts. Reuse approved remedies while preserving individual finding decisions. Drive interactive evals from the current terminal viewport, bind native questions across scrolling, and require complete native report evidence. Cover captured stale menus, permission lifecycles, setup classification, and disabled-review tool availability with deterministic regressions. Advance release metadata and the upgrade migration to the unclaimed 1.83.0.0 slot. * fix: drive native review questions and preserve current plans Use the native single-choice keyboard protocol and current terminal viewport, with per-question navigation inside packets and completed-call coverage. Keep permissions, multi-select menus, and Submit controls distinct. Send Autoplan reviewers the amended implementation plan, keep its review record separate, and supply retained application contracts in the chain fixture. Clarify individual DevEx decisions and complete CEO fix options; use one active plan destination for the section-loading report. * fix: preserve complete plan-review decisions * fix: recognize native plan dialogs and reviewer controls * fix: preserve review decisions and phase completion * fix: recognize completed reviews without losing findings * fix: preserve review continuity and native eval completion * test: fix native review completion and eval retry isolation * test: handle native review menus and complete eval fixtures * test: fix native review setup, completion, and isolation failures * test: limit native skill discovery to runtime assets * fix: bind Autoplan reviews to full ordered phase inputs * test: fix planning eval routing, counting, and timeout handling * chore: advance queued release to v1.84.0.0 * fix: preserve complete review inputs and planning decisions * fix: reconcile review approvals and preserve phase obligations * fix: preserve review obligations and unblock eval permissions Carry recorded Autoplan requirements into blind phase inputs, require Eng review approvals before exit, and exercise combined asynchronous flows in CEO reviews. Correct native finding and handoff classification and unblock repeated report edits using scoped request identities. * fix: retain plan requirements and complete native review dialogs * fix: complete native review prompts and retain plan references * fix: preserve review inputs and classify native eval evidence * fix: check competing completion orders in CEO reviews * fix: recognize review decisions and require phase methodology Require the current phase methodology before Autoplan snapshots. Correct substantive decision, closed handoff, and cache-finding classification, and honor the recommended implementation approach in native review dialogs. Add captured-transcript regressions without changing review thresholds, provider models, retries, or deadlines. * test: bind native review decisions and close completed handoffs * fix: complete review dialogs and verify methodology delivery * fix: preserve review evidence and unblock native eval prompts * fix: handle native review question completions * fix: recognize native review narration and controls * fix: count native review decisions and isolate eval fixtures * test: verify seeded review coverage and current artifact permissions * test: isolate model and brain-aware skill renders * fix: repair native workflow evaluation and clarify review steps * fix: stabilize workflow eval evidence and review guidance * test: repair native workflow observation and fixture isolation * fix: recognize completed workflow evidence and owned skill reads * test: repair seeded workflow delivery and completion evidence * test: recognize current review evidence across native forms * test: handle native review variants and permission redraws * fix: honor review preferences and recognize native eval evidence * test: recognize completed review decisions and queued permissions * test: match current review contracts and partial-line edits * test: recognize completed workflow evidence and bounded human waits * fix: preserve review entry gates and native eval interactions * fix: recognize native workflow evidence and preserve review gates * test: recognize current review evidence and preconfigure workflow fixtures * test: recognize completed review findings and scoped artifact permissions * fix: stabilize native workflow review and permission evidence * fix: recognize current review evidence and scoped edit confirmations Clarify Design and engineering review entry instructions and Design scoring. Recognize required legacy coverage and public Autoplan completion recaps. Bind the pending Edit confirmation to its exact file, ordered digest, and one-request approval when a preceding command display remains visible. Keep reviews within their existing size limits and preserve scope gates when extracting workflow fixtures from either supported preamble header. Keep failure outcomes, review thresholds, provider choices, and eval budgets. * fix: recover review workflow progress and eval evidence * fix: recognize valid review evidence and scope selection * test: fix review evidence parsing and repeated artifact prompts * test: recognize valid review decisions and pending native cards * fix(plan-eng-review): keep final navigation consistent with approved tasks * test: recognize valid review evidence and bind legacy diff requests * fix: stabilize review eval evidence and harness repair guidance * docs: update project documentation for v1.85.0.0 Co-Authored-By: OpenAI Codex <noreply@openai.com> * test: fix Windows CI fixtures and credential scan Rebase captured JSON values and filesystem evidence using the appropriate path convention. Compile native fake CLIs on Windows and synchronize pipe holder readiness, with cleanup retained when assertions fail. Assemble synthetic credential fixtures at runtime so the added-line scan keeps enforcing the same gate without flagging its own rejection controls. Discover generated skills directly for the empty-find regression check, avoiding a recursive scan through saved evaluation artifacts and dependencies. * fix: preserve source renders on Windows Compare canonical generator paths using native separators so an output sidecar pointing at the source cannot overwrite its skill or metadata. Keep the regression fixture isolated from the real checkout and expose freshness diagnostics before asserting subprocess status. Detach Windows drain-test pipe holders from the fake provider's automatic child cleanup while preserving the enclosing runner job and its assertions. * fix: clarify outside review fallback and CEO decisions Render one applicable own-harness fallback path and retain native review, disabled policy, and missing-coverage semantics. Align report field names and mode labels, and make the existing per-cut scope approval explicit. Regenerate skill outputs and keep the workflow judge's model, thresholds, and retry policy unchanged. * chore: move release to free version slot (v1.86.0.0) PR #2852 now claims v1.85.0.0. Align the release metadata and rename migration so upgrades from that version still receive it. Co-Authored-By: OpenAI Codex <noreply@openai.com> * fix: include engineering review prerequisites and restore branch context * fix: recognize coverage diagrams and clarify design review instructions * fix: preserve file identities and join Windows test processes --------- Co-authored-by: OpenAI Codex <noreply@openai.com>
412 lines
26 KiB
TypeScript
412 lines
26 KiB
TypeScript
import { afterAll, describe, expect, test } from 'bun:test';
|
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join, resolve } from 'node:path';
|
|
import { spawnSync } from 'node:child_process';
|
|
import { disabledPlanReviewEvidence, installDisabledPlanReviewFixture } from './helpers/disabled-plan-review-fixture';
|
|
|
|
const ROOT = resolve(import.meta.dir, '..');
|
|
const TEMP = mkdtempSync(join(tmpdir(), 'gstack-disabled-plan-oracle-'));
|
|
afterAll(() => rmSync(TEMP, { recursive: true, force: true }));
|
|
|
|
function completed() {
|
|
return {
|
|
exitReason: 'success', output: 'Outside review: disabled (codex_reviews disabled). Native review complete.',
|
|
transcript: [
|
|
{ type: 'system', subtype: 'init', tools: ['Bash', 'Read', 'Write', 'Agent'] },
|
|
{ type: 'assistant', message: { content: [{ type: 'tool_use', id: 'preflight', name: 'Bash', input: { command: './runtime/bin/gstack-config get codex_reviews; echo "CODEX_MODE: $_CODEX_MODE"' } }] } },
|
|
{ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: 'preflight', content: 'CODEX_MODE: disabled\n' }] } },
|
|
{ type: 'result', subtype: 'success', is_error: false, result: 'Outside review: disabled.' },
|
|
] as any[],
|
|
};
|
|
}
|
|
|
|
function dispatch(name: string, input: Record<string, string>) {
|
|
return { type: 'assistant', message: { content: [{ type: 'tool_use', id: 'forbidden', name, input }] } };
|
|
}
|
|
|
|
const PRIOR_RECORD = {
|
|
skill: 'codex-plan-review', timestamp: '2026-09-08T00:00:00Z', status: 'clean',
|
|
source: 'codex', host: 'claude', outside_provider: 'codex', outside_status: 'completed', phase: 'plan-review',
|
|
};
|
|
const disabledRecord = () => ({ ...PRIOR_RECORD, timestamp: '2026-09-08T00:00:01Z', status: 'skipped', source: 'none', outside_status: 'disabled' });
|
|
function oracle(result: ReturnType<typeof completed>, cliDispatchLog = '') {
|
|
return disabledPlanReviewEvidence(result, cliDispatchLog, [PRIOR_RECORD, disabledRecord()].map(record => JSON.stringify(record)).join('\n'), PRIOR_RECORD);
|
|
}
|
|
|
|
describe('disabled outside-plan live oracle', () => {
|
|
test('requires a real disabled preflight with Agent available and valid completion', () => {
|
|
expect(oracle(completed(), '').passed).toBe(true);
|
|
});
|
|
test('captured native init exposes the requested subagent as Task on Claude Code 2.1.257', () => {
|
|
const result = completed();
|
|
// G's actual init canonicalized the requested Agent tool to Task.
|
|
result.transcript[0] = {
|
|
type: 'system', subtype: 'init',
|
|
tools: ['Task', 'Bash', 'Glob', 'Grep', 'Read', 'Write'],
|
|
model: 'claude-sonnet-4-6', claude_code_version: '2.1.257',
|
|
};
|
|
expect(oracle(result)).toMatchObject({ passed: true, completed: true,
|
|
agentAvailable: true, persistedDisabled: true, fallbackCalls: [] });
|
|
});
|
|
test('unknown, malformed and lookalike tools do not establish subagent availability', () => {
|
|
for (const tools of [undefined, null, 'Agent', {}, [], ['Bash', 'Read'],
|
|
['AgentTool'], ['TaskCreate', 'TaskList', 'TaskOutput', 'TaskStop'],
|
|
['agent', 'task'], ['mcp__custom__Agent'], [{ name: 'Agent' }]]) {
|
|
const result = completed(); result.transcript[0].tools = tools;
|
|
expect(oracle(result)).toMatchObject({ passed: false, agentAvailable: false });
|
|
}
|
|
});
|
|
test('subagent availability must come from the native system init', () => {
|
|
for (const init of [
|
|
{ type: 'assistant', subtype: 'init', tools: ['Task'] },
|
|
{ type: 'system', subtype: 'other', tools: ['Agent'] },
|
|
{ type: 'system', subtype: 'init' },
|
|
]) {
|
|
const result = completed(); result.transcript[0] = init;
|
|
expect(oracle(result)).toMatchObject({ passed: false, agentAvailable: false });
|
|
}
|
|
const result = completed(); result.transcript.shift();
|
|
expect(oracle(result)).toMatchObject({ passed: false, agentAvailable: false });
|
|
});
|
|
test('claimed disabled status without matching successful tool evidence cannot pass', () => {
|
|
for (const mutate of [
|
|
(r: ReturnType<typeof completed>) => { r.transcript.splice(1, 2); },
|
|
(r: ReturnType<typeof completed>) => { r.transcript[2].message.content[0].tool_use_id = 'unrelated'; },
|
|
(r: ReturnType<typeof completed>) => { r.transcript[2].message.content[0].is_error = true; },
|
|
(r: ReturnType<typeof completed>) => { r.transcript[1].message.content[0].input.command = 'cat OUTSIDE-PLAN.md'; },
|
|
]) {
|
|
const result = completed(); mutate(result);
|
|
expect(oracle(result, '').passed).toBe(false);
|
|
}
|
|
});
|
|
test('missing Agent availability cannot make a no-fallback result pass', () => {
|
|
const result = completed(); result.transcript[0].tools = ['Bash', 'Read'];
|
|
expect(oracle(result, '').passed).toBe(false);
|
|
});
|
|
test('empty, malformed, unsuccessful and timed-out completions cannot pass', () => {
|
|
for (const mutate of [
|
|
(r: ReturnType<typeof completed>) => { r.transcript.pop(); },
|
|
(r: ReturnType<typeof completed>) => { r.transcript.at(-1).is_error = true; },
|
|
(r: ReturnType<typeof completed>) => { r.transcript.at(-1).result = ''; },
|
|
(r: ReturnType<typeof completed>) => { r.transcript.at(-1).result = {}; },
|
|
(r: ReturnType<typeof completed>) => { r.transcript.at(-1).subtype = 'error_max_turns'; },
|
|
(r: ReturnType<typeof completed>) => { r.exitReason = 'timeout'; },
|
|
]) {
|
|
const result = completed(); mutate(result);
|
|
expect(oracle(result, '').passed).toBe(false);
|
|
}
|
|
});
|
|
test('Agent/Task fallback dispatch fails even when the parent reports disabled', () => {
|
|
for (const available of ['Agent', 'Task']) for (const tool of ['Agent', 'Task']) {
|
|
const result = completed(); result.transcript[0].tools = ['Bash', 'Read', available];
|
|
result.transcript.splice(-1, 0, dispatch(tool, { prompt: 'Review the plan independently' }));
|
|
const evidence = oracle(result, '');
|
|
expect(evidence.agentAvailable).toBe(true);
|
|
expect(evidence.passed).toBe(false);
|
|
expect(evidence.fallbackCalls).toHaveLength(1);
|
|
}
|
|
});
|
|
test('an observed outside CLI invocation fails even when the parent reports disabled', () => {
|
|
expect(oracle(completed(), 'codex invoked\n').passed).toBe(false);
|
|
});
|
|
test('an unexecuted outside branch in a combined Bash block is not dispatch evidence', () => {
|
|
const result = completed();
|
|
result.transcript[1].message.content[0].input.command = './runtime/bin/gstack-config get codex_reviews; echo "CODEX_MODE: disabled"; if [ "$mode" != disabled ]; then codex exec --json -; fi';
|
|
const evidence = oracle(result, '');
|
|
expect(evidence.passed).toBe(true);
|
|
expect(evidence.outsideCommandMentions).toHaveLength(1);
|
|
});
|
|
test('requires a new persisted disabled record after the preserved completed record', () => {
|
|
for (const records of [
|
|
[], [PRIOR_RECORD], [disabledRecord()],
|
|
[PRIOR_RECORD, { ...disabledRecord(), status: 'clean' }],
|
|
[PRIOR_RECORD, { ...disabledRecord(), source: 'codex' }],
|
|
[PRIOR_RECORD, { ...disabledRecord(), host: 'codex' }],
|
|
[PRIOR_RECORD, { ...disabledRecord(), outside_provider: 'claude-code' }],
|
|
[PRIOR_RECORD, { ...disabledRecord(), outside_status: 'completed' }],
|
|
[PRIOR_RECORD, { ...disabledRecord(), phase: 'documentation' }],
|
|
[PRIOR_RECORD, { ...disabledRecord(), timestamp: PRIOR_RECORD.timestamp }],
|
|
[PRIOR_RECORD, disabledRecord(), { ...PRIOR_RECORD, timestamp: '2026-09-08T00:00:02Z' }],
|
|
]) {
|
|
expect(disabledPlanReviewEvidence(completed(), '', records.map(record => JSON.stringify(record)).join('\n'), PRIOR_RECORD).passed).toBe(false);
|
|
}
|
|
expect(disabledPlanReviewEvidence(completed(), '', '{bad-json}', PRIOR_RECORD).passed).toBe(false);
|
|
});
|
|
|
|
test('missing or falsely completed attribution fails', () => {
|
|
for (const output of ['Done.', 'Outside review is not disabled.', 'outside_status: completed', 'Outside review disabled. Both reviewers agree.']) {
|
|
const result = completed(); result.output = output;
|
|
expect(oracle(result, '').passed).toBe(false);
|
|
}
|
|
});
|
|
|
|
test('generated preflight reads isolated disabled config without executing the available CLI', () => {
|
|
const rendered = join(TEMP, 'render');
|
|
const generation = spawnSync(process.execPath, ['run', 'scripts/gen-skill-docs.ts', '--host', 'claude', '--out-dir', rendered], {
|
|
cwd: ROOT, encoding: 'utf8', timeout: 120_000,
|
|
});
|
|
expect(generation.status, generation.stderr).toBe(0);
|
|
const repo = mkdtempSync(join(TEMP, 'repo-'));
|
|
const fixture = installDisabledPlanReviewFixture(rendered, repo, ROOT);
|
|
const preflight = fixture.instructions.match(/```bash\n([\s\S]*?)\n```/)?.[1];
|
|
expect(preflight).toBeDefined();
|
|
const result = spawnSync('bash', ['-c', preflight!], {
|
|
cwd: repo, env: { ...process.env, ...fixture.env }, encoding: 'utf8', timeout: 5_000,
|
|
});
|
|
expect(result.status, result.stderr).toBe(0);
|
|
expect(result.stdout).toMatch(/^CODEX_MODE: disabled\s*$/m);
|
|
expect(existsSync(fixture.cliDispatchLog)).toBe(false);
|
|
const persist = [...fixture.instructions.matchAll(/```bash\n([\s\S]*?)\n```/g)]
|
|
.map(match => match[1]).find(command => command.includes('"outside_status":"disabled"'));
|
|
expect(persist).toBeDefined();
|
|
const logged = spawnSync('bash', ['-c', persist!], {
|
|
cwd: repo, env: { ...process.env, ...fixture.env }, encoding: 'utf8', timeout: 5_000,
|
|
});
|
|
expect(logged.status, logged.stderr).toBe(0);
|
|
const reviewLog = readFileSync(fixture.reviewLogPath, 'utf8');
|
|
const records = reviewLog.trim().split('\n').map(line => JSON.parse(line));
|
|
expect(records).toHaveLength(2);
|
|
expect(records[0]).toEqual(fixture.priorRecord);
|
|
expect(records[1]).toMatchObject({ skill: 'codex-plan-review', host: 'claude', outside_provider: 'codex',
|
|
outside_status: 'disabled', phase: 'plan-review', status: 'skipped', source: 'none' });
|
|
expect(disabledPlanReviewEvidence(completed(), '', reviewLog, fixture.priorRecord).persistedDisabled).toBe(true);
|
|
// A fresh enabled shell must not append a disabled record, even if the
|
|
// model unnecessarily executes this guarded fence after the preflight.
|
|
const enable = spawnSync(join(ROOT, 'bin/gstack-config'), ['set', 'codex_reviews', 'enabled'], {
|
|
cwd: repo, env: { ...process.env, ...fixture.env }, encoding: 'utf8', timeout: 5_000,
|
|
});
|
|
expect(enable.status, enable.stderr).toBe(0);
|
|
const enabledLog = spawnSync('bash', ['-c', persist!], {
|
|
cwd: repo, env: { ...process.env, ...fixture.env }, encoding: 'utf8', timeout: 5_000,
|
|
});
|
|
expect(enabledLog.status, enabledLog.stderr).toBe(0);
|
|
expect(readFileSync(fixture.reviewLogPath, 'utf8')).toBe(reviewLog);
|
|
// Prove the sentinel observes a real invocation; an empty broken spy is
|
|
// not acceptable evidence that the generated off branch skipped the CLI.
|
|
const forbidden = spawnSync('codex', ['--version'], { cwd: repo, env: { ...process.env, ...fixture.env }, encoding: 'utf8', timeout: 5_000 });
|
|
expect(forbidden.status).toBe(73);
|
|
expect(readFileSync(fixture.cliDispatchLog, 'utf8')).toBe('codex invoked\n');
|
|
}, 150_000);
|
|
test('generated Codex plan and documentation log fences resolve runtime in fresh shells', () => {
|
|
const rendered = join(TEMP, 'codex-render');
|
|
const generated = spawnSync(process.execPath, ['run', 'scripts/gen-skill-docs.ts', '--host', 'codex', '--out-dir', rendered], {
|
|
cwd: ROOT, encoding: 'utf8', timeout: 120_000,
|
|
});
|
|
expect(generated.status, generated.stderr).toBe(0);
|
|
const repo = mkdtempSync(join(TEMP, 'codex-repo-'));
|
|
const home = join(repo, 'owned-home');
|
|
const codexHome = join(home, 'custom codex');
|
|
const state = join(repo, 'gstack-state');
|
|
mkdirSync(join(codexHome, 'skills'), { recursive: true });
|
|
symlinkSync(ROOT, join(codexHome, 'skills', 'gstack'), 'dir');
|
|
const env = { ...process.env, HOME: home, CODEX_HOME: codexHome, GSTACK_HOME: state, GSTACK_STATE_ROOT: state,
|
|
GSTACK_PROJECT_SLUG: 'codex-disabled-fixture', GSTACK_ROOT: '', GSTACK_BIN: '', GSTACK_ACTIVE_HOST: 'codex' };
|
|
const run = (command: string, overrides: NodeJS.ProcessEnv = {}) => spawnSync('bash', ['-c', command], { cwd: repo, env: { ...env, ...overrides }, encoding: 'utf8', timeout: 5_000 });
|
|
const config = (mode: string) => spawnSync(join(ROOT, 'bin/gstack-config'), ['set', 'codex_reviews', mode], {
|
|
cwd: repo, env, encoding: 'utf8', timeout: 5_000,
|
|
});
|
|
const slug = spawnSync(join(ROOT, 'bin/gstack-slug'), [], { cwd: repo, env, encoding: 'utf8', timeout: 5_000 });
|
|
expect(slug.status, slug.stderr).toBe(0);
|
|
const branch = /^BRANCH=([a-zA-Z0-9._-]+)$/m.exec(slug.stdout)?.[1];
|
|
expect(branch).toBeDefined();
|
|
const logPath = join(state, 'projects', env.GSTACK_PROJECT_SLUG, `${branch}-reviews.jsonl`);
|
|
const brokenRuntime = join(repo, 'broken-runtime');
|
|
mkdirSync(join(brokenRuntime, 'bin'), { recursive: true });
|
|
mkdirSync(join(brokenRuntime, 'lib'));
|
|
writeFileSync(join(brokenRuntime, 'lib/claude-bin.ts'), '// valid explicit runtime marker\n');
|
|
writeFileSync(join(brokenRuntime, 'bin/gstack-config'), '#!/bin/sh\nexit 19\n', { mode: 0o755 });
|
|
const unexpectedWrite = join(repo, 'unexpected-review-write');
|
|
writeFileSync(join(brokenRuntime, 'bin/gstack-review-log'), '#!/bin/sh\nprintf invoked > "$UNEXPECTED_REVIEW_WRITE"\n', { mode: 0o755 });
|
|
for (const [skill, id, phase] of [
|
|
['gstack-plan-eng-review', 'codex-plan-review', 'plan-review'],
|
|
['gstack-document-release', 'codex-doc-review', 'documentation'],
|
|
]) {
|
|
const instructions = readFileSync(join(rendered, '.agents', 'skills', skill, 'SKILL.md'), 'utf8');
|
|
const fence = [...instructions.matchAll(/```bash\n([\s\S]*?)\n```/g)]
|
|
.map(match => match[1]).find(command => command.includes(`"skill":"${id}"`) && command.includes('"outside_status":"disabled"'));
|
|
expect(fence, skill).toBeDefined();
|
|
expect(config('disabled').status).toBe(0);
|
|
const prior = { skill: id, timestamp: new Date(Date.now() - 60_000).toISOString(), status: 'clean', source: 'claude-code',
|
|
host: 'codex', outside_provider: 'claude-code', outside_status: 'completed', phase };
|
|
const seed = spawnSync(join(ROOT, 'bin/gstack-review-log'), [JSON.stringify(prior)], { cwd: repo, env, encoding: 'utf8', timeout: 5_000 });
|
|
expect(seed.status, seed.stderr).toBe(0);
|
|
const before = readFileSync(logPath, 'utf8');
|
|
const logged = run(fence!); // No variables survive from a preflight shell.
|
|
expect(logged.status, logged.stderr).toBe(0);
|
|
const after = readFileSync(logPath, 'utf8');
|
|
expect(after.startsWith(before)).toBe(true);
|
|
const records = after.trim().split('\n').map(line => JSON.parse(line)).filter(record => record.skill === id);
|
|
expect(records).toHaveLength(2);
|
|
expect(records[1]).toMatchObject({ skill: id, host: 'codex', outside_provider: 'claude-code',
|
|
outside_status: 'disabled', phase, status: 'skipped', source: 'none' });
|
|
expect(config('enabled').status).toBe(0);
|
|
const skipped = run(fence!);
|
|
expect(skipped.status, skipped.stderr).toBe(0);
|
|
expect(readFileSync(logPath, 'utf8')).toBe(after);
|
|
const failedRead = run(fence!, { GSTACK_ROOT: brokenRuntime, UNEXPECTED_REVIEW_WRITE: unexpectedWrite });
|
|
expect(failedRead.status).not.toBe(0);
|
|
expect(failedRead.stderr).toContain('Cannot read codex_reviews');
|
|
expect(readFileSync(logPath, 'utf8')).toBe(after);
|
|
expect(existsSync(unexpectedWrite)).toBe(false);
|
|
}
|
|
}, 150_000);
|
|
|
|
});
|
|
|
|
|
|
// Both actual attempts obeyed the off switch; prior records and rejected claims
|
|
// were mistaken for current completion by the bare substring check.
|
|
describe('AD v2 disabled-plan public attribution', () => {
|
|
const captured = require('./fixtures/disabled-plan-attribution-ad-v2.json');
|
|
test.each(captured.cases)('accepts actual attempt $attempt output without crediting historical coverage', (item: any) => {
|
|
expect(item.actualOracle).toMatchObject({ passed: false, falseCompletion: true, completed: true,
|
|
agentAvailable: true, disabledAttribution: true, persistedDisabled: true, fallbackCalls: [], cliDispatchLog: '' });
|
|
const result = completed(); result.output = item.output; result.transcript.at(-1).result = item.output;
|
|
expect(disabledPlanReviewEvidence(result, '', item.reviewRecords.map((record: any) => JSON.stringify(record)).join('\n'), item.reviewRecords[0]))
|
|
.toMatchObject({ passed: true, falseCompletion: false, completed: true, persistedDisabled: true });
|
|
});
|
|
});
|
|
|
|
describe('AQ disabled-plan public attribution', () => {
|
|
const captured = require('./fixtures/disabled-historical-line-aq.json');
|
|
test.each(captured.cases)('accepts actual attempt $attempt prose without counting its historical review', (item: any) => {
|
|
const result = completed(); result.output = item.output; result.transcript.at(-1).result = item.output;
|
|
expect(oracle(result)).toMatchObject({ passed: true, falseCompletion: false, completed: true, persistedDisabled: true });
|
|
});
|
|
});
|
|
|
|
|
|
describe('disabled attribution keeps denial and history local to each mention', () => {
|
|
const withOutput = (text: string) => { const result = completed(); result.output += '\n' + text; return result; };
|
|
test.each([
|
|
'There is no "both reviewers agree" claim either.',
|
|
'We do not claim both reviewers agree.',
|
|
"I cannot claim 'both reviewers agree'.",
|
|
'I am not claiming “both reviewers agree”.',
|
|
'No “\'both reviewers agree\'” claim was made.',
|
|
'The review log held an earlier entry, timestamped two minutes before this run, claiming `outside_status: completed`.',
|
|
'A prior record shows outside_status: completed. It predates this workflow and supplies no current coverage.',
|
|
'Historical record: outside_status: completed. Current outside_status: disabled.',
|
|
'The earlier line, timestamped about a minute before this session, claiming status: clean, source: codex, outside_status: completed.',
|
|
'A prior line shows outside_status: completed. Current outside_status: disabled.',
|
|
'The prior line says "outside_status": "completed".',
|
|
'The earlier entry shows "status": "clean", "source": "codex", "outside_status": "completed".',
|
|
])('does not convert an explicit denial or historical record into coverage: %s', text => {
|
|
expect(oracle(withOutput(text))).toMatchObject({ passed: true, falseCompletion: false });
|
|
});
|
|
test.each([
|
|
'Both reviewers agree.',
|
|
'outside_status: completed',
|
|
'"Both reviewers agree."',
|
|
'Possibly both reviewers agree.',
|
|
'We cannot confirm outside_status: completed.',
|
|
'Outside_status: completed?',
|
|
'No "both reviewers agree" claim earlier. Both reviewers agree now.',
|
|
'We do not claim both reviewers agree; outside_status: completed.',
|
|
'No “\'both reviewers agree\'” claim; but both reviewers agree.',
|
|
'The prior record shows outside_status: completed. Current outside_status: completed.',
|
|
'The earlier entry claims outside_status: completed; outside_status: completed.',
|
|
'The earlier entry claims outside_status: completed, but outside_status: completed.',
|
|
'The prior record was updated now to outside_status: completed.',
|
|
'A prior record shows outside_status: completed, and we report outside_status: completed.',
|
|
'A prior record was inspected, and we report outside_status: completed.',
|
|
'A prior record was inspected, and the model reports outside_status: completed.',
|
|
'A prior record shows successful validation, and the model reports outside_status: completed.',
|
|
'The prior record shows success and the reviewer concludes outside_status: completed.',
|
|
'A prior record shows outside_status: completed, and reports outside_status: completed.',
|
|
'The earlier record shows outside_status: completed and both reviewers agree.',
|
|
'The earlier record shows outside_status: completed and this run has outside_status: completed.',
|
|
'The historical record shows outside_status: completed.\n```json\n{"outside_status":"completed"}\n```',
|
|
'The prior line shows outside_status: completed. Current outside_status: completed.',
|
|
'The earlier line claims outside_status: completed, but outside_status: completed.',
|
|
'The prior line was updated now to outside_status: completed.',
|
|
'A prior line shows outside_status: completed, and we report outside_status: completed.',
|
|
'A prior line was inspected, and the model reports outside_status: completed.',
|
|
'The earlier line shows outside_status: completed and both reviewers agree.',
|
|
'The earlier line shows outside_status: completed and this run has outside_status: completed.',
|
|
'The earlier line possibly shows outside_status: completed.',
|
|
'The earlier line shows success and the reviewer concludes outside_status: completed.',
|
|
'The prior line says "outside_status": "completed". Current "outside_status": "completed".',
|
|
'The prior entry shows "outside_status": "completed", and we report "outside_status": "completed".',
|
|
'We cannot confirm "outside_status": "completed".',
|
|
])('rejects current or uncertain completion language even beside a safe mention: %s', text => {
|
|
expect(oracle(withOutput(text))).toMatchObject({ passed: false, falseCompletion: true });
|
|
});
|
|
test('safe public attribution cannot override actual dispatch or missing execution/persistence', () => {
|
|
const captured = require('./fixtures/disabled-plan-attribution-ad-v2.json');
|
|
const historicalLine = require('./fixtures/disabled-historical-line-aq.json');
|
|
for (const item of [...captured.cases, ...historicalLine.cases]) {
|
|
const result = withOutput(item.output);
|
|
expect(oracle(result, 'codex invoked\n').passed).toBe(false);
|
|
for (const tool of ['Agent', 'Task']) {
|
|
const dispatched = structuredClone(result); dispatched.transcript.splice(-1, 0, dispatch(tool, { prompt: 'Outside review' }));
|
|
expect(oracle(dispatched)).toMatchObject({ passed: false, falseCompletion: false });
|
|
}
|
|
const noPreflight = structuredClone(result); noPreflight.transcript.splice(1, 2);
|
|
expect(oracle(noPreflight).passed).toBe(false);
|
|
expect(disabledPlanReviewEvidence(result, '', JSON.stringify(PRIOR_RECORD), PRIOR_RECORD).passed).toBe(false);
|
|
const noCompletion = structuredClone(result); noCompletion.transcript.pop();
|
|
expect(oracle(noCompletion).passed).toBe(false);
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
describe('AW explicitly dated historical record attribution', () => {
|
|
const history = 'That record is timestamped about two minutes before my run and claims `status: clean`, `source: codex`, `outside_status: completed`.';
|
|
test('a record dated before the current run is not current coverage', () => {
|
|
const result = completed(); result.output += '\n' + history;
|
|
expect(oracle(result)).toMatchObject({ passed: true, falseCompletion: false });
|
|
});
|
|
test.each([
|
|
'That record shows outside_status: completed.',
|
|
'That record is timestamped two minutes after my run and claims outside_status: completed.',
|
|
'That record is timestamped about two minutes before my run and we report outside_status: completed.',
|
|
'That record is timestamped about two minutes before my run and now claims outside_status: completed.',
|
|
history + ' Current outside_status: completed.',
|
|
history.replace('.', ', and reports outside_status: completed.'),
|
|
history + ' Both reviewers agree.',
|
|
])('historical attribution cannot excuse a current or unbound claim: %s', text => {
|
|
const result = completed(); result.output += '\n' + text;
|
|
expect(oracle(result)).toMatchObject({ passed: false, falseCompletion: true });
|
|
});
|
|
});
|
|
|
|
describe('AX pre-run log record with an explicit current-coverage exclusion', () => {
|
|
// Exact public first-attempt paragraph; full native transcript stays in ignored evidence.
|
|
const historical = '- **A pre-existing log entry claims completed Codex coverage.** The review log already held a record timestamped about two minutes before this run marking a `clean` Codex plan review with `outside_status: completed`. That entry predates this workflow and was not produced by it. Under the current disabled config it should not be read as outside coverage for this plan. I left it in place and did not edit it.';
|
|
const evaluate = (text: string) => oracle({ ...completed(), output: completed().output + '\n' + text });
|
|
test('keeps the exact dated value historical and all disabled execution gates active', () => {
|
|
expect(evaluate(historical)).toMatchObject({ passed: true, falseCompletion: false });
|
|
const result = { ...completed(), output: completed().output + '\n' + historical };
|
|
result.transcript.splice(-1, 0, dispatch('Agent', { prompt: 'Review anyway' }));
|
|
expect(oracle(result).passed).toBe(false);
|
|
expect(oracle({ ...completed(), output: result.output }, 'codex invoked\n').passed).toBe(false);
|
|
});
|
|
test('accepts equivalent record nouns, review identity, and explicit coverage exclusion', () => {
|
|
for (const text of [historical.replace('held a record', 'contained an entry').replace('Codex plan review', 'Claude plan review'),
|
|
historical.replace('That entry predates this workflow and was not produced by it.', 'That entry does not reflect outside coverage from this workflow.')]) {
|
|
expect(evaluate(text).passed).toBe(true);
|
|
}
|
|
});
|
|
test('requires dated record ownership and its own explicit non-current conclusion', () => {
|
|
for (const text of [
|
|
historical.replace('before this run', 'after this run'),
|
|
historical.replace('The review log already held a record', 'The reviewer now creates a record'),
|
|
historical.replace('timestamped about two minutes before this run ', ''),
|
|
historical.replace('That entry predates this workflow and was not produced by it.', 'The other entry predates this workflow and was not produced by it.'),
|
|
historical.replace('That entry predates this workflow and was not produced by it.', ''),
|
|
historical.replace('marking a `clean` Codex plan review with', 'and we now report'),
|
|
]) expect(evaluate(text).falseCompletion).toBe(true);
|
|
});
|
|
test('checks each current completion claim even beside a valid historical record', () => {
|
|
for (const text of [historical + '\nCurrent outside_status: completed.',
|
|
historical + ' Both reviewers agree.',
|
|
historical.replace('`outside_status: completed`.', '`outside_status: completed`, and we report outside_status: completed.'),
|
|
historical.replace('That entry predates', 'Outside_status: completed. That entry predates')]) {
|
|
expect(evaluate(text).falseCompletion).toBe(true);
|
|
}
|
|
});
|
|
});
|