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
Provenance
- Commit
6534642- Tree
a961f37- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
5e2dcf6
4 files changed+138 added−29 removed
modified:apps/web/src/server/front-page.ts+21 added-16 removed
38 unmodified lines394041424344454647484344454647484950515253545051525354555657585556575859606162636460656667686949 unmodified lines38 unmodified lines const client = yield* Client; const { entries } = yield* client.frontPage({}); const families = familiesOf(entries);
const parents = yield* Effect.forEach( families, ([project, ask]) => client.showAsk({ ask, project }).pipe( Effect.map((read) => Option.some(read.ask)), Effect.orElseSucceed(() => Option.none<Ask>()) // The parents and the replays need only the entries, so the two waves go at once. const { events, parents } = yield* Effect.all( { events: Effect.forEach( Arr.dedupe(families.map(([project]) => project)), (project) => Stream.runCollect(client.watch({ project, since: 0 })).pipe( Effect.map((read) => Option.some({ events: read, project })), Effect.orElseSucceed(() => Option.none()) ), { concurrency: AT_ONCE } ), { concurrency: AT_ONCE } );
const events = yield* Effect.forEach( Arr.dedupe(families.map(([project]) => project)), (project) => Stream.runCollect(client.watch({ project, since: 0 })).pipe( Effect.map((read) => Option.some({ events: read, project })), Effect.orElseSucceed(() => Option.none()) parents: Effect.forEach( families, ([project, ask]) => client.showAsk({ ask, project }).pipe( Effect.map((read) => Option.some(read.ask)), Effect.orElseSucceed(() => Option.none<Ask>()) ), { concurrency: AT_ONCE } ), }, { concurrency: AT_ONCE } { concurrency: "unbounded" } );
return yield* Schema.encodeEffect(FrontPageData)({ entries,49 unmodified linesmodified:apps/web/src/server/llms.ts+12 added-11 removed
59 unmodified lines60 return missing();61 }62 63 const client = yield* Client;64- const { projects } = yield* client.listProjects({});64 65+ const readAsks = client.listAsks({ project: project.value }).pipe(66+ Effect.map((listed) => Option.some(listed.asks)),67+ Effect.catchTag("UnknownProject", () => Effect.succeedNone)68+ );69+70+ // 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+ );75+76 const listing = Arr.findFirst(77 projects,78 (each) => each.project === project.value79 );80 71- if (Option.isNone(listing)) {81+ if (Option.isNone(listing) || Option.isNone(asks)) {82 return missing();83 }84 75- const asks = yield* client.listAsks({ project: project.value }).pipe(76- Effect.map((listed) => Option.some(listed.asks)),77- Effect.catchTag("UnknownProject", () => Effect.succeedNone)78- );79-80- if (Option.isNone(asks)) {81- return missing();82- }83-85 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 the13 unmodified linesmodified:apps/web/test/front.test.tsx+70 added-1 removed
9 unmodified lines10 FrontPageEntry,11 ProjectListing,12 } from "@repo/protocol/domain/front-page";13 import { AskId, KindName, ProjectName } from "@repo/protocol/ids";14+import { UnknownAsk } from "@repo/protocol/refusal";15 import { asTester, unanswered } from "@repo/protocol/testing";15-import { DateTime, Effect, Layer, Option, Schema } from "effect";16+import {17+ DateTime,18+ Deferred,19+ Effect,20+ Layer,21+ Option,22+ Schema,23+ Stream,24+} from "effect";25 import { FetchHttpClient } from "effect/http";26 import { RpcClient, RpcSerialization, RpcTest } from "effect/rpc";27 28 import { devServer } from "../src/dev/server.ts";659 unmodified lines688 asTester,689 ])690 );691 692+/** A family's parent and child, so the page reads the parent and replays its project. */693+const 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+);708+709+/** The parent's read answers only once the replay has begun, so reading the two one after the other never ends. */710+const parentWaitsOnReplay = Layer.unwrap(711+ Effect.gen(function* () {712+ const replayed = yield* Deferred.make<boolean>();713+714+ 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+);737+738 const decodeData = Schema.decodeEffect(FrontPageData);739 740 /** A fresh dev world seeds itself first, which a full test run can slow past 5 s. */741 const seededWorld = { timeout: 30_000 };67 unmodified lines809 810 expect(rowsIn(yield* sentFrom(data))).toHaveLength(3);811 })812 );813+814+ 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+ );820+821+ expect({822+ events: data.events.map(({ project }) => project),823+ parents: data.parents,824+ }).toStrictEqual({ events: ["oscabriel/burrow"], parents: [] });825+ })826+ );827 });828 829 /** A browser's storage held in a map, so a test reads back what was kept. */830 const memoryStorage = (): Storage => {77 unmodified linesmodified:apps/web/test/llms.test.ts+35 added-1 removed
12 unmodified lines13 KindName,14 ProjectName,15 } from "@repo/protocol/ids";16 import type { RepoName } from "@repo/protocol/ids";17-import { Effect, Option } from "effect";17+import { Deferred, Effect, Layer, Option } from "effect";18 19 import { commands as catalog } from "../src/features/agents/catalog.ts";20 import {21 frontLlms,425 unmodified lines447 Effect.succeed({ asks: listedAsks })448 )449 );450 451+/** The listing answers only once the asks have been asked for, so reading the two one after the other never ends. */452+const 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+ );467+468 const getAt = (path: string, accept: string) =>469 new Request(`${webUrl}${path}`, { headers: { accept } });470 471 const BROWSER =41 unmodified lines513 });514 })515 );516 517+ 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+ );529+530+ expect(seen).toMatchObject({ status: 200 });531+ })532+ );533+534 it.effect(535 "answers /oscabriel/datekit with the project's llms.txt, varied by Accept",536 () =>537 Effect.gen(function* () {129 unmodified lines