import { test } from "node:test"; import assert from "node:assert/strict"; import type { ChannelConfig } from "../lib/channelConfig"; import { defaultSyncScheduler, type SyncSchedulerSettings } from "../lib/settings"; import { isFullSweepDue, resolveFullSweepIntervalMinutes } from "./deepSync"; // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test common/jobs/deepSync.test.ts function channel(over: Partial = {}): ChannelConfig { return { handling: "transcribe", url: "https://example.com/c", ...over }; } function scheduler(over: Partial = {}): SyncSchedulerSettings { return { ...defaultSyncScheduler(), ...over }; } const NOW = Date.parse("2026-08-04T12:00:00.000Z"); const MIN = 60_000; test("an unset channel interval inherits the global default", () => { assert.equal( resolveFullSweepIntervalMinutes( channel(), scheduler({ fullSweepIntervalMinutes: 720 }), ), 720, ); }); test("a channel override beats the global default", () => { assert.equal( resolveFullSweepIntervalMinutes( channel({ fullSweepIntervalMinutes: 10080 }), scheduler({ fullSweepIntervalMinutes: 1440 }), ), 10080, ); }); test("a channel override of 0 beats a nonzero global (explicit off)", () => { assert.equal( resolveFullSweepIntervalMinutes( channel({ fullSweepIntervalMinutes: 0 }), scheduler({ fullSweepIntervalMinutes: 1440 }), ), 0, ); }); test("a never-swept channel is due immediately", () => { assert.equal(isFullSweepDue(undefined, 1440, NOW), true); }); test("an unparseable timestamp is treated as never swept", () => { assert.equal(isFullSweepDue("not a date", 1440, NOW), true); }); test("interval 0 is never due, even having never swept", () => { assert.equal(isFullSweepDue(undefined, 0, NOW), false); assert.equal( isFullSweepDue(new Date(NOW - 365 * 24 * 60 * MIN).toISOString(), 0, NOW), false, ); }); test("a negative interval is never due", () => { assert.equal(isFullSweepDue(undefined, -5, NOW), false); }); test("not due one minute short of the interval", () => { const last = new Date(NOW - 1439 * MIN).toISOString(); assert.equal(isFullSweepDue(last, 1440, NOW), false); }); test("due at exactly the interval boundary", () => { const last = new Date(NOW - 1440 * MIN).toISOString(); assert.equal(isFullSweepDue(last, 1440, NOW), true); }); test("due once past the interval", () => { const last = new Date(NOW - 1441 * MIN).toISOString(); assert.equal(isFullSweepDue(last, 1440, NOW), true); }); test("a sweep that just ran is not due again", () => { assert.equal(isFullSweepDue(new Date(NOW).toISOString(), 1440, NOW), false); }); test("the shipped default is a daily sweep with a confirm cap", () => { const d = defaultSyncScheduler(); assert.equal(d.fullSweepIntervalMinutes, 1440); assert.equal(d.fullSweepConfirmMaxSuspects, 25); });