Hold the ask page's headers and not-found pages to decoded names, and test the page loaders
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Review of 512 against its issue and AGENTS.md; fixes on the branch: - The ask page's `Link` header put raw path params into a header. A path that can name no ask (a 404) now gets only `Vary: Accept`, so no decoded `%0A` or `>` from the URL reaches a header (500 or a forged link parameter otherwise); a name that decodes as `AskPath` keeps its alternate. - A `?head=` that is not a whole commit id is a 404 that said the project's or ask's name was wrong. The answer page's not-found now says `?head=` takes the full 40-hex commit id too (`NotFoundView`'s `nothing`, default unchanged for the ask page). - One not-found page for both routes: `NoSuchAsk` in `features/ask/refused.tsx` decodes the refusals a loader's not-found carried (the two identical route components and their decoders are gone). The link class lives once, as `LINK` in `fields.tsx`. - `ContractVisibility` is read from the `Visibility` annotation's own type instead of restating its union. - `readAsk` and `readAnswer` are exported for their tests; the client entry is unchanged (717,829), since the client imports only `Route`. - Tests added: `readAnswer` reads a landed answer's landing, asks for no landing when the answer did not land, shows the verdict alone on `UnknownCommit`, carries `UnknownAsk` in its not-found, and asks nothing for a short `?head=`; `readAsk` reads the ask, carries `UnknownAsk`, and asks nothing for a bad name; `NoSuchAsk` decodes a cloned, encoded not-found and shows a route's own fallback; the page's headers for an undecodable path; `askMarkdownResponse` never caches a `maintainers` contract's answer. - Tests tightened: the answer page's held-back list must read exactly `export 6/7 @ <suite>` (the Check's "no other held-back detail"), and the ask page's `<pre>` must hold the whole brief, not its first 60 characters. Web tests 85 → 96.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+378 added−75 removed
- tests:+313 added−27 removed
- other:+65 added−48 removed
Provenance
- Commit
88a09d9- Tree
9951dc9- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
b99c185
11 files changed+378 added−75 removed
modified:apps/web/src/features/answer/answer-page.tsx+1 added-3 removed
36 unmodified lines37 TableHeader,38 TableRow,39 } from "../../components/ui/table.tsx";40 import { askPath } from "../ask/ask-page.tsx";41-import { CODE, Field, Fields, Region } from "../ask/fields.tsx";41+import { CODE, Field, Fields, LINK, Region } from "../ask/fields.tsx";42 import { CommandLine } from "../shared/command.tsx";43 import { CreditTrailers } from "../shared/credits.tsx";44 import { EmptyState } from "../shared/empty.tsx";45 import { OutcomeView, StageStrip } from "../shared/outcome.tsx";116 unmodified lines162 {short(sha)}163 </code>164 );165 166-const LINK = "decoration-rule underline hover:decoration-current";167-166 export const AnswerView = ({167 landing,168 now,169 verdict,82 unmodified linesmodified:apps/web/src/features/ask/ask-page.tsx+1 added-3 removed
17 unmodified lines18 import { CommandLine } from "../shared/command.tsx";19 import { HandleLink } from "../shared/handle.tsx";20 import { PageShell } from "../shared/layout.tsx";21 import { When } from "../shared/time.tsx";22-import { CODE, Field, Fields, Region } from "./fields.tsx";22+import { CODE, Field, Fields, LINK, Region } from "./fields.tsx";23 import { markdownPath } from "./markdown.ts";24 25 /** An ask's page. */26 export const askPath = (project: ProjectName, ask: AskId) =>2 unmodified lines29 /** The page of the verdict on an ask's latest answer. */30 export const answerPath = (project: ProjectName, ask: AskId) =>31 `/${project}/answers/${ask}`;32 33-const LINK = "decoration-rule underline hover:decoration-current";34-33 /** Each state as a mark, a word and its role colour (none for open: nothing is happening yet). */34 const states = {35 claimed: { icon: CircleDot, tone: "", word: "Claimed" },36 closed: { icon: Minus, tone: "text-muted-foreground", word: "Closed" },290 unmodified linesmodified:apps/web/src/features/ask/fields.tsx+3 added
7 unmodified lines8910111213141516171841 unmodified lines7 unmodified lines
/** Text that is code: an id, a path, a SHA, a command's name. */export const CODE = "font-mono text-[0.8125rem] [overflow-wrap:anywhere]";
/** A link in running text: underlined in the rule colour, darker on hover. */export const LINK = "decoration-rule underline hover:decoration-current";
export const Fields = ({ children, label,}: {41 unmodified linesmodified:apps/web/src/features/ask/markdown.ts+3 added-2 removed
7 unmodified lines8 * `@repo/protocol/render` (AGENTS.md principle 3), then its next command.9 * Pure: a `Request` or an `Exit` in, a string or a `Response` out.10 */11 import { Brand } from "@repo/brand";12+import type { Visibility } from "@repo/protocol/annotations";13 import { Refusal } from "@repo/protocol/refusal";14 import { explain } from "@repo/protocol/render";15 import { Array, Cause, Exit, Option, Schema } from "effect";16 17 const MARKDOWN = "text/markdown; charset=utf-8";18 18-/** Who may share the answer: a `public` contract's for a minute, a `maintainers` one's never. */19-export type ContractVisibility = "public" | "maintainers";19+/** A contract's `Visibility` (spec §3.1): a `public` one's answer may be cached for a minute, a `maintainers` one's never. */20+export type ContractVisibility = ReturnType<typeof Visibility.defaultValue>;21 22 /** One range of an `Accept` header: `text/markdown;q=0.8`. */23 interface MediaRange {24 readonly quality: number;170 unmodified linesmodified:apps/web/src/features/ask/refused.tsx+30 added-3 removed
1234566789101011121314157 unmodified lines23242526272829303132333435363738394041354243444546474849505152535455565758596061626364656667/** * The page for an address that names no ask, or no answer: a 404 whose body * is the refusal the platform gave (`UnknownProject`, `UnknownAsk`), as * `git push` printed it, so a person reads what an agent reads in Markdown. * The refusals travel from the server in a not-found's data, encoded as * `Refusals`; the route decodes them (AGENTS.md principle 2). * `Refusals`; `NoSuchAsk` decodes them where they arrive (AGENTS.md * principle 2). */import { Refusal } from "@repo/protocol/refusal";import { notFound } from "@tanstack/react-router";import { Effect, Schema } from "effect";import { Effect, Option, Schema } from "effect";import type { Array } from "effect";
import { EmptyState } from "../shared/empty.tsx";import { PageShell } from "../shared/layout.tsx";7 unmodified lines Effect.flatMap(Schema.encodeEffect(Refusals)([refusal]), (data) => Effect.fail(notFound({ data })) );
/** What a 404 says when the address could name no ask, so no refusal came back. */export const NAMES_ONLY = "Nothing is at this address: a project's and an ask's names are lowercase words joined by single dashes.";
export const NotFoundView = ({ nothing = NAMES_ONLY, refusals, title,}: { readonly nothing?: string; readonly refusals: Array.NonEmptyReadonlyArray<Refusal> | undefined; readonly title: string;}) => ( <PageShell title={title}> {refusals === undefined ? ( <EmptyState title="Nothing is at this address: a project's and an ask's names are lowercase words joined by single dashes." /> <EmptyState title={nothing} /> ) : ( <RefusalView refusals={refusals} /> )} </PageShell>);
const decodeRefusals = Schema.decodeUnknownOption(Refusals);
/** * A route's not-found page: the refusals its loader's not-found carried, * decoded; `nothing` when it carried none (the address could name no ask). */export const NoSuchAsk = ({ data, nothing = NAMES_ONLY,}: { readonly data?: unknown; readonly nothing?: string;}) => ( <NotFoundView nothing={nothing} refusals={Option.getOrUndefined(decodeRefusals(data))} title="No such ask" />);modified:apps/web/src/routes/$project/answers/$ask.tsx+7 added-15 removed
12 unmodified lines13 14 import { landingAtom, verdictAtom } from "../../../client/answer.ts";15 import { AnswerView } from "../../../features/answer/answer-page.tsx";16 import { answerPath } from "../../../features/ask/ask-page.tsx";17-import { CODE } from "../../../features/ask/fields.tsx";18-import {19- NotFoundView,20- notFoundFor,21- Refusals,22-} from "../../../features/ask/refused.tsx";17+import { CODE, LINK } from "../../../features/ask/fields.tsx";18+import { NoSuchAsk, notFoundFor } from "../../../features/ask/refused.tsx";19 import { PageShell, pageTitle } from "../../../features/shared/layout.tsx";20 import { serverClient } from "../../../server/client.ts";21 22 // The answer page: the latest verdict on an answer to an ask, stage by30 unmodified lines53 ? verdict.outcome.sha54 : undefined;55 56 /** The verdict for the page and, if its answer landed, the landing; or a not-found carrying the refusal (a 404). */61-const readAnswer = ({ ask, head, project }: AnswerAddress) =>57+export const readAnswer = ({ ask, head, project }: AnswerAddress) =>58 Effect.gen(function* () {59 const path = yield* Schema.decodeEffect(AnswerPath)(60 head === undefined ? { ask, project } : { ask, head, project }61 ).pipe(Effect.mapError(() => notFound()));89 unmodified lines151 />152 );153 };154 159-const LINK = "decoration-rule underline hover:decoration-current";160-155 const AnswerPage = () => {156 const read = Schema.decodeSync(AnswerPageData)(Route.useLoaderData());157 const { ask, head, landing, project, verdict } = read;158 const atom = verdictAtom(project, ask, head);33 unmodified lines192 </PageShell>193 );194 };195 202-/** A not-found's refusals, decoded where they arrive; none when it carries none. */203-const decodeRefusals = Schema.decodeUnknownOption(Refusals);196+/** An address with no refusal behind it: a name that can name nothing, or a `?head=` that is no commit id. */197+const NOTHING =198+ "Nothing is at this address: a project's and an ask's names are lowercase words joined by single dashes, and ?head= takes an answer's whole commit id, 40 hex digits.";199 200 const AnswerNotFound = ({ data }: { readonly data?: unknown }) => (206- <NotFoundView207- refusals={Option.getOrUndefined(decodeRefusals(data))}208- title="No such ask"209- />201+ <NoSuchAsk data={data} nothing={NOTHING} />202 );203 204 export const Route = createFileRoute("/$project/answers/$ask")({205 // TanStack infers each option from the ones before it, so the search comes11 unmodified linesmodified:apps/web/src/routes/$project/asks/$ask.tsx+20 added-22 removed
11 unmodified lines12 import {13 markdownAlternate,14 wantsMarkdown,15 } from "../../../features/ask/markdown.ts";16-import {17- NotFoundView,18- notFoundFor,19- Refusals,20-} from "../../../features/ask/refused.tsx";16+import { NoSuchAsk, notFoundFor } from "../../../features/ask/refused.tsx";17 import { pageTitle } from "../../../features/shared/layout.tsx";18 import { serverClient } from "../../../server/client.ts";19 import { AskPath, askMarkdownHandler } from "./{$ask}[.]md.ts";20 import type { AskParams, ClientFor } from "./{$ask}[.]md.ts";21 unmodified lines42 wantsMarkdown(request)43 ? askMarkdownHandler(clientFor)({ params, request })44 : next();45 50-/** The page's headers: its Markdown as an alternate, and that the URL answers by `Accept`. */51-export const askPageHeaders = ({ params }: { readonly params: AskParams }) => ({52- link: markdownAlternate(params.project, params.ask),53- vary: "Accept",54-});46+/**47+ * The page's headers: that the URL answers by `Accept`, and, for a path that48+ * can name an ask, its Markdown as an alternate. A path that cannot (a 404)49+ * names none, so no raw path text reaches a header.50+ */51+export const askPageHeaders = ({52+ params,53+}: {54+ readonly params: AskParams;55+}): Readonly<Record<string, string>> =>56+ Option.match(Schema.decodeOption(AskPath)(params), {57+ onNone: () => ({ vary: "Accept" }),58+ onSome: ({ ask, project }) => ({59+ link: markdownAlternate(project, ask),60+ vary: "Accept",61+ }),62+ });63 64 /** What the page's loader carries from the server, encoded: the ask, its brief, and when it was read. */65 const AskPageData = Schema.Struct({66 ask: Ask,1 unmodified line68 now: Schema.DateTimeUtcFromString,69 });70 71 /** The ask for its page, or a not-found carrying the platform's refusal (a 404). */64-const readAsk = (params: AskParams) =>72+export const readAsk = (params: AskParams) =>73 Effect.gen(function* () {74 const path = yield* Schema.decodeEffect(AskPath)(params).pipe(75 Effect.mapError(() => notFound())76 );70 unmodified lines147 </RegistryProvider>148 );149 };150 143-/** A not-found's refusals, decoded where they arrive; none when it carries none. */144-const decodeRefusals = Schema.decodeUnknownOption(Refusals);145-146-const AskNotFound = ({ data }: { readonly data?: unknown }) => (147- <NotFoundView148- refusals={Option.getOrUndefined(decodeRefusals(data))}149- title="No such ask"150- />151-);152-151 export const Route = createFileRoute("/$project/asks/$ask")({152 // TanStack infers each option from the ones before it: the loader comes153 // first, so `head` reads its data.154 loader: ({ params }) => askPage({ data: params }),7 unmodified lines162 ],163 }),164 headers: askPageHeaders,165 component: AskPage,168- notFoundComponent: AskNotFound,166+ notFoundComponent: NoSuchAsk,167 server: {168 handlers: {169 GET: askPageHandler((request) => serverClient(env, request)),170 },2 unmodified linesmodified:apps/web/test/answer.test.tsx+175 added-3 removed
5 unmodified lines6 * answer shows its landing's credit trailers and the commit.7 */8 import { describe, expect, it } from "@effect/vitest";9 import { Brand } from "@repo/brand";10+import { Client, Contracts } from "@repo/protocol/contracts";11 import { Outcome } from "@repo/protocol/domain/outcome";11-import { AreaName } from "@repo/protocol/ids";12-import { ChecksFailed, HeldBackFailed } from "@repo/protocol/refusal";12+import { AreaName, AskId } from "@repo/protocol/ids";13+import {14+ ChecksFailed,15+ HeldBackFailed,16+ UnknownAsk,17+ UnknownCommit,18+} from "@repo/protocol/refusal";19 import { explain } from "@repo/protocol/render";20+import { asTester, unanswered } from "@repo/protocol/testing";21+import { isNotFound } from "@tanstack/react-router";22+import { Effect, Layer, Ref, Schema } from "effect";23+import { RpcTest } from "effect/rpc";24 25 import {26 AnswerView,27 HeldBackBits,28 LaneTable,29 } from "../src/features/answer/answer-page.tsx";30+import { Refusals } from "../src/features/ask/refused.tsx";31+import { readAnswer } from "../src/routes/$project/answers/$ask.tsx";32 import {33+ askId,34 inOrder,35 landedSha,36 landing,37 markupOf,38 now,39+ plainText,40+ project,41 suite,42 textOf,43 verdictOf,44 } from "./ask-fixtures.ts";53 unmodified lines98 ).toBeTruthy();99 });100 101 it("shows held-back checks only as an area's counts and its suite root", () => {87- expect(textOf(page)).toContain(`export 6/7 @ ${suite}`);102+ const bits =103+ /<ul aria-label="Held-back checks by area"[^>]*>(?<inner>.*?)<\/ul>/su.exec(104+ markupOf(page)105+ )?.groups?.inner;106+107+ expect(plainText(bits ?? "").trim()).toBe(`export 6/7 @ ${suite}`);108 });109 110 it("shows the refusals' explain lines in order, as git printed them", () => {111 expect(68 unmodified lines180 `export 6/7 @ ${suite} parse 3/3 @ ${suite}`181 );182 });183 });184+185+/** What the stub platform was asked: verdicts and landings. */186+interface Asked {187+ readonly landings: number;188+ readonly verdicts: number;189+}190+191+/**192+ * A platform whose datekit ask's latest answer ended in `outcome`, as the193+ * answer page's loader calls it; `landingKnown` says whether it still finds194+ * the landing a landed verdict names.195+ */196+const platformAt = (197+ asked: Ref.Ref<Asked>,198+ outcome: Outcome,199+ landingKnown = true200+) =>201+ Layer.effect(Client, RpcTest.makeClient(Contracts)).pipe(202+ Layer.provide([203+ Layer.mergeAll(204+ unanswered,205+ Contracts.toLayerHandler("verdict", (payload) =>206+ Effect.gen(function* () {207+ yield* Ref.update(asked, (seen) => ({208+ ...seen,209+ verdicts: seen.verdicts + 1,210+ }));211+212+ if (payload.ask !== askId) {213+ return yield* new UnknownAsk({ ask: payload.ask });214+ }215+216+ return { verdict: verdictOf(outcome) };217+ })218+ ),219+ Contracts.toLayerHandler("landing", (payload) =>220+ Effect.gen(function* () {221+ yield* Ref.update(asked, (seen) => ({222+ ...seen,223+ landings: seen.landings + 1,224+ }));225+226+ if (!landingKnown || payload.sha !== landedSha) {227+ return yield* new UnknownCommit({ sha: payload.sha });228+ }229+230+ return { landing };231+ })232+ )233+ ),234+ asTester,235+ ])236+ );237+238+const nothingAsked: Asked = { landings: 0, verdicts: 0 };239+240+describe(readAnswer, () => {241+ it.effect("reads a landed answer's landing with its verdict", () =>242+ Effect.gen(function* () {243+ const asked = yield* Ref.make(nothingAsked);244+ const landed = Outcome.cases.Landed.make({ sha: landedSha });245+246+ const read = yield* readAnswer({ ask: askId, project }).pipe(247+ Effect.provide(platformAt(asked, landed))248+ );249+250+ expect(read.verdict?.outcome._tag).toBe("Landed");251+ expect(read.landing?.sha).toBe(landedSha);252+ expect(yield* Ref.get(asked)).toStrictEqual({ landings: 1, verdicts: 1 });253+ })254+ );255+256+ it.effect("asks for no landing when the answer did not land", () =>257+ Effect.gen(function* () {258+ const asked = yield* Ref.make(nothingAsked);259+260+ const read = yield* readAnswer({ ask: askId, project }).pipe(261+ Effect.provide(platformAt(asked, refused.outcome))262+ );263+264+ expect(read.verdict?.outcome._tag).toBe("Refused");265+ expect(read.landing).toBeUndefined();266+ expect(yield* Ref.get(asked)).toStrictEqual({ landings: 0, verdicts: 1 });267+ })268+ );269+270+ it.effect(271+ "shows the verdict alone when the platform no longer finds its landing",272+ () =>273+ Effect.gen(function* () {274+ const asked = yield* Ref.make(nothingAsked);275+ const landed = Outcome.cases.Landed.make({ sha: landedSha });276+277+ const read = yield* readAnswer({ ask: askId, project }).pipe(278+ Effect.provide(platformAt(asked, landed, false))279+ );280+281+ expect(read.verdict?.outcome._tag).toBe("Landed");282+ expect(read.landing).toBeUndefined();283+ })284+ );285+286+ it.effect(287+ "is a not-found carrying the UnknownAsk refusal for an ask the project lacks",288+ () =>289+ Effect.gen(function* () {290+ const asked = yield* Ref.make(nothingAsked);291+ const missing = AskId.make("no-such-ask");292+293+ const failed = yield* Effect.flip(294+ readAnswer({ ask: missing, project }).pipe(295+ Effect.provide(296+ platformAt(297+ asked,298+ Outcome.cases.Checking.make({ stage: "checks" })299+ )300+ )301+ )302+ );303+304+ expect(isNotFound(failed)).toBeTruthy();305+306+ const carried = yield* Schema.decodeUnknownEffect(Refusals)(307+ isNotFound(failed) ? failed.data : undefined308+ );309+310+ expect(explain(carried)).toStrictEqual(311+ explain([new UnknownAsk({ ask: missing })])312+ );313+ })314+ );315+316+ it.effect(317+ "is a not-found with no refusal, and asks nothing, when ?head= is not a whole commit id",318+ () =>319+ Effect.gen(function* () {320+ const asked = yield* Ref.make(nothingAsked);321+322+ const failed = yield* Effect.flip(323+ readAnswer({ ask: askId, head: "9b1c3e5", project }).pipe(324+ Effect.provide(platformAt(asked, refused.outcome))325+ )326+ );327+328+ expect(isNotFound(failed)).toBeTruthy();329+ expect(330+ isNotFound(failed) ? failed.data : "not a not-found"331+ ).toBeUndefined();332+ expect(yield* Ref.get(asked)).toStrictEqual(nothingAsked);333+ })334+ );335+});modified:apps/web/test/ask-fixtures.ts+6 added-3 removed
143 unmodified lines144 145 export const markupOf = (element: ReactElement) =>146 renderToStaticMarkup(element);147 148-/** What a reader sees: the markup without its tags, entities decoded. */149-export const textOf = (element: ReactElement) =>150- markupOf(element)148+/** What a reader sees of `markup`: the text without its tags, entities decoded. */149+export const plainText = (markup: string) =>150+ markup151 .replaceAll(/<[^>]+>/gu, " ")152 .replaceAll(153 /&(?:#x27|amp|gt|lt|quot);/gu,154 (entity) => ENTITIES.get(entity) ?? entity155 )156 .replaceAll(/\s+/gu, " ");157 158+/** What a reader sees of `element`, rendered. */159+export const textOf = (element: ReactElement) => plainText(markupOf(element));160+161 /** Whether each of `parts` appears in `text`, each after the one before. */162 export const inOrder = (text: string, parts: readonly string[]) => {163 let from = 0;164 12 unmodified linesmodified:apps/web/test/ask-markdown.test.ts+26 added-1 removed
10 unmodified lines11 import { AskId, ProjectName } from "@repo/protocol/ids";12 import { UnknownAsk, UnknownProject } from "@repo/protocol/refusal";13 import { explain } from "@repo/protocol/render";14 import { asTester, unanswered } from "@repo/protocol/testing";15-import { Effect, Layer, Ref } from "effect";15+import { Effect, Exit, Layer, Ref } from "effect";16 import { RpcTest } from "effect/rpc";17 18 import {19+ askMarkdownResponse,20 refusalsMarkdown,21 wantsMarkdown,22 } from "../src/features/ask/markdown.ts";23 import {248 unmodified lines272 link: `</datekit/asks/${askId}.md>; rel="alternate"; type="text/markdown"`,273 vary: "Accept",274 });275 });276+277+ it("names no alternate for a path that can name no ask, so no raw path text reaches a header", () => {278+ expect(279+ askPageHeaders({ params: params('x>; rel="next"\nset-cookie: a=b') })280+ ).toStrictEqual({ vary: "Accept" });281+ });282 });283 284+describe(askMarkdownResponse, () => {285+ it.effect(286+ "never lets a cache keep the answer of a contract only maintainers may see",287+ () =>288+ Effect.gen(function* () {289+ const seen = yield* read(290+ askMarkdownResponse(Exit.succeed({ brief }), "maintainers")291+ );292+293+ expect([seen.status, seen.cacheControl, seen.body]).toStrictEqual([294+ 200,295+ "private, no-store",296+ brief,297+ ]);298+ })299+ );300+});301+302 describe(refusalsMarkdown, () => {303 it("sets every refusal's explain lines in one text block, then each distinct next command once", () => {304 const refusals = [305 new UnknownProject({ project: ProjectName.make("nowhere") }),44 unmodified linesmodified:apps/web/test/ask.test.tsx+106 added-20 removed
4 unmodified lines5 * check it. Rendered to HTML with `react-dom/server`.6 */7 import { describe, expect, it } from "@effect/vitest";8 import { Brand } from "@repo/brand";9+import { Client, Contracts } from "@repo/protocol/contracts";10 import { AskId, Handle } from "@repo/protocol/ids";11 import { UnknownAsk } from "@repo/protocol/refusal";12 import { explain } from "@repo/protocol/render";12-import { Schema } from "effect";13+import { asTester, unanswered } from "@repo/protocol/testing";14+import { isNotFound } from "@tanstack/react-router";15+import { Effect, Layer, Ref, Schema } from "effect";16+import { RpcTest } from "effect/rpc";17 18 import { AskView } from "../src/features/ask/ask-page.tsx";15-import { NotFoundView, Refusals } from "../src/features/ask/refused.tsx";19+import { NoSuchAsk, Refusals } from "../src/features/ask/refused.tsx";20+import { readAsk } from "../src/routes/$project/asks/$ask.tsx";21 import {22 ask,23 askId,24 brief,25 inOrder,26 markupOf,27 now,28+ project,29 textOf,30 } from "./ask-fixtures.ts";31 32 const platformUrl = "https://platform-test.example.workers.dev";33 34+/** The markup inside the first `<pre>`. */35+const inPre = (markup: string) =>36+ /<pre\b[^>]*>(?<inner>.*?)<\/pre>/su.exec(markup)?.groups?.inner;37+38 const page = (shown = ask) => (39 <AskView ask={shown} brief={brief} now={now} platformUrl={platformUrl} />40 );41 125 unmodified lines167 expect(markup).toContain(`href="/datekit/answers/${askId}"`);168 });169 170 it("shows the brief exactly as an agent reads it", () => {161- expect(textOf(page())).toContain(162- textOf(<pre>{brief}</pre>)163- .trim()164- .slice(0, 60)165- );171+ expect(inPre(markupOf(page()))).toBe(inPre(markupOf(<pre>{brief}</pre>)));172 });173 });174 169-describe(NotFoundView, () => {170- it("shows the refusal a not-found carried from the server, as git printed it", () => {175+describe(NoSuchAsk, () => {176+ it("shows the refusal a loader's not-found carried from the server, as git printed it", () => {177 const refusal = new UnknownAsk({ ask: AskId.make("no-such-ask") });178 173- // The refusal crosses from the server encoded, as a loader's not-found carries it.174- const carried = Schema.decodeUnknownSync(Refusals)(175- structuredClone(Schema.encodeSync(Refusals)([refusal]))176- );179+ // The not-found's data, as it crosses from the server: encoded, then cloned.180+ const data = structuredClone(Schema.encodeSync(Refusals)([refusal]));181 178- const text = textOf(179- <NotFoundView refusals={carried} title="No such ask" />180- );181-182 expect(183- inOrder(text, [183+ inOrder(textOf(<NoSuchAsk data={data} />), [184 "No such ask",185 ...explain([refusal]).map((line) => line.trim()),186 `${Brand.cli} asks`,187 ])188 ).toBeTruthy();189 });190 191 it("says nothing is at an address that names no ask at all", () => {192+ expect(textOf(<NoSuchAsk />)).toContain("Nothing is at this address");193+ });194+195+ it("says what its route gives it when a not-found carries no refusal", () => {196 expect(193- textOf(<NotFoundView refusals={undefined} title="No such ask" />)194- ).toContain("Nothing is at this address");197+ textOf(<NoSuchAsk nothing="No answer is at this head." />)198+ ).toContain("No answer is at this head.");199 });200 });201+202+/** A platform that knows datekit's one ask, counting `showAsk` calls. */203+const platformOf = (calls: Ref.Ref<number>) =>204+ Layer.effect(Client, RpcTest.makeClient(Contracts)).pipe(205+ Layer.provide([206+ Layer.mergeAll(207+ unanswered,208+ Contracts.toLayerHandler("showAsk", (payload) =>209+ Effect.gen(function* () {210+ yield* Ref.update(calls, (count) => count + 1);211+212+ if (payload.ask !== askId) {213+ return yield* new UnknownAsk({ ask: payload.ask });214+ }215+216+ return { ask, brief };217+ })218+ )219+ ),220+ asTester,221+ ])222+ );223+224+describe(readAsk, () => {225+ it.effect("reads the ask and its brief for the page", () =>226+ Effect.gen(function* () {227+ const calls = yield* Ref.make(0);228+229+ const read = yield* readAsk({ ask: askId, project }).pipe(230+ Effect.provide(platformOf(calls))231+ );232+233+ expect([read.ask.id, read.brief]).toStrictEqual([askId, brief]);234+ expect(yield* Ref.get(calls)).toBe(1);235+ })236+ );237+238+ it.effect(239+ "is a not-found carrying the UnknownAsk refusal for an ask the project lacks",240+ () =>241+ Effect.gen(function* () {242+ const calls = yield* Ref.make(0);243+ const missing = AskId.make("no-such-ask");244+245+ const failed = yield* Effect.flip(246+ readAsk({ ask: missing, project }).pipe(247+ Effect.provide(platformOf(calls))248+ )249+ );250+251+ expect(isNotFound(failed)).toBeTruthy();252+253+ const carried = yield* Schema.decodeUnknownEffect(Refusals)(254+ isNotFound(failed) ? failed.data : undefined255+ );256+257+ expect(explain(carried)).toStrictEqual(258+ explain([new UnknownAsk({ ask: missing })])259+ );260+ })261+ );262+263+ it.effect(264+ "is a not-found with no refusal, and asks nothing, for a name no ask can have",265+ () =>266+ Effect.gen(function* () {267+ const calls = yield* Ref.make(0);268+269+ const failed = yield* Effect.flip(270+ readAsk({ ask: "Not_An-Ask", project }).pipe(271+ Effect.provide(platformOf(calls))272+ )273+ );274+275+ expect(isNotFound(failed)).toBeTruthy();276+ expect(277+ isNotFound(failed) ? failed.data : "not a not-found"278+ ).toBeUndefined();279+ expect(yield* Ref.get(calls)).toBe(0);280+ })281+ );282+});