Skip to content
Myr

Make the live CLI find its claim and its projects: check diffs from the claim's base, and the D1 front page lists every project it has heard from

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

Found in 499's live run on dev-oscabriel, each fixed test-first: - `<cli> check` defaulted `--base` to `main`, so in a clone whose main holds the answer (how a contributor, and the zero-install flow, works) `main...HEAD` was empty: check said ok while the push was refused OutOfScope (405 #8). Online, with a live claim, the default is now the claim's base, which is exactly what the gateway diffs a claim fork's push from (`recordPush`'s `claim.base`); a claim made at a commit this repo lacks says so on stderr and falls back to main; offline it stays main; `--base` still wins. check.test.ts: "diffs from the claim's base, as the gateway does, even when the answer is committed on main" (red by assertion: it exited 0). - `FrontPageD1.projects()` read nothing until W5 514's tables, so live `projects` listed nothing and `status`/`today` without `--project` fanned out over no project and showed no claims (404 #10). Until 514 replaces it, it lists every project the projection has applied events of (its `cursor` rows), with its open asks, posture `open` and no landing time; credits still read nothing. projection-d1.test.ts's "reads no projects" case became "lists every project it has heard from, with its open asks" (red by assertion: []). - ASSUMPTION: a project shows up once its first projected event (an ask opened) reached D1; a project with no ask yet is not listed, which changes nothing a call without a project could reach.

authored by oscabriel · committed by oscabriel · parent 4ca0d3a · Browse files · 4 files+171 added−17 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+171 added−17 removed

  • tests:+94 added−7 removed
  • other:+77 added−10 removed

4 files+171 added−17 removed

