Archilyzer · Source

archilyzer

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

commit c6b7c90976f21b9997e131087c44f7cbe31b0329
parent a583597c48a719f1f47e70051392c5753a6eed27
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 21 Nov 2026 17:59:47 -0500

network exits, review 3: the guard names its settings file, fails closed, drops the sync wrapper; every yt-dlp option classified

- lib/childEnvGuard.mjs no longer walks up from the cwd (a bundled module joining cwd-derived paths;
  scripts/next-build-trace.test.mjs is green again). The policy file is the one each entry names: the
  editor and umtool servers and the archilyzer CLI from getPaths(), the umtool CLI from SETTINGS_FILE or
  its checkout. Resolved once; nothing named or unreadable means a policy may exist: no child gets a proxy
  variable, said once in the log.
- The sync-export wrapper is gone: nothing networking spawns synchronously, and a gate test fails when a
  networking tool gains a sync spawn. A credential put back into process.env is taken out again at the next
  spawn.
- The editor and umtool refuse to start when the guard cannot install.
- lib/ytdlpOptionClasses.ts classifies every option of the table by hand; an unclassified one is a login
  at run time and fails the test until classified.
- Tests: bindings taken before install for every async API, no-policy environment byte for byte with the
  options passed through, two copies of the module sharing one state.

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

Diffstat:
MOPERATING.md | 8+++++++-
Mcommon/bin/archilyzer.ts | 8++++++--
Mcommon/lib/childEnvGuard.fixture.mjs | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Mcommon/lib/childEnvGuard.gate.test.ts | 29+++++++++++++++++++++++++++++
Mcommon/lib/childEnvGuard.mjs | 112++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Mcommon/lib/childEnvGuard.test.ts | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Mcommon/lib/networkExits.test.ts | 13+++++++++++++
Mcommon/lib/networkExits.ts | 40+++++++++++-----------------------------
Acommon/lib/ytdlpOptionClasses.ts | 379+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Meditor/CHANGELOG.md | 4++++
Mumtool/bin/umtool.mjs | 12+++++++++---
Mumtool/instrumentation.ts | 10++++++++--
12 files changed, 706 insertions(+), 148 deletions(-)

