agent-setup.test.ts
This file
Path
packages/agent-kit/test/agent-setup.test.ts
272 lines · 8.0 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake it
Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 1–3why, one step back1import { NodeServices } from "@effect/platform-node";2import { describe, expect, it } from "@effect/vitest";3import { Brand } from "@repo/brand";Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 4why, one step back4import { groups } from "@repo/protocol/refusal";Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 5–6why, one step back5import { Array as Arr, Effect, Option, Schema } from "effect";6Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 7–13why, one step back7import {8 agentEndpoints,9 agentLimits,10 agentSetup,11 agentSetupMarkdown,12 synopsis,13} from "../src/agent-setup.ts";Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 14–151why, one step back14import type { SetupChannel } from "../src/agent-setup.ts";15import type { CommandDoc } from "../src/command-doc.ts";16import { claudePlugin } from "../src/platform.ts";17import { commands as someCommands } from "./fixtures.ts";18import { expectGolden } from "./golden.ts";1920const platformUrl = "https://platform-test.example.workers.dev";2122const webUrl = "https://web-test.example.workers.dev";2324const login: CommandDoc = {25 flags: ["--url", "--json"],26 needsApproval: false,27 path: ["login"],28 positional: [],29 readOnly: false,30 source: "local",31 summary: "Sign in to a platform.",32};3334const mcp: CommandDoc = {35 flags: [],36 needsApproval: false,37 path: ["mcp"],38 positional: [],39 readOnly: true,40 source: "local",41 summary: "Serve the platform's tools over MCP on stdio.",42};4344const commands: readonly CommandDoc[] = [...someCommands, login, mcp];4546const channels = agentSetup({ commands, platformUrl, webUrl });4748const channel = (from: readonly SetupChannel[], title: string) =>49 Option.getOrThrow(Arr.findFirst(from, (each) => each.title === title));5051const snippet = (title: string, label: string) =>52 Option.getOrThrow(53 Arr.findFirst(channel(channels, title).snippets, (each) =>54 each.label.startsWith(label)55 )56 );5758const parsed = Schema.decodeUnknownSync(59 Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown))60);6162const pluginMcpJson = claudePlugin({ commands, platformUrl }).pipe(63 Effect.map((files) =>64 Option.getOrThrow(65 Arr.findFirst(files, ({ path }) => path.endsWith("/.mcp.json"))66 )67 )68);6970describe("the Agents page's source", () => {71 it.effect("as Markdown, is the golden text", () =>72 expectGolden(73 "agent-setup",74 agentSetupMarkdown({ commands, platformUrl, webUrl })75 ).pipe(Effect.provide(NodeServices.layer))76 );7778 it("lists every channel in order, each saying when to use it", () => {79 expect(channels.map(({ title }) => title)).toStrictEqual([80 "Remote MCP",81 "MCP over stdio",82 "The CLI",83 "Text for any agent",84 "Skills",85 ]);8687 for (const each of channels) {88 expect(each.useWhen).not.toBe("");89 expect(each.snippets.length).toBeGreaterThan(0);90 }91 });9293 it("adds the platform's MCP endpoint to Claude Code under the brand's slug", () => {94 expect(snippet("Remote MCP", "Claude Code").text).toBe(95 `claude mcp add --transport http ${Brand.slug} ${platformUrl}/mcp`96 );97 });9899 it.effect(100 "gives VS Code the server the Claude Code plugin's .mcp.json carries",101 () =>102 Effect.gen(function* () {103 const plugin = yield* pluginMcpJson;104 const vscode = snippet("Remote MCP", "VS Code");105106 expect(vscode.language).toBe("json");107 expect(parsed(vscode.text)).toStrictEqual({108 servers: parsed(plugin.content).mcpServers,109 });110 expect(parsed(vscode.text)).toStrictEqual({111 servers: {112 [Brand.slug]: { type: "http", url: `${platformUrl}/mcp` },113 },114 });115 })116 );117118 it("gives Cursor its mcpServers entry with the endpoint's url", () => {119 const cursor = snippet("Remote MCP", "Cursor");120121 expect(cursor.language).toBe("json");122 expect(parsed(cursor.text)).toStrictEqual({123 mcpServers: { [Brand.slug]: { url: `${platformUrl}/mcp` } },124 });125 });126127 it("serves MCP over stdio through the CLI only when the CLI has mcp", () => {128 expect(snippet("MCP over stdio", "").text).toBe(`${Brand.cli} mcp`);129130 const without = agentSetup({131 commands: commands.filter(({ path }) => path.join(" ") !== "mcp"),132 platformUrl,133 webUrl,134 });135136 expect(without.map(({ title }) => title)).not.toContain("MCP over stdio");137 });138139 it("installs the CLI from the web and signs in to the platform", () => {140 expect(141 channel(channels, "The CLI").snippets.map(({ text }) => text)142 ).toStrictEqual([143 `curl -fsSL ${webUrl}/install.sh | sh`,144 `${Brand.cli} login --url ${platformUrl}`,145 ]);146 });147148 it("points any agent at llms.txt and each ask's Markdown", () => {149 const { text } = snippet("Text for any agent", "");150151 expect(text).toContain(`${webUrl}/llms.txt`);Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
line 152why, one step back152 expect(text).toContain(`${webUrl}/<owner>/<name>/asks/<ask>.md`);Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 153–171why, one step back153 });154155 it("adds the skills from the web's index", () => {156 expect(snippet("Skills", "").text).toBe(`npx skills add ${webUrl}`);157 expect(channel(channels, "Skills").useWhen).toContain(158 `${webUrl}/.well-known/agent-skills/index.json`159 );160 });161162 it("writes every snippet into the Markdown whole", () => {163 const text = agentSetupMarkdown({ commands, platformUrl, webUrl });164165 for (const each of channels) {166 expect(text).toContain(`## ${each.title}`);167168 for (const { text: body } of each.snippets) {169 expect(text).toContain(body);170 }171 }Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 172–208why, one step back172 });173});174175describe("the Agents page's reference sections", () => {176 it("gives every command one synopsis line, as typed, with its summary", () => {177 const lines = synopsis(commands);178179 expect(lines.map(({ summary }) => summary)).toStrictEqual(180 commands.map(({ summary }) => summary)181 );182183 for (const [index, command] of commands.entries()) {184 const line = lines[index]?.usage ?? "";185186 expect(187 line.startsWith(`${Brand.cli} ${command.path.join(" ")}`)188 ).toBeTruthy();189190 for (const name of command.positional) {191 expect(line).toContain(`<${name}>`);192 }193 }194195 expect(synopsis([login])).toStrictEqual([196 {197 summary: login.summary,198 usage: `${Brand.cli} login [--url] [--json]`,199 },200 ]);201 });202203 it("names every endpoint an agent reads, on the host that serves it", () => {204 const endpoints = agentEndpoints({ platformUrl, webUrl });205206 expect(endpoints.map(({ url }) => url)).toStrictEqual([207 `${webUrl}/llms.txt`,208 `${webUrl}/llms-full.txt`,Merge build/1413-docs-and-texts into mainoscabrielbefore adoptionf10338e
lines 209–210why, one step back209 `${webUrl}/<owner>/<name>/llms.txt`,210 `${webUrl}/<owner>/<name>/asks/<ask>.md`,Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 211–270why, one step back211 `${webUrl}/agents.md`,212 `${webUrl}/.well-known/mcp.json`,213 `${webUrl}/.well-known/agent-skills/index.json`,214 `${platformUrl}/mcp`,215 `${platformUrl}/<repo>.git`,216 ]);217218 for (const { what } of endpoints) {219 expect(what).not.toBe("");220 }221222 expect(223 endpoints.filter(({ readable }) => readable).map(({ url }) => url)224 ).toStrictEqual([225 `${webUrl}/llms.txt`,226 `${webUrl}/llms-full.txt`,227 `${webUrl}/agents.md`,228 `${webUrl}/.well-known/mcp.json`,229 `${webUrl}/.well-known/agent-skills/index.json`,230 ]);231 });232233 it("states the limits a policy sets by default, as a person says them", () => {234 const values = agentLimits().map(({ value }) => value);235236 expect(values).toStrictEqual([237 "3 by default",238 "2 by default; 0 turns proposals off",239 "Warned after 2 hours, lapses after 1 day, by default",240 "5 by default",241 "2 weeks by default, then it takes its default",242 "A set number a minute; past it, CapReached says when to try again",243 ]);244245 for (const { limit } of agentLimits()) {246 expect(limit).not.toBe("");247 }248 });249250 it("writes the reference sections into the Markdown, in the page's order", () => {251 const text = agentSetupMarkdown({ commands, platformUrl, webUrl });252 const at = (heading: string) => text.indexOf(`\n## ${heading}\n`);253254 const order = ["Synopsis", "Connect", "Endpoints", "Limits", "Refusals"];255256 for (const heading of order) {257 expect(at(heading)).toBeGreaterThan(0);258 }259260 expect(order.map(at)).toStrictEqual(261 order.map(at).toSorted((a, b) => a - b)262 );263264 for (const group of groups) {265 for (const member of group.members) {266 expect(text).toContain(`\`${member.identifier}\``);267 }268 }269270 expect(text).toContain(`${webUrl}/llms-full.txt`);Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 271–272why, one step back271 });272});