modified:apps/cli/src/local/check.ts+45 added-6 removed
46 unmodified lines
47 Context,48 DateTime,49 Duration,50 Effect,51 Exit,52 FileSystem,53 Option,54 Path,55 Record,
6 unmodified lines
62import { Credentials } from "../credentials.ts";63import { Output, Reported } from "../output.ts";64import { repoContext } from "../repo-context.ts";65import type { RepoContext } from "../repo-context.ts";65import { localFacts, outsideAnyHook, runGit } from "./facts.ts";66import { commitOf, localFacts, outsideAnyHook, runGit } from "./facts.ts";67import {68 ConfigBundler,69 ConfigBundlerBun,70 localPolicy,
160 unmodified lines
231 );232 });233234/**235 * Where the diff starts: `--base` when given; else the live claim's base,236 * which is what the gateway diffs a push to the claim's fork from (so an237 * answer committed on the clone's own main is still seen), when this repo238 * holds that commit; else `main`.239 */240const baseOf = (241 root: string,242 given: Option.Option<string>,243 claim: Option.Option<ClaimView>244) =>245 Effect.gen(function* () {246 if (Option.isSome(given)) {247 return given.value;248 }249250 if (Option.isNone(claim)) {251 return "main";252 }253254 const { base } = claim.value;255 const held = yield* Effect.exit(commitOf(root, base));256257 if (Exit.isSuccess(held)) {258 return base;259 }260261 yield* Output.use((output) =>262 output.note(263 `Your claim was made at ${base}, which this repo doesn't have, so the diff starts at main; fetch the project's main, or pass --base.`264 )265 );266267 return "main";268 });269270/**271 * A live claim on `ask` by `claimant`, as the platform would hold one just272 * made: the parse stage's stand-in when the check runs offline.273 */274const syntheticClaim = (input: {
177 unmodified lines
452 "The ask to check against; the claim fork's remote names it when left out"453 )454 ),455 base: Flag.String("base").pipe(419 Flag.withDefault("main"),456 Flag.optional,457 Flag.withDescription(421 "Main as you have it: the policy is read here, and the diff starts at its merge base with HEAD"458 "Main as you have it: the policy is read here, and the diff starts at its merge base with HEAD. Defaults to your live claim's base, as the gateway diffs, else main"459 )460 ),461 dir: Flag.Directory("dir", { mustExist: true }).pipe(462 Flag.withAlias("C"),
61 unmodified lines
524 ]),525 () => SOMEONE526 );527528 const base = yield* baseOf(context.root, flags.base, claim);529530 const bundler = yield* Effect.serviceOption(ConfigBundler);531493 const policy = yield* localPolicy(context.root, flags.base, {532 const policy = yield* localPolicy(context.root, base, {533 initializer: handle,534 project,535 }).pipe(536 Option.match(bundler, {
1 unmodified line
538 onSome: (found) => Effect.provideService(ConfigBundler, found),539 }),540 Effect.catchTag("RulesFailed", (failure) =>541 stop(503 `The policy at ${flags.base} did not evaluate (${failure.reason}): ${failure.detail}`542 `The policy at ${base} did not evaluate (${failure.reason}): ${failure.detail}`543 )544 )545 );546
21 unmodified lines
568 );569570 const facts = yield* localFacts({571 ask,533 base: flags.base,572 base,573 claim: flags.offline574 ? Option.some(575 yield* syntheticClaim({576 ask: ask.value,
141 unmodified lines
modified:apps/cli/test/local/check.test.ts+72 added
7 unmodified lines
8import type { PushFacts } from "@repo/gate/facts";9import { pushStages, runGate } from "@repo/gate/gate";10import { addedLines, treeDiff } from "@repo/git/tree-diff";11import { Client, Contracts } from "@repo/protocol/contracts";12import { ClaimView } from "@repo/protocol/domain/claim";13import { RefNameText } from "@repo/protocol/domain/common";14import { Envelope } from "@repo/protocol/envelope";15import {16 AskId,
63 unmodified lines
80 asTester,81 ])82);8384const claimView = Schema.decodeUnknownSync(ClaimView);8586/**87 * A platform that says the caller holds a live claim on the ask, made when88 * main stood at `base`, and answers nothing else.89 */90const claimedAt = (base: string) =>91 Layer.effect(Client)(RpcTest.makeClient(Contracts)).pipe(92 Layer.provide([93 Layer.mergeAll(94 unanswered,95 Contracts.toLayerHandler("status", () =>96 Effect.succeed({97 answers: [],98 claims: [99 claimView({100 ask,101 base,102 checkCommand: `true ${checkFile}`,103 claimant: handle,104 fork: `${project}--${ask}--${handle}`,105 lapsesAt: "2099-01-02T00:00:00.000Z",106 openedAt: "2026-10-07T12:00:00.000Z",107 project,108 remote: `https://platform.example.dev/${project}--${ask}--${handle}.git`,109 state: "live",110 warnsAt: "2099-01-01T00:00:00.000Z",111 }),112 ],113 handle: Handle.make(handle),114 })115 )116 ),117 asTester,118 ])119 );120121/** A platform no offline run may call. */122const unreachable = Layer.mock(Client)({});123124/** What `check` runs with: a test console, plain output, real processes. */
361 unmodified lines
486 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))487 );488489 it.live(490 "diffs from the claim's base, as the gateway does, even when the answer is committed on main",491 () =>492 Effect.gen(function* () {493 const repo = yield* aCheckRepo;494495 // What the gateway says of the answer pushed onto the claim's base.496 const expected = yield* gateSays(repo, repo.straying);497498 // A contributor who clones the project and commits the answer on499 // its main, as the zero-install flow does: main...HEAD is empty.500 yield* gitOk(repo.root, "checkout", "--quiet", "main");501 yield* gitOk(repo.root, "reset", "--quiet", "--hard", repo.straying);502503 const printed = yield* run([504 "check",505 "--dir",506 repo.root,507 "--ask",508 ask,509 "--shape-only",510 "--json",511 ]).pipe(Effect.provide(services(claimedAt(repo.main))));512513 expect(Exit.isFailure(printed.exit)).toBeTruthy();514 expect(yield* envelopeOf(printed.out)).toStrictEqual({515 command: "check",516 ok: false,517 refusals: expected.encoded,518 v: 1,519 });520 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))521 );522523 it.live(524 "takes the ask from the claim fork's remote when none is named, and says so on stderr",525 () =>526 Effect.gen(function* () {527 const repo = yield* aCheckRepo;
29 unmodified lines
modified:packages/project/src/projection-d1/front-page.ts+32 added-4 removed
modified:packages/project/test/projection-d1.test.ts+22 added-7 removed
406 unmodified lines
407 expect(yield* migration).toBe(FrontPageDdl);408 })409 );410411 it.effect("reads no projects and no credits until their tables exist", () =>412 Effect.gen(function* () {413 yield* apply(rows(datekit, 1, [opened(parseIsoAsk, 1)]));411 // Until W5 514's projects table, the projects are those the projection412 // has applied events of, so a call without a project (`status`, `today`)413 // reaches each of them.414 it.effect(415 "lists every project it has heard from, with its open asks, and reads no credits",416 () =>417 Effect.gen(function* () {418 yield* apply(419 rows(datekit, 1, [420 opened(parseIsoAsk, 1),421 opened(weekStartAsk, 2),422 closedBy(weekStart),423 ])424 );425 yield* apply(rows(burrow, 1, [opened(noAnyAsk, 3), closedBy(noAny)]));426415 const front = yield* FrontPage;427 const front = yield* FrontPage;428417 expect(yield* front.projects()).toStrictEqual([]);418 expect(yield* front.credits(Handle.make("bram"))).toStrictEqual([]);419 }).pipe(Effect.provide(world))429 expect(yield* front.projects()).toStrictEqual([430 { openAsks: 0, posture: "open", project: burrow },431 { openAsks: 1, posture: "open", project: datekit },432 ]);433 expect(yield* front.credits(Handle.make("bram"))).toStrictEqual([]);434 }).pipe(Effect.provide(world))435 );436});