|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { onReactorShutdown, onTurnBoundary } from "./reactor-events.js"; |
| 3 | + |
| 4 | +describe("onTurnBoundary", () => { |
| 5 | + test("true only for inference.done", () => { |
| 6 | + expect(onTurnBoundary({ type: "inference.done" })).toBe(true); |
| 7 | + expect(onTurnBoundary({ type: "reactor.done" })).toBe(false); |
| 8 | + expect(onTurnBoundary({ type: "tool.done" })).toBe(false); |
| 9 | + }); |
| 10 | + |
| 11 | + // The property all three shipped defects violated: code that gated a |
| 12 | + // turn boundary on `reactor.done` only ever saw it once, at shutdown. |
| 13 | + // A multi-turn session must trip this guard once per turn. |
| 14 | + test("fires more than once across a multi-turn session", () => { |
| 15 | + const turnEvents = [ |
| 16 | + { type: "inference.start" }, |
| 17 | + { type: "inference.done" }, |
| 18 | + { type: "tool.done" }, |
| 19 | + { type: "inference.done" }, |
| 20 | + { type: "inference.done" }, |
| 21 | + ]; |
| 22 | + |
| 23 | + const boundaries = turnEvents.filter((event) => onTurnBoundary(event)); |
| 24 | + |
| 25 | + expect(boundaries.length).toBe(3); |
| 26 | + expect(boundaries.length).toBeGreaterThan(1); |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +describe("onReactorShutdown", () => { |
| 31 | + test("true only for reactor.done, and fires once per session", () => { |
| 32 | + const sessionEvents = [ |
| 33 | + { type: "inference.done" }, |
| 34 | + { type: "inference.done" }, |
| 35 | + { type: "inference.done" }, |
| 36 | + { type: "reactor.done" }, |
| 37 | + ]; |
| 38 | + |
| 39 | + expect(onReactorShutdown({ type: "reactor.done" })).toBe(true); |
| 40 | + expect(onReactorShutdown({ type: "inference.done" })).toBe(false); |
| 41 | + |
| 42 | + const shutdowns = sessionEvents.filter((event) => onReactorShutdown(event)); |
| 43 | + expect(shutdowns.length).toBe(1); |
| 44 | + }); |
| 45 | +}); |
0 commit comments