feat: async function responses in fixtures (closes #154)#156
Merged
Conversation
commit: |
de4540a to
217f617
Compare
Fixture responses can now be sync or async functions that receive the request and return the response dynamically. Factory results are auto-normalized (object content and tool call arguments are JSON.stringified), matching static fixture behavior. All HTTP handlers, WebSocket adapters, router, LLMock convenience methods (on, onMessage, onTurn, onToolCall, onToolResult, onEmbedding), and fixture validation updated. Closes #154 (@5ebastianMeier).
10 tests covering sync/async factories, request-aware content, streaming, onMessage convenience, static+dynamic coexistence, factory throws, async rejection, invalid return shape, and async factory + streaming combined.
Dynamic/async responses section on examples page. Info-box callouts on fixtures and multi-turn pages. Changelog entry credits @5ebastianMeier (issue #154).
217f617 to
2c74c70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixture responses can now be sync or async functions that receive the request and return the response dynamically — eliminating race conditions in complex multi-turn E2E tests where side effects must complete before constructing the next response.
ResponseFactorytype:(req: ChatCompletionRequest) => FixtureResponse | Promise<FixtureResponse>await resolveResponse(fixture, req)JSON.stringifytreatment as static fixtures (object content, tool call arguments)on(),onMessage(),onTurn(),onToolCall(),onToolResult(),onEmbedding()all acceptResponseFactoryCloses #154 — feature request by @5ebastianMeier
Test plan
pnpm test— 2799 passed, 36 skippednpx tsc --noEmit— cleanpnpm run lint/pnpm run format:check— clean