Skip to content

feat: async function responses in fixtures (closes #154)#156

Merged
jpr5 merged 3 commits intomainfrom
feat/async-fixture-response
May 6, 2026
Merged

feat: async function responses in fixtures (closes #154)#156
jpr5 merged 3 commits intomainfrom
feat/async-fixture-response

Conversation

@jpr5
Copy link
Copy Markdown
Contributor

@jpr5 jpr5 commented May 5, 2026

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.

  • ResponseFactory type: (req: ChatCompletionRequest) => FixtureResponse | Promise<FixtureResponse>
  • All 25 handler files updated to use await resolveResponse(fixture, req)
  • Auto-normalization: factory results get the same JSON.stringify treatment as static fixtures (object content, tool call arguments)
  • Convenience methods: on(), onMessage(), onTurn(), onToolCall(), onToolResult(), onEmbedding() all accept ResponseFactory
  • Error handling: factory throws/rejects propagate to handler try/catch → 500; invalid return shapes fall through to 500
  • 10 tests: sync/async factories, streaming, error paths, invalid shapes, convenience wrappers

Closes #154 — feature request by @5ebastianMeier

Test plan

  • pnpm test — 2799 passed, 36 skipped
  • npx tsc --noEmit — clean
  • pnpm run lint / pnpm run format:check — clean
  • CR converged (R1: 4 findings fixed, R2: 0 findings, 7 agents per round)
  • Adversarial review: solution verified against issue author's exact scenario

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@156

commit: 2c74c70

@jpr5 jpr5 force-pushed the feat/async-fixture-response branch from de4540a to 217f617 Compare May 5, 2026 18:01
@jpr5 jpr5 self-assigned this May 5, 2026
jpr5 added 3 commits May 5, 2026 18:00
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).
@jpr5 jpr5 force-pushed the feat/async-fixture-response branch from 217f617 to 2c74c70 Compare May 6, 2026 01:00
@jpr5 jpr5 merged commit 8c75516 into main May 6, 2026
22 checks passed
@jpr5 jpr5 deleted the feat/async-fixture-response branch May 6, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Async Fixture Response

1 participant