Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit fcef7b97140f9823dad492bebc0f9f3784f01d37
parent 2975a8239fdfcd01496a03d5837c12205b1eef10
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 10 Oct 2026 14:00:03 -0400

common: a rewrite keeps what a provenance writer applied (release 24 H3)

`pnpm ops persist-videos` over Wayback JW records rewrote metadata.info.json
from the capture: the title went back to `<id>-<rendition>` and upload_date
vanished, so the next index skipped them. Nothing in the info json marks a
provenance-applied field; the history does. withMetadataHistory now runs
keepProvenanceInFile after any writer that is not a provenance writer
(wayback-provenance, archiveorg-provenance, feed-backfill), before the
entry is recorded: a key a provenance entry set that the rewrite lacks, or
carries at a value a provenance entry replaced, gets the newest provenance
value back (title after the id, anything absent at the end); any other
value is the source's and lands. A record a prefetch already reverted heals
on its next rewrite. The rewrite's own history entry is still written, net
of the kept fields.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mcommon/controller/refreshVideoMetadata.ts | 7++++---
Mcommon/lib/metadataHistory-server.test.ts | 151++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/metadataHistory-server.ts | 52+++++++++++++++++++++++++++++++++++++++++++++++++---
Mcommon/lib/metadataHistory.test.ts | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/metadataHistory.ts | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/ytdlp/downloadOneManaged.ts | 4+++-
Mcommon/ytdlp/forceMedia.test.ts | 39+++++++++++++++++++++++++++++++++++++++
7 files changed, 411 insertions(+), 7 deletions(-)

