Skip to content

Commit aaa11a2

Browse files
feat(scenarios): skill-evals --triggers-only runs the selected bundles' trigger cases alone (#35776)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D4n2wzAmmp4Z6W5jsqtM2qx)_ Fixes #35705 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户无感:内部技能评测工具新增「只跑触发用例」模式,六个元数据技能包的一轮从约 354 次对话降到 42 次。 - 为什么做:给「技能描述改动是否让技能在该加载时加载」的测量省下约九成订阅轮次,前后两轮从约 700 次降到约 84 次。 - 出错会怎样:只影响维护者跑评测时选哪些用例、怎么汇总,不改任何对外发布的技能内容,可直接撤回。 - 要你做什么:无。 ## What changes `pnpm --filter @objectstack/scenarios skill-evals --triggers-only` selects only the `should_trigger` cases of the selected bundles, on the with-skill arm. It reuses the existing selection (`selectBundles`, one path with a `triggersOnly` argument), plan (`planRound`, which already runs a trigger case on the with-skill arm only) and summary (`summariseRound` / `renderSummaryMarkdown`); no second path. - **Selection** (`cases.ts`): the pool narrows to trigger cases before the existing `--skills` checks, so a bundle named in `--skills` with no trigger case is refused by name, and a whole-catalog selection with no trigger case at all is refused. - **Flags** (`cli.ts`): refused beside `--regrade` (a regrade re-draws a round at the scope it ran) and beside `--self-test` (it runs its own fixtures). Works with `--dry-run`, which prints the reduced plan plus how many behaviour cases of those bundles were left out, and with `--skills-from VERSION`. - **Record and summary**: `round.json` records `scope.arms: ["with-skill"]` and `scope.triggersOnly: true`; `--regrade` reads that and keeps the scope, so the behaviour cases are not listed as `added`. The summary title says `trigger cases × the with-skill arm`, and a trigger-only round renders the trigger section alone (no empty per-bundle and per-case tables); the stdout excerpt follows. - **Self-test**: two rows (floor 30 to 32): trigger cases kept on the with-skill arm and behaviour cases dropped; and the refusals (beside `--regrade`, beside `--self-test`, on a bundle with no trigger case), with the flag accepted beside `--skills-from` and `--dry-run`. - **README**: the `skill-evals` section gains the command line and a `--triggers-only` bullet. Changeset: `@objectstack/scenarios` patch (the package publishes, and its `README.md` is in `files[]`). Net-added lines, whole PR: +143 / -38 = 105 (budget 150). ## Tests - `packages/qa/scenarios/test/skill-evals/skill-evals.test.ts`: one new case runs a trigger-only round through `executeRound` with a stub turn, asserts both turns are with-skill, that the summary renders the trigger section only, and that `regradeRound` on a `triggersOnly` round adds no behaviour case and keeps the title. - Self-test rows above. ## Acceptance notes - `--skills-from 18.5.0 --triggers-only` is refused: that published version predates trigger cases, so the selection is empty (`no bundle under ... has a trigger case`). `--skills-from 18.6.0` plans the same 42 turns (138 behaviour cases left out there), which is the "before" leg the card asks for. - Without `--skills`, `--triggers-only` keeps every bundle that has a trigger case and leaves out those without one; the refusal fires only when none has one. The round title then reads `all bundles`. - A `round.json` written before this change has no `scope.triggersOnly` and regrades exactly as before. - The test file `packages/qa/scenarios/test/skill-evals/skill-evals.test.ts` is outside the claim's declared file surface (`src/skill-evals/*` and the README); it is the package's existing suite for this runner. ## Verification Read first, by risk: 1. `packages/qa/scenarios/src/skill-evals/cli.ts`: the two refusals in `parseSkillEvalArgs`, the `scope.triggersOnly` record, and the regrade filter in `regradeRound`. 2. `packages/qa/scenarios/src/skill-evals/cases.ts`: `selectBundles`. 3. `packages/qa/scenarios/src/skill-evals/summary.ts`: the branch that drops the behaviour tables. Two-minute check: `pnpm --filter @objectstack/scenarios skill-evals --skills objectstack-data,objectstack-ui,objectstack-automation,objectstack-formula,objectstack-i18n,objectstack-query --triggers-only --dry-run` prints the plan line below and makes no model call. All local readings at head `2ea2c4fe71` (feature commit `0a97625509` plus a merge of `origin/main` at `cceb5c626d`). <details><summary>Dry-run plan (the card's Done-when)</summary> ```text 42 trigger case(s) × the with-skill arm, × 1 = 42 turn(s), 2 at once --triggers-only: 156 behaviour case(s) of these bundles left out trigger cases: 30 should load the bundle, 12 should not ``` Without the flag the same bundles plan `156 behaviour case(s) × 2 arms + 42 trigger case(s) × the with-skill arm, × 1 = 354 turn(s)`. </details> <details><summary>Self-test</summary> ```text ✓ select: --triggers-only keeps the trigger cases on the with-skill arm and drops the behaviour cases ✓ flags: --triggers-only beside --regrade or --self-test, or on a bundle with no trigger case → REFUSED ✓ skill-evals self-test: 32 rows pass. ``` Refusal messages as the CLI prints them: ```text --triggers-only cannot narrow --self-test: the self-test runs its own fixtures, never a selection of cases --triggers-only cannot narrow --regrade: a regrade re-draws the recorded round at the scope it ran, so a --triggers-only round regrades as one without the flag ``` </details> <details><summary>Package checks</summary> ```text pnpm --filter @objectstack/scenarios run typecheck -> exit 0 (tsconfig includes test/**, so the new test is type-checked) pnpm --filter @objectstack/scenarios exec vitest run --maxWorkers=2 -> Test Files 40 passed (40), Tests 1202 passed (1202) eslint --no-inline-config on the 5 changed .ts files -> exit 0, no findings node scripts/pm/dispatch-gates.mjs --commands -> 62 commands, each run, each exit 0 node scripts/pm/dispatch-gates.mjs --ran -> 62 derived famil(ies) accounted for, 62 run, 0 NOT-MEASURED (a DERIVED zero) node scripts/pm/overlap-check.mjs --branch=claude/area-a4A-35705 -> origin/main merges cleanly, VERDICT clean exit 0 ``` One-time ablation (not kept): deleting the `scope.triggersOnly` filter in `regradeRound` (via `scripts/ablation-replace.mjs`, anchor 1 -> 0 on disk) turns the new test red with `expected [ [ 'beta-skill/cases#1' ], +0, 2 ] to deeply equal [ [], +0, 2 ]`; restored, blob equal to HEAD and `git diff HEAD` empty. The repo-wide lint run, `test:repo` and the type-check lanes are CI's. </details> No model call was made: no real round ran. https://claude.ai/code/session_016WV4d1ZJL93Kin2UHFXbFv 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent e114324 commit aaa11a2

