Files
gstack/test/plan-count-transcript.test.ts
Garry TanandOpenAI Codex 9f81911136 v1.86.0.0 feat: route outside reviews by harness (#2850)
* 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>
2026-09-14 14:32:45 -07:00

253 lines
18 KiB
TypeScript

import { afterEach, describe, expect, test } from 'bun:test';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { readPlanCountTranscript, unresolvedPlanQuestionCalls } from './helpers/plan-count-transcript';
import { nativePlanCallFingerprint, planCountQuestionPhase, engStep0Boundary, ceoStep0Boundary, ceoFirstReviewAUQ } from './helpers/claude-pty-runner';
const dirs: string[] = [];
afterEach(() => { for (const dir of dirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true }); });
function fixture() {
const config = fs.mkdtempSync(path.join(os.tmpdir(), 'plan-count-transcript-'));
dirs.push(config);
const cwd = path.join(config, 'fixture');
const project = path.join(config, 'projects', 'fixture');
fs.mkdirSync(project, { recursive: true });
const sessionId = 'session-a';
const file = path.join(project, `${sessionId}.jsonl`);
const record = (role: string, content: object[], extra = {}) => ({
cwd, sessionId, isSidechain: false, timestamp: '2026-09-08T15:31:13.607Z',
message: { role, content }, ...extra,
});
const question = (text = 'D1 — Cross-project learnings scope <gstack-qid:learnings-cross-project>') => ({
header: 'Learnings', question: text,
options: [{ label: 'Enable cross-project learnings (Recommended)' }, { label: 'Keep project-scoped' }],
});
const ask = (id: string, questions = [question()], extra = {}) => record('assistant', [
{ type: 'tool_use', id, name: 'AskUserQuestion', input: { questions } },
], extra);
const answer = (id: string, questions = [question()], extra = {}) => record('user', [
{ type: 'tool_result', tool_use_id: id, content: 'Your questions have been answered.' },
], { toolUseResult: { answers: Object.fromEntries(questions.map(q => [q.question, q.options[0].label])) }, ...extra });
const append = (...records: object[]) => fs.appendFileSync(file, records.map(r => JSON.stringify(r) + '\n').join(''));
const read = () => readPlanCountTranscript(config, cwd);
return { config, cwd, project, file, question, ask, answer, append, read, record };
}
describe('native plan-count transcripts', () => {
test('the actual partially answered CEO setup packet counts once without selecting its unanswered mode', () => {
const f = fixture();
// Native question/header/label metadata from targeted-a's paired CEO
// call. The successful tool_result answered only routing and approach.
const packet = [{"header":"Routing","question":"gstack works best when your project's CLAUDE.md includes skill routing rules — should I add them? <gstack-qid:routing-injection>","options":[{"label":"Add routing rules (Recommended)"},{"label":"Skip for now"}]},{"header":"Prerequisites","question":"No design doc found for this branch. Run /office-hours to capture structured problem context first, or proceed directly to the plan review? <gstack-qid:plan-ceo-review-office-hours>","options":[{"label":"Skip — review the plan directly (Recommended)"},{"label":"Run /office-hours first"}]},{"header":"Test Scope","question":"Which implementation approach should the tests follow? This shapes the review scope. <gstack-qid:plan-ceo-review-approach>\n\nD1 — Approach selection for processPayment() test coverage\nProject: Payment Processing — adding missing unit tests\nELI10: The plan calls for exactly 2 tests. Adding a few more for the most common real-world Stripe failures (card declined, rate limit) costs ~10 extra minutes with CC but closes the gaps users actually hit. The question is whether to stay at 2 or expand to ~5-6 tests.\nStakes if we pick wrong: Choosing minimal leaves 402 (card declined) untested — the most common production failure. Choosing full adds ~5 min of CC work.\nRecommendation: B (Core Stripe paths) because 402 card declined is the highest-volume real-world failure and CC compresses the extra work to near-zero.\nCompleteness: A=7/10, B=9/10","options":[{"label":"Minimal — 2 tests as planned (7/10)"},{"label":"Core paths — ~5 tests (9/10) (Recommended)"}]},{"header":"Review Mode","question":"D2 — Review mode for this plan?\nProject: Payment Processing test coverage — adding missing unit tests for processPayment()\nELI10: The plan adds 2 missing unit tests. HOLD SCOPE means: take the scope as given, review it with maximum rigor — catch every ambiguity, failure mode, edge case, observability gap. SELECTIVE EXPANSION means: do all that AND surface cherry-pick expansions (additional test scenarios, receipt schema validation, etc.) one at a time for your approval.\nStakes if we pick wrong: HOLD keeps the review tight and fast. SELECTIVE surfaces more opportunities but adds round-trips.\nRecommendation: HOLD SCOPE — this is a focused gap-fill, and rigor matters more than ambition here.\nNote: options differ in kind, not coverage — no completeness score. <gstack-qid:plan-ceo-review-mode>","options":[{"label":"HOLD SCOPE — maximum rigor (Recommended)"},{"label":"SELECTIVE EXPANSION — rigor + cherry-picks"}]}];
f.append(f.ask('actual-packet', packet), f.answer('actual-packet', [packet[0], packet[2]]));
const [call] = f.read().calls;
expect(call.answered).toBe(true);
expect(call.failed).toBe(false);
expect(call.unansweredQuestionIndices).toEqual([1, 3]);
expect(f.read().calls.filter(c => c.answered)).toHaveLength(1);
const setup = nativePlanCallFingerprint(call, 0, true);
expect(setup.options.some(o => /HOLD SCOPE/.test(o.label))).toBe(false);
expect(ceoStep0Boundary(setup)).toBe(false);
expect(ceoFirstReviewAUQ(setup)).toBe(false);
const finding = [{"header":"Receipt Schema","question":"D3 — The plan says 'assert correct receipt is generated' but doesn't define what a correct receipt looks like. Without a schema, the test will pass even if the receipt is missing critical fields.\n\nELI10: Right now the test could assert `receipt != nil` and call it a day. That test passes even if the receipt has the wrong amount or no charge ID. We need to specify what fields a correct receipt must have.\n\nStakes if we pick wrong: Tests pass in CI but fail to catch a real receipt bug — e.g., wrong charge_id linked to wrong customer.\n\nRecommendation: A — specify the receipt schema in the plan now; costs ~5 min, prevents a class of silent bugs.\nCompleteness: A=9/10, B=7/10, C=3/10 <gstack-qid:plan-ceo-receipt-schema>","options":[{"label":"Specify schema in plan (Recommended)"},{"label":"Specify during implementation"},{"label":"Skip — too much detail for a plan"}]}];
f.append(f.ask('receipt-schema', finding), f.answer('receipt-schema', finding));
const review = nativePlanCallFingerprint(f.read().calls[1], 1, true);
expect(planCountQuestionPhase(review, false, ceoStep0Boundary, ceoFirstReviewAUQ))
.toEqual({ preReview: false, reviewStarted: true });
// A refused/empty packet must not receive the same completion credit.
f.append(f.ask('empty-packet', packet), f.answer('empty-packet', []));
const empty = f.read().calls[2];
expect(empty.answered).toBe(false);
expect(empty.failure).toContain('no matching nonempty answers');
});
test('CEO first-finding fallback requires native finding identity and rejects setup decisions', () => {
const f = fixture();
for (const [id, text] of [
['setup', 'D1 — Missing context: choose a scope <gstack-qid:plan-ceo-review-scope>'],
['mode', 'D1 — Missing context: choose a mode <gstack-qid:plan-ceo-review-mode>'],
['unscoped', 'D1 — Missing receipt schema'],
['arbitrary', 'D1 — Pick an option <gstack-qid:plan-ceo-review-choice>'],
['next', 'D1 — Missing engineering review: what next? <gstack-qid:plan-ceo-next-steps>'],
]) {
const questions = [f.question(text)];
f.append(f.ask(id, questions), f.answer(id, questions));
}
for (const call of f.read().calls) expect(ceoFirstReviewAUQ(nativePlanCallFingerprint(call, 0, true))).toBe(false);
});
test('requires a matching successful answer and preserves full native question metadata', () => {
const f = fixture();
const questions = [f.question('D1 — Cross-project learnings scope\n' + 'full context '.repeat(40) + '<gstack-qid:learnings-cross-project>')];
f.append(f.ask('one', questions));
expect(f.read().calls[0].answered).toBe(false);
f.append(f.answer('one', questions));
const before = fs.readFileSync(f.file, 'utf8');
const observed = f.read();
expect(observed.status).toBe('ready');
expect(observed.calls).toHaveLength(1);
expect(observed.calls[0].answered).toBe(true);
expect(observed.calls[0].questions).toEqual(questions);
const fp = nativePlanCallFingerprint(observed.calls[0], 1, true);
expect(fp.promptSnippet.length).toBeGreaterThan(240);
expect(fp.promptSnippet).toContain('<gstack-qid:learnings-cross-project>');
expect(planCountQuestionPhase(fp, false, engStep0Boundary)).toEqual({ preReview: true, reviewStarted: true });
expect(fs.readFileSync(f.file, 'utf8')).toBe(before);
});
test('one completed batched AskUserQuestion call remains one count even with unanswered questions', () => {
const f = fixture();
const questions = [f.question('D1 — Retry behavior?'), f.question('D2 — Error handling?')];
f.append(f.ask('batch', questions), f.answer('batch', [questions[0]]));
expect(f.read().calls.filter(c => c.answered)).toHaveLength(1);
expect(f.read().calls[0].unansweredQuestionIndices).toEqual([1]);
f.append(f.answer('batch', questions));
expect(f.read().calls.filter(c => c.answered)).toHaveLength(1);
expect(f.read().calls[0].questions).toHaveLength(2);
});
test('partial JSONL appends add no call or completion until the final newline', () => {
const f = fixture();
const call = JSON.stringify(f.ask('one'));
fs.writeFileSync(f.file, call.slice(0, 80));
expect(f.read()).toEqual({ status: 'missing', calls: [], assistantMessages: [] });
fs.appendFileSync(f.file, call.slice(80));
expect(f.read().calls).toEqual([]);
fs.appendFileSync(f.file, '\n');
expect(f.read().calls[0].answered).toBe(false);
const result = JSON.stringify(f.answer('one'));
fs.appendFileSync(f.file, result.slice(0, 80));
expect(f.read().calls[0].answered).toBe(false);
fs.appendFileSync(f.file, result.slice(80) + '\n');
expect(f.read().calls[0].answered).toBe(true);
});
test('repeated records and polls dedupe by tool ID, while identical questions in distinct calls remain distinct', () => {
const f = fixture();
f.append(f.ask('one'), f.ask('one'), f.answer('one'), f.answer('one'), f.ask('two'), f.answer('two'));
const first = f.read();
expect(first.calls.filter(c => c.answered)).toHaveLength(2);
expect(f.read()).toEqual(first);
expect(first.calls.map(c => nativePlanCallFingerprint(c, 0, false).signature)).toEqual(['session-a:one', 'session-a:two']);
});
test('wrong cwd, sidechain, session, tool ID, and missing scope cannot provide an answer', () => {
const f = fixture();
f.append(f.ask('one'));
for (const extra of [{ cwd: '/other' }, { isSidechain: true }, { sessionId: 'other' }, { cwd: undefined }, { isSidechain: undefined }]) {
f.append(f.answer('one', undefined, extra), f.ask('foreign', undefined, extra));
}
f.append(f.answer('wrong-id'));
expect(f.read().calls).toHaveLength(1);
expect(f.read().calls[0].answered).toBe(false);
fs.writeFileSync(path.join(f.project, 'other.jsonl'), JSON.stringify(f.answer('one', undefined, { sessionId: 'other' })) + '\n');
expect(f.read().calls[0].answered).toBe(false);
});
test('native permissions, schema failures, errors and refusals do not become completed questions', () => {
const f = fixture();
f.append(f.record('assistant', [{ type: 'tool_use', id: 'write', name: 'Write', input: { file_path: 'PLAN.md' } }]));
f.append(f.answer('write'));
f.append(f.record('assistant', [{ type: 'tool_use', id: 'bad', name: 'AskUserQuestion', input: { questions: [] } }]));
f.append(f.answer('bad'));
f.append(f.ask('error'));
f.append(f.record('user', [{ type: 'tool_result', tool_use_id: 'error', is_error: true, content: 'Rejected' }],
{ toolUseResult: { answers: { [f.question().question]: 'Yes' } } }));
f.append(f.ask('refusal'), f.answer('refusal', undefined, { toolUseResult: { answers: {} } }));
expect(f.read().calls).toHaveLength(2);
expect(f.read().calls.filter(c => c.answered)).toHaveLength(0);
expect(f.read().calls.every(c => c.failed)).toBe(true);
});
test('unrelated answered questions cannot conceal a refusal, but an actual retry can resolve it', () => {
const f = fixture();
const missing = [f.question('Should retries preserve idempotency?')];
const unrelated = [f.question('Should errors be logged?')];
f.append(f.ask('refusal', missing), f.answer('refusal', [], { toolUseResult: { answers: {} } }));
f.append(f.ask('unrelated', unrelated), f.answer('unrelated', unrelated));
expect(unresolvedPlanQuestionCalls(f.read().calls).map(c => c.toolUseId)).toEqual(['refusal']);
f.append(f.ask('retry', missing), f.answer('retry', missing));
expect(unresolvedPlanQuestionCalls(f.read().calls)).toEqual([]);
expect(f.read().calls.filter(c => c.answered)).toHaveLength(2);
});
test('missing transcripts and files from another fixture produce no positive coverage', () => {
const f = fixture();
expect(f.read()).toEqual({ status: 'missing', calls: [], assistantMessages: [] });
f.append(f.ask('other', undefined, { cwd: '/different-fixture' }), f.answer('other', undefined, { cwd: '/different-fixture' }));
expect(f.read()).toEqual({ status: 'missing', calls: [], assistantMessages: [] });
expect(readPlanCountTranscript(path.join(f.config, 'absent'), f.cwd)).toEqual({ status: 'missing', calls: [], assistantMessages: [] });
});
test('invalid completed JSON and excessive bytes fail explicitly without retaining partial coverage', () => {
const f = fixture();
f.append(f.ask('one'), f.answer('one'));
fs.appendFileSync(f.file, 'not JSON\n');
expect(f.read().status).toBe('error');
expect(f.read().calls).toEqual([]);
fs.writeFileSync(f.file, '');
fs.truncateSync(f.file, 32 * 1024 * 1024 + 1);
expect(f.read().error).toContain('32 MiB');
expect(f.read().calls).toEqual([]);
});
test('assistant posture evidence is scoped, timestamped text rather than tool results or partial records', () => {
const f = fixture();
f.append(f.record('assistant', [{ type: 'text', text: 'Earlier assistant posture.' }], { timestamp: '2026-09-08T15:31:10.000Z' }));
f.append(f.ask('mode'), f.answer('mode'));
f.append(f.record('assistant', [{ type: 'text', text: 'Later assistant posture.' }], { timestamp: '2026-09-08T15:31:20.000Z' }));
for (const extra of [{ cwd: '/other' }, { isSidechain: true }, { sessionId: 'other' }, { timestamp: 'invalid' }, { timestamp: undefined }]) {
f.append(f.record('assistant', [{ type: 'text', text: 'Not evidence.' }], extra));
}
f.append(f.record('user', [{ type: 'text', text: 'User prose is not assistant posture.' }]));
f.append(f.record('user', [{ type: 'tool_result', tool_use_id: 'other', content: 'Tool result posture is not evidence.' }]));
const observed = f.read();
expect(observed.assistantMessages).toEqual([
{ sessionId: 'session-a', text: 'Earlier assistant posture.', timestamp: '2026-09-08T15:31:10.000Z' },
{ sessionId: 'session-a', text: 'Later assistant posture.', timestamp: '2026-09-08T15:31:20.000Z' },
]);
expect(observed.calls[0].answeredAt).toBe('2026-09-08T15:31:13.607Z');
fs.appendFileSync(f.file, JSON.stringify(f.record('assistant', [{ type: 'text', text: 'Still writing.' }])));
expect(f.read().assistantMessages).toEqual(observed.assistantMessages);
fs.appendFileSync(f.file, '\ninvalid JSON\n');
expect(f.read().assistantMessages).toEqual([]);
expect(f.read().calls).toEqual([]);
});
});
describe('native plan approval request evidence', () => {
test('captures only a scoped complete ExitPlanMode request and retains error results', () => {
const f = fixture();
// Exact native tool shape from G Design's pending approval gate (its
// zero-question workflow remains a separate failed count observation).
const ready = f.record('assistant', [{ type: 'tool_use', id: 'plan-ready', name: 'ExitPlanMode', input: {}, caller: { type: 'direct' } }]);
const line = JSON.stringify(ready);
fs.writeFileSync(f.file, line);
expect(f.read().planReadyRequests).toBeUndefined();
fs.appendFileSync(f.file, '\n');
expect(f.read().planReadyRequests).toEqual([{ sessionId: 'session-a', toolUseId: 'plan-ready', timestamp: ready.timestamp, failed: false }]);
f.append(f.record('user', [{ type: 'tool_result', tool_use_id: 'plan-ready', is_error: true, content: 'Plan not accepted' }]));
expect(f.read().planReadyRequests![0]!.failed).toBe(true);
f.append(ready); // duplicate request cannot clear a recorded failure
expect(f.read().planReadyRequests![0]!.failed).toBe(true);
});
test('foreign, sidechain, quoted, lookalike and untimestamped requests add no readiness', () => {
const f = fixture();
const block = { type: 'tool_use', id: 'ready', name: 'ExitPlanMode', input: {} };
f.append(f.record('assistant', [block], { cwd: f.cwd + '-other' }),
f.record('assistant', [block], { sessionId: 'foreign' }),
f.record('assistant', [block], { isSidechain: true }),
f.record('assistant', [block], { timestamp: 'invalid' }),
f.record('assistant', [{ ...block, name: 'example_ExitPlanMode' }]),
f.record('assistant', [{ type: 'text', text: JSON.stringify(block) }]));
expect(f.read().planReadyRequests).toBeUndefined();
fs.appendFileSync(f.file, 'bad JSON\n');
expect(f.read().status).toBe('error');
expect(f.read().planReadyRequests).toBeUndefined();
});
});