From 4dbf91395a09ade173390b198edfd7b2810e6e94 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 22:00:38 +0000 Subject: [PATCH 1/4] fix(scenarios): a thrown live turn is recorded and replays as the same failure; a wrongly cased skill file is refused Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH --- .../qa/scenarios/src/runner/ask-skills.ts | 52 ++++++-- packages/qa/scenarios/src/runner/driver.ts | 77 +++++++++++- .../scenarios/test/runner/ask-skills.test.ts | 58 +++++++++ .../scenarios/test/runner/orchestrate.test.ts | 113 ++++++++++++++++++ 4 files changed, 285 insertions(+), 15 deletions(-) diff --git a/packages/qa/scenarios/src/runner/ask-skills.ts b/packages/qa/scenarios/src/runner/ask-skills.ts index abf91d1ba53..364db687ddd 100644 --- a/packages/qa/scenarios/src/runner/ask-skills.ts +++ b/packages/qa/scenarios/src/runner/ask-skills.ts @@ -149,25 +149,57 @@ export function skillVersionOf(skillMd: string): string | undefined { return m ? m[1]!.trim() : undefined; } +/** + * The skill file `dir` holds, read off its listing by exact spelling: + * `SKILL.md` when it holds that file; else the name of a file spelled + * otherwise (`skill.md`, `Skill.md`); else `undefined`. Never `existsSync`: a + * case-insensitive filesystem answers it true for `skill.md`, while the listing + * names each file as it is spelled on every filesystem. + */ +function skillFileOf(dir: string): string | undefined { + const names = readdirSync(dir, { withFileTypes: true }).filter((e) => e.isFile()).map((e) => e.name); + if (names.includes(SKILL_FILE)) return SKILL_FILE; + return names.find((n) => n.toLowerCase() === SKILL_FILE.toLowerCase()); +} + /** * Read a skills directory: either one skill (a directory holding `SKILL.md`, * named after the directory) or a directory of skills (each subdirectory that * holds `SKILL.md`, the layout of a `.claude/skills/` directory). Refused, with * the reason, when the path is no directory or holds no skill: an option that - * gave the client nothing must not run as if it had. Refused too when any - * SKILL.md of a skill carries a front-matter key outside the ask turn's closed - * set ({@link frontMatterRefusal}): a skill must not widen the turn beyond the - * app's tools and `Skill`. + * gave the client nothing must not run as if it had. Refused when a skill file + * is spelled otherwise than `SKILL.md` ({@link skillFileOf}), naming it: a + * session reads such a file on one filesystem and misses it on another, so the + * turn would be given a skill on one machine and none on the next. Refused too + * when any SKILL.md of a skill carries a front-matter key outside the ask + * turn's closed set ({@link frontMatterRefusal}): a skill must not widen the + * turn beyond the app's tools and `Skill`. */ export function readAskSkills(dirArg: string): AskSkillsBundle { const dir = resolve(dirArg); if (!existsSync(dir) || !statSync(dir).isDirectory()) throw new Error(`--ask-skills names \`${dirArg}\`, which is no directory`); - const skillDirs: Array<[string, string]> = existsSync(join(dir, SKILL_FILE)) - ? [[basename(dir), dir]] - : readdirSync(dir, { withFileTypes: true }) - .filter((e) => e.isDirectory() && existsSync(join(dir, e.name, SKILL_FILE))) - .map((e) => [e.name, join(dir, e.name)] as [string, string]) - .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)); + const misspelt = (shown: string) => + new Error( + `--ask-skills names \`${dirArg}\`, which holds \`${shown}\`: a skill file is spelled \`${SKILL_FILE}\` exactly, ` + + `or a session reads it on one filesystem and misses it on another; rename it to \`${SKILL_FILE}\``, + ); + const skillDirs: Array<[string, string]> = []; + const top = skillFileOf(dir); + if (top !== undefined) { + if (top !== SKILL_FILE) throw misspelt(top); + skillDirs.push([basename(dir), dir]); + } else { + const subdirs = readdirSync(dir, { withFileTypes: true }) + .filter((e) => e.isDirectory()) + .map((e) => e.name) + .sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)); + for (const name of subdirs) { + const found = skillFileOf(join(dir, name)); + if (found === undefined) continue; + if (found !== SKILL_FILE) throw misspelt(`${name}/${found}`); + skillDirs.push([name, join(dir, name)]); + } + } if (skillDirs.length === 0) { throw new Error(`--ask-skills names \`${dirArg}\`, which holds no skill: give a directory holding ${SKILL_FILE}, or a directory of skill directories that each hold one`); } diff --git a/packages/qa/scenarios/src/runner/driver.ts b/packages/qa/scenarios/src/runner/driver.ts index 3fa2ede7f43..1a93e689ee9 100644 --- a/packages/qa/scenarios/src/runner/driver.ts +++ b/packages/qa/scenarios/src/runner/driver.ts @@ -31,7 +31,8 @@ * what the recorded run wrote. * * {@link RecordingDriver} wraps a live driver and writes every turn it sees to - * a recording the replay driver reads back. + * a recording the replay driver reads back. A turn that threw is recorded as + * one ({@link RecordedTurn.thrown}), and its replay throws it again. */ import { spawnSync } from 'node:child_process'; @@ -514,10 +515,28 @@ export class ClaudeCodeDriver implements AgentDriver { // ── Replay ────────────────────────────────────────────────────────────────── +/** + * A live turn that threw instead of answering ({@link RecordingDriver}): the + * error's `name` and `message`, as the run counted it. Its turn is empty. + */ +export interface ThrownTurn { + name: string; + message: string; +} + +/** + * A recorded turn: what the driver answered, or, with {@link thrown}, an empty + * turn standing for an ask or authoring turn that threw. Absent ⇒ the turn + * answered, as every turn of a recording made before throws were recorded. + */ +export interface RecordedTurn extends ParsedTurn { + thrown?: ThrownTurn; +} + /** A recording: every turn of a run, keyed by {@link stepKey}. */ export interface Recording { driver: DriverInfo; - turns: Record; + turns: Record; /** Authoring turns' resulting project sources, keyed like `turns`. */ files: Record>; /** @@ -545,6 +564,33 @@ export class MissingRecordingError extends Error { } } +/** + * A replayed turn that threw in the recorded run ({@link RecordedTurn.thrown}), + * thrown again with the recorded `name` and `message`: the runner counts it + * exactly as it counted the live throw (an error, never a missing turn, which a + * dataset question or a confirmation turn reads as not measured). + */ +export class RecordedThrowError extends Error { + constructor( + readonly key: string, + thrown: ThrownTurn, + ) { + super(thrown.message); + this.name = thrown.name; + } +} + +/** + * The turn recorded for a live call that threw `e`, or `undefined` for a throw + * that is itself a replay's verdict on a missing or unfaithful turn: those are + * left unrecorded, as before, so a replay of the recording meets the same gap. + */ +function thrownTurn(e: unknown): RecordedTurn | undefined { + if (e instanceof MissingRecordingError || e instanceof ReplayNotFaithfulError) return undefined; + const thrown: ThrownTurn = e instanceof Error ? { name: e.name, message: e.message } : { name: 'Error', message: String(e) }; + return { replyText: '', toolCalls: [], meta: {}, thrown }; +} + /** * A replayed turn whose recorded writes the booted app did not answer as it * answered the recorded run, or that the recording cannot re-send faithfully. @@ -596,7 +642,8 @@ function remapIds(value: unknown, ids: ReadonlyMap): unknown { } /** - * Replays a {@link Recording}. A step it has no turn for is a loud error, never an empty turn. + * Replays a {@link Recording}. A step it has no turn for is a loud error, never an empty turn; + * a step whose live turn threw throws again ({@link RecordedThrowError}), with nothing re-sent. * Each ask of a repeated question turn is read by its own key ({@link stepKey}); * how many asks are read is the run's `--ask-repeats`, checked against what the * recording holds before any card runs ({@link RecordedDriver.assertAskRepeats}). @@ -702,6 +749,7 @@ export class RecordedDriver implements AgentDriver { const key = stepKey(task); const turn = this.recording.turns[key]; if (!turn) throw new MissingRecordingError(key); + if (turn.thrown) throw new RecordedThrowError(key, turn.thrown); const files = this.recording.files[key] ?? {}; const root = resolve(task.cwd); for (const [rel, content] of Object.entries(files)) { @@ -717,6 +765,7 @@ export class RecordedDriver implements AgentDriver { const key = stepKey(task); const turn = this.recording.turns[key]; if (!turn) throw new MissingRecordingError(key); + if (turn.thrown) throw new RecordedThrowError(key, turn.thrown); const writes = recordedWrites(turn); if (writes.length === 0 || task.callTool === undefined) return turn; const unanswered = writes.filter((c) => c.output === undefined); @@ -775,18 +824,36 @@ export class RecordingDriver implements AgentDriver { } async author(task: AuthorTask): Promise { - const r = await this.inner.author(task); + let r: AuthorResult; + try { + r = await this.inner.author(task); + } catch (e) { + this.recordThrow(task, e); + throw e; + } this.recording.turns[stepKey(task)] = r.turn; if (r.files) this.recording.files[stepKey(task)] = r.files; return r; } async ask(task: AskTask): Promise { - const t = await this.inner.ask(task); + let t: ParsedTurn; + try { + t = await this.inner.ask(task); + } catch (e) { + this.recordThrow(task, e); + throw e; + } this.recording.turns[stepKey(task)] = t; return t; } + /** A turn that threw is recorded as one ({@link RecordedTurn.thrown}), so its replay throws it again and counts as the run did. */ + private recordThrow(task: StepRef, e: unknown): void { + const turn = thrownTurn(e); + if (turn) this.recording.turns[stepKey(task)] = turn; + } + save(path: string): void { mkdirSync(dirname(path), { recursive: true }); writeFileSync(path, JSON.stringify(this.recording, null, 2)); diff --git a/packages/qa/scenarios/test/runner/ask-skills.test.ts b/packages/qa/scenarios/test/runner/ask-skills.test.ts index f470a153e23..171a8512030 100644 --- a/packages/qa/scenarios/test/runner/ask-skills.test.ts +++ b/packages/qa/scenarios/test/runner/ask-skills.test.ts @@ -20,6 +20,23 @@ import { ClaudeCodeDriver, RecordedDriver, RecordingDriver, type AgentDriver, ty import { renderSummaryTable, summaryTables, type SummaryRecord } from '../../src/runner/summary.js'; import type { ParsedTurn } from '../../src/runner/transcript.js'; +/** + * A case-insensitive filesystem (macOS, Windows), stood in for on any host: + * while `on`, `existsSync` answers a path true when its directory holds the + * name in any case, as such a filesystem does. Off, `node:fs` answers as ever. + */ +const caseInsensitive = vi.hoisted(() => ({ on: false })); +vi.mock('node:fs', async (importOriginal) => { + const fs = await importOriginal(); + const { basename, dirname } = await import('node:path'); + const anyCase = (p: string) => { + if (fs.existsSync(p)) return true; + const d = dirname(p); + return fs.existsSync(d) && fs.statSync(d).isDirectory() && fs.readdirSync(d).some((n) => n.toLowerCase() === basename(p).toLowerCase()); + }; + return { ...fs, existsSync: (p: import('node:fs').PathLike) => (caseInsensitive.on ? anyCase(String(p)) : fs.existsSync(p)) }; +}); + const SKILL_MD = '---\nname: ask-data\ndescription: Answer business questions through the governed datasets.\nmetadata:\n version: 1.2.0\n---\n\nCall list_datasets first.\n'; const root = mkdtempSync(join(tmpdir(), 'scenario-ask-skills-')); @@ -118,6 +135,47 @@ describe('readAskSkills — the directory read once, as the record states it', ( }); }); +describe('readAskSkills — a skill file is matched by its exact spelling, on every filesystem', () => { + afterEach(() => { + caseInsensitive.on = false; + }); + const onBoth = (check: () => void) => { + for (const on of [true, false]) { + caseInsensitive.on = on; + check(); + } + }; + + it('⛔ a skill directory whose file is spelled `skill.md` is refused, naming the file found and the spelling required', () => { + const dir = mkdtempSync(join(root, 'lower-')); + writeFileSync(join(dir, 'skill.md'), SKILL_MD); + onBoth(() => + expect(() => readAskSkills(dir)).toThrow( + `--ask-skills names \`${dir}\`, which holds \`skill.md\`: a skill file is spelled \`SKILL.md\` exactly, ` + + 'or a session reads it on one filesystem and misses it on another; rename it to `SKILL.md`', + ), + ); + }); + + it('⛔ in a directory of skills, one spelled `Skill.md` is refused by its path, never skipped while the others load', () => { + const dir = skillsDir(); + mkdirSync(join(dir, 'mixed')); + writeFileSync(join(dir, 'mixed', 'Skill.md'), '---\nname: mixed\n---\n'); + onBoth(() => expect(() => readAskSkills(dir)).toThrow(`--ask-skills names \`${dir}\`, which holds \`mixed/Skill.md\`: a skill file is spelled \`SKILL.md\` exactly`)); + }); + + it('a skill file spelled `SKILL.md` loads as before, on both filesystems', () => { + const dir = skillsDir(); + onBoth(() => { + expect(readAskSkills(dir).info.skills.map((s) => [s.name, s.version])).toEqual([ + ['ask-data', '1.2.0'], + ['fallback', '0.1'], + ]); + expect(readAskSkills(join(dir, 'ask-data')).info.skills.map((s) => s.name)).toEqual(['ask-data']); + }); + }); +}); + /** * A stand-in `claude`: `--version` and `auth status` as a subscription login * answers them; a turn answers its argument list and the skill files its diff --git a/packages/qa/scenarios/test/runner/orchestrate.test.ts b/packages/qa/scenarios/test/runner/orchestrate.test.ts index 187933cfd95..c5da3e0fb0c 100644 --- a/packages/qa/scenarios/test/runner/orchestrate.test.ts +++ b/packages/qa/scenarios/test/runner/orchestrate.test.ts @@ -3561,3 +3561,116 @@ describe('runHalf — a replay of a recording made before the card declared data expect(graded(half.questions)).toEqual(graded(run.modes[0]!.run!.questions)); }); }); + +// ── A live turn that throws: recorded as a failed turn, and replayed as the same failure ── + +/** Throws on the named question, dataset question and operation steps, as a live driver throws when a turn cannot run (`write EPIPE`). */ +class ThrowsOn implements AgentDriver { + constructor( + private readonly inner: AgentDriver, + private readonly steps: ReadonlySet, + ) {} + info(): DriverInfo { + return this.inner.info(); + } + author(task: AuthorTask) { + return this.inner.author(task); + } + async ask(task: AskTask): Promise { + if (this.steps.has(task.step)) throw new Error(`write EPIPE (${task.step})`); + return this.inner.ask(task); + } +} + +describe('runHalf — a live turn that throws is recorded as a failed turn, and its replay counts the row it counted live', () => { + const CARD = 'crm_account_with_contacts'; + const ref = { card: CARD, mode: 'ask', phase: 'run' } as const; + // A dataset question (a missing turn reads not measured there), a question and an operation. + const THROWN = new Set(['dq_staff', 'tech_accounts', 'add_contact']); + const recordLive = async () => { + const { ops, driver: scripted } = setup({ scenario: withDatasets() }); + const live = new RecordingDriver(new ThrowsOn(new DatasetRoutes(scripted), THROWN)); + const run = await runCard(withDatasets(), live, ops, { modes: ['ask'], admin: ADMIN, templateArtifact: artifact() }); + return { recording: JSON.parse(JSON.stringify(live.recording)) as Recording, half: run.modes[0]!.run! }; + }; + const replay = (recording: Recording) => runHalf(namespacedScenario(withDatasets()), new FakeApp(), new RecordedDriver(recording), ref, citationLabels(withDatasets())); + const counted = (rs: ReadonlyArray<{ question: string; persona?: string | null; error?: string; notMeasured?: string; grade?: unknown }>) => + rs.map((r) => ({ question: r.question, persona: r.persona, error: r.error, notMeasured: r.notMeasured, grade: r.grade })); + const thrownOp = (h: { operations: OperationResult[] }) => h.operations.filter((o) => o.operation === 'add_contact').map((o) => ({ error: o.error, notMeasured: o.notMeasured })); + const measuredQuestions = (qs: QuestionResult[]) => ({ total: qs.filter((q) => !q.notMeasured).length, notMeasured: qs.filter((q) => q.notMeasured).length }); + + it('the recording holds each thrown turn: an empty turn naming the error; a replay counts the same rows, the dataset question 1/2 as live, never 1/1', async () => { + const { recording, half: live } = await recordLive(); + expect(recording.turns[`${CARD}/ask/run/dq_staff/-`]).toEqual({ replyText: '', toolCalls: [], meta: {}, thrown: { name: 'Error', message: 'write EPIPE (dq_staff)' } }); + expect(recording.turns[`${CARD}/ask/run/add_contact/sdr`]!.thrown).toEqual({ name: 'Error', message: 'write EPIPE (add_contact)' }); + // Live, each throw is a counted failure. + expect(live.datasetQuestions!.find((q) => q.question === 'dq_staff')!.error).toBe('write EPIPE (dq_staff)'); + expect(datasetTally(live)).toMatchObject({ passed: 1, total: 2, notMeasured: 0 }); + + const replayed = await replay(recording); + expect(datasetTally(replayed)).toEqual(datasetTally(live)); + expect(counted(replayed.datasetQuestions!)).toEqual(counted(live.datasetQuestions!)); + expect(counted(replayed.questions)).toEqual(counted(live.questions)); + expect(measuredQuestions(replayed.questions)).toEqual(measuredQuestions(live.questions)); + expect(thrownOp(replayed)).toEqual([{ error: 'write EPIPE (add_contact)', notMeasured: undefined }]); + expect(thrownOp(replayed)).toEqual(thrownOp(live)); + }); + + it('a recording without the throw marker (made before throws were recorded) replays as it always did: no turn, so the dataset question is not measured', async () => { + const { recording } = await recordLive(); + const turns = Object.fromEntries(Object.entries(recording.turns).filter(([, t]) => t.thrown === undefined)); + expect(Object.keys(recording.turns).length - Object.keys(turns).length).toBe(THROWN.size); + const replayed = await replay({ ...recording, turns }); + const dq = replayed.datasetQuestions!.find((q) => q.question === 'dq_staff')!; + expect([typeof dq.notMeasured, dq.error, dq.grade]).toEqual(['string', undefined, undefined]); + expect(datasetTally(replayed)).toMatchObject({ passed: 1, total: 1, notMeasured: 1 }); + expect(replayed.questions.find((q) => q.question === 'tech_accounts')!.error).toBe(`no recorded turn for \`${CARD}/ask/run/tech_accounts/-\``); + }); + + it('the driver: a live throw is rethrown as it was thrown; a replay throws its name and message again, writes no file, and a recording of that replay holds the same turn', async () => { + const boom = new TypeError('spawn claude ENOENT'); + const inner: AgentDriver = { + info: () => ({ driver: 'live-stand-in', apiBilled: false }), + author: async () => { + throw boom; + }, + ask: async () => { + throw boom; + }, + }; + const live = new RecordingDriver(inner); + const askTask = { card: 'c', mode: 'scratch', phase: 'run', step: 'q', prompt: 'p', mcp: { url: 'http://x', apiKey: 'k' } } as const; + const authorTask = { card: 'c', mode: 'scratch', phase: 'build', step: 'author', prompt: 'p', cwd: mkdtempSync(join(tmpdir(), 'scenario-thrown-author-')), tier: 'control' } as const; + try { + await expect(live.ask(askTask)).rejects.toBe(boom); + await expect(live.author(authorTask)).rejects.toBe(boom); + const thrown = { name: 'TypeError', message: 'spawn claude ENOENT' }; + expect([live.recording.turns['c/scratch/run/q/-']!.thrown, live.recording.turns['c/scratch/build/author/-']!.thrown]).toEqual([thrown, thrown]); + expect(live.recording.files).toEqual({}); + + const again = new RecordingDriver(new RecordedDriver(JSON.parse(JSON.stringify(live.recording)) as Recording)); + for (const call of [() => again.ask(askTask), () => again.author(authorTask)]) { + const e = await call().then( + () => undefined, + (x: unknown) => x as Error, + ); + expect(e).toBeInstanceOf(Error); + expect([e!.name, e!.message, e instanceof ReplayNotFaithfulError]).toEqual(['TypeError', 'spawn claude ENOENT', false]); + } + expect(readdirSync(authorTask.cwd)).toEqual([]); + expect(again.recording.turns).toEqual(live.recording.turns); + } finally { + rmSync(authorTask.cwd, { recursive: true, force: true }); + } + }); + + it('a thrown authoring turn: its replay leaves the build not measured with the live error, not a missing-turn error', async () => { + const live = setup({ authorAs: { 'scratch/build': new TypeError('spawn claude ENOENT') } }); + const recorder = new RecordingDriver(live.driver); + const liveRun = await runCard(live.scenario, recorder, live.ops, { modes: ['scratch'], admin: ADMIN }); + const fresh = setup(); + const replayRun = await runCard(fresh.scenario, new RecordedDriver(JSON.parse(JSON.stringify(recorder.recording)) as Recording), fresh.ops, { modes: ['scratch'], admin: ADMIN }); + expect(liveRun.modes[0]!.build).toMatchObject({ error: 'author: spawn claude ENOENT', notMeasured: 'author turn failed: spawn claude ENOENT' }); + expect(replayRun.modes[0]!.build).toEqual(liveRun.modes[0]!.build); + }); +}); From 39e5ebab45c30c1a567f5e2e8be1bc2dafaf36a2 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 22:08:55 +0000 Subject: [PATCH 2/4] test(scenarios): the thrown-turn pins read the replayed tally first; the control builds the old recording by key Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH --- packages/qa/scenarios/test/runner/orchestrate.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/qa/scenarios/test/runner/orchestrate.test.ts b/packages/qa/scenarios/test/runner/orchestrate.test.ts index c5da3e0fb0c..8209eaff60c 100644 --- a/packages/qa/scenarios/test/runner/orchestrate.test.ts +++ b/packages/qa/scenarios/test/runner/orchestrate.test.ts @@ -3601,14 +3601,14 @@ describe('runHalf — a live turn that throws is recorded as a failed turn, and it('the recording holds each thrown turn: an empty turn naming the error; a replay counts the same rows, the dataset question 1/2 as live, never 1/1', async () => { const { recording, half: live } = await recordLive(); - expect(recording.turns[`${CARD}/ask/run/dq_staff/-`]).toEqual({ replyText: '', toolCalls: [], meta: {}, thrown: { name: 'Error', message: 'write EPIPE (dq_staff)' } }); - expect(recording.turns[`${CARD}/ask/run/add_contact/sdr`]!.thrown).toEqual({ name: 'Error', message: 'write EPIPE (add_contact)' }); // Live, each throw is a counted failure. expect(live.datasetQuestions!.find((q) => q.question === 'dq_staff')!.error).toBe('write EPIPE (dq_staff)'); expect(datasetTally(live)).toMatchObject({ passed: 1, total: 2, notMeasured: 0 }); const replayed = await replay(recording); expect(datasetTally(replayed)).toEqual(datasetTally(live)); + expect(recording.turns[`${CARD}/ask/run/dq_staff/-`]).toEqual({ replyText: '', toolCalls: [], meta: {}, thrown: { name: 'Error', message: 'write EPIPE (dq_staff)' } }); + expect(recording.turns[`${CARD}/ask/run/add_contact/sdr`]!.thrown).toEqual({ name: 'Error', message: 'write EPIPE (add_contact)' }); expect(counted(replayed.datasetQuestions!)).toEqual(counted(live.datasetQuestions!)); expect(counted(replayed.questions)).toEqual(counted(live.questions)); expect(measuredQuestions(replayed.questions)).toEqual(measuredQuestions(live.questions)); @@ -3618,8 +3618,8 @@ describe('runHalf — a live turn that throws is recorded as a failed turn, and it('a recording without the throw marker (made before throws were recorded) replays as it always did: no turn, so the dataset question is not measured', async () => { const { recording } = await recordLive(); - const turns = Object.fromEntries(Object.entries(recording.turns).filter(([, t]) => t.thrown === undefined)); - expect(Object.keys(recording.turns).length - Object.keys(turns).length).toBe(THROWN.size); + // The thrown steps' keys removed: the recording a run made before this change, which recorded nothing for a throw. + const turns = Object.fromEntries(Object.entries(recording.turns).filter(([key]) => !THROWN.has(key.split('/')[3]!))); const replayed = await replay({ ...recording, turns }); const dq = replayed.datasetQuestions!.find((q) => q.question === 'dq_staff')!; expect([typeof dq.notMeasured, dq.error, dq.grade]).toEqual(['string', undefined, undefined]); From 3644012a50212e8768fe2c256d813bdfdce5f4e7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 22:14:32 +0000 Subject: [PATCH 3/4] chore(scenarios): changeset for the thrown-turn recording and the skill-file spelling refusal Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH --- .changeset/34878-scenario-thrown-turn-skill-case.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .changeset/34878-scenario-thrown-turn-skill-case.md diff --git a/.changeset/34878-scenario-thrown-turn-skill-case.md b/.changeset/34878-scenario-thrown-turn-skill-case.md new file mode 100644 index 00000000000..6af87aaea54 --- /dev/null +++ b/.changeset/34878-scenario-thrown-turn-skill-case.md @@ -0,0 +1,11 @@ +--- +'@objectstack/scenarios': patch +--- + +fix(scenarios): a live turn that throws is recorded and replays as the same failure, and a skill file spelled otherwise than `SKILL.md` is refused by name + +Clause-②: no +Metadata-protocol: none + +- **A thrown turn is recorded.** When a live question, dataset question, operation, confirmation or authoring turn threw, the recording held nothing for it, so a replay met a missing turn. A dataset question or a confirmation turn reads a missing turn as not measured, so a row that showed 4/5 live could show 4/4 on replay. The recording now holds such a turn as an empty turn with `thrown: { name, message }`, and the live error is still thrown exactly as before. A replay throws an error with the same name and message again, writes no recorded file and re-sends no write, so the runner counts it exactly as it counted the live throw. A recording made before this change has no such turns and replays exactly as it did. A throw that is itself a replay's verdict (a missing or unfaithful recorded turn, when a replay is recorded) is still left unrecorded. +- **`--ask-skills` matches the skill file by its exact spelling.** The runner checked for `SKILL.md` with `existsSync`, which a case-insensitive filesystem answers true for `skill.md`. The run then crashed with `Cannot read properties of undefined (reading 'toString')`, and on a case-sensitive filesystem the skill was skipped without a word. The directory listing now decides. A skill directory whose file is spelled `skill.md`, `Skill.md` or any other case of `SKILL.md` is refused before any turn runs, with a sentence that names the file found and says to rename it to `SKILL.md`. This happens on every filesystem. From a0892887cc8251852c1602e3dd332a7141e72d58 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 22:54:40 +0000 Subject: [PATCH 4/4] chore(scenarios): the changeset declares the runner type widening Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH --- .changeset/34878-scenario-thrown-turn-skill-case.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/34878-scenario-thrown-turn-skill-case.md b/.changeset/34878-scenario-thrown-turn-skill-case.md index 6af87aaea54..5a5f1046977 100644 --- a/.changeset/34878-scenario-thrown-turn-skill-case.md +++ b/.changeset/34878-scenario-thrown-turn-skill-case.md @@ -4,7 +4,7 @@ fix(scenarios): a live turn that throws is recorded and replays as the same failure, and a skill file spelled otherwise than `SKILL.md` is refused by name -Clause-②: no +Clause-②: yes (widening: published @objectstack/scenarios ./runner types ThrownTurn, RecordedTurn and RecordedThrowError, plus one optional field on Recording.turns) Metadata-protocol: none - **A thrown turn is recorded.** When a live question, dataset question, operation, confirmation or authoring turn threw, the recording held nothing for it, so a replay met a missing turn. A dataset question or a confirmation turn reads a missing turn as not measured, so a row that showed 4/5 live could show 4/4 on replay. The recording now holds such a turn as an empty turn with `thrown: { name, message }`, and the live error is still thrown exactly as before. A replay throws an error with the same name and message again, writes no recorded file and re-sends no write, so the runner counts it exactly as it counted the live throw. A recording made before this change has no such turns and replays exactly as it did. A throw that is itself a replay's verdict (a missing or unfaithful recorded turn, when a replay is recorded) is still left unrecorded.