w9-contracts.test.ts
This file
Path
apps/platform/test/w9-contracts.test.ts
159 lines · 4.9 KiB · TypeScript
Last changed by
Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160import { describe, expect, it } from "@effect/vitest";import { AskId, ProposalId, RepoPath } from "@repo/protocol/ids";import { Unauthenticated } from "@repo/protocol/principal";import { advanceTo } from "@repo/testkit/clock";import { aProject, withAsk, withVouches } from "@repo/testkit/scenarios";import { Effect, Exit, Layer } from "effect";
import { Handlers } from "../src/handlers.ts";import { MemorySessions } from "../src/sessions/memory.ts";import { seeded, worldOf } from "./handlers.fixtures.ts";import { origin, rpcClient, served } from "./harness.ts";
const datekit = aProject({ people: ["bob"] }).pipe( withVouches(["bob"]), withAsk({ id: "parse-iso", territory: "packages/parser" }));
const { project } = datekit;
const sessions = MemorySessions.layer({});
const platform = Effect.gen(function* () { yield* advanceTo("2026-10-07T12:00:00Z");
const world = yield* Layer.build(worldOf([datekit]));
yield* seeded(datekit).pipe(Effect.provide(world));
const ports = Layer.succeedContext(world);
return yield* served( Layer.mergeAll(Handlers.pipe(Layer.provide(ports)), ports, sessions) );});
describe("the code, policy and drafting contracts over /rpc", () => { it.effect("give anyone a project's policy, without its layers", () => Effect.gen(function* () { const { handler } = yield* platform; const anyone = yield* rpcClient(handler);
const read = yield* anyone.projectPolicy({ project }); const { policy } = read;
expect(Object.keys(read)).toStrictEqual(["policy"]); expect(policy?.source).toBe("config"); expect(policy?.deciders).toStrictEqual(datekit.policy.deciders); expect(Object.keys(policy ?? {})).not.toContain("visibility"); expect(Object.keys(policy ?? {})).not.toContain("asks"); }) );
it.effect("give anyone an opening's landing, naming the ask it opened", () => Effect.gen(function* () { const { handler } = yield* platform; const anyone = yield* rpcClient(handler); const ask = AskId.make("parse-iso"); const { ask: opened } = yield* anyone.showAsk({ ask, project });
const { landing } = yield* anyone.landing({ project, sha: opened.openedIn, });
expect({ ask: landing.ask, opened: landing.opened }).toStrictEqual({ ask: undefined, opened: ask, }); }) );
it.effect( "reach the code façade, whose why names the landing behind each line", () => Effect.gen(function* () { const { handler } = yield* platform; const anyone = yield* rpcClient(handler); const path = RepoPath.make("package.json"); const view = yield* anyone.why({ path, project }); const [first] = view.commits;
expect(view.path).toBe(path); expect(first?.subject).toBe("Start"); expect(view.ranges).toStrictEqual([ { end: 1, sha: first?.sha, start: 1 }, ]); expect( view.landings.map(({ author, sha }) => [sha, author]) ).toStrictEqual([[first?.sha, "alice"]]); }) );
it.effect("refuse a draft to anyone not signed in", () => Effect.gen(function* () { const { handler } = yield* platform; const anyone = yield* rpcClient(handler);
expect( yield* Effect.exit( anyone.draftAsk({ project, proposal: ProposalId.make("prop-000001"), }) ) ).toStrictEqual(Exit.fail(new Unauthenticated())); }) );});
describe("the host page and raw files routes", () => { it.effect( "answer / and a project's raw files from their slots, a stale bearer or not", () => Effect.gen(function* () { const { fetch } = yield* platform;
const stale = { authorization: "Bearer not-a-token-the-platform-knows", };
const read = (path: string, headers: Record<string, string> = {}) => Effect.flatMap( fetch(new Request(`${origin}${path}`, { headers })), (response) => Effect.map( Effect.promise(() => response.text()), (text) => ({ status: response.status, text }) ) );
const raw = `/${project}/raw/${"4".repeat(40)}/README.md`;
expect({ home: (yield* read("/")).status, homeStale: (yield* read("/", stale)).status, raw: yield* read(raw), rawStale: yield* read(raw, stale), }).toStrictEqual({ home: 200, homeStale: 200, raw: { status: 404, text: "" }, rawStale: { status: 404, text: "" }, }); }) );
it.effect("leaves git's own paths to git, beside the raw route", () => Effect.gen(function* () { const { fetch } = yield* platform;
const response = yield* fetch( new Request(`${origin}/${project}/raw/info/refs`) );
expect(response.status).toBe(404); expect(yield* Effect.promise(() => response.text())).toBe(""); }) );});