home.test.ts
This file
Path
apps/platform/test/home.test.ts
351 lines · 10.4 KiB · TypeScript
Last changed by
Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
History of this fileTake it
Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 1–5why, one step back1import { describe, expect, it } from "@effect/vitest";2import { commandDocs } from "@repo/agent-kit/command-doc";3import { frontLlms } from "@repo/agent-kit/host-doc";4import { Brand } from "@repo/brand";5import { FrontPageMemory } from "@repo/project/front-page/memory";Merge build/1102 into mainoscabrielbefore adoption084383d
lines 6–7why, one step back6import type { ProjectApi } from "@repo/project/project";7import { Projects } from "@repo/project/projects";Join W12 group 1: kept postures on the platform's /, and vellum's standing in the dev worldoscabrielbefore adoptione817d6c
line 8why, one step back8import { StandingPosturesMemory } from "@repo/project/standing-posture/memory";Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 9–11why, one step back9import { Contracts } from "@repo/protocol/contracts";10import type { ProjectListing } from "@repo/protocol/domain/front-page";11import { ProjectName } from "@repo/protocol/ids";Merge build/1102 into mainoscabrielbefore adoption084383d
lines 12–13why, one step back12import { UnknownProject } from "@repo/protocol/refusal";13import { untouchable } from "@repo/testkit/untouchable";Join W12 group 1: kept postures on the platform's /, and vellum's standing in the dev worldoscabrielbefore adoptione817d6c
line 14why, one step back14import { Effect, Layer, Option, Ref } from "effect";Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 15–23why, one step back1516import { MemorySessions } from "../src/sessions/memory.ts";17import { HostInfo } from "../src/surfaces.ts";18import { noProjects, origin, served } from "./harness.ts";1920const webUrl = "https://web-test.example.workers.dev";2122const projects: readonly ProjectListing[] = [23 {Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 24–28why, one step back24 openAsks: 3,25 posture: "open",26 project: ProjectName.make("alice/datekit"),27 },28 {Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 29–30why, one step back29 openAsks: 1,30 posture: "openWithSealedEvidence",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 31why, one step back31 project: ProjectName.make("alice/burrow"),Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 32–34why, one step back32 },33];34Merge build/1102 into mainoscabrielbefore adoption084383d
lines 35–39why, one step back35const datekitSealed = Layer.succeed(36 Projects,37 Projects.of({38 create: () => Effect.die("the home page makes no project"),39 get: (project) =>Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 40why, one step back40 project === "alice/datekit"Merge build/1102 into mainoscabrielbefore adoption084383d
lines 41–42why, one step back41 ? Effect.succeed(42 untouchable<ProjectApi>("ProjectApi", {Merge build/1213-platform-performance-and-agent-surfacesoscabrielbefore adoption1d75a0d
lines 43–44why, one step back43 standing: () =>44 Effect.succeed({ posture: "openWithSealedEvidence", seen: 1 }),Merge build/1102 into mainoscabrielbefore adoption084383d
lines 45–58why, one step back45 })46 )47 : Effect.fail(new UnknownProject({ project })),48 })49);5051const noneMade = Layer.succeed(52 Projects,53 Projects.of({54 create: () => Effect.die("the home page makes no project"),55 get: (project) => Effect.fail(new UnknownProject({ project })),56 })57);58Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 59–60why, one step back59const platform = (60 listed: readonly ProjectListing[],Merge build/1102 into mainoscabrielbefore adoption084383d
lines 61–62why, one step back61 web: Option.Option<string> = Option.some(webUrl),62 made: Layer.Layer<Projects> = noneMadeMerge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 63–65why, one step back63) =>64 served(65 Layer.mergeAll(Merge build/1102 into mainoscabrielbefore adoption084383d
line 66why, one step back66 made,Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 67–79why, one step back67 noProjects,68 MemorySessions.layer({}),69 FrontPageMemory.layer({ credits: [], entries: [], projects: listed }),70 Layer.succeed(71 HostInfo,72 HostInfo.of({ draftModel: "@cf/test/drafter", webUrl: web })73 )74 )75 );7677const home = (78 listed: readonly ProjectListing[],79 init: RequestInit = {},Merge build/1102 into mainoscabrielbefore adoption084383d
lines 80–81why, one step back80 web?: Option.Option<string>,81 made?: Layer.Layer<Projects>Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 82–83why, one step back82) =>83 Effect.gen(function* () {Merge build/1102 into mainoscabrielbefore adoption084383d
line 84why, one step back84 const { fetch } = yield* platform(listed, web, made);Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 85–105why, one step back85 const response = yield* fetch(new Request(`${origin}/`, init));8687 return {88 status: response.status,89 text: yield* Effect.promise(() => response.text()),90 type: response.headers.get("content-type"),91 };92 });9394const html = { headers: { accept: "text/html,application/xhtml+xml" } };9596describe("the platform's /", () => {97 it.effect("tells a browser what this host serves, from its origin", () =>98 Effect.gen(function* () {99 const { status, text, type } = yield* home(projects, html);100101 expect(status).toBe(200);102 expect(type).toBe("text/html; charset=utf-8");103 expect(text).toContain(`<h1>${Brand.name}</h1>`);104105 for (const named of [Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 106–107why, one step back106 `git clone ${origin}/alice/datekit.git`,107 `git clone ${origin}/alice/burrow.git`,Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 108–187why, one step back108 `curl -fsSL ${origin}/install.sh | sh`,109 `${origin}/releases/manifest.json`,110 `${origin}/mcp`,111 "2026-07-28",112 `POST ${origin}/rpc`,113 `${origin}/.well-known/agent-skills/index.json`,114 `${origin}/.well-known/oauth-protected-resource`,115 `${origin}/.well-known/oauth-authorization-server`,116 `${origin}/signup`,117 `${origin}/authorize`,118 "@cf/test/drafter",119 `${origin}/health`,120 `<a href="${webUrl}">Open the web app</a>`,121 ]) {122 expect(text).toContain(named);123 }124 })125 );126127 it.effect("links no web app on a host that has none", () =>128 Effect.gen(function* () {129 const { status, text } = yield* home(projects, html, Option.none());130131 expect(status).toBe(200);132 expect(text).not.toContain("Open the web app");133 expect(text).not.toContain(webUrl);134 })135 );136137 it.effect("says so when no project is listed yet", () =>138 Effect.gen(function* () {139 const { text } = yield* home([], html);140141 expect(text).toContain("No project is on the platform yet.");142 expect(text).not.toContain("git clone");143 })144 );145146 it.effect("escapes whatever a listing names", () =>147 Effect.gen(function* () {148 const crafted = ProjectName.make(`<script>alert("x")</script>`, {149 disableChecks: true,150 });151152 const { text } = yield* home(153 [{ openAsks: 0, posture: "open", project: crafted }],154 html155 );156157 expect(text).not.toContain("<script>");158 expect(text).toContain(159 "<script>alert("x")</script>"160 );161 })162 );163164 it.effect("gives an agent the web's /llms.txt as Markdown", () =>165 Effect.gen(function* () {166 const expected = frontLlms({167 commands: commandDocs(Contracts),168 platformUrl: origin,169 projects,170 webUrl,171 });172173 const markdown = yield* home(projects, {174 headers: { accept: "text/markdown" },175 });176177 const plain = yield* home(projects, {178 headers: { accept: "text/plain" },179 });180181 expect(markdown).toStrictEqual({182 status: 200,183 text: expected,184 type: "text/markdown; charset=utf-8",185 });186 expect(plain.text).toBe(expected);187 })Merge build/1102 into mainoscabrielbefore adoption084383d
lines 188–208why, one step back188 );189190 it.effect(191 "gives each project the posture its own ledger stands at, as the web's /llms.txt does",192 () =>193 Effect.gen(function* () {194 const { text } = yield* home(195 projects,196 { headers: { accept: "text/markdown" } },197 undefined,198 datekitSealed199 );200201 expect(text).toBe(202 frontLlms({203 commands: commandDocs(Contracts),204 platformUrl: origin,205 projects: [206 {207 openAsks: 3,208 posture: "openWithSealedEvidence",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 209why, one step back209 project: ProjectName.make("alice/datekit"),Merge build/1102 into mainoscabrielbefore adoption084383d
lines 210–213why, one step back210 },211 {212 openAsks: 1,213 posture: "openWithSealedEvidence",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 214why, one step back214 project: ProjectName.make("alice/burrow"),Merge build/1102 into mainoscabrielbefore adoption084383d
lines 215–220why, one step back215 },216 ],217 webUrl,218 })219 );220 expect(text).toContain(Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 221why, one step back221 `- [alice/datekit](${webUrl}/alice/datekit/llms.txt): Open with sealed evidence, 3 open asks.`Merge build/1102 into mainoscabrielbefore adoption084383d
line 222why, one step back222 );Join W12 group 1: kept postures on the platform's /, and vellum's standing in the dev worldoscabrielbefore adoptione817d6c
lines 223–236why, one step back223 })224 );225226 it.effect(227 "keeps the posture it read in the platform's kept postures, so a second / reads no project",228 () =>229 Effect.gen(function* () {230 const reads = yield* Ref.make(0);231232 const counted = Layer.succeed(233 Projects,234 Projects.of({235 create: () => Effect.die("the home page makes no project"),236 get: (project) =>Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 237why, one step back237 project === "alice/datekit"Join W12 group 1: kept postures on the platform's /, and vellum's standing in the dev worldoscabrielbefore adoptione817d6c
lines 238–274why, one step back238 ? Effect.succeed(239 untouchable<ProjectApi>("ProjectApi", {240 standing: () =>241 Effect.as(242 Ref.update(reads, (count) => count + 1),243 { posture: "openWithSealedEvidence", seen: 1 }244 ),245 })246 )247 : Effect.fail(new UnknownProject({ project })),248 })249 );250251 const { fetch } = yield* served(252 Layer.mergeAll(253 counted,254 noProjects,255 StandingPosturesMemory,256 MemorySessions.layer({}),257 FrontPageMemory.layer({ credits: [], entries: [], projects }),258 Layer.succeed(259 HostInfo,260 HostInfo.of({261 draftModel: "@cf/test/drafter",262 webUrl: Option.some(webUrl),263 })264 )265 )266 );267268 const markdown = { headers: { accept: "text/markdown" } };269270 for (const _ of [1, 2]) {271 const response = yield* fetch(new Request(`${origin}/`, markdown));272 const text = yield* Effect.promise(() => response.text());273274 expect(text).toContain(Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 275why, one step back275 `- [alice/datekit](${webUrl}/alice/datekit/llms.txt): Open with sealed evidence, 3 open asks.`Join W12 group 1: kept postures on the platform's /, and vellum's standing in the dev worldoscabrielbefore adoptione817d6c
lines 276–279why, one step back276 );277 }278279 expect(yield* Ref.get(reads)).toBe(1);Merge build/1102 into mainoscabrielbefore adoption084383d
line 280why, one step back280 })Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 281–336why, one step back281 );282283 it.effect(284 "gives an agent the platform's own Markdown on a host with no web app",285 () =>286 Effect.gen(function* () {287 const { text, type } = yield* home(288 projects,289 { headers: { accept: "text/markdown" } },290 Option.none()291 );292293 expect({ text, type }).toStrictEqual({294 text: frontLlms({295 commands: commandDocs(Contracts),296 platformUrl: origin,297 projects,298 }),299 type: "text/markdown; charset=utf-8",300 });301 })302 );303304 it.effect.each([305 { accept: undefined, wants: "html" },306 { accept: "*/*", wants: "html" },307 {308 accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",309 wants: "html",310 },311 { accept: "text/html, text/markdown;q=0.5", wants: "html" },312 { accept: "text/html;q=0.5, text/markdown", wants: "markdown" },313 { accept: "text/plain, text/html", wants: "markdown" },314 { accept: "text/markdown;q=0, text/html;q=0.1", wants: "html" },315 ])("answers Accept $accept with $wants", ({ accept, wants }) =>316 Effect.gen(function* () {317 const { type } = yield* home(318 projects,319 accept === undefined ? {} : { headers: { accept } }320 );321322 expect(type).toBe(323 wants === "html"324 ? "text/html; charset=utf-8"325 : "text/markdown; charset=utf-8"326 );327 })328 );329330 it.effect("answers a stale credential, as every public path does", () =>331 Effect.gen(function* () {332 const { status, text } = yield* home(projects, {333 headers: { ...html.headers, authorization: "Bearer nope" },334 });335336 expect(status).toBe(200);Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 337why, one step back337 expect(text).toContain(`git clone ${origin}/alice/datekit.git`);Merge branch 'build/906-platform-root-page'oscabrielbefore adoption10c8b54
lines 338–351why, one step back338 })339 );340341 it.effect("answers HEAD with no body", () =>342 Effect.gen(function* () {343 const { status, text } = yield* home(projects, {344 ...html,345 method: "HEAD",346 });347348 expect({ status, text }).toStrictEqual({ status: 200, text: "" });349 })350 );351});