Skip to content

Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA

TypeScript
23.5 KB
Raw Blame
import { afterAll, beforeAll, 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 { spawnSync } from 'node:child_process';
import { buildRunManifest, collectPaidTestFiles, shardCaseId, shardTrial, type PaidRunManifest, type SliceResult } from '../scripts/test-paid-shards';
import { STRICT_RETRY_CASE_BUDGETS } from './helpers/eval-budgets';
import { manualReviewFixture } from './helpers/manual-judge-review-fixture';

const ROOT = path.resolve(import.meta.dir, '..');
type Step = { uses?: string; run?: string; if?: string; with?: Record<string, unknown> };
type Job = {
  needs?: string | string[];
  if?: string;
  container?: unknown;
  permissions: Record<string, string>;
  steps: Step[];
};
/** A passing trial record for an isolated trial shard (the executor's current result schema). */
const trialRecord = (entry: PaidRunManifest['entries'][number]) => entry.trial ? { trial: {
  case: shardCaseId(entry.file)!, trial: shardTrial(entry.file)!, ...entry.trial, outcome: 'passed' as const, cost_usd: 0, duration_ms: 1,
} } : {};

const workflows = ['evals.yml', 'evals-periodic.yml'].map(name => ({
  name,
  jobs: (Bun.YAML.parse(fs.readFileSync(path.join(ROOT, '.github/workflows', name), 'utf8')) as {
    jobs: Record<string, Job>;
  }).jobs,
}));

describe('paid CI coordination stays off the eval image', () => {
  test('the actual planner and reporter load from a checkout without installed packages', () => {
    const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'paid-offline-'));
    const listed = spawnSync('git', ['ls-files', '-z'], { cwd: ROOT, encoding: 'utf8', timeout: 5_000 });
    expect(listed.status, listed.stderr).toBe(0);
    try {
      for (const relative of listed.stdout.split('\0').filter(Boolean)) {
        const source = path.join(ROOT, relative);
        const destination = path.join(directory, relative);
        fs.mkdirSync(path.dirname(destination), { recursive: true });
        expect(fs.realpathSync(path.dirname(destination)).startsWith(fs.realpathSync(directory) + path.sep)
          || fs.realpathSync(path.dirname(destination)) === fs.realpathSync(directory)).toBe(true);
        if (fs.lstatSync(source).isSymbolicLink()) fs.symlinkSync(fs.readlinkSync(source), destination);
        else fs.copyFileSync(source, destination);
      }
      const env = { ...process.env, ANTHROPIC_API_KEY: undefined, EVALS: undefined, EVALS_ALL: undefined,
        EVALS_PROFILE: 'pr', EVALS_TIER: 'gate' };
      for (const args of [['init', '-b', 'main'], ['add', '-A'], ['commit', '-m', 'Seed offline planner fixture'], ['checkout', '-b', 'fixture-head']]) {
        const git = spawnSync('git', args, { cwd: directory, env, encoding: 'utf8', timeout: 15_000 });
        expect(git.status, git.stderr).toBe(0);
      }
      fs.appendFileSync(path.join(directory, '.github/workflows/evals.yml'), '\n');
      const report = path.join(directory, 'report');
      const plan = spawnSync(process.execPath, ['--no-install', 'run', 'scripts/test-paid-shards.ts', '--tier', 'gate',
        '--emit-plan', path.join(report, 'manifest.json'), '--slices', '6'], { cwd: directory, env, encoding: 'utf8', timeout: 15_000 });
      expect(plan.status, plan.stdout + plan.stderr).toBe(0);
      const manifest = JSON.parse(fs.readFileSync(path.join(report, 'manifest.json'), 'utf8'));
      expect(manifest.sliceCount).toBe(6);
      expect(manifest.entries.some((entry: any) => entry.status === 'planned')).toBe(true);
      const reconcile = spawnSync(process.execPath, ['--no-install', 'run', 'scripts/test-paid-shards.ts', '--tier', 'gate',
        '--report', report], { cwd: directory, env, encoding: 'utf8', timeout: 15_000 });
      expect(reconcile.status, reconcile.stdout + reconcile.stderr).toBe(1);
      expect(reconcile.stdout).toContain('report: 0/6 slices');
      expect(reconcile.stderr.match(/slice \d\/6 reported NO result/g)).toHaveLength(6);
      expect(reconcile.stderr).not.toContain('Cannot find module');
      expect(fs.existsSync(path.join(directory, 'node_modules'))).toBe(false);
      const provider = spawnSync(process.execPath, ['--no-install', '-e', 'import "./test/helpers/llm-judge.ts"'],
        { cwd: directory, env, encoding: 'utf8', timeout: 15_000 });
      expect(provider.status).toBe(1);
      expect(provider.stderr).toContain("Cannot find module '@anthropic-ai/sdk'");
    } finally { fs.rmSync(directory, { recursive: true, force: true }); }
  }, 60_000);

  for (const { name, jobs } of workflows) {
    test(`${name}: planning is independent of image startup and has no dependency install`, () => {
      const planner = jobs['plan-slices'];
      if (name === 'evals.yml') {
        // The PR lane plans after its three tiny coordination jobs (route, readiness, base-ref receipt recovery), never after the image.
        expect(planner.needs).toEqual(['readiness', 'recover-receipts', 'route']);
        for (const id of ['readiness', 'recover-receipts', 'route']) {
          const job = jobs[id] as Job & { 'runs-on'?: string };
          expect(job.container, id).toBeUndefined();
          expect(job['runs-on'], id).toBe('ubuntu-24.04');
          expect(job.needs ?? [], id).not.toContain('build-image');
          expect(JSON.stringify(job.steps), id).not.toMatch(/secrets\.|restore-deps|bun install|bun run build/);
        }
      } else {
        expect(planner.needs).toBeUndefined();
      }
      expect(planner.container).toBeUndefined();
      expect(planner.permissions).toEqual({ contents: 'read' });
      const checkout = planner.steps.find(step => step.uses?.startsWith('actions/checkout@'))!;
      expect(checkout.with?.['persist-credentials']).toBe(false);
      if (name === 'evals.yml') expect(checkout.with?.['fetch-depth']).toBe(0);
      const setup = planner.steps.find(step => step.uses?.startsWith('oven-sh/setup-bun@'))!;
      expect(setup.with?.['bun-version']).toBe('1.4.2');
      expect(JSON.stringify(planner)).not.toMatch(/secrets\.|restore-deps|bun install|bun run build/);
      expect(planner.steps.find(step => step.run?.includes('--emit-plan'))?.run).toContain('bun --no-install run');
    });

    test(`${name}: cancel-in-progress can stop every job (no job-level always())`, () => {
      for (const [id, job] of Object.entries(jobs)) {
        const condition = String((job as { if?: unknown }).if ?? '');
        expect(`${id}: ${condition}`).not.toMatch(/(^|[^!])always\(\)/);
      }
    });

    test(`${name}: executors still require both prerequisites and consume the image`, () => {
      const executor = jobs['eval-slices'];
      expect(executor.needs).toEqual(['build-image', 'plan-slices']);
      expect(JSON.stringify(executor.container)).toContain('needs.build-image.outputs.image-tag');
      if (name === 'evals.yml') {
        // A confirmed verdict reuse (R2a/R2) is the one PR run that executes no slice.
        expect(executor.if).toBe("${{ !cancelled() && needs.build-image.result == 'success' && needs.plan-slices.result == 'success' && needs.plan-slices.outputs.gate_reuse != 'true' }}");
      } else {
        // A census-only run (monthly cron or census_arms dispatch) executes no periodic slice.
        expect(executor.if).toBe("${{ needs.plan-slices.outputs.periodic_lane == 'true' }}");
      }
      expect(executor.steps.some(step => step.run === 'bun run build')).toBe(true);
      expect(executor.steps.some(step => step.uses === './.github/actions/restore-deps')).toBe(true);
    });

    test(`${name}: report still reconciles failed executors without installing dependencies`, () => {
      const report = jobs[name === 'evals.yml' ? 'slices-report' : 'report'];
      expect(report.container).toBeUndefined();
      expect(report.needs).toContain('plan-slices');
      expect(report.needs).toContain('eval-slices');
      expect(report.if).toBe("${{ !cancelled() && needs.plan-slices.result == 'success' }}");
      expect(JSON.stringify(report.steps)).not.toMatch(/restore-deps|bun install/);
      expect(report.steps.find(step => step.run?.includes('--report'))?.run).toContain('bun --no-install run');
      if (name === 'evals.yml') expect(report.permissions).toEqual({ contents: 'read' });
    });

    test(`${name}: shard logs include the hidden spool directory without uploading the rest of the cache`, () => {
      const logs = jobs['eval-slices'].steps.find(step => step.with?.name === 'paid-logs-slice-${{ matrix.slice }}-a${{ github.run_attempt }}');
      expect(logs?.uses).toStartWith('actions/upload-artifact@');
      // A failed trial no longer reds its runner; its log is still the evidence.
      expect(logs?.if).toBe('always()');
      expect(logs?.with?.['include-hidden-files']).toBe(true);
      expect(String(logs?.with?.path).trim().split('\n')).toEqual([
        '/home/runner/.cache/gstack-paid-shard-*.log',
        '/tmp/gstack-paid-shard-*.log',
      ]);
      const hiddenUploads = Object.values(jobs).flatMap(job => job.steps).filter(step => step.with?.['include-hidden-files']);
      const captures = hiddenUploads.filter(step => step.with?.name === 'native-captures-${{ env.EVALS_RUN_ID }}');
      // evals-periodic's host-run Codex job mounts $RUNNER_TEMP/eval-home as the container's HOME.
      const hostHome = (pattern: string) => pattern.replace('${{ runner.temp }}/eval-home/', '~/');
      // evals.yml: eval-slices, the rule-16 eval-rerun and train-bisect (GSTA-49 T1b), each under its own EVALS_RUN_ID.
      expect(captures).toHaveLength(name === 'evals.yml' ? 3 : name === 'evals-periodic.yml' ? 3 : 2);
      for (const capture of captures) {
        expect(capture.if).toBe('always()');
        expect(String(capture.with?.path).trim().split('\n').map(hostHome)).toEqual([
          '~/.gstack/projects/*/e2e-runs', '~/.gstack/projects/*/evals/qa-callers',
          '~/.gstack-dev/e2e-runs', '~/.gstack-dev/evals/qa-callers',
        ]);
      }
      const codexLogs = name === 'evals-periodic.yml'
        ? jobs['eval-codex-slices'].steps.find(step => step.with?.name === 'paid-logs-slice-${{ matrix.slice }}-a${{ github.run_attempt }}') : undefined;
      if (codexLogs) {
        expect(codexLogs.if).toBe('always()');
        // The container sets TMPDIR under HOME, so shard logs land in the mounted HOME's cache.
        expect(String(codexLogs.with?.path).trim().split('\n').map(hostHome)).toEqual(['~/.cache/gstack-paid-shard-*.log']);
      }
      // GSTA-49 T1b: train-bisect keeps the same shard-log upload under its own name.
      const bisectLogs = name === 'evals.yml'
        ? jobs['train-bisect'].steps.find(step => step.with?.name === 'train-bisect-logs-${{ matrix.slice }}-a${{ github.run_attempt }}') : undefined;
      if (name === 'evals.yml') expect(String(bisectLogs?.with?.path)).toBe(String(logs?.with?.path));
      // F1: the rule-16 eval-rerun keeps the same shard-log upload under its own name.
      const rerunLogs = name === 'evals.yml'
        ? jobs['eval-rerun'].steps.find(step => step.with?.name === 'rerun-logs-${{ matrix.slice }}-a${{ github.run_attempt }}') : undefined;
      if (name === 'evals.yml') expect(String(rerunLogs?.with?.path)).toBe(String(logs?.with?.path));
      expect(hiddenUploads.filter(step => !captures.includes(step))).toEqual([logs!, ...(codexLogs ? [codexLogs] : []), ...(rerunLogs ? [rerunLogs] : []), ...(bisectLogs ? [bisectLogs] : [])]);
    });
  }

  test('PR planning preserves the fork and Dependabot trust boundaries across the coordination jobs', () => {
    const jobs = workflows[0].jobs;
    const trust = "github.actor != 'dependabot[bot]' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)";
    // !cancelled() lets planning proceed when readiness was skipped (dispatch) or recovery was skipped or failed (reuse is then off);
    // a readiness failure (Free Tests red on this head) or a superseded head plans nothing; the trust clause still gates it.
    // GSTA-49 T1b: the route job must have succeeded and named a planned mode (pr, screen, train, dispatch); a superseded screen plans nothing.
    const route = "needs.route.result == 'success' && needs.route.outputs.superseded != 'true' && contains(fromJSON('[\"pr\",\"screen\",\"train\",\"dispatch\"]'), needs.route.outputs.mode)";
    expect(jobs['plan-slices'].if).toBe(`\${{ !cancelled() && (needs.readiness.result == 'success' || needs.readiness.result == 'skipped') && needs.readiness.outputs.superseded != 'true' && ${route} && ${trust} }}`);
    // The coordination jobs never run for Dependabot or for a fork PR either (recovery also serves an explicit pr_receipts dispatch).
    expect(jobs.readiness.if).toContain("github.actor != 'dependabot[bot]'");
    expect(jobs.readiness.if).toContain("github.event_name == 'pull_request'");
    expect(jobs.readiness.if).toContain('github.event.pull_request.head.repo.full_name == github.repository');
    expect(jobs['recover-receipts'].if).toContain("github.actor != 'dependabot[bot]'");
    expect(jobs['recover-receipts'].if).toContain("(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository");
    expect(jobs['recover-receipts'].if).toContain("(github.event_name == 'workflow_dispatch' && inputs.pr_receipts != '')");
    // Only recovery holds actions: read, and it runs base-ref code; the planner keeps contents: read.
    expect(jobs['recover-receipts'].permissions).toEqual({ contents: 'read', actions: 'read' });
    expect(jobs['plan-slices'].permissions).toEqual({ contents: 'read' });
  });
});

