From 9bd05bdff11d94c62d8a3e55084c75bbd205a375 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Wed, 2 Dec 2026 16:49:31 -0800 Subject: [PATCH] fix(check): send recording replay scenarios inline from the branch The simulations API now accepts an inline transcriptReplay, with the same checks as saving a scenario. A check sends a replay scenario inline like any other, so a PR that edits a recording URL, answer key or WER threshold is tested with those edits, and the scenario needn't be deployed first. Drops the saved-UUID path and the pre-run comparison with the saved copy. The build now refuses what the platform would for a replay: chat transport, a squad target, hooks or latencyExpectations. A replay can run in a runOrg. Co-Authored-By: Claude Opus 5.5 --- docs/guides/pr-checks.md | 26 +++--- docs/learnings/simulations.md | 21 +++-- improvements.md | 20 ++-- src/check-mocks.ts | 33 +++---- src/check-payload.ts | 168 ++++++---------------------------- src/check-run.ts | 57 ++---------- tests/check-mocks.test.ts | 10 +- tests/check-payload.test.ts | 135 +++++++++------------------ tests/check-run.test.ts | 69 -------------- 9 files changed, 126 insertions(+), 413 deletions(-) diff --git a/docs/guides/pr-checks.md b/docs/guides/pr-checks.md index 08cd113..2ede935 100644 --- a/docs/guides/pr-checks.md +++ b/docs/guides/pr-checks.md @@ -65,21 +65,17 @@ personality instead. A scenario with `transcriptReplay` plays a fixed recording into the target and scores what its transcriber heard (see -[simulations learnings](../learnings/simulations.md#recording-replays)). The -simulations API runs a replay only from a **saved** scenario, so a check -sends a replay scenario by its UUID in the org, not from the branch. The -target is still built from the branch, which is what a replay tests. So: - -- The check needs `transport: voice`, and runs only in its own org (no - `runOrg`). -- Apply the scenario before the check can run it. The build fails for a - replay scenario that has never been deployed. -- Before a live run, the check reads each saved replay scenario. If the - file's `transcriptReplay`, `evaluations`, `latencyExpectations` or - `toolMocks` differ from the saved copy, the check stops with an error and - sends nothing: apply the scenario, then rerun. -- Replays are in a platform rollout. An org outside it gets a 400 from the - run. +[simulations learnings](../learnings/simulations.md#recording-replays)). Like +every other scenario, a check sends it inline from the branch, so a PR that +edits the recording URL, the answer key or the WER threshold is tested with +those edits, and the scenario needn't be deployed first. The build refuses +what the platform would: + +- The check needs `transport: voice` and an assistant target, not a squad. +- A replay scenario takes no `hooks` and no `latencyExpectations`. +- Replays are in a platform rollout. A run org outside it gets a 400 from + the run. An org or target assistant with HIPAA, PCI or zero data + retention must use `answerKeyUrl` instead of an inline `answerKey`. ## 3. Dry run locally (no key, nothing sent) diff --git a/docs/learnings/simulations.md b/docs/learnings/simulations.md index a3a4bbc..0114541 100644 --- a/docs/learnings/simulations.md +++ b/docs/learnings/simulations.md @@ -271,14 +271,12 @@ behaviours worth knowing when a check surprises you. default error mocks whether or not a tool was called; read tool results from `metadata.call.messages` (`tool_calls` carry the ids and names, `tool_call_result` the answers by `toolCallId`). -- **Replays go by saved UUID.** The run API rejects an inline - `transcriptReplay` ("An inline scenario cannot use transcriptReplay"), on - purpose: a replay must pass the checks that run when a scenario is saved, - and an answer key sent in a run request is never stored. So the check sends - `{type: "simulation", scenarioId, personality}` for a replay scenario, and - first compares the saved copy with the branch's file (see - [Recording replays](#recording-replays)). Replays mock every tool on the - platform by default, so the fail-closed tool rule still holds. +- **Replays go inline too.** The run API accepts an inline + `transcriptReplay` and applies the checks that run when a scenario is + saved, so the 400s match save's (see + [Recording replays](#recording-replays)). Before that change it refused + one ("An inline scenario cannot use transcriptReplay"), and a check had to + run the saved copy instead of the branch's. - **Runs are named by their entries.** The run API has no run-level name. The dashboard's runs table (and the runs list's `summary.source.name`) shows the entries' shared `name` when every entry has the same one (2 or @@ -319,8 +317,11 @@ transcriptReplay: required only when it says `required: true`. For HIPAA, PCI and zero-data-retention orgs, `value` is absent and only an `answerKeyUrl` can be saved. -- **Replays run only from a saved scenario**, by `scenarioId` or - `simulationId`, and the org must be in the replay rollout. +- **Replays run inline or saved**, and the org must be in the replay + rollout. Inline or saved, a replay needs the voice transport and a single + assistant target, takes only `wer` metric evaluations, and takes no + `hooks` or `latencyExpectations`. Omitted `instructions` and + `evaluations` are stored as `''` and `[]`. - **Host the recording at a fixed public URL**, and keep it fetchable for every future run. Presigned call-recording links expire after 30 minutes, and Vapi's file store rejects audio. A URL pinned to a commit SHA works. diff --git a/improvements.md b/improvements.md index bdf30ef..c0ff444 100644 --- a/improvements.md +++ b/improvements.md @@ -2401,18 +2401,20 @@ failing one, or a run failing only on a latency budget, showed no detail. ### Current behavior and mitigation -A check sends a replay scenario by its saved UUID, with the target still -built from the branch. It needs voice, its own org, and a deployed scenario. -Before a live run it reads each saved replay scenario and stops with an error -if the file's replay settings differ, so a branch edit isn't judged on the -old copy. The verdict reads `results.transcriptEvaluation` and -`results.latencyEvaluations`. +The platform now accepts an inline `transcriptReplay`, with save's checks, +so a check sends a replay scenario inline from the branch like any other. +The build refuses a replay over chat, against a squad, or with `hooks` or +`latencyExpectations`, as the platform does. The verdict reads +`results.transcriptEvaluation` and `results.latencyEvaluations`. + +Before inline replays shipped, a check ran the saved copy by UUID and +compared it with the branch's file first, so a PR that edited a replay was +never what ran. ### Risk -The exception to "what's in the files is what runs" is permanent unless the -platform starts accepting inline replays. The stale-copy comparison accepts -extra keys the platform adds, so a key removed from the file goes unnoticed. +A run org outside the replay rollout, or one where the inline-replay change +hasn't deployed, gets a 400 for the whole run. ### Status diff --git a/src/check-mocks.ts b/src/check-mocks.ts index 9806835..060c13b 100644 --- a/src/check-mocks.ts +++ b/src/check-mocks.ts @@ -436,12 +436,7 @@ export function checkMocksApply(args: CheckMocksArgs): void { walkObject(w, body.target, base); body.simulations.forEach((entry, index) => { const label = `simulations[${index}] (${entry.name})`; - // Only a transcript replay goes by scenarioId (see replayEntryBuild). Its - // saved copy can't take default mocks; the platform answers a replay's - // tool calls with a mock of its own, and the dead servers still apply. - if (entry.scenario === undefined && entry.scenarioId === undefined) - w.errors.push(`${label}: needs an inline scenario or a scenarioId`); - if (entry.scenario !== undefined && entry.scenarioId !== undefined) + if ("scenarioId" in entry) w.errors.push(`${label}: scenarios must be inline, not by scenarioId`); if ( entry.personalityId !== undefined && @@ -450,12 +445,11 @@ export function checkMocksApply(args: CheckMocksArgs): void { w.errors.push( `${label}: personalities must be inline or stock, not ${entry.personalityId}`, ); - if (entry.scenario) - walkObject(w, entry.scenario, { - ...base, - path: `${label}.scenario`, - where: "scenario", - }); + walkObject(w, entry.scenario, { + ...base, + path: `${label}.scenario`, + where: "scenario", + }); if (entry.personality) walkObject(w, entry.personality, { ...base, @@ -464,12 +458,11 @@ export function checkMocksApply(args: CheckMocksArgs): void { }); }); if (!w.strict) return; - body.simulations.forEach((entry, index) => { - if (entry.scenario) - defaultMocksAdd( - w, - entry.scenario, - `simulations[${index}] (${entry.name}).scenario`, - ); - }); + body.simulations.forEach((entry, index) => + defaultMocksAdd( + w, + entry.scenario, + `simulations[${index}] (${entry.name}).scenario`, + ), + ); } diff --git a/src/check-payload.ts b/src/check-payload.ts index a695a35..26a0df1 100644 --- a/src/check-payload.ts +++ b/src/check-payload.ts @@ -2,14 +2,13 @@ // from the PR branch's files: the target assistant or squad with its tools, // handoffs and structured outputs, plus every scenario, judge and // personality the check's suites and simulations name. Nothing is looked up -// on the platform — what's in the files is what runs — with one exception: -// the API runs a transcript replay only from a saved scenario, so a replay -// scenario is sent by its deployed UUID (replayEntryBuild). +// on the platform — what's in the files is what runs. // // Pure: inputs come from orgResourcesRead and promotionStateParse. Every // problem is collected, so one dry run reports them all. import type { CheckDefinition, CheckTarget } from "./check-config.ts"; +import { checkMocksApply } from "./check-mocks.ts"; import { assistantInline, assistantSelfRefs, @@ -29,7 +28,6 @@ import { refResolve, serverFieldsStrip, } from "./check-payload-refs.ts"; -import { checkMocksApply } from "./check-mocks.ts"; import { credentialForwardMap, replaceCredentialRefs } from "./credentials.ts"; import type { PromotionBindingsResolved } from "./promotion.ts"; import { promotionBindingsApply } from "./promotion.ts"; @@ -53,9 +51,7 @@ export interface CheckPayloadInput { export interface CheckSimulationEntry { type: "simulation"; name: string; - // Inline, except for a transcript replay, which goes by scenarioId. - scenario?: Record; - scenarioId?: string; + scenario: Record; personality?: Record; personalityId?: string; } @@ -69,21 +65,11 @@ export interface CheckRunBody { iterations: number; } -// A replay scenario the body runs by its saved UUID, with the branch file's -// replay settings, so a live run can first check the saved copy matches. -export interface CheckReplay { - // simulations/scenarios/ - scenario: string; - scenarioId: string; - expected: Record; -} - export interface CheckPayloadResult { body?: CheckRunBody; errors: string[]; warnings: string[]; bytes: number; - replays?: CheckReplay[]; } export const MAX_PAYLOAD_BYTES = 4.5 * 1024 * 1024; @@ -377,7 +363,6 @@ function personalityBuild( function entriesBuild( ctx: CheckPayloadContext, check: CheckDefinition, - replays: CheckReplay[], ): CheckSimulationEntry[] { const entries: CheckSimulationEntry[] = []; const used = new Set(); @@ -400,24 +385,9 @@ function entriesBuild( continue; } const scenarioLabel = `simulations/scenarios/${scenarioFile.id}`; - if (isObject(scenarioFile.data.transcriptReplay)) { - const entry = replayEntryBuild(ctx, { - check, - scenarioFile, - simulation, - label, - }); - if (!entry) continue; - entries.push({ ...entry, name: entryName(entry.name, used) }); - if (!replays.some((replay) => replay.scenarioId === entry.scenarioId)) - replays.push({ - scenario: scenarioLabel, - scenarioId: entry.scenarioId!, - expected: replayComparedPick(scenarioFile.data), - }); - continue; - } const scenario = serverFieldsStrip(scenarioFile.data); + if (isObject(scenario.transcriptReplay)) + replayRulesCheck(ctx, check, scenario, scenarioLabel); judgesInline(ctx, scenario, scenarioLabel); if (isObject(scenario.targetOverrides)) overridesProcess( @@ -448,110 +418,35 @@ function entriesBuild( return entries; } -interface ReplayEntryArgs { - check: CheckDefinition; - scenarioFile: OrgResource; - simulation: OrgResource; - label: string; -} - -// POST /eval/simulation/run rejects an inline transcriptReplay ("Save the -// scenario, then run it by simulationId or scenarioId"), so a replay runs the -// copy saved in the org. The target is still built from the branch, which is -// what a replay tests: the branch's transcriber against a fixed recording. -function replayEntryBuild( +// The platform runs a transcript replay only over voice against a single +// assistant, and refuses a replay scenario with a tester's settings. Checked +// here so a dry run reports what a live run's 400 would. +function replayRulesCheck( ctx: CheckPayloadContext, - { check, scenarioFile, simulation, label }: ReplayEntryArgs, -): CheckSimulationEntry | undefined { - const scenarioLabel = `simulations/scenarios/${scenarioFile.id}`; - if (check.transport !== "voice") { - ctx.errors.push( - `${scenarioLabel}: a transcriptReplay scenario needs transport: voice`, - ); - return undefined; - } - if (check.runOrg !== check.org) { + check: CheckDefinition, + scenario: Record, + label: string, +): void { + if (check.transport !== "voice") ctx.errors.push( - `${scenarioLabel}: a transcriptReplay scenario runs only in its own org (${check.org}), not runOrg ${check.runOrg}`, + `${label}: a transcriptReplay scenario needs transport: voice`, ); - return undefined; - } - const uuid = ctx.sourceState.scenarios[scenarioFile.id]?.uuid; - if (!uuid) { + if (ctx.targetMembers) ctx.errors.push( - `${scenarioLabel}: a transcriptReplay scenario runs from its saved copy; apply it to ${check.org} first`, + `${label}: a transcriptReplay scenario runs only against an assistant, not a squad`, ); - return undefined; - } - ctx.warnings.push( - `${scenarioLabel}: transcriptReplay runs the copy saved in ${check.org}; a live check fails if this file's replay settings differ from it, until you apply`, - ); - const personality = personalityBuild( - ctx, - simulation.data.personalityId, - `${label}.personalityId`, - ); - if (!personality) return undefined; - const name = - typeof simulation.data.name === "string" - ? simulation.data.name - : simulation.id; - return { type: "simulation", name, scenarioId: uuid, ...personality }; -} - -// The scenario settings that decide a replay's result. None hold a -// reference: a replay takes only metric evaluations. -const REPLAY_COMPARED_KEYS = [ - "transcriptReplay", - "evaluations", - "latencyExpectations", - "toolMocks", -] as const; - -function replayComparedPick( - data: Record, -): Record { - const picked: Record = {}; - for (const key of REPLAY_COMPARED_KEYS) - if (data[key] !== undefined) picked[key] = clone(data[key]); - return picked; + for (const key of ["hooks", "latencyExpectations"]) + if (!isEmpty(scenario[key])) + ctx.errors.push( + `${label}.${key}: a transcriptReplay scenario takes none`, + ); } function isEmpty(value: unknown): boolean { - if (value === undefined || value === null) return true; - if (Array.isArray(value)) return value.length === 0; - return isObject(value) && Object.keys(value).length === 0; -} - -// Whether the saved value holds everything the file says. The platform can -// add defaults the file leaves out, so extra saved keys don't count; arrays -// must match item for item. -function savedCovers(local: unknown, saved: unknown): boolean { - if (isEmpty(local) && isEmpty(saved)) return true; - if (Array.isArray(local)) - return ( - Array.isArray(saved) && - saved.length === local.length && - local.every((item, index) => savedCovers(item, saved[index])) - ); - if (isObject(local)) - return ( - isObject(saved) && - Object.entries(local).every( - ([key, value]) => value === undefined || savedCovers(value, saved[key]), - ) - ); - return local === saved; -} - -// The replay settings where the branch's file and the saved scenario -// differ, for checkRunAll to refuse a run that would test a stale copy. -export function replayDifferences( - replay: CheckReplay, - saved: Record, -): string[] { - return REPLAY_COMPARED_KEYS.filter( - (key) => !savedCovers(replay.expected[key], saved[key]), + return ( + value === undefined || + value === null || + (Array.isArray(value) && value.length === 0) ); } @@ -658,8 +553,7 @@ export function checkPayloadBuild( warnings: [], }; const target = targetBuild(ctx, input.target); - const replays: CheckReplay[] = []; - const simulations = entriesBuild(ctx, input.check, replays); + const simulations = entriesBuild(ctx, input.check); const label = runLabelBuild(input); // The dashboard labels a run with its entries' name only when they all // share it; each item still shows its own scenario and personality. @@ -696,11 +590,5 @@ export function checkPayloadBuild( ); if (ctx.errors.length > 0) return { errors: ctx.errors, warnings: ctx.warnings, bytes }; - return { - body, - errors: [], - warnings: ctx.warnings, - bytes, - ...(replays.length > 0 ? { replays } : {}), - }; + return { body, errors: [], warnings: ctx.warnings, bytes }; } diff --git a/src/check-run.ts b/src/check-run.ts index 71eddc4..4203a70 100644 --- a/src/check-run.ts +++ b/src/check-run.ts @@ -5,8 +5,6 @@ import type { CheckJob } from "./check-build.ts"; import { MOCK_MARKER } from "./check-mocks.ts"; -import type { CheckReplay } from "./check-payload.ts"; -import { replayDifferences } from "./check-payload.ts"; import type { CommitState } from "./check-status.ts"; import type { SimRunExecuteOptions } from "./sim.ts"; import { simRunExecute } from "./sim.ts"; @@ -17,7 +15,7 @@ import type { } from "./sim-result.ts"; import { simRunItemLabels } from "./sim-result.ts"; import type { VapiConnection } from "./vapi-client.ts"; -import { VapiApiError, vapiFetchJson } from "./vapi-client.ts"; +import { VapiApiError } from "./vapi-client.ts"; // passed / failed / incomplete come from the run's verdict; error is a // config or build problem (nothing was sent); built is a dry run's success. @@ -91,43 +89,6 @@ export function mockNoticesCollect(items: SimRunItem[]): string[] { return [...notices]; } -// A replay runs the scenario saved in the org (see replayEntryBuild), so -// a branch that edits one would otherwise be judged on the old copy. Each -// stale or missing scenario becomes a failure row. -async function replaysStaleFind( - connection: VapiConnection, - replays: CheckReplay[], -): Promise { - const stale: SimRunFailure[] = []; - for (const replay of replays) { - let saved: Record; - try { - saved = await vapiFetchJson>( - connection, - "GET", - `/eval/simulation/scenario/${replay.scenarioId}`, - ); - } catch (error) { - if (!(error instanceof VapiApiError && error.statusCode === 404)) - throw error; - stale.push({ - item: replay.scenario, - evaluation: "saved replay scenario", - reason: `${replay.scenarioId} no longer exists; apply the scenario first`, - }); - continue; - } - const differences = replayDifferences(replay, saved); - if (differences.length > 0) - stale.push({ - item: replay.scenario, - evaluation: "saved replay scenario", - reason: `the file's ${differences.join(", ")} ${differences.length === 1 ? "differs" : "differ"} from the saved copy, which is what runs; apply the scenario first`, - }); - } - return stale; -} - function errorReason(error: unknown): string { if (error instanceof VapiApiError && error.statusCode === 402) return `billing: the run org can't start simulations (402: ${error.apiMessage})`; @@ -172,17 +133,11 @@ async function jobRun( }, }; try { - const connection = args.connectionFor(job); - const stale = await replaysStaleFind(connection, job.result.replays ?? []); - if (stale.length > 0) - return { - ...base, - outcome: "error", - reason: `${stale.length} replay scenario${stale.length === 1 ? " doesn't" : "s don't"} match the saved copy that would run; nothing was sent`, - failures: stale, - durationMs: Date.now() - start, - }; - const { summary, items } = await simRunExecute(connection, body, options); + const { summary, items } = await simRunExecute( + args.connectionFor(job), + body, + options, + ); const verdict = summary.verdict; return { job, diff --git a/tests/check-mocks.test.ts b/tests/check-mocks.test.ts index 0663eac..6f3c586 100644 --- a/tests/check-mocks.test.ts +++ b/tests/check-mocks.test.ts @@ -100,7 +100,7 @@ test("function tools get the dead server and a default error mock in every scena [ result.errors, toolsOf(result.body), - result.body.simulations[0]!.scenario!.toolMocks, + result.body.simulations[0]!.scenario.toolMocks, ], [ [], @@ -134,7 +134,7 @@ test("scenario mocks are kept, disabled ones are replaced, and mocks for unknown }, }); assert.deepEqual( - [result.body.simulations[0]!.scenario!.toolMocks, result.warnings], + [result.body.simulations[0]!.scenario.toolMocks, result.warnings], [ [ { toolName: "book", result: '{"ok":true}', enabled: true }, @@ -169,7 +169,7 @@ test("apiRequest tools are mocked by their top-level name and point at the dead [ toolsOf(result.body), ( - result.body.simulations[0]!.scenario!.toolMocks as Array<{ + result.body.simulations[0]!.scenario.toolMocks as Array<{ toolName: string; }> ).map((m) => m.toolName), @@ -560,7 +560,7 @@ test("scenario webhook hooks point at the dead server", () => { toolMocks: [], }, }); - assert.deepEqual(result.body.simulations[0]!.scenario!.hooks, [ + assert.deepEqual(result.body.simulations[0]!.scenario.hooks, [ { on: "call.ended", do: [{ type: "webhook", server: DEAD }] }, ]); }); @@ -653,7 +653,7 @@ test("toolMocks off sends tools as written; stripWebhooks still replaces assista result.errors, (target.model as { tools: unknown }).tools, target.server, - result.body.simulations[0]!.scenario!.toolMocks, + result.body.simulations[0]!.scenario.toolMocks, ], [[], tools, DEAD, []], ); diff --git a/tests/check-payload.test.ts b/tests/check-payload.test.ts index 7a955c5..73e5192 100644 --- a/tests/check-payload.test.ts +++ b/tests/check-payload.test.ts @@ -8,7 +8,7 @@ import { fileURLToPath } from "node:url"; import type { CheckDefinition, CheckTarget } from "../src/check-config.ts"; import { checksConfigParse } from "../src/check-config.ts"; import type { CheckPayloadResult } from "../src/check-payload.ts"; -import { checkPayloadBuild, replayDifferences } from "../src/check-payload.ts"; +import { checkPayloadBuild } from "../src/check-payload.ts"; import { promotionStateParse } from "../src/promotion.ts"; import { orgResourcesRead } from "../src/resource-parse.ts"; import type { StateFile } from "../src/types.ts"; @@ -583,73 +583,73 @@ test("payloads above 4.5 MB fail", async () => { assert.deepEqual(result.errors, ["payload is 5.0 MB; the limit is 4.5 MB"]); }); -test("transcriptReplay scenarios go by their saved UUID over voice, and fail over chat, in a runOrg or undeployed", async () => { +test("transcriptReplay scenarios go inline from the branch over voice, in any run org, and fail over chat, against a squad or with tester settings", async () => { + const replay = + "name: Replay\nevaluations:\n - metric: wer\n comparator: '<='\n value: 0.2\ntranscriptReplay:\n recordingUrl: https://example.com/a.wav\n answerKey:\n transcript: Hello there.\n"; const files = { "assistants/main.yml": MAIN(""), - "simulations/scenarios/replay.yml": - "name: Replay\nevaluations:\n - metric: wer\n comparator: '<='\n value: 0.2\ntranscriptReplay:\n recordingUrl: https://example.com/a.wav\n answerKey:\n transcript: Hello there.\n", + "simulations/scenarios/replay.yml": replay, "simulations/tests/t2.yml": `name: T2\npersonalityId: ${STOCK_PERSONALITY}\nscenarioId: replay\n`, "simulations/suites/core.yml": "name: Core\nsimulationIds: [t1, t2]\n", }; - const saved = { - scenarios: { replay: { uuid: UUID_A } }, - } as Partial; + // Deployed, but the branch's copy is what runs. const voice = await build({ files, check: " transport: voice\n", - sourceState: saved, + sourceState: { scenarios: { replay: { uuid: UUID_A } } }, }); - const chat = await build({ files, sourceState: saved }); - const undeployed = await build({ files, check: " transport: voice\n" }); const ciOrg = await build({ files, check: " transport: voice\n runOrg: acme-ci\n", - sourceState: saved, }); + const chat = await build({ files }); + const squad = await build({ + files: { + ...files, + "squads/team.yml": "name: Team\nmembers:\n - assistantId: main\n", + }, + target: "squads/team", + check: " transport: voice\n", + }); + const tester = await build({ + files: { + ...files, + "simulations/scenarios/replay.yml": `${replay}hooks:\n - on: call.ended\n do: []\nlatencyExpectations:\n - metric: turn\n aggregation: median\n thresholdMs: 1500\n`, + }, + check: " transport: voice\n", + }); + const replayEntry = voice.body?.simulations[1]; assert.deepEqual( [ voice.errors, voice.warnings, - voice.body?.simulations.map((e) => [ - e.name, - e.scenarioId, - e.scenario?.name, - ]), - voice.replays, - chat.errors, - undeployed.errors, + replayEntry && "scenarioId" in replayEntry, + replayEntry?.scenario.transcriptReplay, + replayEntry?.scenario.evaluations, ciOrg.errors, + chat.errors, + squad.errors, + tester.errors, ], [ [], - [ - "simulations/scenarios/replay: transcriptReplay runs the copy saved in acme; a live check fails if this file's replay settings differ from it, until you apply", - ], - [ - ["T1", undefined, "S1"], - ["T2", UUID_A, undefined], - ], - [ - { - scenario: "simulations/scenarios/replay", - scenarioId: UUID_A, - expected: { - transcriptReplay: { - recordingUrl: "https://example.com/a.wav", - answerKey: { transcript: "Hello there." }, - }, - evaluations: [{ metric: "wer", comparator: "<=", value: 0.2 }], - }, - }, - ], + [], + false, + { + recordingUrl: "https://example.com/a.wav", + answerKey: { transcript: "Hello there." }, + }, + [{ metric: "wer", comparator: "<=", value: 0.2 }], + [], [ "simulations/scenarios/replay: a transcriptReplay scenario needs transport: voice", ], [ - "simulations/scenarios/replay: a transcriptReplay scenario runs from its saved copy; apply it to acme first", + "simulations/scenarios/replay: a transcriptReplay scenario runs only against an assistant, not a squad", ], [ - "simulations/scenarios/replay: a transcriptReplay scenario runs only in its own org (acme), not runOrg acme-ci", + "simulations/scenarios/replay.hooks: a transcriptReplay scenario takes none", + "simulations/scenarios/replay.latencyExpectations: a transcriptReplay scenario takes none", ], ], ); @@ -699,56 +699,3 @@ test("a check label names every simulation in the run, with the label context ap rmSync(root, { recursive: true, force: true }); } }); - -test("replayDifferences: names the replay settings the saved copy doesn't hold", () => { - const replay = { - scenario: "simulations/scenarios/replay", - scenarioId: UUID_A, - expected: { - transcriptReplay: { - recordingUrl: "https://example.com/a.wav", - answerKey: { - transcript: "Hello there.", - keyValues: [{ value: "there", required: true }], - }, - }, - evaluations: [{ metric: "wer", comparator: "<=", value: 0.2 }], - toolMocks: [], - }, - }; - const saved = { - id: UUID_A, - name: "Replay", - transcriptReplay: { - recordingUrl: "https://example.com/a.wav", - answerKey: { - transcript: "Hello there.", - keyValues: [{ value: "there", required: true, acceptedVariants: [] }], - }, - }, - evaluations: [ - { metric: "wer", comparator: "<=", value: 0.2, required: true }, - ], - }; - // Defaults the platform adds, and an empty list the file spells out, match. - assert.deepEqual(replayDifferences(replay, saved), []); - const edited = structuredClone(saved); - edited.transcriptReplay.answerKey.transcript = "Hello."; - edited.evaluations.push({ - metric: "wer", - comparator: "<=", - value: 0.5, - required: true, - }); - assert.deepEqual(replayDifferences(replay, edited), [ - "transcriptReplay", - "evaluations", - ]); - assert.deepEqual( - replayDifferences(replay, { - ...saved, - toolMocks: [{ toolName: "lookup", result: "{}" }], - }), - ["toolMocks"], - ); -}); diff --git a/tests/check-run.test.ts b/tests/check-run.test.ts index 330ce59..1faa07d 100644 --- a/tests/check-run.test.ts +++ b/tests/check-run.test.ts @@ -37,8 +37,6 @@ interface Stub { requests: string[]; userAgents: Set; maxActive: number; - // Saved scenarios by UUID, for the replay check. - scenarios: Map>; } const DEADLINE_FAR = () => Date.now() + 60 * 60_000; @@ -105,7 +103,6 @@ async function withStub(fn: (stub: Stub) => Promise): Promise { requests: [], userAgents: new Set(), maxActive: 0, - scenarios: new Map(), }; const active = () => [...runs.values()].filter((run) => !run.ended).length; const server = createServer((req, res) => { @@ -148,13 +145,6 @@ async function withStub(fn: (stub: Stub) => Promise): Promise { ), }); } - const scenario = url.match(/^\/eval\/simulation\/scenario\/(.+)$/); - if (req.method === "GET" && scenario) { - const saved = stub.scenarios.get(scenario[1]!); - return saved - ? reply(200, saved) - : reply(404, { message: "Scenario not found" }); - } const match = url.match(/^\/eval\/simulation\/run\/(run-\d+)(\/item)?/); const run = match ? runs.get(match[1]!) : undefined; if (!run) return reply(404, { message: "not found" }); @@ -431,62 +421,3 @@ test("at most three runs are in flight, and results come back in job order", asy ); }); }); - -test("a replay whose saved copy differs from the branch, or is gone, is an error and sends nothing", async () => { - await withStub(async (stub) => { - const expected = { - transcriptReplay: { - recordingUrl: "https://example.com/a.wav", - answerKey: { transcript: "Hello there." }, - }, - }; - stub.scenarios.set("saved-same", { id: "saved-same", ...expected }); - stub.scenarios.set("saved-old", { - id: "saved-old", - transcriptReplay: { - recordingUrl: "https://example.com/a.wav", - answerKey: { transcript: "Hello." }, - }, - }); - const replayJob = (name: string, scenarioIds: string[]) => { - const built = job(name); - built.result.replays = scenarioIds.map((scenarioId) => ({ - scenario: `simulations/scenarios/${scenarioId}`, - scenarioId, - expected, - })); - return built; - }; - const [same, stale] = await checkRunAll( - runArgs(stub, [ - replayJob("pass", ["saved-same"]), - replayJob("pass", ["saved-old", "saved-gone"]), - ]), - ); - assert.deepEqual( - [ - same!.outcome, - stale!.outcome, - stale!.reason, - stale!.failures.map((failure) => [failure.item, failure.reason]), - stub.requests.filter((r) => r === "POST /eval/simulation/run").length, - ], - [ - "passed", - "error", - "2 replay scenarios don't match the saved copy that would run; nothing was sent", - [ - [ - "simulations/scenarios/saved-old", - "the file's transcriptReplay differs from the saved copy, which is what runs; apply the scenario first", - ], - [ - "simulations/scenarios/saved-gone", - "saved-gone no longer exists; apply the scenario first", - ], - ], - 1, - ], - ); - }); -});