Skip to content
Myr

Read /asks's parents and replays at once, and a project's Markdown listing beside its asks

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The front page read each family's parent, then replayed each project, though both need only the entries; the project's llms.txt read the listing, then the asks, though the asks need only the name. Each pair now goes at once, and a test for each holds one read until the other has started, so reading them one after the other never ends.

authored by oscabriel · committed by oscabriel · parent 5e2dcf6 · Browse files · 4 files+138 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+138 added−29 removed

  • tests:+105 added−2 removed
  • other:+33 added−27 removed

4 files+138 added−29 removed

modified:apps/web/src/server/front-page.ts+21 added-16 removed
modified:apps/web/src/server/llms.ts+12 added-11 removed
59 unmodified lines
60 return missing();61 }6263 const client = yield* Client;64 const { projects } = yield* client.listProjects({});6465 const readAsks = client.listAsks({ project: project.value }).pipe(66 Effect.map((listed) => Option.some(listed.asks)),67 Effect.catchTag("UnknownProject", () => Effect.succeedNone)68 );6970 // The asks need only the name, so they are read beside the listing.71 const [{ projects }, asks] = yield* Effect.all(72 [client.listProjects({}), readAsks],73 { concurrency: 2 }74 );7576 const listing = Arr.findFirst(77 projects,78 (each) => each.project === project.value79 );8071 if (Option.isNone(listing)) {81 if (Option.isNone(listing) || Option.isNone(asks)) {82 return missing();83 }8475 const asks = yield* client.listAsks({ project: project.value }).pipe(76 Effect.map((listed) => Option.some(listed.asks)),77 Effect.catchTag("UnknownProject", () => Effect.succeedNone)78 );7980 if (Option.isNone(asks)) {81 return missing();82 }8385 return markdown(86 projectLlms({87 // An ask waits only on asks still open, and a family's finale88 // is folded into its family while it waits, so the count is the
13 unmodified lines
modified:apps/web/test/front.test.tsx+70 added-1 removed
9 unmodified lines
10 FrontPageEntry,11 ProjectListing,12} from "@repo/protocol/domain/front-page";13import { AskId, KindName, ProjectName } from "@repo/protocol/ids";14import { UnknownAsk } from "@repo/protocol/refusal";15import { asTester, unanswered } from "@repo/protocol/testing";15import { DateTime, Effect, Layer, Option, Schema } from "effect";16import {17 DateTime,18 Deferred,19 Effect,20 Layer,21 Option,22 Schema,23 Stream,24} from "effect";25import { FetchHttpClient } from "effect/http";26import { RpcClient, RpcSerialization, RpcTest } from "effect/rpc";2728import { devServer } from "../src/dev/server.ts";
659 unmodified lines
688 asTester,689 ])690);691692/** A family's parent and child, so the page reads the parent and replays its project. */693const familyEntries = Schema.decodeSync(Schema.Array(FrontPageEntry))(694 ["drop-fetch", "drop-fetch-auth"].map((ask) => ({695 ask: {696 ask,697 blockedBy: ask === "drop-fetch" ? ["drop-fetch-auth"] : [],698 claimed: false,699 kind: "migrate",700 territory: ".",701 want: `The want of ${ask}.`,702 },703 posture: "open",704 project: "burrow",705 takeable: true,706 }))707);708709/** The parent's read answers only once the replay has begun, so reading the two one after the other never ends. */710const parentWaitsOnReplay = Layer.unwrap(711 Effect.gen(function* () {712 const replayed = yield* Deferred.make<boolean>();713714 return Layer.effect(Client, RpcTest.makeClient(Contracts)).pipe(715 Layer.provide([716 Layer.mergeAll(717 unanswered,718 Contracts.toLayerHandler("frontPage", () =>719 Effect.succeed({ entries: familyEntries })720 ),721 Contracts.toLayerHandler("showAsk", (payload) =>722 Deferred.await(replayed).pipe(723 Effect.andThen(new UnknownAsk({ ask: payload.ask }))724 )725 ),726 Contracts.toLayerHandler("watch", () =>727 Stream.fromEffect(Deferred.succeed(replayed, true)).pipe(728 Stream.flatMap(() => Stream.empty)729 )730 )731 ),732 asTester,733 ])734 );735 })736);737738const decodeData = Schema.decodeEffect(FrontPageData);739740/** A fresh dev world seeds itself first, which a full test run can slow past 5 s. */741const seededWorld = { timeout: 30_000 };
67 unmodified lines
809810 expect(rowsIn(yield* sentFrom(data))).toHaveLength(3);811 })812 );813814 it.effect("reads the parents and replays the projects at once", () =>815 Effect.gen(function* () {816 const data = yield* readFrontPage.pipe(817 Effect.flatMap(decodeData),818 Effect.provide(parentWaitsOnReplay)819 );820821 expect({822 events: data.events.map(({ project }) => project),823 parents: data.parents,824 }).toStrictEqual({ events: ["oscabriel/burrow"], parents: [] });825 })826 );827});828829/** A browser's storage held in a map, so a test reads back what was kept. */830const memoryStorage = (): Storage => {
77 unmodified lines
modified:apps/web/test/llms.test.ts+35 added-1 removed
12 unmodified lines
13 KindName,14 ProjectName,15} from "@repo/protocol/ids";16import type { RepoName } from "@repo/protocol/ids";17import { Effect, Option } from "effect";17import { Deferred, Effect, Layer, Option } from "effect";1819import { commands as catalog } from "../src/features/agents/catalog.ts";20import {21 frontLlms,
425 unmodified lines
447 Effect.succeed({ asks: listedAsks })448 )449 );450451/** The listing answers only once the asks have been asked for, so reading the two one after the other never ends. */452const listingWaitsOnAsks =453 (listed: readonly ProjectListing[], listedAsks: readonly AskListing[]) =>454 () =>455 Layer.unwrap(456 Effect.map(Deferred.make<boolean>(), (asked) =>457 platformWith(458 Contracts.toLayerHandler("listProjects", () =>459 Effect.as(Deferred.await(asked), { projects: listed })460 ),461 Contracts.toLayerHandler("listAsks", () =>462 Effect.as(Deferred.succeed(asked, true), { asks: listedAsks })463 )464 )465 )466 );467468const getAt = (path: string, accept: string) =>469 new Request(`${webUrl}${path}`, { headers: { accept } });470471const BROWSER =
41 unmodified lines
513 });514 })515 );516517 it.effect("reads /oscabriel/datekit's listing and asks at once", () =>518 Effect.gen(function* () {519 const seen = yield* answered(520 projectPageHandler(521 listingWaitsOnAsks(projects, asks),522 platformUrl523 )({524 next: () => "the page" as const,525 params: { project: "datekit" },526 request: getAt("/oscabriel/datekit", "text/markdown"),527 })528 );529530 expect(seen).toMatchObject({ status: 200 });531 })532 );533534 it.effect(535 "answers /oscabriel/datekit with the project's llms.txt, varied by Accept",536 () =>537 Effect.gen(function* () {
129 unmodified lines