commit d2539fbed33b767c2e342e74d4c53969b6fd558a
parent 1fe254be46893ad4052ab6b0f426c7dc425057a8
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 21 Oct 2026 18:13:02 -0400
tests: Recheck's tests live beside it in controller/ (lib may not import controller)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 131 insertions(+), 74 deletions(-)
diff --git a/common/controller/recheckServiceCookies.test.ts b/common/controller/recheckServiceCookies.test.ts
@@ -0,0 +1,126 @@
+// RECHECK A SERVICE'S COOKIES (cookie refresh alerts,
+// plans/cookie-refresh-alerts.md): one request through the service's own path,
+// the alert cleared when it comes back clean. Every test in a temp transcripts
+// dir; yt-dlp and the forum browser are injected.
+//
+// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test controller/recheckServiceCookies.test.ts
+
+import test from "node:test";
+import assert from "node:assert/strict";
+import { mkdtemp, rm } from "node:fs/promises";
+import os from "node:os";
+import path from "node:path";
+import { readFileSync } from "node:fs";
+import { fileURLToPath } from "node:url";
+import {
+ noteForumServiceOutcome,
+ noteServiceCookieSignal,
+ readServiceCookieState,
+} from "../lib/serviceCookies-server";
+import { isAlertRaised } from "../lib/serviceCookies";
+import { CHALLENGE_PAGE } from "../social/__fixtures__/xenforoPages";
+import { recheckServiceCookies } from "./recheckServiceCookies";
+
+const FIX = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "lib", "__fixtures__");
+const EMBED_403 = readFileSync(path.join(FIX, "rumble-embed-403.download.log"), "utf8");
+const embed403For = (id: string) => EMBED_403.replaceAll("v7ez8hg", id);
+
+type RecheckPaths = Parameters<typeof recheckServiceCookies>[0]["paths"];
+
+async function tmpPaths(): Promise<RecheckPaths> {
+ const transcriptsDir = await mkdtemp(path.join(os.tmpdir(), "service-cookies-recheck-"));
+ return { transcriptsDir, channelsDir: path.join(transcriptsDir, "channels"), ytdlpBin: "yt-dlp" } as RecheckPaths;
+}
+
+test("Recheck (Rumble): one metadata request for the request that failed, with the channel's args and cookies; clean clears and settles the backoff", async () => {
+ const paths = await tmpPaths();
+ try {
+ await noteServiceCookieSignal(paths, { service: "rumble", kind: "embed-403", line: "a", videoId: "e1" }, { url: "https://rumble.com/v1-a.html" });
+ await noteServiceCookieSignal(paths, { service: "rumble", kind: "embed-403", line: "b", videoId: "e2" }, { url: "https://rumble.com/v2-b.html", channel: "huck" });
+ const calls: { cwd: string; args: string[] }[] = [];
+ const settled: string[] = [];
+ let answer = { exitCode: 1, stderrTail: embed403For("e2"), archiveLine: null };
+ const deps = {
+ runYtdlp: async (cwd: string, args: string[]) => {
+ calls.push({ cwd, args });
+ return answer;
+ },
+ readChannelConfig: async () => ({ name: "Huck", url: "https://rumble.com/c/huck", cookiesFromBrowser: "firefox" }) as never,
+ cookieSpec: () => "firefox",
+ recordPlatformClean: async (p: string) => {
+ settled.push(p);
+ return "rumble answered cleanly: its rate-limit backoff is cleared.\n";
+ },
+ };
+ const stale = await recheckServiceCookies({ paths, service: "rumble", deps });
+ assert.equal(stale.result, "stale");
+ assert.equal(calls.length, 1);
+ const args = calls[0].args;
+ assert.equal(args.at(-1), "https://rumble.com/v2-b.html");
+ assert.ok(args.includes("--skip-download"));
+ assert.deepEqual(args.slice(args.indexOf("--print"), args.indexOf("--print") + 2), ["--print", "id"]);
+ assert.deepEqual(args.slice(args.indexOf("--cookies-from-browser"), args.indexOf("--cookies-from-browser") + 2), ["--cookies-from-browser", "firefox"]);
+ assert.ok(args.includes("--impersonate"), "Rumble's own platform args");
+ assert.ok(args.indexOf("--no-write-info-json") > args.indexOf("--cookies-from-browser"), "refusals after the channel's args");
+ assert.equal(calls[0].cwd, path.join(paths.channelsDir, "huck"));
+ assert.equal(isAlertRaised((await readServiceCookieState(paths)).services.rumble), true);
+
+ answer = { exitCode: 0, stderrTail: "", archiveLine: null };
+ const clean = await recheckServiceCookies({ paths, service: "rumble", deps });
+ assert.equal(clean.result, "clean");
+ const state = await readServiceCookieState(paths);
+ assert.equal(state.services.rumble.clearedBy, "recheck");
+ assert.equal(state.lastGood.rumble.url, "https://rumble.com/v2-b.html");
+ assert.deepEqual(settled, ["rumble"]);
+
+ const nothing = await recheckServiceCookies({ paths, service: "odysee", deps });
+ assert.equal(nothing.result, "failed");
+ } finally {
+ await rm(paths.transcriptsDir, { recursive: true, force: true });
+ }
+});
+
+test("Recheck (forum): one page through the profile, judged by classifyForumPage", async () => {
+ const paths = await tmpPaths();
+ try {
+ const url = "https://kiwifarms.st/threads/x.1/";
+ await noteForumServiceOutcome(paths, url, { block: "challenge" });
+ let html = CHALLENGE_PAGE;
+ const loaded: string[] = [];
+ const deps = {
+ loadForumPage: async (_p: unknown, u: string) => {
+ loaded.push(u);
+ return { html };
+ },
+ };
+ assert.equal((await recheckServiceCookies({ paths, service: "kiwifarms.st", deps })).result, "stale");
+ html = `<html data-template="thread_view"><article class="message" data-content="post-1"></article></html>`;
+ assert.equal((await recheckServiceCookies({ paths, service: "kiwifarms.st", deps })).result, "clean");
+ assert.deepEqual(loaded, [url, url]);
+ } finally {
+ await rm(paths.transcriptsDir, { recursive: true, force: true });
+ }
+});
+
+test("Recheck (archive.today): the request that met the check, again; a check still standing keeps it", async () => {
+ const paths = await tmpPaths();
+ try {
+ const url = "https://archive.ph/timemap/https://example.com/page";
+ await noteServiceCookieSignal(paths, { service: "archive.today", kind: "check-page", line: "check" }, { url });
+ const asked: string[] = [];
+ let refuse = true;
+ const deps = {
+ archiveTodayRequest: async (u: string) => {
+ asked.push(u);
+ if (refuse) throw Object.assign(new Error("a CAPTCHA"), { code: "challenge" });
+ },
+ };
+ assert.equal((await recheckServiceCookies({ paths, service: "archive.today", deps })).result, "stale");
+ refuse = false;
+ assert.equal((await recheckServiceCookies({ paths, service: "archive.today", deps })).result, "clean");
+ assert.deepEqual(asked, [url, url]);
+ assert.equal((await readServiceCookieState(paths)).services["archive.today"].clearedBy, "recheck");
+ } finally {
+ await rm(paths.transcriptsDir, { recursive: true, force: true });
+ }
+});
diff --git a/common/lib/serviceCookies-server.test.ts b/common/lib/serviceCookies-server.test.ts
@@ -1,5 +1,6 @@
// Cookie refresh alerts — the file, the job's log line, the yt-dlp hook, the
-// forum and archive.today paths, and Recheck (plans/cookie-refresh-alerts.md).
+// forum and archive.today paths (plans/cookie-refresh-alerts.md; Recheck is
+// controller/recheckServiceCookies.test.ts).
// Every test in a temp transcripts dir.
//
// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/serviceCookies-server.test.ts
@@ -26,7 +27,6 @@ import {
import { isAlertRaised } from "./serviceCookies";
import { classifyForumPage } from "../social/xenforoParse";
import { CHALLENGE_PAGE, LOGIN_PAGE } from "../social/__fixtures__/xenforoPages";
-import { recheckServiceCookies } from "../controller/recheckServiceCookies";
import { ArchiveTodayClient } from "./archives/archiveTodayClient";
import { startFakeArchiveToday, AT_CHECKED_ID, AT_ARTICLE_URL } from "../testing/web/fakeArchiveToday.mjs";
@@ -193,73 +193,3 @@ test("dismiss and re-run marks", async () => {
await rm(paths.transcriptsDir, { recursive: true, force: true });
}
});
-
-test("Recheck (Rumble): one metadata request for the request that failed, with the channel's args and cookies; clean clears and settles the backoff", async () => {
- const paths = { ...(await tmpPaths()), ytdlpBin: "yt-dlp" } as Parameters<typeof recheckServiceCookies>[0]["paths"];
- try {
- await noteServiceCookieSignal(paths, { service: "rumble", kind: "embed-403", line: "a", videoId: "e1" }, { url: "https://rumble.com/v1-a.html" });
- await noteServiceCookieSignal(paths, { service: "rumble", kind: "embed-403", line: "b", videoId: "e2" }, { url: "https://rumble.com/v2-b.html", channel: "huck" });
- const calls: { cwd: string; args: string[] }[] = [];
- const settled: string[] = [];
- let answer = { exitCode: 1, stderrTail: embed403For("e2"), archiveLine: null };
- const deps = {
- runYtdlp: async (cwd: string, args: string[]) => {
- calls.push({ cwd, args });
- return answer;
- },
- readChannelConfig: async () => ({ name: "Huck", url: "https://rumble.com/c/huck", cookiesFromBrowser: "firefox" }) as never,
- cookieSpec: () => "firefox",
- recordPlatformClean: async (p: string) => {
- settled.push(p);
- return "rumble answered cleanly: its rate-limit backoff is cleared.\n";
- },
- };
- const stale = await recheckServiceCookies({ paths, service: "rumble", deps });
- assert.equal(stale.result, "stale");
- assert.equal(calls.length, 1);
- const args = calls[0].args;
- assert.equal(args.at(-1), "https://rumble.com/v2-b.html");
- assert.ok(args.includes("--skip-download"));
- assert.deepEqual(args.slice(args.indexOf("--print"), args.indexOf("--print") + 2), ["--print", "id"]);
- assert.deepEqual(args.slice(args.indexOf("--cookies-from-browser"), args.indexOf("--cookies-from-browser") + 2), ["--cookies-from-browser", "firefox"]);
- assert.ok(args.includes("--impersonate"), "Rumble's own platform args");
- assert.ok(args.indexOf("--no-write-info-json") > args.indexOf("--cookies-from-browser"), "refusals after the channel's args");
- assert.equal(calls[0].cwd, path.join(paths.channelsDir, "huck"));
- assert.equal(isAlertRaised((await readServiceCookieState(paths)).services.rumble), true);
-
- answer = { exitCode: 0, stderrTail: "", archiveLine: null };
- const clean = await recheckServiceCookies({ paths, service: "rumble", deps });
- assert.equal(clean.result, "clean");
- const state = await readServiceCookieState(paths);
- assert.equal(state.services.rumble.clearedBy, "recheck");
- assert.equal(state.lastGood.rumble.url, "https://rumble.com/v2-b.html");
- assert.deepEqual(settled, ["rumble"]);
-
- const nothing = await recheckServiceCookies({ paths, service: "odysee", deps });
- assert.equal(nothing.result, "failed");
- } finally {
- await rm(paths.transcriptsDir, { recursive: true, force: true });
- }
-});
-
-test("Recheck (forum): one page through the profile, judged by classifyForumPage", async () => {
- const paths = { ...(await tmpPaths()), ytdlpBin: "yt-dlp" } as Parameters<typeof recheckServiceCookies>[0]["paths"];
- try {
- const url = "https://kiwifarms.st/threads/x.1/";
- await noteForumServiceOutcome(paths, url, { block: "challenge" });
- let html = CHALLENGE_PAGE;
- const loaded: string[] = [];
- const deps = {
- loadForumPage: async (_p: unknown, u: string) => {
- loaded.push(u);
- return { html };
- },
- };
- assert.equal((await recheckServiceCookies({ paths, service: "kiwifarms.st", deps })).result, "stale");
- html = `<html data-template="thread_view"><article class="message" data-content="post-1"></article></html>`;
- assert.equal((await recheckServiceCookies({ paths, service: "kiwifarms.st", deps })).result, "clean");
- assert.deepEqual(loaded, [url, url]);
- } finally {
- await rm(paths.transcriptsDir, { recursive: true, force: true });
- }
-});
diff --git a/plans/cookie-refresh-alerts.md b/plans/cookie-refresh-alerts.md
@@ -76,9 +76,10 @@ Files:
Tests: `common/lib/serviceCookies.test.ts` (15: the real Rumble samples — `lib/__fixtures__/rumble-*.log`, scrubbed —
the two-videos rule, a removed page's and a media 403, the same video twice, the streak broken by a clean request,
the pending TTL, YouTube's bot check, Odysee with and without Cloudflare's words, clearing/pruning, coercion, the
-view), `common/lib/serviceCookies-server.test.ts` (10: the job's log line, the yt-dlp hook both ways, no-op writes,
+view), `common/lib/serviceCookies-server.test.ts` (8: the job's log line, the yt-dlp hook both ways, no-op writes,
the lock, a torn file, Kiwi Farms' challenge page, archive.today's check page through the client and its fake,
-dismiss/rerun, Recheck for Rumble and a forum), `bin/doctor.test.ts`, `scripts/archilyzer-ops.test.mjs`,
+dismiss/rerun), `common/controller/recheckServiceCookies.test.ts` (3: Rumble's probe argv and both answers, a
+forum page, archive.today), `bin/doctor.test.ts`, `scripts/archilyzer-ops.test.mjs`,
`editor/app/api/ops/_writes.test.ts`, `editor/app/api/view/[name]/route.test.ts`, and e2e
`editor/e2e/cookie-alerts.spec.ts` (fake yt-dlp `embed403` → two 403s → banner → Recheck stale → fresh cookies →
Recheck clean → "OK again — re-run the 1 job it stopped" → Re-run → the batch finishes `done`).