/** * Code the server sends highlighted (ADR 0027): a blob page's file and a * commit page's first files, drawn by `@pierre/diffs/ssr` into a * declarative shadow root, in a fixed set of languages and within the * server's own limit; anything else is sent as plain text, as before. * * Each page is rendered as its route renders it on the server: the loader * draws the code ahead (`drawFileAhead`, `drawDiffAhead`), then the page * renders with the browser's drawing (`ClientFile`, `ClientDiffs`) holding * the server's fallback, which is all a server render shows. */ import { describe, expect, it } from "@effect/vitest"; import { ChangedFile, CommitDiff, FileView } from "@repo/protocol/domain/code"; import { ProjectName } from "@repo/protocol/ids"; import { DateTime, Effect, Schema } from "effect"; import { renderToStaticMarkup } from "react-dom/server"; import { BlobView } from "../src/features/code/blob-view.tsx"; import { ClientDiffs, ClientFile } from "../src/features/code/client-code.tsx"; import { CommitView } from "../src/features/code/commit-view.tsx"; import { drawnFiles } from "../src/features/code/diff-model.ts"; import { PlainDiff } from "../src/features/code/plain-diff.tsx"; import { prerenderFile } from "../src/features/code/prerender-server.ts"; import { drawDiffAhead, drawFileAhead, prerenderedPaths, prerendersFile, SERVER_FILES, SERVER_LINES, } from "../src/features/code/prerender.ts"; import { FileFallback } from "../src/features/code/server-code.tsx"; const datekit = ProjectName.make("datekit"); const now = DateTime.makeUnsafe("2026-10-07T12:00:00Z"); const AT = "a".repeat(40); const decodeFile = Schema.decodeSync(FileView); const decodeFiles = Schema.decodeSync(Schema.Array(ChangedFile)); /** A highlighted token, as Pierre draws one in the token theme. */ const TOKEN = /--diffs-token-light:var\(--diffs-token-[a-z-]+/gu; /** How many highlighted tokens `markup` holds. */ const tokensIn = (markup: string) => [...markup.matchAll(TOKEN)].length; /** How many server drawings `markup` holds. */ const shadowRootsIn = (markup: string) => [...markup.matchAll(/