( request: ChatCompletionRequest, recordConfig?: RecordConfig, )
| 2029 | type EndpointType = NonNullable<FixtureMatch["endpoint"]>; |
| 2030 | |
| 2031 | export function buildFixtureMatch( |
| 2032 | request: ChatCompletionRequest, |
| 2033 | recordConfig?: RecordConfig, |
| 2034 | ): { |
| 2035 | userMessage?: string; |
| 2036 | inputText?: string; |
| 2037 | model?: string; |
| 2038 | endpoint?: EndpointType; |
| 2039 | turnIndex?: number; |
| 2040 | hasToolResult?: boolean; |
| 2041 | context?: string; |
| 2042 | } { |
| 2043 | const match: { |
| 2044 | userMessage?: string; |
| 2045 | inputText?: string; |
| 2046 | model?: string; |
| 2047 | endpoint?: EndpointType; |
| 2048 | turnIndex?: number; |
| 2049 | hasToolResult?: boolean; |
| 2050 | context?: string; |
| 2051 | } = {}; |
| 2052 | |
| 2053 | // Include endpoint type for multimedia fixtures |
| 2054 | if (request._endpointType && request._endpointType !== "chat") { |
| 2055 | match.endpoint = request._endpointType as EndpointType; |
| 2056 | } |
| 2057 | |
| 2058 | // Embedding request |
| 2059 | if (request.embeddingInput) { |
| 2060 | match.inputText = request.embeddingInput; |
| 2061 | return match; |
| 2062 | } |
| 2063 | |
| 2064 | // Chat/multimedia request — match on the last user message |
| 2065 | const lastUser = getLastMessageByRole(request.messages ?? [], "user"); |
| 2066 | if (lastUser) { |
| 2067 | const text = getTextContent(lastUser.content); |
| 2068 | if (text) { |
| 2069 | match.userMessage = text; |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | // Record normalized model for all requests so fixtures disambiguate |
| 2074 | // calls that share the same userMessage but target different models. |
| 2075 | if (request.model) { |
| 2076 | match.model = |
| 2077 | normalizeModelName(request.model, recordConfig?.recordFullModelVersion) ?? request.model; |
| 2078 | } |
| 2079 | |
| 2080 | // Multi-turn disambiguation: writing only `userMessage` lets the recorder's |
| 2081 | // in-memory cache shadow follow-up turns that share it (initial tool call |
| 2082 | // vs. text reply after the tool result). turnIndex + hasToolResult give |
| 2083 | // each call a distinct, matcher-aware key. Skip for non-chat (no messages). |
| 2084 | const messages = request.messages ?? []; |
| 2085 | if ( |
| 2086 | messages.length > 0 && |
| 2087 | (request._endpointType === "chat" || request._endpointType === undefined) |
| 2088 | ) { |
no test coverage detected
searching dependent graphs…