Merge build/1103 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 084383d, 087ef48 · Browse files · 4 files·+268 added−21 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+268 added−21 removed
- tests:+223 added−0 removed
- other:+45 added−21 removed
Provenance
- Commit
9c64f9b- Tree
6c0a211- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent 1
084383d- Parent 2
087ef48
4 files changed+268 added−21 removed
modified:apps/platform/src/adapters/custody.ts+27 added-11 removed
5 unmodified lines6 * may move, from the project's own record through `ProjectApi`. A canonical7 * repo takes no push (`DirectPush`) but its initializer's first8 * (`firstPusher`); a claim's fork takes its claimant's pushes while the claim9 * is live, and a decider's commits on top when they finish its answer; a10- * working fork takes its owner's. `ProjectApi` has no read of the push facts the gate's parse11- * stage takes (the policy, the ask, the claim), so `admit` asks the12- * claimant's own `status` and leaves the full parse to `review`, where13- * `recordPush` runs it.10+ * working fork takes its owner's. A fork takes branches only: a push of its11+ * notes, a tag or the platform's own refs is `DirectPush`, whoever makes it,12+ * and refuses the whole push. The platform writes its notes and merge refs13+ * straight to the store (`RepoHost.push`, the Lander), never through the14+ * gateway; no one writes a fork's tags.15+ * `ProjectApi` has no read of the push facts the gate's parse stage takes16+ * (the policy, the ask, the claim), so `admit` asks the claimant's own17+ * `status` and leaves the full parse to `review`, where `recordPush` runs it.18 *19 * `custodyFor` reads what `admit` needs before the gateway starts, and20 * `admit` answers at once. The gateway makes the push's upstream body as21 * soon as it has read the command list, before it asks `admit`, and that55 unmodified lines77 /** Every ref in the push turned away: main moves only by a landing. */78 const directPushes = (commands: readonly Command[]) =>79 commands.map(({ ref }) => new DirectPush({ ref }));80 81+/** Where a person's work goes on a fork: its branches. */82+const branchPrefix = "refs/heads/";83+84+/**85+ * A fork takes branches only: every other ref, created, moved or deleted,86+ * is the platform's (its verdict notes, the Lander's merge refs) or no one's87+ * (a tag), so each is a direct push, whoever pushes it.88+ */89+const branchesOnly = (commands: readonly Command[]): readonly Refusal[] =>90+ commands.flatMap(({ ref }) =>91+ ref.startsWith(branchPrefix) ? [] : [new DirectPush({ ref })]92+ );93+94 /** Where a push moves `main`, if it moves it to a commit; a deletion moves it nowhere. */95 const mainTip = (commands: readonly Command[]) =>96 Option.flatMap(97 Array.findFirst(commands, ({ ref }) => ref === mainRef),173 unmodified lines271 )272 );273 274 return custodyOf(258- () => refused,275+ (commands) => [...branchesOnly(commands), ...refused],276 // A decider's commits are judged by `<cli> finish`, not by the push.277 (repo, commands) =>278 Option.match(279 Option.filter(mainTip(commands), () => isClaimant),50 unmodified lines330 Effect.withSpan("custody.review", { attributes: annotations })331 ),332 });333 317-/** Custody that takes every push as it comes: a person's own working fork. */318-const takeAll = custodyOf(319- () => [],320- () => Effect.succeed([])321-);334+/** Custody of a person's own working fork: every branch push as it comes. */335+const ownBranches = custodyOf(branchesOnly, () => Effect.succeed([]));336 337 /** Custody that takes no push at all: every ref is a direct push. */338 export const refuseAll = custodyOf(directPushes, (_repo, commands) =>339 Effect.succeed(directPushes(commands))31 unmodified lines371 // The platform makes no repo by any other name; nothing pushes there.372 Unknown: () => Effect.succeed(refuseAll),373 // A person's working fork: only its owner pushes; their `land` judges it.374 WorkingFork: ({ handle }) =>361- Effect.succeed(sameHandle(pusher.handle, handle) ? takeAll : refuseAll),375+ Effect.succeed(376+ sameHandle(pusher.handle, handle) ? ownBranches : refuseAll377+ ),378 });379 380 return annotated(custody, annotations);381 });51 unmodified linesmodified:apps/platform/test/gateway.test.ts+193 added
39 unmodified lines40 } from "./gateway.fixtures.ts";41 42 const datekit = ProjectName.make("datekit");43 44+/** The ref the platform keeps a fork's verdict notes under. */45+const notesRef = `refs/notes/${Brand.slug}`;46+47 const parseIso = AskId.make("parse-iso");48 49 /** A project made empty, awaiting its first push. */50 const fresh = ProjectName.make("fresh");54 unmodified lines105 .split("\n")106 .filter((line) => line.startsWith("remote: "))107 .map((line) => line.trimEnd());108 109+/** What git says of a push custody turned away as a direct push of `ref`. */110+const refusedAs = (ref: string) => ({111+ exitCode: 1,112+ remote: explain([new DirectPush({ ref })]).map((line) => `remote: ${line}`),113+});114+115 /**116 * A GET of `url`, with `authorization` if given, through the Worker's fetch:117 * its status, and whether it asks for Basic.118 */340 unmodified lines459 30_000460 );461 462 it.live(463+ "a claimant's push of the notes ref, a tag or the platform's merge ref to their claim fork is DirectPush, and the fork keeps only its branches",464+ () =>465+ Effect.gen(function* () {466+ const { api, repos, root, seen, urlOf } = yield* withDatekit;467+ const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);468+ const clone = `${root}/alices`;469+ const forkRepo = `${repos}/${claim.fork}.git`;470+471+ yield* gitOk(472+ root,473+ ...as(tokens.alice),474+ "clone",475+ "--quiet",476+ urlOf(claim.fork),477+ clone478+ );479+ yield* gitOk(clone, "notes", `--ref=${Brand.slug}`, "add", "-m", "{}");480+ yield* gitOk(clone, "tag", "v1");481+482+ const refsBefore = yield* gitOk(forkRepo, "for-each-ref");483+484+ const pushOf = (refspec: string) =>485+ Effect.map(486+ git(clone, ...as(tokens.alice), "push", "origin", refspec),487+ ({ exitCode, stderr }) => ({488+ exitCode,489+ remote: remoteLines(stderr),490+ })491+ );492+493+ const merge = `${Brand.refsPrefix}merge/${"a".repeat(40)}`;494+495+ expect({496+ merge: yield* pushOf(`HEAD:${merge}`),497+ notes: yield* pushOf(notesRef),498+ tag: yield* pushOf("refs/tags/v1"),499+ }).toStrictEqual({500+ merge: refusedAs(merge),501+ notes: refusedAs(notesRef),502+ tag: refusedAs("refs/tags/v1"),503+ });504+ expect(yield* gitOk(forkRepo, "for-each-ref")).toBe(refsBefore);505+ expect(506+ (yield* Ref.get(seen.upstream)).filter(507+ ({ method, path }) =>508+ method === "POST" && path.endsWith("/git-receive-pack")509+ )510+ ).toStrictEqual([]);511+ }).pipe(Effect.provide(NodeServices.layer)),512+ 30_000513+ );514+515+ it.live(516+ "a claimant's deletion of their claim fork's notes ref is DirectPush, and the verdict notes stay",517+ () =>518+ Effect.gen(function* () {519+ const { api, repos, root, urlOf } = yield* withDatekit;520+ const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);521+ const clone = `${root}/alices`;522+ const forkRepo = `${repos}/${claim.fork}.git`;523+524+ yield* gitOk(525+ root,526+ ...as(tokens.alice),527+ "clone",528+ "--quiet",529+ urlOf(claim.fork),530+ clone531+ );532+533+ // The platform's own verdict note, written straight to the fork as534+ // `RepoHost.push` writes it, never through the gateway.535+ yield* gitOk(clone, "notes", `--ref=${Brand.slug}`, "add", "-m", "{}");536+ yield* gitOk(clone, "push", "--quiet", forkRepo, notesRef);537+538+ const noted = yield* gitOk(forkRepo, "rev-parse", notesRef);539+540+ const pushed = yield* git(541+ clone,542+ ...as(tokens.alice),543+ "push",544+ "origin",545+ `:${notesRef}`546+ );547+548+ expect({549+ exitCode: pushed.exitCode,550+ remote: remoteLines(pushed.stderr),551+ }).toStrictEqual(refusedAs(notesRef));552+ expect(yield* gitOk(forkRepo, "rev-parse", notesRef)).toBe(noted);553+ }).pipe(Effect.provide(NodeServices.layer)),554+ 30_000555+ );556+557+ it.live(558+ "a claimant's push of main beside a tag is refused whole: main stays and nothing is offered",559+ () =>560+ Effect.gen(function* () {561+ const { api, repos, root, seen, urlOf } = yield* withDatekit;562+ const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);563+ const clone = `${root}/alices`;564+ const forkRepo = `${repos}/${claim.fork}.git`;565+566+ yield* gitOk(567+ root,568+ ...as(tokens.alice),569+ "clone",570+ "--quiet",571+ urlOf(claim.fork),572+ clone573+ );574+ yield* commit(clone, "parse the year", {575+ "packages/parser/src/parse.ts":576+ "export const parse = (s) => ({ year: 2026 });\n",577+ });578+ yield* gitOk(clone, "tag", "v1");579+580+ const before = yield* gitOk(forkRepo, "rev-parse", "main");581+582+ const pushed = yield* git(583+ clone,584+ ...as(tokens.alice),585+ "push",586+ "origin",587+ "HEAD:main",588+ "refs/tags/v1"589+ );590+591+ expect({592+ exitCode: pushed.exitCode,593+ remote: remoteLines(pushed.stderr),594+ }).toStrictEqual(refusedAs("refs/tags/v1"));595+ expect(596+ [" HEAD -> main (DirectPush)", " v1 -> v1 (DirectPush)"].map(597+ (rejected) =>598+ pushed.stderr.includes(` ! [remote rejected]${rejected}`)599+ )600+ ).toStrictEqual([true, true]);601+ expect(yield* gitOk(forkRepo, "rev-parse", "main")).toBe(before);602+ expect(yield* Ref.get(seen.started)).toStrictEqual([]);603+ }).pipe(Effect.provide(NodeServices.layer)),604+ 30_000605+ );606+607+ it.live(608 "a fork is read by signed-in people, and a name the platform never makes is a 404",609 () =>610 Effect.gen(function* () {611 const { api, origin } = yield* withDatekit;145 unmodified lines757 30_000758 );759 760 it.live(761+ "a fork takes branches only, whoever pushes: a working fork's owner and a finishing decider hear DirectPush for a tag",762+ () =>763+ Effect.gen(function* () {764+ const { api, landed, projects } = yield* withDatekit;765+ const { claim } = yield* api.claim(bob, parseIso).pipe(Effect.orDie);766+ const working = `${datekit}--me--alice`;767+ const tag = RefName.make("refs/tags/v1");768+ const side = RefName.make("refs/heads/side");769+ const tagged = Array.of(moving(tag, Option.none()));770+771+ const deletion = Array.of<Command>({772+ from: Option.some(CommitSha.make(landed)),773+ ref: RefName.make(notesRef),774+ to: Option.none(),775+ });776+777+ expect({778+ decider: (yield* judged(projects, alice, claim.fork, tagged))779+ .admitted,780+ deletion: (yield* judged(projects, bob, claim.fork, deletion))781+ .admitted,782+ owner: (yield* judged(projects, alice, working, tagged)).admitted,783+ ownerBranch: (yield* judged(784+ projects,785+ alice,786+ working,787+ Array.of(moving(side, Option.none()))788+ )).admitted,789+ }).toStrictEqual({790+ decider: [new DirectPush({ ref: tag })],791+ deletion: [new DirectPush({ ref: notesRef })],792+ owner: [new DirectPush({ ref: tag })],793+ ownerBranch: [],794+ });795+ }).pipe(Effect.provide(NodeServices.layer)),796+ 30_000797+ );798+799+ it.live(800 "a canonical repo takes no ref but main, and its first push only from its initializer, as the project says",801 () =>802 Effect.gen(function* () {803 const { projects } = yield* gatewayWorld([scenario]);51 unmodified linesmodified:packages/gate/src/stages/parse.ts+18 added-10 removed
56 unmodified lines575859606162636465636466676869707166676869707273747576777879807273748182838485868779 unmodified lines56 unmodified lines
return decides ? "vouched" : "unknown";};
/** Where a person's work goes on a fork: its branches, never another ref. */const branchPrefix = "refs/heads/";
/** * Main moves only by a landing: no push reaches a canonical ref. * A working fork takes pushes from its owner only, and a layer's repo takes * none here: its writers arrive with the visibility cartridge. * A fork takes branches only: its notes and merge refs are the platform's * to write and a tag is no one's, so a push of any ref outside `refs/heads/` * is a direct push, whoever makes it. A working fork takes pushes from its * owner only, and a layer's repo takes none here: its writers arrive with * the visibility cartridge. */const directPush: Rule = (facts) => PushTarget.$match(facts.target, { Canonical: () => Option.some(new DirectPush({ ref: facts.ref })), ClaimFork: () => Option.none(), Layer: () => Option.some(new DirectPush({ ref: facts.ref })),const directPush: Rule = (facts) => { const refused = Option.some(new DirectPush({ ref: facts.ref })); const onBranch = facts.ref.startsWith(branchPrefix);
return PushTarget.$match(facts.target, { Canonical: () => refused, ClaimFork: () => (onBranch ? Option.none() : refused), Layer: () => refused, WorkingFork: ({ owner }) => isPusher(facts, owner) ? Option.none() : Option.some(new DirectPush({ ref: facts.ref })), onBranch && isPusher(facts, owner) ? Option.none() : refused, });};
/** * A denounced person pushes nothing. An unvouched one pushes to a working * fork (a sealed answer, a decider's own change) only when the mode says so.79 unmodified linesmodified:packages/gate/test/parse.test.ts+30 added
53 unmodified lines54 });55 56 const main = RefNameText.make("refs/heads/main");57 58+const tag = RefNameText.make("refs/tags/v1");59+60 // Each row is one push; parse answers with at most one refusal, the first61 // rule the push breaks.62 const rows: readonly {63 readonly name: string;160 unmodified lines224 }),225 name: "a push to a layer's repo, which W6 opens to its writers",226 refusals: [new DirectPush({ ref: main })],227 },228+ // A fork takes branches only: every other ref is the platform's or no one's.229+ {230+ facts: testFacts({ ref: tag }),231+ name: "the claimant's push of a tag to their claim's fork",232+ refusals: [new DirectPush({ ref: tag })],233+ },234+ {235+ facts: testFacts({236+ ask: Option.none(),237+ claim: Option.none(),238+ pusher: Person.make({ handle: alice }),239+ ref: tag,240+ target: PushTarget.WorkingFork({ owner: alice, project: ask.project }),241+ }),242+ name: "an owner's push of a tag to their own working fork",243+ refusals: [new DirectPush({ ref: tag })],244+ },245+ {246+ facts: testFacts({247+ ask: Option.none(),248+ claim: Option.none(),249+ pusher: Person.make({ handle: alice }),250+ ref: RefNameText.make("refs/heads/wip"),251+ target: PushTarget.WorkingFork({ owner: alice, project: ask.project }),252+ }),253+ name: "an owner's push of another branch to their own working fork",254+ refusals: [],255+ },256 ];257 258 describe("parse: who may push what", () => {259 it.effect.each(rows)("$name", ({ facts, refusals }) =>7 unmodified lines