import fs from "node:fs"; import path from "node:path"; // A FIXTURE PUBLISH for the /source/ page's History block (release 15 slice // SG). The page reads the directory E2E_SOURCE_PUBLIC_DIR names instead of // public/ while it holds a manifest (app/lib/source.ts sourcePublicDir, // honoured only outside a production build), so a spec can show the page with // a history and without one, whatever this checkout has published. The spec // writes it, and removes it after each test: with it gone, the page — and // every other spec — reads public/ again. playwright.config.ts clears it // before the server starts, in case a killed run left one. // // Only the files the loader requires: the manifest, the mirror's info/refs, // the tarball, and — with a history — the log page. Nothing here is served: // the dev server serves public/, so the History links are checked by their // hrefs, and the real pages by source.spec.ts. export const FIXTURE_SOURCE_NAME = ".e2e-source"; export const FIXTURE_HISTORY = { href: "/source/git/log.html", commits: 1234, total: 1234, head: "c".repeat(40), files: 1240, bytes: 1_000_000, sha256: "d".repeat(64), tool: "stagit (sha256 0123456789ab)", }; export const FIXTURE_MIRROR_HEAD = "c".repeat(40); // `total` over the history's `commits` is a history past the cap: the page // says "the latest N of M". export function writeFixtureSource(dir: string, o: { history: boolean; total?: number }): void { clearFixtureSource(dir); fs.mkdirSync(path.join(dir, "source", "archilyzer.git", "info"), { recursive: true }); fs.mkdirSync(path.join(dir, "downloads"), { recursive: true }); fs.writeFileSync(path.join(dir, "source", "archilyzer.git", "info", "refs"), `${FIXTURE_MIRROR_HEAD}\trefs/heads/main\n`); fs.writeFileSync(path.join(dir, "downloads", "archilyzer-source.tar.gz"), "fixture"); if (o.history) { fs.mkdirSync(path.join(dir, "source", "git"), { recursive: true }); fs.writeFileSync(path.join(dir, "source", "git", "log.html"), "\n"); } const manifest = { version: 1, generatedAt: "2026-09-30T12:00:00.000Z", branch: "main", sourceCommit: "b".repeat(40), mirrorHead: FIXTURE_MIRROR_HEAD, subject: "a fixture publish", files: 10, bytes: 100, mirror: { files: 9, bytes: 80, packs: 1 }, tree: { files: 5, dirs: 2, bytes: 20 }, tarball: { href: "/downloads/archilyzer-source.tar.gz", bytes: 7, sha256: "e".repeat(64) }, cloneUrl: "https://archilyzer.pages.dev/source/archilyzer.git", treeHref: "/source/tree/", audit: { objects: 3, commits: 1, gitleaks: "skipped" }, tools: { git: "2.55.0", filterRepo: "fixture" }, ...(o.history ? { history: { ...FIXTURE_HISTORY, total: o.total ?? FIXTURE_HISTORY.total } } : {}), }; // Written last, as the publish writes it: the page reads the fixture only // once a manifest is there. fs.writeFileSync(path.join(dir, "source", "manifest.json"), JSON.stringify(manifest, null, 2)); } export function clearFixtureSource(dir: string): void { fs.rmSync(dir, { recursive: true, force: true }); }