commit ef9f9aab9a0fb459da7512ff291aa12801c6c9af
parent a7465e423884d4c1fa05bd5232e04172cd0de235
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 21 Nov 2026 20:46:47 -0500
Merge main into lane/landing-fix
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
5 files changed, 125 insertions(+), 14 deletions(-)
diff --git a/common/controller/xTrendingCooldown.test.ts b/common/controller/xTrendingCooldown.test.ts
@@ -1,6 +1,7 @@
// X's cooldown after a trending read met a rate limit (lane x-trending, review
// 1 SHOULD 5), on the real state file of a temp corpus: 15 minutes on the
-// `twitter` platform entry, read back by the read's own held check.
+// `twitter` platform entry — X's one stop (lane x-sittings) — read back by the
+// read's own held check.
//
// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test controller/xTrendingCooldown.test.ts
@@ -16,10 +17,16 @@ writeFileSync(path.join(ROOT, "settings.json"), "{}");
after(() => rmSync(ROOT, { recursive: true, force: true }));
const { getPaths } = await import("../lib/paths");
-const { platformCooldownRemainingMs, recordPlatformClean, recordPlatformCooldown } = await import("../jobs/downloadBackoff");
+const { clearXStop, clearPlatformHold, platformCooldownRemainingMs, recordPlatformClean, recordPlatformCooldown, xStopRemainingMs } = await import(
+ "../jobs/downloadBackoff"
+);
const { X_RATE_LIMIT_HOLD_MS, xTrendingHeld } = await import("./readXTrending");
-test("no cooldown: a read may start; after a 429: refused until the minute it names; a clean answer settles it", async () => {
+// THE ONE X STOP (lane x-sittings): a trending read's 429 is X's 15-minute
+// stop, the same entry every X job's guard reads — not a cooldown of the
+// read's own — and NOTHING ends it early but the operator's "Clear the X
+// stop" (clearXStop, confirmed): not a clean answer, not Clear hold.
+test("no cooldown: a read may start; after a 429: refused until the minute it names; only the operator's clear ends it early", async () => {
const paths = getPaths();
assert.equal(await xTrendingHeld(paths), null);
const now = Date.now();
@@ -37,8 +44,25 @@ test("no cooldown: a read may start; after a 429: refused until the minute it na
assert.equal(await platformCooldownRemainingMs("bluesky", paths), 0);
// A second, shorter cooldown never brings the end forward.
assert.equal(await recordPlatformCooldown("twitter", 60_000, paths, now), until);
+ // It is the X stop itself, as the guard of every X job reads it.
+ const stop = await xStopRemainingMs(paths, now);
+ assert.equal(stop, until - now);
+ // A clean answer does not clear it, nor does Clear hold: the read stays refused.
await recordPlatformClean("twitter", paths);
- assert.equal(await xTrendingHeld(paths), null);
+ assert.equal(await xStopRemainingMs(paths, now), stop);
+ assert.ok(await xTrendingHeld(paths, now));
+ await clearPlatformHold("twitter", paths);
+ assert.equal(await xStopRemainingMs(paths, now), stop);
+ assert.ok(await xTrendingHeld(paths, now));
+ // The operator's clear, unconfirmed, removes nothing.
+ const asked = await clearXStop(paths, { confirm: false, by: "test", now });
+ assert.equal(asked.ok, false);
+ assert.ok(await xTrendingHeld(paths, now));
+ // Confirmed, it ends the stop, and a read may start again.
+ const cleared = await clearXStop(paths, { confirm: true, by: "test", now });
+ assert.ok(cleared.ok && cleared.cleared?.until === until);
+ assert.equal(await xStopRemainingMs(paths, now), 0);
+ assert.equal(await xTrendingHeld(paths, now), null);
});
// Review 2 N4: a clean trending read settles nothing on the platform. The
diff --git a/common/jobs/instagramPacing.test.ts b/common/jobs/instagramPacing.test.ts
@@ -180,7 +180,22 @@ async function runCount(): Promise<number> {
}
}
+// EVERY JOB'S END ASKS FOR ITS CHANNEL'S REPORT (jobs/snapshotScheduler.ts):
+// a refresh-report a second later, which writes into the channel's dir. Left
+// alone it lands in the next test's reset — or the final cleanup — while that
+// removes the dir: ENOTEMPTY under a loaded run. Before either, the pending
+// regeneration is dropped and any one already started is waited out.
+const { resetSnapshotScheduler } = await import("./snapshotScheduler");
+const { getRegistry } = await import("./registry");
+async function settleReports(): Promise<void> {
+ resetSnapshotScheduler();
+ const busy = () => getRegistry().list().some((j) => j.kind === "refresh-report" && (j.status === "queued" || j.status === "running"));
+ for (let i = 0; i < 400 && busy(); i += 1) await new Promise((r) => setTimeout(r, 25));
+ assert.equal(busy(), false, "a channel report still regenerating after 10 s");
+}
+
async function reset(cookies: string | null = "firefox:ig-profile"): Promise<void> {
+ await settleReports();
clearQueueGaps();
cdn.length = 0;
await rm(RUNS, { force: true });
@@ -194,6 +209,7 @@ async function readLog(jobId: string): Promise<string> {
}
test.after(async () => {
+ await settleReports();
await rm(ROOT, { recursive: true, force: true });
});
diff --git a/common/lib/doNotCleanGate.test.ts b/common/lib/doNotCleanGate.test.ts
@@ -17,7 +17,10 @@ import { fileURLToPath } from "node:url";
const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
const ROOTS = ["common", "editor", "umtool", "mcp", "scripts", "export", "homepage", "plans"];
-const SKIP_DIRS = new Set(["node_modules", ".next", "out", "dist", "public", "e2e", ".e2e-song", "test-results", ".git", "coverage"]);
+// Build and test output, never source. `out-private` is the homepage's private
+// build (gitignored): it holds the published source tree — a copy of every
+// file this gate reads, the one writer and its allow-list among them.
+const SKIP_DIRS = new Set(["node_modules", ".next", "out", "out-private", "dist", "public", "e2e", ".e2e-song", "test-results", ".git", "coverage"]);
const EXT = /\.(ts|tsx|mts|cts|js|mjs|cjs)$/;
const TEST = /\.(test|spec)\.[cm]?[jt]sx?$|\.unit\.ts$/;
diff --git a/common/lib/recordingClock-server.test.ts b/common/lib/recordingClock-server.test.ts
@@ -60,6 +60,31 @@ async function encode(samples: Float32Array, out: string, codec: string[]) {
await rm(raw);
}
+// WHERE THE ENCODER PUT THE START (seconds the decoded file lags its input).
+// Not always zero: lame 4.0's gapless tag says an encoder delay of 47 samples
+// where the stream has 576, so ffmpeg (9.1) decodes its mp3 529 samples —
+// 33 ms at 16 kHz — late. The clock maps the files AS DECODED (what the
+// transcriber hears), so the offsets it must find are the spliced ones plus
+// the toolchain's lags: found here to the sample, independently of the code
+// under test, by matching a decoded second against the input.
+async function decodedLag(file: string, input: Float32Array): Promise<number> {
+ const r = await execa(FFMPEG, ["-v", "error", "-i", file, "-t", "3", "-ac", "1", "-ar", String(SR), "-f", "f32le", "pipe:1"], {
+ encoding: "buffer",
+ });
+ const buf = Buffer.from(r.stdout as Uint8Array);
+ const dec = new Float32Array(Math.floor(buf.length / 4));
+ for (let i = 0; i < dec.length; i += 1) dec[i] = buf.readFloatLE(i * 4);
+ const MAX = Math.round(0.2 * SR);
+ let best = 0;
+ let bestScore = -Infinity;
+ for (let lag = -MAX; lag <= MAX; lag += 1) {
+ let dot = 0;
+ for (let k = MAX; k < MAX + SR; k += 1) dot += input[k] * (dec[k + lag] ?? 0);
+ if (dot > bestScore) [bestScore, best] = [dot, lag];
+ }
+ return best / SR;
+}
+
async function fixture() {
const root = await mkdtemp(path.join(os.tmpdir(), "clock-"));
dirs.push(root);
@@ -81,13 +106,17 @@ async function fixture() {
path.join(videoDir, "saved-video.json"),
JSON.stringify({ storedAt: "2026-11-06T00:00:00.000Z", dir: store, file: "source-media.mp4", bytes }),
);
- return { videoDir, container: path.join(store, "source-media.mp4") };
+ // A span's offset is its splice offset plus (target lag - source lag).
+ const lag = (await decodedLag(path.join(store, "source-media.mp4"), tgt)) - (await decodedLag(path.join(videoDir, "audio.mp3"), src));
+ return { videoDir, container: path.join(store, "source-media.mp4"), lag };
}
const OPTS = { sampleRate: 4000, probeSeconds: 10, searchSeconds: 20, everySeconds: 60, minGapSeconds: 10 };
test("a step and an offset, measured from an mp3 against an AAC mp4, written as clock.json", async () => {
- const { videoDir, container } = await fixture();
+ const { videoDir, container, lag } = await fixture();
+ const before = 2.5 + lag;
+ const afterSplice = 13.1 + lag;
assert.equal((await planRecordingClock(videoDir)).kind, "measure");
const logs: string[] = [];
const r = await ensureRecordingClock({
@@ -104,8 +133,9 @@ test("a step and an offset, measured from an mp3 against an AAC mp4, written as
assert.equal(clock.segments.length, 2, JSON.stringify(clock.segments));
// Exact to the sample: the source decoded from its start, the target seeked
// with a pre-roll (an input seek alone lands an AAC excerpt 10–55 ms off).
- assert.ok(Math.abs(clock.segments[0].offset - 2.5) < 0.002, `before ${clock.segments[0].offset}`);
- assert.ok(Math.abs(clock.segments[1].offset - 13.1) < 0.002, `after ${clock.segments[1].offset}`);
+ // The toolchain's lag is part of what the clock must find (decodedLag).
+ assert.ok(Math.abs(clock.segments[0].offset - before) < 0.002, `before ${clock.segments[0].offset} (expected ${before})`);
+ assert.ok(Math.abs(clock.segments[1].offset - afterSplice) < 0.002, `after ${clock.segments[1].offset} (expected ${afterSplice})`);
assert.ok(Math.abs(clock.segments[1].offset - clock.segments[0].offset - 10.6) < 0.002);
assert.ok(clock.gaps[0].from < 200 && clock.gaps[0].to > 200, JSON.stringify(clock.gaps));
assert.ok((clock.residual.rms ?? 1) < 0.005);
@@ -117,8 +147,9 @@ test("a step and an offset, measured from an mp3 against an AAC mp4, written as
const again = await ensureRecordingClock({ ffmpegBin: FFMPEG, ffprobeBin: FFPROBE, videoDir, options: OPTS });
assert.equal(again.measured, false);
assert.equal(again.plan, "current");
- // The map: a span before the splice +2.5, after it +13.1, across it uncertain.
- assert.ok(Math.abs(clockOffsetAt(clock, 100).offset - 2.5) < 0.002);
+ // The map: a span before the splice +2.5, after it +13.1 (each plus the
+ // toolchain's lag), across it uncertain.
+ assert.ok(Math.abs(clockOffsetAt(clock, 100).offset - before) < 0.002);
assert.equal(mapSpan(clock, 300, 310).certain, true);
assert.equal(mapSpan(clock, 190, 210).certain, false);
});
diff --git a/common/lib/storedText.grep.test.ts b/common/lib/storedText.grep.test.ts
@@ -34,7 +34,11 @@ const COMMON = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
const REPO = path.dirname(COMMON);
const ROOTS = ["common", "editor/app", "editor/lib", "mcp/src", "umtool", "export/scripts", "export/lib", "export/app", "scripts", "docker"];
-const SKIP_DIRS = new Set(["node_modules", ".next", "out", "public", "e2e", "dist", ".turbo"]);
+const SKIP_DIRS = new Set(["node_modules", ".next", "out", "out-private", "public", "e2e", "dist", ".turbo"]);
+// Every dot-directory under these roots is build or test output, never source
+// (umtool's alternate dist dirs `.next-*`, `.e2e-song`, …, all gitignored): a
+// checkout that has run a build holds its compiled chunks, which name the same
+// files as the source they were built from — and the source is what is gated.
// The names of the raw chat in code: the two constants, the stored one, the
// literal (but not its `.part`, its `.zst` spelled out in a comment, or the
@@ -102,7 +106,9 @@ async function walk(dir: string, out: string[]): Promise<void> {
for (const e of entries) {
if (SKIP_DIRS.has(e.name)) continue;
const p = path.join(dir, e.name);
- if (e.isDirectory()) await walk(p, out);
+ if (e.isDirectory()) {
+ if (!e.name.startsWith(".")) await walk(p, out);
+ }
else if (/\.(?:ts|tsx|mjs|js)$/.test(e.name) && !/\.(?:test|spec|unit)\.|\.d\.m?ts$/.test(e.name)) out.push(p);
}
}
@@ -224,6 +230,26 @@ const CALLERS: Record<string, Record<string, number>> = {
downloadSubsForUrl: { "common/ytdlp/runYtdlp.ts": 1 },
};
+// yt-dlp's OPTION TABLES (lane network-exits): every option the installed
+// yt-dlp's parser accepts, and a person's class of each — pure data, outside
+// any function, read only by lib/networkExits.ts to RESOLVE a listing's argv
+// as yt-dlp would (resolveLongOption, argvOptions). Nothing builds an argv
+// from them, so a row naming a subtitle flag writes nothing. Only a table ROW
+// outside every function passes: an argv element in these files, or a row
+// moved into a function, is a site like any other.
+const OPTION_TABLES: { file: string; row: RegExp; why: string }[] = [
+ {
+ file: "common/lib/ytdlpOptions.ts",
+ row: /^\s*\[(?:null|"[^"]+"), "--[a-z0-9-]+", (?:true|false)\],$/,
+ why: "YTDLP_OPTIONS: [short, long, takes a value], generated from yt-dlp's parser",
+ },
+ {
+ file: "common/lib/ytdlpOptionClasses.ts",
+ row: /^\s*"--[a-z0-9-]+": "(?:cookie|login|header|config|proxy|none)",$/,
+ why: "YTDLP_OPTION_CLASSES: the network-exit class of each long name",
+ },
+];
+
const BUILDER_RES = Object.keys(CHAT_WRITERS).map((name) => ({
name,
call: new RegExp(`\\b${name}\\s*\\(`, "g"),
@@ -243,13 +269,16 @@ function enclosingFunction(lines: string[], i: number): string | null {
test("every yt-dlp argv that can write the raw chat is a pinned builder, and every caller of one is pinned", async () => {
const sites: string[] = [];
const calls: Record<string, Record<string, number>> = {};
+ const tableRows = new Set<string>();
for (const { rel, lines } of await appFiles()) {
for (let i = 0; i < lines.length; i++) {
const code = codeOnly(lines[i]);
if (SUB_FLAGS.test(code)) {
const fn = enclosingFunction(lines, i);
const pinned = fn ? CHAT_WRITERS[fn] : undefined;
- if (!pinned || pinned.file !== rel) sites.push(`${rel}:${i + 1} (in ${fn ?? "no function"}): ${lines[i].trim()}`);
+ const table = fn === null ? OPTION_TABLES.find((t) => t.file === rel && t.row.test(code)) : undefined;
+ if (table) tableRows.add(table.file);
+ else if (!pinned || pinned.file !== rel) sites.push(`${rel}:${i + 1} (in ${fn ?? "no function"}): ${lines[i].trim()}`);
}
for (const { name, call, def } of BUILDER_RES) {
if (!code.includes(name)) continue;
@@ -265,6 +294,14 @@ test("every yt-dlp argv that can write the raw chat is a pinned builder, and eve
"for the stored chat first (listingHas / storedFormsIn), have a test that the fake yt-dlp is not asked for it, " +
"and be listed in CHAT_WRITERS",
);
+ // The table exemption cannot rot, and holds only while the tables are read
+ // by the one argv RESOLVER: a new importer of either could build from them.
+ for (const t of OPTION_TABLES) assert.ok(tableRows.has(t.file), `${t.file} has no subtitle-flag row any more: drop it from OPTION_TABLES`);
+ const importers = new Set<string>();
+ for (const { rel, lines } of await appFiles()) {
+ if (lines.some((l) => /\bfrom\s+["'][^"']*\/ytdlpOption(?:s|Classes)(?:\.[jt]s)?["']/.test(codeOnly(l)))) importers.add(rel);
+ }
+ assert.deepEqual([...importers], ["common/lib/networkExits.ts"], "yt-dlp's option tables are read by lib/networkExits.ts alone");
assert.deepEqual(
calls,
CALLERS,