import { test } from "node:test"; import assert from "node:assert/strict"; import { DEFAULT_SEEDER_SETTINGS, sanitizeSeeder, seederConfigured } from "./seederSettings"; // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/seederSettings.test.ts test("absent or garbage is the default, which is not configured", () => { for (const v of [undefined, null, "x", 3, [], { sites: "jeralyzer-private" }]) { const s = sanitizeSeeder(v); assert.deepEqual(s.sites, []); assert.equal(seederConfigured(s), false, JSON.stringify(v)); } assert.deepEqual(sanitizeSeeder({}), DEFAULT_SEEDER_SETTINGS); }); test("sites and trackers keep only well-formed, distinct entries", () => { const s = sanitizeSeeder({ sites: ["jeralyzer-private", " jeralyzer-private ", "BAD ID", 3, "../x"], trackers: ["wss://tracker.example/announce", "http://10.0.0.2:8000/announce", "udp://t.example:6969", "file:///etc/passwd", "not a url"], }); assert.deepEqual(s.sites, ["jeralyzer-private"]); assert.deepEqual(s.trackers, ["wss://tracker.example/announce", "http://10.0.0.2:8000/announce", "udp://t.example:6969"]); assert.equal(seederConfigured(s), true); }); test("numbers are clamped, and a bad interface name reads as unset", () => { const s = sanitizeSeeder({ maxUploadKiBps: -5, maxConnections: 10_000, pollSeconds: 1, standbyAfterSeconds: 10, bindInterface: "wg0; rm -rf /", }); assert.equal(s.maxUploadKiBps, 0); assert.equal(s.maxConnections, 500); assert.equal(s.pollSeconds, 10); assert.equal(s.standbyAfterSeconds, 60); assert.equal(s.bindInterface, ""); assert.equal(sanitizeSeeder({ bindInterface: " wg0 " }).bindInterface, "wg0"); });