7 files changed

Lines changed: 143 additions & 38 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
skill-evals: `--triggers-only` runs the selected bundles' trigger cases alone
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`pnpm --filter @objectstack/scenarios skill-evals --triggers-only` selects only the `should_trigger` cases of the selected bundles, on the with-skill arm, so a change to when a skill loads is measured on its trigger cases alone: the six metadata bundles plan 42 turns instead of 354. The summary is the trigger section alone; `round.json` records `scope.triggersOnly`, and `--regrade` keeps that scope. It works with `--dry-run` and `--skills-from VERSION`. It is refused beside `--regrade` or `--self-test`, and a bundle named in `--skills` with no trigger case is refused. The README section "Running the published skills' eval cases" documents it.

‎packages/qa/scenarios/README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ pnpm --filter @objectstack/scenarios skill-evals --dry-run # the plan and t
900900
pnpm --filter @objectstack/scenarios skill-evals # every case × 2 arms
901901
pnpm --filter @objectstack/scenarios skill-evals --skills objectstack-query --repeats 3 # a touched skill
902902
pnpm --filter @objectstack/scenarios skill-evals --skills-from 18.5.0 # a published @objectstack/skills version's bundles and cases
903+
pnpm --filter @objectstack/scenarios skill-evals --skills objectstack-query --triggers-only # its trigger cases alone
903904
pnpm --filter @objectstack/scenarios skill-evals --regrade DIR # re-draw a recorded round's verdicts from its records; no model call
904905
pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's own fixtures; no model call
905906
```
@@ -931,6 +932,11 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o
931932
cases are all positive, or all negative, is refused. The summary reports trigger cases in their own section beside
932933
the behaviour cases, never inside their pass rates: per bundle, loaded when it should, left alone when it should
933934
not, the missed loads and the false loads.
935+
- **`--triggers-only`**: the selected bundles' trigger cases alone, on the with-skill arm, for a change that only
936+
touches when a skill loads (its `description`). The summary is the trigger section alone, and `round.json` records
937+
`scope.triggersOnly`, so `--regrade DIR` keeps that scope. A bundle `--skills` names with no trigger case is refused
938+
(a published version before trigger cases has none), and so is the flag beside `--regrade` or `--self-test`.
939+
`--dry-run` prints the reduced plan, and `--skills-from VERSION` runs it on the published bundles.
934940
- **Case files**: a case's `files` entries are paths under the bundle's `evals/files/` (anything else is refused, and
935941
so is a path the bundle lacks or one with a `.claude` segment, since `.claude/` is where the runner places the skill). Each is copied, a directory whole, into both arms' directories at its path below
936942
`evals/files/`, so the arms still differ only in the bundle. A case whose prompt states its context needs none.

‎packages/qa/scenarios/src/skill-evals/cases.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,23 @@ export function notUserInvocable(skillMd: string): boolean {
263263
}
264264

265265
/**
266-
* Narrow a catalog to the named bundles (`--skills a,b`). A name that is not a
267-
* bundle of the catalog is refused, never dropped: a misspelt touched skill
268-
* would otherwise run nothing and read as a clean round.
266+
* Narrow a catalog to the named bundles (`--skills a,b`) and, with
267+
* `triggersOnly` (`--triggers-only`), to their trigger cases. A name that is
268+
* not a bundle of the catalog, or names one with no case left to run, is
269+
* refused, never dropped: a misspelt touched skill would otherwise run nothing
270+
* and read as a clean round. So is a trigger-only selection with no case.
269271
*/
270-
export function selectBundles(catalog: SkillEvalCatalog, names: readonly string[] | undefined): SkillEvalCase[] {
271-
if (!names || names.length === 0) return catalog.cases;
272+
export function selectBundles(catalog: SkillEvalCatalog, names: readonly string[] | undefined, triggersOnly = false): SkillEvalCase[] {
273+
const pool = triggersOnly ? catalog.cases.filter((c) => c.shouldTrigger !== undefined) : catalog.cases;
274+
const kind = triggersOnly ? 'trigger case (`should_trigger`)' : 'eval case';
275+
if (!names || names.length === 0) {
276+
if (triggersOnly && pool.length === 0) throw new Error(`--triggers-only: no bundle under ${catalog.root} has a ${kind}`);
277+
return pool;
278+
}
272279
const unknown = names.filter((n) => !catalog.bundles.includes(n));
273280
if (unknown.length) throw new Error(`--skills names ${unknown.map((n) => `\`${n}\``).join(', ')}, not a bundle under ${catalog.root} (bundles: ${catalog.bundles.join(', ')})`);
274-
const noCases = names.filter((n) => !catalog.cases.some((c) => c.bundle === n));
275-
if (noCases.length) throw new Error(`--skills names ${noCases.map((n) => `\`${n}\``).join(', ')}, a bundle with no eval case under ${catalog.root}`);
281+
const noCases = names.filter((n) => !pool.some((c) => c.bundle === n));
282+
if (noCases.length) throw new Error(`--skills names ${noCases.map((n) => `\`${n}\``).join(', ')}, a bundle with no ${kind} under ${catalog.root}`);
276283
const set = new Set(names);
277-
return catalog.cases.filter((c) => set.has(c.bundle));
284+
return pool.filter((c) => set.has(c.bundle));
278285
}

‎packages/qa/scenarios/src/skill-evals/cli.ts‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* --skills-from SOURCE `workspace` (default: this checkout's skills/) or an
1616
* `@objectstack/skills` version (`18.5.0`), packed from npm;
1717
* cases and bundles both come from SOURCE
18+
* --triggers-only only the selected bundles' trigger cases (`should_trigger`), on
19+
* the with-skill arm; refused beside --regrade or --self-test
1820
* --repeats N turns per case per arm (default 1)
1921
* --concurrency N turns at once (default 2)
2022
* --max-turns N `--max-turns` per turn (default 16)
@@ -64,6 +66,7 @@ export interface SkillEvalArgs {
6466
bin: string;
6567
out?: string;
6668
regrade?: string;
69+
triggersOnly: boolean;
6770
dryRun: boolean;
6871
selfTest: boolean;
6972
help: boolean;
@@ -77,7 +80,7 @@ const positiveInt = (flag: string, raw: string | undefined): number => {
7780

7881
/** Parse argv; an unknown flag or a flag missing its value is refused. Pure over its input. */
7982
export function parseSkillEvalArgs(argv: readonly string[]): SkillEvalArgs {
80-
const a: SkillEvalArgs = { skillsFrom: 'workspace', repeats: 1, concurrency: 2, maxTurns: 16, caseTimeoutMin: 5, maxUtilization: 0.9, bin: 'claude', dryRun: false, selfTest: false, help: false };
83+
const a: SkillEvalArgs = { skillsFrom: 'workspace', repeats: 1, concurrency: 2, maxTurns: 16, caseTimeoutMin: 5, maxUtilization: 0.9, bin: 'claude', triggersOnly: false, dryRun: false, selfTest: false, help: false };
8184
for (let i = 0; i < argv.length; i++) {
8285
const flag = argv[i]!;
8386
const val = () => {
@@ -105,11 +108,15 @@ export function parseSkillEvalArgs(argv: readonly string[]): SkillEvalArgs {
105108
else if (flag === '--bin') a.bin = val();
106109
else if (flag === '--out') a.out = val();
107110
else if (flag === '--regrade') a.regrade = val();
111+
else if (flag === '--triggers-only') a.triggersOnly = true;
108112
else if (flag === '--dry-run') a.dryRun = true;
109113
else if (flag === '--self-test') a.selfTest = true;
110114
else if (flag === '--help' || flag === '-h') a.help = true;
111115
else throw new Error(`unknown flag \`${flag}\` (see --help)`);
112116
}
117+
// Refused, never ignored: neither of these reads a selection the flag could narrow.
118+
if (a.triggersOnly && a.regrade !== undefined) throw new Error('--triggers-only cannot narrow --regrade: a regrade re-draws the recorded round at the scope it ran, so a --triggers-only round regrades as one without the flag');
119+
if (a.triggersOnly && a.selfTest) throw new Error('--triggers-only cannot narrow --self-test: the self-test runs its own fixtures, never a selection of cases');
113120
return a;
114121
}
115122

