Skip to content

Commit d71b7d3

Browse files
committed
fix: thread recordMatchOptions/logger through record-path handlers
Pass recordMatchOptions and the logger through the server record path into each provider handler (messages, responses, gemini, bedrock, bedrock-converse, cohere, ollama) so recorded fixtures carry the content-anchored match metadata.
1 parent 0468c80 commit d71b7d3

8 files changed

Lines changed: 61 additions & 8 deletions

File tree

src/bedrock-converse.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
strictNoMatchMessage,
3535
strictNoMatchLogLine,
3636
} from "./helpers.js";
37-
import { matchFixtureDiagnostic } from "./router.js";
37+
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
3838
import { writeErrorResponse } from "./sse-writer.js";
3939
import { writeEventStream } from "./aws-event-stream.js";
4040
import { createInterruptionSignal } from "./interruption.js";
@@ -608,6 +608,10 @@ export async function handleConverse(
608608
completionReq,
609609
journal.getFixtureMatchCountsForTest(testId),
610610
defaults.requestTransform,
611+
// Record mode proxies on a miss to capture a fresh turn (see record gate
612+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
613+
// shadowing a longer request and skipping the new turn's recording.
614+
recordMatchOptions(!!defaults.record, defaults.logger),
611615
);
612616

613617
if (fixture) {
@@ -920,6 +924,10 @@ export async function handleConverseStream(
920924
completionReq,
921925
journal.getFixtureMatchCountsForTest(testId),
922926
defaults.requestTransform,
927+
// Record mode proxies on a miss to capture a fresh turn (see record gate
928+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
929+
// shadowing a longer request and skipping the new turn's recording.
930+
recordMatchOptions(!!defaults.record, defaults.logger),
923931
);
924932

925933
if (fixture) {

src/bedrock.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
strictNoMatchMessage,
4646
strictNoMatchLogLine,
4747
} from "./helpers.js";
48-
import { matchFixtureDiagnostic } from "./router.js";
48+
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
4949
import { writeErrorResponse } from "./sse-writer.js";
5050
import { writeEventStream } from "./aws-event-stream.js";
5151
import { createInterruptionSignal } from "./interruption.js";
@@ -407,6 +407,10 @@ export async function handleBedrock(
407407
completionReq,
408408
journal.getFixtureMatchCountsForTest(testId),
409409
defaults.requestTransform,
410+
// Record mode proxies on a miss to capture a fresh turn (see record gate
411+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
412+
// shadowing a longer request and skipping the new turn's recording.
413+
recordMatchOptions(!!defaults.record, defaults.logger),
410414
);
411415

412416
if (fixture) {
@@ -1114,6 +1118,10 @@ export async function handleBedrockStream(
11141118
completionReq,
11151119
journal.getFixtureMatchCountsForTest(testId),
11161120
defaults.requestTransform,
1121+
// Record mode proxies on a miss to capture a fresh turn (see record gate
1122+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
1123+
// shadowing a longer request and skipping the new turn's recording.
1124+
recordMatchOptions(!!defaults.record, defaults.logger),
11171125
);
11181126

11191127
if (fixture) {

src/cohere.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
strictNoMatchMessage,
4343
strictNoMatchLogLine,
4444
} from "./helpers.js";
45-
import { matchFixtureDiagnostic } from "./router.js";
45+
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
4646
import { writeErrorResponse, delay, calculateDelay } from "./sse-writer.js";
4747
import { createInterruptionSignal } from "./interruption.js";
4848
import type { Journal } from "./journal.js";
@@ -871,6 +871,10 @@ export async function handleCohere(
871871
completionReq,
872872
journal.getFixtureMatchCountsForTest(testId),
873873
defaults.requestTransform,
874+
// Record mode proxies on a miss to capture a fresh turn (see record gate
875+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
876+
// shadowing a longer request and skipping the new turn's recording.
877+
recordMatchOptions(!!defaults.record, defaults.logger),
874878
);
875879

876880
if (fixture) {
@@ -1300,6 +1304,10 @@ export async function handleCohereEmbed(
13001304
syntheticReq,
13011305
journal.getFixtureMatchCountsForTest(testId),
13021306
defaults.requestTransform,
1307+
// Record mode proxies on a miss to capture a fresh turn (see record gate
1308+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
1309+
// shadowing a longer request and skipping the new turn's recording.
1310+
recordMatchOptions(!!defaults.record, defaults.logger),
13031311
);
13041312

13051313
if (fixture) {

src/gemini.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
strictNoMatchMessage,
3939
strictNoMatchLogLine,
4040
} from "./helpers.js";
41-
import { matchFixtureDiagnostic } from "./router.js";
41+
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
4242
import { writeErrorResponse, delay, calculateDelay } from "./sse-writer.js";
4343
import { createInterruptionSignal } from "./interruption.js";
4444
import type { Journal } from "./journal.js";
@@ -708,6 +708,10 @@ export async function handleGemini(
708708
completionReq,
709709
journal.getFixtureMatchCountsForTest(testId),
710710
defaults.requestTransform,
711+
// Record mode proxies on a miss to capture a fresh turn (see record gate
712+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
713+
// shadowing a longer request and skipping the new turn's recording.
714+
recordMatchOptions(!!defaults.record, defaults.logger),
711715
);
712716
const path = req.url ?? `/v1beta/models/${model}:generateContent`;
713717

src/messages.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
strictNoMatchMessage,
3838
strictNoMatchLogLine,
3939
} from "./helpers.js";
40-
import { matchFixtureDiagnostic } from "./router.js";
40+
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
4141
import { writeErrorResponse, delay, calculateDelay } from "./sse-writer.js";
4242
import { createInterruptionSignal } from "./interruption.js";
4343
import type { Journal } from "./journal.js";
@@ -1152,6 +1152,10 @@ export async function handleMessages(
11521152
completionReq,
11531153
journal.getFixtureMatchCountsForTest(testId),
11541154
defaults.requestTransform,
1155+
// Record mode proxies on a miss to capture a fresh turn (see record gate
1156+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
1157+
// shadowing a longer request and skipping the new turn's recording.
1158+
recordMatchOptions(!!defaults.record, defaults.logger),
11551159
);
11561160

11571161
if (fixture) {

src/ollama.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
strictNoMatchMessage,
4141
strictNoMatchLogLine,
4242
} from "./helpers.js";
43-
import { matchFixtureDiagnostic } from "./router.js";
43+
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
4444
import { writeErrorResponse } from "./sse-writer.js";
4545
import { writeNDJSONStream } from "./ndjson-writer.js";
4646
import { createInterruptionSignal } from "./interruption.js";
@@ -585,6 +585,10 @@ export async function handleOllama(
585585
completionReq,
586586
journal.getFixtureMatchCountsForTest(testId),
587587
defaults.requestTransform,
588+
// Record mode proxies on a miss to capture a fresh turn (see record gate
589+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
590+
// shadowing a longer request and skipping the new turn's recording.
591+
recordMatchOptions(!!defaults.record, defaults.logger),
588592
);
589593

590594
if (fixture) {
@@ -969,6 +973,10 @@ export async function handleOllamaGenerate(
969973
completionReq,
970974
journal.getFixtureMatchCountsForTest(testId),
971975
defaults.requestTransform,
976+
// Record mode proxies on a miss to capture a fresh turn (see record gate
977+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
978+
// shadowing a longer request and skipping the new turn's recording.
979+
recordMatchOptions(!!defaults.record, defaults.logger),
972980
);
973981

974982
if (fixture) {
@@ -1304,6 +1312,10 @@ export async function handleOllamaEmbeddings(
13041312
syntheticReq,
13051313
journal.getFixtureMatchCountsForTest(testId),
13061314
defaults.requestTransform,
1315+
// Record mode proxies on a miss to capture a fresh turn (see record gate
1316+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
1317+
// shadowing a longer request and skipping the new turn's recording.
1318+
recordMatchOptions(!!defaults.record, defaults.logger),
13071319
);
13081320

13091321
if (fixture) {

src/responses.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
strictNoMatchMessage,
3737
strictNoMatchLogLine,
3838
} from "./helpers.js";
39-
import { matchFixtureDiagnostic } from "./router.js";
39+
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
4040
import { writeErrorResponse, delay, calculateDelay } from "./sse-writer.js";
4141
import { createInterruptionSignal } from "./interruption.js";
4242
import type { RecordedTimings } from "./types.js";
@@ -967,6 +967,10 @@ export async function handleResponses(
967967
completionReq,
968968
journal.getFixtureMatchCountsForTest(testId),
969969
defaults.requestTransform,
970+
// Record mode proxies on a miss to capture a fresh turn (see record gate
971+
// below), so keep turnIndex strict to prevent an earlier-turn fixture from
972+
// shadowing a longer request and skipping the new turn's recording.
973+
recordMatchOptions(!!defaults.record, defaults.logger),
970974
);
971975

972976
if (fixture) {

src/server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
RecordProviderKey,
1010
} from "./types.js";
1111
import { Journal } from "./journal.js";
12-
import { matchFixtureDiagnostic } from "./router.js";
12+
import { matchFixtureDiagnostic, recordMatchOptions } from "./router.js";
1313
import { validateFixtures, entryToFixture } from "./fixture-loader.js";
1414
import { writeSSEStream, writeErrorResponse } from "./sse-writer.js";
1515
import { createInterruptionSignal } from "./interruption.js";
@@ -564,6 +564,11 @@ async function handleCompletions(
564564
body,
565565
journal.getFixtureMatchCountsForTest(testId),
566566
defaults.requestTransform,
567+
// In record mode a miss proxies upstream to capture a fresh turn, so an
568+
// earlier-turn capture must not shadow a longer request via the relaxed
569+
// turnIndex disambiguator — keep turnIndex a strict gate while recording.
570+
// This handler's record gate (below) is `defaults.record && providerKey`.
571+
recordMatchOptions(!!(defaults.record && providerKey), defaults.logger),
567572
);
568573

569574
if (fixture) {

0 commit comments

Comments
 (0)