Skip to content

Testing utilities

import { fakeModel } from "@hellohelen-ai/goliath/testing";
import type { FakeModel, ScriptedReply } from "@hellohelen-ai/goliath/testing";

A language model that reads from a script. Each call consumes the next reply. Running out throws fakeModel: script exhausted after N call(s).

type ScriptedReply =
| { text: string }
| { json: unknown }
| { error: Error }
| { toolCall: { name: string; input: unknown } };

{ error: new Error("...") } throws a scripted provider failure while recording the call, so tests can verify recovery without replacing the model implementation.

The returned model adds two members:

Member Notes
calls Every prompt the harness sent, in order
remaining() Replies not yet consumed. Zero at the end of a good test

Token usage is estimated at four characters per token, so budget events fire realistically.

From the main entry, for tests that measure prompts:

Export Notes
estimateTokens chars / 4 with a 15% margin
fitWithin Drop the oldest non-system messages first, keep the last
transcriptTokens Estimate for a list of messages
summarizeToolResult The built-in structural compressor
planSchema The conductor’s plan schema, as Zod

See Testing without a phone for the pattern.