import { afterEach, describe, expect, it, vi } from "vitest"; import { AEGIS_LIVE_TOOLS, AEGIS_LIVE_MODEL, AEGIS_LIVE_VOICE, aegisLiveInstructions } from "@/lib/aegis-live-policy"; import { mintLiveToken } from "@/lib/gemini-live.server"; afterEach(() => vi.unstubAllGlobals()); describe("Aegis Live boundaries", () => { it("restricts the security session to observations and permission requests, with no build or deploy tools", () => { expect(AEGIS_LIVE_TOOLS[0]?.functionDeclarations.map(tool => tool.name)).toEqual(["get_security_overview", "request_security_scan", "request_echo_handoff"]); }); it("locks a single-use token to the existing Gemini voice and security persona", async () => { const fetchMock = vi.fn().mockResolvedValue(Response.json({ name: "single-use-test-token" })); vi.stubGlobal("fetch", fetchMock); const setup = { model: `models/${AEGIS_LIVE_MODEL}`, voice: AEGIS_LIVE_VOICE, tools: AEGIS_LIVE_TOOLS, instructions: aegisLiveInstructions("Aman") }; expect(await mintLiveToken("test-only", setup)).toEqual({ token: "single-use-test-token" }); const body = JSON.parse(fetchMock.mock.calls[0]?.[1].body); expect(body.uses).toBe(1); expect(body.bidiGenerateContentSetup).toEqual(setup); expect(AEGIS_LIVE_MODEL).toBe("gemini-3.8-live"); expect(AEGIS_LIVE_VOICE).toBe("Charon"); }); it("stops when the configured live model is unavailable instead of switching providers", async () => { const fetchMock = vi.fn().mockResolvedValue(new Response("", { status: 404 })); vi.stubGlobal("fetch", fetchMock); expect(await mintLiveToken("test-only", {})).toEqual({ error: "The configured Gemini Live model is unavailable. Check Google model access before starting a new call." }); expect(fetchMock).toHaveBeenCalledTimes(1); }); });