feat(http-recorder): default mode to "auto" (#26719)
This commit is contained in:
parent
11030c627b
commit
4fb417d3b5
6 changed files with 99 additions and 30 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue