Something went wrong. Try again.
A local-first event pipeline for independent agents, built on Jazz.
Something went wrong. Try again.
3.8 kB · 40 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041import { afterEach, describe, expect, it, vi } from "vitest";import { mkdtemp, mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import path from "node:path";import { spawnSync } from "node:child_process";import { configureCoChat } from "../src/web/co-chat-config.js";const roots: string[] = [];afterEach(async () => { vi.unstubAllGlobals(); await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true }))); });async function root() { const value = await mkdtemp(path.join(tmpdir(), "co-config-test-")); roots.push(value); return value; }describe("Co activation configuration", () => { it("is disabled by default and never falls back to another backend or computer", async () => { const directory = await root(); const options = { directory, projectRoot: directory, key: Buffer.alloc(32, 7), origin: "https://synthetic.example" }; expect(await configureCoChat(options, {})).toBeUndefined(); await expect(configureCoChat(options, { THOUGHTSTREAM_CO_CHAT_ENABLED: "1" })).rejects.toThrow("Invalid Co chat enablement"); await expect(configureCoChat(options, { THOUGHTSTREAM_CO_CHAT_ENABLED: "true", LETTA_API_KEY: "synthetic" })).rejects.toThrow("verified API authority"); await expect(configureCoChat(options, { THOUGHTSTREAM_CO_CHAT_ENABLED: "true", LETTA_API_KEY: "synthetic", LETTA_BASE_URL: "https://api.letta.com", THOUGHTSTREAM_CO_COMPUTER_DEVICE_ID: "unverified" })).rejects.toThrow("configured computer"); }); it("startup opens only a new empty registry, without any SDK call or inference", async () => { const directory = await root(); await mkdir(path.join(directory, "dist/co-chat"), { recursive: true }); await writeFile(path.join(directory, "dist/co-chat/app.js"), "/* fixture */"); await writeFile(path.join(directory, "dist/co-chat/app.css"), "/* fixture */"); const network = vi.fn(() => { throw new Error("No network allowed in fixture"); }); vi.stubGlobal("fetch", network); const web = await configureCoChat({ directory, projectRoot: directory, key: Buffer.alloc(32, 7), origin: "https://synthetic.example" }, { THOUGHTSTREAM_CO_CHAT_ENABLED: "true", LETTA_API_KEY: "synthetic-not-a-live-key", LETTA_BASE_URL: "https://api.letta.com", THOUGHTSTREAM_CO_AGENT_ID: "agent-synthetic-web-chat", THOUGHTSTREAM_CO_COMPUTER_DEVICE_ID: "00000000-0000-0000-0000-000000000001" }); expect(web?.chat.list()).toEqual([]); expect(network).not.toHaveBeenCalled(); await web?.chat.close(); }); it("provisions only the explicit synthetic key, refuses overwrite, and prints no values", async () => { const directory = await root(); const key = "synthetic-api-key-not-a-live-credential"; const options = { encoding: "utf8" as const, env: { PATH: process.env.PATH, HOME: directory, THOUGHTSTREAM_CREDENTIALS_DIR: directory, LETTA_API_KEY: key, LETTA_BASE_URL: "https://api.letta.com", THOUGHTSTREAM_CO_AGENT_ID: "agent-synthetic-web-chat", THOUGHTSTREAM_CO_COMPUTER_DEVICE_ID: "00000000-0000-0000-0000-000000000001" } }; const result = spawnSync(process.execPath, ["--import", "tsx", "scripts/configure-inspector-co-chat.ts"], options); expect(result.status).toBe(0); expect(result.stdout + result.stderr).not.toContain(key); const file = path.join(directory, "inspector-co-chat.env"); expect((await stat(file)).mode & 0o777).toBe(0o600); const contents = await readFile(file, "utf8"); expect(contents).toContain(`LETTA_API_KEY=${key}`); expect(contents).not.toContain("OAUTH"); const second = spawnSync(process.execPath, ["--import", "tsx", "scripts/configure-inspector-co-chat.ts"], options); expect(second.status).not.toBe(0); expect(await readFile(file, "utf8")).toBe(contents); });});