posture-listing.test.ts
This file
Path
apps/platform/test/posture-listing.test.ts
120 lines · 3.7 KiB · TypeScript
Last changed by
Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
History of this fileTake it
Merge build/1102 into mainoscabrielbefore adoption084383d
lines 1–6why, one step back1import { describe, expect, it } from "@effect/vitest";2import { RepoHost } from "@repo/artifacts/repo-host";3import { EvidenceStoreMemory } from "@repo/checks/evidence-store/memory";4import { FrontPageMemory } from "@repo/project/front-page/memory";5import type { ProjectApi } from "@repo/project/project";6import { Projects } from "@repo/project/projects";Merge build/1213-platform-performance-and-agent-surfacesoscabrielbefore adoption1d75a0d
line 7why, one step back7import { StandingPosturesMemory } from "@repo/project/standing-posture/memory";Merge build/1102 into mainoscabrielbefore adoption084383d
lines 8–16why, one step back8import { Contracts } from "@repo/protocol/contracts";9import { ProjectName } from "@repo/protocol/ids";10import {11 Anonymous,12 Authenticated,13 CurrentPrincipal,14} from "@repo/protocol/principal";15import { UnknownProject } from "@repo/protocol/refusal";16import { untouchable } from "@repo/testkit/untouchable";Merge build/1213-platform-performance-and-agent-surfacesoscabrielbefore adoption1d75a0d
line 17why, one step back17import { Effect, Layer, Ref } from "effect";Merge build/1102 into mainoscabrielbefore adoption084383d
lines 18–22why, one step back18import { RpcTest } from "effect/rpc";1920import { MemoryRateLimits, WorkerCaps } from "../src/adapters/rate-limits.ts";21import { Handlers } from "../src/handlers.ts";22Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 23why, one step back23const datekit = ProjectName.make("alice/datekit");Merge build/1102 into mainoscabrielbefore adoption084383d
line 24why, one step back24Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 25why, one step back25const ghost = ProjectName.make("alice/ghost");Merge build/1102 into mainoscabrielbefore adoption084383d
line 26why, one step back26Merge build/1213-platform-performance-and-agent-surfacesoscabrielbefore adoption1d75a0d
lines 27–37why, one step back27const datekitApi = (reads: Ref.Ref<number>) =>28 untouchable<ProjectApi>("ProjectApi", {29 standing: () =>30 Effect.as(31 Ref.update(reads, (count) => count + 1),32 {33 posture: "openWithSealedEvidence",34 seen: 1,35 }36 ),37 });Merge build/1102 into mainoscabrielbefore adoption084383d
line 38why, one step back38Merge build/1213-platform-performance-and-agent-surfacesoscabrielbefore adoption1d75a0d
lines 39–67why, one step back39const platformCounting = (reads: Ref.Ref<number>) =>40 Handlers.pipe(41 Layer.provide([42 Layer.succeed(43 Projects,44 Projects.of({45 create: () => Effect.die("a listing makes no project"),46 get: (project) =>47 project === datekit48 ? Effect.succeed(datekitApi(reads))49 : Effect.fail(new UnknownProject({ project })),50 })51 ),52 FrontPageMemory.layer({53 credits: [],54 entries: [],55 projects: [56 { openAsks: 3, posture: "open", project: datekit },57 { openAsks: 0, posture: "openCore", project: ghost },58 ],59 }),60 MemoryRateLimits(WorkerCaps),61 EvidenceStoreMemory,62 Layer.succeed(RepoHost, untouchable<RepoHost["Service"]>("RepoHost")),63 ])64 );6566const platform = Layer.unwrap(67 Effect.map(Ref.make(0), (reads) => platformCounting(reads))Merge build/1102 into mainoscabrielbefore adoption084383d
lines 68–89why, one step back68);6970const anonymous = Layer.succeed(Authenticated, (effect) =>71 Effect.provideService(effect, CurrentPrincipal, Anonymous.make({}))72);7374describe("the platform's project list", () => {75 it.effect("gives each project the posture its ledger stands at", () =>76 Effect.gen(function* () {77 const anyone = yield* RpcTest.makeClient(Contracts);7879 expect(yield* anyone.listProjects({})).toStrictEqual({80 projects: [81 {82 openAsks: 3,83 posture: "openWithSealedEvidence",84 project: datekit,85 },86 { openAsks: 0, posture: "openCore", project: ghost },87 ],88 });89 }).pipe(Effect.provide(Layer.mergeAll(platform, anonymous)))Merge build/1213-platform-performance-and-agent-surfacesoscabrielbefore adoption1d75a0d
lines 90–118why, one step back90 );9192 it.effect(93 "keeps each posture it read where the platform keeps them, so the next list reads none",94 () =>95 Effect.gen(function* () {96 const reads = yield* Ref.make(0);9798 const [first, second] = yield* Effect.gen(function* () {99 const anyone = yield* RpcTest.makeClient(Contracts);100101 return [102 yield* anyone.listProjects({}),103 yield* anyone.listProjects({}),104 ] as const;105 }).pipe(106 Effect.provide(107 Layer.mergeAll(108 platformCounting(reads).pipe(109 Layer.provide(StandingPosturesMemory)110 ),111 anonymous112 )113 )114 );115116 expect(second).toStrictEqual(first);117 expect(yield* Ref.get(reads)).toBe(1);118 })Merge build/1102 into mainoscabrielbefore adoption084383d
lines 119–120why, one step back119 );120});