Skip to content
Myr

Merge build/1314-import-list into main

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by oscabriel · committed by oscabriel · parents 0e29c37, b3c5f2d · Browse files · 8 files+1037 added−116 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+1037 added−116 removed

  • tests:+207 added−48 removed
  • other:+830 added−68 removed

8 files+1037 added−116 removed

modified:apps/web/e2e/imports.e2e.ts+115 added-9 removed
7 unmodified lines
8 * exercise: ky's lowercase `readme.md` and its SVG logo through raw,9 * awesome's relative links, changesets' deep tree and scoped tags, stb's10 * 730 KB header and a PNG, fuzzel's submodule, click's second log page and11 * anyhow's annotated tags. The first view of `tree`, `why` and12 * `commits?path=` on changesets and click is timed and printed.12 * `commits?path=` on changesets and click is timed and printed. The thirty13 * well-known imports after them each show their home with its README, the14 * root folder, a file at line 5, the log, and why that file's lines are15 * there.16 *17 * It runs only against `WEB_URL` (a dev stage's web origin) and is skipped18 * without it. `WEB_IMPORTS` narrows it to some projects (a comma list),19 * for a run while the imports go in one at a time. It only reads.
90 unmodified lines
110 readme: "Fuzzel is a Wayland-native application launcher",111 },112];113114/** One of the well-known imports: a file at its root of at least five lines, and its README's name. */115interface Known {116 readonly project: string;117 readonly file: string;118 readonly readme: string;119}120121/** The thirty well-known imports, in the order the script imports them. */122const known: readonly Known[] = [123 { file: "package.json", project: "hono", readme: "README.md" },124 { file: "package.json", project: "express", readme: "Readme.md" },125 { file: "package.json", project: "fastify", readme: "README.md" },126 { file: "package.json", project: "zustand", readme: "README.md" },127 { file: "package.json", project: "immer", readme: "readme.md" },128 { file: "package.json", project: "nanoid", readme: "README.md" },129 { file: "package.json", project: "commander", readme: "Readme.md" },130 { file: "package.json", project: "execa", readme: "readme.md" },131 { file: "package.json", project: "chalk", readme: "readme.md" },132 { file: "package.json", project: "mitt", readme: "README.md" },133 { file: "package.json", project: "clsx", readme: "readme.md" },134 { file: "Cargo.toml", project: "ripgrep", readme: "README.md" },135 { file: "Cargo.toml", project: "serde", readme: "README.md" },136 { file: "Cargo.toml", project: "axum", readme: "README.md" },137 { file: "Cargo.toml", project: "fd", readme: "README.md" },138 { file: "Cargo.toml", project: "hyperfine", readme: "README.md" },139 { file: "go.mod", project: "bubbletea", readme: "README.md" },140 { file: "go.mod", project: "fzf", readme: "README.md" },141 { file: "go.mod", project: "cobra", readme: "README.md" },142 { file: "go.mod", project: "gin", readme: "README.md" },143 { file: "pyproject.toml", project: "requests", readme: "README.md" },144 { file: "pyproject.toml", project: "flask", readme: "README.md" },145 { file: "pyproject.toml", project: "httpx", readme: "README.md" },146 { file: "pyproject.toml", project: "typer", readme: "README.md" },147 { file: "pyproject.toml", project: "jinja", readme: "README.md" },148 { file: "lua.c", project: "lua", readme: "README.md" },149 { file: "Makefile.am", project: "jq", readme: "README.md" },150 { file: "Makefile", project: "kilo", readme: "README.md" },151 { file: "Gemfile", project: "sinatra", readme: "README.md" },152 { file: "package.json", project: "nvm", readme: "README.md" },153];154155/** What the check reads of its env: where the web lives, and which imports to visit. */156const settings = Effect.runSync(157 Effect.gen(function* () {158 return {
5 unmodified lines
164 };165 })166);167168/** Those of `all` this run visits: `WEB_IMPORTS`' names, or all of them. */169const visitedOf = <A extends { readonly project: string }>(170 all: readonly A[]124/** The imports this run visits: `WEB_IMPORTS`' names, or all eight. */125const visited = Option.match(settings.only, {126 onNone: () => imports,127 onSome: (names) => {128 const named = new Set(names.split(",").map((name) => name.trim()));171): readonly A[] =>172 Option.match(settings.only, {173 onNone: () => all,174 onSome: (names) => {175 const named = new Set(names.split(",").map((name) => name.trim()));176130 return imports.filter(({ project }) => named.has(project));131 },132});177 return all.filter(({ project }) => named.has(project));178 },179 });180181const visited = visitedOf(imports);182183/** Where screenshots go: `e2e/out/imports/<project>/<shot>.png`. */184const out = decodeURIComponent(185 new URL("out/imports/", import.meta.url).pathname186);
268 unmodified lines
455 ));456 }457};458459/** The pages each well-known import shows. */460const knownPages = ({ file, project, readme }: Known) => {461 test(`${project}'s home renders its ${readme}`, ({ page: browser }) =>462 Effect.runPromise(463 visit(browser, project, `/${project}`, "home", {464 selectors: ["[data-clone]", "[data-readme]"],465 texts: [readme],466 })467 ));468469 test(`${project}'s root lists ${file}`, ({ page: browser }) =>470 Effect.runPromise(471 visit(browser, project, `/${project}/tree/main`, "tree", {472 selectors: [`[data-entry="${file}"]`],473 })474 ));475476 test(`${project}'s ${file} opens at line 5`, ({ page: browser }) =>477 Effect.runPromise(478 Effect.gen(function* () {479 yield* visit(480 browser,481 project,482 `/${project}/blob/main/${file}#L5`,483 "blob",484 {485 selectors: ['[data-toolbar="file"]'],486 }487 );488489 expect(new URL(browser.url()).hash).toBe("#L5");490 })491 ));492493 test(`${project}'s log groups its commits by day`, ({ page: browser }) =>494 Effect.runPromise(495 visit(browser, project, `/${project}/commits/main`, "commits", {496 selectors: [`a[href^="/${project}/commit/"]`, "[data-day]"],497 })498 ));499500 test(`${project}'s ${file} says why each line is there`, ({501 page: browser,502 }) =>503 Effect.runPromise(504 visit(browser, project, `/${project}/why/main/${file}`, "why", {505 selectors: ["[data-range]"],506 })507 ));508};509510/** What each repo was picked to exercise. */511const specifics = new Map<string, (browser: Page) => Effect.Effect<void>>([512 [513 "anyhow",
191 unmodified lines
705 }) => Effect.runPromise(specific(browser)));706 }707 });708 }709710 for (const imported of visitedOf(known)) {711 test.describe(imported.project, () => {712 knownPages(imported);713 });714 }715});
added:packages/agent-kit/src/docs/imported.ts+245 added
1/**2 * The open-source projects imported onto the platform for reading, each a3 * copy of a public repo under its own licence, read-only here and not run4 * by its maintainers. A copy of the import script's plan, which a test in5 * `packages/config` holds equal to it, so the docs can name each one's6 * source and licence.7 */8import { ProjectName } from "@repo/protocol/ids";910/** One imported project: its name here, its source, its licence, and what it is. */11export interface ImportedProject {12 readonly project: ProjectName;13 readonly url: string;14 readonly licence: string;15 readonly kind: string;16}1718const imported = (19 project: string,20 url: string,21 licence: string,22 kind: string23): ImportedProject => ({24 kind,25 licence,26 project: ProjectName.make(project),27 url,28});2930/** Every imported project, in the order they were imported. */31export const importedProjects: readonly ImportedProject[] = [32 imported(33 "anyhow",34 "https://github.com/dtolnay/anyhow",35 "MIT OR Apache-2.0",36 "Rust crate"37 ),38 imported(39 "ky",40 "https://github.com/sindresorhus/ky",41 "MIT",42 "TypeScript library"43 ),44 imported("gum", "https://github.com/charmbracelet/gum", "MIT", "Go CLI"),45 imported(46 "click",47 "https://github.com/pallets/click",48 "BSD-3-Clause",49 "Python package"50 ),51 imported(52 "awesome",53 "https://github.com/sindresorhus/awesome",54 "CC0-1.0",55 "Markdown list"56 ),57 imported(58 "changesets",59 "https://github.com/changesets/changesets",60 "MIT",61 "TypeScript monorepo"62 ),63 imported(64 "stb",65 "https://github.com/nothings/stb",66 "MIT OR Unlicense",67 "C single-file headers"68 ),69 imported(70 "fuzzel",71 "https://codeberg.org/dnkl/fuzzel",72 "MIT",73 "C on Codeberg"74 ),75 imported(76 "hono",77 "https://github.com/honojs/hono",78 "MIT",79 "TypeScript web framework"80 ),81 imported(82 "express",83 "https://github.com/expressjs/express",84 "MIT",85 "JavaScript web framework"86 ),87 imported(88 "fastify",89 "https://github.com/fastify/fastify",90 "MIT",91 "JavaScript web framework"92 ),93 imported(94 "zustand",95 "https://github.com/pmndrs/zustand",96 "MIT",97 "TypeScript state library"98 ),99 imported(100 "immer",101 "https://github.com/immerjs/immer",102 "MIT",103 "JavaScript immutable state"104 ),105 imported(106 "nanoid",107 "https://github.com/ai/nanoid",108 "MIT",109 "JavaScript ID generator"110 ),111 imported(112 "commander",113 "https://github.com/tj/commander.js",114 "MIT",115 "JavaScript CLI parser"116 ),117 imported(118 "execa",119 "https://github.com/sindresorhus/execa",120 "MIT",121 "JavaScript process runner"122 ),123 imported(124 "chalk",125 "https://github.com/chalk/chalk",126 "MIT",127 "JavaScript terminal colours"128 ),129 imported(130 "mitt",131 "https://github.com/developit/mitt",132 "MIT",133 "TypeScript event emitter"134 ),135 imported(136 "clsx",137 "https://github.com/lukeed/clsx",138 "MIT",139 "JavaScript class names"140 ),141 imported(142 "ripgrep",143 "https://github.com/BurntSushi/ripgrep",144 "Unlicense OR MIT",145 "Rust CLI"146 ),147 imported(148 "serde",149 "https://github.com/serde-rs/serde",150 "MIT OR Apache-2.0",151 "Rust serialization"152 ),153 imported(154 "axum",155 "https://github.com/tokio-rs/axum",156 "MIT",157 "Rust web framework"158 ),159 imported(160 "fd",161 "https://github.com/sharkdp/fd",162 "MIT OR Apache-2.0",163 "Rust CLI"164 ),165 imported(166 "hyperfine",167 "https://github.com/sharkdp/hyperfine",168 "MIT OR Apache-2.0",169 "Rust benchmarking CLI"170 ),171 imported(172 "bubbletea",173 "https://github.com/charmbracelet/bubbletea",174 "MIT",175 "Go TUI framework"176 ),177 imported("fzf", "https://github.com/junegunn/fzf", "MIT", "Go fuzzy finder"),178 imported(179 "cobra",180 "https://github.com/spf13/cobra",181 "Apache-2.0",182 "Go CLI library"183 ),184 imported(185 "gin",186 "https://github.com/gin-gonic/gin",187 "MIT",188 "Go web framework"189 ),190 imported(191 "requests",192 "https://github.com/psf/requests",193 "Apache-2.0",194 "Python HTTP library"195 ),196 imported(197 "flask",198 "https://github.com/pallets/flask",199 "BSD-3-Clause",200 "Python web framework"201 ),202 imported(203 "httpx",204 "https://github.com/encode/httpx",205 "BSD-3-Clause",206 "Python HTTP client"207 ),208 imported(209 "typer",210 "https://github.com/fastapi/typer",211 "MIT",212 "Python CLI library"213 ),214 imported(215 "jinja",216 "https://github.com/pallets/jinja",217 "BSD-3-Clause",218 "Python templates"219 ),220 imported(221 "lua",222 "https://github.com/lua/lua",223 "MIT",224 "C language interpreter"225 ),226 imported("jq", "https://github.com/jqlang/jq", "MIT", "C JSON processor"),227 imported(228 "kilo",229 "https://github.com/antirez/kilo",230 "BSD-2-Clause",231 "C text editor"232 ),233 imported(234 "sinatra",235 "https://github.com/sinatra/sinatra",236 "MIT",237 "Ruby web framework"238 ),239 imported(240 "nvm",241 "https://github.com/nvm-sh/nvm",242 "MIT",243 "Shell version manager"244 ),245];
modified:packages/config/test/import-examples.test.ts+185 added-48 removed
20 unmodified lines
21 Redacted,22 Exit,23 Ref,24 Result,25 Schema,26} from "effect";27import { TestClock } from "effect/testing";2829import { LedgerFile, readLedger } from "../../../infra/created.ts";
1 unmodified line
31 examples,32 planImports,33 shownCommand,34 tagBackfillCommands,35 warmPaths,36} from "../../../scripts/lib/import/plan.ts";37import type { ImportExample } from "../../../scripts/lib/import/plan.ts";38import {39 ImportExamplesFailed,40 importExamples,41 ImportTarget,42 initUntilAnswered,43 TagBackfill,44 Warmer,45} from "../../../scripts/lib/import/run.ts";46import { ProjectName } from "../../protocol/src/ids.ts";4748const project = (name: string) => ProjectName.make(name);
1 unmodified line
50const names = (planned: readonly ImportExample[]) =>51 planned.map(({ project: name }) => name);5253describe("the import plan", () => {51 it("holds the eight repos of the preview, anyhow first, each master repo on its branch", () => {54 it("holds the eight repos of the preview first, then thirty well-known ones, each on its branch with its licence", () => {55 expect(53 examples.map(({ branch, project: name, url }) => [name, branch, url])56 examples.map(({ branch, licence, project: name, url }) => [57 name,58 branch,59 url,60 licence,61 ])62 ).toStrictEqual([63 [64 "anyhow",65 "master",66 "https://github.com/dtolnay/anyhow",67 "MIT OR Apache-2.0",55 ["anyhow", "master", "https://github.com/dtolnay/anyhow"],56 ["ky", "main", "https://github.com/sindresorhus/ky"],57 ["gum", "main", "https://github.com/charmbracelet/gum"],58 ["click", "main", "https://github.com/pallets/click"],59 ["awesome", "main", "https://github.com/sindresorhus/awesome"],60 ["changesets", "main", "https://github.com/changesets/changesets"],61 ["stb", "master", "https://github.com/nothings/stb"],62 ["fuzzel", "master", "https://codeberg.org/dnkl/fuzzel"],68 ],69 ["ky", "main", "https://github.com/sindresorhus/ky", "MIT"],70 ["gum", "main", "https://github.com/charmbracelet/gum", "MIT"],71 ["click", "main", "https://github.com/pallets/click", "BSD-3-Clause"],72 ["awesome", "main", "https://github.com/sindresorhus/awesome", "CC0-1.0"],73 ["changesets", "main", "https://github.com/changesets/changesets", "MIT"],74 ["stb", "master", "https://github.com/nothings/stb", "MIT OR Unlicense"],75 ["fuzzel", "master", "https://codeberg.org/dnkl/fuzzel", "MIT"],76 ["hono", "main", "https://github.com/honojs/hono", "MIT"],77 ["express", "master", "https://github.com/expressjs/express", "MIT"],78 ["fastify", "main", "https://github.com/fastify/fastify", "MIT"],79 ["zustand", "main", "https://github.com/pmndrs/zustand", "MIT"],80 ["immer", "main", "https://github.com/immerjs/immer", "MIT"],81 ["nanoid", "main", "https://github.com/ai/nanoid", "MIT"],82 ["commander", "master", "https://github.com/tj/commander.js", "MIT"],83 ["execa", "main", "https://github.com/sindresorhus/execa", "MIT"],84 ["chalk", "main", "https://github.com/chalk/chalk", "MIT"],85 ["mitt", "main", "https://github.com/developit/mitt", "MIT"],86 ["clsx", "master", "https://github.com/lukeed/clsx", "MIT"],87 [88 "ripgrep",89 "master",90 "https://github.com/BurntSushi/ripgrep",91 "Unlicense OR MIT",92 ],93 [94 "serde",95 "master",96 "https://github.com/serde-rs/serde",97 "MIT OR Apache-2.0",98 ],99 ["axum", "main", "https://github.com/tokio-rs/axum", "MIT"],100 ["fd", "master", "https://github.com/sharkdp/fd", "MIT OR Apache-2.0"],101 [102 "hyperfine",103 "master",104 "https://github.com/sharkdp/hyperfine",105 "MIT OR Apache-2.0",106 ],107 [108 "bubbletea",109 "main",110 "https://github.com/charmbracelet/bubbletea",111 "MIT",112 ],113 ["fzf", "master", "https://github.com/junegunn/fzf", "MIT"],114 ["cobra", "main", "https://github.com/spf13/cobra", "Apache-2.0"],115 ["gin", "master", "https://github.com/gin-gonic/gin", "MIT"],116 ["requests", "main", "https://github.com/psf/requests", "Apache-2.0"],117 ["flask", "main", "https://github.com/pallets/flask", "BSD-3-Clause"],118 ["httpx", "master", "https://github.com/encode/httpx", "BSD-3-Clause"],119 ["typer", "master", "https://github.com/fastapi/typer", "MIT"],120 ["jinja", "main", "https://github.com/pallets/jinja", "BSD-3-Clause"],121 ["lua", "master", "https://github.com/lua/lua", "MIT"],122 ["jq", "master", "https://github.com/jqlang/jq", "MIT"],123 ["kilo", "master", "https://github.com/antirez/kilo", "BSD-2-Clause"],124 ["sinatra", "main", "https://github.com/sinatra/sinatra", "MIT"],125 ["nvm", "master", "https://github.com/nvm-sh/nvm", "MIT"],126 ]);127 });128129 it("names each project once, as a name the platform takes", () => {130 const all = names(examples);131132 expect(new Set(all).size).toBe(all.length);133 expect(all.filter((name) => !Schema.is(ProjectName)(name))).toStrictEqual(134 []135 );136 });137138 it("skips a project the platform lists already, and keeps only the one --only names", () => {139 expect({140 all: names(141 planImports(
12 unmodified lines
154 only: names(155 planImports(examples, new Set(), Option.some(project("gum")))156 ),157 }).toStrictEqual({86 all: ["anyhow", "gum", "click", "awesome", "changesets", "fuzzel"],158 all: names(examples).filter((name) => name !== "ky" && name !== "stb"),159 listed: [],160 only: ["gum"],161 });162 });163});164165describe("the warm plan", () => {166 it("reads a project's home, its tree, its landings, and its README and why the README is there", () => {167 expect(warmPaths(project("ky"), Option.some("readme.md"))).toStrictEqual([168 "/ky",169 "/ky/tree/main",170 "/ky/commits/main",171 "/ky/blob/main/readme.md",172 "/ky/why/main/readme.md",173 ]);174 });175176 it("reads no README when the project has none", () => {177 expect(warmPaths(project("awesome"), Option.none())).toStrictEqual([178 "/awesome",179 "/awesome/tree/main",180 "/awesome/commits/main",181 ]);182 });183});184185describe("the tag backfill's commands", () => {186 const token = Redacted.make("artifacts-write-token-0123456789abcdef");187188 const commands = tagBackfillCommands({
84 unmodified lines
273 backfill: (example) =>274 note(`tags ${example.project}`).pipe(Effect.as(105)),275 });276277 // Every read answers but fuzzel's why, which the web never answered.278 const warmer = Warmer.of({279 warm: (name) =>280 note(`warm ${name}`).pipe(281 Effect.as(282 warmPaths(name, Option.some("README.md")).map((path) =>283 name === "fuzzel" && path.includes("/why/")284 ? { ok: false, path, said: "no answer" }285 : { ok: true, path, said: "200" }286 )287 )288 ),289 });290291 return {292 calls: Ref.get(calls),293 layer: Layer.mergeAll(294 Layer.succeed(ImportTarget, target),189 Layer.succeed(TagBackfill, backfill)295 Layer.succeed(TagBackfill, backfill),296 Layer.succeed(Warmer, warmer)297 ),298 };299 });300301/** `importExamples(argv)` over `layer`, with the ledger in a temp folder: how it ended, and what it printed. */302const ran = (303 argv: readonly string[],197 layer: Layer.Layer<ImportTarget | TagBackfill>304 layer: Layer.Layer<ImportTarget | TagBackfill | Warmer>305) =>306 Effect.gen(function* () {307 const fs = yield* FileSystem.FileSystem;308 const path = yield* Path.Path;
40 unmodified lines
349 built += 1;350351 return Layer.mergeAll(352 Layer.effect(ImportTarget, Effect.die("a target was built")),246 Layer.effect(TagBackfill, Effect.die("a backfill was built"))353 Layer.effect(TagBackfill, Effect.die("a backfill was built")),354 Layer.effect(Warmer, Effect.die("a warmer was built"))355 );356 }).pipe(Effect.result);357358 expect({ built, result }).toStrictEqual({
8 unmodified lines
367 }).pipe(Effect.provide(NodeServices.layer))368 );369370 it.live(263 "imports each project the platform doesn't list, one at a time, with its counts, and records each in the ledger as a kept import",371 "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",372 () =>373 Effect.gen(function* () {266 const platform = yield* fakePlatform(["ky", "stb", "click", "gum"]);374 const fresh = ["anyhow", "awesome", "changesets", "fuzzel"];375376 const platform = yield* fakePlatform(377 names(examples).filter((name) => !fresh.includes(name))378 );379380 const { ledger, printed, result } = yield* ran(onDev(), platform.layer);381382 expect({383 calls: yield* platform.calls,
3 unmodified lines
387 name,388 namespace,389 stage,390 })),278 printed,391 printed: printed.filter((line) => !line.startsWith(" skip ")),392 result: Result.isSuccess(result),393 skipped: printed.filter((line) => line.startsWith(" skip ")).length,394 }).toStrictEqual({395 calls: [396 "listProjects",283 "init anyhow master",284 "ls-remote anyhow",285 "init awesome main",286 "ls-remote awesome",287 "init changesets main",288 "ls-remote changesets",289 "init fuzzel master",290 "ls-remote fuzzel",397 ...fresh.flatMap((name) => [398 `init ${name} ${name === "anyhow" || name === "fuzzel" ? "master" : "main"}`,399 `ls-remote ${name}`,400 `warm ${name}`,401 ]),402 ],292 ledger: ["anyhow", "awesome", "changesets", "fuzzel"].flatMap(293 (name) => [294 {295 by: "import",296 kind: "project",297 name,298 namespace: undefined,299 stage: "dev-oscabriel",300 },301 {302 by: "import",303 kind: "repo",304 name,305 namespace: "projects-dev-oscabriel",306 stage: "dev-oscabriel",307 },308 ]403 ledger: fresh.flatMap((name) => [404 {405 by: "import",406 kind: "project",407 name,408 namespace: undefined,409 stage: "dev-oscabriel",410 },411 {412 by: "import",413 kind: "repo",414 name,415 namespace: "projects-dev-oscabriel",416 stage: "dev-oscabriel",417 },418 ]),309 ),419 printed: [311 "import-examples on dev-oscabriel (https://platform.test): 4 to import, 4 listed already",312 " skip ky: listed already",313 " skip gum: listed already",314 " skip click: listed already",315 " skip stb: listed already",420 "import-examples on dev-oscabriel (https://platform.test): 4 to import, 34 listed already",421 "imported anyhow (Rust crate, master): main at aaaaaaaaaaaa, 2 heads, 0 tags",422 " warmed anyhow: 5 of 5 pages read",423 "imported awesome (Markdown list, main): main at aaaaaaaaaaaa, 2 heads, 0 tags",424 " warmed awesome: 5 of 5 pages read",425 "imported changesets (TypeScript monorepo, main): main at aaaaaaaaaaaa, 2 heads, 0 tags",426 " warmed changesets: 5 of 5 pages read",427 "imported fuzzel (C on Codeberg, master): main at aaaaaaaaaaaa, 2 heads, 0 tags",428 " warmed fuzzel: 4 of 5 pages read; /fuzzel/why/main/README.md: no answer",429 "imported 4 of 4, each recorded in infra/created.jsonl as a kept import",430 ],431 result: true,432 skipped: 34,433 });434 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))435 );436437 it.live(438 "--warm warms every example the platform lists already, and imports nothing it lists",439 () =>440 Effect.gen(function* () {441 const platform = yield* fakePlatform(["ky", "gum"]);442443 const { printed } = yield* ran(444 onDev("--only", "ky", "--warm"),445 platform.layer446 );447448 expect({449 calls: yield* platform.calls,450 printed,451 }).toStrictEqual({452 calls: ["listProjects", "warm ky"],453 printed: [454 "import-examples on dev-oscabriel (https://platform.test): 0 to import, 1 listed already",455 " skip ky: listed already",456 " warmed ky: 5 of 5 pages read",457 "imported 0 of 0, each recorded in infra/created.jsonl as a kept import",458 ],459 });460 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))461 );462463 it.live("--dry-run prints the plan and imports and records nothing", () =>464 Effect.gen(function* () {465 const platform = yield* fakePlatform(["ky"]);466
34 unmodified lines
501 "listProjects",502 "init anyhow master",503 "ls-remote anyhow",504 "tags anyhow",505 "warm anyhow",506 ],507 ledger: [508 ["project", "anyhow", undefined],509 ["repo", "anyhow", undefined],
117 unmodified lines
added:packages/config/test/imported-docs.test.ts+22 added
modified:scripts/lib/import/live.ts+110 added-25 removed
1/**2 * The import run's real target and backfill: a platform over `/rpc` as the3 * operator, git's `ls-remote` anonymously through the gateway, and the tag2 * The import run's real target, backfill and web: a platform over `/rpc` as3 * the operator, git's `ls-remote` anonymously through the gateway, the tag4 * backfill through `@repo/artifacts`' REST adapter with the ops5 * credentials, as `infra/teardown.ts` reaches Artifacts. No token is ever6 * printed: the operator's goes only into the `Authorization` header of7 * `/rpc` calls, and the backfill's write token only into git's env.5 * credentials, as `infra/teardown.ts` reaches Artifacts, and the warm6 * reads through the stage's web, anonymously. No token is ever printed:7 * the operator's goes only into the `Authorization` header of `/rpc`8 * calls, and the backfill's write token only into git's env.9 */10import { Fetch, FetchFailed } from "@repo/artifacts/fetch";11import { RepoHost, RepoName } from "@repo/artifacts/repo-host";12import { RepoHostRest } from "@repo/artifacts/repo-host/rest";
7 unmodified lines
20 Duration,21 Effect,22 FileSystem,23 Layer,24 Option,25 Redacted,26 Schema,27 Stream,28} from "effect";
6 unmodified lines
35 platformOrigin,36 recordedSubdomain,37 resources,38 subdomainFile,39 webOrigin,40} from "../../../infra/stages.ts";41import type { Stage } from "../../../infra/stages.ts";42import { servedWorld, worldOperator } from "../seed.ts";40import { shownCommand, tagBackfillCommands } from "./plan.ts";43import { shownCommand, tagBackfillCommands, warmPaths } from "./plan.ts";44import type { Command } from "./plan.ts";45import {46 ImportExamplesFailed,47 ImportTarget,48 initUntilAnswered,49 TagBackfill,50 Warmer,51} from "./run.ts";52import type { WarmRead } from "./run.ts";5354const failed = (reason: string) => new ImportExamplesFailed({ reason });5556const isRefusal = Schema.is(Refusal);
147 unmodified lines
204 });205 })206 ).pipe(Layer.provide(clientAt(input.origin, input.token)));207208/** How long one warm read may take: a cold why on a long history takes seconds. */209const WARM_READ_TIMEOUT = Duration.seconds(90);210211/** `duration` in seconds, to a tenth. */212const secondsOf = (duration: Duration.Duration) =>213 `${(Duration.toMillis(duration) / 1000).toFixed(1)} s`;214215/**216 * The web at `web`, read anonymously, page by page, each body read to its217 * end so the server finishes what it draws; the README's path asked of the218 * platform at `origin` (`readTree`, a public read).219 */220export const webWarmer = (input: {221 readonly origin: string;222 readonly token: Redacted.Redacted;223 readonly web: string;224}): Layer.Layer<Warmer> =>225 Layer.effect(226 Warmer,227 Effect.gen(function* () {228 const client = yield* Client;229 const http = yield* HttpClient.HttpClient;230231 const read = (path: string): Effect.Effect<WarmRead> =>232 http.get(`${input.web}${path}`).pipe(233 Effect.flatMap((response) =>234 Effect.as(response.text, response.status)235 ),236 Effect.timed,237 Effect.timeout(WARM_READ_TIMEOUT),238 Effect.map(([took, status]) => ({239 ok: status === 200,240 path,241 said: `${status} in ${secondsOf(took)}`,242 })),243 Effect.orElseSucceed(() => ({ ok: false, path, said: "no answer" }))244 );245246 return Warmer.of({247 warm: (project) =>248 client.readTree({ project }).pipe(249 Effect.map(({ readme }) => Option.fromUndefinedOr(readme?.path)),250 Effect.orElseSucceed(() => Option.none<string>()),251 Effect.flatMap((readme) =>252 Effect.forEach(warmPaths(project, readme), read)253 )254 ),255 });256 })257 ).pipe(258 Layer.provide(clientAt(input.origin, input.token)),259 Layer.provide(FetchHttpClient.layer)260 );261262/** No web to warm through: the Node world serves the platform alone. */263export const noWarmer = Layer.succeed(264 Warmer,265 Warmer.of({ warm: () => Effect.succeed([]) })266);267268/**269 * A deployed dev stage at `url`, or at the workers.dev origin bootstrap270 * recorded, as the operator: `OPERATOR_TOKEN` from the env271 * (`bunx varlock run --path apps/platform/ -- …`), never printed.272 */273export const stageTarget = (274 stage: Stage,210 url: string | undefined275 url: string | undefined,276 web: string | undefined277): Layer.Layer<212 ImportTarget,278 ImportTarget | Warmer,279 ImportExamplesFailed,280 ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path281> =>282 Layer.unwrap(
5 unmodified lines
288 )289 )290 );291292 const subdomain = yield* recordedSubdomain.pipe(293 Effect.orElseSucceed(() => Option.none<string>())294 );295296 const origin =297 url ??228 platformOrigin(229 stage,230 yield* recordedSubdomain.pipe(231 Effect.flatMap(Effect.fromOption),232 Effect.mapError(() =>233 failed(234 `no --url, and ${subdomainFile} doesn't record the account's workers.dev subdomain`235 )236 )237 )298 Option.map(subdomain, (sub) => platformOrigin(stage, sub)).pipe(299 Option.getOrUndefined300 );301240 return platformTarget({ label: `${stage} (${origin})`, origin, token });302 if (origin === undefined) {303 return yield* failed(304 `no --url, and ${subdomainFile} doesn't record the account's workers.dev subdomain`305 );306 }307308 // With --url and no --web, the stage's web can't be known: no warming.309 const webAt =310 web ??311 (url === undefined312 ? Option.getOrUndefined(313 Option.map(subdomain, (sub) => webOrigin(stage, sub))314 )315 : undefined);316317 return Layer.mergeAll(318 platformTarget({ label: `${stage} (${origin})`, origin, token }),319 webAt === undefined320 ? noWarmer321 : webWarmer({ origin, token, web: webAt })322 );323 })324 );325326/** The operator's token in the Node world: no secret, never leaves this machine. */
2 unmodified lines
329);330331/** The Node world, served for as long as the layer lasts, with the operator's session. */332export const worldTarget: Layer.Layer<251 ImportTarget,333 ImportTarget | Warmer,334 ImportExamplesFailed,335 ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path336> = Layer.unwrap(337 servedWorld(new Map([[worldOperator, worldToken]])).pipe(338 Effect.mapError(({ reason }) => failed(reason)),339 Effect.map((origin) =>340 Layer.mergeAll(258 platformTarget({259 label: `the Node world (${origin})`,260 origin,261 token: worldToken,262 })341 platformTarget({342 label: `the Node world (${origin})`,343 origin,344 token: worldToken,345 }),346 noWarmer347 )348 )349 )350);351
141 unmodified lines
modified:scripts/lib/import/plan.ts+279 added-18 removed
1/**2 * What `scripts/import-examples.ts` imports, and the commands its `--tags`3 * backfill runs: pure, so a test reads both without a network.2 * What `scripts/import-examples.ts` imports, the pages it reads to warm3 * each import, and the commands its `--tags` backfill runs: pure, so a test4 * reads them without a network.5 *5 * Eight repos, each picked for a shape the code browser must render: a Rust crate with6 * a `master` default and 105 annotated tags first, then a TypeScript7 * library, a Go CLI, a Python package with a long merge history, a8 * Markdown list, a deep monorepo with 740 scoped tags, large single-file C9 * headers, and a repo off GitHub with a submodule.6 * Thirty-eight repos. The first eight were each picked for a shape the7 * code browser must render: a Rust crate with a `master` default and 1058 * annotated tags first, then a TypeScript library, a Go CLI, a Python9 * package with a long merge history, a Markdown list, a deep monorepo with10 * 740 scoped tags, large single-file C headers, and a repo off GitHub with11 * a submodule. The thirty after them are well-known projects in12 * TypeScript, JavaScript, Rust, Go, Python, C, Ruby and shell, so a reader13 * finds code they know; each is a copy, read-only here, under its own14 * licence.15 */16import { ProjectName } from "@repo/protocol/ids";17import { Option, Redacted } from "effect";1814/** One repo to import: the project it becomes, where it is, its branch, and what it exercises. */19/** One repo to import: the project it becomes, where it is, its branch, what it is, and its licence. */20export interface ImportExample {21 readonly project: ProjectName;22 readonly url: string;23 /** The remote's default branch, named so the import never guesses. */24 readonly branch: string;25 /** What kind of repo it is, said for a person. */26 readonly kind: string;27 /** Its licence, as an SPDX expression. */28 readonly licence: string;29}3031const example = (32 project: string,33 url: string,34 branch: string,28 kind: string29): ImportExample => ({ branch, kind, project: ProjectName.make(project), url });35 kind: string,36 licence: string37): ImportExample => ({38 branch,39 kind,40 licence,41 project: ProjectName.make(project),42 url,43});4445/** The repos, in the order they import: anyhow first, the probe for `master` and tags. */46export const examples: readonly ImportExample[] = [47 example(48 "anyhow",49 "https://github.com/dtolnay/anyhow",50 "master",37 "Rust crate"51 "Rust crate",52 "MIT OR Apache-2.0"53 ),54 example(55 "ky",56 "https://github.com/sindresorhus/ky",57 "main",43 "TypeScript library"58 "TypeScript library",59 "MIT"60 ),45 example("gum", "https://github.com/charmbracelet/gum", "main", "Go CLI"),61 example(62 "gum",63 "https://github.com/charmbracelet/gum",64 "main",65 "Go CLI",66 "MIT"67 ),68 example(69 "click",70 "https://github.com/pallets/click",71 "main",50 "Python package"72 "Python package",73 "BSD-3-Clause"74 ),75 example(76 "awesome",77 "https://github.com/sindresorhus/awesome",78 "main",56 "Markdown list"79 "Markdown list",80 "CC0-1.0"81 ),82 example(83 "changesets",84 "https://github.com/changesets/changesets",85 "main",62 "TypeScript monorepo"86 "TypeScript monorepo",87 "MIT"88 ),89 example(90 "stb",91 "https://github.com/nothings/stb",92 "master",68 "C single-file headers"93 "C single-file headers",94 "MIT OR Unlicense"95 ),96 example(97 "fuzzel",98 "https://codeberg.org/dnkl/fuzzel",99 "master",74 "C on Codeberg"100 "C on Codeberg",101 "MIT"102 ),103 // Well known, so a reader meets code they have read before: permissive104 // licences, each under 14 MB on GitHub, as the eight above import well.105 example(106 "hono",107 "https://github.com/honojs/hono",108 "main",109 "TypeScript web framework",110 "MIT"111 ),112 example(113 "express",114 "https://github.com/expressjs/express",115 "master",116 "JavaScript web framework",117 "MIT"118 ),119 example(120 "fastify",121 "https://github.com/fastify/fastify",122 "main",123 "JavaScript web framework",124 "MIT"125 ),126 example(127 "zustand",128 "https://github.com/pmndrs/zustand",129 "main",130 "TypeScript state library",131 "MIT"132 ),133 example(134 "immer",135 "https://github.com/immerjs/immer",136 "main",137 "JavaScript immutable state",138 "MIT"139 ),140 example(141 "nanoid",142 "https://github.com/ai/nanoid",143 "main",144 "JavaScript ID generator",145 "MIT"146 ),147 example(148 "commander",149 "https://github.com/tj/commander.js",150 "master",151 "JavaScript CLI parser",152 "MIT"153 ),154 example(155 "execa",156 "https://github.com/sindresorhus/execa",157 "main",158 "JavaScript process runner",159 "MIT"160 ),161 example(162 "chalk",163 "https://github.com/chalk/chalk",164 "main",165 "JavaScript terminal colours",166 "MIT"167 ),168 example(169 "mitt",170 "https://github.com/developit/mitt",171 "main",172 "TypeScript event emitter",173 "MIT"174 ),175 example(176 "clsx",177 "https://github.com/lukeed/clsx",178 "master",179 "JavaScript class names",180 "MIT"181 ),182 example(183 "ripgrep",184 "https://github.com/BurntSushi/ripgrep",185 "master",186 "Rust CLI",187 "Unlicense OR MIT"188 ),189 example(190 "serde",191 "https://github.com/serde-rs/serde",192 "master",193 "Rust serialization",194 "MIT OR Apache-2.0"195 ),196 example(197 "axum",198 "https://github.com/tokio-rs/axum",199 "main",200 "Rust web framework",201 "MIT"202 ),203 example(204 "fd",205 "https://github.com/sharkdp/fd",206 "master",207 "Rust CLI",208 "MIT OR Apache-2.0"209 ),210 example(211 "hyperfine",212 "https://github.com/sharkdp/hyperfine",213 "master",214 "Rust benchmarking CLI",215 "MIT OR Apache-2.0"216 ),217 example(218 "bubbletea",219 "https://github.com/charmbracelet/bubbletea",220 "main",221 "Go TUI framework",222 "MIT"223 ),224 example(225 "fzf",226 "https://github.com/junegunn/fzf",227 "master",228 "Go fuzzy finder",229 "MIT"230 ),231 example(232 "cobra",233 "https://github.com/spf13/cobra",234 "main",235 "Go CLI library",236 "Apache-2.0"237 ),238 example(239 "gin",240 "https://github.com/gin-gonic/gin",241 "master",242 "Go web framework",243 "MIT"244 ),245 example(246 "requests",247 "https://github.com/psf/requests",248 "main",249 "Python HTTP library",250 "Apache-2.0"251 ),252 example(253 "flask",254 "https://github.com/pallets/flask",255 "main",256 "Python web framework",257 "BSD-3-Clause"258 ),259 example(260 "httpx",261 "https://github.com/encode/httpx",262 "master",263 "Python HTTP client",264 "BSD-3-Clause"265 ),266 example(267 "typer",268 "https://github.com/fastapi/typer",269 "master",270 "Python CLI library",271 "MIT"272 ),273 example(274 "jinja",275 "https://github.com/pallets/jinja",276 "main",277 "Python templates",278 "BSD-3-Clause"279 ),280 example(281 "lua",282 "https://github.com/lua/lua",283 "master",284 "C language interpreter",285 "MIT"286 ),287 example(288 "jq",289 "https://github.com/jqlang/jq",290 "master",291 "C JSON processor",292 "MIT"293 ),294 example(295 "kilo",296 "https://github.com/antirez/kilo",297 "master",298 "C text editor",299 "BSD-2-Clause"300 ),301 example(302 "sinatra",303 "https://github.com/sinatra/sinatra",304 "main",305 "Ruby web framework",306 "MIT"307 ),308 example(309 "nvm",310 "https://github.com/nvm-sh/nvm",311 "master",312 "Shell version manager",313 "MIT"314 ),315];316317/**318 * The imports still to run: `only`'s example when it names one, else every
12 unmodified lines
331 onSome: (named) => named === project,332 }) && !listed.has(project)333 );334335/**336 * The pages read once after an import, so its first reader does not pay337 * for a cold read: its home, its root folder, its landings, and, when it338 * has a README, the README and why each of its lines is there. Why and a339 * file's history are kept by commit once read (ADR 0020).340 */341export const warmPaths = (342 project: ProjectName,343 readme: Option.Option<string>344): readonly string[] => [345 `/${project}`,346 `/${project}/tree/main`,347 `/${project}/commits/main`,348 ...Option.match(readme, {349 onNone: () => [],350 onSome: (path) => [351 `/${project}/blob/main/${path}`,352 `/${project}/why/main/${path}`,353 ],354 }),355];356357/** A git remote and the token that writes to it, kept apart so the URL can be shown. */358export interface RedactedUrl {359 readonly url: string;360 readonly token: Redacted.Redacted;
66 unmodified lines
modified:scripts/lib/import/run.ts+72 added-11 removed
1/**2 * The import run: reads the flags, asks the platform what it lists, imports3 * the rest of the examples one at a time, prints each one's heads and tags,4 * records each new import on a stage in the ledger as kept, and with5 * `--tags` backfills the tags of an import that came without them.4 * records each new import on a stage in the ledger as kept, warms each new5 * import by reading its pages once through the web, with `--tags`6 * backfills the tags of an import that came without them, and with7 * `--warm` warms the examples the platform listed already.8 *7 * The platform and the backfill are services (`ImportTarget`,8 * `TagBackfill`), so a test runs the whole run over fakes; `live.ts` holds9 * the real ones.9 * The platform, the backfill and the web are services (`ImportTarget`,10 * `TagBackfill`, `Warmer`), so a test runs the whole run over fakes;11 * `live.ts` holds the real ones.12 */13import { ProjectName } from "@repo/protocol/ids";14import { ProjectExists } from "@repo/protocol/refusal";15import {
49 unmodified lines
65 /** Print the plan, import and record nothing. */66 readonly dryRun: boolean;67 /** Backfill the tags of an import that has none. */68 readonly tags: boolean;69 /** Warm the examples the platform lists already, as well as each new import. */70 readonly warm: boolean;71 /** The web's origin to warm through, when the stage's own can't be known. */72 readonly web: Option.Option<string>;73}7475/** The platform the imports go to, as the operator. */76export class ImportTarget extends Context.Service<
32 unmodified lines
109 ) => Effect.Effect<number, ImportExamplesFailed>;110 }111>()("scripts/TagBackfill") {}112113/** One page read to warm an import: where, whether it answered, and what it said. */114export interface WarmRead {115 readonly path: string;116 readonly ok: boolean;117 /** Its status and time, or why it failed; said for a person. */118 readonly said: string;119}120121/**122 * Reads an import's pages once through the web, anonymously, so its first123 * reader finds why and its history kept. A read that fails is reported in124 * what it gives back, never as a failure: warming is a courtesy.125 */126export class Warmer extends Context.Service<127 Warmer,128 {129 readonly warm: (project: ProjectName) => Effect.Effect<readonly WarmRead[]>;130 }131>()("scripts/Warmer") {}132133const isProjectExists = Schema.is(ProjectExists);134135/**136 * One import's `initProject`, asked again 30 s apart, up to three more
29 unmodified lines
166 );167 });168169const USAGE =144 "bun scripts/import-examples.ts --world node | --stage <dev-…> [--url <origin>] [--only <project>] [--tags] [--dry-run]";170 "bun scripts/import-examples.ts --world node | --stage <dev-…> [--url <origin>] [--web <origin>] [--only <project>] [--tags] [--warm] [--dry-run]";171172/** The flags the command takes; any other is a typo, refused. */173const FLAGS = new Set([174 "--dry-run",175 "--only",176 "--stage",177 "--tags",178 "--url",179 "--warm",180 "--web",181 "--world",182]);183184const decodeProject = Schema.decodeUnknownOption(ProjectName);
72 unmodified lines
257 }258 ),259 });260233 return { dryRun: argv.includes("--dry-run"), only, tags, where };261 return {262 dryRun: argv.includes("--dry-run"),263 only,264 tags,265 warm: argv.includes("--warm"),266 web: Option.map(flagValue(argv, "--web"), (web) =>267 web.replace(/\/+$/u, "")268 ),269 where,270 };271 });272273/** The ledger's line for an import's repo, in the stage's public namespace. */274const repoLine = (
64 unmodified lines
339 ` ${example.project}: ${pushed} tags backfilled from ${example.url}`340 );341 });342343/** One project warmed, and a line saying how it went. */344const warmOne = (project: ProjectName) =>345 Effect.gen(function* () {346 const reads = yield* Warmer.use((warmer) => warmer.warm(project));347 const failures = reads.filter(({ ok }) => !ok);348349 yield* Console.log(350 Array.isReadonlyArrayNonEmpty(reads)351 ? [352 ` warmed ${project}: ${reads.length - failures.length} of ${reads.length} pages read`,353 ...failures.map(({ path, said }) => `${path}: ${said}`),354 ].join("; ")355 : ` warm ${project}: no web to read through`356 );357 });358306/** The run itself, over a target and a backfill. */359/** The run itself, over a target, a backfill and a web. */360const run = (options: ImportOptions) =>361 Effect.gen(function* () {362 const target = yield* ImportTarget;363 const listed = yield* target.listProjects;
47 unmodified lines
411412 if (options.tags) {413 yield* backfillOne(example, tags, stage);414 }415416 yield* warmOne(example.project);417 }),418 { discard: true }419 );420
25 unmodified lines
446 { discard: true }447 );448 }449450 if (options.warm) {451 yield* Effect.forEach(skipped, ({ project }) => warmOne(project), {452 discard: true,453 });454 }455456 yield* Console.log(457 Option.isSome(stage)458 ? `imported ${plan.length} of ${plan.length}, each recorded in ${ledgerPath} as a kept import`459 : `imported ${plan.length} of ${plan.length} into the Node world (not recorded: the ledger is for stages)`
1 unmodified line
461 });462463/**464 * `bun scripts/import-examples.ts …`: reads the flags (refusing `demo`404 * before anything is built or called), then runs over the target and405 * backfill `layersOf` gives for them.465 * before anything is built or called), then runs over the target, backfill466 * and web `layersOf` gives for them.467 */468export const importExamples = <E, R>(469 argv: readonly string[],470 layersOf: (471 options: ImportOptions411 ) => Layer.Layer<ImportTarget | TagBackfill, E, R>472 ) => Layer.Layer<ImportTarget | TagBackfill | Warmer, E, R>473): Effect.Effect<void, ImportExamplesFailed | E, R | FileSystem.FileSystem> =>474 Effect.gen(function* () {475 const options = yield* optionsOf(argv);476
2 unmodified lines
modified:scripts/import-examples.ts+9 added-5 removed