PAIPAI

createTestUtils()

Typed mock-model builders and thread-state selectors.

import { createTestUtils } from "@pai/test-utils";

const t = createTestUtils(assistantAgent);
const model = t.model.queue((m) => [
  m.response([m.toolCall("searchDocs", { query: "tenancy" })]),
  m.response([m.text("Done.")]),
]);

Import

import { createTestUtils } from "@pai/test-utils";

Signature

function createTestUtils(agent?: AgentDefinition): ContractTestUtils;

Parameters

agent?: AgentDefinition

Binds toolCall("searchDocs", …) to the contract.

Returns

A ContractTestUtils.

Usual helpers for runtime tests. Also on the object: mockModel, textStream, error, aborted, rawStream, multiToolCall, clientToolCall, tools, getClientTool, submitClientTool.

model: TestModelBuilders

queue: ((m) => responses[]) => LanguageModel

Scripted model for createTestRuntime(). Inside the callback: m.response, m.toolCall, m.text.

toolCall: (name, input) => StreamResponseFactory

Standalone stream factory. Prefer m.toolCall inside model.queue.

text: (text) => StreamResponseFactory

getTool: (state, name) => tool part

First matching tool part, or throw.

findTool: (state, name) => tool part | undefined

waitForTool: (thread, name) => Promise<tool part>

waitForPending: (thread, selector) => Promise<PendingActionView>

actionName: (tool, suspend) => string

"publishPost.approve".

stubTool: (tool, execute) => StubbedTool

Examples

model.queue

const model = t.model.queue((m) => [
  m.response([m.toolCall("searchDocs", { query: "tenancy" })]),
  m.response([m.text("See the identity guide.")]),
]);

Selectors

expect(t.getTool(state, "searchDocs").output?.hits[0]?.title).toBe("Identity");
await t.waitForTool(thread, "searchDocs");
await t.waitForPending(thread, t.actionName("publishPost", "approve"));

Learn more

On this page