// Integration: a SALVAGE transcript is marked on its index record and its // published page (release 30, lane Q) — `salvaged: {decodedSeconds, // totalSeconds}` from transcribe-outcome.json — and only there: every other // record's page bytes are what they were, and a clean re-transcription drops // the mark. Synthetic records through the REAL buildIndex over a temp corpus. // // Run with: node_modules/.bin/tsx --test common/controller/buildIndexSalvaged.test.ts import { after, test } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, utimesSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; const ROOT = mkdtempSync(path.join(tmpdir(), "build-index-salvaged-")); const PINNED: Record = { TRANSCRIPTS_DIR: path.join(ROOT, "transcripts"), SAVED_VIDEOS_DIR: path.join(ROOT, "saved-videos"), SITES_DIR: path.join(ROOT, "transcripts", "sites"), SETTINGS_FILE: path.join(ROOT, "settings.json"), EXPORT_PUBLIC_DIR: path.join(ROOT, "public"), EXPORT_INDEX_DIR: path.join(ROOT, ".export-index"), EXPORT_BUILDS_DIR: path.join(ROOT, ".export-builds"), EDITOR_CHANGELOG_FILE: path.join(ROOT, "editor-CHANGELOG.md"), EXPORT_CHANGELOG_FILE: path.join(ROOT, "export-CHANGELOG.md"), CHARTS_CONFIG_FILE: path.join(ROOT, "chart-templates.json"), SEARCH_ALIASES_FILE: path.join(ROOT, "transcripts", "search-aliases.json"), CURATED_TAGS_FILE: path.join(ROOT, "transcripts", "tags.json"), ARCHILYZER_CONFIG_DIR: path.join(ROOT, "config"), ARCHILYZER_SOURCE_SCRATCH: path.join(ROOT, "source-scratch"), }; Object.assign(process.env, PINNED); delete process.env.ARCHILYZER_INDEX_ALLOW_HELD; after(() => rmSync(ROOT, { recursive: true, force: true })); const { getPaths } = await import("../lib/paths"); const { buildIndex } = await import("./buildIndex"); const { open } = await import("lmdb"); const paths = getPaths(); const SLUG = "example-salvage"; const SITE = "testsite"; const writeJson = (file: string, value: unknown) => { mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, JSON.stringify(value, null, 2)); }; const dirOf = (id: string) => path.join(paths.channelsDir, SLUG, "data", id); function video(id: string, salvaged?: { decodedSeconds: number; totalSeconds: number; gaps: number[][] }) { const dir = dirOf(id); writeJson(path.join(dir, "metadata.info.json"), { id, title: `Recording ${id}`, upload_date: "20260105", duration: 6000, webpage_url: `https://odysee.com/@example:0/${id}:0`, extractor_key: "LBRY", }); writeJson(path.join(dir, "transcript.json"), { chunk_data: [{ start_time: 1, end_time: 2, text: "a synthetic line" }], }); writeJson(path.join(dir, "transcribe-outcome.json"), { videoId: id, transcribedAt: "2026-10-15T00:00:00.000Z", ...(salvaged ? { salvaged: { source: "audio.mp4", ...salvaged } } : {}), }); } function pagesOf(slug: string): string { const dir = path.join(paths.exportSharedTranscriptsDir, slug); return readdirSync(dir) .filter((f) => f.startsWith("page-")) .map((f) => readFileSync(path.join(dir, f), "utf8")) .join("\n"); } function records(): Record { const out: Record = {}; for (const page of pagesOf(SLUG).split("\n").filter(Boolean)) { for (const r of JSON.parse(page) as Array<{ id: string; salvaged?: unknown }>) out[r.id] = r.salvaged; } return out; } test("a salvage transcript's record says how much decoded; a clean one says nothing", async () => { writeFileSync(paths.settingsFile, "{}"); writeJson(path.join(paths.channelsDir, SLUG, "config.json"), { handling: "transcribe", name: SLUG }); writeJson(path.join(paths.sitesDir, SITE, "site.json"), { siteId: SITE, siteTitle: "Test Site", siteDescription: "fixture", headerTitle: "Test Site", homeTagline: "", socialLinks: [], groups: [{ id: "default", name: "All channels", selectedByDefault: true }], defaultGroupId: "default", channels: [{ slug: SLUG, groupId: "default" }], }); video("SalvagedRec1", { decodedSeconds: 2335, totalSeconds: 6000, gaps: [[2335, 6000]] }); video("CleanRec0001"); await buildIndex({ paths, onLog: () => {} }); assert.deepEqual(records(), { SalvagedRec1: { decodedSeconds: 2335, totalSeconds: 6000 }, CleanRec0001: undefined, }); // The gaps stay on disk; the record carries the two numbers. assert.doesNotMatch(pagesOf(SLUG), /gaps/); // Transcribed again from clean audio: the mark goes. video("SalvagedRec1"); const later = new Date(Date.now() + 5000); utimesSync(path.join(dirOf("SalvagedRec1"), "transcript.json"), later, later); await buildIndex({ paths, onLog: () => {} }); assert.deepEqual(records(), { SalvagedRec1: undefined, CleanRec0001: undefined }); assert.doesNotMatch(pagesOf(SLUG), /salvaged/); });