Archilyzer · Source

archilyzer

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

commit fb6f0eb492deb6c54b7e76788da338484ac549c1
parent 84b71cf3fb4a7af3e2fe2535d05f9a87059d42d0
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri,  6 Nov 2026 19:06:08 -0500

umtool bench: every wall a gap stops at is drawn and said, the client checks the writer's whole rule, and the bench updates when it is come back to

Operator, 6 Nov: "the gap tool gets blocked at random invisible walls in
the clip" and "I just had to refresh. Maybe address that so it updates if
you click the back button".

The walls (gaps.mjs gapWalls), on the clip bench's waveform and the reel's
beat: the seconds outside the span gaps lie in and the keep bands at its
edges and beside each gap, hatched along the foot (the full height while a
gap is being picked), each with its sentence on hover; the span's edges
labelled; a tick at every second a gap can't cover (the mute mark, each
claim mark's or stamp's `at`). The bench now carries the clip's marks
(benchData, the clip route), so its check of a gap is the writer's whole
validateGaps -- a gap over a mark used to look fine and then be refused by
the writer with a sentence the bench had not said. The reel's master gaps
say why no beat gap can lie inside one.

Coming back: ClipBench reads its state again through the clip route on
pageshow (persisted), on visibilitychange -> visible and once on mount (a
Next back navigation restores the page from the router cache with the
payload it had then) -- never while something is in flight or a gap or cut
edge is being dragged, nor over anything unsaved, which keeps the token it
was drafted against. A changed token takes the clip as it is now (the
route now also sends verdict, reason, rejectNote and onscreen). The clip
editor's player looks for its media again on the same two events.

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

Diffstat:
Mumtool/app/api/report/clip/route.ts | 9+++++++++
Mumtool/components/projects/ClipBench.tsx | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mumtool/components/projects/bench/BenchWave.tsx | 6+++++-
Mumtool/components/projects/bench/GapsZoom.tsx | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/projects/reel/ReelBench.tsx | 13+++++++++++--
Mumtool/components/projects/review/ClipEditor.tsx | 25+++++++++++++++++++++++++
Mumtool/e2e/clip-bench.spec.ts | 44++++++++++++++++++++++++++++++++++++++++++++
Mumtool/e2e/gaps-zoom.spec.ts | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/benchData.ts | 4++++
9 files changed, 383 insertions(+), 5 deletions(-)

