gateway.test.ts
This file
Path
apps/platform/test/gateway.test.ts
837 lines · 25.7 KiB · TypeScript
Last changed by
Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
History of this fileTake it
1import { NodeServices } from "@effect/platform-node";2import { describe, expect, it } from "@effect/vitest";3import { Fetch } from "@repo/artifacts/fetch";4import { RefName, RepoName } from "@repo/artifacts/repo-host";5import { Brand } from "@repo/brand";6import type { Command } from "@repo/git/custody";7import { Projects } from "@repo/project/projects";8import {9 AskId,10 CommitSha,11 Handle,12 LandedSha,13 ProjectName,14 keyOf,15 addressOfRepo,16 repoNameOfAddress,17 RepoPath,18} from "@repo/protocol/ids";19import { Person } from "@repo/protocol/principal";20import {21 ClaimLapsed,22 DirectPush,23 NotClaimed,24 OutOfScope,25 UnknownProject,26} from "@repo/protocol/refusal";27import { explain } from "@repo/protocol/render";28import { git, gitOk } from "@repo/testkit/git";29import { aProject, withAsk, withVouches } from "@repo/testkit/scenarios";30import { Array, DateTime, Effect, Option, Ref } from "effect";31import { TestClock } from "effect/testing";3233import { custodyFor, pushRequestId } from "../src/adapters/custody.ts";34import { WorkerFetch } from "../src/adapters/fetch.ts";35import { repoKind } from "../src/repo-names.ts";36import {37 alice,38 as,39 bob,40 commit,41 gatewayWorld,42 tokens,43} from "./gateway.fixtures.ts";4445const datekit = ProjectName.make("alice/datekit");4647const notesRef = `refs/notes/${Brand.slug}`;4849const parseIso = AskId.make("parse-iso");5051const fresh = ProjectName.make("alice/fresh");5253const scenario = aProject({ name: datekit, people: ["bob"] }).pipe(54 withAsk({ id: parseIso, territory: "packages/parser" }),55 withVouches(["bob"])56);5758const askOf = (id: AskId) =>59 Option.getOrThrow(60 Array.findFirst(scenario.policy.asks, (ask) => ask.id === id)61 );6263const withDatekit = Effect.gen(function* () {64 const world = yield* gatewayWorld([scenario]);65 const seed = `${world.root}/seed`;66 const api = yield* world.projects.create(datekit).pipe(Effect.orDie);6768 yield* api.initProject(alice, {}).pipe(Effect.orDie);69 yield* gitOk(world.root, "init", "--quiet", "--initial-branch=main", seed);7071 const first = yield* commit(seed, "first", {72 "README.md": "datekit\n",73 "packages/parser/src/parse.ts": "export const parse = (s) => s;\n",74 });7576 yield* gitOk(77 seed,78 "push",79 "--quiet",80 `${world.repos}/${keyOf(datekit)}.git`,81 "HEAD:refs/heads/main"82 );83 yield* api.recordFirstPush(alice, first).pipe(Effect.orDie);8485 const { landed } = yield* world.openAsk(86 api,87 LandedSha.make(first),88 askOf(parseIso)89 );9091 return { ...world, api, first, landed, seed };92});9394const remoteLines = (stderr: string) =>95 stderr96 .split("\n")97 .filter((line) => line.startsWith("remote: "))98 .map((line) => line.trimEnd());99100const refusedAs = (ref: string) => ({101 exitCode: 1,102 remote: explain([new DirectPush({ ref })]).map((line) => `remote: ${line}`),103});104105const request = (url: string, authorization?: string) =>106 Fetch.use(({ fetch }) =>107 fetch(108 new Request(url, {109 headers: authorization === undefined ? {} : { authorization },110 })111 )112 ).pipe(113 Effect.map((response) => ({114 basic:115 response.headers.get("www-authenticate")?.startsWith("Basic ") ?? false,116 status: response.status,117 })),118 Effect.orDie,119 Effect.provide(WorkerFetch)120 );121122describe("git through the platform", () => {123 it.live(124 "1. anyone clones a project's canonical repo, with no credential",125 () =>126 Effect.gen(function* () {127 const { landed, root, urlOf } = yield* withDatekit;128 const clone = `${root}/clone`;129 const cloned = yield* git(root, "clone", urlOf(datekit), clone);130131 expect(cloned.exitCode).toBe(0);132 expect(yield* gitOk(clone, "rev-parse", "HEAD")).toBe(landed);133 }).pipe(Effect.provide(NodeServices.layer)),134 30_000135 );136137 it.live(138 "2. a maintainer's push to canonical main is DirectPush, and main stays where it was",139 () =>140 Effect.gen(function* () {141 const { landed, repos, root, urlOf } = yield* withDatekit;142 const clone = `${root}/clone`;143144 yield* gitOk(root, "clone", "--quiet", urlOf(datekit), clone);145 yield* commit(clone, "straight to main", { "README.md": "mine\n" });146147 const pushed = yield* git(148 clone,149 ...as(tokens.alice),150 "push",151 "origin",152 "HEAD:main"153 );154155 expect(pushed.exitCode).toBe(1);156 expect(remoteLines(pushed.stderr)).toStrictEqual(157 explain([new DirectPush({ ref: "refs/heads/main" })]).map(158 (line) => `remote: ${line}`159 )160 );161 expect(pushed.stderr).toContain(162 " ! [remote rejected] HEAD -> main (DirectPush)"163 );164 expect(165 yield* gitOk(`${repos}/${keyOf(datekit)}.git`, "rev-parse", "main")166 ).toBe(landed);167 }).pipe(Effect.provide(NodeServices.layer)),168 30_000169 );170171 it.live(172 "3. an empty project takes its initializer's first push once; the next is DirectPush",173 () =>174 Effect.gen(function* () {175 const { projects, repos, root, urlOf } = yield* gatewayWorld([176 scenario,177 ]);178179 const api = yield* projects.create(fresh).pipe(Effect.orDie);180181 yield* api.initProject(alice, {}).pipe(Effect.orDie);182183 const work = `${root}/work`;184185 yield* gitOk(root, "init", "--quiet", "--initial-branch=main", work);186187 const first = yield* commit(work, "first", { "README.md": "fresh\n" });188189 const byBob = yield* git(190 work,191 ...as(tokens.bob),192 "push",193 urlOf(fresh),194 "HEAD:main"195 );196197 const byAlice = yield* git(198 work,199 ...as(tokens.alice),200 "push",201 urlOf(fresh),202 "HEAD:main"203 );204205 const mainAfterFirst = yield* gitOk(206 `${repos}/${keyOf(fresh)}.git`,207 "rev-parse",208 "main"209 );210211 const second = yield* commit(work, "second", { "README.md": "two\n" });212213 const again = yield* git(214 work,215 ...as(tokens.alice),216 "push",217 urlOf(fresh),218 "HEAD:main"219 );220221 const refused = " ! [remote rejected] HEAD -> main (DirectPush)";222223 expect({224 again: again.stderr.includes(refused),225 bob: byBob.stderr.includes(refused),226 first: byAlice.exitCode,227 main: mainAfterFirst,228 }).toStrictEqual({ again: true, bob: true, first: 0, main: first });229 expect(230 yield* gitOk(`${repos}/${keyOf(fresh)}.git`, "rev-parse", "main")231 ).toBe(first);232 expect(233 yield* Effect.flip(api.recordFirstPush(alice, second))234 ).toStrictEqual(new DirectPush({ ref: "refs/heads/main" }));235 }).pipe(Effect.provide(NodeServices.layer)),236 30_000237 );238239 it.live(240 "4. a push to someone else's claim fork is NotClaimed, before the upstream hears of it",241 () =>242 Effect.gen(function* () {243 const { api, repos, root, seen, urlOf } = yield* withDatekit;244 const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);245 const clone = `${root}/bobs`;246247 yield* gitOk(248 root,249 ...as(tokens.bob),250 "clone",251 "--quiet",252 urlOf(claim.fork),253 clone254 );255 yield* commit(clone, "bob's", {256 "packages/parser/src/parse.ts":257 "export const parse = (s) => s.trim();\n",258 });259260 const before = yield* gitOk(261 `${repos}/${claim.fork}.git`,262 "rev-parse",263 "main"264 );265266 const pushed = yield* git(267 clone,268 ...as(tokens.bob),269 "push",270 "origin",271 "HEAD:main"272 );273274 expect(pushed.exitCode).toBe(1);275 expect(remoteLines(pushed.stderr)).toStrictEqual(276 explain([NotClaimed.of(parseIso)]).map((line) => `remote: ${line}`)277 );278 expect(pushed.stderr).toContain(279 " ! [remote rejected] HEAD -> main (NotClaimed)"280 );281 expect(282 yield* gitOk(`${repos}/${claim.fork}.git`, "rev-parse", "main")283 ).toBe(before);284 expect(285 (yield* Ref.get(seen.upstream)).filter(286 ({ method, path }) =>287 method === "POST" && path.endsWith("/git-receive-pack")288 )289 ).toStrictEqual([]);290 }).pipe(Effect.provide(NodeServices.layer)),291 30_000292 );293294 it.live(295 "5. an out-of-territory push to your own claim fork is OutOfScope, and the fork keeps it",296 () =>297 Effect.gen(function* () {298 const { api, root, urlOf } = yield* withDatekit;299 const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);300 const clone = `${root}/alices`;301302 yield* gitOk(303 root,304 ...as(tokens.alice),305 "clone",306 "--quiet",307 urlOf(claim.fork),308 clone309 );310311 const wide = yield* commit(clone, "too wide", {312 "README.md": "a different readme\n",313 "packages/parser/src/parse.ts":314 "export const parse = (s) => s.trim();\n",315 });316317 const pushed = yield* git(318 clone,319 ...as(tokens.alice),320 "push",321 "origin",322 "HEAD:main"323 );324325 const listed = yield* gitOk(326 root,327 ...as(tokens.alice),328 "ls-remote",329 urlOf(claim.fork),330 "refs/heads/main"331 );332333 expect(pushed.exitCode).toBe(1);334 expect(remoteLines(pushed.stderr)).toStrictEqual(335 explain([336 new OutOfScope({ paths: [RepoPath.make("README.md")] }),337 ]).map((line) => `remote: ${line}`)338 );339 expect(pushed.stderr).toContain(340 " ! [remote rejected] HEAD -> main (OutOfScope)"341 );342 expect(listed).toBe(`${wide}\trefs/heads/main`);343 }).pipe(Effect.provide(NodeServices.layer)),344 30_000345 );346347 it.live(348 "6. an unknown token is a 401 asking for Basic, and so is a push with no credential",349 () =>350 Effect.gen(function* () {351 const { origin, root, urlOf } = yield* withDatekit;352353 const unknown = yield* request(354 `${origin}/${datekit}.git/info/refs?service=git-upload-pack`,355 `Basic ${btoa("x:a-token-nobody-was-given-0123456789")}`356 );357358 const anonymousPush = yield* request(359 `${origin}/${datekit}.git/info/refs?service=git-receive-pack`360 );361362 const clone = `${root}/clone`;363364 yield* gitOk(root, "clone", "--quiet", urlOf(datekit), clone);365 yield* commit(clone, "anonymous", { "README.md": "who\n" });366367 const pushed = yield* git(clone, "push", "origin", "HEAD:main");368369 expect(unknown).toStrictEqual({ basic: true, status: 401 });370 expect(anonymousPush).toStrictEqual({ basic: true, status: 401 });371 expect(pushed.exitCode).toBe(128);372 expect(pushed.stderr).toContain("could not read Username");373 }).pipe(Effect.provide(NodeServices.layer)),374 30_000375 );376377 it.live(378 "a clean push to your own claim fork is offered as the answer, and says it is being checked",379 () =>380 Effect.gen(function* () {381 const { api, root, seen, urlOf } = yield* withDatekit;382 const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);383 const clone = `${root}/alices`;384385 const cloned = yield* git(386 root,387 ...as(tokens.alice),388 "clone",389 urlOf(claim.fork),390 clone391 );392393 const fix = yield* commit(clone, "parse the year", {394 "packages/parser/src/parse.ts":395 "export const parse = (s) => ({ year: 2026 });\n",396 });397398 const pushed = yield* git(399 clone,400 ...as(tokens.alice),401 "push",402 "origin",403 "HEAD:main"404 );405406 const requestId = pushRequestId(alice.handle, fix);407 const { answers } = yield* api.status(alice);408409 expect(pushed.exitCode).toBe(0);410 expect(remoteLines(pushed.stderr)).toStrictEqual([411 `remote: checking ${parseIso} at ${fix.slice(0, 7)}; follow with ${Brand.cli} status`,412 ]);413 expect(414 answers.map((answer) => [answer.requestId, answer.head])415 ).toStrictEqual([[requestId, fix]]);416 expect(yield* Ref.get(seen.started)).toStrictEqual([requestId]);417418 const minted = yield* Ref.get(seen.minted);419420 const credentials = new Set(421 minted.map((secret) => `Basic ${btoa(`x:${secret}`)}`)422 );423424 const output = [425 cloned.stdout,426 cloned.stderr,427 pushed.stdout,428 pushed.stderr,429 ].join("\n");430431 expect({432 leaked: [...minted, tokens.alice].filter((secret) =>433 output.includes(secret)434 ),435 minted: minted.length > 0,436 sent: (yield* Ref.get(seen.upstream)).filter(437 ({ authorization }) =>438 !Option.exists(authorization, (header) => credentials.has(header))439 ),440 }).toStrictEqual({ leaked: [], minted: true, sent: [] });441 }).pipe(Effect.provide(NodeServices.layer)),442 30_000443 );444445 it.live(446 "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",447 () =>448 Effect.gen(function* () {449 const { api, repos, root, seen, urlOf } = yield* withDatekit;450 const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);451 const clone = `${root}/alices`;452 const forkRepo = `${repos}/${claim.fork}.git`;453454 yield* gitOk(455 root,456 ...as(tokens.alice),457 "clone",458 "--quiet",459 urlOf(claim.fork),460 clone461 );462 yield* gitOk(clone, "notes", `--ref=${Brand.slug}`, "add", "-m", "{}");463 yield* gitOk(clone, "tag", "v1");464465 const refsBefore = yield* gitOk(forkRepo, "for-each-ref");466467 const pushOf = (refspec: string) =>468 Effect.map(469 git(clone, ...as(tokens.alice), "push", "origin", refspec),470 ({ exitCode, stderr }) => ({471 exitCode,472 remote: remoteLines(stderr),473 })474 );475476 const merge = `${Brand.refsPrefix}merge/${"a".repeat(40)}`;477478 expect({479 merge: yield* pushOf(`HEAD:${merge}`),480 notes: yield* pushOf(notesRef),481 tag: yield* pushOf("refs/tags/v1"),482 }).toStrictEqual({483 merge: refusedAs(merge),484 notes: refusedAs(notesRef),485 tag: refusedAs("refs/tags/v1"),486 });487 expect(yield* gitOk(forkRepo, "for-each-ref")).toBe(refsBefore);488 expect(489 (yield* Ref.get(seen.upstream)).filter(490 ({ method, path }) =>491 method === "POST" && path.endsWith("/git-receive-pack")492 )493 ).toStrictEqual([]);494 }).pipe(Effect.provide(NodeServices.layer)),495 30_000496 );497498 it.live(499 "a claimant's deletion of their claim fork's notes ref is DirectPush, and the verdict notes stay",500 () =>501 Effect.gen(function* () {502 const { api, repos, root, urlOf } = yield* withDatekit;503 const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);504 const clone = `${root}/alices`;505 const forkRepo = `${repos}/${claim.fork}.git`;506507 yield* gitOk(508 root,509 ...as(tokens.alice),510 "clone",511 "--quiet",512 urlOf(claim.fork),513 clone514 );515516 yield* gitOk(clone, "notes", `--ref=${Brand.slug}`, "add", "-m", "{}");517 yield* gitOk(clone, "push", "--quiet", forkRepo, notesRef);518519 const noted = yield* gitOk(forkRepo, "rev-parse", notesRef);520521 const pushed = yield* git(522 clone,523 ...as(tokens.alice),524 "push",525 "origin",526 `:${notesRef}`527 );528529 expect({530 exitCode: pushed.exitCode,531 remote: remoteLines(pushed.stderr),532 }).toStrictEqual(refusedAs(notesRef));533 expect(yield* gitOk(forkRepo, "rev-parse", notesRef)).toBe(noted);534 }).pipe(Effect.provide(NodeServices.layer)),535 30_000536 );537538 it.live(539 "a claimant's push of main beside a tag is refused whole: main stays and nothing is offered",540 () =>541 Effect.gen(function* () {542 const { api, repos, root, seen, urlOf } = yield* withDatekit;543 const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);544 const clone = `${root}/alices`;545 const forkRepo = `${repos}/${claim.fork}.git`;546547 yield* gitOk(548 root,549 ...as(tokens.alice),550 "clone",551 "--quiet",552 urlOf(claim.fork),553 clone554 );555 yield* commit(clone, "parse the year", {556 "packages/parser/src/parse.ts":557 "export const parse = (s) => ({ year: 2026 });\n",558 });559 yield* gitOk(clone, "tag", "v1");560561 const before = yield* gitOk(forkRepo, "rev-parse", "main");562563 const pushed = yield* git(564 clone,565 ...as(tokens.alice),566 "push",567 "origin",568 "HEAD:main",569 "refs/tags/v1"570 );571572 expect({573 exitCode: pushed.exitCode,574 remote: remoteLines(pushed.stderr),575 }).toStrictEqual(refusedAs("refs/tags/v1"));576 expect(577 [" HEAD -> main (DirectPush)", " v1 -> v1 (DirectPush)"].map(578 (rejected) =>579 pushed.stderr.includes(` ! [remote rejected]${rejected}`)580 )581 ).toStrictEqual([true, true]);582 expect(yield* gitOk(forkRepo, "rev-parse", "main")).toBe(before);583 expect(yield* Ref.get(seen.started)).toStrictEqual([]);584 }).pipe(Effect.provide(NodeServices.layer)),585 30_000586 );587588 it.live(589 "a fork is read by signed-in people, and a name the platform never makes is a 404",590 () =>591 Effect.gen(function* () {592 const { api, origin } = yield* withDatekit;593 const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);594595 const refs = (repo: string) =>596 `${origin}/${597 repo.includes("/")598 ? repo599 : Option.getOrElse(addressOfRepo(RepoName.make(repo)), () => repo)600 }.git/info/refs?service=git-upload-pack`;601602 expect(yield* request(refs(claim.fork))).toStrictEqual({603 basic: true,604 status: 401,605 });606 expect(607 (yield* request(refs(claim.fork), `Bearer ${tokens.bob}`)).status608 ).toBe(200);609 expect(610 (yield* request(refs(`${keyOf(datekit)}--layer--alice`))).status611 ).toBe(404);612 expect(613 (yield* request(refs(`${datekit}--${parseIso}--Alice`))).status614 ).toBe(404);615 }).pipe(Effect.provide(NodeServices.layer)),616 30_000617 );618});619620describe("a push's request id", () => {621 it("names the whole head, then as much of the pusher as fits", () => {622 const head = CommitSha.make("0123456789abcdef0123456789abcdef01234567");623 const next = CommitSha.make("0123456789abcdef0123456789abcdef01234568");624 const long = Handle.make(`Long-${"handle".repeat(10)}`);625626 expect([627 pushRequestId(alice.handle, head),628 pushRequestId(bob.handle, head),629 pushRequestId(long, head),630 pushRequestId(long, next),631 ]).toStrictEqual([632 `push-${head}-alice`,633 `push-${head}-bob`,634 `push-${head}-long-handlehandleh`,635 `push-${next}-long-handlehandleh`,636 ]);637 });638});639640const carol = Person.make({ handle: Handle.make("carol") });641642const mainRef = RefName.make("refs/heads/main");643644const moving = (ref: RefName, from: Option.Option<CommitSha>): Command => ({645 from,646 ref,647 to: Option.some(CommitSha.make("c".repeat(40))),648});649650const judged = (651 projects: Projects["Service"],652 pusher: Person,653 repo: string,654 commands: Array.NonEmptyReadonlyArray<Command>655) =>656 Effect.gen(function* () {657 const name = Option.getOrElse(repoNameOfAddress(repo), () =>658 RepoName.make(repo)659 );660661 const custody = yield* custodyFor(pusher, repoKind(name));662663 return {664 admitted: yield* custody.admit(name, commands),665 reviewed: yield* custody.review(name, commands),666 };667 }).pipe(Effect.provideService(Projects, projects));668669describe("custody of one push", () => {670 it.live(671 "a claim's fork takes its claimant's pushes while the claim is live, and a lapsed claim is ClaimLapsed",672 () =>673 Effect.gen(function* () {674 const { api, landed, projects } = yield* withDatekit;675 const { claim } = yield* api.claim(alice, parseIso).pipe(Effect.orDie);676 const push = Array.of(moving(mainRef, Option.some(landed)));677678 const live = yield* custodyFor(alice, repoKind(claim.fork)).pipe(679 Effect.flatMap((custody) => custody.admit(claim.fork, push)),680 Effect.provideService(Projects, projects)681 );682683 const lapsed = yield* Effect.gen(function* () {684 yield* TestClock.setTime(685 DateTime.toEpochMillis(686 DateTime.addDuration(claim.lapsesAt, "1 minute")687 )688 );689 yield* api.onAlarm();690691 const custody = yield* custodyFor(alice, repoKind(claim.fork));692693 return yield* custody.admit(claim.fork, push);694 }).pipe(695 Effect.provideService(Projects, projects),696 Effect.provide(TestClock.layer())697 );698699 expect(live).toStrictEqual([]);700 expect(lapsed).toStrictEqual([ClaimLapsed.of(parseIso)]);701 }).pipe(Effect.provide(NodeServices.layer)),702 30_000703 );704705 it.live(706 "a maintainer pushes onto someone's claim fork to finish its answer, which the push itself does not offer",707 () =>708 Effect.gen(function* () {709 const { api, landed, projects, seen } = yield* withDatekit;710 const { claim } = yield* api.claim(bob, parseIso).pipe(Effect.orDie);711 const push = Array.of(moving(mainRef, Option.some(landed)));712713 expect(yield* judged(projects, alice, claim.fork, push)).toStrictEqual({714 admitted: [],715 reviewed: [],716 });717 expect(yield* Ref.get(seen.started)).toStrictEqual([]);718 expect(719 (yield* judged(projects, carol, claim.fork, push)).admitted720 ).toStrictEqual([NotClaimed.of(parseIso)]);721 }).pipe(Effect.provide(NodeServices.layer)),722 30_000723 );724725 it.live(726 "a working fork takes its owner's pushes only",727 () =>728 Effect.gen(function* () {729 const { projects } = yield* withDatekit;730 const fork = `${keyOf(datekit)}--me--alice`;731 const push = Array.of(moving(mainRef, Option.none()));732733 expect(yield* judged(projects, alice, fork, push)).toStrictEqual({734 admitted: [],735 reviewed: [],736 });737 expect(738 (yield* judged(projects, bob, fork, push)).admitted739 ).toStrictEqual([new DirectPush({ ref: mainRef })]);740 }).pipe(Effect.provide(NodeServices.layer)),741 30_000742 );743744 it.live(745 "a fork takes branches only, whoever pushes: a working fork's owner and a finishing maintainer hear DirectPush for a tag",746 () =>747 Effect.gen(function* () {748 const { api, landed, projects } = yield* withDatekit;749 const { claim } = yield* api.claim(bob, parseIso).pipe(Effect.orDie);750 const working = `${keyOf(datekit)}--me--alice`;751 const tag = RefName.make("refs/tags/v1");752 const side = RefName.make("refs/heads/side");753 const tagged = Array.of(moving(tag, Option.none()));754755 const deletion = Array.of<Command>({756 from: Option.some(CommitSha.make(landed)),757 ref: RefName.make(notesRef),758 to: Option.none(),759 });760761 expect({762 decider: (yield* judged(projects, alice, claim.fork, tagged))763 .admitted,764 deletion: (yield* judged(projects, bob, claim.fork, deletion))765 .admitted,766 owner: (yield* judged(projects, alice, working, tagged)).admitted,767 ownerBranch: (yield* judged(768 projects,769 alice,770 working,771 Array.of(moving(side, Option.none()))772 )).admitted,773 }).toStrictEqual({774 decider: [new DirectPush({ ref: tag })],775 deletion: [new DirectPush({ ref: notesRef })],776 owner: [new DirectPush({ ref: tag })],777 ownerBranch: [],778 });779 }).pipe(Effect.provide(NodeServices.layer)),780 30_000781 );782783 it.live(784 "a canonical repo takes no ref but main, and its first push only from its initializer, as the project says",785 () =>786 Effect.gen(function* () {787 const { projects } = yield* gatewayWorld([scenario]);788 const api = yield* projects.create(fresh).pipe(Effect.orDie);789 const side = RefName.make("refs/heads/side");790791 const first = Array.make(792 moving(mainRef, Option.none()),793 moving(side, Option.none())794 );795796 yield* api.initProject(alice, {}).pipe(Effect.orDie);797798 const byBob = yield* judged(projects, bob, fresh, first);799 const byAlice = yield* judged(projects, alice, fresh, first);800801 const unmade = yield* judged(802 projects,803 alice,804 ProjectName.make("alice/nokit"),805 first806 );807808 expect(byAlice.admitted).toStrictEqual([new DirectPush({ ref: side })]);809 expect(byBob.admitted).toStrictEqual([810 new DirectPush({ ref: mainRef }),811 new DirectPush({ ref: side }),812 ]);813 expect(unmade.admitted).toStrictEqual(byBob.admitted);814 }).pipe(Effect.provide(NodeServices.layer)),815 30_000816 );817818 it.live(819 "a push to a project nobody made is UnknownProject",820 () =>821 Effect.gen(function* () {822 const { projects } = yield* gatewayWorld([scenario]);823 const nobody = ProjectName.make("alice/nokit");824 const push = Array.of(moving(mainRef, Option.none()));825826 expect(827 (yield* judged(828 projects,829 alice,830 `${keyOf(nobody)}--${parseIso}--alice`,831 push832 )).admitted833 ).toStrictEqual([new UnknownProject({ project: nobody })]);834 }).pipe(Effect.provide(NodeServices.layer)),835 30_000836 );837});