Skip to content
Myr

created.test.ts

This file

Path

packages/config/test/created.test.ts

113 lines · 3.5 KiB · TypeScript

Last changed by

Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503

History of this file

Take it

Name the swarm, seed and release scripts, and record every throwaway resource a live run makes in one ledgeroscabrielbefore adoptiond7064cb

lines 1–113why, one step back
1import { NodeServices } from "@effect/platform-node";
2import { describe, expect, it } from "@effect/vitest";3import { DateTime, Effect, FileSystem, Path } from "effect";45import {6 ledgerPath,7 LedgerFile,8 readLedger,9 recordCreated,10 throwawayName,11} from "../../../infra/created.ts";12import type { Created } from "../../../infra/created.ts";13import { repoRoot } from "./root.ts";1415const smokeRepo: Created = {16 at: DateTime.makeUnsafe("2026-10-13T09:00:00Z"),17 by: "smoke",18 kind: "repo",19 name: "smoke-r1",20 namespace: "projects-dev-oscabriel",21 stage: "dev-oscabriel",22};2324const swarmProject: Created = {25 at: DateTime.makeUnsafe("2026-10-13T09:05:00Z"),26 by: "swarm",27 kind: "project",28 name: "swarm-r2",29 stage: "dev-oscabriel",30};3132const tempLedger = Effect.gen(function* () {33 const fs = yield* FileSystem.FileSystem;34 const path = yield* Path.Path;35 const dir = yield* fs.makeTempDirectoryScoped({ prefix: "ledger-701-" });3637 return path.join(dir, "created.jsonl");38});3940describe("the throwaway ledger", () => {41 it.live("appends one JSON line per entry and reads them back in order", () =>42 Effect.gen(function* () {43 const fs = yield* FileSystem.FileSystem;44 const file = yield* tempLedger;4546 const read = yield* Effect.gen(function* () {47 yield* recordCreated(smokeRepo);48 yield* recordCreated(swarmProject);4950 return yield* readLedger;51 }).pipe(Effect.provideService(LedgerFile, file));5253 expect({54 lines: (yield* fs55 .readFileString(file)56 .pipe(Effect.orElseSucceed(() => ""))).split("\n"),57 read,58 }).toStrictEqual({59 lines: [60 '{"at":"2026-10-13T09:00:00.000Z","by":"smoke","kind":"repo","name":"smoke-r1","namespace":"projects-dev-oscabriel","stage":"dev-oscabriel"}',61 '{"at":"2026-10-13T09:05:00.000Z","by":"swarm","kind":"project","name":"swarm-r2","stage":"dev-oscabriel"}',62 "",63 ],64 read: [smokeRepo, swarmProject],65 });66 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))67 );6869 it.live("writes the repo's own ledger unless a test points elsewhere", () =>70 Effect.gen(function* () {71 const path = yield* Path.Path;72 const root = yield* repoRoot;7374 expect(yield* LedgerFile).toBe(path.join(root, ledgerPath));75 }).pipe(Effect.provide(NodeServices.layer))76 );7778 it.live("reads a ledger no run has written yet as empty", () =>79 Effect.gen(function* () {80 const file = yield* tempLedger;8182 expect(83 yield* readLedger.pipe(Effect.provideService(LedgerFile, file))84 ).toStrictEqual([]);85 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))86 );8788 it.live("fails on a line that is not a Created entry", () =>89 Effect.gen(function* () {90 const fs = yield* FileSystem.FileSystem;91 const file = yield* tempLedger;9293 yield* fs.writeFileString(94 file,95 '{"at":"2026-10-13T09:00:00.000Z","by":"smoke","kind":"repo","name":"smoke-r1","stage":"dev-oscabriel"}\n{"by":"bench","kind":"repo","name":"bench-r1"}\n'96 );9798 const error = yield* readLedger.pipe(99 Effect.provideService(LedgerFile, file),100 Effect.flip101 );102103 expect(error._tag).toBe("SchemaError");104 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))105 );106107 it("names a throwaway by the run that made it, never by the brand", () => {108 expect([109 throwawayName("smoke", "r1"),110 throwawayName("swarm", "r2"),111 ]).toStrictEqual(["smoke-r1", "swarm-r2"]);112 });113});