@@ -172,7 +179,8 @@ export interface RoundRecord {
172179
concurrency: number;
173180
maxUtilization: number;
174181
};
175-
scope: { cases: number; arms: string[]; repeats: number; plannedTurns: number; ranTurns: number; notRunTurns: number };
182+
/** `triggersOnly`: the round ran `--triggers-only` (its trigger cases alone, on the with-skill arm), and `--regrade` keeps that scope. */
183+
scope: { cases: number; arms: string[]; repeats: number; plannedTurns: number; ranTurns: number; notRunTurns: number; triggersOnly?: true };
176184
stopped?: RoundStop;
177185
/**
178186
* Set by `--regrade`: when, by which runner, and how many verdicts now differ
@@ -200,17 +208,17 @@ export function regradedLines(g: NonNullable<RoundRecord['regraded']>): string[]
200208
];
201209
}
202210

203-
/** `N behaviour case(s) × 2 arms [+ M trigger case(s) × the with-skill arm], × R`. Pure. */
211+
/** `N behaviour case(s) × 2 arms [+ M trigger case(s) × the with-skill arm], × R`; the behaviour part only when there is one, or nothing else. Pure. */
204212
export const turnsLine = (behaviour: number, trigger: number, repeats: number): string =>
205-
`${behaviour} behaviour case(s) × ${ARMS.length} arms${trigger ? ` + ${trigger} trigger case(s) × the with-skill arm` : ''}, × ${repeats}`;
213+
`${[behaviour || !trigger ? `${behaviour} behaviour case(s) × ${ARMS.length} arms` : '', trigger ? `${trigger} trigger case(s) × the with-skill arm` : ''].filter(Boolean).join(' + ')}, × ${repeats}`;
206214

