Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Split prompt + image-only turns match `userMessage` on Anthropic, Gemini, Bedrock, Cohere (#643)
- Split prompt + image-only turns match `userMessage` on Gemini Live too (#648)
- `llmock` now errors on blank `--port`/`--host`/`--latency`/... values instead of starting (#644)
- Stale fixtures served via the OpenRouter `models` fallback get `staleFixture` and a warning (#651)

## [1.48.1] - 2026-11-20

Expand Down
34 changes: 34 additions & 0 deletions src/__tests__/stale-fixture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,40 @@ describe("stale fixture detection (#638)", () => {
expect(r.entry.response).not.toHaveProperty("staleFixture");
expect(staleWarnings(r.warnings)).toEqual([]);
});

it("flags a stale fixture served through the OpenRouter models fallback (#647)", async () => {
const route = "/api/v1/chat/completions";
const fixtures = await record("/v1/chat/completions", openaiBody(RECORDED));
const expected = fixtures[0].metadata?.requestHash;
// The primary model has no fixture; the second candidate matches the recording.
const viaFallback = (refundResult: string) =>
JSON.stringify({
...openaiBody(refundResult, "missing-model"),
models: ["missing-model", "gpt-5"],
});

const single = await replay(
fixtures,
"/v1/chat/completions",
JSON.stringify(openaiBody(CHANGED)),
);
const r = await replay(fixtures, route, viaFallback(CHANGED));
expect(r.status).toBe(200);
expect(r.body.includes("refunded $500")).toBe(true);
expect(r.entry.response.fixture).not.toBeNull();
// Hashed with the winning candidate's model, so it matches the plain request.
expect(r.entry.response.staleFixture).toEqual(single.entry.response.staleFixture);
expect(r.entry.response.staleFixture?.expected).toBe(expected);
const lines = staleWarnings(r.warnings);
expect(lines).toHaveLength(1);
expect(lines[0]).toContain(String(expected));

// The unchanged request served by the same fallback candidate is not stale.
const clean = await replay(fixtures, route, viaFallback(RECORDED));
expect(clean.status).toBe(200);
expect(clean.entry.response).not.toHaveProperty("staleFixture");
expect(staleWarnings(clean.warnings)).toEqual([]);
});
});

// ─── Tool calls without ids: converters make up random ids ──────────────────
Expand Down
10 changes: 10 additions & 0 deletions src/request-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ export function noteStaleFixture(
else staleMarks.set(req, { fixture, expected, actual });
}

/**
* Give `to` the stale mark of `from` (or clear it when `from` has none). Used
* when the matched request is a copy of the object that gets journaled.
*/
export function copyStaleFixtureMark(from: object, to: object): void {
const mark = staleMarks.get(from);
if (mark) staleMarks.set(to, mark);
else staleMarks.delete(to);
}

/**
* The stale mark for a journaled request body, when `fixture` is the fixture
* the mark was made for. Returns undefined otherwise.
Expand Down
5 changes: 5 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
resolveMisbehaviorShortCircuit,
} from "./misbehavior.js";
import { Journal } from "./journal.js";
import { copyStaleFixtureMark } from "./request-hash.js";
import { matchFixtureDiagnostic, recordMatchOptions, type MatchOptions } from "./router.js";
import {
validateFixtures,
Expand Down Expand Up @@ -1981,6 +1982,10 @@ async function handleCompletions(
const attempt = selectFixture(probe, matchCounts);
skippedBySequenceOrTurn = Math.max(skippedBySequenceOrTurn, attempt.skippedBySequenceOrTurn);
if (!attempt.fixture) return null;
// The journal looks the stale mark up on `body`, not on this copy. The
// served fixture is always the last candidate that matched, so the last
// copy wins.
copyStaleFixtureMark(probe, body);
const response = await resolveResponse(attempt.fixture, probe);
// A raw fixture with an error status is a provider failure, like a typed
// error fixture with the same status, so it fails over the same way.
Expand Down
Loading