diff --git a/OPERATING.md b/OPERATING.md @@ -303,7 +303,13 @@ pnpm ops network --json '{"platforms":{"rumble":null}}' # back to direct ffmpeg, browser, in or out of the trial's scope, cookie-bearing or not (`common/lib/childEnvGuard.mjs`, a hook on Node's own spawn installed by the editor, umtool and the CLI at boot). With no policy, children get the environment they always did. So an inherited `HTTPS_PROXY` no longer carries anything once a policy is - saved: one login is never seen from two addresses. `socks5h://` has the proxy resolve the hostname; `socks5://` resolves it here. + saved: one login is never seen from two addresses. + **What it costs:** on a machine that needs a proxy to reach the internet at all, saving any policy also + takes the proxy from wrangler, git, pnpm, pip, model downloads, docker and the browsers — publishing and + installs stop until the policy is removed. The policy is read from the editor's own settings file (every + entry names it); if that file cannot be read, a policy is assumed and the log says so once. The sync spawn + API is not covered, and nothing networking uses it (a test fails if something starts to). If the guard + cannot install, the editor and umtool refuse to start. `socks5h://` has the proxy resolve the hostname; `socks5://` resolves it here. With the VPN down, every preflight asks the home resolver for the relay's name. - **Probes**: the startup probe (a minute after boot, when an exit is enabled) only connects to each proxy — no greeting, no destination, no echo; `{"startupProbe": false}` turns it off. The echo URL is fetched only diff --git a/common/bin/archilyzer.ts b/common/bin/archilyzer.ts @@ -9,11 +9,15 @@ // machinery (parser, lookup, usage) is `_cli.ts`; this file is only the table. // What every child inherits (lane network-exits): installed before any row -// can spawn (lib/childEnvGuard.mjs). -import "../lib/childEnvGuard.mjs"; +// can spawn (lib/childEnvGuard.mjs), reading the policy from the same +// settings file the editor uses. +import { setNetworkPolicySettingsFile } from "../lib/childEnvGuard.mjs"; +import { getPaths } from "../lib/paths"; import type { Command } from "./_cli"; import { runCli, runIfEntryPoint } from "./_cli"; +setNetworkPolicySettingsFile(getPaths().settingsFile); + export const COMMANDS: Command[] = [ { path: ["index"], diff --git a/common/lib/childEnvGuard.fixture.mjs b/common/lib/childEnvGuard.fixture.mjs @@ -1,38 +1,111 @@ -// The fixture of childEnvGuard.test.ts, run as its own node process: the -// environment is set up the way an operator's service would carry it, the -// guard is installed, and a child is spawned every way the app spawns one. -// Prints what each child saw (proxy and credential NAMES and values) as JSON. -import { readFileSync } from "node:fs"; +// The fixture of childEnvGuard.test.ts, run as its own node process: +// `node childEnvGuard.fixture.mjs <mode> <settings file | "-">`. Bindings to +// child_process are taken BEFORE the guard is installed — an ESM named import +// here and a CommonJS require below — as code loaded earlier than an entry's +// import would hold them. Prints JSON. +import { spawn as eSpawn, exec as eExec, execFile as eExecFile, fork as eFork, spawnSync as eSpawnSync, execFileSync as eExecFileSync } from "node:child_process"; +import { createRequire } from "node:module"; +import { fileURLToPath } from "node:url"; -const childScript = +const require = createRequire(import.meta.url); +const cjs = require("node:child_process"); +const { spawn: rSpawn, execFile: rExecFile } = cjs; +const SELF = fileURLToPath(import.meta.url); +const [mode, settingsFile] = process.argv.slice(2); + +const ENV_SCRIPT = "const o={};for(const [k,v] of Object.entries(process.env)){if(/proxy$/i.test(k)||/^NETWORK_EXIT_/.test(k))o[k]=v;}process.stdout.write(JSON.stringify(o));"; -const settingsFile = process.argv[2]; -Object.assign(process.env, { - SETTINGS_FILE: settingsFile, - HTTPS_PROXY: "http://127.0.0.1:2", - no_proxy: "*", - NETWORK_EXIT_EXIT_A: "fixture-user:fixture-value", -}); -const guard = await import("./childEnvGuard.mjs"); -const cp = await import("node:child_process"); -const { execa } = await import("execa"); -const out = { parentHasCredential: "NETWORK_EXIT_EXIT_A" in process.env, captured: guard.networkExitEnvValue("NETWORK_EXIT_EXIT_A") !== undefined }; -const run = (child) => +const WHOLE_ENV = "process.stdout.write(JSON.stringify(Object.entries(process.env).filter(([k])=>k!=='_')))"; + +if (mode === "fork-child") { + const o = {}; + for (const [k, v] of Object.entries(process.env)) if (/proxy$/i.test(k) || /^NETWORK_EXIT_/.test(k)) o[k] = v; + process.stdout.write(JSON.stringify(o)); + process.exit(0); +} + +const collect = (child) => new Promise((resolve) => { let s = ""; child.stdout.on("data", (d) => (s += d)); child.on("close", () => resolve(JSON.parse(s || "{}"))); }); -out.spawn = await run(cp.spawn(process.execPath, ["-e", childScript])); -out.execFile = await run(cp.execFile(process.execPath, ["-e", childScript])); -out.execa = JSON.parse((await execa(process.execPath, ["-e", childScript])).stdout || "{}"); -out.execaOwnEnv = JSON.parse( - (await execa(process.execPath, ["-e", childScript], { env: { ...process.env, ALL_PROXY: "http://127.0.0.1:3" } })).stdout || "{}", -); -out.routed = JSON.parse( - (await execa(process.execPath, ["-e", childScript], { env: guard.routedChildEnv(), extendEnv: false })).stdout || "{}", -); -out.spawnSync = JSON.parse(cp.spawnSync(process.execPath, ["-e", childScript]).stdout.toString() || "{}"); -out.execFileSync = JSON.parse(cp.execFileSync(process.execPath, ["-e", childScript]).toString() || "{}"); -void readFileSync; +const node = process.execPath; + +Object.assign(process.env, { HTTPS_PROXY: "http://127.0.0.1:2", no_proxy: "*", NETWORK_EXIT_EXIT_A: "fixture-user:fixture-value" }); +if (settingsFile && settingsFile !== "-") process.env.SETTINGS_FILE = settingsFile; +else delete process.env.SETTINGS_FILE; + +const errs = []; +const origError = console.error; +console.error = (...a) => errs.push(a.join(" ")); +const guard = await import("./childEnvGuard.mjs"); + +const out = {}; +if (mode === "apis") { + out.parentHasCredential = "NETWORK_EXIT_EXIT_A" in process.env; + out.esmSpawn = await collect(eSpawn(node, ["-e", ENV_SCRIPT])); + out.esmExec = await collect(eExec(`"${node}" -e '${ENV_SCRIPT}'`)); + out.esmExecFile = await collect(eExecFile(node, ["-e", ENV_SCRIPT])); + out.esmExecFileUndefined = await collect(eExecFile(node, ["-e", ENV_SCRIPT], undefined)); + out.cjsSpawn = await collect(rSpawn(node, ["-e", ENV_SCRIPT])); + out.cjsExecFile = await collect(rExecFile(node, ["-e", ENV_SCRIPT])); + out.shellTrue = await collect(eSpawn(`"${node}" -e '${ENV_SCRIPT}'`, { shell: true })); + out.fork = await collect(eFork(SELF, ["fork-child"], { silent: true })); + const { execa } = await import("execa"); + out.execa = JSON.parse((await execa(node, ["-e", ENV_SCRIPT])).stdout || "{}"); + out.execaOwnEnv = JSON.parse((await execa(node, ["-e", ENV_SCRIPT], { env: { ...process.env, ALL_PROXY: "http://127.0.0.1:3" } })).stdout || "{}"); + out.routed = JSON.parse((await execa(node, ["-e", ENV_SCRIPT], { env: guard.routedChildEnv(), extendEnv: false })).stdout || "{}"); + // The sync API is NOT hooked (no networking spawn uses it; the gate holds + // that): it gets main's environment — minus the credential, which left + // process.env at install. + out.spawnSync = JSON.parse(eSpawnSync(node, ["-e", ENV_SCRIPT]).stdout.toString() || "{}"); + out.execFileSync = JSON.parse(eExecFileSync(node, ["-e", ENV_SCRIPT]).toString() || "{}"); + out.log = errs; +} else if (mode === "main") { + // No policy: the WHOLE environment a child sees is the parent's, in order. + const parent = Object.entries(process.env).filter(([k]) => k !== "_"); + const child = await collect(eSpawn(node, ["-e", WHOLE_ENV])); + out.sameWhole = JSON.stringify(child) === JSON.stringify(parent); + const base = { PATH: process.env.PATH ?? "", HTTPS_PROXY: "http://127.0.0.1:2", INHERITED_ONLY: "1" }; + const ownAndInherited = Object.create(base); + ownAndInherited.OWN_KEY = "own"; + const viaSpawn = await collect(eSpawn(node, ["-e", WHOLE_ENV], { env: ownAndInherited })); + out.explicitEnv = Object.fromEntries(viaSpawn); + // The test harness re-adds its no-network preload to a child given its own + // environment (common/lib/noNetwork.mjs guardedChildEnv), which copies own + // keys only; the inherited-key case is then the harness's, not the guard's. + out.noNetworkHarness = process.env.ARCHILYZER_NO_NETWORK === "1"; + // Options reach Node unchanged. + const { execa } = await import("execa"); + out.cwd = (await execa(node, ["-e", "process.stdout.write(process.cwd())"], { cwd: "/" })).stdout; + out.input = (await execa(node, ["-e", "process.stdin.pipe(process.stdout)"], { input: "piped-in" })).stdout; + const t0 = Date.now(); + const timedOut = await execa(node, ["-e", "setTimeout(()=>{},5000)"], { timeout: 200, reject: false }); + out.timeout = { timedOut: timedOut.timedOut, fast: Date.now() - t0 < 3000 }; + const ac = new AbortController(); + const aborted = execa(node, ["-e", "setTimeout(()=>{},5000)"], { cancelSignal: ac.signal, reject: false }); + setTimeout(() => ac.abort(), 100); + out.signal = (await aborted).isCanceled; + const det = eSpawn(node, ["-e", "process.stdout.write(String(process.pid))"], { detached: true, stdio: ["ignore", "pipe", "ignore"] }); + out.detached = (await new Promise((r) => { let s = ""; det.stdout.on("data", (d) => (s += d)); det.on("close", () => r(s)); })) !== ""; +} else if (mode === "twocopies") { + const { ChildProcess } = cjs; + const first = ChildProcess.prototype.spawn; + const copy = await import("./childEnvGuard.mjs?copy=2"); + out.onePatch = ChildProcess.prototype.spawn === first; + out.bothRead = + guard.networkExitEnvValue("NETWORK_EXIT_EXIT_A") === "fixture-user:fixture-value" && + copy.networkExitEnvValue("NETWORK_EXIT_EXIT_A") === "fixture-user:fixture-value"; + // A credential put back (Next's dev .env reload does this) reaches no child. + const PUT_BACK = "NETWORK_EXIT_EXIT_B"; + process.env[PUT_BACK] = "fixture-user:put-back"; + out.putBack = await collect(eSpawn(node, ["-e", ENV_SCRIPT])); + out.putBackLeftEnv = !(PUT_BACK in process.env); +} else if (mode === "unresolved") { + out.child = await collect(eSpawn(node, ["-e", ENV_SCRIPT])); + await collect(eSpawn(node, ["-e", ENV_SCRIPT])); + out.log = errs; +} +console.error = origError; process.stdout.write(JSON.stringify(out)); diff --git a/common/lib/childEnvGuard.gate.test.ts b/common/lib/childEnvGuard.gate.test.ts @@ -87,3 +87,32 @@ test("4. no source sets a proxy variable for a child but the guard", () => { ); assert.deepEqual(setters, []); }); + +// REVIEW 3 finding 3: the sync API is not hooked, so no networking spawn may +// use it. A sync call naming a networking tool (or a URL) fails the gate. +test("5. no networking tool is spawned through the sync API", () => { + const SYNC = /\b(spawnSync|execSync|execFileSync|execaSync)\s*\(([\s\S]{0,240})/g; + const NET = /yt-?dlp|ytdlpBin|gallery-?dl|galleryDlBin|streamlink|\bcurl\b|\bwget\b|aria2c|chromium|playwright|https?:\/\//i; + const hits: string[] = []; + for (const f of SOURCES) { + for (const m of read(f).matchAll(SYNC)) if (NET.test(m[2]!)) hits.push(`${f}: ${m[0].slice(0, 80)}`); + } + assert.deepEqual(hits, []); +}); + +// REVIEW 3 finding 2: every entry names the settings file the editor uses. +test("6. every process entry tells the guard which settings file holds the policy", () => { + for (const entry of ["editor/instrumentation.ts", "umtool/instrumentation.ts", "common/bin/archilyzer.ts", "umtool/bin/umtool.mjs"]) { + assert.match(read(entry), /setNetworkPolicySettingsFile\(/, entry); + } +}); + +// REVIEW 3 nit 4: a guard that does not install stops the server. +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); + assert.match(block, /catch[\s\S]*refuses to start[\s\S]*process\.exit\(1\)/, entry); + } +}); diff --git a/common/lib/childEnvGuard.mjs b/common/lib/childEnvGuard.mjs @@ -16,21 +16,35 @@ // this lane. // // ONE PLACE, AND NO WAY AROUND IT: the hook is on Node's own spawn — -// ChildProcess.prototype.spawn, which spawn, execFile, exec, fork and execa -// all reach with the final environment (`envPairs`) — and on the -// child_process sync exports (spawnSync, execSync, execFileSync). A call site +// ChildProcess.prototype.spawn, which spawn, execFile, exec, fork, execa, +// cross-spawn and Playwright all reach with the final environment +// (`envPairs`), however and whenever the caller took its binding. A call site // cannot build its environment another way: whatever it passes is filtered // here. lib/childEnvGuard.gate.test.ts holds the process entries and the // networking modules to importing it. // +// THE SYNC API (spawnSync, execSync, execFileSync) IS NOT HOOKED (review 3, +// finding 3): it does not pass through the prototype, and wrapping its exports +// meant guessing the caller's options argument. Nothing that does networking +// spawns synchronously — the repo's sync spawns are git, ffprobe, local ffmpeg, +// systemd-run and a version probe — and gate test 5 fails when a networking +// tool gains one. A sync child still never sees a credential: it left +// process.env at install. +// +// WHICH SETTINGS FILE (review 3, finding 2): the one the entry names +// (setNetworkPolicySettingsFile — the editor, umtool and both CLIs name the +// file getPaths() reads), else SETTINGS_FILE, resolved ONCE. No cwd walk: a +// module both Next apps bundle must not join cwd-derived paths (finding 1, +// scripts/next-build-trace.test.mjs). When no file is named, or it cannot be +// read, a policy MAY exist: children get no proxy variable (fail closed), and +// the log says so once. +// // Plain ESM: umtool's .mjs and the scripts run it under bare node. // Idempotent; per process (the mark is on the prototype and on globalThis, // which Next's two module graphs share). -import childProcess, { ChildProcess } from "node:child_process"; +import { ChildProcess } from "node:child_process"; import { readFileSync, statSync } from "node:fs"; -import { syncBuiltinESMExports } from "node:module"; -import path from "node:path"; const MARK = Symbol.for("archilyzer.childEnvGuard"); const STATE = Symbol.for("archilyzer.childEnvGuard.state"); @@ -40,10 +54,10 @@ export const DEAD_PROXY = "socks5h://127.0.0.1:1"; export const PROXY_ENV_RE = /(?:^|_)proxy$/i; export const CREDENTIAL_ENV_RE = /^NETWORK_EXIT_/; -/** @returns {{ creds: Map<string, string>, settingsFile: string | null, cache: { file: string, mtimeMs: number, size: number, active: boolean } | null }} */ +/** @returns {{ creds: Map<string, string>, settingsFile: string | null, resolved: boolean, said: Set<string>, cache: { mtimeMs: number, size: number, active: boolean } | null }} */ function state() { const g = /** @type {any} */ (globalThis); - if (!g[STATE]) g[STATE] = { creds: new Map(), settingsFile: null, cache: null }; + if (!g[STATE]) g[STATE] = { creds: new Map(), settingsFile: null, resolved: false, said: new Set(), cache: null }; return g[STATE]; } @@ -64,53 +78,67 @@ export function networkExitEnvValue(name) { return state().creds.get(name); } -// The settings file the policy is read from. The editor and the CLI set it -// from getPaths(); otherwise SETTINGS_FILE, else the workspace root's. +// The settings file the policy is read from, named by the entry. /** @param {string} file */ export function setNetworkPolicySettingsFile(file) { - state().settingsFile = file; - state().cache = null; + const st = state(); + st.settingsFile = file; + st.resolved = true; + st.cache = null; +} + +/** @param {string} line */ +function sayOnce(line) { + const st = state(); + if (st.said.has(line)) return; + st.said.add(line); + console.error(line); } -function settingsFile() { +// Resolved once: the named file, else SETTINGS_FILE (absolute), else null. +function resolvedSettingsFile() { const st = state(); - if (st.settingsFile) return st.settingsFile; - if (process.env.SETTINGS_FILE) return process.env.SETTINGS_FILE; - let dir = process.cwd(); - for (let i = 0; i < 8; i++) { - try { - statSync(path.join(dir, "pnpm-workspace.yaml")); - return path.join(dir, "settings.json"); - } catch { - const up = path.dirname(dir); - if (up === dir) break; - dir = up; - } + if (!st.resolved) { + const env = process.env.SETTINGS_FILE; + st.settingsFile = env && env.startsWith("/") ? env : null; + st.resolved = true; } - return path.join(process.cwd(), "settings.json"); + return st.settingsFile; } -// Whether a network policy exists. Absent file: no. Unreadable, not JSON: -// yes (fail safe). Re-read when the file changes. +// Whether a network policy exists. No file named, unreadable, not JSON: yes +// (fail safe). Absent at the named path: no (a fresh install has none). The +// CONTENT is re-read when the file's mtime or size changes; the path never is. export function networkPolicyActive() { - const file = settingsFile(); + const file = resolvedSettingsFile(); + if (!file) { + sayOnce( + "childEnvGuard: no settings file was named (setNetworkPolicySettingsFile / SETTINGS_FILE) — a network policy " + + "may exist, so no child process gets a proxy variable", + ); + return true; + } let st; try { st = statSync(file); } catch (e) { - return /** @type {NodeJS.ErrnoException} */ (e).code === "ENOENT" || /** @type {NodeJS.ErrnoException} */ (e).code === "ENOTDIR" ? false : true; + const code = /** @type {NodeJS.ErrnoException} */ (e).code; + if (code === "ENOENT" || code === "ENOTDIR") return false; + sayOnce(`childEnvGuard: ${file} could not be read — a network policy may exist, so no child process gets a proxy variable`); + return true; } const s = state(); - if (s.cache && s.cache.file === file && s.cache.mtimeMs === st.mtimeMs && s.cache.size === st.size) return s.cache.active; + if (s.cache && s.cache.mtimeMs === st.mtimeMs && s.cache.size === st.size) return s.cache.active; let active = true; try { const raw = JSON.parse(readFileSync(file, "utf8")); const platforms = raw && typeof raw === "object" ? raw.network?.platforms : undefined; active = !!platforms && typeof platforms === "object" && Object.keys(platforms).length > 0; } catch { + sayOnce(`childEnvGuard: ${file} could not be read — a network policy may exist, so no child process gets a proxy variable`); active = true; } - s.cache = { file, mtimeMs: st.mtimeMs, size: st.size, active }; + s.cache = { mtimeMs: st.mtimeMs, size: st.size, active }; return active; } @@ -174,26 +202,12 @@ export function installChildEnvGuard() { const spawn = proto.spawn; proto.spawn = function guardedSpawn(/** @type {any} */ options) { if (options && Array.isArray(options.envPairs)) options.envPairs = filterEnvPairs(options.envPairs); + // A credential put back into process.env since (Next's dev .env reload) + // was filtered out above; take it out of process.env again. + captureNetworkExitEnv(); return spawn.call(this, options); }; proto[MARK] = true; - // The sync API does not pass through the prototype: wrap its exports. - const cp = /** @type {any} */ (childProcess); - for (const name of ["spawnSync", "execSync", "execFileSync"]) { - const orig = cp[name]; - cp[name] = function guardedSync(/** @type {any[]} */ ...args) { - // (file, args?, options?) or (command, options?): the options object is - // the last plain object argument; give it a filtered env. - let at = args.findIndex((a, i) => i > 0 && a && typeof a === "object" && !Array.isArray(a)); - if (at < 0) { - args.push({}); - at = args.length - 1; - } - args[at] = { ...args[at], env: filterEnv(args[at].env ?? process.env) }; - return orig.apply(this, args); - }; - } - syncBuiltinESMExports(); } installChildEnvGuard(); diff --git a/common/lib/childEnvGuard.test.ts b/common/lib/childEnvGuard.test.ts @@ -1,7 +1,7 @@ import { test, after } from "node:test"; import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; -import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -9,52 +9,94 @@ import { fileURLToPath } from "node:url"; // Run with: // pnpm --filter yt-dlp-transcript-common exec tsx --test lib/childEnvGuard.test.ts // -// REVIEW 2, findings 1 and 2: no child ever inherits a NETWORK_EXIT_* -// credential, and once ANY network policy exists no child inherits a proxy -// variable — whichever API spawns it (spawn, execFile, execa, a custom env, -// spawnSync, execFileSync). With no policy the environment is main's. The -// routed spawn keeps only its dead-proxy backstop. Each case runs in a fresh -// node process (lib/childEnvGuard.fixture.mjs). +// THE CHILD-ENVIRONMENT HOOK (lane network-exits, reviews 2-3). Each case runs +// lib/childEnvGuard.fixture.mjs as its own node process, with child_process +// bindings taken before the guard is installed (ESM named imports and a +// CommonJS require). const HERE = path.dirname(fileURLToPath(import.meta.url)); const DIR = mkdtempSync(path.join(os.tmpdir(), "child-env-guard-")); after(() => rmSync(DIR, { recursive: true, force: true })); -function run(settings: string | null) { - const file = path.join(DIR, `settings-${Math.random().toString(36).slice(2)}.json`); - if (settings !== null) writeFileSync(file, settings); +function run(mode: string, settings: string | null | "unset") { + let file = "-"; + if (settings !== "unset") { + file = path.join(DIR, `settings-${Math.random().toString(36).slice(2)}.json`); + if (settings !== null) writeFileSync(file, settings); + } const env: Record<string, string> = {}; - for (const [k, v] of Object.entries(process.env)) if (v !== undefined && !/proxy$/i.test(k)) env[k] = v; - return JSON.parse(execFileSync(process.execPath, [path.join(HERE, "childEnvGuard.fixture.mjs"), file], { env, cwd: HERE }).toString()); + for (const [k, v] of Object.entries(process.env)) { + if (v !== undefined && !/proxy$/i.test(k) && !["NODE_OPTIONS", "ARCHILYZER_NO_NETWORK", "SETTINGS_FILE"].includes(k)) env[k] = v; + } + return JSON.parse(execFileSync(process.execPath, [path.join(HERE, "childEnvGuard.fixture.mjs"), mode, file], { env, cwd: DIR }).toString()); } -const WAYS = ["spawn", "execFile", "execa", "execaOwnEnv", "spawnSync", "execFileSync"] as const; +const POLICY = JSON.stringify({ network: { exits: [], platforms: { twitch: { exits: ["direct"], mode: "sticky" } } } }); +const ASYNC = ["esmSpawn", "esmExec", "esmExecFile", "esmExecFileUndefined", "cjsSpawn", "cjsExecFile", "shellTrue", "fork", "execa", "execaOwnEnv"] as const; -test("a credential is moved out of process.env at load and no child inherits it (finding 1)", () => { - const r = run(null); +test("a credential leaves process.env at load and no child gets it, whatever API spawns it (review 2 finding 1)", () => { + const r = run("apis", POLICY); assert.equal(r.parentHasCredential, false); - assert.equal(r.captured, true); - for (const w of [...WAYS, "routed"]) assert.ok(!Object.keys(r[w]).some((k) => k.startsWith("NETWORK_EXIT_")), w); -}); - -test("no policy: every child's proxy variables are main's (unchanged)", () => { - const r = run(JSON.stringify({ network: { exits: [], platforms: {} } })); - for (const w of ["spawn", "execFile", "execa", "spawnSync", "execFileSync"] as const) { - assert.deepEqual(r[w], { HTTPS_PROXY: "http://127.0.0.1:2", no_proxy: "*" }, w); + for (const w of [...ASYNC, "routed", "spawnSync", "execFileSync"]) { + assert.ok(!Object.keys(r[w]).some((k) => k.startsWith("NETWORK_EXIT_")), w); } - assert.equal(r.execaOwnEnv.ALL_PROXY, "http://127.0.0.1:3"); }); -test("any policy: no child inherits a proxy variable, however it is spawned (finding 2)", () => { - const policy = { network: { exits: [], platforms: { twitch: { exits: ["direct"], mode: "sticky" } } } }; - const r = run(JSON.stringify(policy)); - for (const w of WAYS) assert.deepEqual(r[w], {}, w); - // The routed spawn carries only its dead-proxy backstop. +test("any policy: every async spawn, bindings taken before install included, gets no proxy variable (review 3 test 1)", () => { + const r = run("apis", POLICY); + for (const w of ASYNC) assert.deepEqual(r[w], {}, w); assert.deepEqual(Object.keys(r.routed).sort(), ["ALL_PROXY", "HTTPS_PROXY", "HTTP_PROXY", "all_proxy", "http_proxy", "https_proxy"]); for (const v of Object.values(r.routed)) assert.equal(v, "socks5h://127.0.0.1:1"); }); -test("unreadable settings strip too (fail safe)", () => { - const r = run("{ not json"); - for (const w of WAYS) assert.deepEqual(r[w], {}, w); +test("the sync API is not hooked: it keeps main's environment (no networking spawn uses it — the gate holds that)", () => { + const r = run("apis", POLICY); + assert.deepEqual(r.spawnSync, { HTTPS_PROXY: "http://127.0.0.1:2", no_proxy: "*" }); + assert.deepEqual(r.execFileSync, { HTTPS_PROXY: "http://127.0.0.1:2", no_proxy: "*" }); +}); + +test("no policy is main, byte for byte: the whole environment, explicit env own and inherited keys, and the options (review 3 test 2)", () => { + const r = run("main", JSON.stringify({ network: { exits: [], platforms: {} } })); + assert.equal(r.sameWhole, true); + assert.equal(r.explicitEnv.OWN_KEY, "own"); + if (!r.noNetworkHarness) { + assert.equal(r.explicitEnv.INHERITED_ONLY, "1"); + assert.equal(r.explicitEnv.HTTPS_PROXY, "http://127.0.0.1:2"); + } + assert.equal(r.cwd, "/"); + assert.equal(r.input, "piped-in"); + assert.deepEqual(r.timeout, { timedOut: true, fast: true }); + assert.equal(r.signal, true); + assert.equal(r.detached, true); +}); + +test("two copies of the module share one state: one patch, one map, a put-back credential reaches no child (review 3 test 3)", () => { + const r = run("twocopies", POLICY); + assert.equal(r.onePatch, true); + assert.equal(r.bothRead, true); + assert.deepEqual(r.putBack, {}); + assert.equal(r.putBackLeftEnv, true); +}); + +test("no settings file named: fail closed (a policy may exist), said once in the log (review 3 finding 2)", () => { + const r = run("unresolved", "unset"); + assert.deepEqual(r.child, {}); + assert.equal(r.log.filter((l: string) => /childEnvGuard: no settings file was named/.test(l)).length, 1); +}); + +test("unreadable settings strip too (fail safe), said once", () => { + const r = run("apis", "{ not json"); + for (const w of ASYNC) assert.deepEqual(r[w], {}, w); + assert.equal(r.log.filter((l: string) => /could not be read/.test(l)).length, 1); +}); + +test("an absent settings file at the named path is no policy: main's proxies", () => { + const r = run("apis", null); + assert.deepEqual(r.esmSpawn, { HTTPS_PROXY: "http://127.0.0.1:2", no_proxy: "*" }); +}); + +test("the policy path is resolved once (review 3 nit 6): SETTINGS_FILE changed later is not re-read", () => { + const src = readFileSync(path.join(HERE, "childEnvGuard.mjs"), "utf8"); + assert.match(src, /resolvedSettingsFile/); + assert.doesNotMatch(src, /process\.cwd\(\)/, "no cwd walk (review 3 findings 1-2)"); }); diff --git a/common/lib/networkExits.test.ts b/common/lib/networkExits.test.ts @@ -24,6 +24,7 @@ import { import { execFileSync } from "node:child_process"; import { readFileSync, realpathSync } from "node:fs"; import { YTDLP_OPTIONS, YTDLP_OPTIONS_DUMP } from "./ytdlpOptions"; +import { YTDLP_OPTION_CLASSES } from "./ytdlpOptionClasses"; // The installed yt-dlp's own option table, from its own parser, run with the // interpreter its launcher names (a pip/pipx install); null when there is no @@ -215,3 +216,15 @@ test("applyNetworkRequest: a proxy URL fills the fields; credentials only as yes const probeOff = applyNetworkRequest(cur, { startupProbe: false }); assert.equal(probeOff.startupProbe, false); }); + +test("every option of the table is classified by a person (review 3 nit 5): a new one fails until it is", () => { + const unclassified = [...new Set(YTDLP_OPTIONS.map(([, l]) => l))].filter((l) => !(l in YTDLP_OPTION_CLASSES)); + assert.deepEqual(unclassified, []); + const stale = Object.keys(YTDLP_OPTION_CLASSES).filter((l) => !YTDLP_OPTIONS.some(([, x]) => x === l)); + assert.deepEqual(stale, []); + // And an option the classes do not know is a login at run time. + assert.equal(requestJar(["--flat-playlist", "--plugin-dirs", "/x"]), "config"); + assert.equal(requestJar(["--flat-playlist", "--xff", "US"]), "header"); + assert.equal(requestJar(["--flat-playlist", "--mark-watched"]), "login:--mark-watched"); + assert.equal(requestJar(["--flat-playlist", "--referer", "https://example.test/"]), null); +}); diff --git a/common/lib/networkExits.ts b/common/lib/networkExits.ts @@ -33,6 +33,7 @@ import type { FieldDocs } from "./fieldDocs"; import { YTDLP_OPTIONS } from "./ytdlpOptions"; +import { YTDLP_OPTION_CLASSES, type YtdlpOptionClass } from "./ytdlpOptionClasses"; export const DIRECT_EXIT = "direct"; @@ -496,30 +497,11 @@ export function exitById(network: NetworkSettings | undefined, id: string): Netw return network?.exits.find((e) => e.id === id); } -// THE OPTIONS THAT MAKE A REQUEST A LOGGED-IN ONE, by yt-dlp's long name -// (lib/ytdlpOptions.ts is the table they are resolved against). -const COOKIE_OPTIONS = new Set(["--cookies", "--cookies-from-browser"]); -const HEADER_OPTIONS = new Set(["--add-headers"]); -// Another config, an alias (which can expand to any option) or an info file -// (which can carry headers and cookies): anything could be in it. -const CONFIG_OPTIONS = new Set(["--config-locations", "--alias", "--load-info-json", "--batch-file"]); -const LOGIN_OPTIONS = new Set([ - "--username", - "--password", - "--twofactor", - "--video-password", - "--netrc", - "--netrc-location", - "--netrc-cmd", - "--ap-mso", - "--ap-username", - "--ap-password", - "--client-certificate", - "--client-certificate-key", - "--client-certificate-password", - "--extractor-args", -]); -const PROXY_OPTIONS = new Set(["--proxy", "--geo-verification-proxy"]); +// WHAT EACH OPTION MEANS is a person's classification (lib/ytdlpOptionClasses.ts); +// an option it does not list counts as `config` — a login, pinned direct. +function optionClass(long: string): YtdlpOptionClass { + return YTDLP_OPTION_CLASSES[long] ?? "config"; +} const LONG = new Map(YTDLP_OPTIONS.map(([, l, v]) => [l, v] as const)); const SHORT = new Map(YTDLP_OPTIONS.filter(([s]) => s !== null).map(([s, l, v]) => [s!, { long: l, value: v }] as const)); @@ -590,10 +572,10 @@ export function requestJar(argv: readonly string[]): string | null { if (o.long === null) return "config"; if (o.long === "--cookies-from-browser") return `browser:${o.value ?? ""}`; if (o.long === "--cookies") return `file:${o.value ?? ""}`; - if (COOKIE_OPTIONS.has(o.long)) return `login:${o.long}`; - if (HEADER_OPTIONS.has(o.long)) return "header"; - if (CONFIG_OPTIONS.has(o.long)) return "config"; - if (LOGIN_OPTIONS.has(o.long)) return `login:${o.long}`; + const c = optionClass(o.long); + if (c === "cookie" || c === "login") return `login:${o.long}`; + if (c === "header") return "header"; + if (c === "config") return "config"; } return userinfoUrl ? "login:url" : null; } @@ -601,7 +583,7 @@ export function requestJar(argv: readonly string[]): string | null { // The channel's own proxy in its args (`--proxy`, `--prox`, `--geo-verification- // proxy`, …): today's request, which the channel's explicit proxy carries. export function ownProxy(argv: readonly string[]): boolean { - return argvOptions(argv).options.some((o) => o.long !== null && PROXY_OPTIONS.has(o.long)); + return argvOptions(argv).options.some((o) => o.long !== null && YTDLP_OPTION_CLASSES[o.long] === "proxy"); } // A JAR NEVER USES TWO EXITS: changing a jar's exit while the jar is fresh diff --git a/common/lib/ytdlpOptionClasses.ts b/common/lib/ytdlpOptionClasses.ts @@ -0,0 +1,379 @@ +// WHAT EACH yt-dlp OPTION MEANS FOR A NETWORK EXIT (lane network-exits, +// review 3 nit 5), classified BY A PERSON, one entry per long name of +// lib/ytdlpOptions.ts: +// cookie carries a cookie jar -> the listing goes direct +// login carries an account, a token or acts as one (--mark-watched) +// header sets a request header or spoofs where the request comes from +// config loads other options, code or another program (anything could be in it) +// proxy the channel's own proxy (the listing is today's, untouched) +// none reviewed: changes nothing about who is asking or from where +// An option the table has and this map does not is treated as `config` at run +// time (pinned direct), and lib/networkExits.test.ts FAILS until it is +// classified here: regenerating the table never silently admits a new option. +// Classified for yt-dlp 2026.10.26, 21 Nov 2026. + +export type YtdlpOptionClass = "cookie" | "login" | "header" | "config" | "proxy" | "none"; + +export const YTDLP_OPTION_CLASSES: Readonly<Record<string, YtdlpOptionClass>> = { + "--S-force": "none", + "--abort-on-error": "none", + "--abort-on-unavailable-fragments": "none", + "--add-chapters": "none", + "--add-headers": "header", + "--add-metadata": "none", + "--age-limit": "none", + "--alias": "config", + "--all-formats": "none", + "--all-subs": "none", + "--allow-dynamic-mpd": "none", + "--allow-unplayable-formats": "none", + "--ap-list-mso": "none", + "--ap-mso": "login", + "--ap-password": "login", + "--ap-username": "login", + "--audio-format": "none", + "--audio-multistreams": "none", + "--audio-quality": "none", + "--autonumber-size": "none", + "--autonumber-start": "none", + "--batch-file": "config", + "--bidi-workaround": "none", + "--break-match-filters": "none", + "--break-on-existing": "none", + "--break-on-reject": "none", + "--break-per-input": "none", + "--buffer-size": "none", + "--cache-dir": "none", + "--call-home": "none", + "--check-all-formats": "none", + "--check-formats": "none", + "--clean-info-json": "none", + "--clean-infojson": "none", + "--client-certificate": "login", + "--client-certificate-key": "login", + "--client-certificate-password": "login", + "--cn-verification-proxy": "proxy", + "--color": "none", + "--compat-options": "config", + "--concat-playlist": "none", + "--concurrent-fragments": "none", + "--config-locations": "config", + "--console-title": "none", + "--continue": "none", + "--convert-sub": "none", + "--convert-subs": "none", + "--convert-subtitles": "none", + "--convert-thumbnails": "none", + "--cookies": "cookie", + "--cookies-from-browser": "cookie", + "--date": "none", + "--dateafter": "none", + "--datebefore": "none", + "--default-search": "none", + "--download-archive": "none", + "--download-sections": "none", + "--downloader": "config", + "--downloader-args": "config", + "--dump-json": "none", + "--dump-pages": "none", + "--dump-single-json": "none", + "--dump-user-agent": "none", + "--embed-chapters": "none", + "--embed-info-json": "none", + "--embed-metadata": "none", + "--embed-subs": "none", + "--embed-thumbnail": "none", + "--enable-file-urls": "none", + "--encoding": "none", + "--exec": "config", + "--exec-before-download": "config", + "--external-downloader": "config", + "--external-downloader-args": "config", + "--extract-audio": "none", + "--extractor-args": "login", + "--extractor-descriptions": "none", + "--extractor-retries": "none", + "--ffmpeg-location": "config", + "--file-access-retries": "none", + "--fixup": "none", + "--flat-playlist": "none", + "--force-download-archive": "none", + "--force-generic-extractor": "none", + "--force-ipv4": "none", + "--force-ipv6": "none", + "--force-keyframes-at-cuts": "none", + "--force-overwrites": "none", + "--force-write-archive": "none", + "--force-write-download-archive": "none", + "--format": "none", + "--format-sort": "none", + "--format-sort-force": "none", + "--format-sort-reset": "none", + "--fragment-retries": "none", + "--geo-bypass": "none", + "--geo-bypass-country": "header", + "--geo-bypass-ip-block": "header", + "--geo-verification-proxy": "proxy", + "--get-comments": "none", + "--get-description": "none", + "--get-duration": "none", + "--get-filename": "none", + "--get-format": "none", + "--get-id": "none", + "--get-thumbnail": "none", + "--get-title": "none", + "--get-url": "none", + "--help": "none", + "--hls-prefer-ffmpeg": "none", + "--hls-prefer-native": "none", + "--hls-split-discontinuity": "none", + "--hls-use-mpegts": "none", + "--http-chunk-size": "none", + "--id": "none", + "--ies": "config", + "--ignore-config": "none", + "--ignore-dynamic-mpd": "none", + "--ignore-errors": "none", + "--ignore-no-formats-error": "none", + "--impersonate": "none", + "--include-ads": "none", + "--js-runtimes": "config", + "--keep-fragments": "none", + "--keep-video": "none", + "--lazy-playlist": "none", + "--legacy-server-connect": "none", + "--limit-rate": "none", + "--list-extractors": "none", + "--list-formats": "none", + "--list-formats-as-table": "none", + "--list-formats-old": "none", + "--list-impersonate-targets": "none", + "--list-subs": "none", + "--list-thumbnails": "none", + "--live-from-start": "none", + "--load-info-json": "config", + "--load-pages": "config", + "--mark-watched": "login", + "--match-filters": "none", + "--match-title": "none", + "--max-downloads": "none", + "--max-filesize": "none", + "--max-sleep-interval": "none", + "--max-views": "none", + "--merge-output-format": "none", + "--metadata-from-title": "none", + "--min-filesize": "none", + "--min-sleep-interval": "none", + "--min-views": "none", + "--mtime": "none", + "--netrc": "login", + "--netrc-cmd": "login", + "--netrc-location": "login", + "--newline": "none", + "--no-abort-on-error": "none", + "--no-abort-on-unavailable-fragments": "none", + "--no-add-chapters": "none", + "--no-add-metadata": "none", + "--no-allow-dynamic-mpd": "none", + "--no-allow-unplayable-formats": "none", + "--no-audio-multistreams": "none", + "--no-batch-file": "none", + "--no-break-match-filters": "none", + "--no-break-on-existing": "none", + "--no-break-per-input": "none", + "--no-cache-dir": "none", + "--no-call-home": "none", + "--no-check-certificates": "none", + "--no-check-formats": "none", + "--no-clean-info-json": "none", + "--no-clean-infojson": "none", + "--no-colors": "none", + "--no-colours": "none", + "--no-config": "none", + "--no-config-locations": "none", + "--no-continue": "none", + "--no-cookies": "none", + "--no-cookies-from-browser": "none", + "--no-download": "none", + "--no-download-archive": "none", + "--no-embed-chapters": "none", + "--no-embed-info-json": "none", + "--no-embed-metadata": "none", + "--no-embed-subs": "none", + "--no-embed-thumbnail": "none", + "--no-exec": "none", + "--no-exec-before-download": "none", + "--no-flat-playlist": "none", + "--no-force-keyframes-at-cuts": "none", + "--no-force-overwrites": "none", + "--no-format-sort-force": "none", + "--no-geo-bypass": "none", + "--no-get-comments": "none", + "--no-hls-split-discontinuity": "none", + "--no-hls-use-mpegts": "none", + "--no-ignore-dynamic-mpd": "none", + "--no-ignore-errors": "none", + "--no-ignore-no-formats-error": "none", + "--no-include-ads": "none", + "--no-js-runtimes": "none", + "--no-keep-fragments": "none", + "--no-keep-video": "none", + "--no-lazy-playlist": "none", + "--no-list-formats-as-table": "none", + "--no-live-from-start": "none", + "--no-mark-watched": "none", + "--no-match-filters": "none", + "--no-mtime": "none", + "--no-overwrites": "none", + "--no-part": "none", + "--no-playlist": "none", + "--no-playlist-reverse": "none", + "--no-plugin-dirs": "none", + "--no-post-overwrites": "none", + "--no-prefer-avconv": "none", + "--no-prefer-ffmpeg": "none", + "--no-prefer-free-formats": "none", + "--no-progress": "none", + "--no-quiet": "none", + "--no-remote-components": "none", + "--no-remove-chapters": "none", + "--no-resize-buffer": "none", + "--no-restrict-filenames": "none", + "--no-simulate": "none", + "--no-skip-unavailable-fragments": "none", + "--no-split-chapters": "none", + "--no-split-tracks": "none", + "--no-sponskrub": "none", + "--no-sponskrub-cut": "none", + "--no-sponskrub-force": "none", + "--no-sponsorblock": "none", + "--no-update": "none", + "--no-video-multistreams": "none", + "--no-wait-for-video": "none", + "--no-warnings": "none", + "--no-windows-filenames": "none", + "--no-write-annotations": "none", + "--no-write-auto-subs": "none", + "--no-write-automatic-subs": "none", + "--no-write-comments": "none", + "--no-write-description": "none", + "--no-write-info-json": "none", + "--no-write-playlist-metafiles": "none", + "--no-write-srt": "none", + "--no-write-subs": "none", + "--no-write-thumbnail": "none", + "--no-youtube-include-dash-manifest": "none", + "--no-youtube-include-hls-manifest": "none", + "--no-youtube-skip-dash-manifest": "none", + "--no-youtube-skip-hls-manifest": "none", + "--output": "none", + "--output-na-placeholder": "none", + "--parse-metadata": "none", + "--part": "none", + "--password": "login", + "--paths": "none", + "--playlist-end": "none", + "--playlist-items": "none", + "--playlist-random": "none", + "--playlist-reverse": "none", + "--playlist-start": "none", + "--plugin-dirs": "config", + "--post-overwrites": "none", + "--postprocessor-args": "config", + "--ppa": "config", + "--prefer-avconv": "none", + "--prefer-ffmpeg": "none", + "--prefer-free-formats": "none", + "--prefer-insecure": "none", + "--prefer-unsecure": "none", + "--preset-alias": "none", + "--print": "none", + "--print-json": "none", + "--print-to-file": "none", + "--print-traffic": "config", + "--progress": "none", + "--progress-delta": "none", + "--progress-template": "none", + "--proxy": "proxy", + "--quiet": "none", + "--rate-limit": "none", + "--recode-video": "none", + "--referer": "none", + "--reject-title": "none", + "--remote-components": "config", + "--remove-chapters": "none", + "--remux-video": "none", + "--replace-in-metadata": "none", + "--resize-buffer": "none", + "--restrict-filenames": "none", + "--retries": "none", + "--retry-sleep": "none", + "--rm-cache-dir": "none", + "--simulate": "none", + "--skip-download": "none", + "--skip-playlist-after-errors": "none", + "--skip-unavailable-fragments": "none", + "--sleep-interval": "none", + "--sleep-requests": "none", + "--sleep-subtitles": "none", + "--socket-timeout": "none", + "--source-address": "none", + "--split-chapters": "none", + "--split-tracks": "none", + "--sponskrub": "none", + "--sponskrub-args": "none", + "--sponskrub-cut": "none", + "--sponskrub-force": "none", + "--sponskrub-location": "config", + "--sponsorblock-api": "none", + "--sponsorblock-chapter-title": "none", + "--sponsorblock-mark": "none", + "--sponsorblock-remove": "none", + "--srt-langs": "none", + "--sub-format": "none", + "--sub-langs": "none", + "--test": "none", + "--throttled-rate": "none", + "--trim-file-names": "none", + "--trim-filenames": "none", + "--twofactor": "login", + "--update": "config", + "--update-to": "config", + "--use-extractors": "config", + "--use-postprocessor": "config", + "--user-agent": "none", + "--username": "login", + "--verbose": "none", + "--version": "none", + "--video-multistreams": "none", + "--video-password": "login", + "--wait-for-video": "none", + "--windows-filenames": "none", + "--write-all-thumbnails": "none", + "--write-annotations": "none", + "--write-auto-subs": "none", + "--write-automatic-subs": "none", + "--write-comments": "none", + "--write-description": "none", + "--write-desktop-link": "none", + "--write-info-json": "none", + "--write-link": "none", + "--write-pages": "none", + "--write-playlist-metafiles": "none", + "--write-srt": "none", + "--write-subs": "none", + "--write-thumbnail": "none", + "--write-url-link": "none", + "--write-webloc-link": "none", + "--xattr": "none", + "--xattr-set-filesize": "none", + "--xattrs": "none", + "--xff": "header", + "--yes-overwrites": "none", + "--yes-playlist": "none", + "--youtube-include-dash-manifest": "none", + "--youtube-include-hls-manifest": "none", + "--youtube-print-sig-code": "none", + "--youtube-skip-dash-manifest": "none", + "--youtube-skip-hls-manifest": "none", +}; diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -20,6 +20,10 @@ - Once any network policy exists, no child process (yt-dlp, gallery-dl, ffmpeg, a browser) inherits a proxy variable, and `NETWORK_EXIT_*` is moved out of the environment at boot so no child ever sees it. A policy whose exits are all disabled fails its listings; the key file must be yours, mode 600, under the config directory. + The policy is read from the editor's settings file in every process; when it cannot be read, a policy is + assumed. Saving any policy also takes an inherited proxy from wrangler, git, pnpm and the browsers. The editor + and umtool refuse to start if this guard cannot install. Every yt-dlp option is classified by hand; one that is + not counts as a login. - `pnpm ops network`, `pnpm ops network-exit`, `pnpm ops get network [--probe]`, and /settings → Network exits. The startup probe only connects to each proxy and can be turned off. Not a disguise: no fingerprint or user-agent changes. - **The copies scan dates a re-upload by the stream's day, not the upload's, and says what it could not date.** diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -149,8 +149,10 @@ // umtool ingredient <channel>/<video> [--window <from>-<to>] [--used-in] [--json] a recording's life cycle, nine stages (/ingredients) import process from "node:process"; // What every child inherits (lane network-exits): installed before anything -// can spawn (common/lib/childEnvGuard.mjs). -import "../../common/lib/childEnvGuard.mjs"; +// can spawn (common/lib/childEnvGuard.mjs), and told below which settings +// file holds the policy — the editor's (SETTINGS_FILE, else the checkout's), +// never the cwd's. +import { setNetworkPolicySettingsFile } from "../../common/lib/childEnvGuard.mjs"; import { zstdSupportProblem } from "yt-dlp-transcript-common/lib/zstdSupport.mjs"; import { PROJECT_KINDS, @@ -180,6 +182,10 @@ 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")); + /** What the walk said about a clip, with why when it was rejected: "rejected (irrelevant: covered in c07)". */ const reviewWords = (e) => { const r = rejectionOf(e); @@ -197,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, SITES_DIR } from "../lib/paths.mjs"; +import { ARTICLES_DIR, ARTICLES_KEY, MEDIA_ROOT, MEDIA_TIERED, REPO_ROOT, SITES_DIR } from "../lib/paths.mjs"; import { deliverablesState, moveDeliverables, diff --git a/umtool/instrumentation.ts b/umtool/instrumentation.ts @@ -13,7 +13,7 @@ import { isIdleBoot } from "yt-dlp-transcript-common/lib/idleBoot"; export async function register() { if (process.env.NEXT_RUNTIME !== "nodejs") return; - // WHAT EVERY CHILD INHERITS (lane network-exits, review 2): before anything + // WHAT EVERY CHILD INHERITS (lane network-exits, reviews 2-3): before anything // can spawn, NETWORK_EXIT_* credentials leave process.env and, once a // network policy exists, no child inherits a proxy variable // (common/lib/childEnvGuard.mjs; lib/childEnvGuard.gate.test.ts). @@ -22,7 +22,13 @@ export async function register() { const { getPaths } = await import("yt-dlp-transcript-common/lib/paths"); setNetworkPolicySettingsFile(getPaths().settingsFile); } catch (e) { - console.error(`umtool: the child environment guard failed to install: ${e instanceof Error ? e.message : String(e)}`); + // 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 — ${ + e instanceof Error ? e.message : String(e) + }`, + ); + process.exit(1); } // ARCHILYZER_NO_NETWORK (common/lib/noNetwork.mjs) is the test harness's switch. A server booted with it reaches // no site at all, so it is said first and loudly: set by accident in a service unit, it must not pass for a