host-doc.test.ts
This file
Path
packages/agent-kit/test/host-doc.test.ts
219 lines · 6.6 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220import { NodeServices } from "@effect/platform-node";import { describe, expect, it } from "@effect/vitest";import { Brand } from "@repo/brand";import type { ProjectListing } from "@repo/protocol/domain/front-page";import { ProjectName } from "@repo/protocol/ids";import { Effect } from "effect";
import type { CommandDoc } from "../src/command-doc.ts";import { frontLlms, indexBanner, projectLlms, underTitle,} from "../src/host-doc.ts";import { expectGolden } from "./golden.ts";
const platformUrl = "https://platform-test.example.workers.dev";
const webUrl = "https://web-test.example.workers.dev";
const row = ( path: readonly [string, ...string[]], summary: string, more: Partial<CommandDoc> = {}): CommandDoc => ({ flags: ["--json"], needsApproval: false, path, positional: [], readOnly: true, source: "contract", summary, ...more,});
const commands: readonly CommandDoc[] = [ row( ["ask"], "Show one ask in full, with its brief in Markdown for an answerer to read first.", { flags: ["--project", "--json"], positional: ["ask"] } ), row(["asks"], "List a project's open asks.", { flags: ["--project", "--json"], }), row(["check"], "Run the gate's checks on your answer locally.", { flags: ["--ask", "--project", "--json"], source: "local", }), row(["claim"], "Claim an ask: an exclusive, expiring right to answer it.", { flags: ["--project", "--json", "--dry-run"], positional: ["ask"], readOnly: false, }), row(["env", "set"], "Set a sensitive env item's value from stdin.", { flags: ["--project", "--yes"], needsApproval: true, positional: ["key"], readOnly: false, source: "local", }), row(["front"], "List the open asks across every project."), row(["login"], "Sign in to a platform.", { flags: ["--url", "--json"], readOnly: false, source: "local", }), row(["mcp"], "Serve the platform's tools over MCP on stdio.", { flags: [], source: "local", }), row(["verdict"], "Show the verdict on an answer to an ask.", { flags: ["--ask", "--head", "--project", "--json"], }),];
const projects: readonly ProjectListing[] = [ { openAsks: 3, posture: "open", project: ProjectName.make("oscabriel/datekit"), }, { openAsks: 1, posture: "openWithSealedEvidence", project: ProjectName.make("oscabriel/burrow"), },];
const linesOf = (text: string) => text.split("\n");
describe("the host's Markdown", () => { it.effect("with a web app, is the text the web served at /llms.txt", () => expectGolden( "host-doc", frontLlms({ commands, platformUrl, projects, webUrl }) ).pipe(Effect.provide(NodeServices.layer)) );
describe("without a web app", () => { const text = frontLlms({ commands, platformUrl, projects }); const lines = linesOf(text);
it("installs the CLI and finds the skills on the platform itself", () => { expect(lines).toContain(`curl -fsSL ${platformUrl}/install.sh | sh`); expect(lines).toContain( `- Skills: ${platformUrl}/.well-known/agent-skills/index.json lists each project's contribute skill, with its digest.` ); expect(lines).toContain( `- Endpoint: ${platformUrl}/mcp (streamable HTTP, MCP 2026-07-28).` ); });
it("gives each project's clone URL in place of a web page", () => { expect(lines).toContain( `- oscabriel/datekit: Open, 3 open asks. Clone: \`git clone ${platformUrl}/oscabriel/datekit.git\`.` ); expect(lines).toContain( `- oscabriel/burrow: Open with sealed evidence, 1 open ask. Clone: \`git clone ${platformUrl}/oscabriel/burrow.git\`.` ); });
it("spells a project as <owner>/<name>, never <project>", () => { expect(text).not.toContain("<project>"); expect(text).toContain("--project <owner>/<name>"); });
it("names no page only a web app serves", () => { expect(text).not.toContain("llms.txt"); expect(text).not.toContain("mcp.json"); expect(text).not.toContain(".md"); });
it("still opens with the name and lists every command", () => { expect(lines[0]).toBe(`# ${Brand.name}`); expect( lines.filter((line) => line.startsWith(`- \`${Brand.cli} `)) ).toHaveLength(commands.length); }); });
it("with a web app, names /llms-full.txt in its opening sentence", () => { const lines = linesOf( frontLlms({ commands, platformUrl, projects, webUrl }) );
expect(lines[4]).toContain(`${webUrl}/llms-full.txt`); });
it("without a web app, names no /llms-full.txt", () => { expect(frontLlms({ commands, platformUrl, projects })).not.toContain( "llms-full.txt" ); });
it("with a web app, names the docs for people under its opening", () => { const lines = linesOf( frontLlms({ commands, platformUrl, projects, webUrl }) );
expect(lines[6]).toBe( `Guides and a reference written for people are at ${webUrl}/docs, each page also as Markdown at ${webUrl}/docs/<page>.md.` ); expect(frontLlms({ commands, platformUrl, projects })).not.toContain( "/docs" ); });});
describe("the index banner", () => { it("is one blockquote naming the index and the full text", () => { const banner = indexBanner({ webUrl });
expect(banner.split("\n")).toHaveLength(1); expect(banner.startsWith("> ")).toBeTruthy(); expect(banner).toContain(`${webUrl}/llms.txt`); expect(banner).toContain(`${webUrl}/llms-full.txt`); });
it("goes under a page's title, and on top of a page without one", () => { const banner = indexBanner({ webUrl });
expect(underTitle("# A title\n\nThe body.\n", banner)).toBe( `# A title\n\n${banner}\n\nThe body.\n` ); expect(underTitle("No title here.\n", banner)).toBe( `${banner}\n\nNo title here.\n` ); });
it("names a project's own index when it has one", () => { expect( indexBanner({ project: ProjectName.make("oscabriel/datekit"), webUrl }) ).toContain(`${webUrl}/oscabriel/datekit/llms.txt`); });
it("follows a project's heading and summary in its llms.txt", () => { const lines = linesOf( projectLlms({ asks: [], commands, listing: projects[0] ?? { openAsks: 0, posture: "open", project: ProjectName.make("oscabriel/datekit"), }, platformUrl, webUrl, }) );
expect(lines[0]).toBe("# oscabriel/datekit"); expect(lines[2]?.startsWith("> A project on ")).toBeTruthy(); expect(lines.slice(3, 6)).toStrictEqual([ "", indexBanner({ project: ProjectName.make("oscabriel/datekit"), webUrl }), "", ]); });});