Commit 0bb4b18
committed
test(sdk,core): session-aware mockChatAgent harness + chat.test.ts mocks
Unblocks the unit tests after the chat.agent -> Sessions migration
(phases B/C/D). Before: 43 passed / 43 failed (35 in chat.test.ts + 10
mockChatAgent + 2 skillsRuntime). After: 86 passed / 0 failed.
Core (@trigger.dev/core/v3/test)
- TestSessionStreamManager: in-memory SessionStreamManager keyed on
(sessionId, io) mirroring TestInputStreamManager. Dispatch rules
match production with one test-only tweak — when a record arrives
and only handlers are registered (no .once waiter), it's buffered
for the next once() instead of discarded. Production doesn't need
this because the SSE tail naturally serializes records after the
agent's turn-loop has re-registered a waiter; tests send
synchronously right after turn-complete, so without the buffer
the next waitWithIdleTimeout loses the message.
- runInMockTaskContext installs the manager via
sessionStreams.setGlobalManager, exposes drivers.sessions.in.send
/ .close, and tears down on exit.
SDK (@trigger.dev/sdk/v3/test)
- __setSessionOpenImplForTests hook in sessions.ts lets the harness
override sessions.open(id) with an in-memory SessionHandle.
SessionHandle constructor now accepts { in?, out? } overrides.
- TestSessionOutputChannel extends SessionOutputChannel and
intercepts pipe / writer / append into a shared TestSessionOutState
(chunks + listener registry). Never constructs SessionStreamInstance
so it avoids initializeSessionStream / StreamsWriterV2 entirely.
- mockChatAgent rewritten: drops CHAT_MESSAGES_STREAM_ID /
CHAT_STOP_STREAM_ID / the "chat" output stream key. sendMessage /
sendRegenerate / sendAction push ChatInputChunk { kind: "message",
payload } via drivers.sessions.in.send. sendStop pushes
{ kind: "stop" }. Turn-complete detection moves from
drivers.outputs.onWrite to a TestSessionOutputChannel listener.
chat.test.ts
- New URL-predicate helpers at the top (isSessionCreateUrl,
isTriggerTaskUrl, isSessionOutSubscribeUrl,
isSessionStreamAppendUrl) + defaultSessionCreateResponse /
defaultAppendResponse so every global.fetch mock speaks the
same vocabulary.
- Bulk-updated all 25 mock blocks: added session-create handler
(transport's accessToken path now lazily upserts via POST
/api/v1/sessions before trigger), swapped /realtime/v1/streams/
for /realtime/v1/sessions/ URL matchers, and replaced
(streams/ && /input/) append-URL matchers with
isSessionStreamAppendUrl.
- Three tests updated for new semantics: onSessionChange fires
twice on first message (ensureSession -> sessionId only, then
triggerNewRun -> adds runId + isStreaming). Async-token call
count goes 1 -> 2 on first message because ensureSession and
trigger both resolve the token with purpose: "trigger".
- "minimal wire payloads" test's body parsing updated — session.in
append body is a raw JSON.stringify({ kind, payload }) string,
not a { data } wrapper.
- Replaced the vestigial "custom streamKey URL" test with a
"subscribes to the backing Session's .out" assertion. streamKey
option is a no-op under sessions; removal can land in a follow-up.
- One test (stream closes without control chunk) legitimately
needs 9s for SSE-close fallback — bumped its timeout to 15s.1 parent 7847d78 commit 0bb4b18
7 files changed
Lines changed: 833 additions & 162 deletions
File tree
- packages
- core/src/v3/test
- trigger-sdk/src/v3
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
86 | 106 | | |
87 | 107 | | |
88 | 108 | | |
| |||
198 | 218 | | |
199 | 219 | | |
200 | 220 | | |
| 221 | + | |
201 | 222 | | |
202 | 223 | | |
203 | 224 | | |
| |||
207 | 228 | | |
208 | 229 | | |
209 | 230 | | |
| 231 | + | |
210 | 232 | | |
211 | 233 | | |
212 | 234 | | |
| |||
215 | 237 | | |
216 | 238 | | |
217 | 239 | | |
| 240 | + | |
218 | 241 | | |
219 | 242 | | |
220 | 243 | | |
| |||
237 | 260 | | |
238 | 261 | | |
239 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
240 | 271 | | |
241 | 272 | | |
242 | 273 | | |
| |||
251 | 282 | | |
252 | 283 | | |
253 | 284 | | |
| 285 | + | |
254 | 286 | | |
255 | 287 | | |
256 | 288 | | |
257 | 289 | | |
| 290 | + | |
258 | 291 | | |
259 | 292 | | |
260 | 293 | | |
Lines changed: 271 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
0 commit comments