feat(http-recorder): default mode to "auto" (#26719)

This commit is contained in:
Kit Langton 2026-05-10 12:05:11 -04:00 committed by GitHub
commit 4fb417d3b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 99 additions and 30 deletions

View file

@ -12,12 +12,12 @@ import {
} from "effect/unstable/http"
import * as CassetteService from "./cassette"
import { defaultMatcher, selectMatch, selectSequential, type RequestMatcher } from "./matching"
import { appendOrFail, makeReplayState } from "./recorder"
import { appendOrFail, makeReplayState, resolveAutoMode } from "./recorder"
import { defaults, type Redactor } from "./redactor"
import { redactUrl } from "./redaction"
import { httpInteractions, type CassetteMetadata, type HttpInteraction, type ResponseSnapshot } from "./schema"
export type RecordReplayMode = "record" | "replay" | "passthrough"
export type RecordReplayMode = "auto" | "record" | "replay" | "passthrough"
export interface RecordReplayOptions {
readonly mode?: RecordReplayMode
@ -69,7 +69,8 @@ export const recordingLayer = (
const cassetteService = yield* CassetteService.Service
const redactor = options.redactor ?? defaults()
const match = options.match ?? defaultMatcher
const mode = options.mode ?? "replay"
const requested = options.mode ?? "auto"
const mode = requested === "auto" ? yield* resolveAutoMode(cassetteService, name) : requested
const sequential = options.dispatch === "sequential"
const replay = yield* makeReplayState(cassetteService, name, httpInteractions)
@ -114,7 +115,12 @@ export const recordingLayer = (
return Effect.gen(function* () {
const incoming = yield* snapshotRequest(request)
const interactions = yield* replay.load.pipe(
Effect.mapError(() => transportError(request, `Fixture "${name}" not found.`)),
Effect.mapError(() =>
transportError(
request,
`Fixture "${name}" not found. Run locally to record it (CI=true forces replay).`,
),
),
)
const result = sequential
? selectSequential(interactions, incoming, match, yield* replay.cursor)