diff --git a/umtool/app/api/report/clip/route.ts b/umtool/app/api/report/clip/route.ts @@ -3,6 +3,7 @@ import { ensureWindowFile, projectCache, resolveClip, segmentFor, windowVersion, import { takeToken } from "@/lib/report/takeEdit.mjs"; import { manifestToken } from "@/lib/report/manifest.mjs"; import { cuesInWindow, readClipDetail, siblingsOf } from "@/lib/projects/report.mjs"; +import { gapWalls } from "umtool-report-to-video/gaps"; export const dynamic = "force-dynamic"; @@ -69,10 +70,18 @@ export async function GET(request: Request) { muteFrom: clip.muteFrom ?? null, // Seconds cut out of its middle (gaps.mjs). gaps: Array.isArray(clip.gaps) ? clip.gaps : [], + // The seconds no gap may cover: each claim mark's or stamp's `at` (gaps.mjs gapWalls). + marks: gapWalls({ ...clip, type: "clip", muteFrom: null }).marks.map((m) => ({ id: m.id, at: m.at })), // What the walk said that is not a verdict, and a deliberate repeat. walkNote: typeof clip.walkNote === "string" ? clip.walkNote : null, star: clip.star === true, repeatOf: typeof clip.repeatOf === "string" ? clip.repeatOf : null, + // The rest of what the bench holds, so a page come back to (the back + // button, lane/clip-fixes) can take the clip as it is now, not as it was. + verdict: clip.verdict === "confirmed" || clip.verdict === "incorrect" || clip.verdict === "rejected" ? clip.verdict : null, + reason: typeof clip.reason === "string" ? clip.reason : null, + rejectNote: typeof clip.rejectNote === "string" ? clip.rejectNote : null, + onscreen: clip.onscreen ?? null, }, view, // `v`: the version of each window's bytes, for the media URLs -- a refetch diff --git a/umtool/components/projects/ClipBench.tsx b/umtool/components/projects/ClipBench.tsx @@ -33,7 +33,7 @@ import { TightenButtons, useEdgeTools, type BenchWord } from "./bench/TightenToo import { attributionLine } from "umtool-report-to-video/attribution"; import { DETAIL_SPAN } from "@/lib/report/benchZoom.mjs"; // Gaps inside a clip: the rule (the writer's and the build's) and the pieces that play. -import { gapSpan, gappedLength, validateGaps } from "umtool-report-to-video/gaps"; +import { gapSpan, gapWalls, gappedLength, validateGaps } from "umtool-report-to-video/gaps"; import { useGapEditor } from "./bench/useGapEditor"; import { BenchWaveBox, GapTools } from "./bench/BenchWave"; import { CutEdges } from "./bench/CutEdges"; @@ -143,6 +143,12 @@ type Clip = { * not drafted like the edges; every playback here skips them. */ gaps: Span[]; + /** + * The seconds no gap may cover (lane/clip-fixes): each claim mark's or + * stamp's `at` (`claims`, else `claim`; gaps.mjs gapWalls), read so the + * bench's check of a gap is the writer's whole rule, not most of it. + */ + marks: { id: string | null; at: number }[]; /** "confirmed" / "incorrect" / "rejected", or null for "nobody has looked at this yet". */ verdict: "confirmed" | "incorrect" | "rejected" | null; /** An editorial note from the walk -- not a correction (a fact error). Never rendered. */ @@ -213,6 +219,12 @@ const attribValue = (c: Clip, k: AttribKey): string => const emptyDraft = (c: Clip) => Object.fromEntries(ATTRIB.map(([k]) => [k, attribValue(c, k)])) as Record<AttribKey, string>; +/** An entry's claim marks' and stamp's seconds (gapWalls), as the bench holds them. */ +const marksOf = (e: Record<string, unknown>): Clip["marks"] => + gapWalls({ ...e, type: "clip", muteFrom: null }) + .marks.filter((m) => m.kind !== "mute") + .map((m) => ({ id: m.id, at: m.at })); + /** * A saved entry, back into the shape this component holds. * @@ -239,6 +251,7 @@ const fromEntry = (prev: Clip, e: Record<string, unknown>): Clip => ({ lockCut: !!e.lockCut, muteFrom: e.muteFrom == null ? null : Number(e.muteFrom), gaps: Array.isArray(e.gaps) ? (e.gaps as Span[]) : [], + marks: Array.isArray(e.marks) ? (e.marks as Clip["marks"]) : marksOf(e), verdict: e.verdict === "confirmed" || e.verdict === "incorrect" || e.verdict === "rejected" ? e.verdict : null, walkNote: (e.walkNote as string) ?? null, star: e.star === true, @@ -1302,10 +1315,14 @@ export default function ClipBench({ cutStart: clip.cutStart, cutEnd: clip.cutEnd, muteFrom: windowMoved || muteMoved ? mute : clip.muteFrom, + // The marks too: the writer refuses a gap over one, so the check here does. + claims: (clip.marks ?? []).map((m) => (m.id ? { id: m.id, at: m.at } : { at: m.at })), }), - [clip.id, clip.start, clip.end, clip.cutStart, clip.cutEnd, clip.muteFrom, windowMoved, muteMoved, sel.from, sel.to, mute], + [clip.id, clip.start, clip.end, clip.cutStart, clip.cutEnd, clip.muteFrom, clip.marks, windowMoved, muteMoved, sel.from, sel.to, mute], ); const gapsSpan = gapSpan(draftEntry); + // Every wall a gap stops at, drawn (bench/GapsZoom.tsx GapWallsLayer). + const walls = useMemo(() => gapWalls({ ...draftEntry, gaps: clip.gaps ?? [] }), [draftEntry, clip.gaps]); const gapRefusalFor = useCallback( (gaps: Span[], over: Partial<typeof draftEntry> = {}) => { const errs = validateGaps({ ...draftEntry, ...over, gaps }, "gap"); @@ -2001,6 +2018,80 @@ export default function ClipBench({ // otherwise blank the line the composition was built with. const osTexts: DeckTexts = osAuto ? { [clip.id]: osShown } : {}; const osChanged = !sameOs(os, osDraftOf(clip.onscreen)); + + // ---- coming back to the page ------------------------------------------------ + // + // The back button restores this page as it was shown (the browser's page + // cache: pageshow, persisted; or Next's router cache, which remounts it with + // the payload it had then), and a hidden tab comes back to whatever happened + // meanwhile -- a window fetched, the clip saved from another tab. Operator, + // 6 Nov: "I just had to refresh. Maybe address that so it updates if you + // click the back button." So: read the clip's state again on pageshow + // (persisted), on visibilitychange -> visible and once on mount, through the + // same route a fetch reads -- never while something is in flight or a gap or + // cut edge is being dragged, nor over anything unsaved (an edge, the mark, a + // field): those keep the token they were drafted against, so the writer's + // stale check still guards them. + const returnState = useRef({ busy: false, clean: true }); + returnState.current = { + busy: !!busy || !!gap.sel || gap.pick || cutDraft != null, + clean: !dirty && !muteMoved && !osChanged && ATTRIB.every(([k]) => draft[k] === attribValue(clip, k)), + }; + const windowsRef = useRef(windows); + windowsRef.current = windows; + const clipRef = useRef(clip); + clipRef.current = clip; + const resync = useCallback(async () => { + const ok = () => !returnState.current.busy && returnState.current.clean; + if (!ok()) return; + const r = await fetch( + `/api/report/clip?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}${tq}`, + { cache: "no-store" }, + ).catch(() => null); + if (!r?.ok) return; + const j = (await r.json()) as ClipBenchData & { clip: Record<string, unknown> }; + if (!ok()) return; + const wk = (ws: Win[]) => ws.map((w) => `${w.name}|${w.from}|${w.to}|${w.v ?? ""}`).join(","); + if (wk(j.windows) !== wk(windowsRef.current)) { + setWindows(j.windows); + setCues(j.cues); + if (j.windows[0]) setView({ from: j.windows[0].from, to: j.windows[0].to }); + } + setProposed(j.proposed); + setSegment(j.segment); + setSegmentMtime(j.segmentMtime); + if (j.token !== token.current) { + token.current = j.token; + const next = fromEntry(clipRef.current, j.clip); + setClip(next); + setSel({ from: next.start, to: next.end }); + setDirty(false); + setMute(next.muteFrom); + muteRef.current = next.muteFrom; + setDraft(emptyDraft(next)); + setOs(osDraftOf(next.onscreen)); + } + }, [data.project, clip.id, tq]); + const resyncRef = useRef(resync); + resyncRef.current = resync; + useEffect(() => { + const again = () => void resyncRef.current(); + const onShow = (e: PageTransitionEvent) => { + if (e.persisted) again(); + }; + const onVis = () => { + if (document.visibilityState === "visible") again(); + }; + window.addEventListener("pageshow", onShow); + document.addEventListener("visibilitychange", onVis); + // Once on mount: Next's router restores a page gone back to from its own + // cache, with no pageshow -- and a fresh load pays one small request. + again(); + return () => { + window.removeEventListener("pageshow", onShow); + document.removeEventListener("visibilitychange", onVis); + }; + }, [clip.id]); const osOver = osShown.title.length > osMax; // The strip follows the player when the player is inside what the cut // plays, mapped onto the cut's clock; anywhere else it holds mid-segment. @@ -3153,6 +3244,7 @@ export default function ClipBench({ words={nearWords?.words ?? null} busy={!!busy} held={mutePick} + walls={walls} > {/* The mute mark over the waveform: a line where the sound stops and a hatch over what is silent to the end of the selection. diff --git a/umtool/components/projects/bench/BenchWave.tsx b/umtool/components/projects/bench/BenchWave.tsx @@ -4,7 +4,7 @@ import { useRef } from "react"; import Waveform, { type Peaks } from "@/components/Waveform"; import { buttonVariants } from "@/components/ui/button"; import { GAP_LIMITS, gappedLength } from "umtool-report-to-video/gaps"; -import { GapLayer, type WaveZoom } from "./GapsZoom"; +import { GapLayer, type GapWallsView, type WaveZoom } from "./GapsZoom"; import type { Span } from "./benchMedia"; import type { GapEditor } from "./useGapEditor"; @@ -34,6 +34,7 @@ export function BenchWaveBox({ words, busy, held = false, + walls = null, children, }: { zoom: WaveZoom; @@ -51,6 +52,8 @@ export function BenchWaveBox({ busy: boolean; /** Another pick is armed (the mute mark's): Alt + drag and the gap pick stand down. */ held?: boolean; + /** Where a gap cannot go, and why (gaps.mjs gapWalls), drawn on the waveform. */ + walls?: GapWallsView | null; children?: React.ReactNode; }) { const altDrag = useRef<{ id: number; at: number } | null>(null); @@ -110,6 +113,7 @@ export function BenchWaveBox({ gaps={gaps} selection={gap.sel} live={gap.live} + walls={walls} picking={gap.pick && !held} silences={silences} words={words} diff --git a/umtool/components/projects/bench/GapsZoom.tsx b/umtool/components/projects/bench/GapsZoom.tsx @@ -181,6 +181,15 @@ export function ZoomRuler({ vis }: { vis: Span }) { * between words. `onRemove` on a gap's click; while `picking` (or with Alt * held over the waveform, the caller's capture handler) a drag selects a span. */ +/** What GapLayer draws of the walls: gapWalls's shape, the zones' kinds open (a reel adds its master's gaps). */ +export type GapWallsView = { + span: Span; + /** What the span is called in a sentence: "cut", "clip", "beat". */ + whose: string; + zones: Array<{ from: number; to: number; kind: string; why: string }>; + marks: Array<{ at: number; kind: string; why: string }>; +}; + export function GapLayer({ vis, gaps, @@ -192,12 +201,21 @@ export function GapLayer({ onRemove, onSelect, live = null, + walls = null, }: { vis: Span; gaps: Span[]; selection: Span | null; /** What the selection would do, checked on every move (useGapEditor's GapLive). */ live?: { why: string | null; wall: string | null; merged: { from: number; to: number } | null; short: boolean } | null; + /** + * Where a gap cannot go, and why (gaps.mjs gapWalls, or a reel beat's own): + * drawn so no wall a gap drag stops at is invisible -- outside the span and + * the keep bands shaded (a strip along the foot always, the full height + * while a gap is being picked), each mark a gap can't cover ticked, every + * one with its sentence on hover. + */ + walls?: GapWallsView | null; picking: boolean; silences: Span[] | null; /** The recording's words (the clip-editor route's): timed (`end`), or a caption word's start only. */ @@ -261,6 +279,7 @@ export function GapLayer({ {quiet.map((t) => ( <div key={`q-${t}`} data-wave-quiet={t} aria-hidden className="pointer-events-none absolute top-0 h-full border-l border-dotted border-[color-mix(in_srgb,var(--color-meter)_55%,transparent)]" style={{ left: pct(t) }} /> ))} + {walls && <GapWallsLayer walls={walls} vis={vis} pct={pct} width={width} full={picking || !!selection} />} {gaps.filter(inView).map((g) => ( <button key={`gap-${g.from}`} @@ -497,3 +516,84 @@ export function ZoomOverview({ </div> ); } + + +/** The walls (GapLayer's `walls`): no-cut zones and the marks a gap can't cover. */ +function GapWallsLayer({ + walls, + vis, + pct, + width, + full, +}: { + walls: GapWallsView; + vis: Span; + pct: (t: number) => string; + width: (a: number, b: number) => string; + /** A gap is being picked: shade the full height, not just the foot. */ + full: boolean; +}) { + const inView = (a: number, b: number) => b > vis.from && a < vis.to; + const zones: Array<{ from: number; to: number; kind: string; why: string }> = []; + if (walls.span.from > vis.from) zones.push({ from: vis.from, to: walls.span.from, kind: "outside", why: `before the ${walls.whose}'s start: a gap goes inside the ${walls.whose}` }); + if (walls.span.to < vis.to) zones.push({ from: walls.span.to, to: vis.to, kind: "outside", why: `after the ${walls.whose}'s end: a gap goes inside the ${walls.whose}` }); + zones.push(...walls.zones.filter((z) => z.to > z.from)); + return ( + <> + {zones + .filter((z) => inView(z.from, z.to)) + .map((z, k) => ( + <div + key={`nocut-${k}-${z.from}`} + data-gap-nocut={z.kind} + data-gap-nocut-at={`${z.from.toFixed(2)}-${z.to.toFixed(2)}`} + title={`no gap here — ${z.why}`} + className={ + full + ? "pointer-events-none absolute bottom-0 z-[3] h-full [background:repeating-linear-gradient(135deg,color-mix(in_srgb,var(--color-bad)_20%,transparent)_0_2px,transparent_2px_6px)]" + : "absolute bottom-0 z-[3] h-1.5 [background:repeating-linear-gradient(135deg,color-mix(in_srgb,var(--color-bad)_55%,transparent)_0_2px,transparent_2px_5px)]" + } + style={{ left: pct(z.from), width: width(z.from, z.to) }} + /> + ))} + {/* The cut's own edges, labelled: where the span of gaps starts and ends. */} + {(["start", "end"] as const).map((side) => { + const t = side === "start" ? walls.span.from : walls.span.to; + if (!(t >= vis.from && t <= vis.to)) return null; + return ( + <div + key={`edge-${side}`} + data-gap-span-edge={side} + aria-hidden + className={ + side === "start" + ? "pointer-events-none absolute bottom-1.5 z-[3] translate-x-0.5 whitespace-nowrap font-mono text-[9px] leading-none text-[var(--color-bad)]" + : "pointer-events-none absolute bottom-1.5 z-[3] -translate-x-full whitespace-nowrap pr-0.5 font-mono text-[9px] leading-none text-[var(--color-bad)]" + } + style={{ left: pct(t) }} + > + {side === "start" ? `${walls.whose} ▸` : `◂ ${walls.whose}`} + </div> + ); + })} + {walls.marks + .filter((m) => m.at >= vis.from && m.at <= vis.to) + .map((m) => ( + <div + key={`mark-${m.kind}-${m.at}`} + data-gap-wall-mark={m.at} + data-gap-wall-mark-kind={m.kind} + className="pointer-events-none absolute top-0 z-[6] h-full border-l border-dashed border-[var(--color-bad)]" + style={{ left: pct(m.at) }} + > + <span + title={`a gap can't cover this — ${m.why}`} + className="pointer-events-auto absolute bottom-1.5 -translate-x-1/2 cursor-help rounded-sm bg-[var(--color-bad)] px-0.5 font-mono text-[9px] leading-[11px] text-[var(--color-ground)]" + > + {m.kind === "mute" ? "mute" : m.kind === "stamp" ? "stamp" : "mark"} + </span> + </div> + ))} + </> + ); +} diff --git a/umtool/components/projects/reel/ReelBench.tsx b/umtool/components/projects/reel/ReelBench.tsx @@ -12,7 +12,7 @@ import { DETAIL_SPAN } from "@/lib/report/benchZoom.mjs"; import { fileSpans } from "@/lib/report/fileMedia.mjs"; import type { ReelBenchData } from "@/lib/report/reelBenchData"; import { cn } from "@/lib/utils"; -import { beatGapsOf, editGaps } from "umtool-report-to-video/gaps"; +import { beatGapsOf, editGaps, gapWalls } from "umtool-report-to-video/gaps"; import { BenchWaveBox, GapTools } from "../bench/BenchWave"; import { renderedFileMedia, type Span } from "../bench/benchMedia"; import { ZoomControls, ZoomOverview, ZoomRuler, useWaveZoom } from "../bench/GapsZoom"; @@ -385,6 +385,14 @@ function BeatEditor({ const fmt = isClip ? sourceClock : clock; const kept = sel.to - sel.from - gaps.reduce((s, g) => s + Math.max(0, Math.min(g.to, sel.to) - Math.max(g.from, sel.from)), 0); const masterGaps = isClip ? m.map.gaps.filter((g) => g.to > span.from && g.from < span.to) : []; + // Where a gap cannot go in the beat, drawn as on the clip bench (lane/clip-fixes): the beat's + // edges and the keep bands, the clip rule's (gaps.mjs gapWalls), said as the beat's. The + // master's own gaps are drawn below, each with its title. + const walls = useMemo(() => { + if (!isClip) return null; + const w = gapWalls({ type: "clip", id: row.id ?? "beat", start: saved.from, end: saved.to, gaps }); + return { ...w, whose: "beat", zones: w.zones.map((z) => ({ ...z, why: z.why.replace("the clip's", "the beat's") })) }; + }, [isClip, row.id, saved.from, saved.to, gaps]); const confirmedCount = (view.rows ?? []).filter((x) => x.verdict === "confirmed").length; return ( @@ -449,13 +457,14 @@ function BeatEditor({ words={nearWords?.words ?? null} busy={busy} held={!isClip} + walls={walls} > {/* What the master already left out of the clip (its render's gaps): nothing plays there. */} {masterGaps.map((g) => ( <div key={`mg-${g.from}`} data-reel-master-gap={`${g.from}-${g.to}`} - title={`${sourceClock(g.from)}–${sourceClock(g.to)}: cut out of ${row.id} in the master (the clip's own gap) — edit it on the clip's walk`} + title={`${sourceClock(g.from)}–${sourceClock(g.to)}: cut out of ${row.id} in the master (the clip's own gap) — nothing plays here, so no beat gap can lie wholly inside it; edit it on the clip's walk`} className="pointer-events-none absolute top-0 h-full bg-[color-mix(in_srgb,var(--color-dim)_25%,transparent)]" style={{ left: zpct(g.from), width: `calc(${zpct(g.to)} - ${zpct(g.from)})` }} /> diff --git a/umtool/components/projects/review/ClipEditor.tsx b/umtool/components/projects/review/ClipEditor.tsx @@ -953,6 +953,31 @@ const Player = forwardRef<PlayerHandle, { clipId: string; targets: Target[]; cut // eslint-disable-next-line react-hooks/exhaustive-deps }, [key, attempt]); + // COMING BACK TO THE PAGE (lane/clip-fixes; operator, 6 Nov: "I just had to + // refresh"): the back button restores this page from the browser's cache + // (pageshow, persisted) or a hidden tab comes back, and what is on disk may + // have changed meanwhile (a window fetched on the bench). Look again -- the + // same file at the same clock keeps playing (settle), so it costs a request. + useEffect(() => { + const again = () => { + const m = media.current; + if (m && !m.paused) return; + setAttempt((a) => a + 1); + }; + const onShow = (e: PageTransitionEvent) => { + if (e.persisted) again(); + }; + const onVis = () => { + if (document.visibilityState === "visible") again(); + }; + window.addEventListener("pageshow", onShow); + document.addEventListener("visibilitychange", onVis); + return () => { + window.removeEventListener("pageshow", onShow); + document.removeEventListener("visibilitychange", onVis); + }; + }, []); + // Another clip on the same file: go to its cut, paused. useEffect(() => { const m = media.current; diff --git a/umtool/e2e/clip-bench.spec.ts b/umtool/e2e/clip-bench.spec.ts @@ -1679,3 +1679,47 @@ test("a window wider than the editor's 900 s is refused with the next step, not expect(j.error).toContain("at most 900 s end to end"); expect(j.error).toContain("whole source"); }); + +// --------------------------------------------------------------------------- +// Coming back to the bench (lane/clip-fixes; operator, 6 Nov: "I just had to +// refresh. Maybe address that so it updates if you click the back button"). +// The back button restores the page as it was shown -- Next's router cache, or +// the browser's page cache (pageshow, persisted) -- so a window fetched +// meanwhile did not show. The bench reads its state again on mount, on +// pageshow (persisted) and when the tab comes back; it never fetches to do so. +// --------------------------------------------------------------------------- + +test("back to the bench shows the window fetched meanwhile, and so does a page restored from the page cache -- without a fetch", async ({ page, request }) => { + test.setTimeout(240_000); + const visTo = async () => Number(((await page.locator("[data-wave-box]").getAttribute("data-wave-vis")) ?? "").split("-")[1]); + const widen = async (padAfter: number) => { + const r = await request.post("/api/report/fetch", { data: { project: REACH, clip: "r01", padBefore: 3, padAfter } }); + expect(r.status(), await r.text()).toBe(202); + await waitJob(request, ((await r.json()) as { job: { id: string } }).job.id); + return (await reachWindows(request))[0].to; + }; + const before = (await reachWindows(request))[0]?.to ?? (await widen(30)); + const fetches: string[] = []; + page.on("request", (r) => { + if (r.method() === "POST" && r.url().endsWith("/api/report/fetch")) fetches.push(r.url()); + }); + await page.goto(urls.clipBenchHref(REACH, "r01")); + await expect.poll(visTo).toBeCloseTo(before, 1); + + // Away through the app's own link (a client navigation), a wider window + // fetched meanwhile (another tab, a CLI), and back. + await page.locator("[data-bench-back]").click(); + await expect(page.locator("[data-bench=r01]")).toHaveCount(0); + const wider = await widen(Math.round(before - 306) + 30); + expect(wider).toBeGreaterThan(before + 1); + await page.goBack(); + await expect(page.locator("[data-bench=r01]")).toBeVisible(); + await expect.poll(visTo, { timeout: 15_000 }).toBeCloseTo(wider, 1); + + // A page the browser restored from its page cache says so with pageshow (persisted). + const widest = await widen(Math.round(wider - 306) + 30); + await page.evaluate(() => window.dispatchEvent(new PageTransitionEvent("pageshow", { persisted: true }))); + await expect.poll(visTo, { timeout: 15_000 }).toBeCloseTo(widest, 1); + // The bench fetched nothing to show any of it. + expect(fetches).toEqual([]); +}); diff --git a/umtool/e2e/gaps-zoom.spec.ts b/umtool/e2e/gaps-zoom.spec.ts @@ -390,3 +390,94 @@ test("a cut narrower than the clip: drawn on the waveform, said, a gap stops at expect((await putWindow(request, { cutStart: "", cutEnd: "", lockCut: false })).ok()).toBeTruthy(); } }); + +// --------------------------------------------------------------------------- +// Every wall a gap stops at is drawn and said (lane/clip-fixes; operator, 6 +// Nov: "the gap tool gets blocked at random invisible walls in the clip"): the +// no-cut zones (outside the span, the keep bands at its edges and beside each +// gap), a tick at each second a gap can't cover, and the writer's whole rule +// checked on every move -- the claim marks included, which the bench used to +// leave to the writer, which then refused with a sentence the bench had not +// said. +// --------------------------------------------------------------------------- + +/** Put a claim mark's second on g01 (`claim: {id, verdict, at}`), straight into the manifest; null takes it off. */ +const setStamp = (at: number | null) => { + const m = JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: Record<string, unknown>[] }; + const e = m.timeline.find((x) => x.id === "g01")!; + if (at == null) delete e.claim; + else e.claim = { id: "k9", verdict: "CORROBORATED", at }; + writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n"); +}; +/** An Alt + drag from a to b, held (not released): what the span says WHILE it is dragged. */ +const altDragHeld = async (page: Page, a: number, b: number) => { + await page.keyboard.down("Alt"); + const y = await midY(page); + await page.mouse.move(await xAt(page, a), y); + await page.mouse.down(); + await page.mouse.move(await xAt(page, b), y, { steps: 4 }); +}; +const altRelease = async (page: Page) => { + await page.mouse.up(); + await page.keyboard.up("Alt"); +}; + +test("the walls are drawn: no-cut zones and the marks a gap can't cover; a drag into one turns red with the reason before release; a gap over a claim mark is refused with the writer's sentence", async ({ page, request }) => { + expect((await putWindow(request, { gapAdd: "3.5-5.5" })).ok()).toBeTruthy(); + setStamp(7); + try { + await openBench(page); + // The zones: outside the clip (the view runs 0-9, the clip 0.5-8.5), 0.5 s + // at each of its edges, and 0.5 s either side of the gap. + const kinds = await page.locator("[data-gap-nocut]").evaluateAll((els) => els.map((e) => `${e.getAttribute("data-gap-nocut")} ${e.getAttribute("data-gap-nocut-at")}`)); + expect(kinds).toEqual( + expect.arrayContaining(["outside 0.00-0.50", "outside 8.50-9.00", "keep-start 0.50-1.00", "keep-end 8.00-8.50", "keep-gap 3.00-3.50", "keep-gap 5.50-6.00"]), + ); + await expect(page.locator("[data-gap-nocut='keep-gap']").first()).toHaveAttribute("title", /keep at least 0.5 s between cuts/); + await expect(page.locator("[data-gap-span-edge]")).toHaveCount(2); + // The mark's second, ticked, with what it means on hover. + const tick = page.locator("[data-gap-wall-mark='7']"); + await expect(tick).toHaveAttribute("data-gap-wall-mark-kind", "mark"); + await expect(tick.locator("span")).toHaveAttribute("title", /a gap can't cover this/); + await shot(page, "walls"); + + // Into the keep band beside the gap: red, and why, while still dragging. + await altDragHeld(page, 5.7, 6.6); + await expect(page.locator("[data-gap-selection]")).toHaveAttribute("data-gap-selection-state", "refused"); + await expect(page.locator("[data-gap-selection-why]")).toContainText("keep at least 0.5 s"); + await shot(page, "gap-into-keep-band"); + await altRelease(page); + await page.locator("body").press("Escape"); + + // Over the mark's second: refused here, with the writer's own sentence. + await altDragHeld(page, 6.6, 7.6); + await expect(page.locator("[data-gap-selection]")).toHaveAttribute("data-gap-selection-state", "refused"); + await expect(page.locator("[data-gap-selection-why]")).toContainText("the mark k9's second (at 7) lies inside the gap"); + await shot(page, "gap-over-mark"); + await altRelease(page); + const [a, b] = spanOf(await page.locator("[data-gap-selection]").getAttribute("data-gap-selection")); + const posts: string[] = []; + page.on("request", (r) => { + if (r.method() === "PUT" && r.url().endsWith("/api/report/window")) posts.push(r.url()); + }); + await page.locator("[data-gap-cut]").click(); + // The writer, asked the same span, says the same thing (less the clip id it starts with). + const r = await putWindow(request, { gapAdd: `${a}-${b}` }); + expect(r.status()).toBe(400); + const said = ((await r.json()) as { error: string }).error.replace(/^g01: /, ""); + expect(said).toContain("the mark k9's second (at 7) lies inside the gap"); + await expect(page.locator("[data-bench-note]")).toContainText(`not cut: ${said}`); + // Refused before anything was sent. + expect(posts).toEqual([]); + expect(clipOf("g01").gaps).toEqual([{ from: 3.5, to: 5.5 }]); + + // Touching the gap: no wall -- it says the two become one. + await page.locator("body").press("Escape"); + await altDragHeld(page, 5.2, 6.4); + await expect(page.locator("[data-gap-selection]")).toHaveAttribute("data-gap-selection-state", "merge"); + await expect(page.locator("[data-gap-selection-why]")).toContainText("touches a gap — cutting makes one gap 3.50–"); + await altRelease(page); + } finally { + setStamp(null); + } +}); diff --git a/umtool/lib/report/benchData.ts b/umtool/lib/report/benchData.ts @@ -12,6 +12,7 @@ import { import { walkNeighbours, walkOf } from "@/lib/report/walkData.mjs"; import { projectCache, segmentFor, windowVersion, windowsFor } from "@/lib/report/serve.mjs"; import { FETCH_MAX_WINDOW } from "@/lib/report/driver.mjs"; +import { gapWalls } from "umtool-report-to-video/gaps"; import { deckOn } from "umtool-report-to-video/deck"; import { pieceHrefOfProject } from "@/lib/pieces/article"; import { readWorkingCut } from "@/lib/report/workingCut.mjs"; @@ -132,6 +133,9 @@ export async function clipBenchData( gaps: ((manifest.timeline ?? []) as { id: string; gaps?: { from: number; to: number }[] }[]).find((e) => e.id === clipId) ?.gaps ?? [], + // The seconds no gap may cover (claim marks, a stamp), from the manifest's own entry. + marks: gapWalls({ ...(((manifest.timeline ?? []) as { id: string }[]).find((e) => e.id === clipId) ?? {}), type: "clip", muteFrom: null }) + .marks.map((m) => ({ id: m.id, at: m.at })), verdict: entry.verdict === "confirmed" || entry.verdict === "incorrect" || entry.verdict === "rejected" ? entry.verdict : null, // What the walk said that is not a verdict, and a deliberate repeat.