Skip to content
Myr

fixture.ts

This file

Path

apps/cli/test/local/fixture.ts

120 lines · 3.5 KiB · TypeScript

Last changed by

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

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–4why, one step back
1import { Brand } from "@repo/brand";
2import { gitOk } from "@repo/testkit/git";3import { Effect, FileSystem, Path } from "effect";4

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 5why, one step back
5export const project = "alice/fixture";

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 6–18why, one step back
6
7export const ask = "fix-a";89export const handle = "alice";1011export const platform = "https://platform.example.dev";1213const forkRemote = `${platform}/${project}--${ask}--${handle}.git`;1415export const policyFile = `${Brand.configDir}/policy.json`;1617export const checkFile = "packages/a/test/a.test.ts";18

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

line 19why, one step back
19// The fixture's `{configDir}` is written over with the brand's folder name.

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 20–120why, one step back
20export const policyText = Effect.gen(function* () {
21 const fs = yield* FileSystem.FileSystem;22 const path = yield* Path.Path;2324 const file = yield* path.fromFileUrl(25 new URL("../fixtures/check/policy.json", import.meta.url)26 );2728 const text = yield* fs.readFileString(file);2930 return text.replaceAll("{configDir}", Brand.configDir);31});3233const testOnMain = [34 'import { expect, it } from "vitest";',35 'import { a } from "../src/a.ts";',36 "",37 'it("is two", () => expect(a).toBe(2));',38 "",39].join("\n");4041const onMain = {42 [checkFile]: testOnMain,43 "package.json":44 '{ "name": "fixture", "private": true, "workspaces": ["packages/*"] }\n',45 "packages/a/package.json":46 '{ "name": "a", "exports": { ".": "./src/a.ts" } }\n',47 "packages/a/src/a.ts": "export const a = 1;\n",48 "packages/b/package.json": '{ "name": "b" }\n',49 "packages/b/src/b.ts": "export const b = 1;\n",50} as const satisfies Readonly<Record<string, string>>;5152const straying = {53 [checkFile]: testOnMain.replace(54 "it(",55 'it.skip("is one", () => expect(a).toBe(1));\nit('56 ),57 "packages/a/src/a.ts": "export const a = 2;\n",58 "packages/b/src/b.ts": "export const b = 2;\n",59} as const satisfies Readonly<Record<string, string>>;6061const clean = {62 "packages/a/src/a.ts": "export const a = 2;\n",63} as const satisfies Readonly<Record<string, string>>;6465export interface CheckRepo {66 readonly root: string;67 readonly main: string;68 readonly straying: string;69 readonly clean: string;70}7172const write = (root: string, files: Readonly<Record<string, string>>) =>73 Effect.gen(function* () {74 const fs = yield* FileSystem.FileSystem;75 const path = yield* Path.Path;7677 for (const [file, content] of Object.entries(files)) {78 const at = path.join(root, file);7980 yield* fs.makeDirectory(path.dirname(at), { recursive: true });81 yield* fs.writeFileString(at, content);82 }83 });8485export const commit = (86 root: string,87 files: Readonly<Record<string, string>>,88 message: string89) =>90 Effect.gen(function* () {91 yield* write(root, files);92 yield* gitOk(root, "add", "--all");93 yield* gitOk(root, "commit", "--quiet", "--message", message);9495 return yield* gitOk(root, "rev-parse", "HEAD");96 });9798export const aCheckRepo = Effect.gen(function* () {99 const fs = yield* FileSystem.FileSystem;100 const root = yield* fs.realPath(yield* fs.makeTempDirectoryScoped());101102 yield* gitOk(root, "init", "--quiet", "--initial-branch", "main");103 yield* gitOk(root, "remote", "add", "origin", forkRemote);104105 const main = yield* commit(106 root,107 { ...onMain, [policyFile]: yield* policyText },108 "Start the fixture"109 );110111 yield* gitOk(root, "checkout", "--quiet", "-b", "clean");112113 const fixed = yield* commit(root, clean, "Make a two");114115 yield* gitOk(root, "checkout", "--quiet", "-b", "straying", "main");116117 const strayed = yield* commit(root, straying, "Make a two, and more");118119 return { clean: fixed, main, root, straying: strayed } satisfies CheckRepo;120});