Skip to content

Commit a5054b0

Browse files
committed
fix(evals): seed the route baseline only on a clean pass
1 parent 5ee3e53 commit a5054b0

2 files changed

Lines changed: 58 additions & 8 deletions

File tree

‎scripts/eval-prompts-dispatch.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,55 @@ describe("drop baseline", () => {
246246
await rm(dir, { recursive: true, force: true });
247247
}
248248
});
249+
250+
test("a clean pass seeds a missing baseline and the next run compares", async () => {
251+
const dir = await mkdtemp(join(tmpdir(), "dispatch-routing-"));
252+
const baselinePath = join(dir, "baseline.json");
253+
const lastPath = join(dir, "last.json");
254+
try {
255+
const seeded = await evaluateRouting({
256+
cases: [coderCase],
257+
run: async () => "coder\nAdd a regression test for token refresh.",
258+
lastPath,
259+
baselinePath,
260+
});
261+
expect(seeded).toBe(0);
262+
const seededText = await readFile(baselinePath, "utf8");
263+
const parsed = JSON.parse(seededText) as {
264+
cases: { "fix-token-refresh": { routes: { pass: boolean } } };
265+
};
266+
expect(parsed.cases["fix-token-refresh"].routes.pass).toBe(true);
267+
268+
const dropped = await evaluateRouting({
269+
cases: [coderCase],
270+
run: async () => "reviewer\nI refuse.",
271+
lastPath,
272+
baselinePath,
273+
});
274+
expect(dropped).not.toBe(0);
275+
expect(await readFile(baselinePath, "utf8")).toBe(seededText);
276+
} finally {
277+
await rm(dir, { recursive: true, force: true });
278+
}
279+
});
280+
281+
test("a within-budget miss leaves an existing baseline unchanged", async () => {
282+
const dir = await mkdtemp(join(tmpdir(), "dispatch-routing-"));
283+
const baselinePath = join(dir, "baseline.json");
284+
const lastPath = join(dir, "last.json");
285+
const before = stored(false);
286+
await writeFile(baselinePath, before);
287+
try {
288+
const code = await evaluateRouting({
289+
cases: [coderCase],
290+
run: async () => "reviewer\nI refuse.",
291+
lastPath,
292+
baselinePath,
293+
});
294+
expect(code).toBe(0);
295+
expect(await readFile(baselinePath, "utf8")).toBe(before);
296+
} finally {
297+
await rm(dir, { recursive: true, force: true });
298+
}
299+
});
249300
});

‎scripts/eval-prompts-dispatch.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,13 @@ export async function evaluateRouting(args: {
238238
},
239239
});
240240
console.log(report.markdown());
241-
const routeMisses = report.checks["routes"]?.missed;
242-
if (!hadBaseline) {
243-
console.error(
244-
`eval "${DISPATCH_EVAL}" failed: no baseline at ${args.baselinePath}`,
245-
);
246-
return 1;
247-
}
248-
if (routeMisses !== 0) {
241+
if (report.checks["routes"]?.missed !== 0) {
242+
if (!hadBaseline) {
243+
console.error(
244+
`eval "${DISPATCH_EVAL}" failed: no baseline at ${args.baselinePath}`,
245+
);
246+
return 1;
247+
}
249248
return 0;
250249
}
251250
await copyFile(args.lastPath, args.baselinePath);

0 commit comments

Comments
 (0)