Skip to content
Myr

state.test.ts

This file

Path

apps/platform/test/visibility/state.test.ts

107 lines · 3.4 KiB · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–27why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { AdmissionStarts, SaltSource } from "@repo/project/visibility/state";3import { CommitSha, LayerName, ProjectName } from "@repo/protocol/ids";4import { Cause, Effect, Exit, Schema } from "effect";56import { AdmissionParams } from "../../src/answer-runs.ts";7import { admissionStarts, WebCryptoSalts } from "../../src/visibility/state.ts";8import type { AdmissionWorkflow } from "../../src/visibility/state.ts";910const hexOf = (bytes: Uint8Array) =>11 [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");1213describe("salts from WebCrypto", () => {14 it.effect("are 32 bytes, fresh each time", () =>15 Effect.gen(function* () {16 const salts = yield* SaltSource.use(({ next }) =>17 Effect.all([next, next, next])18 );1920 expect({21 distinct: new Set(salts.map(hexOf)).size,22 lengths: salts.map(({ length }) => length),23 }).toStrictEqual({ distinct: 3, lengths: [32, 32, 32] });24 }).pipe(Effect.provide(WebCryptoSalts))25 );26});27

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 28why, one step back
28const datekit = ProjectName.make("alice/datekit");

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 29–85why, one step back
29
30const maintainers = LayerName.make("maintainers");3132const head = CommitSha.make("a".repeat(40));3334const later = CommitSha.make("b".repeat(40));3536const workflowOf = (down = false) => {37 const created: { readonly id: string; readonly params: unknown }[] = [];3839 const workflow: AdmissionWorkflow = {40 create: ({ id, params }) => {41 if (down || created.some((each) => each.id === id)) {42 return Promise.reject(new Error(`instance ${id} was not created`));43 }4445 created.push({ id, params });4647 return Promise.resolve({ id });48 },49 get: (id) =>50 !down && created.some((each) => each.id === id)51 ? Promise.resolve({ id })52 : Promise.reject(new Error(`no instance ${id}`)),53 };5455 return { created, workflow };56};5758const decodeParams = Schema.decodeUnknownSync(AdmissionParams);5960const admissionOf = (at: CommitSha) =>61 AdmissionParams.make({ head: at, layer: maintainers, project: datekit });6263const start = (input: { readonly head: CommitSha }) =>64 AdmissionStarts.use((admissions) =>65 admissions.start({ head: input.head, layer: maintainers, project: datekit })66 );6768describe("an admission's start", () => {69 it.effect(70 "runs one Answer Workflow instance per project, layer and head, found again when started twice",71 () => {72 const { created, workflow } = workflowOf();7374 return Effect.gen(function* () {75 yield* start({ head });76 yield* start({ head });77 yield* start({ head: later });7879 expect(80 created.map(({ id, params: given }) => ({81 id,82 params: decodeParams(given),83 }))84 ).toStrictEqual([85 {

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 86why, one step back
86 id: `admit-alice__datekit-maintainers-${head}`,

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 87–89why, one step back
87 params: admissionOf(head),
88 },89 {

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 90why, one step back
90 id: `admit-alice__datekit-maintainers-${later}`,

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 91–107why, one step back
91 params: admissionOf(later),
92 },93 ]);94 }).pipe(Effect.provide(admissionStarts(workflow)));95 }96 );9798 it.effect(99 "is a defect when the instance can be neither made nor found, so the outbox runs it again",100 () =>101 Effect.gen(function* () {102 const exit = yield* Effect.exit(start({ head }));103104 expect(Exit.isFailure(exit) && Cause.hasDies(exit.cause)).toBeTruthy();105 }).pipe(Effect.provide(admissionStarts(workflowOf(true).workflow)))106 );107});