Skip to content

Commit 67ba3a8

Browse files
committed
docs(ai-chat): changelog entry for 0.0.0-chat-prerelease-20260418083610
Documents the new mockChatAgent test harness, setupLocals DI pattern, and the lower-level runInMockTaskContext utility.
1 parent b3f055e commit 67ba3a8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

docs/ai-chat/changelog.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,58 @@ sidebarTitle: "Changelog"
44
description: "Pre-release updates for AI chat agents."
55
---
66

7+
<Update label="April 18, 2026" description="0.0.0-chat-prerelease-20260418083610" tags={["SDK"]}>
8+
9+
## Offline test harness for `chat.agent`
10+
11+
`@trigger.dev/sdk/ai/test` now ships `mockChatAgent`, a harness that drives a `chat.agent` definition through real turns without network or task runtime. Send messages, actions, and stop signals; inspect emitted chunks; assert on hook order.
12+
13+
```ts
14+
import { mockChatAgent } from "@trigger.dev/sdk/ai/test";
15+
import { MockLanguageModelV3 } from "ai/test";
16+
import { myAgent } from "./my-agent";
17+
18+
const harness = mockChatAgent(myAgent, {
19+
chatId: "test-1",
20+
clientData: { model: new MockLanguageModelV3({ /* ... */ }) },
21+
});
22+
23+
const turn = await harness.sendMessage({
24+
id: "u1",
25+
role: "user",
26+
parts: [{ type: "text", text: "hi" }],
27+
});
28+
expect(turn.chunks).toContainEqual(
29+
expect.objectContaining({ type: "text-delta", delta: "hello" }),
30+
);
31+
await harness.close();
32+
```
33+
34+
### Dependency injection via locals
35+
36+
`setupLocals` pre-seeds `locals` before `run()` starts — the pattern for injecting database clients, service stubs, and other server-side dependencies that shouldn't leak through untrusted `clientData`:
37+
38+
```ts
39+
import { dbKey } from "./db";
40+
41+
const harness = mockChatAgent(agent, {
42+
chatId: "test-1",
43+
setupLocals: ({ set }) => {
44+
set(dbKey, testDb);
45+
},
46+
});
47+
```
48+
49+
Hooks then read the seeded value with `locals.get(dbKey)`. Falls through to the production client in real runs.
50+
51+
See [Testing](/ai-chat/testing).
52+
53+
## `runInMockTaskContext` — lower-level test harness
54+
55+
`@trigger.dev/core/v3/test` now exports `runInMockTaskContext` for unit-testing any task code offline (not just chat agents). Installs in-memory managers for `locals`, `lifecycleHooks`, `runtime`, `inputStreams`, and `realtimeStreams`, plus a mock `TaskContext`. Drivers let you push data into input streams and inspect chunks written to output streams.
56+
57+
</Update>
58+
759
<Update label="April 17, 2026" description="0.0.0-chat-prerelease-20260417152143" tags={["SDK"]}>
860

961
## Multi-tab coordination

0 commit comments

Comments
 (0)