import-examples.test.ts
This file
Path
packages/config/test/import-examples.test.ts
744 lines · 24.8 KiB · TypeScript
Last changed by
Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf
History of this fileTake it
Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 1–17why, one step back1import { NodeServices } from "@effect/platform-node";2import { describe, expect, it } from "@effect/vitest";3import { ProjectExists } from "@repo/protocol/refusal";4import {5 Console,6 Data,7 Duration,8 Effect,9 Fiber,10 FileSystem,11 Layer,12 Option,13 Path,14 Redacted,15 Exit,16 Ref,17 Result,Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 18why, one step back18 Schema,Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 19–27why, one step back19} from "effect";20import { TestClock } from "effect/testing";2122import { LedgerFile, readLedger } from "../../../infra/created.ts";23import {24 examples,25 planImports,26 shownCommand,27 tagBackfillCommands,Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 28why, one step back28 warmPaths,Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 29–34why, one step back29} from "../../../scripts/lib/import/plan.ts";30import type { ImportExample } from "../../../scripts/lib/import/plan.ts";31import {32 importExamples,33 ImportTarget,34 initUntilAnswered,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 35why, one step back35 optionsOf,Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 36why, one step back36 TagBackfill,Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 37why, one step back37 Warmer,Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 38why, one step back38} from "../../../scripts/lib/import/run.ts";Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 39why, one step back39import { keyOf, ProjectName } from "../../protocol/src/ids.ts";Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 40why, one step back40Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 41–43why, one step back41// A project of the plan by the key it was imported under (`anyhow`), read42// as its name (`github.com/dtolnay/anyhow`), as every surface reads it.43const project = (key: string) => Schema.decodeSync(ProjectName)(key);Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 44–45why, one step back4445const names = (planned: readonly ImportExample[]) =>Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 46why, one step back46 planned.map(({ name }) => name);Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 47–48why, one step back4748describe("the import plan", () => {Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 49why, one step back49 it("holds the eight repos of the preview first, then thirty well-known ones, each on its branch with its licence", () => {Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 50why, one step back50 expect(Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 51–52why, one step back51 examples.map(({ branch, key, licence, url }) => [52 key,Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 53–56why, one step back53 branch,54 url,55 licence,56 ])Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 57why, one step back57 ).toStrictEqual([Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 58–120why, one step back58 [59 "anyhow",60 "master",61 "https://github.com/dtolnay/anyhow",62 "MIT OR Apache-2.0",63 ],64 ["ky", "main", "https://github.com/sindresorhus/ky", "MIT"],65 ["gum", "main", "https://github.com/charmbracelet/gum", "MIT"],66 ["click", "main", "https://github.com/pallets/click", "BSD-3-Clause"],67 ["awesome", "main", "https://github.com/sindresorhus/awesome", "CC0-1.0"],68 ["changesets", "main", "https://github.com/changesets/changesets", "MIT"],69 ["stb", "master", "https://github.com/nothings/stb", "MIT OR Unlicense"],70 ["fuzzel", "master", "https://codeberg.org/dnkl/fuzzel", "MIT"],71 ["hono", "main", "https://github.com/honojs/hono", "MIT"],72 ["express", "master", "https://github.com/expressjs/express", "MIT"],73 ["fastify", "main", "https://github.com/fastify/fastify", "MIT"],74 ["zustand", "main", "https://github.com/pmndrs/zustand", "MIT"],75 ["immer", "main", "https://github.com/immerjs/immer", "MIT"],76 ["nanoid", "main", "https://github.com/ai/nanoid", "MIT"],77 ["commander", "master", "https://github.com/tj/commander.js", "MIT"],78 ["execa", "main", "https://github.com/sindresorhus/execa", "MIT"],79 ["chalk", "main", "https://github.com/chalk/chalk", "MIT"],80 ["mitt", "main", "https://github.com/developit/mitt", "MIT"],81 ["clsx", "master", "https://github.com/lukeed/clsx", "MIT"],82 [83 "ripgrep",84 "master",85 "https://github.com/BurntSushi/ripgrep",86 "Unlicense OR MIT",87 ],88 [89 "serde",90 "master",91 "https://github.com/serde-rs/serde",92 "MIT OR Apache-2.0",93 ],94 ["axum", "main", "https://github.com/tokio-rs/axum", "MIT"],95 ["fd", "master", "https://github.com/sharkdp/fd", "MIT OR Apache-2.0"],96 [97 "hyperfine",98 "master",99 "https://github.com/sharkdp/hyperfine",100 "MIT OR Apache-2.0",101 ],102 [103 "bubbletea",104 "main",105 "https://github.com/charmbracelet/bubbletea",106 "MIT",107 ],108 ["fzf", "master", "https://github.com/junegunn/fzf", "MIT"],109 ["cobra", "main", "https://github.com/spf13/cobra", "Apache-2.0"],110 ["gin", "master", "https://github.com/gin-gonic/gin", "MIT"],111 ["requests", "main", "https://github.com/psf/requests", "Apache-2.0"],112 ["flask", "main", "https://github.com/pallets/flask", "BSD-3-Clause"],113 ["httpx", "master", "https://github.com/encode/httpx", "BSD-3-Clause"],114 ["typer", "master", "https://github.com/fastapi/typer", "MIT"],115 ["jinja", "main", "https://github.com/pallets/jinja", "BSD-3-Clause"],116 ["lua", "master", "https://github.com/lua/lua", "MIT"],117 ["jq", "master", "https://github.com/jqlang/jq", "MIT"],118 ["kilo", "master", "https://github.com/antirez/kilo", "BSD-2-Clause"],119 ["sinatra", "main", "https://github.com/sinatra/sinatra", "MIT"],120 ["nvm", "master", "https://github.com/nvm-sh/nvm", "MIT"],Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 121–123why, one step back121 ]);122 });123Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 124–145why, one step back124 it("names each project at its source path, beside the key it was first imported under", () => {125 expect(126 examples127 .filter(({ key }) => ["click", "commander", "fuzzel"].includes(key))128 .map(({ key, name }) => [key, name])129 ).toStrictEqual([130 ["click", "github.com/pallets/click"],131 ["fuzzel", "codeberg.org/dnkl/fuzzel"],132 ["commander", "github.com/tj/commander"],133 ]);134 });135136 it.effect.each([137 ["github.com/pallets/click"],138 ["click"],139 ["GitHub.com/Pallets/click"],140 ] as const)("takes --only %s as click", ([named]) =>141 Effect.map(optionsOf(["--world", "node", "--only", named]), ({ only }) => {142 expect(only).toStrictEqual(Option.some("github.com/pallets/click"));143 })144 );145Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 146–154why, one step back146 it("names each project once, as a name the platform takes", () => {147 const all = names(examples);148149 expect(new Set(all).size).toBe(all.length);150 expect(all.filter((name) => !Schema.is(ProjectName)(name))).toStrictEqual(151 []152 );153 });154Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 155–174why, one step back155 it("skips a project the platform lists already, and keeps only the one --only names", () => {156 expect({157 all: names(158 planImports(159 examples,160 new Set([project("ky"), project("stb")]),161 Option.none()162 )163 ),164 listed: names(165 planImports(166 examples,167 new Set([project("anyhow")]),168 Option.some(project("anyhow"))169 )170 ),171 only: names(172 planImports(examples, new Set(), Option.some(project("gum")))173 ),174 }).toStrictEqual({Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 175–179why, one step back175 all: names(examples).filter(176 (name) =>177 name !== "github.com/sindresorhus/ky" &&178 name !== "github.com/nothings/stb"179 ),Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 180why, one step back180 listed: [],Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 181why, one step back181 only: ["github.com/charmbracelet/gum"],Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 182–185why, one step back182 });183 });184});185Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 186–188why, one step back186describe("the warm plan", () => {187 it("reads a project's home, its tree, its landings, and its README and why the README is there", () => {188 expect(warmPaths(project("ky"), Option.some("readme.md"))).toStrictEqual([Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 189–193why, one step back189 "/github.com/sindresorhus/ky",190 "/github.com/sindresorhus/ky/tree/main",191 "/github.com/sindresorhus/ky/commits/main",192 "/github.com/sindresorhus/ky/blob/main/readme.md",193 "/github.com/sindresorhus/ky/why/main/readme.md",Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 194–198why, one step back194 ]);195 });196197 it("reads no README when the project has none", () => {198 expect(warmPaths(project("awesome"), Option.none())).toStrictEqual([Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 199–201why, one step back199 "/github.com/sindresorhus/awesome",200 "/github.com/sindresorhus/awesome/tree/main",201 "/github.com/sindresorhus/awesome/commits/main",Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 202–205why, one step back202 ]);203 });204});205Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 206–279why, one step back206describe("the tag backfill's commands", () => {207 const token = Redacted.make("artifacts-write-token-0123456789abcdef");208209 const commands = tagBackfillCommands({210 mirror: "/tmp/import-tags/anyhow.git",211 remote: {212 token,213 url: "https://acct.artifacts.cloudflare.net/git/projects-dev-oscabriel/anyhow.git",214 },215 source: "https://github.com/dtolnay/anyhow",216 });217218 it("fetches the source's tags into a local bare repo, then pushes refs/tags/* and nothing else", () => {219 expect(commands.map(shownCommand)).toStrictEqual([220 "git init --bare --quiet /tmp/import-tags/anyhow.git",221 "git --git-dir /tmp/import-tags/anyhow.git fetch --quiet --no-tags https://github.com/dtolnay/anyhow refs/tags/*:refs/tags/*",222 "git --git-dir /tmp/import-tags/anyhow.git push --quiet https://acct.artifacts.cloudflare.net/git/projects-dev-oscabriel/anyhow.git refs/tags/*:refs/tags/*",223 ]);224225 const pushes = commands.filter(({ argv }) => argv.includes("push"));226227 expect(228 pushes.map(({ argv }) => argv.filter((arg) => arg.includes(":")))229 ).toStrictEqual([230 [231 "https://acct.artifacts.cloudflare.net/git/projects-dev-oscabriel/anyhow.git",232 "refs/tags/*:refs/tags/*",233 ],234 ]);235 expect(236 pushes.flatMap(({ argv }) =>237 argv.filter((arg) => /--force|--all|--mirror|main|heads/u.test(arg))238 )239 ).toStrictEqual([]);240 });241242 it("never prints the token: it rides in git's env as a header, redacted, not in an argument or a URL", () => {243 const printed = [244 ...commands.map(shownCommand),245 JSON.stringify(commands),246 JSON.stringify(commands.map(({ env }) => env)),247 ].join("\n");248249 expect(printed.includes(Redacted.value(token))).toBeFalsy();250 expect(251 commands.map(({ env = {} }) =>252 Object.entries(env).map(([name, value]) => [253 name,254 Redacted.value(value),255 ])256 )257 ).toStrictEqual([258 [],259 [],260 [261 ["GIT_CONFIG_COUNT", "1"],262 ["GIT_CONFIG_KEY_0", "http.extraHeader"],263 [264 "GIT_CONFIG_VALUE_0",265 "Authorization: Bearer artifacts-write-token-0123456789abcdef",266 ],267 ],268 ]);269 });270});271272const fakePlatform = (listed: readonly string[]) =>273 Effect.gen(function* () {274 const calls = yield* Ref.make<readonly string[]>([]);275 const have = new Set(listed.map(project));276 const note = (call: string) => Ref.update(calls, (all) => [...all, call]);277278 const target = ImportTarget.of({279 counts: (name) =>Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 280why, one step back280 note(`ls-remote ${keyOf(name)}`).pipe(Effect.as({ heads: 2, tags: 0 })),Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 281why, one step back281 initProject: (example) =>Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 282–283why, one step back282 note(`init ${example.key} ${example.branch}`).pipe(283 Effect.tap(() => Effect.sync(() => have.add(example.name))),Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 284–292why, one step back284 Effect.as({ landed: "a".repeat(40) })285 ),286 label: "dev-oscabriel (https://platform.test)",287 listProjects: note("listProjects").pipe(288 Effect.andThen(Effect.sync(() => new Set(have)))289 ),290 });291292 const backfill = TagBackfill.of({Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 293why, one step back293 backfill: (example) => note(`tags ${example.key}`).pipe(Effect.as(105)),Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 294–295why, one step back294 });295Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 296–298why, one step back296 // Every read answers but fuzzel's why, which the web never answered.297 const warmer = Warmer.of({298 warm: (name) =>Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 299why, one step back299 note(`warm ${keyOf(name)}`).pipe(Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 300–301why, one step back300 Effect.as(301 warmPaths(name, Option.some("README.md")).map((path) =>Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 302why, one step back302 keyOf(name) === "fuzzel" && path.includes("/why/")Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 303–309why, one step back303 ? { ok: false, path, said: "no answer" }304 : { ok: true, path, said: "200" }305 )306 )307 ),308 });309Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 310–313why, one step back310 return {311 calls: Ref.get(calls),312 layer: Layer.mergeAll(313 Layer.succeed(ImportTarget, target),Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 314–315why, one step back314 Layer.succeed(TagBackfill, backfill),315 Layer.succeed(Warmer, warmer)Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 316–321why, one step back316 ),317 };318 });319320const ran = (321 argv: readonly string[],Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 322why, one step back322 layer: Layer.Layer<ImportTarget | TagBackfill | Warmer>Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 323–326why, one step back323) =>324 Effect.gen(function* () {325 const fs = yield* FileSystem.FileSystem;326 const path = yield* Path.Path;Close the code browser and drafting wave: its decisions in two ADRs, every rule it added held, and its leftovers folded inoscabrielbefore adoption009640c
line 327why, one step back327 const dir = yield* fs.makeTempDirectoryScoped({ prefix: "importing-" });Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 328–360why, one step back328 const ledgerFile = path.join(dir, "created.jsonl");329 const printed: string[] = [];330331 const captured: Console.Console = {332 ...console,333 log: (...args: readonly unknown[]) => {334 printed.push(args.map(String).join(" "));335 },336 };337338 const result = yield* importExamples(argv, () => layer).pipe(339 Effect.provideService(LedgerFile, ledgerFile),340 Effect.provideService(Console.Console, captured),341 Effect.result342 );343344 const ledger = yield* readLedger.pipe(345 Effect.provideService(LedgerFile, ledgerFile)346 );347348 return { ledger, printed, result };349 });350351const onDev = (...flags: readonly string[]) => [352 "--stage",353 "dev-oscabriel",354 "--url",355 "https://platform.test",356 ...flags,357];358359describe("bun scripts/import-examples.ts", () => {360 it.live(Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf
line 361why, one step back361 "takes --stage prod as any declared stage: its dry run plans the import onto prod",Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 362–363why, one step back362 () =>363 Effect.gen(function* () {Merge build/imports-onto-demo into mainoscabrielbefore adoption873046e
line 364why, one step back364 const platform = yield* fakePlatform(["ky"]);Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 365why, one step back365Merge build/imports-onto-demo into mainoscabrielbefore adoption873046e
line 366why, one step back366 const { ledger, printed, result } = yield* ran(Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf
line 367why, one step back367 ["--stage", "prod", "--dry-run", "--only", "anyhow"],Merge build/imports-onto-demo into mainoscabrielbefore adoption873046e
lines 368–369why, one step back368 platform.layer369 );Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 370why, one step back370Merge build/imports-onto-demo into mainoscabrielbefore adoption873046e
lines 371–378why, one step back371 expect({372 ledger,373 printed,374 result: Result.isSuccess(result),375 }).toStrictEqual({376 ledger: [],377 printed: [378 "import-examples on dev-oscabriel (https://platform.test): 1 to import, 0 listed already",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 379why, one step back379 " would import github.com/dtolnay/anyhow from https://github.com/dtolnay/anyhow (master)",Merge build/imports-onto-demo into mainoscabrielbefore adoption873046e
lines 380–382why, one step back380 "dry run: nothing imported, nothing recorded",381 ],382 result: true,Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 383why, one step back383 });Merge build/imports-onto-demo into mainoscabrielbefore adoption873046e
line 384why, one step back384 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 385–387why, one step back385 );386387 it.live(Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 388why, one step back388 "imports each project the platform doesn't list, one at a time, with its counts, warms it, and records each in the ledger as a kept import",Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 389–390why, one step back389 () =>390 Effect.gen(function* () {Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 391–393why, one step back391 const fresh = ["anyhow", "awesome", "changesets", "fuzzel"];392393 const platform = yield* fakePlatform(Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 394–396why, one step back394 examples.flatMap(({ key, name }) =>395 fresh.includes(key) ? [] : [name]396 )Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 397–398why, one step back397 );398Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 399–409why, one step back399 const { ledger, printed, result } = yield* ran(onDev(), platform.layer);400401 expect({402 calls: yield* platform.calls,403 ledger: ledger.map(({ by, kind, name, namespace, stage }) => ({404 by,405 kind,406 name,407 namespace,408 stage,409 })),Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 410why, one step back410 printed: printed.filter((line) => !line.startsWith(" skip ")),Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 411why, one step back411 result: Result.isSuccess(result),Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 412why, one step back412 skipped: printed.filter((line) => line.startsWith(" skip ")).length,Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 413–415why, one step back413 }).toStrictEqual({414 calls: [415 "listProjects",Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 416–420why, one step back416 ...fresh.flatMap((name) => [417 `init ${name} ${name === "anyhow" || name === "fuzzel" ? "master" : "main"}`,418 `ls-remote ${name}`,419 `warm ${name}`,420 ]),Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 421why, one step back421 ],Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 422–437why, one step back422 ledger: fresh.flatMap((name) => [423 {424 by: "import",425 kind: "project",426 name,427 namespace: undefined,428 stage: "dev-oscabriel",429 },430 {431 by: "import",432 kind: "repo",433 name,434 namespace: "projects-dev-oscabriel",435 stage: "dev-oscabriel",436 },437 ]),Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
line 438why, one step back438 printed: [Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 439why, one step back439 "import-examples on dev-oscabriel (https://platform.test): 4 to import, 34 listed already",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 440–447why, one step back440 "imported github.com/dtolnay/anyhow (Rust crate, master): main at aaaaaaaaaaaa, 2 heads, 0 tags",441 " warmed github.com/dtolnay/anyhow: 5 of 5 pages read",442 "imported github.com/sindresorhus/awesome (Markdown list, main): main at aaaaaaaaaaaa, 2 heads, 0 tags",443 " warmed github.com/sindresorhus/awesome: 5 of 5 pages read",444 "imported github.com/changesets/changesets (TypeScript monorepo, main): main at aaaaaaaaaaaa, 2 heads, 0 tags",445 " warmed github.com/changesets/changesets: 5 of 5 pages read",446 "imported codeberg.org/dnkl/fuzzel (C on Codeberg, master): main at aaaaaaaaaaaa, 2 heads, 0 tags",447 " warmed codeberg.org/dnkl/fuzzel: 4 of 5 pages read; /codeberg.org/dnkl/fuzzel/why/main/README.md: no answer",Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 448–450why, one step back448 "imported 4 of 4, each recorded in infra/created.jsonl as a kept import",449 ],450 result: true,Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 451why, one step back451 skipped: 34,Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 452–455why, one step back452 });453 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))454 );455Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 456–473why, one step back456 it.live(457 "--warm warms every example the platform lists already, and imports nothing it lists",458 () =>459 Effect.gen(function* () {460 const platform = yield* fakePlatform(["ky", "gum"]);461462 const { printed } = yield* ran(463 onDev("--only", "ky", "--warm"),464 platform.layer465 );466467 expect({468 calls: yield* platform.calls,469 printed,470 }).toStrictEqual({471 calls: ["listProjects", "warm ky"],472 printed: [473 "import-examples on dev-oscabriel (https://platform.test): 0 to import, 1 listed already",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 474–475why, one step back474 " skip github.com/sindresorhus/ky: listed already",475 " warmed github.com/sindresorhus/ky: 5 of 5 pages read",Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
lines 476–481why, one step back476 "imported 0 of 0, each recorded in infra/created.jsonl as a kept import",477 ],478 });479 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))480 );481Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 482–495why, one step back482 it.live("--dry-run prints the plan and imports and records nothing", () =>483 Effect.gen(function* () {484 const platform = yield* fakePlatform(["ky"]);485486 const { ledger, printed } = yield* ran(487 onDev("--dry-run", "--only", "anyhow"),488 platform.layer489 );490491 expect({ calls: yield* platform.calls, ledger, printed }).toStrictEqual({492 calls: ["listProjects"],493 ledger: [],494 printed: [495 "import-examples on dev-oscabriel (https://platform.test): 1 to import, 0 listed already",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 496why, one step back496 " would import github.com/dtolnay/anyhow from https://github.com/dtolnay/anyhow (master)",Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 497–523why, one step back497 "dry run: nothing imported, nothing recorded",498 ],499 });500 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))501 );502503 it.live(504 "--tags backfills an import that came with no tags, and the ledger says so",505 () =>506 Effect.gen(function* () {507 const platform = yield* fakePlatform([]);508509 const { ledger, printed } = yield* ran(510 onDev("--only", "anyhow", "--tags"),511 platform.layer512 );513514 expect({515 calls: yield* platform.calls,516 ledger: ledger.map(({ kind, name, note }) => [kind, name, note]),517 printed: printed.filter((line) => line.includes("tags")),518 }).toStrictEqual({519 calls: [520 "listProjects",521 "init anyhow master",522 "ls-remote anyhow",523 "tags anyhow",Merge build/1314-import-list into mainoscabrielbefore adoption33c4cac
line 524why, one step back524 "warm anyhow",Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 525–531why, one step back525 ],526 ledger: [527 ["project", "anyhow", undefined],528 ["repo", "anyhow", undefined],529 ["repo", "anyhow", "tags backfilled"],530 ],531 printed: [Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 532–533why, one step back532 "imported github.com/dtolnay/anyhow (Rust crate, master): main at aaaaaaaaaaaa, 2 heads, 0 tags",533 " github.com/dtolnay/anyhow: 105 tags backfilled from https://github.com/dtolnay/anyhow",Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 534–545why, one step back534 ],535 });536 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))537 );538539 it.live(540 "--tags backfills an earlier import the ledger records, and never a listed project it doesn't",541 () =>542 Effect.gen(function* () {543 const fs = yield* FileSystem.FileSystem;544 const path = yield* Path.Path;545Close the code browser and drafting wave: its decisions in two ADRs, every rule it added held, and its leftovers folded inoscabrielbefore adoption009640c
line 546why, one step back546 const dir = yield* fs.makeTempDirectoryScoped({ prefix: "importing-" });Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 547–568why, one step back547548 const ledgerFile = path.join(dir, "created.jsonl");549 const platform = yield* fakePlatform(["anyhow", "ky"]);550551 yield* fs.writeFileString(552 ledgerFile,553 `${JSON.stringify({ at: "2026-10-08T20:00:00.000Z", by: "import", kind: "project", name: "anyhow", stage: "dev-oscabriel" })}\n`554 );555556 yield* importExamples(onDev("--tags"), () => platform.layer).pipe(557 Effect.provideService(LedgerFile, ledgerFile),558 Effect.provideService(Console.Console, {559 ...console,560 log: () => {},561 })562 );563564 expect(565 (yield* platform.calls).filter((call) => /ky|anyhow/u.test(call))566 ).toStrictEqual(["ls-remote anyhow", "tags anyhow"]);567 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))568 );Merge build/imported-from into mainoscabrielbefore adoptionf224a14
lines 569–624why, one step back569570 it.live(571 "--sources asks initProject again for each import the ledger records, listed or not, and never for a listed project it doesn't",572 () =>573 Effect.gen(function* () {574 const fs = yield* FileSystem.FileSystem;575 const path = yield* Path.Path;576577 const dir = yield* fs.makeTempDirectoryScoped({ prefix: "importing-" });578579 const ledgerFile = path.join(dir, "created.jsonl");580581 const platform = yield* fakePlatform(["anyhow", "ky"]);582583 yield* fs.writeFileString(584 ledgerFile,585 ["anyhow", "gum"]586 .map(587 (name) =>588 `${JSON.stringify({ at: "2026-10-08T20:00:00.000Z", by: "import", kind: "project", name, stage: "dev-oscabriel" })}\n`589 )590 .join("")591 );592593 const printed: string[] = [];594595 yield* importExamples(596 onDev("--only", "gum", "--sources"),597 () => platform.layer598 ).pipe(599 Effect.provideService(LedgerFile, ledgerFile),600 Effect.provideService(Console.Console, {601 ...console,602 log: (...args: readonly unknown[]) => {603 printed.push(args.map(String).join(" "));604 },605 })606 );607608 yield* importExamples(onDev("--sources"), () => platform.layer).pipe(609 Effect.provideService(LedgerFile, ledgerFile),610 Effect.provideService(Console.Console, {611 ...console,612 log: () => {},613 })614 );615616 expect(617 (yield* platform.calls).filter((call) => /gum|anyhow|ky/u.test(call))618 ).toStrictEqual([619 "init gum main",620 "init anyhow master",621 "init gum main",622 ]);623 expect(printed).toStrictEqual([624 "import-examples on dev-oscabriel (https://platform.test): 0 to import, 1 listed already",Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 625–626why, one step back625 " skip github.com/charmbracelet/gum: imported already, as the ledger records",626 " github.com/charmbracelet/gum: source kept: https://github.com/charmbracelet/gum (main)",Merge build/imported-from into mainoscabrielbefore adoptionf224a14
lines 627–667why, one step back627 "imported 0 of 0, each recorded in infra/created.jsonl as a kept import",628 ]);629 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))630 );631632 it.live(633 "--sources --dry-run prints each source it would keep, and keeps none",634 () =>635 Effect.gen(function* () {636 const platform = yield* fakePlatform(["anyhow"]);637638 const { ledger, printed } = yield* ran(639 onDev("--only", "anyhow", "--sources", "--dry-run"),640 platform.layer641 );642643 expect({644 calls: yield* platform.calls,645 ledger,646 printed: printed.filter((line) => line.includes("source")),647 }).toStrictEqual({648 calls: ["listProjects"],649 ledger: [],650 printed: [],651 });652 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))653 );654655 it.live(656 "--sources in the Node world goes over every example listed, with no ledger",657 () =>658 Effect.gen(function* () {659 const platform = yield* fakePlatform(["anyhow", "ky"]);660661 const { printed } = yield* ran(662 ["--world", "node", "--sources", "--dry-run"],663 platform.layer664 );665666 expect(printed.filter((line) => line.includes("source"))).toStrictEqual(667 [Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 668–669why, one step back668 " would keep the source of github.com/dtolnay/anyhow: https://github.com/dtolnay/anyhow (master)",669 " would keep the source of github.com/sindresorhus/ky: https://github.com/sindresorhus/ky (main)",Merge build/imported-from into mainoscabrielbefore adoptionf224a14
lines 670–673why, one step back670 ]671 );672 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))673 );Merge branch 'build/913-import-any-branch-and-examples'oscabrielbefore adoptiona4543f6
lines 674–744why, one step back674});675676class NoAnswer extends Data.TaggedError("NoAnswer")<{677 readonly after: string;678}> {}679680const askedAgain = (681 answers: readonly Effect.Effect<682 { readonly landed?: string },683 NoAnswer | ProjectExists684 >[]685) =>686 Effect.gen(function* () {687 const made = yield* Ref.make(0);688689 const call = Effect.flatMap(690 Ref.getAndUpdate(made, (count) => count + 1),691 (count) => answers[count] ?? Effect.die("asked once too often")692 );693694 const fiber = yield* Effect.forkChild(695 initUntilAnswered(call, (error) => !(error instanceof NoAnswer))696 );697698 yield* TestClock.adjust(Duration.minutes(2));699700 return { calls: yield* Ref.get(made), ended: yield* Fiber.await(fiber) };701 });702703describe("an import's initProject, asked again", () => {704 const anyhow = project("anyhow");705706 it.effect(707 "takes ProjectExists after a call that got no answer as that call's project, made",708 () =>709 Effect.gen(function* () {710 expect(711 yield* askedAgain([712 Effect.fail(new NoAnswer({ after: "100 s" })),713 Effect.fail(new ProjectExists({ project: anyhow })),714 ])715 ).toStrictEqual({ calls: 2, ended: Exit.succeed({}) });716 })717 );718719 it.effect(720 "answers ProjectExists on the first call, and asks nothing again",721 () =>722 Effect.gen(function* () {723 expect(724 yield* askedAgain([725 Effect.fail(new ProjectExists({ project: anyhow })),726 ])727 ).toStrictEqual({728 calls: 1,729 ended: Exit.fail(new ProjectExists({ project: anyhow })),730 });731 })732 );733734 it.effect("gives up after three more calls with no answer", () =>735 Effect.gen(function* () {736 const lost = Effect.fail(new NoAnswer({ after: "100 s" }));737738 expect(yield* askedAgain([lost, lost, lost, lost])).toStrictEqual({739 calls: 4,740 ended: Exit.fail(new NoAnswer({ after: "100 s" })),741 });742 })743 );744});