describe('dependency-free CI planner and report execution', () => {
  let fixture: string;

  beforeAll(() => {
    fixture = fs.mkdtempSync(path.join(os.tmpdir(), 'ci-paid-coordination-'));
    const sourceOnly = { recursive: true, filter: (file: string) => path.basename(file) !== 'node_modules' };
    fs.cpSync(path.join(ROOT, 'scripts'), path.join(fixture, 'scripts'), sourceOnly);
    fs.cpSync(path.join(ROOT, 'test/helpers'), path.join(fixture, 'test/helpers'), sourceOnly);
    expect(fs.readFileSync(path.join(fixture, 'test/helpers/llm-judge.ts'), 'utf8'))
      .toBe(fs.readFileSync(path.join(ROOT, 'test/helpers/llm-judge.ts'), 'utf8'));
    fs.cpSync(path.join(ROOT, 'lib'), path.join(fixture, 'lib'), sourceOnly);
    fs.cpSync(path.join(ROOT, 'crew'), path.join(fixture, 'crew'), sourceOnly);
    expect(fs.existsSync(path.join(fixture, 'lib/diagram-render/node_modules'))).toBe(false);
    for (const file of collectPaidTestFiles()) {
      fs.copyFileSync(path.join(ROOT, file), path.join(fixture, file));
    }
  });

  afterAll(() => {
    fs.rmSync(fixture, { recursive: true, force: true });
  });

  function run(args: string[], tier: string, env: NodeJS.ProcessEnv = {}) {
    return spawnSync(process.execPath, ['--no-install', 'run', 'scripts/test-paid-shards.ts', '--tier', tier, ...args], {
      cwd: fixture,
      env: { PATH: '', HOME: fixture, EVALS_ALL: '1', EVALS_TIER: tier, ...env },
      encoding: 'utf8',
      timeout: 10_000,
    });
  }

  test('diff-selected host planning matches the same checkout with no installed dependencies', () => {
    const git = Bun.which('git')!;
    const gitDir = spawnSync(git, ['rev-parse', '--absolute-git-dir'], { cwd: ROOT, encoding: 'utf8', timeout: 10_000 });
    expect(gitDir.status).toBe(0);
    const manifestPath = path.join(fixture, 'diff-manifest.json');
    const env = { EVALS_ALL: '', EVALS_BASE: 'HEAD' };
    const planned = run(['--emit-plan', manifestPath, '--slices', '6'], 'gate', {
      ...env,
      PATH: path.dirname(git),
      GIT_DIR: gitDir.stdout.trim(),
      GIT_WORK_TREE: ROOT,
    });
    expect(planned.status, planned.stderr).toBe(0);
    const manifest: PaidRunManifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
    expect(manifest).toEqual(buildRunManifest({ tier: 'gate', sliceCount: 6, evalsAll: false, env }));
    expect(manifest.evalsAll).toBe(false);
  });

  for (const tier of ['gate', 'periodic'] as const) {
    test(`${tier}: host planner preserves the complete manifest and report fails closed`, () => {
      const sliceCount = tier === 'gate' ? 6 : 7;
      const reportDir = path.join(fixture, tier);
      const manifestPath = path.join(reportDir, 'manifest.json');
      const planned = run(['--emit-plan', manifestPath, '--slices', String(sliceCount)], tier);
      expect(planned.error).toBeUndefined();
      expect(planned.status, planned.stderr).toBe(0);
      const manifest: PaidRunManifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
      expect(manifest).toEqual(buildRunManifest({
        tier, sliceCount, evalsAll: true, env: { EVALS_ALL: '1' },
      }));
      expect(manifest.entries.filter(entry => entry.status === 'planned').length).toBeGreaterThan(0);
      expect(fs.existsSync(path.join(fixture, 'node_modules'))).toBe(false);
      for (let sliceIndex = 1; sliceIndex <= sliceCount; sliceIndex++) {
        const result: SliceResult = {
          version: 1, tier, sliceIndex, sliceCount,
          outcomes: manifest.entries.filter(entry => entry.status === 'planned' && entry.slice === sliceIndex).map(entry => ({
            files: [entry.file], status: 'passed', exitCode: 0, elapsedMs: 1,
            executedTests: STRICT_RETRY_CASE_BUDGETS.find(budget => budget.file === entry.file)?.cases ?? 1,
            skippedTests: 0,
            ...(entry.budget ? { budget: entry.budget } : {}),
            ...trialRecord(entry),
          })),
        };
        fs.writeFileSync(path.join(reportDir, `slice-${sliceIndex}.json`), JSON.stringify(result));
      }
      const clean = run(['--report', reportDir], tier);
      expect(clean.status, clean.stderr).toBe(0);
      expect(clean.stdout).toContain('every planned shard accounted and passed');

      const lastSlice = path.join(reportDir, `slice-${sliceCount}.json`);
      const saved = fs.readFileSync(lastSlice, 'utf8');
      fs.rmSync(lastSlice);
      const missing = run(['--report', reportDir], tier);
      expect(missing.status).toBe(1);
      expect(missing.stderr).toContain(`slice ${sliceCount}/${sliceCount} reported NO result`);

      const failed: SliceResult = JSON.parse(saved);
      expect(failed.outcomes.length).toBeGreaterThan(0);
      failed.outcomes[0].status = 'failed';
      failed.outcomes[0].exitCode = 1;
      fs.writeFileSync(lastSlice, JSON.stringify(failed));
      fs.writeFileSync(path.join(reportDir, 'retry-results.json'), JSON.stringify({
        tests: [
          { name: 'recovered', passed: false }, { name: 'recovered', passed: true },
          { name: 'exhausted', passed: false }, { name: 'exhausted', passed: false },
          { name: 'regressed', passed: true }, { name: 'regressed', passed: false },
        ],
        flaky_retries: ['recovered', 'exhausted', 'regressed'].map(name => ({ name, attempts: 2 })),
      }));
      const red = run(['--report', reportDir], tier);
      expect(red.status).toBe(1);
      expect(red.stderr).toContain(`${failed.outcomes[0].files[0]}: failed`);
      // Paid evals never retry: every record counts, a later pass never hides an earlier failure.
      expect(red.stdout).toContain('6 executed, 0 reused; 2 passed, 4 failed, 0 manual accepted (unscored; no score-cache credit) (6 attempt records from 1 collectors');
      expect(red.stdout).toContain('3 cases with multiple attempts this run:');
      expect(red.stdout).not.toMatch(/passed only on retry|not blocking/);

      fs.writeFileSync(manifestPath, '{');
      const corrupt = run(['--report', reportDir], tier);
      expect(corrupt.status).toBe(1);
    });
  }

  test('report rejects every manual-review claim, preserves attempts, and never masks a failed shard', () => {
    const reportDir = path.join(fixture, 'manual-report');
    const manifestPath = path.join(reportDir, 'manifest.json');
    const planned = run(['--emit-plan', manifestPath, '--slices', '1'], 'gate');
    expect(planned.status, planned.stderr).toBe(0);
    const manifest: PaidRunManifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
    const slice: SliceResult = {
      version: 1, tier: 'gate', sliceIndex: 1, sliceCount: 1,
      outcomes: manifest.entries.filter(entry => entry.status === 'planned').map(entry => ({
        files: [entry.file], status: 'passed', exitCode: 0, elapsedMs: 1,
        executedTests: STRICT_RETRY_CASE_BUDGETS.find(budget => budget.file === entry.file)?.cases ?? 1,
        skippedTests: 0, ...(entry.budget ? { budget: entry.budget } : {}), ...trialRecord(entry),
      })),
    };
    const slicePath = path.join(reportDir, 'slice-1.json');
    const collectorPath = path.join(reportDir, 'judge-results.json');
    const summaryPath = path.join(reportDir, 'collector-outcomes.json');
    const receipt = manualReviewFixture();
    const executed = { name: 'executed', suite: 'other', passed: true, execution: 'executed' };
    const reused = { name: 'automated', suite: 'other', passed: true, execution: 'reused' };
    const write = (tests: unknown[]) => fs.writeFileSync(collectorPath, JSON.stringify({
      total_tests: tests.length, tier: 'llm-judge', shard: 1, total_cost_usd: 0,
      tests, flaky_retries: [{ name: executed.name, attempts: tests.length }],
    }));
    fs.writeFileSync(slicePath, JSON.stringify(slice));
    write([receipt, reused]);
    const retired = run(['--report', reportDir], 'gate');
    expect(retired.status).toBe(1);
    expect(retired.stderr).toContain('attempt 1: manual-review claims were retired with the workflow judges');
    expect(fs.existsSync(summaryPath)).toBe(false);

    write([executed, { ...receipt, passed: true }]);
    const forgedPass = run(['--report', reportDir], 'gate');
    expect(forgedPass.status).toBe(1);
    expect(forgedPass.stderr).toContain('attempt 2: manual-review claims were retired with the workflow judges');
    expect(fs.existsSync(summaryPath)).toBe(false);

    write([executed, reused]);
    const clean = run(['--report', reportDir], 'gate');
    expect(clean.status, clean.stderr).toBe(0);
    expect(clean.stdout).toContain('2 passed, 0 failed, 0 manual accepted (unscored; no score-cache credit) (2 attempt records');
    const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8'));
    expect(summary.totals).toEqual({ executed: 1, reused: 1, passed: 2, failed: 0,
      manual_accepted: 0, attempts: 2, total: 2, flaky: 1 });
    expect(summary.files[0]).toMatchObject({ file: 'judge-results.json', total: 2, manual_accepted: 0, passed: 2 });

    write([executed, { name: 'unapproved', passed: false, execution: 'executed' }]);
    const failedCollector = run(['--report', reportDir], 'gate');
    expect(failedCollector.status).toBe(1);
    expect(failedCollector.stderr).toContain('1 unapproved final collector failure(s)');
    expect(JSON.parse(fs.readFileSync(summaryPath, 'utf8')).totals).toMatchObject({ failed: 1, passed: 1 });

    write([executed, { passed: true }]);
    const missingName = run(['--report', reportDir], 'gate');
    expect(missingName.status).toBe(1);
    expect(missingName.stderr).toContain('attempt 2: malformed collector entry (name/passed required)');
    expect(fs.existsSync(summaryPath)).toBe(false);
    write([executed, { name: 'malformed', passed: 'true' }]);
    const malformedPassed = run(['--report', reportDir], 'gate');
    expect(malformedPassed.status).toBe(1);
    expect(malformedPassed.stderr).toContain('attempt 2: malformed collector entry (name/passed required)');
    expect(fs.existsSync(summaryPath)).toBe(false);

    write([executed, reused]);

    slice.outcomes[0].status = 'failed';
    slice.outcomes[0].exitCode = 1;
    fs.writeFileSync(slicePath, JSON.stringify(slice));
    const failedShard = run(['--report', reportDir], 'gate');
    expect(failedShard.status).toBe(1);
    expect(failedShard.stderr).toContain(`${slice.outcomes[0].files[0]}: failed`);
    expect(JSON.parse(fs.readFileSync(summaryPath, 'utf8')).totals.passed).toBe(2);
  });
});