Something went wrong. Try again.
Your thinking partner.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import { describe, expect, mock, test } from "bun:test";import { noteText, readHomeNote } from "./homeNote";
function fixture({ primary = true, error }: { primary?: boolean; error?: unknown } = {}) { const list = mock(async () => [ { id: "shared-repo", isPrimary: false }, ...(primary ? [{ id: "agent-memory", isPrimary: true }] : []), ]); const read = mock(async () => { if (error) throw error; return { content: "# Today\n\n[A resource](https://example.com)\n" }; }); const client = { agents: { repositories: { list } }, repositories: { files: { read } } } as unknown as Parameters<typeof readHomeNote>[0]; return { client, list, read };}
describe("home note", () => { test("reads home.md from this agent's primary repo, keeping Markdown intact", async () => { const { client, list, read } = fixture(); expect(await readHomeNote(client, "agent-1")).toBe("# Today\n\n[A resource](https://example.com)"); expect(list).toHaveBeenCalledWith("agent-1"); expect(read).toHaveBeenCalledWith("agent-memory", { path: "home.md" }); });
test("never substitutes an attached shared repo for missing agent memory", async () => { const { client, read } = fixture({ primary: false }); expect(await readHomeNote(client, "agent-1")).toBeNull(); expect(read).not.toHaveBeenCalled(); });
test("missing file is an empty note", async () => { expect(await readHomeNote(fixture({ error: { status: 404 } }).client, "agent-1")).toBeNull(); });
test("authentication and network errors are not mistaken for an empty note", async () => { for (const error of [{ status: 401 }, { status: 403 }, new Error("offline")]) { await expect(readHomeNote(fixture({ error }).client, "agent-1")).rejects.toEqual(error); } });
test("an empty file clears the note", () => { expect(noteText("\n \n")).toBeNull(); });
test("oversized content is rejected rather than rendering a large document", () => { expect(() => noteText("x".repeat(20_001))).toThrow("Home note is too long"); });});