agents.test.tsx
This file
Path
apps/web/test/agents.test.tsx
257 lines · 7.8 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 1–3why, one step back1// The setup page moved from `/agents` to `/install` (ADR 0041); its guarantee moved with it: every snippet and command2// on the page is `@repo/agent-kit`'s. Its endpoints and limits moved to the docs' Limits and endpoints page, held by3// `docs.test.tsx` and agent-kit's `docs.test.ts`.Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 4why, one step back4import { describe, expect, it } from "@effect/vitest";Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 5–8why, one step back5import { agentSetupMarkdown } from "@repo/agent-kit/agent-setup";6import { installChannels } from "@repo/agent-kit/install-channels";7import { isRedirect } from "@tanstack/react-router";8import { Effect, Option } from "effect";Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 9–10why, one step back910import { commands } from "../src/features/agents/catalog.ts";Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 11–16why, one step back11import {12 installHref,13 InstallView,14} from "../src/features/agents/install-page.tsx";15import { getRouter } from "../src/router.tsx";16import { agentsLoader } from "../src/routes/agents.tsx";Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 17why, one step back17import { agentsMarkdownHandler } from "../src/routes/agents[.]md.ts";Merge redesign into mainoscabrielbefore adoptioncaedd21
line 18why, one step back18import { Route as InstallRoute } from "../src/routes/install.tsx";Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 19why, one step back19import { renderAt } from "./render.tsx";Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 20–24why, one step back2021const platformUrl = "https://platform-test.example.workers.dev";2223const webUrl = "https://web-test.example.workers.dev";24Merge redesign into mainoscabrielbefore adoptioncaedd21
line 25why, one step back25const channels = installChannels({ commands, platformUrl, webUrl });Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 26–40why, one step back2627const ENTITIES: ReadonlyMap<string, string> = new Map([28 ["'", "'"],29 ["&", "&"],30 [">", ">"],31 ["<", "<"],32 [""", '"'],33]);3435const decoded = (html: string) =>36 html.replaceAll(37 /&(?:#x27|amp|gt|lt|quot);/gu,38 (entity) => ENTITIES.get(entity) ?? entity39 );40Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 41why, one step back41const textOf = (html: string) => decoded(html.replaceAll(/<[^>]+>/gu, ""));Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 42why, one step back42Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 43–45why, one step back43const codeOf = (html: string) =>44 [...html.matchAll(/<code\b[^>]*>(?<body>.*?)<\/code>/gsu)].map(45 ({ groups: found }) => textOf(found?.body ?? "")Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 46–47why, one step back46 );47Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 48why, one step back48const page = renderAt(Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 49–50why, one step back49 "/install",50 <InstallView commands={commands} platformUrl={platformUrl} webUrl={webUrl} />Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 51why, one step back51);Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 52why, one step back52Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 53–55why, one step back53const sectionOf = (html: string, id: string) => {54 const start = html.indexOf(`<section aria-labelledby="${id}"`);55 const end = html.indexOf("</section>", start);Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 56why, one step back56Merge redesign into mainoscabrielbefore adoptioncaedd21
line 57why, one step back57 expect(start, `#${id}`).toBeGreaterThanOrEqual(0);Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 58why, one step back58Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 59–60why, one step back59 return html.slice(start, end);60};Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 61why, one step back61Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 62–64why, one step back62const channelNamed = (id: string) =>63 Option.getOrThrow(64 Option.fromNullishOr(channels.find((each) => each.id === id))Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 65–66why, one step back65 );66Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 67–72why, one step back67const snippetCount = channels.reduce(68 (count, { snippets }) => count + snippets.length,69 070);7172describe("the Install page", () => {Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 73why, one step back73 it.effect(Merge redesign into mainoscabrielbefore adoptioncaedd21
line 74why, one step back74 "is titled Install, every heading in sentence case and never mono",Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 75–78why, one step back75 () =>76 Effect.gen(function* () {77 const html = yield* page;78Merge redesign into mainoscabrielbefore adoptioncaedd21
line 79why, one step back79 expect(html).toMatch(/<h1\b[^>]*>Install<\/h1>/u);Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 80–81why, one step back8081 for (const { groups: found } of html.matchAll(Merge redesign into mainoscabrielbefore adoptioncaedd21
line 82why, one step back82 /<h(?<level>[1-4])\b(?<attributes>[^>]*)>(?<text>.*?)<\/h\k<level>>/guMerge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 83–85why, one step back83 )) {84 const words = textOf(found?.text ?? "");85Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 86–87why, one step back86 expect(found?.attributes).not.toContain("uppercase");87 expect(found?.attributes).not.toContain("font-mono");Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 88–95why, one step back88 expect(89 words === words.toUpperCase() && /[A-Z]/u.test(words)90 ).toBeFalsy();91 }92 })93 );9495 it.effect(Merge redesign into mainoscabrielbefore adoptioncaedd21
line 96why, one step back96 "gives every channel agent-kit names its own section, in order, headed by its title below the sticky bar",Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 97–100why, one step back97 () =>98 Effect.gen(function* () {99 const html = yield* page;100Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 101–105why, one step back101 const headings = [102 ...html.matchAll(103 /<h2 (?<attributes>[^>]*)id="(?<id>[a-z]+)"[^>]*>(?<text>[^<]*)<\/h2>/gu104 ),105 ];Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 106why, one step back106Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 107–114why, one step back107 expect(108 headings.map(({ groups: found }) => [found?.id, found?.text])109 ).toStrictEqual(channels.map(({ id, title }) => [id, title]));110111 for (const { groups: found } of headings) {112 expect(found?.attributes, `#${found?.id}`).toContain(113 "scroll-mt-[calc(var(--top-bar)+"114 );Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 115why, one step back115 }Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 116–119why, one step back116117 for (const { id } of channels) {118 sectionOf(html, id);119 }Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 120–122why, one step back120 })121 );122Merge redesign into mainoscabrielbefore adoptioncaedd21
line 123why, one step back123 it.effect("shows every snippet agent-kit gives, and no code of its own", () =>Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 124why, one step back124 Effect.gen(function* () {Merge redesign into mainoscabrielbefore adoptioncaedd21
line 125why, one step back125 const html = yield* page;Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 126why, one step back126Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 127–129why, one step back127 expect(codeOf(html)).toStrictEqual(128 channels.flatMap(({ snippets }) => snippets.map(({ text }) => text))129 );Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 130why, one step back130Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 131–133why, one step back131 const text = textOf(html);132133 for (const { audience, snippets, summary, title } of channels) {Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 134why, one step back134 expect(Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 135–141why, one step back135 [136 audience,137 summary,138 title,139 ...snippets.map(({ label }) => label),140 ].filter((words) => !text.includes(words))141 ).toStrictEqual([]);Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 142why, one step back142 }Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 143–144why, one step back143 })144 );Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 145why, one step back145Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 146–155why, one step back146 it.effect("gives every snippet a button that copies it", () =>147 Effect.gen(function* () {148 expect(149 (yield* page).match(150 /<button\b[^>]*>(?:(?!<\/button>).)*Copy(?:(?!<\/button>).)*<\/button>/gu151 )152 ).toHaveLength(snippetCount);153 })154 );155Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 156why, one step back156 it.effect(Merge redesign into mainoscabrielbefore adoptioncaedd21
line 157why, one step back157 "shows MCP's clients and stdio as tabs, each with its snippet in a panel",Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 158–159why, one step back158 () =>159 Effect.gen(function* () {Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 160–161why, one step back160 const mcp = sectionOf(yield* page, "mcp");161 const names = channelNamed("mcp").snippets.map(({ name }) => name);Merge build/1107 into mainoscabrielbefore adoption0ac60f3
line 162why, one step back162Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 163–171why, one step back163 expect(mcp).toContain('role="tablist"');164 expect(165 [166 ...mcp.matchAll(167 /<button\b[^>]*role="tab"[^>]*>(?<name>.*?)<\/button>/gu168 ),169 ].map(({ groups: found }) => textOf(found?.name ?? ""))170 ).toStrictEqual(names);171 expect(mcp.match(/role="tabpanel"/gu)).toHaveLength(names.length);Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 172–174why, one step back172 })173 );174Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 175–180why, one step back175 it.effect(176 "shows the pi extension as planned, with no command, and git over HTTPS with no SSH key",177 () =>178 Effect.gen(function* () {179 const html = yield* page;180 const pi = sectionOf(html, "pi");Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 181why, one step back181Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 182–190why, one step back182 expect(textOf(pi)).toContain("Planned");183 expect(codeOf(pi)).toStrictEqual([]);184 expect(textOf(sectionOf(html, "git"))).toContain("HTTPS");185 expect(186 textOf(html)187 .replaceAll("no SSH keys", "")188 .match(/ssh|git@/giu)189 ).toBeNull();190 })Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 191–193why, one step back191 );192193 it.effect(Merge redesign into mainoscabrielbefore adoptioncaedd21
line 194why, one step back194 "links each channel's references, the commands and the limits at the docs, and signing in back to /install",Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 195–196why, one step back195 () =>196 Effect.gen(function* () {Merge redesign into mainoscabrielbefore adoptioncaedd21
line 197why, one step back197 const html = yield* page;Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 198why, one step back198Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 199–211why, one step back199 expect(200 channels201 .flatMap(({ id, links }) =>202 links.map((link) => ({ href: installHref(link), id }))203 )204 .filter(205 ({ href, id }) => !sectionOf(html, id).includes(`href="${href}"`)206 )207 ).toStrictEqual([]);208 expect(sectionOf(html, "cli")).toContain('href="/docs/commands"');209 expect(sectionOf(html, "text")).toContain('href="/docs/limits"');210 expect(sectionOf(html, "web")).toContain(211 'href="/auth/signin?return=%2Finstall"'Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 212–214why, one step back212 );213 })214 );Merge redesign into mainoscabrielbefore adoptioncaedd21
line 215why, one step back215});Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 216why, one step back216Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 217–218why, one step back217describe("the old /agents", () => {218 it.effect("answers a 301 to /install", () =>Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 219why, one step back219 Effect.gen(function* () {Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 220–230why, one step back220 const answered = yield* Effect.flip(221 Effect.tryPromise({222 catch: (thrown): readonly [number, string | null] =>223 isRedirect(thrown)224 ? [thrown.status, thrown.headers.get("location")]225 : [0, null],226 try: agentsLoader,227 })228 );229230 expect(answered).toStrictEqual([301, "/install"]);Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
lines 231–232why, one step back231 })232 );Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 233–236why, one step back233234 it("leaves /install to the Install page", () => {235 expect(getRouter().getMatchedRoutes("/install")[2]).toBe(InstallRoute);236 });Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 237–239why, one step back237});238239describe("/agents.md", () => {Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349
line 240why, one step back240 it.effect("answers the reference as Markdown for the web's own origin", () =>Merge build/1107 into mainoscabrielbefore adoption0ac60f3
lines 241–257why, one step back241 Effect.gen(function* () {242 const response = yield* Effect.promise(() =>243 agentsMarkdownHandler(platformUrl)({244 request: new Request(`${webUrl}/agents.md`),245 })246 );247248 expect(response.status).toBe(200);249 expect(response.headers.get("content-type")).toBe(250 "text/markdown; charset=utf-8"251 );252 expect(yield* Effect.promise(() => response.text())).toBe(253 agentSetupMarkdown({ commands, platformUrl, webUrl })254 );255 })256 );257});