|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | + |
| 3 | +import { DIRECTOR_REGISTRY } from "../registry.js"; |
| 4 | + |
| 5 | +const card = (): string => DIRECTOR_REGISTRY.dispatch.systemPrompt; |
| 6 | + |
| 7 | +/** |
| 8 | + * CL-9920: mailbox turn yield vs task completion, plus midflight steering. |
| 9 | + * Instruction-only change, so the existing harness is the prompt contract: |
| 10 | + * each test scripts a staggered-worker scenario and asserts the dispatch |
| 11 | + * card carries the guidance that scenario requires. All fail before the |
| 12 | + * guidance lands. |
| 13 | + */ |
| 14 | +describe("dispatch yield/steering guidance (CL-9920)", () => { |
| 15 | + test("staggered completion: yield with pending workers is not task completion", () => { |
| 16 | + // Two workers spawned; one reports while the other still runs. The |
| 17 | + // resume turn must end as a yield, never as a completion claim. |
| 18 | + expect(card()).toMatch(/yield ends this turn/i); |
| 19 | + expect(card()).toMatch(/never .* completion .* pending/i); |
| 20 | + }); |
| 21 | + |
| 22 | + test("completion requires acceptance assessment and blocker disposition", () => { |
| 23 | + // All workers reported but a check is unassessed and a blocker is open: |
| 24 | + // completion still needs report-vs-brief acceptance plus disposition. |
| 25 | + expect(card()).toMatch(/acceptance/i); |
| 26 | + expect(card()).toMatch(/blocker/i); |
| 27 | + }); |
| 28 | + |
| 29 | + test("resumed steering reaches active workers through existing messaging only", () => { |
| 30 | + // Operator steers midflight; a worker is still running. The resumed |
| 31 | + // turn must incorporate the steering and forward it via send_input — |
| 32 | + // the existing channel — with no new scheduling/messaging invented. |
| 33 | + expect(card()).toMatch(/steering/i); |
| 34 | + expect(card()).toMatch(/send_input/); |
| 35 | + expect(card()).not.toMatch(/new channel|new tool|new messag/i); |
| 36 | + }); |
| 37 | + |
| 38 | + test("superseded work is named; stale results are never approval", () => { |
| 39 | + // Steering supersedes one lane while its stale report lands anyway. |
| 40 | + // Dispatch must name the superseded work and refuse the stale result. |
| 41 | + expect(card()).toMatch(/superseded/i); |
| 42 | + expect(card()).toMatch(/stale/i); |
| 43 | + }); |
| 44 | + |
| 45 | + test("unreachable steering is disclosed, acceptance withheld, stop preserved", () => { |
| 46 | + // Steering arrives but cannot reach active work: dispatch must say so, |
| 47 | + // withhold acceptance, and keep stop/cancel semantics unchanged. |
| 48 | + expect(card()).toMatch(/withhold acceptance/i); |
| 49 | + expect(card()).toMatch(/stop/i); |
| 50 | + }); |
| 51 | +}); |
0 commit comments