v1.91.8.0 test: smaller suite, derived paid selection, retired never-green evals (#2994)

* test: delete test-infrastructure dead code (G)

- exit-propagation drives the runner's real strict verdict
  (BunTestOutputClassifier + strictTestExitCode); delete the unused
  shardRunLooksTruncated predicate.
- delete skill-coverage-matrix registry + its gate (nothing reads it; the
  floor already iterates skillCensus()).
- delete touchfiles-facade export-parity tests (Bun fails missing imports
  at link time) and the duplicated E2E_TIERS tier-value test.
- delete brain-cache-spec TRANSPORT_DEFAULT_POLICY, SKILL_RUN_RETENTION_DAYS
  and the now-unused BrainTrustPolicy type with their literal tests.
  AUTOPLAN_PREFLIGHT_BUDGET_BYTES stays: skill-preflight-budget enforces it
  against real resolver output.
- delete audit-compliance's JSDoc-comment grep.

* test: replace product tests that fake the product with real-boundary tests (F)

- design: serve.test.ts drove an inline mirror server; now two tests run the
  real serve() on an ephemeral port (reload confinement, submit exit 0).
- setup-gbrain: rollback + voyage tests execute the template-extracted init
  blocks (3 sites) instead of drifted local bash copies.
- terminal-agent: internalHandler source greps replaced by a behavioral
  /internal/grant + /internal/revoke auth matrix (no/wrong/valid token).
- /health: server-security-surface and the server-auth / security-audit-r2 /
  sidebar-tabs source greps fold into one liveness-only check on the real
  body; the L4 sidecar wiring gets a behavioral /pty-inject-scan test.
- delete tautologies (browser-manager onDisconnect, memory-command #12),
  ios swiftui tap fixture self-check, memory-ingest put_page grep, detach
  source greps, sidebar-agent absence pins, dead-CSS pins + the dead CSS,
  security-audit-r2 Task 1 + the test-only meta-commands re-export,
  duplicate generated-SKILL.md checks.
- make-pdf coverage-gaps cases move into their owner test files.

* test: delete tests of dead eval code (A)

- A1: the retired Eng lexical oracle (evaluateEngSeedCoverage,
  isEngSeedDecisionAUQ), the completion-handoff detector and the retained
  corpus had no paid caller since v1.87.6; delete their 26 replay files,
  ~2.6k helper LOC and fixtures, and the dead blocks in 8 mixed files
  (live hasNativePlanTerminal / batching assertions stay).
- A2: dead viewport approvers in autoplan-artifact-permission and their 11
  replay files + fixtures; recorder/launcher cases stay.
- A3: never-wired oracles and seeders (autoplan-phase-order,
  eng-finding-fixture, ceo-paired-fixture, design-ui-scope,
  plan-skill-completion, pty-current-screen, required-reads,
  transcript-section-logger); plan-seed-submission now decodes through the
  production createPtyScreen; section manifests name their actual guard.
- A4: zero-reference helper exports, plus execGit and invokeAndObserve
  found by the reachability pass.
- 52 fixtures orphaned by the deletions; touchfile and selection-table
  entries for every deleted path.

* test: clean up the paid eval lane (B1-B4, B6, B7)

- B1: delete paid files that assert nothing or cannot pass meaningfully:
  skill-llm-eval-spec and skill-e2e-spec-execute (test.todo), gemini-e2e
  (+ gemini-session-runner; no gemini CLI in CI), ship-idempotency (red
  since v1.63), the two opus-4-7 *-sonnet overlay wrappers, conductor-prose
  (+ its source-evaluation replay), codex-e2e-plan-format; drop their keys,
  scripts and census rows.
- B2: skill-llm-eval grades browse/sections/command-list.md with one union
  judge that also carries the baseline score pin; regression-vs-baseline
  deleted (paid run: pass, c4/c4/a4).
- B3: memory-pipeline, ios-qa, ios-qa-swift-build and plan-tune-cathedral
  make no model calls; renamed out of the paid glob so they run on every
  PR. Swift builds need GSTACK_TEST_SWIFT=1; device stub deleted.
- B4: codex-e2e*, outside-voice, aside and ios-device cannot run in the CI
  image; excluded from the weekly lane with a tracked re-entry condition.
- B6: fold opus-47's negative routing controls into skill-routing-e2e
  journey-negatives (paid run: 3/3 unrouted) and delete the file.
- B7: delete the never-green brain-privacy-gate eval; a free
  gstack-skill-start test now proves consent precedes artifacts egress.

* test: retire the finding-count cluster and trim its helpers (C)

- C0/C1: the five never-green evals (skill-e2e-autoplan-chain and
  skill-e2e-plan-{ceo,eng,design,devex}-finding-count) failed on harness and
  budget, never on skill behavior; delete them, their touchfile/tier ids,
  AUTOPLAN_CHAIN_BUDGET and the dedicated eighth periodic slice (--slices 7).
- C2: delete the helper groups whose only paid consumers were those files
  (11 modules), trim claude-pty-runner and eng-seeded-coverage to the paid
  closure, and delete the free replay tests whose assertions exercised only
  that dead code (89 files, 135 orphaned fixtures). Blocks that used dead code
  only as input for a live subject keep their assertions: the multiSelect
  default moved to plan-review-decisions, runner PTY tests use inline caller
  policies, and the timer-safe budget checks moved to eng-finding-retry-budget.
- The eight production-touching files stay except ceo-current-decision-record
  (its template read only feeds the retired counter).
- CARVE_GUARDS.autoplan is behavioral 'none'; TODOS records the lost chain
  and per-finding cadence coverage with their re-entry tests.

* test: fold per-incident replay series into their detector owners (D)

Twelve detector families move into one owner test each: 73 incident files
become describe blocks in ceo-section-loading-fixture (stale-fill race),
model-overlays, coverage-audit-evidence, autoplan-phase-observer,
native-auto-decide, outside-voice-evidence, eng-first-review,
plan-count-completion, plan-count-file-permission, ceo-mode-option,
plan-scope-selection and plan-count-prerequisite. Each block keeps its original
code and fixture, so every case still runs; only tests asserting the incident
file's own touchfile registration are dropped (41). Touchfile lists that named
an incident now name its owner.

* test: start the plan-count history PTY on its readiness marker (H)

The fake CLI prints a startup marker and the runner waits for it instead of the
fixed 8 s startup sleep (8.6 s -> 0.9 s locally). eng-semantic-terminal's
sleeping registration cases went with C; plan-count-timeout keeps the fixed wait
because it asserts deadline behavior.

* test: derive paid touchfiles from each eval's static closure (E)

touchfiles.test.ts now checks, per key, that the paid file's static
test/helpers and test/fixtures closure (plus fixture paths it names in string
literals) is covered, and names the file, path, chain and key to fix when it is
not. Free *.test.ts files are no longer touchfiles, so editing a free replay
test stops selecting paid evals: 950 entries removed, 653 real closure paths
added. The hand-copied inventories go: periodic-fixture-selection,
fake-impeccable-touchfiles and 45 per-file selection examples. Selection for
the sample edits (plan-eng-review template, claude-pty-runner,
plan-count-fixture, gstack-config) loses no case under either profile.
CONTRIBUTING documents the rule and its lower bound.

* test: skip hollow tier shards and census judges in the paid planner (B5)

A paid file is now skipped for a tier lane only when every E2E id it registers
is known statically and none has that tier; ids come from the touchfile
registrations and literal testName/*IfSelected arguments, so a comment or
skill path that quotes another id cannot unschedule it, and computed names
keep today's scheduling. --list and the manifest show each skip as
"skipped: no E2E_TIERS id has tier <tier>". The weekly gate census drops the
LLM judges (--skip-judges); they still run in the periodic census and PR gate
lanes. Gate lane 52 -> 42 files, census 41; periodic 77 -> 69.

* test: run seven paid evals on the current default capture model (B8)

skill-e2e-{auq-matrix,plan-format,qa-bugs,retro,workflow} pinned
claude-opus-4-7 and skill-e2e-office-hours plus -brain-writeback pinned
claude-sonnet-4-6; none tests a historical model, so they now capture with
resolveEvalModel('capture'), and the free harness tests that execute these
registrations receive the same resolver. The paid re-pin run passed all of
them. skill-e2e-{design,office-hours-phase4,plan-prosons,plan} keep
claude-opus-4-7: six of their cases failed on the default model (three
timeouts, a missing report file, a format miss and a posture score of 3), so
per the plan's fallback they keep their pins with a TODOS entry. The pre-spend
estimate and drop threshold are in docs/test-audit-2026-09.md.

* test: guard the reduced suite against new test-of-test files

- test/test-of-test-ratchet.test.ts records the 228 free tests that import only
  test/ code and fails on a new one, naming the owner test to extend instead;
  a stale baseline entry fails with the remove instruction.
- test/helpers/resolve-repo-path.ts is the one specifier/literal resolver for
  the ratchet and the touchfile closure invariant, with its own unit tests.
- CONTRIBUTING "Test tiers" describes the paid-failure workflow (fix, then one
  row in the detector's owner test) and the ratchet; TEST_PORTFOLIO gains the
  detector -> owner-test table and no longer claims an Autoplan chain eval.
- TODOS: automatic exclusion policy for chronically red periodic files (P3),
  the deferred native-completion table collapse, the unused CEO payment
  seeder; the PTY readiness item is narrowed to the paid runner.
- docs/test-audit-2026-09.md collects the triage, security mapping, inventories,
  selection proof, behavior-commit decisions and retained false positives.

* v1.91.8.0 test: smaller suite, derived paid selection, retired never-green evals

Release metadata for the test-reduction branch: VERSION 1.91.8.0 (1.91.7.0 is
claimed by #2983), CHANGELOG with the measured before/after table and a
contributor section, durations re-recorded on Ubicloud standard-16 (857 files,
0 failures), the agents digest, CONTRIBUTING's after-measurement row, the B8
fallback TODOS entry, and the after metrics, kept-vs-plan notes, B8 run and
census estimate in docs/test-audit-2026-09.md.

* fix(ubicloud): skip retrieval globs that match nothing instead of reporting a failed pull

* test: count issue-numbered Design findings in the UI-scope gate eval
This commit is contained in:
Garry Tan authored and GitHub committed 2026-09-29 08:58:49 -07:00
1 parent dcaea52800
commit 943105f109
668 files changed
+11998 -102381

No files matched your search

+1 -293
View File
@@ -1,298 +1,6 @@
import { expect, test } from 'bun:test';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import captured from './fixtures/eng-count-actor-491.json';
import planningCapture from './fixtures/eng-d2-planning-prelude-4d.json';
import { createEngCountActor, engCountActorRequest, ENG_COUNT_COMMITMENTS, pickEngCountQuestion } from './helpers/eng-count-question-policy';
import { capturePlanCountQuestion, nativePlanCallFingerprint, planCountQuestionInput, planCountPrerequisitePick, matchesNativePlanQuestion, runPlanSkillCounting } from './helpers/claude-pty-runner';
import type { NativeQuestion } from './helpers/plan-skill-questions';
import type { NativePlanQuestionCall } from './helpers/plan-count-transcript';
import { runPlanSkillCounting } from './helpers/claude-pty-runner';
const ROOT = path.resolve(import.meta.dir, '..');
const request = engCountActorRequest(captured.seed);
const original = (i: number) => structuredClone(captured.calls[i]!.questions[0]!) as NativeQuestion;
const commitment = (id: string) => {
const row = ENG_COUNT_COMMITMENTS.find(row => row.id === id);
if (!row) throw new Error('Unknown test catalog ID '+id);
return {label:row.label,description:row.description};
};
const question = (ids: readonly string[], source = original(0)) => ({...source, options:ids.map(commitment)});
const offered = (id: string, source = original(0)) => ({...source,options:[commitment(id),{label:'Different recommendation',description:'An arbitrary alternative; this option is not approved.'}]});
const controlled = (i: number) => {
const q=original(i);q.options[captured.controlledReplacements.replaceIndices[i]!]=commitment(captured.controlledReplacements.selectedIds[i]!);return q;
};
function pending(i = 0, q = controlled(i)): NativePlanQuestionCall {
return {...structuredClone(captured.calls[i]!), questions:[q], answered:false, failed:false,
answers:undefined, answeredAt:undefined, unansweredQuestionIndices:[0]};
}
function frame(q: NativeQuestion, packet?: NativeQuestion[], index = 0): string {
const header = packet ? `← ${packet.map((p,i) => `${i < index ? '☒' : '☐'} ${p.header}`).join(' ')} ✔ Submit →` : `☐ ${q.header}`;
return `${header}\n${q.question}\n${q.options.map((o,i) => `${i === 0 ? '❯ ' : ' '}${i+1}. ${o.label}\n ${o.description}`).join('\n')}\n ${q.options.length+1}. Type something.\n ${q.options.length+2}. Chat about this\nEnter to select · ${packet ? 'Tab/Arrow keys' : '↑/↓'} to navigate · Esc to cancel`;
}
function owned<T>(run: (cwd: string) => T): T {
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'eng-actor-owned-'));
try { fs.writeFileSync(path.join(cwd,'PLAN.md'),request); return run(cwd); }
finally { fs.rmSync(cwd, {recursive:true,force:true}); }
}
function active(call = pending()) {
return {...nativePlanCallFingerprint(call,1,false),nativeQuestionIndex:0};
}
test('original evidence retains thirteen actual option-one answers and the timeout; replacements are controlled', () => {
expect(captured.provenance.source).toBe('491566889b47a73db0f5b20799a901a80c38d756');
expect(captured.provenance.outcome).toBe('timeout');
expect(captured.provenance.noNewBehaviorCredit).toBe(true);
expect(captured.calls).toHaveLength(13);
expect(captured.calls.map(c => c.questions[0]!.options.findIndex(o => o.label === c.answers[c.questions[0]!.question]) + 1)).toEqual(Array(13).fill(1));
expect(original(10).question).toContain('This is new behavior');
expect(captured.controlledReplacements.qualification).toContain('not recovered original native calls or paid outcomes');
});
for (let i=0;i<13;i++) {
test(`original D${i+1} cannot borrow newly declared authority`,()=>expect(()=>pickEngCountQuestion(original(i))).toThrow());
test(`controlled D${i+1} replacement preserves choice intent across reorderings`,()=>{
const q=controlled(i),chosen=commitment(captured.controlledReplacements.selectedIds[i]!);
expect(q.options[pickEngCountQuestion(q)-1]).toEqual(chosen);
q.options.reverse();expect(q.options[pickEngCountQuestion(q)-1]).toEqual(chosen);
q.options=q.options.slice(1).concat(q.options[0]!);expect(q.options[pickEngCountQuestion(q)-1]).toEqual(chosen);
expect(q.question).toBe(original(i).question);
});
}
test('request keeps the entire original seed and leaves analysis, count and legacy regression evidence to the review',()=>{
expect(request.startsWith(captured.seed+'\n\n')).toBe(true);
const extra=request.slice(captured.seed.length);
expect(extra).not.toContain('legacyAuthFlow');expect(extra).not.toContain('baseline');expect(extra).not.toContain('replay');
expect(extra).toContain('does not require an item to be offered');
for(const row of ENG_COUNT_COMMITMENTS){expect(extra).toContain(JSON.stringify(row.label));expect(extra).toContain(JSON.stringify(row.description));}
expect(()=>engCountActorRequest('')).toThrow();expect(()=>engCountActorRequest(request)).toThrow();
expect(()=>createEngCountActor(captured.seed)).toThrow('declared catalog');
});
for(const row of ENG_COUNT_COMMITMENTS) for(const [name, mutate] of Object.entries({
label:(q:NativeQuestion)=>q.options[0]!.label+=' (recommended)',
whitespace:(q:NativeQuestion)=>q.options[0]!.description+=' ',
case:(q:NativeQuestion)=>q.options[0]!.label=q.options[0]!.label.toUpperCase(),
'extra state':(q:NativeQuestion)=>q.options[0]!.description+=' Add a shared pending map.',
'extra provider':(q:NativeQuestion)=>q.options[0]!.description+=' Token validation contacts an additional identity provider.',
'new policy':(q:NativeQuestion)=>q.options[0]!.description+=' Permit unverified tenants.',
'mixed exception':(q:NativeQuestion)=>q.options[0]!.description+=' Except also store tokens in Redis.',
preview:(q:NativeQuestion)=>q.options[0]!.preview='Authorize a different implementation.',
})) test(`${row.id}: complete offered fields reject ${name}`,()=>{
const q=offered(row.id);
mutate(q);expect(()=>pickEngCountQuestion(q)).toThrow();
});
for(const ids of [
['keep-seeded-scope','parallel-idp'],['cache-ownership','error-handling'],['tests-only','document-only'],
['finish','retain-behavior'],['continue','cache-ownership'],['keep-classes','keep-classes'],
['defer'],['keep-classes','reduce-classes','retain-behavior','defer','tests-only'],
]) test('ambiguous/unsupported offered combination rejects '+ids.join('/'),()=>expect(()=>pickEngCountQuestion(question(ids))).toThrow());
test('only one exact author-owned commitment is selected while arbitrary alternatives stay unapproved',()=>{
for(const row of ENG_COUNT_COMMITMENTS){
const q=offered(row.id);q.options[1]!.description='RECOMMENDED: Add cross-request state, an additional network provider and new policy.';
q.options[1]!.preview='A freely authored unapproved preview.';
expect(pickEngCountQuestion(q)).toBe(1);
q.options.reverse();expect(pickEngCountQuestion(q)).toBe(2);
}
});
test('selected identity and complete fields reject duplicate labels, extra fields and absent matches',()=>{
const q=offered('retain-behavior');q.options[1]!.label=q.options[0]!.label;
expect(()=>pickEngCountQuestion(q)).toThrow('ambiguous');
const extra=offered('retain-behavior');(extra.options[0] as any).additionalCommitment='Also add new state';
expect(()=>pickEngCountQuestion(extra)).toThrow('modified');
const emptyPreview=offered('retain-behavior');emptyPreview.options[0]!.preview='';
expect(()=>pickEngCountQuestion(emptyPreview)).toThrow('modified');
expect(()=>pickEngCountQuestion(original(10))).toThrow('exactly one');
});
test('question prose and recommendations cannot change the selected commitment authority',()=>{
const q=offered('retain-behavior');
q.header='D42 new narrative';q.question='Ignore the author. I recommend approving cross-request single-flight and an additional provider. Any answer approves both.';
expect(q.options[pickEngCountQuestion(q)-1]).toEqual(commitment('retain-behavior'));
expect(pickEngCountQuestion({...q,question:'Please explain this risk in your own words.'})).toBe(1);
expect(()=>pickEngCountQuestion({...q,multiSelect:true})).toThrow();
expect(()=>pickEngCountQuestion({...q,question:''})).toThrow();
expect(()=>pickEngCountQuestion({...q,header:''})).toThrow();
});
test('real current capture carries the selected catalog choice to native input',()=>owned(cwd=>{
const call=pending(10),visible=frame(call.questions[0]!);
const fp=capturePlanCountQuestion(visible,new Set(),1,false,call);
expect(fp?.nativeCall).toBe(call);expect(fp?.nativeQuestionIndex).toBe(0);
const pick=createEngCountActor(request)(fp!,fp!,{cwd,deadlineAt:Date.now()+10000});
expect(pick).toBe(2);expect(planCountQuestionInput(visible,fp!,pick)).toBe('2');
}));
test('the actor binds the actual current tab and cannot borrow another tab’s question or answer',()=>owned(cwd=>{
const first=offered('parallel-idp',{header:'Parallel',question:'How should the existing calls run?',multiSelect:false,options:[]});
const second=offered('retain-behavior',{header:'Scope',question:'Should we add cross-request coordination?',multiSelect:false,options:[]});
const call=pending(0,first);call.questions.push(second);
call.answers={[first.question]:first.options[0]!.label};
const visible=frame(second,call.questions,1),fp=capturePlanCountQuestion(visible,new Set(),1,false,call)!;
expect(fp.nativeCall).toBe(call);expect(fp.nativeQuestionIndex).toBe(1);
const actor=createEngCountActor(request),context={cwd,deadlineAt:Date.now()+10000};
expect(actor(fp,fp,context)).toBe(1);
expect(()=>actor(fp,{...fp,nativeQuestionIndex:0},context)).toThrow('pending native tab');
expect(()=>actor(fp,{...fp,signature:fp.signature.replace(/1$/,'0')},context)).toThrow('pending native tab');
}));
for(const [name,mutate] of Object.entries({
'missing native':(fp:any)=>delete fp.nativeCall,
'wrong signature':(fp:any)=>fp.signature='foreign:call',
'answered':(fp:any)=>fp.nativeCall.answered=true,
'failed':(fp:any)=>fp.nativeCall.failed=true,
'answered active tab':(fp:any)=>fp.nativeCall.answers={[fp.nativeCall.questions[0].question]:'answer'},
'wrong tab':(fp:any)=>fp.nativeQuestionIndex=1,
'absent tab':(fp:any)=>delete fp.nativeQuestionIndex,
'partial prompt':(fp:any)=>fp.promptSnippet=fp.promptSnippet.slice(-300),
'different options':(fp:any)=>fp.options[0].label='Approve anything',
'missing option':(fp:any)=>fp.options.pop(),
'wrong indices':(fp:any)=>fp.options[0].index=4,
'missing session':(fp:any)=>fp.nativeCall.sessionId='',
})) test('native binding rejects '+name,()=>owned(cwd=>{
const fp=active();mutate(fp);expect(()=>createEngCountActor(request)(fp,fp,{cwd,deadlineAt:Date.now()+10000})).toThrow();
}));
test('request, session, ordinary seed file and deadline remain bound',()=>owned(cwd=>{
const actor=createEngCountActor(request),fp=active(),context={cwd,deadlineAt:Date.now()+10000};
expect(actor(fp,fp,context)).toBe(1);
const other=pending(1);other.sessionId='foreign';const changed=active(other);
expect(()=>actor(changed,changed,context)).toThrow('pending native tab');
expect(()=>actor(fp,fp,{cwd,deadlineAt:Date.now()-1})).toThrow('deadline');
fs.writeFileSync(path.join(cwd,'PLAN.md'),request+'\nnew authority');expect(()=>actor(fp,fp,context)).toThrow('owned request');
fs.renameSync(path.join(cwd,'PLAN.md'),path.join(cwd,'other.md'));expect(()=>actor(fp,fp,context)).toThrow();
fs.symlinkSync('other.md',path.join(cwd,'PLAN.md'));expect(()=>actor(fp,fp,context)).toThrow('owned request');
}));
// Execute the actual loop's narrow dispatch region, with its real capture,
// prerequisite, and input functions. No model, timer, UI or acceptance mock is
// involved in proving whether it sends a key or consumes a seen fingerprint.
const runnerSource=fs.readFileSync(path.join(ROOT,'test/helpers/claude-pty-runner.ts'),'utf8');
const dispatchStart=runnerSource.indexOf(' // Dedupe the complete question, not just its answer labels:');
const dispatchEnd=runnerSource.indexOf(' // Give the agent a beat to advance to the next state.',dispatchStart);
if(dispatchStart<0 || dispatchEnd<=dispatchStart)throw Error('Missing actual counting dispatch adapter boundary');
const dispatchBody=runnerSource.slice(dispatchStart,dispatchEnd);
const dispatchFactory=new Function('capturePlanCountQuestion','nativePlanCallFingerprint','planCountPrerequisitePick','planCountQuestionInput','matchesNativePlanQuestion','path',
new Bun.Transpiler({loader:'ts'}).transformSync(`return async function(opts,frames,pickerContext){
const seen=new Set(),sent=[],checkpoints=[];let isFirstAUQ=true;const startedAt=Date.now(),boundaryFired=false;
const defaultPick=opts.defaultPick??1,remainingWork=()=>10000;
const session={send:key=>sent.push(key),hermeticConfigDir:opts.hermeticConfigDir??null};const selectPtyNumberedOption=async(s,pick)=>s.send(String(pick)+'\\r');
const planningDirectory=session.hermeticConfigDir?path.join(session.hermeticConfigDir,'plans'):undefined;
for(const state of frames){const {visible,pending}=state;const newlyMatched=pending&&matchesNativePlanQuestion(visible,pending,planningDirectory);checkpoints.push({seen:seen.size,sent:sent.length});
${dispatchBody}
}
return {sent,seen:[...seen],checkpoints};
}`));
const drive=dispatchFactory(capturePlanCountQuestion,nativePlanCallFingerprint,planCountPrerequisitePick,planCountQuestionInput,matchesNativePlanQuestion,path);
const shortQuestion=(id:string)=>offered('parallel-idp',{header:id,question:'Explain the existing request behavior for '+id+'?',multiSelect:false,options:[]});
for (const config of [planningCapture.pendingRecord.configDir, '/tmp/foreign/.claude', undefined])
test('actual Eng dispatch requires the session planning directory: '+String(config), async()=>{
const record=structuredClone(planningCapture.pendingRecord.pending);
const call={sessionId:record.sessionId,toolUseId:record.toolUseId,questions:record.questions,answered:false,failed:false};
let calls=0;
const result=await drive({hermeticConfigDir:config,requireNativePicker:true,pickAUQ:(_fp,active)=>{
calls++;expect(active.nativeCall).toBe(call);return pickEngCountQuestion(call.questions[active.nativeQuestionIndex]);
}},[{visible:planningCapture.screen,pending:call},{visible:planningCapture.screen,pending:call}],{});
const owned=config===planningCapture.pendingRecord.configDir;
expect(calls).toBe(owned?1:0);expect(result.sent).toEqual(owned?['1']:[]);
expect(result.seen.length>0).toBe(owned);
});
test('opt-in unbound multi-tab redraw waits without calling picker or consuming seen state, then answers matched render',async()=>{
const first=shortQuestion('First'),second=shortQuestion('Second');const call=pending(0,first);call.questions.push(second);
let calls=0;
const result=await drive({requireNativePicker:true,pickAUQ:()=>{calls++;return 2;}},[
{visible:frame(first),pending:call}, {visible:frame(first,call.questions),pending:call},
],{cwd:'unused',deadlineAt:Date.now()+10000});
expect(result.checkpoints).toEqual([{seen:0,sent:0},{seen:0,sent:0}]);expect(calls).toBe(1);expect(result.sent).toEqual(['2']);
expect(result.seen).toContain(`${call.sessionId}:${call.toolUseId}:question:0`);
});
test('absent native identity and stale single-question render cannot invoke the required actor',async()=>{
const q=shortQuestion('Current'),other=shortQuestion('Foreign'),call=pending(0,q);let calls=0;
const result=await drive({requireNativePicker:true,pickAUQ:()=>{calls++;return 1;}},[
{visible:frame(q)}, {visible:frame(other),pending:call},
],{});
expect(calls).toBe(0);expect(result.sent).toEqual([]);expect(result.seen).toEqual([]);
});
for(const value of [null,undefined])test('bound required picker cannot fall through on '+String(value),async()=>{
const q=shortQuestion('Current'),call=pending(0,q);let calls=0;
await expect(drive({requireNativePicker:true,pickAUQ:()=>{calls++;return value;}},[{visible:frame(q),pending:call}],{})).rejects.toThrow('no authorized choice');
expect(calls).toBe(1);
});
test('the default multi-tab fallback remains unchanged when opt-in is absent',async()=>{
const q=shortQuestion('First'),call=pending(0,q);call.questions.push(shortQuestion('Second'));let calls=0;
const result=await drive({pickAUQ:()=>{calls++;return 2;}},[{visible:frame(q),pending:call}],{});
expect(calls).toBe(0);expect(result.sent).toEqual(['1']);expect(result.seen.length).toBeGreaterThan(0);
});
test('declared optional prerequisite decline precedes catalog authority only on its matched native tab',async()=>{
const q:NativeQuestion={header:'Office hours',question:'There is no design doc. Run /office-hours or proceed?',multiSelect:false,
options:[{label:'Run /office-hours first',description:'Produce a design doc.'},{label:'Skip — standard review',description:'Proceed with the supplied plan.'}]};
const call=pending(0,q);let calls=0;
const result=await drive({requireNativePicker:true,pickAUQ:()=>{calls++;throw Error('not the catalog');}},[{visible:frame(q),pending:call}],{});
expect(calls).toBe(0);expect(result.sent).toEqual(['2']);
});
test('opt-in requires a picker before creating any native fixture',async()=>{
await expect(runPlanSkillCounting({requireNativePicker:true} as any)).rejects.toThrow('requires a declared picker');
});
for(const scenario of ['controlled','original-d11','modified-choice'] as const)test('actual registration declares the finite actor and unchanged terminal budget: '+scenario,async()=>{
const temp=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'eng-catalog-registration-')));
const script=path.join(temp,'registered.test.ts'),factsPath=path.join(temp,'facts.json');
const helper=(name:string)=>path.join(ROOT,'test/helpers',name);
fs.writeFileSync(script,`
import {describe,expect,mock} from 'bun:test';import * as fs from 'node:fs';import * as path from 'node:path';
import captured from ${JSON.stringify(path.join(ROOT,'test/fixtures/eng-count-actor-491.json'))};
import oldTerminal from ${JSON.stringify(path.join(ROOT,'test/fixtures/eng-fb10-count-public.json'))};
import {ENG_COUNT_COMMITMENTS} from ${JSON.stringify(helper('eng-count-question-policy.ts'))};
import * as imported from ${JSON.stringify(helper('claude-pty-runner.ts'))};const actual={...imported};
const facts={actors:0,judges:0,answers:[],required:false,originalSeed:false,report:''};
const save=()=>fs.writeFileSync(${JSON.stringify(factsPath)},JSON.stringify(facts));
const source=fs.readFileSync(${JSON.stringify(path.join(ROOT,'test/skill-e2e-plan-eng-finding-count.test.ts'))},'utf8');
const terminator=${JSON.stringify("].join('\\n');")};
const a=source.indexOf('const planEng5Findings = '),b=source.indexOf(terminator,a);
if(a<0||b<=a)throw Error('Missing actual original-seed builder');
const seed=new Function(new Bun.Transpiler({loader:'ts'}).transformSync(source.slice(a,b+terminator.length))+';return planEng5Findings;')();
mock.module(${JSON.stringify(helper('e2e-gate.ts'))},()=>({describeE2ETier:t=>{expect(t).toBe('periodic');return describe;}}));
mock.module(${JSON.stringify(helper('eng-seeded-coverage.ts'))},()=>({evaluateEngTerminalReview:async(plan,input)=>{
facts.judges++;facts.originalSeed=plan===seed(facts.report);save();expect(facts.originalSeed).toBe(true);
expect(plan).not.toContain('Declared review actor interface');expect(input.deadlineAt).toBeLessThanOrEqual(Date.now()+1_500_000);
return {administrativeCallIds:[],substantiveCallIds:[]};
}}));
mock.module(${JSON.stringify(helper('claude-pty-runner.ts'))},()=>({...actual,runPlanSkillCounting:async opts=>{
facts.actors++;facts.required=opts.requireNativePicker;facts.report=opts.expectedPlanPath;save();
expect(opts.requireNativePicker).toBe(true);expect(opts.observeSetupQuestions).toBe(true);expect(opts.preconfiguredReviewActor).toBe(true);
expect(opts.defaultPick).toBeUndefined();expect(opts.model).toBeUndefined();expect(opts.reviewCountCeiling).toBe(Infinity);
expect(opts.timeoutMs).toBeLessThanOrEqual(1_500_000);expect(opts.timeoutMs).toBeGreaterThan(1_499_000);
expect(opts.env).toEqual({QUESTION_TUNING:'false',EXPLAIN_LEVEL:'default'});
const original=seed(opts.expectedPlanPath);expect(opts.followUpPrompt.startsWith(original+'\\n\\n')).toBe(true);
fs.writeFileSync(${JSON.stringify(path.join(temp,'PLAN.md'))},opts.followUpPrompt);
for(let i=0;i<13;i++){
const call=structuredClone(captured.calls[i]);call.answered=false;call.failed=false;delete call.answers;delete call.answeredAt;
const q=call.questions[0];
if(${JSON.stringify(scenario)}!=='original-d11'||i!==10){const r=ENG_COUNT_COMMITMENTS.find(row=>row.id===captured.controlledReplacements.selectedIds[i]);q.options[captured.controlledReplacements.replaceIndices[i]]={label:r.label,description:r.description};}
if(${JSON.stringify(scenario)}==='modified-choice'&&i===0)q.options[0].description+=' Contact another provider.';
const screen='☐ '+q.header+'\\n'+q.question+'\\n'+q.options.map((o,j)=>(j===0?'❯ ':' ')+(j+1)+'. '+o.label+'\\n '+o.description).join('\\n')+'\\n '+(q.options.length+1)+'. Type something.\\n '+(q.options.length+2)+'. Chat about this\\nEnter to select · ↑/↓ to navigate · Esc to cancel';
const fp=actual.capturePlanCountQuestion(screen,new Set(),1,false,call);expect(fp?.nativeCall).toBe(call);
const picked=opts.pickAUQ(fp,fp,{cwd:${JSON.stringify(temp)},deadlineAt:Date.now()+10000});facts.answers.push({i,picked,label:q.options[picked-1].label});save();
}
const report=oldTerminal.report.replace('| Review | Skill | Runs | Status | Last run | Notes |','| Review | Trigger | Runs | Status | Why | Findings |');
fs.writeFileSync(opts.expectedPlanPath,report);
await opts.evaluateTerminal({transcript:{status:'ready',calls:[],assistantMessages:[]},report,reportMtimeMs:Date.now(),startedAt:Date.now(),finishedAt:Date.now(),deadlineAt:Date.now()+1_500_000});
return {outcome:'plan_ready',elapsedMs:1,step0Count:0,reviewCount:4,fingerprints:[],transcript:{status:'ready',calls:[],assistantMessages:[]},evidence:'controlled callback transport, no behavioral credit'};
}}));
await import(${JSON.stringify(path.join(ROOT,'test/skill-e2e-plan-eng-finding-count.test.ts'))});
`);
try{
const child=Bun.spawn([process.execPath,'test',script],{cwd:ROOT,stdout:'pipe',stderr:'pipe',timeout:10000,
env:{PATH:process.env.PATH??'',HOME:temp,TMPDIR:temp,TEMP:temp,TMP:temp,EVALS_HERMETIC:'1',GIT_CONFIG_NOSYSTEM:'1'}});
const [out,err,code]=await Promise.all([new Response(child.stdout).text(),new Response(child.stderr).text(),child.exited]);
expect(fs.existsSync(factsPath),out+'\n'+err).toBe(true);
const facts=JSON.parse(fs.readFileSync(factsPath,'utf8'));
expect(code,out+'\n'+err).toBe(scenario==='controlled'?0:1);expect(facts.actors).toBe(1);expect(facts.required).toBe(true);
expect(facts.answers).toHaveLength(scenario==='controlled'?13:scenario==='original-d11'?10:0);
expect(facts.judges).toBe(scenario==='controlled'?1:0);
if(scenario==='controlled'){expect(facts.originalSeed).toBe(true);expect(facts.answers[10].label).toBe('Keep current behavior');}
else expect(err).toContain('exactly one complete author-owned offered commitment');
expect(fs.existsSync(facts.report)).toBe(false);
}finally{fs.rmSync(temp,{recursive:true,force:true});}
});