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
5 changes: 5 additions & 0 deletions .changeset/curvy-peaches-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"braintrust": minor
---

feat(typesafe): Capture image inputs
14 changes: 12 additions & 2 deletions dev-packages/seinfeld/src/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface CassetteContext {
ignoredRequests: IgnoredRequestMatcher[] | undefined;
streamingRequests: StreamingRequestMatcher[] | undefined;
threshold: number | false;
inlineRequestBodies: boolean;
onMiss: ((req: RecordedRequest) => void) | undefined;

// Per-run mutable state (reset on each start)
Expand Down Expand Up @@ -106,11 +107,17 @@ async function handleCassetteRequest(

switch (ctx.mode) {
case "replay": {
const recorded = await recordRequest(request, ctx.threshold);
const recorded = await recordRequest(
request,
ctx.inlineRequestBodies ? false : ctx.threshold,
);
return handleReplay(ctx, recorded);
}
case "record": {
const draft = await recordRequestDraft(request, ctx.threshold);
const draft = await recordRequestDraft(
request,
ctx.inlineRequestBodies ? false : ctx.threshold,
);
return handleRecord(ctx, getRealResponse, draft);
}
case "passthrough":
Expand Down Expand Up @@ -449,6 +456,8 @@ export interface CassetteServerOptions {
store: CassetteStore;
/** Filter spec (matching-only normalization). */
filters?: FilterSpec;
/** Keep large request bodies inline so matching filters can normalize their bytes. */
inlineRequestBodies?: boolean;
/** Redaction spec for what gets persisted to disk. Defaults to paranoid. */
redact?: RedactionSpec;
/**
Expand Down Expand Up @@ -496,6 +505,7 @@ function createContext(options: CassetteServerOptions): CassetteContext {
ignoredRequests: options.ignoredRequests,
streamingRequests: options.streamingRequests,
threshold: DEFAULT_EXTERNAL_BLOB_THRESHOLD,
inlineRequestBodies: options.inlineRequestBodies ?? false,
onMiss: options.onMiss,
candidates: [],
callCounts: new Map(),
Expand Down
12 changes: 10 additions & 2 deletions e2e/config/pr-comment-scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,19 @@
"variants": [
{
"variantKey": "typesafe-v0",
"label": "v0 pinned"
"label": "v0.6 pinned"
},
{
"variantKey": "typesafe-v0-latest",
"label": "v0 latest"
"label": "v0.6 latest"
},
{
"variantKey": "typesafe-v0-7",
"label": "v0.7 pinned"
},
{
"variantKey": "typesafe-v0-7-latest",
"label": "v0.7 latest"
}
]
},
Expand Down
4 changes: 4 additions & 0 deletions e2e/helpers/scenario-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ function resolveCassetteMode(

async function loadScenarioCassetteOptions(scenarioDir: string): Promise<{
filter: FilterSpec | undefined;
inlineRequestBodies?: boolean;
redact: RedactionSpec | undefined;
streamingRequests: StreamingRequestMatcher[] | undefined;
}> {
Expand All @@ -465,11 +466,13 @@ async function loadScenarioCassetteOptions(scenarioDir: string): Promise<{
}
const mod = (await import(pathToFileURL(filterPath).href)) as {
filter?: FilterSpec;
inlineRequestBodies?: boolean;
redact?: RedactionSpec;
streamingRequests?: StreamingRequestMatcher[];
};
return {
filter: mod.filter ?? "default",
inlineRequestBodies: mod.inlineRequestBodies,
redact: mod.redact,
streamingRequests: mod.streamingRequests,
};
Expand Down Expand Up @@ -808,6 +811,7 @@ export async function withScenarioHarness(
mode: wiring.mode,
store: createJsonFileStore({ rootDir: wiring.cassetteDir }),
filters: cassetteOptions.filter,
inlineRequestBodies: cassetteOptions.inlineRequestBodies,
redact: cassetteOptions.redact,
streamingRequests: cassetteOptions.streamingRequests,
ignoredRequests: CASSETTE_IGNORED_REQUESTS,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Loading