Skip to content
Myr

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 file

Take it

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 1–3why, one step back
1// The setup page moved from `/agents` to `/install` (ADR 0041); its guarantee moved with it: every snippet and command
2// 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 back
4import { describe, expect, it } from "@effect/vitest";

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 5–8why, one step back
5import { 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 back
9
10import { commands } from "../src/features/agents/catalog.ts";

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 11–16why, one step back
11import {
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 back
17import { agentsMarkdownHandler } from "../src/routes/agents[.]md.ts";

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 18why, one step back
18import { Route as InstallRoute } from "../src/routes/install.tsx";

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 19why, one step back
19import { renderAt } from "./render.tsx";

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

lines 20–24why, one step back
20
21const platformUrl = "https://platform-test.example.workers.dev";2223const webUrl = "https://web-test.example.workers.dev";24

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 25why, one step back
25const channels = installChannels({ commands, platformUrl, webUrl });

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

lines 26–40why, one step back
26
27const ENTITIES: ReadonlyMap<string, string> = new Map([28 ["&#x27;", "'"],29 ["&amp;", "&"],30 ["&gt;", ">"],31 ["&lt;", "<"],32 ["&quot;", '"'],33]);3435const decoded = (html: string) =>36 html.replaceAll(37 /&(?:#x27|amp|gt|lt|quot);/gu,38 (entity) => ENTITIES.get(entity) ?? entity39 );40

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 41why, one step back
41const textOf = (html: string) => decoded(html.replaceAll(/<[^>]+>/gu, ""));

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

line 42why, one step back
42

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

lines 43–45why, one step back
43const 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 back
46 );
47

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 48why, one step back
48const page = renderAt(

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 49–50why, one step back
49 "/install",
50 <InstallView commands={commands} platformUrl={platformUrl} webUrl={webUrl} />

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 51why, one step back
51);

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

line 52why, one step back
52

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

lines 53–55why, one step back
53const 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 back
56

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 57why, one step back
57 expect(start, `#${id}`).toBeGreaterThanOrEqual(0);

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

line 58why, one step back
58

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

lines 59–60why, one step back
59 return html.slice(start, end);
60};

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

line 61why, one step back
61

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 62–64why, one step back
62const 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 back
65 );
66

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 67–72why, one step back
67const 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 back
73 it.effect(

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 74why, one step back
74 "is titled Install, every heading in sentence case and never mono",

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

lines 75–78why, one step back
75 () =>
76 Effect.gen(function* () {77 const html = yield* page;78

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 79why, one step back
79 expect(html).toMatch(/<h1\b[^>]*>Install<\/h1>/u);

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

lines 80–81why, one step back
80
81 for (const { groups: found } of html.matchAll(

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 82why, one step back
82 /<h(?<level>[1-4])\b(?<attributes>[^>]*)>(?<text>.*?)<\/h\k<level>>/gu

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

lines 83–85why, one step back
83 )) {
84 const words = textOf(found?.text ?? "");85

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 86–87why, one step back
86 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 back
88 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 back
96 "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 back
97 () =>
98 Effect.gen(function* () {99 const html = yield* page;100

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 101–105why, one step back
101 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 back
106

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 107–114why, one step back
107 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 back
115 }

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 116–119why, one step back
116
117 for (const { id } of channels) {118 sectionOf(html, id);119 }

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

lines 120–122why, one step back
120 })
121 );122

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 123why, one step back
123 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 back
124 Effect.gen(function* () {

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 125why, one step back
125 const html = yield* page;

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 126why, one step back
126

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 127–129why, one step back
127 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 back
130

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 131–133why, one step back
131 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 back
134 expect(

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 135–141why, one step back
135 [
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 back
142 }

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

lines 143–144why, one step back
143 })
144 );

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

line 145why, one step back
145

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 146–155why, one step back
146 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 );155

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 156why, one step back
156 it.effect(

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 157why, one step back
157 "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 back
158 () =>
159 Effect.gen(function* () {

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 160–161why, one step back
160 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 back
162

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 163–171why, one step back
163 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 back
172 })
173 );174

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 175–180why, one step back
175 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 back
181

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 182–190why, one step back
182 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 back
191 );
192193 it.effect(

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 194why, one step back
194 "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 back
195 () =>
196 Effect.gen(function* () {

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 197why, one step back
197 const html = yield* page;

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 198why, one step back
198

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 199–211why, one step back
199 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 back
212 );
213 })214 );

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 215why, one step back
215});

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 216why, one step back
216

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 217–218why, one step back
217describe("the old /agents", () => {
218 it.effect("answers a 301 to /install", () =>

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 219why, one step back
219 Effect.gen(function* () {

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 220–230why, one step back
220 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 back
231 })
232 );

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 233–236why, one step back
233
234 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 back
237});
238239describe("/agents.md", () => {

Merge build/1212-people-agents-platform-pagesoscabrielbefore adoptionf44d349

line 240why, one step back
240 it.effect("answers the reference as Markdown for the web's own origin", () =>

Merge build/1107 into mainoscabrielbefore adoption0ac60f3

lines 241–257why, one step back
241 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});