Skip to content

Add turnIndex and hasToolResult stateless match criteria#142

Merged
jpr5 merged 4 commits intomainfrom
blitz/aimock-turn-index/integration
Apr 29, 2026
Merged

Add turnIndex and hasToolResult stateless match criteria#142
jpr5 merged 4 commits intomainfrom
blitz/aimock-turn-index/integration

Conversation

@jpr5
Copy link
Copy Markdown
Contributor

@jpr5 jpr5 commented Apr 29, 2026

Summary

  • Adds turnIndex and hasToolResult as new stateless fixture matching criteria that complement the existing sequenceIndex
  • turnIndex counts assistant messages in the request's conversation history (0 = first turn, 1 = after first assistant reply, etc.)
  • hasToolResult checks for the presence/absence of tool-role messages, discriminating pre-tool vs post-tool conversation states
  • Both are stateless (derived from request content, not server-side counters), making them safe for shared/deployed aimock instances with concurrent clients
  • Adds onTurn() convenience method on LLMock for the common turnIndex + userMessage pattern
  • Fixes validateFixtures duplicate-shadowing warning to account for discriminated fixtures (turnIndex/hasToolResult/sequenceIndex)
  • Adds type validation for turnIndex (non-negative integer) and hasToolResult (boolean) in JSON fixture validation
  • Bumps to v1.16.0

Why

sequenceIndex uses mutable server-side counters that drift when multiple test runners share a single aimock instance. The conversation history already encodes the state that sequenceIndex tracks — turnIndex and hasToolResult extract it statelessly from the request, eliminating counter drift without replacing sequenceIndex (which still serves the "same stateless request repeated N times" use case).

Test plan

  • 10 unit tests for turnIndex/hasToolResult in router.test.ts
  • 12 integration tests across OpenAI, Anthropic Claude, and Gemini providers
  • Concurrency test: 5+5 parallel requests verifying statelessness (no counter drift)
  • Combined AND-logic test: turnIndex + hasToolResult together
  • JSON fixture loading test
  • onTurn() convenience method test
  • validateFixtures tests: shadowing false-positive fix + type validation
  • 2573 tests pass, tsc clean, build clean

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 29, 2026

Open in StackBlitz

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

commit: 48456ba

jpr5 added 4 commits April 28, 2026 18:02
turnIndex counts assistant messages in the request conversation history.
hasToolResult checks for the presence of tool-role messages. Both are
stateless and safe for shared aimock instances with concurrent clients.

Includes onTurn() convenience method and unit tests.
Cross-provider tests (OpenAI, Anthropic, Gemini), concurrency
verification, combined AND-logic, JSON fixture loading, and
validateFixtures type/shadowing coverage.
@jpr5 jpr5 force-pushed the blitz/aimock-turn-index/integration branch from 6b46392 to 48456ba Compare April 29, 2026 01:02
@jpr5 jpr5 merged commit 87607a4 into main Apr 29, 2026
22 checks passed
@jpr5 jpr5 deleted the blitz/aimock-turn-index/integration branch April 29, 2026 01:04
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.

1 participant