import { test, expect } from "bun:test"; import { currentActor, currentSsoEmail, runAsSystem } from "../src/actor_context"; test("no scope → null; system scope survives a detached promise chain like notifyStatusTransition's", async () => { expect(await currentActor()).toBeNull(); const seen = await runAsSystem("unattended", async () => { let out: string | null = "unset"; await new Promise((done) => { void Promise.resolve().then(() => new Promise((r) => setTimeout(r, 5))).then(async () => { out = await currentActor(); done(); }); }); return out; }); expect(seen).toBe("system:unattended"); }); test("a transition long after the scope opened is not attributed to it", async () => { const late = await runAsSystem("x", () => currentActor(Date.now() + 6 * 60_000)); expect(late).toBeNull(); }); test("commit-author SSO slot is empty without a session, and system actors are not emails", async () => { expect(await currentSsoEmail()).toBeNull(); expect(await runAsSystem("unattended", () => currentSsoEmail())).toBeNull(); });