Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 0e297ec5e8428c6a88313c0be195a9f732466331
parent 9e81637c888de827f91ba0bad434927f73d3dd59
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 21 Nov 2026 18:20:53 -0500

network exits: only a confirmed routed listing is evidence; servers clear credentials before refusing to start; the umtool CLI names getPaths()'s settings file

- A rate-limited listing confirmed through its exit keeps its partial entries as listing evidence and
  rests the exit; one whose proxy use yt-dlp did not show contributes no evidence (its entries are dropped
  before verify-resume's evidence writer sees them). Tests for both.
- editor/ and umtool/instrumentation.ts: a guard that fails to install deletes every NETWORK_EXIT_* before
  the process exits (the editor's refuse-to-start, which arrived in a merge, now has its own commit and
  gate test).
- umtool/lib/paths.mjs editorSettingsFile(): the file getPaths() would read in this process (SETTINGS_FILE,
  else the cwd's workspace), else the CLI's own checkout's; the umtool CLI names it to the guard.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/lib/childEnvGuard.gate.test.ts | 6+++++-
Mcommon/ytdlp/networkExitListing.test.ts | 48+++++++++++++++++++++++++++++++++++++++++++++---
Meditor/instrumentation.ts | 2++
Mumtool/bin/umtool.mjs | 8++++----
Mumtool/instrumentation.ts | 2++
Aumtool/lib/editorSettingsFile.test.mjs | 35+++++++++++++++++++++++++++++++++++
Mumtool/lib/paths.mjs | 23+++++++++++++++++++++++
7 files changed, 116 insertions(+), 8 deletions(-)

diff --git a/common/lib/childEnvGuard.gate.test.ts b/common/lib/childEnvGuard.gate.test.ts @@ -105,6 +105,8 @@ test("6. every process entry tells the guard which settings file holds the polic for (const entry of ["editor/instrumentation.ts", "umtool/instrumentation.ts", "common/bin/archilyzer.ts", "umtool/bin/umtool.mjs"]) { assert.match(read(entry), /setNetworkPolicySettingsFile\(/, entry); } + // The umtool CLI names the file getPaths() reads (umtool/lib/paths.mjs editorSettingsFile). + assert.match(read("umtool/bin/umtool.mjs"), /setNetworkPolicySettingsFile\(editorSettingsFile\(\)\)/); }); // REVIEW 3 nit 4: a guard that does not install stops the server. @@ -112,7 +114,9 @@ test("7. a server whose guard does not install refuses to start", () => { for (const entry of ["editor/instrumentation.ts", "umtool/instrumentation.ts"]) { const s = read(entry); const at = s.indexOf("setNetworkPolicySettingsFile("); - const block = s.slice(at, at + 600); + const block = s.slice(at, at + 900); assert.match(block, /catch[\s\S]*refuses to start[\s\S]*process\.exit\(1\)/, entry); + // …and does not leave a credential behind for whatever runs before the exit. + assert.match(block, /catch[\s\S]*NETWORK_EXIT_[\s\S]*process\.exit\(1\)/, `${entry}: the catch clears NETWORK_EXIT_* first`); } }); diff --git a/common/ytdlp/networkExitListing.test.ts b/common/ytdlp/networkExitListing.test.ts @@ -20,7 +20,8 @@ process.env.SETTINGS_FILE = path.join(ROOT, "settings.json"); process.env.ARCHILYZER_CREDENTIALS_DIR = ROOT; writeFileSync(process.env.SETTINGS_FILE, "{}\n"); -const { fetchFlatPlaylistUrls, EnumerationIncompleteError, NetworkExitError } = await import("./runYtdlp"); +const { fetchFlatPlaylistUrls, runYtdlp, EnumerationIncompleteError, NetworkExitError } = await import("./runYtdlp"); +const { readListingEvidence } = await import("../controller/listingEvidence"); const { getPaths } = await import("../lib/paths"); const { JobDeferredError } = await import("../jobs/jobDeferred"); const { platformCooldownRemainingMs } = await import("../jobs/downloadBackoff"); @@ -64,13 +65,13 @@ appendFileSync(process.env.FAKE_RECORD, JSON.stringify({ argv, stdin, envProxy } const stdinProxy = stdin ? /--proxy '([^']*)'/.exec(stdin)?.[1] : undefined; const proxy = stdinProxy ?? process.env.ALL_PROXY ?? process.env.all_proxy; if (argv.includes("-v")) process.stderr.write("[debug] | Stdin config: " + JSON.stringify(stdin) + "\\n"); -if (argv.includes("-v") && proxy && mode !== "no-map") process.stderr.write("[debug] Proxy map: {'all': '" + proxy + "'}\\n"); +if (argv.includes("-v") && proxy && mode !== "no-map" && mode !== "no-map-429") process.stderr.write("[debug] Proxy map: {'all': '" + proxy + "'}\\n"); if (mode === "slow") { process.stdout.write("https://rumble.com/v1-a.html\\n"); await new Promise((r) => setTimeout(r, 3000)); } const finish = () => { - if (mode === "429") { + if (mode === "429" || mode === "no-map-429") { process.stdout.write("https://rumble.com/v1-a.html\\n"); process.stderr.write("[RumbleChannel] x: Downloading page 2\\nERROR: [RumbleChannel] x: Unable to download webpage: HTTP Error 429: Too Many Requests\\n"); process.exit(1); @@ -494,3 +495,44 @@ test("a rate limit is classified before the secret is scrubbed (review 2 nit 7)" await assert.rejects(list(ON_A), (err: unknown) => err instanceof EnumerationIncompleteError && err.exit === "exit-a"); assert.ok((await NE.exitRestUntil(getPaths(), "rumble", "exit-a"))! > Date.now()); }); + +// LANE verify-resume MEETS THE EXIT: a cut-short listing's entries are kept as +// evidence for the pre-clean check — but only entries yt-dlp showed came +// through the exit. +async function storePlaylistJob(slug: string) { + mkdirSync(path.join(ROOT, "channels", slug), { recursive: true }); + const config = { handling: "transcribe", url: "https://rumble.com/c/demo" }; + writeFileSync(path.join(ROOT, "channels", slug, "config.json"), JSON.stringify(config)); + return runYtdlp({ + channelSlug: slug, + mode: "store-playlist", + channelConfig: config as never, + paths: { ...getPaths(), ytdlpBin: BIN }, + onLog: () => {}, + signal: new AbortController().signal, + }); +} + +test("a rate-limited listing CONFIRMED through its exit keeps its partial entries as evidence and rests the exit", async () => { + settings(RUMBLE_POLICY); + rmSync(path.join(ROOT, "channels", ON_A, "listing-evidence.json"), { force: true }); + process.env.FAKE_MODE = "429"; + await assert.rejects(storePlaylistJob(ON_A), (err: unknown) => err instanceof EnumerationIncompleteError && err.urls.length === 1 && err.exit === "exit-a"); + const ev = await readListingEvidence(getPaths(), ON_A); + assert.ok(Object.keys(ev.seen).length > 0, JSON.stringify(ev)); + assert.ok((await NE.exitRestUntil(getPaths(), "rumble", "exit-a"))! > Date.now()); +}); + +test("a routed listing whose proxy use was NOT confirmed contributes no evidence (its entries are dropped first)", async () => { + settings(RUMBLE_POLICY); + rmSync(path.join(ROOT, "channels", ON_B, "listing-evidence.json"), { force: true }); + process.env.FAKE_MODE = "no-map-429"; + await assert.rejects(storePlaylistJob(ON_B), (err: unknown) => err instanceof EnumerationIncompleteError && err.urls.length === 0); + const ev = await readListingEvidence(getPaths(), ON_B); + assert.deepEqual(ev.seen, {}); + // A clean exit with no confirmation: discarded, no evidence either. + process.env.FAKE_MODE = "no-map"; + await NE.clearExitRest(getPaths(), "rumble", "exit-b"); + await assert.rejects(storePlaylistJob(ON_B), /its result is discarded/); + assert.deepEqual((await readListingEvidence(getPaths(), ON_B)).seen, {}); +}); diff --git a/editor/instrumentation.ts b/editor/instrumentation.ts @@ -30,6 +30,8 @@ export async function register() { const { getPaths } = await import("yt-dlp-transcript-common/lib/paths"); setNetworkPolicySettingsFile(getPaths().settingsFile); } catch (e) { + // Nothing that runs before the exit may hand a child a credential. + for (const k of Object.keys(process.env)) if (k.startsWith("NETWORK_EXIT_")) delete process.env[k]; console.error( `editor refuses to start: the child environment guard (common/lib/childEnvGuard.mjs) did not install — ${ e instanceof Error ? e.message : String(e) diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -182,9 +182,9 @@ import { rejectionOf } from "../lib/report/rejectReasons.mjs"; import { hms } from "umtool-report-to-video/attribution"; import { gappedLength, gapSpan, gapsOf, gapsText, parseGapSpec } from "umtool-report-to-video/gaps"; -// The policy the child-environment guard reads is the editor's settings file -// (as getPaths() names it: SETTINGS_FILE, else the checkout's), never the cwd's. -setNetworkPolicySettingsFile(process.env.SETTINGS_FILE ?? path.join(REPO_ROOT, "settings.json")); +// The policy the child-environment guard reads is the settings file getPaths() +// names in this process (umtool/lib/paths.mjs editorSettingsFile). +setNetworkPolicySettingsFile(editorSettingsFile()); /** What the walk said about a clip, with why when it was rejected: "rejected (irrelevant: covered in c07)". */ const reviewWords = (e) => { @@ -203,7 +203,7 @@ import { probeTools } from "../lib/tools.mjs"; import { notesCommand } from "../lib/annotations/cli.mjs"; import { scaffoldReportVideo } from "../lib/projects/scaffold.mjs"; import { rootsReport } from "../lib/system/roots.mjs"; -import { ARTICLES_DIR, ARTICLES_KEY, MEDIA_ROOT, MEDIA_TIERED, REPO_ROOT, SITES_DIR } from "../lib/paths.mjs"; +import { ARTICLES_DIR, ARTICLES_KEY, MEDIA_ROOT, MEDIA_TIERED, SITES_DIR, editorSettingsFile } from "../lib/paths.mjs"; import { deliverablesState, moveDeliverables, diff --git a/umtool/instrumentation.ts b/umtool/instrumentation.ts @@ -22,6 +22,8 @@ export async function register() { const { getPaths } = await import("yt-dlp-transcript-common/lib/paths"); setNetworkPolicySettingsFile(getPaths().settingsFile); } catch (e) { + // Nothing that runs before the exit may hand a child a credential. + for (const k of Object.keys(process.env)) if (k.startsWith("NETWORK_EXIT_")) delete process.env[k]; // A guard that does not install is no boot (review 3 nit 4). console.error( `umtool refuses to start: the child environment guard (common/lib/childEnvGuard.mjs) did not install — ${ diff --git a/umtool/lib/editorSettingsFile.test.mjs b/umtool/lib/editorSettingsFile.test.mjs @@ -0,0 +1,35 @@ +import { test, after } from "node:test"; +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { editorSettingsFile } from "./paths.mjs"; + +// Run with: node --test umtool/lib/editorSettingsFile.test.mjs +// +// THE SETTINGS FILE THE umtool CLI NAMES TO THE CHILD-ENVIRONMENT GUARD +// (lane network-exits, review 4 nit 3): the one common/lib/paths.ts getPaths() +// reads in the same process — SETTINGS_FILE, else the workspace found by +// walking up from the cwd (8 levels) — and, where getPaths() would find none +// (a project directory outside every checkout), the CLI's own checkout's, so +// a policy there is never missed. + +const DIR = mkdtempSync(path.join(os.tmpdir(), "editor-settings-file-")); +after(() => rmSync(DIR, { recursive: true, force: true })); +const repo = path.join(DIR, "repo"); +mkdirSync(path.join(repo, "a", "b"), { recursive: true }); +writeFileSync(path.join(repo, "pnpm-workspace.yaml"), ""); +const outside = path.join(DIR, "project"); +mkdirSync(outside, { recursive: true }); + +test("SETTINGS_FILE wins, as in getPaths()", () => { + assert.equal(editorSettingsFile({ cwd: outside, env: { SETTINGS_FILE: "/x/settings.json" }, fallbackRoot: repo }), "/x/settings.json"); +}); + +test("a cwd inside a checkout names that checkout's file, as getPaths() does", () => { + assert.equal(editorSettingsFile({ cwd: path.join(repo, "a", "b"), env: {}, fallbackRoot: "/elsewhere" }), path.join(repo, "settings.json")); +}); + +test("a cwd outside every checkout names the CLI's own checkout's file", () => { + assert.equal(editorSettingsFile({ cwd: outside, env: {}, fallbackRoot: repo }), path.join(repo, "settings.json")); +}); diff --git a/umtool/lib/paths.mjs b/umtool/lib/paths.mjs @@ -211,6 +211,29 @@ export function findCheckout(start) { } /** + * THE SETTINGS FILE THE EDITOR'S CODE READS IN THIS PROCESS, for the + * child-environment guard (lane network-exits, common/lib/childEnvGuard.mjs): + * what common/lib/paths.ts getPaths() resolves — SETTINGS_FILE, else the + * workspace found walking up from the cwd (8 levels) — and, where that finds + * none (a project directory outside every checkout), `fallbackRoot`'s (the + * CLI's own checkout), so a policy there is never missed. + * @param {{ cwd?: string, env?: Record<string, string | undefined>, fallbackRoot?: string }} [o] + */ +export function editorSettingsFile({ cwd = process.cwd(), env = process.env, fallbackRoot = REPO_ROOT } = {}) { + if (env.SETTINGS_FILE) return env.SETTINGS_FILE; + let dir = path.resolve(/* turbopackIgnore: true */ cwd); + for (let i = 0; i < 8; i++) { + if (existsSync(path.join(/* turbopackIgnore: true */ dir, "pnpm-workspace.yaml"))) { + return path.join(/* turbopackIgnore: true */ dir, "settings.json"); + } + const up = path.dirname(/* turbopackIgnore: true */ dir); + if (up === dir) break; + dir = up; + } + return path.join(/* turbopackIgnore: true */ fallbackRoot, "settings.json"); +} + +/** * The checkout THIS MODULE is in -- `<repo>/umtool/lib/paths.mjs` -- or null * (a bundle, where import.meta.url is not the file on disk: the Next server's * cwd walk answers there).