Archilyzer · Source

archilyzer

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

commit 776c915250ed855b3c429c251c22057c5205eb48
parent e5079bb9f1edeaf803df8322e6b98c7cb700a6d3
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 24 Nov 2026 12:45:48 -0500

record-live: REVIEW-8 3: the fragment length from the highest fragment number, capped; a part with dropped fragments is never verified on its spans alone

fragmentSecondsOf takes the highest kept fragment number or the state's
index, never the count of files left, and caps the result at 10 s. A part
whose fragments were dropped for want of disk, whose byte check is
skipped, is not "verified whole" on the track spans alone, neither at the
landing nor by "Verify again": nothing is removed and the row says why.
Tests red on e5079bb9f.

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

Diffstat:
Mcommon/controller/recordLive.test.ts | 22++++++++++++++++++++--
Mcommon/controller/recordLive.ts | 22+++++++++++++++-------
2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts @@ -5002,7 +5002,7 @@ test("REVIEW-7 4: a verification that failed is checked AGAIN by reverifyLiveLan assert.equal((await rowOf(id))[0]!.verification?.state, "verified"); }); -test("REVIEW-7 4: a part whose fragments were dropped for want of disk skips the byte check (said), and can be verified", { timeout: 60_000 }, async () => { +test("REVIEW-7 4 / REVIEW-8 3: a part whose fragments were dropped for want of disk is NOT 'verified whole' on the track spans alone — nothing removed, loud", { timeout: 60_000 }, async () => { const id = "exmplr7drp1"; let live = true; let free = 1e15; @@ -5021,7 +5021,25 @@ test("REVIEW-7 4: a part whose fragments were dropped for want of disk skips the ); await run; assert.ok(log.some((l) => /byte check .* is skipped: they were dropped/.test(l))); - assert.equal((await rowOf(id))[0]!.verification?.state, "verified"); + const row = (await rowOf(id))[0]!; + assert.equal(row.verification?.state, "failed"); + assert.match(row.verification?.why ?? "", /cannot be proven whole/); + assert.ok((await left(id)).some((n) => n.endsWith(`.${FAKE_V}`)), "the stream files are kept"); +}); + +test("REVIEW-8 3: one fragment's length comes from the HIGHEST fragment number, never the count of files left (5 kept of 3601 is not 30 min a fragment), capped at 10 s", async () => { + const { fragmentSecondsOf } = await import("./recordLive"); + const dir = path.join(ROOT, "frag8"); + await mkdir(dir, { recursive: true }); + const f = ".x.live-8.ytdlp.f136.mp4"; + await writeFile(path.join(dir, f), "x"); + for (const n of [3597, 3598, 3599, 3600, 3601]) await writeFile(path.join(dir, `${f}-Frag${n}`), "x"); + const sec = await fragmentSecondsOf(dir, [f], 7200); + assert.ok(sec !== undefined && sec <= 2.01, `about 2 s a fragment: ${sec}`); + const g = ".x.live-9.ytdlp.f136.mp4"; + await writeFile(path.join(dir, g), "x"); + for (const n of [1, 2]) await writeFile(path.join(dir, `${g}-Frag${n}`), "x"); + assert.ok(((await fragmentSecondsOf(dir, [g], 7200)) ?? 0) <= 10, "capped at 10 s"); }); test("REVIEW-7 5: a merge that fails leaves its output set aside (never at the finished name the next run would land)", async () => { diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts @@ -422,17 +422,20 @@ export function isProgressLine(line: string): boolean { return PROGRESS_RE.test(line) && !NEVER_THINNED_RE.test(line); } +// The longest a fragment can be taken to be (YouTube's are 1, 2 or 5 s). +export const FRAGMENT_SECONDS_CAP = 10; + // REVIEW-7 4: one fragment's length, from a stream file's kept fragments and // the landed length (undefined when nothing tells it). export async function fragmentSecondsOf(dir: string, streams: readonly string[], seconds: number | null): Promise<number | undefined> { if (!seconds || !streams.length) return undefined; const names = await readdir(dir).catch(() => [] as string[]); - let n = fragNumbers(streams[0]!, names).length; - if (n < 2) { - const idx = await readYtdlIndex(path.join(dir, streams[0]!)); - n = typeof idx === "number" ? idx : 0; - } - return n > 1 ? seconds / (n - 1) : undefined; + // REVIEW-8 3: the HIGHEST fragment number (or the state's index), never the + // count of files left — a part whose fragments were dropped keeps a few. + const nums = fragNumbers(streams[0]!, names); + const idx = await readYtdlIndex(path.join(dir, streams[0]!)); + const n = Math.max(nums.length ? nums[nums.length - 1]! : 0, typeof idx === "number" ? idx : 0); + return n > 1 ? Math.min(FRAGMENT_SECONDS_CAP, seconds / (n - 1)) : undefined; } // A `.ytdl` state's fragment index, or null when it does not parse. @@ -4056,7 +4059,11 @@ async function recordLiveRunInner( // (REVIEW-7 4: a part whose fragments were dropped for want of disk has // none to compare with — the byte check is skipped, said.) const droppedHere = best.part?.fragmentsDropped ?? (await readStemMarks(slugStore, best.group.stem)).dropped; - if (verdict.ok && droppedHere && mergedFrom.length) say(`The byte check against the kept fragments is skipped: they were dropped for want of disk (${droppedHere}).`); + if (verdict.ok && droppedHere && mergedFrom.length) { + say(`The byte check against the kept fragments is skipped: they were dropped for want of disk (${droppedHere}).`); + // REVIEW-8 3: the track spans alone are no proof — never "verified whole". + verdict = { ok: false, why: `its fragments were dropped for want of disk (${droppedHere}): it cannot be proven whole by its track spans alone` }; + } if (verdict.ok && !droppedHere) { for (const f of mergedFrom) { const eq = await streamEqualsFragments(slugStore, f).catch((e: Error) => ({ ok: false as const, why: e.message })); @@ -4204,6 +4211,7 @@ export async function reverifyLiveLanding(o: { ).catch((e: Error) => ({ ok: false as const, why: e.message })); const stems = [...new Set(livePartFiles(o.id, against).map((g) => g.stem))]; const dropped = (await Promise.all(stems.map((st) => readStemMarks(slugStore, st)))).some((m) => m.dropped); + if (verdict.ok && dropped) verdict = { ok: false, why: "its fragments were dropped for want of disk: it cannot be proven whole by its track spans alone" }; if (verdict.ok && !dropped) { for (const n of against) { const eq = await streamEqualsFragments(slugStore, n).catch((e: Error) => ({ ok: false as const, why: e.message }));