import test from "node:test"; import assert from "node:assert/strict"; import { publishBossEvent } from "../src/lib/boss-events.ts"; import { waitForMasterAgentTaskWakeup } from "../src/lib/master-agent-task-wakeup.ts"; test("waitForMasterAgentTaskWakeup resolves when a queued task event targets the device", async () => { const startedAt = Date.now(); const waiting = waitForMasterAgentTaskWakeup("macbook-air", 1_000); setTimeout(() => { publishBossEvent("master_agent.task.updated", { deviceId: "mac-studio", taskId: "task-other-device", status: "queued", }); publishBossEvent("master_agent.task.updated", { deviceId: "macbook-air", taskId: "task-macbook-air", status: "queued", }); }, 20); assert.equal(await waiting, true); assert.ok(Date.now() - startedAt < 500); }); test("waitForMasterAgentTaskWakeup times out when no matching device task arrives", async () => { const startedAt = Date.now(); const woke = await waitForMasterAgentTaskWakeup("macbook-air", 30); assert.equal(woke, false); assert.ok(Date.now() - startedAt >= 20); });