Archilyzer · Source

archilyzer

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

commit ff6bf47c44b7ed7b5fbabdecc93d83aadd522dcb
parent 550673dcbd7d0f08f6e3bfc4b2c5ee5523083783
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 10 Nov 2026 17:28:06 -0500

umtool: a review pass's Keep never overwrites a newer bench ruling -- writeWalkVerdict reads the clip's verdict at write time (the clip GET whose token it writes on) and refuses `confirmed` over `incorrect` or `rejected`; before, only the view's entry was checked, so a ruling made in the bench since was overwritten on a fresh token. The bench tests run in `pnpm --filter umtool test` (L7b re-review should-fix 1)

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

Diffstat:
Aumtool/components/projects/bench/walkVerdict.test.ts | 46++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/projects/bench/walkVerdict.ts | 32+++++++++++++++++++++++++++-----
Mumtool/components/projects/workspace/ReviewPass.tsx | 4++--
Mumtool/package.json | 2+-
4 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/umtool/components/projects/bench/walkVerdict.test.ts b/umtool/components/projects/bench/walkVerdict.test.ts @@ -0,0 +1,46 @@ +// The walk's verdict writer, outside the bench (bench/walkVerdict.ts): what a review pass's Keep may write, and in +// what order. No server: `fetch` is a fake that answers the clip GET and records the window PUT. +// +// Run with: pnpm --filter umtool exec tsx --test components/projects/bench/walkVerdict.test.ts +import { afterEach, test } from "node:test"; +import assert from "node:assert/strict"; +import { writeWalkVerdict } from "./walkVerdict"; + +const realFetch = globalThis.fetch; +afterEach(() => { + globalThis.fetch = realFetch; +}); + +/** A fake server: the clip GET answers `verdict` on token "t1"; the PUT is recorded and answered ok. */ +function fakeServer(verdict: string | null) { + const puts: Record<string, unknown>[] = []; + globalThis.fetch = (async (url: string, init?: RequestInit) => { + if (String(url).startsWith("/api/report/clip?")) return Response.json({ token: "t1", clip: { id: "c1", verdict } }); + if (String(url) === "/api/report/window" && init?.method === "PUT") { + const body = JSON.parse(String(init.body)) as Record<string, unknown>; + puts.push(body); + return Response.json({ ok: true, token: "t2", entry: { id: "c1", verdict: body.verdict } }); + } + return new Response("no", { status: 404 }); + }) as typeof fetch; + return puts; +} + +test("Keep is refused over a ruling the bench made since the view was read: the clip's verdict at write time decides, nothing is PUT", async () => { + for (const ruled of ["incorrect", "rejected"]) { + const puts = fakeServer(ruled); + const w = await writeWalkVerdict("p", "c1", { verdict: "confirmed" }); + assert.equal(w.ok, false); + assert.match(!w.ok ? w.error : "", new RegExp(`marked ${ruled} in the bench`)); + assert.deepEqual(puts, [], `nothing written over ${ruled}`); + } +}); + +test("Keep writes `confirmed` on the token its own read gave, over no verdict or over confirmed", async () => { + for (const now of [null, "confirmed"]) { + const puts = fakeServer(now); + const w = await writeWalkVerdict("p", "c1", { verdict: "confirmed" }); + assert.equal(w.ok, true); + assert.deepEqual(puts, [{ project: "p", clip: "c1", token: "t1", verdict: "confirmed" }]); + } +}); diff --git a/umtool/components/projects/bench/walkVerdict.ts b/umtool/components/projects/bench/walkVerdict.ts @@ -9,11 +9,23 @@ export type ClipWrite = | { ok: true; entry: Record<string, unknown>; token: string; json: Record<string, unknown> } | { ok: false; error: string; stale: boolean }; -/** One clip's patch through the window writer, on the clip's token as it is now. */ -export async function writeClipPatch(project: string, clip: string, patch: Record<string, unknown>): Promise<ClipWrite> { +/** + * One clip's patch through the window writer, on the clip's token as it is now. `refuse` sees the clip as that + * read gave it and may refuse the write (its words); the token is the same read's, so a write landing after it + * makes the PUT stale rather than overwritten. + */ +export async function writeClipPatch( + project: string, + clip: string, + patch: Record<string, unknown>, + refuse?: (clip: Record<string, unknown>) => string | null, +): Promise<ClipWrite> { const r = await fetch(`/api/report/clip?project=${encodeURIComponent(project)}&clip=${encodeURIComponent(clip)}`, { cache: "no-store" }); if (!r.ok) return { ok: false, error: `HTTP ${r.status}`, stale: false }; - const tok = ((await r.json().catch(() => ({}))) as { token?: string }).token ?? null; + const got = (await r.json().catch(() => ({}))) as { token?: string; clip?: Record<string, unknown> }; + const said = refuse?.(got.clip ?? {}) ?? null; + if (said) return { ok: false, error: said, stale: false }; + const tok = got.token ?? null; const w = await fetch("/api/report/window", { method: "PUT", headers: { "content-type": "application/json" }, @@ -24,7 +36,17 @@ export async function writeClipPatch(project: string, clip: string, patch: Recor return { ok: true, entry: (j.entry ?? {}) as Record<string, unknown>, token: String(j.token ?? ""), json: j }; } -/** The walk's verdict a review pass writes: Keep (`confirmed`) -- never `incorrect`, the bench's fact-error ruling. */ +/** The words a Keep is refused with over a clip the bench ruled. */ +export const ruledInBench = (verdict: string) => `marked ${verdict} in the bench: the Full bench changes it`; + +/** + * The walk's verdict a review pass writes: Keep (`confirmed`) -- never `incorrect`, the bench's fact-error ruling, + * and never OVER it: the clip's verdict is read at write time (the view's entry may be older than a ruling the + * bench made since), and `confirmed` is refused over `incorrect` or `rejected`. + */ export function writeWalkVerdict(project: string, clip: string, v: { verdict: "confirmed" } | { verdict: "" }): Promise<ClipWrite> { - return writeClipPatch(project, clip, v); + return writeClipPatch(project, clip, v, (c) => { + const now = typeof c.verdict === "string" ? c.verdict : null; + return v.verdict === "confirmed" && (now === "incorrect" || now === "rejected") ? ruledInBench(now) : null; + }); } diff --git a/umtool/components/projects/workspace/ReviewPass.tsx b/umtool/components/projects/workspace/ReviewPass.tsx @@ -8,7 +8,7 @@ import { clipBenchHref, openInDraftHref } from "@/lib/hrefs"; import { blockAnswer, clipKeepable, clipVerdict, reviewProgress } from "@/lib/report/reviewPassModel.mjs"; import AnchoredNotes from "@/components/notes/AnchoredNotes"; import { useSharedNotes } from "@/components/notes/NotesProvider"; -import { writeWalkVerdict } from "../bench/walkVerdict"; +import { ruledInBench, writeWalkVerdict } from "../bench/walkVerdict"; import { MANIFEST_CHANGED, announceManifestChanged } from "../timelineApi"; import VersionVerdict from "../review/VersionVerdict"; import type { PlayEntry } from "../review/PlayCut"; @@ -108,7 +108,7 @@ export function useReviewPass(project: string, entries: PlayEntry[], on: boolean // A version on screen (readOnly.ts): its marks would land on the draft's blocks. if (readOnly) return READ_ONLY_SAID; if (mark === "fix" || e.type !== "clip") return postMark(e.id, mark, note); - if (!clipKeepable(e)) return `marked ${clipVerdict(e)} in the bench: the Full bench changes it`; + if (!clipKeepable(e)) return ruledInBench(String(clipVerdict(e))); // A Fix it carried is taken back: kept now. if (marks[e.id]) { const err = await postMark(e.id, null, null); diff --git a/umtool/package.json b/umtool/package.json @@ -8,7 +8,7 @@ "build": "next build", "start": "next start --port ${UMTOOL_PORT:-3050}", "typecheck": "tsc --noEmit", - "test": "tsx --test lib/brandIcon.test.ts lib/research/*.test.ts lib/inbox/*.test.ts lib/clips/*.test.ts", + "test": "tsx --test lib/brandIcon.test.ts lib/research/*.test.ts lib/inbox/*.test.ts lib/clips/*.test.ts components/projects/bench/*.test.ts", "e2e": "node ../scripts/worktree.mjs run -- node ../scripts/queue-lock.mjs --name e2e-umtool --estimate 1500 --prebuild umtool --ports UMTOOL_E2E_PORT:3051,EDITOR_STUB_PORT:3052 -- playwright test" }, "dependencies": {