| ... | ... | @@ -241,6 +241,98 @@ describe("ProviderRuntimeIngestion", () => { |
| 241 | 241 | expect(thread.session?.lastError).toBe("turn failed"); |
| 242 | 242 | }); |
| 243 | 243 | |
| 244 | it("applies provider session.state.changed transitions directly", async () => { |
| 245 | const harness = await createHarness(); |
| 246 | const waitingAt = new Date().toISOString(); |
| 247 | |
| 248 | harness.emit({ |
| 249 | type: "session.state.changed", |
| 250 | eventId: asEventId("evt-session-state-waiting"), |
| 251 | provider: "codex", |
| 252 | sessionId: asSessionId("sess-1"), |
| 253 | createdAt: waitingAt, |
| 254 | threadId: asProviderThreadId("provider-thread-1"), |
| 255 | payload: { |
| 256 | state: "waiting", |
| 257 | reason: "awaiting approval", |
| 258 | }, |
| 259 | }); |
| 260 | |
| 261 | let thread = await waitForThread( |
| 262 | harness.engine, |
| 263 | (entry) => entry.session?.status === "running" && entry.session?.activeTurnId === null, |
| 264 | ); |
| 265 | expect(thread.session?.status).toBe("running"); |
| 266 | expect(thread.session?.lastError).toBeNull(); |
| 267 | |
| 268 | harness.emit({ |
| 269 | type: "session.state.changed", |
| 270 | eventId: asEventId("evt-session-state-error"), |
| 271 | provider: "codex", |
| 272 | sessionId: asSessionId("sess-1"), |
| 273 | createdAt: new Date().toISOString(), |
| 274 | threadId: asProviderThreadId("provider-thread-1"), |
| 275 | payload: { |
| 276 | state: "error", |
| 277 | reason: "provider crashed", |
| 278 | }, |
| 279 | }); |
| 280 | |
| 281 | thread = await waitForThread( |
| 282 | harness.engine, |
| 283 | (entry) => |
| 284 | entry.session?.status === "error" && |
| 285 | entry.session?.activeTurnId === null && |
| 286 | entry.session?.lastError === "provider crashed", |
| 287 | ); |
| 288 | expect(thread.session?.status).toBe("error"); |
| 289 | expect(thread.session?.lastError).toBe("provider crashed"); |
| 290 | |
| 291 | harness.emit({ |
| 292 | type: "session.state.changed", |
| 293 | eventId: asEventId("evt-session-state-stopped"), |
| 294 | provider: "codex", |
| 295 | sessionId: asSessionId("sess-1"), |
| 296 | createdAt: new Date().toISOString(), |
| 297 | threadId: asProviderThreadId("provider-thread-1"), |
| 298 | payload: { |
| 299 | state: "stopped", |
| 300 | }, |
| 301 | }); |
| 302 | |
| 303 | thread = await waitForThread( |
| 304 | harness.engine, |
| 305 | (entry) => |
| 306 | entry.session?.status === "stopped" && |
| 307 | entry.session?.activeTurnId === null && |
| 308 | entry.session?.lastError === "provider crashed", |
| 309 | ); |
| 310 | expect(thread.session?.status).toBe("stopped"); |
| 311 | expect(thread.session?.lastError).toBe("provider crashed"); |
| 312 | |
| 313 | harness.emit({ |
| 314 | type: "session.state.changed", |
| 315 | eventId: asEventId("evt-session-state-ready"), |
| 316 | provider: "codex", |
| 317 | sessionId: asSessionId("sess-1"), |
| 318 | createdAt: new Date().toISOString(), |
| 319 | threadId: asProviderThreadId("provider-thread-1"), |
| 320 | payload: { |
| 321 | state: "ready", |
| 322 | }, |
| 323 | }); |
| 324 | |
| 325 | thread = await waitForThread( |
| 326 | harness.engine, |
| 327 | (entry) => |
| 328 | entry.session?.status === "ready" && |
| 329 | entry.session?.activeTurnId === null && |
| 330 | entry.session?.lastError === null, |
| 331 | ); |
| 332 | expect(thread.session?.status).toBe("ready"); |
| 333 | expect(thread.session?.lastError).toBeNull(); |
| 334 | }); |
| 335 | |
| 244 | 336 | it("does not clear active turn when session/thread started arrives mid-turn", async () => { |
| 245 | 337 | const harness = await createHarness(); |
| 246 | 338 | const now = new Date().toISOString(); |