Skip to content
Myr

Merge perf/header-refs into main

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

authored by oscabriel · committed by oscabriel · parents 5e2dcf6, 481725e · Browse files · 4 files+97 added−28 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+97 added−28 removed

  • tests:+45 added−3 removed
  • other:+52 added−25 removed

4 files+97 added−28 removed

modified:apps/web/src/features/project/project-header.tsx+23 added
2 unmodified lines
3 * and three actions, then its nine tabs. Every page of the project draws it4 * the same; only the current tab moves.5 */6import { Brand } from "@repo/brand";7import type { RefsView, TagName } from "@repo/protocol/domain/code";8import type { Handle, ProjectName } from "@repo/protocol/ids";9import type { Posture } from "@repo/protocol/posture";10import { Option } from "effect";11import type { DateTime } from "effect";12import { ChevronDown, Tag } from "lucide-react";13import type { ReactNode } from "react";14
29 unmodified lines
44 | { readonly label: string; readonly posture: Posture }45 | undefined;46}4748/**49 * Newest by name, not by date: a tag carries only its name and commit. Its50 * numbers sort as numbers (`v0.10.0` is newer than `v0.9.0`), but a51 * pre-release such as `v2.0.0-beta` reads as newer than `v2.0.0`, and a tag52 * of no version shape wins or loses by its letters. Once a tag is read with53 * its time, the header can say the newest in time.54 */55const byNewest = (a: TagName, b: TagName) =>56 b.localeCompare(a, "en", { numeric: true });5758/** The header's newest tag once the refs are read; none while they are not, or when there is none. */59export const newestTag = (refs: Option.Option<RefsView>) =>60 Option.match(refs, {61 onNone: () => ({}),62 onSome: ({ tags }) => {63 const [latestTag] = tags.map((tag) => tag.name).toSorted(byNewest);6465 return latestTag === undefined ? {} : { latestTag };66 },67 });6869/** A source path's owner is everything before its last slash (`github.com/pallets`). */70const ownerAndName = (project: ProjectName) => {71 const at = project.lastIndexOf("/");72
305 unmodified lines
modified:apps/web/src/routes/$owner/$project/route.tsx+24 added-2 removed
modified:apps/web/src/server/project-page.ts+5 added-23 removed
1import { Client, PolicyOf } from "@repo/protocol/contracts";2import { Ask, AskListing } from "@repo/protocol/domain/ask";3import { FileView, TagName, TreeListing } from "@repo/protocol/domain/code";3import { FileView, TreeListing } from "@repo/protocol/domain/code";4import { ProjectEvent } from "@repo/protocol/domain/event";5import { Ledger } from "@repo/protocol/domain/visibility";6import { Handle, ProjectName } from "@repo/protocol/ids";7import { Posture } from "@repo/protocol/posture";
21 unmodified lines
29export const decodeName = Schema.decodeUnknownOption(ProjectName);3031/**32 * What a project's header says on every one of its pages: only the facts it33 * shows, so the header's read stays small in each page's HTML.33 * shows, so the header's read stays small in each page's HTML. Its newest tag34 * is read in the browser: the refs are the slowest read a page would wait on.35 */36export const ProjectHeaderData = Schema.Struct({37 deciders: Schema.optionalKey(Schema.Array(Handle)),38 landedAt: Schema.optionalKey(Schema.DateTimeUtcFromString),38 latestTag: Schema.optionalKey(TagName),39 lede: Schema.optionalKey(Schema.String),40 now: Schema.DateTimeUtcFromString,41 open: Schema.optionalKey(42 Schema.Struct({ asks: Schema.Int, takeable: Schema.Int })
49 unmodified lines
92 ),93 ledger: optional(client.ledger({ project })),94 log: optional(client.log({ limit: 1, project })),95 policy: optional(client.projectPolicy({ project })),96 refs: optional(client.listRefs({ project })),96});9798type HeaderReads = ReturnType<typeof headerReads>;99100type HeaderRead = {101 readonly [K in keyof HeaderReads]: Effect.Success<HeaderReads[K]>;102};103105/**106 * Newest by name, not by date: a tag carries only its name and commit. Its107 * numbers sort as numbers (`v0.10.0` is newer than `v0.9.0`), but a108 * pre-release such as `v2.0.0-beta` reads as newer than `v2.0.0`, and a tag109 * of no version shape wins or loses by its letters. Once a tag is read with110 * its time, the header can say the newest in time.111 */112const byNewest = (a: TagName, b: TagName) =>113 b.localeCompare(a, "en", { numeric: true });114104/** A field only when its read gave it; the header never says what it was not told. */105const onlySome = <A, B extends object>(106 read: Option.Option<A>,107 field: (value: A) => B108) => Option.match(read, { onNone: () => ({}), onSome: field });109110/**122 * The asks it counts, the ledger's posture, who decides, the newest tag,123 * main's last landing and the README's first sentence.111 * The asks it counts, the ledger's posture, who decides, main's last landing112 * and the README's first sentence.113 */114const headerOf = (115 project: ProjectName,116 now: DateTime.Utc,
29 unmodified lines
146 ({ commits }) => commits[0]?.landing?.landedAt147 ),148 (landedAt) => ({ landedAt })149 ),161 ...onlySome(162 Option.flatMapNullishOr(163 read.refs,164 ({ tags }) => tags.map((tag) => tag.name).toSorted(byNewest)[0]165 ),166 (latestTag) => ({ latestTag })167 ),150 ...onlySome(lede, (sentence) => ({ lede: sentence })),151 ...onlySome(read.ledger, ({ posture, postureLabel }) => ({152 posture: { label: postureLabel, posture },153 })),
95 unmodified lines
modified:apps/web/test/project.test.tsx+45 added-3 removed
12 unmodified lines
13import type { Ledger } from "@repo/protocol/domain/visibility";14import {15 AreaName,16 AskId,17 CommitSha,18 Handle,19 KindName,20 LayerName,21 ProjectName,
26 unmodified lines
48import { postureWord } from "../src/features/project/posture-label.ts";49import { ProjectFrame } from "../src/features/project/project-frame.tsx";50import {51 CloneSteps,52 newestTag,53 ProjectHeader,54 WatchSteps,55} from "../src/features/project/project-header.tsx";56import type { ProjectHeaderFacts } from "../src/features/project/project-header.tsx";57import {58 ProjectView,59 heldBackOf,60 homeListing,
673 unmodified lines
734 Effect.provide(world)735 );736737/** A project page as its route draws it: the project's frame, its header (its tab from the path alone), then the page. */735const framed = (url: string, header: ProjectHeaderData, body: ReactNode) =>738const framed = (url: string, header: ProjectHeaderFacts, body: ReactNode) =>739 renderAt(740 url,741 <ProjectFrame742 header={
118 unmodified lines
861 label: "Open with sealed evidence · sealed checks in export",862 posture: "openWithSealedEvidence",863 },864 project: ProjectName.make("oscabriel/datekit"),862} satisfies ProjectHeaderData;865} satisfies ProjectHeaderFacts;866867const headerOf = (markup: string) =>868 elementWith(markup, 'data-project-header=""');869
9 unmodified lines
879880const HEADER_READS = [881 "ledger",882 "listAsks",880 "listRefs",883 "log",884 "projectPolicy",885 "readFile",886 "readTree",
335 unmodified lines
1222 }),1223 seededWorld1224 );12251226 it.effect(1227 "never waits on the refs, on Overview or on any other page",1228 () =>1229 Effect.gen(function* () {1230 const seen = yield* Ref.make<readonly string[]>([]);12311232 yield* Effect.gen(function* () {1233 yield* readProjectPage("oscabriel/datekit");1234 yield* readProjectHeader("oscabriel/datekit");1235 }).pipe(Effect.provide(countingWorld(seen)));12361237 expect(yield* Ref.get(seen)).not.toContain("listRefs");1238 }),1239 seededWorld1240 );12411242 it.effect(1243 "says the newest tag by its numbers once the refs are read, and none before",1244 () =>1245 Effect.sync(() => {1246 const project = ProjectName.make("oscabriel/datekit");1247 const sha = CommitSha.make("a".repeat(40));12481249 const refs = {1250 forks: [],1251 project,1252 tags: ["v0.9.0", "v0.10.0", "v0.2.0"].map((name) => ({1253 name: TagName.make(name),1254 sha,1255 })),1256 };12571258 expect(newestTag(Option.some(refs))).toStrictEqual({1259 latestTag: "v0.10.0",1260 });1261 expect(newestTag(Option.some({ ...refs, tags: [] }))).toStrictEqual({});1262 expect(newestTag(Option.none())).toStrictEqual({});1263 })1264 );12651266 it.live("makes every read at once, none waiting on another", () =>1267 Effect.gen(function* () {1268 const header = yield* readProjectHeader("oscabriel/datekit").pipe(1269 Effect.flatMap(decodeHeader),
301 unmodified lines