diff --git a/common/controller/refreshVideoMetadata.ts b/common/controller/refreshVideoMetadata.ts @@ -30,9 +30,10 @@ // // NOT FOR A RECORD yt-dlp DID NOT WRITE. An archive.org record, a Wayback copy // and a record completed from a podcast feed hold metadata their own writers -// put there; a yt-dlp re-read would replace it with what the bare URL says (the -// hazard the persist prefetch already has with Wayback titles). Those are -// refused, by URL and by the writers in the history. +// put there; a yt-dlp re-read would replace it with what the bare URL says. +// Those are refused, by URL and by the writers in the history. (A managed +// download's prefetch over such a record keeps the provenance's fields since +// release 24 H3 — lib/metadataHistory.ts keepProvenanceFields.) // // A RATE LIMIT IS RECORDED, NOT RETRIED: the caller's `onPlatformBackoff` // writes the shared per-platform cooldown the download lane honours, and the diff --git a/common/lib/metadataHistory-server.test.ts b/common/lib/metadataHistory-server.test.ts @@ -175,3 +175,154 @@ test("patchMetadataInfo refuses a missing file or one that is not a JSON object" await assert.rejects(patchMetadataInfo(dir, { title: "x" }, { by: "feed-backfill" }), /not JSON/); }); }); + +// ── Release 24 H3: a rewrite keeps what a provenance writer applied ────────── + +const readInfo = async (dir: string) => JSON.parse(await readFile(path.join(dir, INFO), "utf8")); + +// A raw JW Player file captured by the Wayback Machine, as yt-dlp's generic +// extractor writes it: the title is the file's name, and there is no date. +const CAPTURE = "https://web.archive.org/web/20190405000000/https://cdn.example.test/videos/AbCd1234-720.mp4"; +const waybackCapture = (extra: Record<string, unknown> = {}) => + JSON.stringify({ + id: "AbCd1234-720", + title: "AbCd1234-720", + webpage_url: CAPTURE, + extractor_key: "Generic", + formats: [{ url: `${CAPTURE}?sig=${Math.random()}` }], + ...extra, + }); + +test("a prefetch over a Wayback record keeps the title and date the provenance set; a new field lands", async () => { + await withDir(async (dir) => { + await writeFile(path.join(dir, INFO), waybackCapture()); + await patchMetadataInfo( + dir, + { title: "The Real Title", upload_date: "20190405" }, + { by: "wayback-provenance", requestedBy: "cli" }, + ); + const lines: string[] = []; + await withMetadataHistory(dir, { by: "prefetch", onLog: (l) => lines.push(l) }, async () => { + // The persist prefetch rewrites the file from the capture again. + await writeFile(path.join(dir, INFO), waybackCapture({ duration: 61.5 })); + }); + const info = await readInfo(dir); + assert.equal(info.title, "The Real Title"); + assert.equal(info.upload_date, "20190405"); + assert.equal(info.duration, 61.5, "a genuinely new field still lands"); + // The title stays in the head, the date is the tail's last key. + assert.deepEqual(Object.keys(info), ["id", "title", "webpage_url", "extractor_key", "formats", "duration", "upload_date"]); + assert.ok(lines.some((l) => /^Kept what the provenance set over this rewrite: title, upload_date/.test(l)), lines.join("")); + // The prefetch's entry is still written, net of the kept fields. + const h = await loadMetadataHistory(dir); + assert.deepEqual(h?.entries.map((e) => e.by), ["wayback-provenance", "prefetch"]); + const pre = h!.entries[1]; + assert.deepEqual(pre.changed, {}); + assert.deepEqual(pre.added, { duration: 61.5 }); + assert.deepEqual(pre.removed, {}); + assert.deepEqual(pre.volatile, ["formats"]); + + // A title the source genuinely changed is the source's. + await withMetadataHistory(dir, { by: "prefetch" }, async () => { + await writeFile(path.join(dir, INFO), waybackCapture({ title: "Retitled At The Source" })); + }); + const again = await readInfo(dir); + assert.equal(again.title, "Retitled At The Source"); + assert.equal(again.upload_date, "20190405"); + }); +}); + +test("a record a prefetch already reverted gets the provenance's fields back on the next rewrite", async () => { + await withDir(async (dir) => { + await writeFile(path.join(dir, INFO), waybackCapture()); + await patchMetadataInfo(dir, { title: "The Real Title", upload_date: "20190405" }, { by: "wayback-provenance" }); + // The history a pre-H3 prefetch left: the placeholder back, the date gone. + const reverted = await readInfo(dir); + const h = await loadMetadataHistory(dir); + await writeFile( + metadataHistoryPath(dir), + JSON.stringify({ + entries: [ + ...h!.entries, + { + at: "2026-10-06T00:00:00.000Z", + by: "prefetch", + from: { sha256: "a".repeat(64), bytes: 1 }, + to: { sha256: "b".repeat(64), bytes: 1 }, + changed: { title: { from: "The Real Title", to: "AbCd1234-720" } }, + added: {}, + removed: { upload_date: "20190405" }, + counters: {}, + volatile: ["formats"], + }, + ], + }), + ); + assert.equal(reverted.title, "The Real Title"); + await writeFile(path.join(dir, INFO), waybackCapture()); + await withMetadataHistory(dir, { by: "audio-check" }, async () => { + await writeFile(path.join(dir, INFO), waybackCapture()); + }); + const info = await readInfo(dir); + assert.equal(info.title, "The Real Title"); + assert.equal(info.upload_date, "20190405"); + }); +}); + +test("an archive.org re-import keeps the mirror's title and date and the dropped timestamp; a new field lands", async () => { + await withDir(async (dir) => { + // As imported: the item's title and date, and the timestamp yt-dlp + // derived from the item's publicdate. + const item = (extra: Record<string, unknown> = {}) => + JSON.stringify({ + id: "some-item--show-2019-03-01", + title: "Some Item", + webpage_url: "https://archive.org/details/some-item/show-2019-03-01.mp4", + extractor_key: "ArchiveOrg", + timestamp: 1577836800, + formats: [{ url: "https://archive.org/download/some-item/show-2019-03-01.mp4" }], + ...extra, + upload_date: "20200101", + }); + await writeFile(path.join(dir, INFO), item()); + await patchMetadataInfo( + dir, + { title: "The Mirror's Title", upload_date: "20190301", timestamp: null }, + { by: "archiveorg-provenance" }, + ); + await withMetadataHistory(dir, { by: "archiveorg-import" }, async () => { + await writeFile(path.join(dir, INFO), item({ description: "now described" })); + }); + const info = await readInfo(dir); + assert.equal(info.title, "The Mirror's Title"); + assert.equal(info.upload_date, "20190301"); + assert.equal(info.timestamp, null); + assert.equal(info.description, "now described"); + const h = await loadMetadataHistory(dir); + assert.deepEqual(h?.entries.map((e) => e.by), ["archiveorg-provenance", "archiveorg-import"]); + assert.deepEqual(h!.entries[1].added, { description: "now described" }); + assert.deepEqual(h!.entries[1].changed, {}); + }); +}); + +test("a provenance writer is never kept against, and a record with no provenance is the rewrite's", async () => { + await withDir(async (dir) => { + await writeFile(path.join(dir, INFO), waybackCapture()); + await patchMetadataInfo(dir, { title: "First Find" }, { by: "wayback-provenance" }); + // The operator's next find replaces the first. + await patchMetadataInfo(dir, { title: "Better Find" }, { by: "wayback-provenance" }); + assert.equal((await readInfo(dir)).title, "Better Find"); + // A placeholder rewrite now restores the newest find. + await withMetadataHistory(dir, { by: "prefetch" }, async () => { + await writeFile(path.join(dir, INFO), waybackCapture()); + }); + assert.equal((await readInfo(dir)).title, "Better Find"); + }); + await withDir(async (dir) => { + await writeFile(path.join(dir, INFO), meta("old")); + await withMetadataHistory(dir, { by: "prefetch" }, async () => { + await writeFile(path.join(dir, INFO), meta("new")); + }); + assert.equal((await readInfo(dir)).title, "new"); + }); +}); diff --git a/common/lib/metadataHistory-server.ts b/common/lib/metadataHistory-server.ts @@ -18,9 +18,12 @@ // so this needs a directory left by an earlier pass that was NOT rejected (a // failed download, say) and a filter that rejects it now. // -// THE FILE yt-dlp WRITES IS STILL THE FILE. Nothing here changes what lands in -// metadata.info.json; it reads the old bytes before the spawn and the new ones -// after it, and appends what moved. +// THE FILE yt-dlp WRITES IS STILL THE FILE — with one exception (release 24 +// H3): a field a provenance writer applied (a Wayback copy's title and date, +// an archive.org mirror's, a feed entry's) that the rewrite lost, or reverted +// to the placeholder the provenance replaced, is put back before the entry is +// recorded (keepProvenanceInFile). Otherwise it reads the old bytes before the +// spawn and the new ones after it, and appends what moved. // // SERVER-ONLY (node:fs). @@ -30,7 +33,9 @@ import { withJsonFileLock, writeJsonAtomic } from "./jsonFile-server"; import { sidecar, sidecarField } from "./sidecar-server"; import { METADATA_HISTORY_FILENAME, + PROVENANCE_WRITERS, appendMetadataHistoryEntry, + keepProvenanceFields, buildMetadataHistoryEntry, coerceMetadataHistory, type MetadataHistoryEntry, @@ -124,6 +129,16 @@ export async function withMetadataHistory<T>( return await run(); } finally { if (before) { + // A rewrite by anything but a provenance writer keeps what one applied + // (release 24 H3, keepProvenanceFields) — BEFORE the entry is recorded, + // so the entry says what the rewrite changed net of the kept fields. + if (!PROVENANCE_WRITERS.has(ctx.by)) { + try { + await keepProvenanceInFile(videoDir, before, ctx.onLog); + } catch (err) { + ctx.onLog?.(`Could not keep the provenance's fields: ${(err as Error).message}\n`); + } + } try { const entry = await recordMetadataRewrite(videoDir, before, ctx); if (entry) ctx.onEntry?.(entry); @@ -136,6 +151,37 @@ export async function withMetadataHistory<T>( } } +// After a rewrite of metadata.info.json (its bytes differ from `before`): put +// back every field a provenance writer applied that the rewrite lost or +// reverted to the placeholder it replaced (lib/metadataHistory.ts +// keepProvenanceFields, over the history as it stood before this rewrite). +// Returns the keys kept. Not under the file's lock: it runs inside the wrap a +// yt-dlp spawn runs in, which does not lock either (patchMetadataInfo's +// caveat), and patchMetadataInfo — which does — is a provenance writer's, +// never asked to keep. +export async function keepProvenanceInFile( + videoDir: string, + before: MetadataSnapshot, + onLog?: (line: string) => void, +): Promise<string[]> { + const after = await snapshotMetadata(videoDir); + if (!after || after.text.equals(before.text)) return []; + let fresh: unknown; + try { + fresh = JSON.parse(after.text.toString("utf8")); + } catch { + return []; + } + if (typeof fresh !== "object" || fresh === null || Array.isArray(fresh)) return []; + const history = await loadMetadataHistory(videoDir).catch(() => null); + if (!history?.entries.length) return []; + const { next, kept } = keepProvenanceFields(history, fresh as Record<string, unknown>); + if (kept.length === 0) return []; + await writeJsonAtomic(path.join(videoDir, INFO_JSON), next, { indent: 0, newline: false }); + onLog?.(`Kept what the provenance set over this rewrite: ${kept.join(", ")} (metadata.history.json).\n`); + return kept; +} + // THE ONE WRITER OF metadata.info.json THAT IS NOT yt-dlp: merge `patch` into // the file on disk, inside `withMetadataHistory`, so the rewrite is recorded // exactly as a yt-dlp one is (by `ctx.by`, with what moved). diff --git a/common/lib/metadataHistory.test.ts b/common/lib/metadataHistory.test.ts @@ -10,6 +10,8 @@ import { isValueDigest, normalizeForDiff, type MetadataHistoryEntry, + keepProvenanceFields, + provenanceClaims, } from "./metadataHistory"; // Run with: @@ -213,3 +215,69 @@ test("coerceMetadataHistory keeps good entries and drops torn ones", () => { entries: [good], }); }); + +// ── Release 24 H3: keepProvenanceFields ────────────────────────────────────── + +function provEntry(by: string, diff: Partial<Pick<MetadataHistoryEntry, "changed" | "added" | "removed">>): MetadataHistoryEntry { + return { + at: "2026-10-01T00:00:00.000Z", + by: by as MetadataHistoryEntry["by"], + from: { sha256: "a".repeat(64), bytes: 1 }, + to: { sha256: "b".repeat(64), bytes: 1 }, + changed: {}, + added: {}, + removed: {}, + counters: {}, + volatile: [], + ...diff, + }; +} + +test("provenanceClaims: the newest provenance value per key, every value it replaced; other writers ignored", () => { + const claims = provenanceClaims({ + entries: [ + provEntry("wayback-provenance", { changed: { title: { from: "f-720", to: "First" } }, added: { upload_date: "20190405" } }), + provEntry("prefetch", { changed: { title: { from: "First", to: "f-720" } }, removed: { upload_date: "20190405" } }), + provEntry("wayback-provenance", { changed: { title: { from: "f-720", to: "Better" } } }), + provEntry("archiveorg-provenance", { changed: { timestamp: { from: 1, to: null } }, removed: { uploader: "a@b" } }), + provEntry("feed-backfill", { added: { description: { sha256: "c".repeat(64), bytes: 20000 }, subtitles_langs: ["en"] } }), + ], + }); + assert.deepEqual(Object.fromEntries(claims), { + title: { value: "Better", replaced: ["f-720", "First", "f-720"] }, + upload_date: { value: "20190405", replaced: [] }, + timestamp: { value: null, replaced: [1] }, + uploader: { value: undefined, replaced: ["a@b"] }, + }); + assert.equal(provenanceClaims(null).size, 0); +}); + +test("keepProvenanceFields: a lost or placeholder field comes back, a new value lands, order kept for the byte readers", () => { + const history = { + entries: [ + provEntry("wayback-provenance", { + changed: { title: { from: "f-720", to: "Real" } }, + added: { upload_date: "20190405" }, + }), + provEntry("archiveorg-provenance", { removed: { uploader: "a@b" } }), + ], + }; + // Title reverted, date gone, the removed key back: all three kept. + const r = keepProvenanceFields(history, { id: "f", title: "f-720", uploader: "a@b", duration: 3 }); + assert.deepEqual(r.kept.sort(), ["title", "upload_date", "uploader"]); + assert.deepEqual(r.next, { id: "f", title: "Real", duration: 3, upload_date: "20190405" }); + // A title lost entirely goes right after the id. + assert.deepEqual(Object.keys(keepProvenanceFields(history, { id: "f", duration: 3 }).next), [ + "id", + "title", + "duration", + "upload_date", + ]); + // A new title and date from the source land; nothing to keep is `fresh` itself. + const fresh = { id: "f", title: "Retitled", upload_date: "20200101" }; + const none = keepProvenanceFields(history, fresh); + assert.deepEqual(none.kept, []); + assert.equal(none.next, fresh); + // No history: the rewrite's. + assert.deepEqual(keepProvenanceFields(null, { id: "f", title: "f-720" }).kept, []); +}); diff --git a/common/lib/metadataHistory.ts b/common/lib/metadataHistory.ts @@ -397,3 +397,100 @@ export function coerceMetadataHistory(value: unknown): MetadataHistory | null { ); return { entries }; } + +// ── WHAT A PROVENANCE WRITER APPLIED, KEPT OVER A LATER REWRITE ────────────── +// +// Release 24 H3. A record yt-dlp cannot describe is completed by a writer that +// is not yt-dlp: a raw Wayback file's title and date as the operator found +// them (`wayback-provenance`), an archive.org record's mirror title and date +// (`archiveorg-provenance`), a podcast episode's feed entry (`feed-backfill`). +// A later managed download rewrites the whole file from the source again — the +// persist prefetch put a Wayback JW record's title back to `<id>-<rendition>` +// and dropped its upload_date, and the next index skipped the record. Nothing +// in the info json marks a field as provenance-applied; the HISTORY does: each +// of those writers' entries names the key, the value it wrote and the value it +// replaced. +// +// The rule (keepProvenanceFields): for each key a provenance writer last set, +// a rewrite that LACKS the key, or carries exactly a value a provenance entry +// replaced (the capture's own placeholder, or an earlier find a later one +// superseded), gets the provenance's newest value back. +// Any other value is the source saying something new, and it lands. A value +// the history holds only as a digest (over 16 KB) cannot be restored and is +// left to the rewrite. + +// The writers whose fields a later rewrite keeps: every writer that completes +// a record with what its source cannot say (refreshVideoMetadata.ts refuses a +// yt-dlp re-read of a record they touched, for the same reason). +export const PROVENANCE_WRITERS: ReadonlySet<MetadataHistoryWriter> = new Set<MetadataHistoryWriter>([ + "wayback-provenance", + "archiveorg-provenance", + "feed-backfill", +]); + +// One key's claim: the value the provenance wrote last (undefined: it removed +// the key), and every value it replaced on the way — the capture's own, and an +// earlier provenance value a later one superseded (an absent key is no value). +export type ProvenanceClaim = { value: Json | undefined; replaced: Json[] }; + +const DERIVED_KEYS: ReadonlySet<string> = new Set(Object.values(LANG_LIST_KEYS)); + +/** Per key, what the NEWEST provenance entry that touched it wrote and replaced. */ +export function provenanceClaims(history: MetadataHistory | null): Map<string, ProvenanceClaim> { + const claims = new Map<string, ProvenanceClaim>(); + const claim = (k: string, value: Json | undefined, replaced: Json | undefined) => { + const prev = claims.get(k); + const all = [...(prev?.replaced ?? []), ...(prev && prev.value !== undefined ? [prev.value] : [])]; + if (replaced !== undefined) all.push(replaced); + claims.set(k, { value, replaced: all }); + }; + for (const e of history?.entries ?? []) { + if (!PROVENANCE_WRITERS.has(e.by)) continue; + for (const [k, c] of Object.entries(e.changed)) claim(k, c.to, c.from); + for (const [k, v] of Object.entries(e.added)) claim(k, v, undefined); + for (const [k, v] of Object.entries(e.removed)) claim(k, undefined, v); + } + for (const [k, c] of claims) { + if (DERIVED_KEYS.has(k) || isValueDigest(c.value)) claims.delete(k); + else c.replaced = c.replaced.filter((v) => !isValueDigest(v)); + } + return claims; +} + +/** + * `fresh` (a rewritten info json) with every provenance-applied key it lost or + * reverted to its placeholder restored, and the keys restored (empty: `next` + * is `fresh` itself). A restored key `fresh` lacked is placed where the byte + * readers look for it: `title` right after `id` (the 16 KB head, + * videoTitles.ts), anything else at the end (`upload_date`: the 8 KB tail, + * recencyIndex.ts). PURE. + */ +export function keepProvenanceFields( + history: MetadataHistory | null, + fresh: JsonObject, +): { next: JsonObject; kept: string[] } { + const kept: string[] = []; + const set: JsonObject = {}; + const drop = new Set<string>(); + for (const [k, c] of provenanceClaims(history)) { + const has = Object.hasOwn(fresh, k); + const current = has ? fresh[k] : undefined; + if (canonicalJson(current) === canonicalJson(c.value)) continue; + const placeholder = !has || c.replaced.some((r) => jsonEqual(current, r)); + if (!placeholder) continue; + kept.push(k); + if (c.value === undefined) drop.add(k); + else set[k] = c.value; + } + if (kept.length === 0) return { next: fresh, kept }; + const next: JsonObject = {}; + const putTitle = Object.hasOwn(set, "title") && !Object.hasOwn(fresh, "title"); + if (putTitle && !Object.hasOwn(fresh, "id")) next.title = set.title; + for (const [k, v] of Object.entries(fresh)) { + if (drop.has(k)) continue; + next[k] = Object.hasOwn(set, k) ? set[k] : v; + if (k === "id" && putTitle) next.title = set.title; + } + for (const [k, v] of Object.entries(set)) if (!Object.hasOwn(next, k)) next[k] = v; + return { next, kept }; +} diff --git a/common/ytdlp/downloadOneManaged.ts b/common/ytdlp/downloadOneManaged.ts @@ -760,7 +760,9 @@ async function runManagedDownload( // EVERY PREFETCH REWRITES metadata.info.json (no existence check — the // filters decide on today's metadata), so each spawn runs inside the // history wrap: what moved since the last version is appended to - // metadata.history.json. The file yt-dlp writes is still the file. + // metadata.history.json. The file yt-dlp writes is still the file, less + // any field a provenance writer set that the rewrite reverted (a Wayback + // copy's title and date: release 24 H3, keepProvenanceFields). const prefetchHistory = { by: "prefetch" as const, ...(opts.persistOrigin?.requestedBy diff --git a/common/ytdlp/forceMedia.test.ts b/common/ytdlp/forceMedia.test.ts @@ -19,6 +19,7 @@ import { type ManagedDownloadOpts, } from "./downloadOneManaged"; import type { DownloadOutcomeRecord } from "../lib/downloadOutcome"; +import { patchMetadataInfo } from "../lib/metadataHistory-server"; // Run with: // pnpm --filter yt-dlp-transcript-common exec tsx --test ytdlp/forceMedia.test.ts @@ -104,6 +105,8 @@ async function runWith(opts: { // The media pass (the source-media output) fails with a 403 after writing a // partial. mediaFail?: boolean; + // Anything else the video dir holds before the run (after priorMeta). + seed?: (videoDir: string) => Promise<void>; }): Promise<Run & { cleanup: () => Promise<void> }> { const root = await mkdtemp(path.join(tmpdir(), "force-media-")); const ytdlp = path.join(root, "fake-ytdlp.cjs"); @@ -134,6 +137,7 @@ async function runWith(opts: { JSON.stringify(opts.priorMeta), ); } + await opts.seed?.(videoDir); let log = ""; const record = await downloadOneManaged({ channelSlug: "c", @@ -319,6 +323,41 @@ test("the prefetch's rewrite of metadata.info.json lands in metadata.history.jso } }); +// RELEASE 24 H3: "Persist source video" over a record whose title and date a +// provenance writer set (a Wayback copy's, as the operator found them): the +// prefetch's rewrite from the bare source keeps them, a field the source +// genuinely adds still lands, and the prefetch's history entry is written. +test("a persist prefetch keeps the title and date a provenance writer set, and records its own rewrite", async () => { + const placeholder = { ...META, title: ID }; + const r = await runWith({ + meta: { ...placeholder, view_count: 7 }, + priorMeta: placeholder, + seed: (videoDir) => + patchMetadataInfo( + videoDir, + { title: "The Real Title", upload_date: "20190405" }, + { by: "wayback-provenance", requestedBy: "cli" }, + ).then(() => undefined), + transcript: TRANSCRIPT, + managed: FORCED, + }); + try { + const info = JSON.parse(await readFile(path.join(r.videoDir, "metadata.info.json"), "utf8")); + assert.equal(info.title, "The Real Title"); + assert.equal(info.upload_date, "20190405"); + assert.equal(info.view_count, 7); + assert.match(r.log, /Kept what the provenance set over this rewrite: title, upload_date/); + const h = JSON.parse( + await readFile(path.join(r.videoDir, "metadata.history.json"), "utf8"), + ) as { entries: Array<Record<string, unknown>> }; + assert.deepEqual(h.entries.map((e) => e.by), ["wayback-provenance", "prefetch"]); + assert.deepEqual(h.entries[1].changed, {}); + assert.deepEqual(h.entries[1].counters, { view_count: [null, 7] }); + } finally { + await r.cleanup(); + } +}); + // A FAILED MEDIA PASS OVER A TRANSCRIPT IS NOT A FAILED DOWNLOAD (release 11 // slice O3; release 10 slice N's review L2). The subtitle pass succeeded and the // transcript is on disk; the extra the caller asked for — the source — failed.