Skip to main content
Test agents with a fixture model instead of a paid model, in a Restate server that forces replay. Forced replay runs your handler again from its journal at every suspension point. Code that takes different steps on replay fails with a journal mismatch, and side effects outside journaled steps run again, which your assertions can catch.
Prerequisites: Docker, to run the Restate Server in a container.
Install the test dependencies:

Fixture models

A fixture model returns fixed responses based on the request. Wrap it with journaledModel, so its responses are journaled like real model calls:
The request contains the messages and the available tools, and, when they apply, the instructions, maxOutputTokens, the step number, and the outputSchema for typed output. A request without a step asks for a summary, for example of a stopped run, and its name identifies the summary, such as Summarize stopped run. For typed output, return {type: "final", text: "", output}. This fixture returns an answer only after it receives a successful lookupTicket result with valid ticket data. A missing tool or failed lookup fails the test.

Integration tests

Replace the model provider with the fixture, start the services in a Restate container, and call them through the Restate client:
  • vi.mock replaces aiModel with the fixture, so the test imports the same services that your application serves.
  • The fetchTicket spy calls the original function and records each call. The assertion verifies that replay doesn’t repeat the lookup, and the second test verifies that a failed lookup cannot produce a successful answer.
  • alwaysReplay makes Restate replay the invocation at every suspension point, and disableRetries makes Restate kill an invocation that fails with a retryable error instead of retrying it. Retry policies of an asyncTool, a model, or a service still apply. See Testing.
A run rejects a batch of tool calls if a call reuses the ID of an earlier call in its history: no call in the batch runs, and the model receives an invalid_response note instead. A fixture that returns the same call IDs in every turn therefore runs no tools after the first turn of a conversation. Use a new object key per test, or return unique call IDs per turn. Assert on observable effects: a tool that must run once runs once, an approval blocks the run until it’s resolved, and the losing run of a race is cleaned up. The Restate Harness integration tests test the tutorial lessons this way.