Files
gstack/test/e2e-harness-audit.test.ts
T
Garry Tan d46a83b2e1 test: plan-mode handshake E2E coverage and unit assertions
Adds 6 E2E test files and 8 new unit assertions to verify the plan-mode
handshake works end-to-end and stays correct under regeneration.

E2E tests (gate-tier, paid, EVALS=1 EVALS_TIER=gate):
- test/skill-e2e-plan-ceo-plan-mode.test.ts — handshake fires before any
  Write/Edit when plan-mode distinctive phrase is present; 2-option shape
  (Exit/Cancel); option A routes to ExitPlanMode cleanly
- test/skill-e2e-plan-eng-plan-mode.test.ts — same contract for plan-eng
- test/skill-e2e-plan-design-plan-mode.test.ts — same contract for
  plan-design; exercises C-cancel branch instead of A-exit
- test/skill-e2e-plan-devex-plan-mode.test.ts — same contract for plan-devex
- test/skill-e2e-plan-mode-no-op.test.ts — negative regression: handshake
  must NOT fire when distinctive phrase is absent; skill proceeds normally
  through Step 0 (REGRESSION RULE guardrail against breaking existing
  interactive-review sessions)
- test/e2e-harness-audit.test.ts — free unit test asserting every
  `interactive: true` skill has at least one canUseTool-using test file
  (prevents future drift where a skill opts in without coverage)

Shared helper test/helpers/plan-mode-handshake-helpers.ts centralizes the
canUseTool interceptor + distinctive-phrase injection so the 4 sibling
E2E tests are thin wiring (~20 LOC each) and can't drift out of sync.

Unit assertions added to test/gen-skill-docs.test.ts:
- handshake section present in all 4 Claude-generated SKILL.md files
- handshake section absent from non-interactive Claude skills (ship,
  review, qa, office-hours, codex, retro, cso)
- handshake section absent from non-Claude host outputs (.agents, etc.)
- 0C-bis STOP block present in plan-ceo-review/SKILL.md at correct
  position (between the "Present these approach options" line and
  "### 0D-prelude" header)
- handshake resolver wired BEFORE generateUpgradeCheck in preamble
  composition order

6 new gate-tier entries added to test/helpers/touchfiles.ts so any change
to the handshake resolver, preamble composition, skill templates, question
registry, one-way-door classifier, or agent-sdk-runner fires the relevant
E2E tests. test/touchfiles.test.ts updated for the new selection count
(plan-ceo-review/** now triggers 15 tests, up from 8).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 23:41:13 -07:00

114 lines
3.4 KiB
TypeScript

/**
* E2E harness audit — every skill with `interactive: true` in its frontmatter
* must have at least one test file that uses `canUseTool` via the extended
* agent-sdk-runner. This prevents future drift where a skill opts into the
* handshake without adding real coverage.
*
* Runs as a free unit test (no API calls). Pure filesystem scan.
*/
import { describe, test, expect } from 'bun:test';
import * as fs from 'fs';
import * as path from 'path';
const ROOT = path.resolve(import.meta.dir, '..');
const SKILL_GLOBS = [
'plan-ceo-review',
'plan-eng-review',
'plan-design-review',
'plan-devex-review',
'office-hours',
'codex',
'investigate',
'qa',
'retro',
'cso',
'review',
'ship',
'design-review',
'devex-review',
'qa-only',
'design-consultation',
'design-shotgun',
'autoplan',
'land-and-deploy',
'plan-tune',
'document-release',
'context-save',
'context-restore',
'health',
'setup-deploy',
'setup-browser-cookies',
'canary',
'learn',
'benchmark',
'benchmark-models',
'make-pdf',
'open-gstack-browser',
'gstack-upgrade',
'pair-agent',
'design-html',
'freeze',
'unfreeze',
'careful',
'guard',
];
/**
* Load .tmpl files for each skill and return the names of those that have
* `interactive: true` in frontmatter.
*/
function findInteractiveSkills(): string[] {
const interactive: string[] = [];
for (const skill of SKILL_GLOBS) {
const tmplPath = path.join(ROOT, skill, 'SKILL.md.tmpl');
if (!fs.existsSync(tmplPath)) continue;
const content = fs.readFileSync(tmplPath, 'utf-8');
// Frontmatter lives between the first '---' and the next '---'.
const fmEnd = content.indexOf('\n---', 4);
if (fmEnd < 0) continue;
const frontmatter = content.slice(0, fmEnd);
if (/^interactive:\s*true\s*$/m.test(frontmatter)) {
interactive.push(skill);
}
}
return interactive;
}
/**
* Scan a test file's contents for the canUseTool-via-harness pattern.
* Either: direct canUseTool usage in runAgentSdkTest, or usage of the
* shared plan-mode-handshake-helpers that wrap it.
*/
function hasCanUseToolCoverage(testFile: string): boolean {
const content = fs.readFileSync(testFile, 'utf-8');
if (content.includes('canUseTool')) return true;
if (content.includes('runPlanModeHandshakeTest')) return true;
return false;
}
describe('E2E harness audit — interactive skills must have canUseTool coverage', () => {
test('every interactive: true skill has at least one canUseTool test', () => {
const interactive = findInteractiveSkills();
expect(interactive.length).toBeGreaterThan(0);
const testFiles = fs
.readdirSync(path.join(ROOT, 'test'))
.filter((f) => f.startsWith('skill-e2e-') && f.endsWith('.test.ts'))
.map((f) => path.join(ROOT, 'test', f));
const filesWithCoverage = testFiles.filter(hasCanUseToolCoverage);
for (const skill of interactive) {
// Match the skill name in any test file that uses canUseTool. File
// naming convention is `skill-e2e-<skill>-*.test.ts` — either the full
// name (plan-ceo-review) or a subset token.
const hasDedicatedTest = filesWithCoverage.some((f) => {
const base = path.basename(f, '.test.ts');
return base.includes(skill) || base.includes(skill.replace(/-review$/, ''));
});
expect(hasDedicatedTest, `skill "${skill}" has interactive:true but no canUseTool-based E2E test`).toBe(true);
}
});
});