Merge build/1004
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parents e8561dc, 30e38d8 · Browse files · 6 files·+577 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
6 files+577 added−29 removed
- tests:+322 added−14 removed
- other:+255 added−15 removed
Provenance
- Commit
46e88e0- Tree
e7dec1c- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent 1
e8561dc- Parent 2
30e38d8
6 files changed+577 added−29 removed
modified:apps/cli/src/render.ts+136 added
11 unmodified lines12 FrontPage,13 LedgerOf,14 ListAsks,15 ListProjects,16+ PolicyOf,17 ShowAsk,18 Status,19 SubmitAnswer,20 TodayOf,3 unmodified lines24 import { LandReceipt } from "@repo/protocol/domain/answer";25 import type { AnswerReceipt } from "@repo/protocol/domain/answer";26 import { DecisionSubject } from "@repo/protocol/domain/decision";27 import { Outcome } from "@repo/protocol/domain/outcome";28+import type { PolicyPending, PublicPolicy } from "@repo/protocol/domain/policy";29 import { LedgerEntry } from "@repo/protocol/domain/visibility";30 import type { Refusal } from "@repo/protocol/refusal";31 import { receiptLine } from "@repo/protocol/render";32 import { DateTime, Option, Result, Schema } from "effect";44 unmodified lines77 ].join("\n"),78 };79 };80 81+/** Labelled values, one a line: a Markdown list, and padded for a person. */82+const fields = (rows: readonly (readonly [string, string])[]): View => {83+ const width = Math.max(0, ...rows.map(([label]) => label.length));84+85+ return {86+ markdown: rows.map(([label, value]) => `- ${label}: ${value}`).join("\n"),87+ text: rows88+ .map(([label, value]) => `${label.padEnd(width)} ${value}`)89+ .join("\n"),90+ };91+};92+93 /** Views one after another, as sections. */94 const joined = (...parts: readonly View[]): View => ({95 markdown: parts.map(({ markdown }) => markdown).join("\n\n"),96 text: parts.map(({ markdown, text }) => text ?? markdown).join("\n\n"),207 unmodified lines304 ])305 )306 );307 308+const plural = (count: number, one: string, many: string) =>309+ `${count} ${count === 1 ? one : many}`;310+311+/** How many a vouch file names, as the people page says none: "nobody". */312+const countOf = (count: number) => (count === 0 ? "nobody" : `${count}`);313+314+const HOUR_MS = 3_600_000;315+316+/** A claim timing as the people page says it: whole hours up to two days, then days. */317+const spanOf = (ms: number) => {318+ if (ms % HOUR_MS !== 0) {319+ return plural(Math.round(ms / 60_000), "minute", "minutes");320+ }321+322+ const hours = ms / HOUR_MS;323+324+ return hours > 48 && hours % 24 === 0325+ ? plural(hours / 24, "day", "days")326+ : plural(hours, "hour", "hours");327+};328+329+/** The config folder's `project.ts`. */330+const PROJECT_FILE = `${Brand.configDir}/project.ts`;331+332+/** What a vouch gates, in the people page's words. */333+const vouchModes = {334+ all: "For everything: claiming an ask, offering a sealed answer and proposing an ask all need a vouch.",335+ bansOnly:336+ "Bans only: nobody needs a vouch, but a denounced person still may not claim, push or propose.",337+ forCode:338+ "For code: claiming an ask or offering a sealed answer needs a vouch; anyone not denounced may propose an ask.",339+} as const satisfies Record<PublicPolicy["vouch"]["mode"], string>;340+341+/** A policy at its landed commit, section by section, as the people page shows it. */342+const evaluated = (policy: PublicPolicy) => {343+ const { agents, budget, caps, claims, record, vouch, vouches } = policy;344+ const denounced = vouches.filter((line) => line.denounced).length;345+346+ return joined(347+ prose(348+ policy.source === "config"349+ ? `As of ${short(policy.at)}, the landed commit, from ${PROJECT_FILE}.`350+ : `As of ${short(policy.at)}, the landed commit. This project has no ${PROJECT_FILE}: the person who set it up decides everything, under the platform's defaults.`351+ ),352+ prose("Deciders by path:"),353+ table(354+ ["paths", "deciders"],355+ policy.deciders.map(({ handles, paths }) => [paths, handles.join(", ")]),356+ "Nobody decides."357+ ),358+ prose(359+ `Vouching: ${vouchModes[vouch.mode]} ${vouch.file} vouches for ${countOf(vouches.length - denounced)} and denounces ${countOf(denounced)}.`360+ ),361+ prose("Limits:"),362+ fields([363+ [364+ "Claims",365+ `${plural(caps.claimsPerPerson, "claim", "claims")} per person at once`,366+ ],367+ [368+ "Proposals",369+ caps.proposalsPerPerson === 0370+ ? "Proposals are off"371+ : `${plural(caps.proposalsPerPerson, "proposal", "proposals")} per person at once`,372+ ],373+ [374+ "Budget",375+ `${plural(budget.decisionsPerDay, "decision", "decisions")} a day per decider; an undecided one takes its default after ${plural(budget.expireDays, "day", "days")}`,376+ ],377+ [378+ "Claim timing",379+ `warned after ${spanOf(claims.warnAfterMs)} without a push; lapses after ${spanOf(claims.lapseAfterMs)}`,380+ ],381+ [382+ "Record",383+ `a landing counts ${384+ record.countsAfterDays === 0385+ ? "from the day it lands"386+ : `once it has stood ${plural(record.countsAfterDays, "day", "days")}`387+ }, for ${plural(record.windowDays, "day", "days")}`,388+ ],389+ ]),390+ prose(391+ agents === "trailer"392+ ? "Agents: each landing names the agents its people worked through, in an Assisted-by: trailer."393+ : "Agents: landings carry no Assisted-by: trailer."394+ )395+ );396+};397+398+/** Why the config at the landed commit has not evaluated, and what makes it, in the people page's words. */399+const pendingText = ({ at, reason }: PolicyPending) => {400+ const notEvaluated = `The config at the landed commit ${short(at)} has not been evaluated`;401+402+ return reason === "noConfig"403+ ? [404+ `${notEvaluated}: the project has no ${Brand.configDir}/ folder, and the defaults need a test command that the platform could not find in its CI or package files.`,405+ `To make it evaluate, a decider lands a ${PROJECT_FILE} that names the test command (\`${Brand.cli} init --dry-run\` in a clone prints the one the CLI proposes); it is evaluated again at every landing.`,406+ ]407+ : [408+ `${notEvaluated}: ${Brand.configDir}/ at ${short(at)} did not evaluate.`,409+ `Fix it by landing a change to ${Brand.configDir}/; it is evaluated again at every landing.`,410+ ];411+};412+413+const policy = viewOf(PolicyOf.successSchema, (read) => {414+ if (read.policy !== undefined) {415+ return evaluated(read.policy);416+ }417+418+ if (read.unevaluated === undefined) {419+ return prose(420+ "Nothing has landed yet. The config is evaluated at every landing."421+ );422+ }423+424+ const lines = pendingText(read.unevaluated);425+426+ return { markdown: lines.join("\n\n"), text: lines.join("\n") };427+});428+429 const ledger = viewOf(LedgerOf.successSchema, (book) =>430 joined(431 prose(`${book.project}: ${book.postureLabel}.`),432 table(86 unmodified lines519 frontPage: front,520 ledger,521 listAsks: asks,522 listProjects: projects,523+ projectPolicy: policy,524 showAsk: ask,525 status,526 submitAnswer: submitted,527 today,9 unmodified linesadded:apps/cli/test/policy-view.test.ts+190 added
1+/**2+ * `policy` as a person reads it: datekit's evaluated config folder at the3+ * landed commit in the people page's words (deciders by path, the vouch4+ * rule and its counts, the caps, budget, claim timing and record window),5+ * or, with no policy there, why it has not evaluated and what makes it.6+ * The view is a pure function of `projectPolicy`'s decoded success; under7+ * `--json` the success prints as JSON whatever the view says.8+ */9+import { describe, expect, it } from "@effect/vitest";10+import { Brand } from "@repo/brand";11+import { Contracts, PolicyOf } from "@repo/protocol/contracts";12+import type { PublicPolicy } from "@repo/protocol/domain/policy";13+import { Envelope } from "@repo/protocol/envelope";14+import { unanswered } from "@repo/protocol/testing";15+import { Effect, Layer, Option, Schema } from "effect";16+17+import { views } from "../src/render.ts";18+import { runProgram } from "./remote-server.ts";19+20+const sha = "4c2e6a8b0d2f4a6c8e0b2d4f6a8c0e2b4d6f8a0c";21+22+const decodeSuccess = Schema.decodeSync(PolicyOf.successSchema);23+24+/** datekit's evaluated config folder at `sha`, encoded. */25+const datekitPolicy = {26+ agents: "trailer",27+ at: sha,28+ budget: { decisionsPerDay: 5, expireDays: 14 },29+ caps: { claimsPerPerson: 3, proposalsPerPerson: 2 },30+ claims: { lapseAfterMs: 86_400_000, warnAfterMs: 7_200_000 },31+ deciders: [32+ { handles: ["ines-v"], paths: "**" },33+ { handles: ["okonkwo", "bram"], paths: "src/tz.ts" },34+ ],35+ judge: { paths: [`${Brand.configDir}/**`], pointers: [] },36+ kinds: [],37+ modules: [],38+ ratchets: [],39+ record: { countsAfterDays: 30, windowDays: 365 },40+ run: { checks: { unit: "bun test" }, test: "bun test {path}" },41+ source: "config",42+ vouch: { file: `${Brand.configDir}/vouched.td`, mode: "forCode" },43+ vouches: [44+ { denounced: false, handle: "bram", note: "first answer landed" },45+ { denounced: false, handle: "ines-v" },46+ { denounced: true, handle: "spam-bot" },47+ ],48+ weakening: { markers: [] },49+} as const satisfies typeof PublicPolicy.Encoded;50+51+/** datekit's policy as `projectPolicy` returns it. */52+const datekit = decodeSuccess({ policy: datekitPolicy });53+54+const noConfig = decodeSuccess({55+ unevaluated: { at: sha, reason: "noConfig" },56+});57+58+const configFailed = decodeSuccess({59+ unevaluated: { at: sha, reason: "configFailed" },60+});61+62+/** What a person reads: the view's text, or its Markdown when it has none. */63+const textOf = (success: typeof PolicyOf.successSchema.Type) =>64+ Option.match(views.projectPolicy(success), {65+ onNone: () => "",66+ onSome: ({ markdown, text }) => text ?? markdown,67+ });68+69+/** Each non-empty line, its runs of spaces made one. */70+const linesOf = (text: string) =>71+ text72+ .split("\n")73+ .map((line) => line.replaceAll(/\s+/gu, " ").trim())74+ .filter((line) => line !== "");75+76+describe("policy's text view", () => {77+ it("lists each decider glob with its handles, in the policy's order", () => {78+ const lines = linesOf(textOf(datekit));79+80+ expect(lines).toContain("** ines-v");81+ expect(lines).toContain("src/tz.ts okonkwo, bram");82+ expect(lines.indexOf("** ines-v")).toBeLessThan(83+ lines.indexOf("src/tz.ts okonkwo, bram")84+ );85+ });86+87+ it("says which commit it is as of, and where it comes from", () => {88+ const text = textOf(datekit);89+90+ expect(text).toContain(`As of ${sha.slice(0, 7)}, the landed commit`);91+ expect(text).toContain(`${Brand.configDir}/project.ts`);92+ });93+94+ it("states the vouch rule in words, with how many are vouched for and denounced", () => {95+ const text = textOf(datekit);96+97+ expect(text).toContain(98+ "For code: claiming an ask or offering a sealed answer needs a vouch"99+ );100+ expect(text).toContain(101+ `${Brand.configDir}/vouched.td vouches for 2 and denounces 1`102+ );103+ });104+105+ it("says a vouch file that names nobody vouches for nobody and denounces nobody, as the people page does", () => {106+ const text = textOf(107+ decodeSuccess({ policy: { ...datekitPolicy, vouches: [] } })108+ );109+110+ expect(text).toContain(111+ `${Brand.configDir}/vouched.td vouches for nobody and denounces nobody`112+ );113+ });114+115+ it("shows the caps, the budget, the claim timing and the record window", () => {116+ const lines = linesOf(textOf(datekit));117+118+ for (const line of [119+ "Claims 3 claims per person at once",120+ "Proposals 2 proposals per person at once",121+ "Budget 5 decisions a day per decider; an undecided one takes its default after 14 days",122+ "Claim timing warned after 2 hours without a push; lapses after 24 hours",123+ "Record a landing counts once it has stood 30 days, for 365 days",124+ ]) {125+ expect(lines).toContain(line);126+ }127+ });128+129+ it("says a project with no config folder has not been evaluated, why, and what makes it evaluate", () => {130+ const lines = linesOf(textOf(noConfig));131+132+ expect(lines).toStrictEqual([133+ `The config at the landed commit ${sha.slice(0, 7)} has not been evaluated: the project has no ${Brand.configDir}/ folder, and the defaults need a test command that the platform could not find in its CI or package files.`,134+ `To make it evaluate, a decider lands a ${Brand.configDir}/project.ts that names the test command (\`${Brand.cli} init --dry-run\` in a clone prints the one the CLI proposes); it is evaluated again at every landing.`,135+ ]);136+ });137+138+ it("says a config folder that did not evaluate has not been evaluated, and to land a fix", () => {139+ expect(linesOf(textOf(configFailed))).toStrictEqual([140+ `The config at the landed commit ${sha.slice(0, 7)} has not been evaluated: ${Brand.configDir}/ at ${sha.slice(0, 7)} did not evaluate.`,141+ `Fix it by landing a change to ${Brand.configDir}/; it is evaluated again at every landing.`,142+ ]);143+ });144+145+ it("says nothing has landed yet when there is neither a policy nor a reason", () => {146+ expect(textOf(decodeSuccess({}))).toContain("Nothing has landed yet");147+ });148+});149+150+const decodeEnvelope = Schema.decodeEffect(151+ Schema.fromJsonString(Envelope(Schema.Unknown))152+);153+154+/** A platform whose `projectPolicy` answers `success`. */155+const answering = (success: typeof PolicyOf.successSchema.Type) =>156+ Layer.mergeAll(157+ unanswered,158+ Contracts.toLayerHandler("projectPolicy", () => Effect.succeed(success))159+ );160+161+describe("policy on the command line", () => {162+ it.effect("prints the text view for a person", () =>163+ Effect.gen(function* () {164+ const run = yield* runProgram(["policy", "--project", "datekit"], {165+ handlers: answering(noConfig),166+ });167+168+ expect(run.code).toBe(0);169+ expect(run.out.join("\n")).toContain("has not been evaluated");170+ })171+ );172+173+ it.effect("prints the success as JSON under --json", () =>174+ Effect.gen(function* () {175+ const run = yield* runProgram(176+ ["policy", "--project", "datekit", "--json"],177+ { handlers: answering(noConfig) }178+ );179+180+ expect(run.code).toBe(0);181+ expect(run.out).toHaveLength(1);182+ expect(yield* decodeEnvelope(run.out[0] ?? "")).toStrictEqual({183+ command: "policy",184+ data: { unevaluated: { at: sha, reason: "noConfig" } },185+ ok: true,186+ v: 1,187+ });188+ })189+ );190+});modified:apps/web/e2e/imports.e2e.ts+7 added-1 removed
15 unmodified lines16 * for a run while the imports go in one at a time. It only reads.17 */18 import { expect, test } from "@playwright/test";19 import type { Page } from "@playwright/test";20+import { Brand } from "@repo/brand";21 import { Config, Console, Effect, Option } from "effect";22 23 /** One imported project: where its pages look, and what they must show. */24 interface Imported {335 unmodified lines360 `/${project}/people`,361 "people",362 evaluated363 ? { selectors: ['tr[data-paths="**"]'] }363- : { texts: ["has not been evaluated"] }364+ : {365+ texts: [366+ "has not been evaluated",367+ `the project has no ${Brand.configDir}/ folder`,368+ ],369+ }370 )371 ));372 373 test(`${project}'s ${file} says why each line is there`, ({233 unmodified linesmodified:apps/web/src/features/project-people/people-view.tsx+99 added-3 removed
5 unmodified lines6 * budget and timings, and whether landings disclose agents. Each section7 * links the file it comes from at that commit.8 *9 * Props in, markup out: the route reads `projectPolicy` and `ledger`10- * (`src/client/{policy,ledger}.ts`) and hands them here. The page is10+ * (`src/client/{policy,ledger}.ts`) and hands them here. With no policy at11+ * the landed commit, the page says why (`unevaluated`: no config folder, or12+ * one that did not evaluate), names the commit and says what makes it13+ * evaluate; with no reason either, nothing has landed yet. The page is14 * read-only: the one way to change any of it is to land a change to the15 * config folder, and it says so with the commands.16 */17 import { Brand } from "@repo/brand";15-import type { PublicPolicy } from "@repo/protocol/domain/policy";18+import type { PolicyPending, PublicPolicy } from "@repo/protocol/domain/policy";19 import type { Layer, Ledger, Members } from "@repo/protocol/domain/visibility";20 import type { Handle, ProjectName } from "@repo/protocol/ids";21 import { Option } from "effect";22 import { Fragment } from "react";46 unmodified lines69 /** A file at a commit, on the code browser. */70 const blobPath = (project: ProjectName, at: string, path: string) =>71 `/${project}/blob/${at}/${path}`;72 73+/** A folder at a commit, on the code browser. */74+const treePath = (project: ProjectName, at: string, path: string) =>75+ `/${project}/tree/${at}/${path}`;76+77+/** The config folder as a reader writes it: `<configDir>/`. */78+const CONFIG_DIR = `${Brand.configDir}/`;79+80 /** What a vouch gates, in words. */81 const vouchModes = {82 all: "For everything: claiming an ask, offering a sealed answer and proposing an ask all need a vouch.",83 bansOnly:283 unmodified lines367 </>368 );369 };370 371+/** The landed commit, short and linked: "The config at the landed commit <sha> has not been evaluated". */372+const NotEvaluated = ({373+ at,374+ project,375+}: {376+ readonly at: string;377+ readonly project: ProjectName;378+}) => (379+ <>380+ {"The config at the landed commit "}381+ <a className={`${LINK} ${CODE}`} href={`/${project}/commit/${at}`}>382+ {short(at)}383+ </a>384+ {" has not been evaluated"}385+ </>386+);387+388+/**389+ * Why the config at the landed commit has not been evaluated, and what390+ * makes it evaluate: a `project.ts` naming the test command, or a fix to391+ * the folder that did not evaluate. Either way, it evaluates again at392+ * every landing.393+ */394+const Pending = ({395+ pending,396+ project,397+}: {398+ readonly pending: PolicyPending;399+ readonly project: ProjectName;400+}) => (401+ <div402+ className="border-rule flex flex-col gap-3 border border-dashed px-4 py-5"403+ data-unevaluated={pending.reason}404+ >405+ {pending.reason === "noConfig" ? (406+ <>407+ <p className="max-w-[70ch] text-sm font-medium">408+ <NotEvaluated at={pending.at} project={project} />409+ {": the project has no "}410+ <Code>{CONFIG_DIR}</Code>411+ {412+ " folder, and the defaults need a test command that the platform could not find in its CI or package files."413+ }414+ </p>415+ <p className="max-w-[70ch] text-sm">416+ {"To make it evaluate, a decider lands a "}417+ <Code>{PROJECT_FILE}</Code>418+ {419+ " that names the test command. In a clone, this prints the file the CLI proposes from the repo's own files; add the test command to it, commit it, and land it with the commands below."420+ }421+ </p>422+ <CommandLine423+ command={`${Brand.cli} init --project ${project} --dry-run`}424+ />425+ </>426+ ) : (427+ <>428+ <p className="max-w-[70ch] text-sm font-medium">429+ <NotEvaluated at={pending.at} project={project} />430+ {": "}431+ <a432+ className={`${LINK} ${CODE}`}433+ href={treePath(project, pending.at, Brand.configDir)}434+ >435+ {CONFIG_DIR}436+ </a>437+ {` at ${short(pending.at)} did not evaluate.`}438+ </p>439+ <p className="max-w-[70ch] text-sm">440+ {`Fix it by landing a change to ${CONFIG_DIR}.`}441+ </p>442+ </>443+ )}444+ <p className="text-muted-foreground text-sm">445+ It is evaluated again at every landing.446+ </p>447+ </div>448+);449+450 export const PeopleView = ({451 ledger,452 policy,453 project,454+ unevaluated,455 }: {456 readonly ledger: Ledger;457 readonly policy: Option.Option<PublicPolicy>;458 readonly project: ProjectName;459+ /** Why there is no policy at the landed commit; none before the first landing. */460+ readonly unevaluated: Option.Option<PolicyPending>;461 }): ReactNode => (462 <PageShell title={`${project}: people`}>463 <ProjectNav current="people" project={project} />464 {Option.isSome(policy) ? (465 <Evaluated ledger={ledger} policy={policy.value} project={project} />466 ) : (467 <>376- <EmptyState title="The config at the landed commit has not been evaluated yet. It is evaluated once per landing; this page shows it once that is done." />468+ {Option.isSome(unevaluated) ? (469+ <Pending pending={unevaluated.value} project={project} />470+ ) : (471+ <EmptyState title="Nothing has landed yet. The config is evaluated at every landing; this page shows it once the first one lands." />472+ )}473 <Layers ledger={ledger} project={project} />474 </>475 )}476 <Region id="editing" title="Changing these">12 unmodified linesmodified:apps/web/src/routes/$project/people.tsx+13 added-11 removed
2 unmodified lines345677891011121313141516178 unmodified lines2627282930303132333435363738394041425 unmodified lines48495051475253545556525354575859606111 unmodified lines737475767477787980816 unmodified lines8889909192939495965 unmodified lines10210310410510210310410610710810911023 unmodified lines2 unmodified lines useAtomMount, useAtomValue,} from "@effect/atom-react";import { Client } from "@repo/protocol/contracts";import { PublicPolicy } from "@repo/protocol/domain/policy";import { PolicyPending, PublicPolicy } from "@repo/protocol/domain/policy";import { Ledger } from "@repo/protocol/domain/visibility";import { ProjectName } from "@repo/protocol/ids";import { createFileRoute, notFound } from "@tanstack/react-router";import { createServerFn } from "@tanstack/react-start";import { env } from "cloudflare:workers";import { Effect, Option, Schema } from "effect";import { Effect, Option, Schema, Struct } from "effect";import { AsyncResult, Atom } from "effect/reactivity";
import { ledgerAtom } from "../../client/ledger.ts";import { policyAtom } from "../../client/policy.ts";8 unmodified lines// ledger. The loader reads both on the server, so the page arrives whole// and an address naming no project is a 404; in the browser each reads// again as the platform lands changes and appends entries.
/** What the page's loader carries from the server, encoded: the policy (absent until evaluated) and the ledger. *//** * What the page's loader carries from the server, encoded: the policy * (absent until evaluated), why it has not evaluated (absent before the * first landing and once it has), and the ledger. */const PeoplePageData = Schema.Struct({ ledger: Ledger, policy: Schema.optionalKey(PublicPolicy), unevaluated: Schema.optionalKey(PolicyPending),});
type PeoplePageData = typeof PeoplePageData.Type;
5 unmodified lines );
const client = yield* Client;
const [{ policy }, ledger] = yield* Effect.all( const [read, ledger] = yield* Effect.all( [client.projectPolicy({ project }), client.ledger({ project })], { concurrency: 2 } ).pipe(Effect.catchTag("UnknownProject", () => Effect.fail(notFound())));
return yield* Schema.encodeEffect(PeoplePageData)( policy === undefined ? { ledger } : { ledger, policy } ); return yield* Schema.encodeEffect(PeoplePageData)({ ...read, ledger }); });
const peoplePage = createServerFn({ method: "GET" }) .validator((name: string) => name)11 unmodified lines}) => { // Live: a landing re-reads the policy, a ledger entry the layers. useAtomMount(watchAtom(project));
const { policy } = Option.getOrElse( const { policy, unevaluated } = Option.getOrElse( AsyncResult.value(useAtomValue(policyAtom(project))), () => read );
6 unmodified lines <PeopleView ledger={ledger} policy={Option.fromUndefinedOr(policy)} project={project} unevaluated={Option.fromUndefinedOr(unevaluated)} /> );};
5 unmodified lines <RegistryProvider initialValues={[ Atom.initialValue( policyAtom(project), AsyncResult.success( read.policy === undefined ? {} : { policy: read.policy } ) AsyncResult.success(Struct.pick(read, ["policy", "unevaluated"])) ), Atom.initialValue( ledgerAtom(project), AsyncResult.success(read.ledger)23 unmodified linesmodified:apps/web/test/project-people.test.tsx+132 added-14 removed
8 unmodified lines9 import { describe, expect, it } from "@effect/vitest";10 import { commandDocs } from "@repo/agent-kit/command-doc";11 import { Brand } from "@repo/brand";12 import { Client, Contracts } from "@repo/protocol/contracts";13-import { PublicPolicy } from "@repo/protocol/domain/policy";13+import { PolicyPending, PublicPolicy } from "@repo/protocol/domain/policy";14 import { Ledger } from "@repo/protocol/domain/visibility";15 import { ProjectName } from "@repo/protocol/ids";16 import { UnknownProject } from "@repo/protocol/refusal";17 import { asTester, unanswered } from "@repo/protocol/testing";81 unmodified lines99 vouch: { file: `${Brand.configDir}/vouched.td`, mode: "forCode" },100 vouches: [],101 });102 103+/** Why an import with no config folder, whose defaults found no test command, has no policy at `sha`. */104+const noConfig = Schema.decodeSync(PolicyPending)({105+ at: sha,106+ reason: "noConfig",107+});108+109 const burrowLedger = decodeLedger({110 entries: [],111 layers: [],112 posture: "open",5 unmodified lines118 <PeopleView119 ledger={datekitLedger}120 policy={Option.some(datekitPolicy)}121 project={datekit}122+ unevaluated={Option.none()}123 />124 );125 126 /** The markup from `start` up to `end` (or to the end): one section of the page. */134 unmodified lines261 <PeopleView262 ledger={datekitLedger}263 policy={Option.some({ ...datekitPolicy, agents: "none" })}264 project={datekit}265+ unevaluated={Option.none()}266 />267 ),268 "agents"269 )16 unmodified lines286 ...datekitPolicy,287 vouch: { ...datekitPolicy.vouch, mode: "bansOnly" },288 })}289 project={datekit}290+ unevaluated={Option.none()}291 />292 ),293 "vouching"294 )92 unmodified lines387 <PeopleView388 ledger={burrowLedger}389 policy={Option.some(burrowPolicy)}390 project={ProjectName.make("burrow")}391+ unevaluated={Option.none()}392 />393 );394 395 const markup = markupOf(view);8 unmodified lines404 expect(markup).not.toContain(`/${Brand.configDir}/project.ts"`);405 expect(textOf(view)).toContain("vouches for nobody");406 });407 398- it("says the config has not been evaluated yet, and shows no tables, when there is no policy", () => {408+ it("says nothing has landed yet, and shows no tables, when there is no policy and no reason", () => {409 const view = (410 <PeopleView411 ledger={datekitLedger}412 policy={Option.none()}413 project={datekit}414+ unevaluated={Option.none()}415 />416 );417 418 const markup = markupOf(view);419 409- expect(textOf(view)).toContain("has not been evaluated yet");420+ expect(textOf(view)).toContain("Nothing has landed yet");421 expect(markup).not.toContain("<table");422 expect(markup).not.toContain('id="vouching"');423 });424 425+ it("says a config with no config folder has not been evaluated, at which commit, and why", () => {426+ const view = (427+ <PeopleView428+ ledger={burrowLedger}429+ policy={Option.none()}430+ project={ProjectName.make("burrow")}431+ unevaluated={Option.some(noConfig)}432+ />433+ );434+435+ const text = textOf(view);436+ const markup = markupOf(view);437+438+ expect(439+ inOrder(text, [440+ `The config at the landed commit ${sha.slice(0, 7)} has not been evaluated`,441+ `the project has no ${Brand.configDir}/ folder`,442+ "the defaults need a test command",443+ "could not find in its CI or package files",444+ ])445+ ).toBeTruthy();446+ expect(markup).toMatch(447+ new RegExp(448+ `<a\\b[^>]*href="/burrow/commit/${sha}"[^>]*>${sha.slice(0, 7)}</a>`,449+ "u"450+ )451+ );452+ expect(text).toContain(`${Brand.configDir}/project.ts`);453+ expect(text).toContain("It is evaluated again at every landing.");454+ expect(markup).not.toContain("<table");455+ });456+457+ it("offers the CLI lines that make a config with no config folder evaluate, each a real command", () => {458+ const lines = commandsOf(459+ markupOf(460+ <PeopleView461+ ledger={burrowLedger}462+ policy={Option.none()}463+ project={ProjectName.make("burrow")}464+ unevaluated={Option.some(noConfig)}465+ />466+ )467+ );468+469+ expect(lines.map((line) => commandOf(line)?.path.join(" "))).toStrictEqual([470+ "init",471+ "ask open",472+ "land",473+ ]);474+ expect(lines[0]).toContain("--dry-run");475+476+ for (const line of lines) {477+ const flags = commandOf(line)?.flags ?? [];478+479+ expect(480+ line481+ .split(" ")482+ .filter((word) => word.startsWith("--"))483+ .filter((flag) => !flags.includes(flag))484+ ).toStrictEqual([]);485+ }486+ });487+488+ it("says a config folder that did not evaluate has not been evaluated, linking the folder at that commit", () => {489+ const view = (490+ <PeopleView491+ ledger={burrowLedger}492+ policy={Option.none()}493+ project={ProjectName.make("burrow")}494+ unevaluated={Option.some({ ...noConfig, reason: "configFailed" })}495+ />496+ );497+498+ const text = textOf(view);499+500+ expect(text).toContain(501+ `The config at the landed commit ${sha.slice(0, 7)} has not been evaluated: ${Brand.configDir}/ at ${sha.slice(0, 7)} did not evaluate`502+ );503+ expect(text).toContain(504+ `Fix it by landing a change to ${Brand.configDir}/.`505+ );506+ expect(markupOf(view)).toMatch(507+ new RegExp(508+ `<a\\b[^>]*href="/burrow/tree/${sha}/${Brand.configDir}"[^>]*>${Brand.configDir}/</a>`,509+ "u"510+ )511+ );512+ expect(text).not.toContain("test command");513+ });514+515 it("shows a project without layers as open, with nothing held back", () => {516 const view = (517 <PeopleView518 ledger={burrowLedger}519 policy={Option.some(burrowPolicy)}520 project={ProjectName.make("burrow")}521+ unevaluated={Option.none()}522 />523 );524 525 expect(textOf(view)).toContain("Open: nothing is held back");2 unmodified lines528 529 /** A platform that knows only datekit, counting the reads it is asked for. */530 const platformOf = (531 asked: Ref.Ref<number>,430- policy: Option.Option<PublicPolicy>532+ read: {533+ readonly policy?: PublicPolicy;534+ readonly unevaluated?: PolicyPending;535+ }536 ) =>537 Layer.effect(Client, RpcTest.makeClient(Contracts)).pipe(538 Layer.provide(539 Layer.mergeAll(5 unmodified lines545 if (project !== datekit) {546 return yield* new UnknownProject({ project });547 }548 444- return Option.match(policy, {445- onNone: () => ({}),446- onSome: (evaluated) => ({ policy: evaluated }),447- });549+ return read;550 })551 ),552 Contracts.toLayerHandler("ledger", ({ project }) =>553 Effect.gen(function* () {16 unmodified lines570 Effect.gen(function* () {571 const asked = yield* Ref.make(0);572 573 const read = yield* readPeople("datekit").pipe(472- Effect.provide(platformOf(asked, Option.some(datekitPolicy)))574+ Effect.provide(platformOf(asked, { policy: datekitPolicy }))575 );576 577 expect(read.policy?.at).toBe(sha);578 expect(read.ledger.layers.map(({ name }) => name)).toStrictEqual([2 unmodified lines581 expect(yield* Ref.get(asked)).toBe(2);582 })583 );584 483- it.effect("carries no policy while the config has not evaluated", () =>585+ it.effect(586+ "carries no policy, and why, while the config has not evaluated",587+ () =>588+ Effect.gen(function* () {589+ const asked = yield* Ref.make(0);590+591+ const read = yield* readPeople("datekit").pipe(592+ Effect.provide(platformOf(asked, { unevaluated: noConfig }))593+ );594+595+ expect(read.policy).toBeUndefined();596+ expect(read.unevaluated).toStrictEqual({ at: sha, reason: "noConfig" });597+ })598+ );599+600+ it.effect("carries neither before the first landing", () =>601 Effect.gen(function* () {602 const asked = yield* Ref.make(0);603 604 const read = yield* readPeople("datekit").pipe(488- Effect.provide(platformOf(asked, Option.none()))605+ Effect.provide(platformOf(asked, {}))606 );607 491- expect(read.policy).toBeUndefined();608+ expect(read).not.toHaveProperty("policy");609+ expect(read).not.toHaveProperty("unevaluated");610 })611 );612 613 it.effect("is a not-found for a project the platform does not know", () =>1 unmodified line615 const asked = yield* Ref.make(0);616 617 const failed = yield* Effect.flip(618 readPeople("no-such-project").pipe(501- Effect.provide(platformOf(asked, Option.some(datekitPolicy)))619+ Effect.provide(platformOf(asked, { policy: datekitPolicy }))620 )621 );622 623 expect(isNotFound(failed)).toBeTruthy();7 unmodified lines631 const asked = yield* Ref.make(0);632 633 const failed = yield* Effect.flip(634 readPeople("Not_A-Project").pipe(517- Effect.provide(platformOf(asked, Option.some(datekitPolicy)))635+ Effect.provide(platformOf(asked, { policy: datekitPolicy }))636 )637 );638 639 expect(isNotFound(failed)).toBeTruthy();25 unmodified lines