Archilyzer · Source

archilyzer

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

commit 4a923dec96cff2e4938a42ea2d0e89e89f95c83e
parent 6ebba54d259170cf5c0deca8a11779b325b19062
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 18:29:47 -0500

lookouts: a damaged verdicts.json is never written over, and a record's duration is its own

setLookoutVerdict read a verdicts.json that was there and not parseable as
empty, so the next mark replaced every verdict in it with one; it now refuses
and leaves the file. metaDatesOf took the first "duration" in a
metadata.info.json, which on a YouTube record is a storyboard fragment's
(formats come first); it takes the last before upload_date. Tests for both.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/lookoutPlan.test.ts | 5+++--
Mcommon/controller/lookoutPlan.ts | 10++++++++--
Mcommon/lib/lookoutStore.test.ts | 3+++
Mcommon/lib/lookoutStore.ts | 13+++++++++++--
4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/common/controller/lookoutPlan.test.ts b/common/controller/lookoutPlan.test.ts @@ -340,9 +340,10 @@ test("a lookout with no channels is refused", async () => { test("metaDatesOf reads the scalars wherever yt-dlp put them", () => { // YouTube's order: upload_date then timestamp, near the end; a comment's - // nested timestamp earlier is not taken. + // nested timestamp earlier is not taken, nor a storyboard fragment's duration. const yt = - '{"id": "a", "comments": [{"timestamp": 1600000000}], "duration": 747, "live_status": "not_live", ' + + '{"id": "a", "formats": [{"format_id": "sb0", "fragments": [{"url": "u", "duration": 496.98}, {"url": "u", "duration": 250.02}]}], ' + + '"comments": [{"timestamp": 1600000000}], "duration": 747, "live_status": "not_live", ' + '"upload_date": "20261106", "timestamp": 1793993883, "is_live": false}'; assert.deepEqual(metaDatesOf(yt), { releaseTimestamp: null, diff --git a/common/controller/lookoutPlan.ts b/common/controller/lookoutPlan.ts @@ -164,7 +164,8 @@ function last(buf: Buffer, key: string, before = buf.length): { at: number; valu * The dating fields of a metadata.info.json, found by byte search — a YouTube * record is megabytes of formats and caption URLs, and only these five scalars * are wanted, so the file is never decoded or parsed. `release_timestamp` is - * taken wherever it is (no nested object carries one); `timestamp` is the one + * taken wherever it is (no nested object carries one); `duration` is the last + * before `upload_date` (formats' fragments carry their own); `timestamp` is the one * right after the last `upload_date` (yt-dlp's top-level order) when it is * there, else the last in the file; airDateOf then refuses any timestamp more * than two days from `upload_date`. @@ -181,12 +182,17 @@ export function metaDatesOf(input: Buffer | string): MetaDates { timestamp ??= last(buf, "timestamp")?.value ?? null; const uploadDate = upload?.value && /^\d{8}$/.test(upload.value) ? upload.value : null; const live = first(buf, "live_status"); + // The record's own duration, not a format's: a YouTube storyboard format + // lists `"fragments": [{"duration": …}]` long before the top-level key, so + // the first in the file can be one sheet's seconds. The top-level one is the + // last before `upload_date`; with no upload date, the last in the file. + const duration = (upload ? last(buf, "duration", upload.at) : last(buf, "duration"))?.value ?? first(buf, "duration"); return { releaseTimestamp: num(first(buf, "release_timestamp") ?? undefined), timestamp: num(timestamp ?? undefined), uploadDate, liveStatus: live && /^[a-z_]+$/.test(live) ? live : null, - duration: num(first(buf, "duration") ?? undefined), + duration: num(duration ?? undefined), }; } diff --git a/common/lib/lookoutStore.test.ts b/common/lib/lookoutStore.test.ts @@ -93,6 +93,9 @@ test("a hand-damaged verdicts file reads as what is valid in it", async () => { await mkdir(path.dirname(lookoutVerdictsFile(p, "weekly")), { recursive: true }); await writeFile(lookoutVerdictsFile(p, "weekly"), "{ not json"); assert.deepEqual(await readLookoutVerdicts(p, "weekly"), { version: 1, ideas: {} }); + // ...and is never written over as if it were empty. + await assert.rejects(setLookoutVerdict(p, "weekly", { key: k, verdict: "make" }), /unparseable.*not written/); + assert.equal(await readFile(lookoutVerdictsFile(p, "weekly"), "utf8"), "{ not json"); } finally { await rm(p.transcriptsDir, { recursive: true, force: true }); } diff --git a/common/lib/lookoutStore.ts b/common/lib/lookoutStore.ts @@ -307,7 +307,8 @@ export type SetVerdictInput = { * THE writer of verdicts.json: one idea's verdict set (replacing the one it * had), under the file's lock, written atomically. A note or project not sent * is kept from the verdict before, so "Make" recording its project does not - * erase the operator's note. + * erase the operator's note. Refused when verdicts.json is there and is not + * readable JSON — it is never overwritten as if it were empty. */ export async function setLookoutVerdict( paths: Pick<Paths, "transcriptsDir">, @@ -318,7 +319,15 @@ export async function setLookoutVerdict( if (!isLookoutVerdict(input.verdict)) throw new LookoutStoreError(`verdict is one of ${VERDICTS.join(", ")}`); const file = lookoutVerdictsFile(paths, id); return withJsonFileLock(file, async () => { - const current = await readLookoutVerdicts(paths, id); + // A file that is there and cannot be read is NOT an empty one: writing over + // it would drop every verdict it holds for the one being set. + const read = await readJsonFile(file); + if (!read.ok && read.reason !== "absent") { + throw new LookoutStoreError( + `${file} is ${read.reason} — the verdict was not written; mend the file or move it aside first`, + ); + } + const current = read.ok ? sanitizeLookoutVerdicts(read.value) : emptyLookoutVerdicts(); const before = current.ideas[input.key]; const v: LookoutVerdict = { verdict: input.verdict, at: (input.now ?? new Date()).toISOString() }; const note = input.note !== undefined ? input.note.trim() : before?.note;