207215
/** `round.json`, `summary.md` and `summary.github.md` into `outDir`, and the per-bundle tables on stdout. */
208216
export function writeRoundOutputs(outDir: string, round: RoundRecord): void {
209217
writeFileSync(join(outDir, 'round.json'), JSON.stringify(round, null, 2) + '\n');
210218
const { driver: d, scope } = round;
211219
const wallMin = Math.round(round.wallMs / 6000) / 10;
212220
const head = {
213-
title: `Skill evals · ${round.skills.allBundles ? 'all bundles' : round.skills.bundles.join(', ')} × 2 arms × ${scope.repeats} rep${scope.repeats === 1 ? '' : 's'}`,
221+
title: `Skill evals · ${round.skills.allBundles ? 'all bundles' : round.skills.bundles.join(', ')} × ${scope.triggersOnly ? 'trigger cases × the with-skill arm' : '2 arms'} × ${scope.repeats} rep${scope.repeats === 1 ? '' : 's'}`,
214222
lines: [
215223
`runner: ${round.runner.repo} ${round.runner.sha}`,
216224
`skills: ${round.skills.source}`,
@@ -225,7 +233,7 @@ export function writeRoundOutputs(outDir: string, round: RoundRecord): void {
225233
writeFileSync(join(outDir, 'summary.github.md'), renderSummaryMarkdown(round.summary, head, { forGitHub: true }));
226234
const md = renderSummaryMarkdown(round.summary, head);
227235
const triggerTable = md.includes('\n## Trigger cases') ? md.slice(md.indexOf('\n## Trigger cases')).split('\n| trigger case |')[0] : '';
228-
console.log(`\n${md.split('## Per case')[0]}${triggerTable}`);
236+
console.log(`\n${md.split(/## (?:Per case|Trigger cases)/)[0]}${triggerTable}`);
229237
console.log(`round: ${join(outDir, 'round.json')} · summary: ${join(outDir, 'summary.md')}`);
230238
}
231239

@@ -249,7 +257,8 @@ export function regradeRound(dir: string, catalog: SkillEvalCatalog, sourceLabel
249257
if (round.skills.source !== sourceLabel) throw new Error(`--regrade: the round ran on ${round.skills.source}, not ${sourceLabel}; pass the same --skills-from`);
250258
// The bundles may have left the catalog too; their cases are then set apart as removed.
251259
const present = round.skills.bundles.filter((b) => catalog.bundles.includes(b));
252-
const catalogCases = present.length ? catalog.cases.filter((c) => present.includes(c.bundle)) : [];
260+
// A `--triggers-only` round planned its trigger cases alone: its behaviour cases are not `added` since.
261+
const catalogCases = present.length ? catalog.cases.filter((c) => present.includes(c.bundle) && (!round.scope.triggersOnly || c.shouldTrigger !== undefined)) : [];
253262
const view = { bundles: catalog.bundles, unlisted: catalog.unlistedBundles };
254263
const runsDir = join(dir, 'runs');
255264
const files = readdirSync(runsDir).filter((n) => n.endsWith('.json')).sort();
@@ -277,7 +286,7 @@ export function regradeRound(dir: string, catalog: SkillEvalCatalog, sourceLabel
277286
const HELP = `skill-evals — run the published skills' eval cases on a with-skill and a no-skill arm
278287
pnpm --filter @objectstack/scenarios skill-evals [--skills a,b] [--skills-from workspace|VERSION] [--repeats N]
279288
[--concurrency N] [--max-turns N] [--case-timeout MIN] [--max-utilization F] [--model M] [--effort L]
280-
[--bin PATH] [--out DIR] [--dry-run] [--regrade DIR] [--self-test]
289+
[--bin PATH] [--out DIR] [--triggers-only] [--dry-run] [--regrade DIR] [--self-test]
281290
See packages/qa/scenarios/README.md, "Running the published skills' eval cases".`;
282291

283292
export async function main(argv: readonly string[]): Promise<number> {
@@ -308,7 +317,7 @@ export async function main(argv: readonly string[]): Promise<number> {
308317
}
309318
const catalogView = { bundles: catalog.bundles, unlisted: catalog.unlistedBundles };
310319
if (args.regrade) return regradeRound(resolve(args.regrade), catalog, source.label);
311-
const cases = selectBundles(catalog, args.skills);
320+
const cases = selectBundles(catalog, args.skills, args.triggersOnly);
312321
const jobs = planRound(cases, args.repeats);
313322
const bundles = [...new Set(cases.map((c) => c.bundle))];
314323
const turnOpts = { maxTurns: args.maxTurns, ...(args.model ? { model: args.model } : {}), ...(args.effort ? { effort: args.effort } : {}) };
@@ -318,8 +327,9 @@ export async function main(argv: readonly string[]): Promise<number> {
318327
for (const b of bundles) console.log(` ${b}: ${cases.filter((c) => c.bundle === b).length} case(s)`);
319328
const triggers = cases.filter((c) => c.shouldTrigger !== undefined);
320329
console.log(`${turnsLine(cases.length - triggers.length, triggers.length, args.repeats)} = ${jobs.length} turn(s), ${args.concurrency} at once`);
330+
if (args.triggersOnly) console.log(`--triggers-only: ${selectBundles(catalog, args.skills).length - cases.length} behaviour case(s) of these bundles left out`);
321331
if (triggers.length) console.log(`trigger cases: ${triggers.filter((c) => c.shouldTrigger).length} should load the bundle, ${triggers.filter((c) => !c.shouldTrigger).length} should not`);
322-
console.log(`each turn: a fresh directory holding the case's files; with-skill also holds .claude/skills/BUNDLE/ (no evals/), no-skill no skill`);
332+
console.log(`each turn: a fresh directory holding the case's files; with-skill also holds .claude/skills/BUNDLE/ (no evals/)${args.triggersOnly ? '' : ', no-skill no skill'}`);
323333
console.log(`argv (prompt on stdin): ${args.bin} ${armArgs('TURN_DIR/mcp.json', turnOpts).join(' ')}`);
324334
console.log('dry run: no login read, no model called, nothing written');
325335
return 0;
@@ -372,7 +382,7 @@ export async function main(argv: readonly string[]): Promise<number> {
372382
concurrency: args.concurrency,
373383
maxUtilization: args.maxUtilization,
374384
},
375-
scope: { cases: cases.length, arms: [...ARMS], repeats: args.repeats, plannedTurns: jobs.length, ranTurns: exec.records.length, notRunTurns: exec.notRun.length },
385+
scope: { cases: cases.length, arms: args.triggersOnly ? ['with-skill'] : [...ARMS], repeats: args.repeats, plannedTurns: jobs.length, ranTurns: exec.records.length, notRunTurns: exec.notRun.length, ...(args.triggersOnly ? { triggersOnly: true as const } : {}) },
376386
...(exec.stopped ? { stopped: exec.stopped } : {}),
377387
summary: summariseRound(cases, exec.records, exec.notRun),
378388
};

‎packages/qa/scenarios/src/skill-evals/self-test.ts‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { join } from 'node:path';
1818

1919
import { ApiBillingRefusedError } from '../runner/driver.js';
2020
import { armArgs, placeCaseFiles, prepareArmWorkdir } from './arms.js';
21-
import { loadSkillEvalCatalog, notUserInvocable, parseEvalFile, type SkillEvalCase } from './cases.js';
21+
import { loadSkillEvalCatalog, notUserInvocable, parseEvalFile, selectBundles, type SkillEvalCase } from './cases.js';
22+
import { parseSkillEvalArgs } from './cli.js';
2223
import { type Grader, gradeAnswer } from './grade.js';
2324
import { judgeTurn, planRound, preflight, regradeRecords, type SkillEvalRunRecord } from './run.js';
2425
import { summariseRound } from './summary.js';
@@ -55,10 +56,12 @@ export const SELF_TEST_BATTERIES = Object.freeze({
5556
'round: a trigger case runs on the with-skill arm only': 1,
5657
'arms: a case\'s files land in the turn\'s project on both arms': 1,
5758
'summary: trigger cases are tallied apart from the behaviour pass rates': 1,
59+
'select: --triggers-only keeps the trigger cases on the with-skill arm and drops the behaviour cases': 1,
60+
'flags: --triggers-only beside --regrade or --self-test, or on a bundle with no trigger case → REFUSED': 1,
5861
});
5962

6063
/** The roster's own size, pinned: a deleted row takes its floor with it otherwise. */
61-
export const SELF_TEST_BATTERY_FLOOR = 30;
64+
export const SELF_TEST_BATTERY_FLOOR = 32;
6265

6366
let selfTestReachedVerdict = false;
6467
/** Whether the last {@link runSelfTest} reached its verdict line. */
@@ -121,6 +124,13 @@ export function runSelfTest(deps: SelfTestDeps): SelfTestResult {
121124
const judge = (c: SkillEvalCase, arm: 'with-skill' | 'no-skill', stdout: string): SkillEvalRunRecord =>
122125
judgeTurn(c, arm, 1, exited(stdout), { bundles: ['demo-skill', 'other-skill', 'quiet-skill'], unlisted: ['quiet-skill'] }, 'fixture', grade);
123126

127+
// Two bundles: `demo-skill` with a behaviour case and a trigger case of each kind; `other-skill` with a behaviour case only.
128+
const selectCatalog = { root: 'fixture', bundles: ['demo-skill', 'other-skill'], unlistedBundles: [], refusals: [], cases: [
129+
fixtureCase(),
130+
fixtureCase({ id: 2, key: 'demo-skill/demo#2', shouldTrigger: true, mustContain: [] }),
131+
fixtureCase({ id: 3, key: 'demo-skill/demo#3', shouldTrigger: false, mustContain: [] }),
132+
fixtureCase({ bundle: 'other-skill', key: 'other-skill/demo#1' }),
133+
] };
124134
type Row = { label: keyof typeof SELF_TEST_BATTERIES | string; run: () => true | string };
125135
const rows: Row[] = [
126136
{
@@ -390,6 +400,34 @@ export function runSelfTest(deps: SelfTestDeps): SelfTestResult {
390400
: `behaviour cases ${s.cases.length} (with-skill ${s.totals.withSkill.pass}/${s.totals.withSkill.fail}); missed [${t?.missedLoads.join() ?? ''}], false [${t?.falseLoads.join() ?? ''}]`;
391401
},
392402
},
403+
{
404+
label: 'select: --triggers-only keeps the trigger cases on the with-skill arm and drops the behaviour cases',
405+
run: () => {
406+
const all = selectBundles(selectCatalog, ['demo-skill']).map((c) => String(c.id)).join();
407+
const jobs = planRound(selectBundles(selectCatalog, ['demo-skill'], true), 1).map((j) => `${String(j.case.id)}:${j.arm}`).join();
408+
return all === '1,2,3' && jobs === '2:with-skill,3:with-skill' ? true : `without the flag [${all}], expected 1,2,3; with it [${jobs}], expected 2:with-skill,3:with-skill`;
409+
},
410+
},
411+
{
412+
label: 'flags: --triggers-only beside --regrade or --self-test, or on a bundle with no trigger case → REFUSED',
413+
run: () => {
414+
const refusal = (f: () => unknown, why: RegExp) => {
415+
try {
416+
f();
417+
} catch (e) {
418+
return why.test(e instanceof Error ? e.message : String(e));
419+
}
420+
return false;
421+
};
422+
const kept = parseSkillEvalArgs(['--triggers-only', '--skills-from', '18.5.0', '--dry-run']).triggersOnly;
423+
const r = [
424+
refusal(() => parseSkillEvalArgs(['--triggers-only', '--regrade', 'DIR']), /--triggers-only cannot narrow --regrade/),
425+
refusal(() => parseSkillEvalArgs(['--self-test', '--triggers-only']), /--triggers-only cannot narrow --self-test/),
426+
refusal(() => selectBundles(selectCatalog, ['other-skill'], true), /`other-skill`, a bundle with no trigger case/),
427+
];
428+
return kept && r.every(Boolean) ? true : `accepted beside --skills-from: ${kept}; refused (--regrade, --self-test, no trigger case): ${r.join(', ')}`;
429+
},
430+
},
393431
];
394432

395433
let failed = 0;

0 commit comments

Comments
 (0)