You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`@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.
`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.
0 commit comments