import { describe, expect, test, mock } from "bun:test"; import { createManifestRoute } from "../routes/manifest.ts"; import type { Runtime, Action } from "@gizmo-ai/runtime"; function createMockRuntime(state: Record): Runtime, Action> { return { getState: () => state, dispatch: mock(() => {}), dispatchToReducer: mock(() => {}), resetState: mock(() => {}), execute: mock(() => ({ included: Promise.resolve(), completed: Promise.resolve({ status: "completed" }), cancel: () => {}, })), subscribe: () => () => {}, subscribeToActions: () => () => {}, getPluginGraph: () => ({ nodes: [], edges: [] }), getPlugins: () => [], } as Runtime, Action>; } describe("createManifestRoute", () => { test("returns stable agentId across sequential requests when not configured", async () => { const runtime = createMockRuntime({ execution: { id: null, state: "idle" }, }); const app = createManifestRoute({ runtime, historyEnabled: false }); const res1 = await app.request("/"); const res2 = await app.request("/"); expect(res1.status).toBe(200); expect(res2.status).toBe(200); const body1 = await res1.json() as { identity: { agentId: string } }; const body2 = await res2.json() as { identity: { agentId: string } }; expect(body1.identity.agentId).toBe(body2.identity.agentId); }); test("uses configured agentId when provided", async () => { const runtime = createMockRuntime({ execution: { id: null, state: "idle" }, }); const app = createManifestRoute({ runtime, historyEnabled: false, manifestConfig: { identity: { agentId: "my-stable-id", name: "Test Agent", version: "1.0.0", }, }, }); const res = await app.request("/"); expect(res.status).toBe(200); const body = await res.json() as { identity: { agentId: string } }; expect(body.identity.agentId).toBe("my-stable-id"); }); });