commit cc7c2f9a2bbbfe6e97d23da59043795da6438fe3
parent 18b643e46bb1b12402ae6d3a5cdd902f9ce4396d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 14 Oct 2026 04:50:32 -0400
umtool: drafts as decisions — a cut's unreviewed drafts are one Review card; reportSignature signs the review files
drafts-unreviewed: one row per drafted field still waiting (unreviewed, or
changed since approved), from r28's draftsView, kept per project against
reportSignature; one card per piece in Review ("Narration draft · 5 fields"),
its action Review drafts → /projects/<p>/review. reportSignature now signs
drafts.review.json, narration.review.json and every <task>-draft.json, so an
approve (which writes only the review file) refreshes the cache. e2e
running.spec: the Running list with stub jobs (running, queued, a draft's
spend, lanes folded), the 503 and unreachable sentences, and the drafts card
cleared by approving on the review page.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
6 files changed, 433 insertions(+), 11 deletions(-)
diff --git a/umtool/e2e/running.spec.ts b/umtool/e2e/running.spec.ts
@@ -0,0 +1,210 @@
+import { test, expect, type APIRequestContext, type Page } from "@playwright/test";
+import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import { portFor } from "yt-dlp-transcript-common/lib/ports.mjs";
+
+// ---------------------------------------------------------------------------
+// P2b: what is running, in the rail, and drafts as decisions in the Inbox.
+//
+// The Running list (components/shell/RunningList.tsx, lib/activity.ts) is
+// umtool's own jobs and the editor's live ones, from the editor stub's
+// `GET /api/ops/jobs?active=1`, which a spec controls through the stub's own
+// door (`POST /__stub/ops-jobs {mode, jobs}`, e2e/fixtures/editor-stub.mjs).
+// The editor's three ways of not answering -- unreachable, its WORKER_TOKEN
+// unset (503), and nothing running -- are three different sentences.
+//
+// The drafts card (lib/inbox.ts, lib/inbox/drafts.mjs) is written here: a
+// project whose fields a model drafted, one card in Review, its action the
+// review page; once every field is approved there, the card is gone on the
+// next read -- the approve writes only drafts.review.json, which
+// reportSignature now signs.
+// ---------------------------------------------------------------------------
+
+const HERE = path.dirname(fileURLToPath(import.meta.url));
+const FIXTURE = path.join(HERE, "..", ".e2e-song");
+const STUB = `http://127.0.0.1:${portFor("EDITOR_STUB_PORT")}`;
+
+async function editorJobs(request: APIRequestContext, mode: "ok" | "editor-token" | "unreachable", jobs: Record<string, unknown>[] = []) {
+ const r = await request.post(`${STUB}/__stub/ops-jobs`, { data: { mode, jobs } });
+ expect(r.ok(), await r.text()).toBeTruthy();
+ // Ask again now, so the page's first read is not the 2 s memo of the last test.
+ const fresh = await request.get("/api/running?fresh=1");
+ expect(fresh.ok()).toBeTruthy();
+}
+
+const running = (page: Page) => page.locator("[data-app-rail] [data-rail-section=running]");
+
+test.afterEach(async ({ request }) => {
+ await editorJobs(request, "ok", []);
+});
+
+const NOW = Date.now();
+const JOBS = [
+ { id: "e2e-lane-dl", kind: "auto-download", status: "running", queuedAt: NOW - 9e5, startedAt: NOW - 9e5, queueKey: "" },
+ { id: "e2e-lane-tx", kind: "auto-transcribe", status: "running", queuedAt: NOW - 9e5, startedAt: NOW - 9e5, queueKey: "" },
+ {
+ id: "e2e-draft-run",
+ kind: "report-draft",
+ status: "running",
+ queuedAt: NOW - 60_000,
+ startedAt: NOW - 60_000,
+ progress: { metric: "turns", initial: 0, current: 3, target: 12 },
+ log: [
+ "sweep of zeta i7 on claude-sonnet-5-5 (the Claude API, cap $5)",
+ "turn 1: search_transcripts — ~$0.04",
+ "turn 3: get_transcripts — ~$0.31",
+ ],
+ },
+ {
+ id: "e2e-sync",
+ kind: "download-missing",
+ channelSlug: "sitechan",
+ status: "running",
+ queuedAt: NOW - 30_000,
+ startedAt: NOW - 30_000,
+ progress: { metric: "downloads", initial: 2, target: 8 },
+ },
+ { id: "e2e-draft-queued", kind: "report-draft", status: "queued", queuedAt: NOW - 10_000, queue: { key: "draft:api", position: 2, queued: 2 } },
+ { id: "e2e-q1", kind: "download-missing", channelSlug: "otherchan", status: "queued", queuedAt: NOW - 5000, queue: { key: "youtube", position: 1, queued: 3 } },
+ { id: "e2e-q2", kind: "download-missing", channelSlug: "otherchan", status: "queued", queuedAt: NOW - 4000, queue: { key: "youtube", position: 2, queued: 3 } },
+ { id: "e2e-q3", kind: "download-missing", channelSlug: "otherchan", status: "queued", queuedAt: NOW - 3000, queue: { key: "youtube", position: 3, queued: 3 } },
+];
+
+test("the rail lists the editor's running and queued jobs, a draft's spend, and the day's", async ({ page, request }) => {
+ await editorJobs(request, "ok", JOBS);
+ await page.goto("/tools");
+ const r = running(page);
+ await expect(r).toHaveAttribute("data-editor-state", "ok");
+ await expect(r.locator("[data-running-count]")).toHaveAttribute("data-running-count", "2");
+ // The fixture's ledger holds today's $0.42 (iterations-fixture.mjs).
+ await expect(r.locator("[data-today-spend]")).toHaveText("$0.42 today");
+
+ // A running draft: its kind in words, its article (from the log's first
+ // line: no iteration names the job), its live spend in Meter, its turns,
+ // a bar -- and a link to the article's iterations, not the editor.
+ const draft = r.locator("[data-running=e2e-draft-run]");
+ await expect(draft).toHaveAttribute("data-running-state", "running");
+ await expect(draft.locator("[data-running-kind]")).toHaveText("Report draft");
+ await expect(draft.locator("[data-running-spend]")).toHaveText("$0.31");
+ await expect(draft.locator("[data-running-target]")).toHaveText("zeta i7 · 3/12 turns");
+ await expect(draft.locator("[data-job-progress]")).toHaveAttribute("data-job-progress", "25");
+ await expect(draft.locator("a")).toHaveAttribute("href", "/articles/zeta?tab=iterations");
+
+ // A sync: its channel, its count; it has no piece, so it links the editor's /jobs.
+ const sync = r.locator("[data-running=e2e-sync]");
+ await expect(sync.locator("[data-running-kind]")).toHaveText("Download missing");
+ await expect(sync.locator("[data-running-target]")).toHaveText("sitechan");
+ await expect(sync.locator("[data-job-progress-text]")).toHaveText("2/8 downloads");
+ await expect(sync.locator("a")).toHaveAttribute("href", `${STUB}/jobs`);
+
+ // A queued draft is a row, said as queued; queued syncs and the lanes fold.
+ const queued = r.locator("[data-running=e2e-draft-queued]");
+ await expect(queued).toHaveAttribute("data-running-state", "queued");
+ await expect(queued.locator("[data-job-progress-text]")).toHaveText("queued · 1 ahead");
+ await expect(queued.locator("[data-job-progress]")).toHaveCount(0);
+ await expect(r.locator("[data-running=e2e-q1]")).toHaveCount(0);
+ await expect(r.locator("[data-running=e2e-lane-dl]")).toHaveCount(0);
+ await expect(r.locator("[data-running-more]")).toHaveText("+ 3 queued · 2 lanes");
+ await expect(r.locator("[data-running-more]")).toHaveAttribute("href", `${STUB}/jobs`);
+ // Rows in order: running (generation first), then the queued draft.
+ await expect(r.locator("[data-running]")).toHaveCount(3);
+ expect(await r.locator("[data-running]").evaluateAll((els) => els.map((e) => e.getAttribute("data-running")))).toEqual([
+ "e2e-draft-run",
+ "e2e-sync",
+ "e2e-draft-queued",
+ ]);
+ await expect(r.locator("[data-running-empty], [data-running-editor]")).toHaveCount(0);
+
+ // The API says the same, with no tokens in it.
+ const api = await (await request.get("/api/running")).json();
+ expect(api.running).toBe(2);
+ expect(api.queued).toBe(4);
+ expect(api.more).toMatchObject({ running: 0, queued: 3, lanes: 2 });
+ expect(JSON.stringify(api)).not.toContain("umtool-e2e-token");
+});
+
+test("nothing running, the editor's token unset, and an editor that does not answer are three sentences", async ({ page, request }) => {
+ await editorJobs(request, "ok", [{ id: "e2e-lane-only", kind: "auto-publish", status: "running", queuedAt: NOW, startedAt: NOW }]);
+ await page.goto("/tools");
+ const r = running(page);
+ await expect(r).toHaveAttribute("data-editor-state", "ok");
+ await expect(r.locator("[data-running-empty]")).toHaveText("Nothing running");
+ await expect(r.locator("[data-running-more]")).toHaveText("1 lane");
+ await expect(r.locator("[data-running-count]")).toHaveAttribute("data-running-count", "0");
+
+ await editorJobs(request, "editor-token");
+ await page.reload();
+ await expect(r).toHaveAttribute("data-editor-state", "editor-token");
+ await expect(r.locator("[data-running-editor]")).toHaveText("Editor's WORKER_TOKEN not set");
+ await expect(r.locator("[data-running-editor]")).toHaveAttribute("title", /worker endpoint disabled/);
+ await expect(r.locator("[data-running-empty]")).toHaveCount(0);
+
+ await editorJobs(request, "unreachable");
+ await page.reload();
+ await expect(r).toHaveAttribute("data-editor-state", "unreachable");
+ await expect(r.locator("[data-running-editor]")).toHaveText("Editor unreachable");
+ await expect(r.locator("[data-running-empty]")).toHaveCount(0);
+ // The day's spend is the ledger's: it is said whatever the editor does.
+ await expect(r.locator("[data-today-spend]")).toHaveText("$0.42 today");
+});
+
+// ─── Drafts as decisions ────────────────────────────────────────────────────
+
+const DRAFTS = "reports/p2b-drafts";
+const DRAFTS_DIR = path.join(FIXTURE, "reports", "p2b-drafts");
+const P = (task: string, model = "qwen3:8b") => ({ task, model, at: "2026-10-14T10:00:00.000Z", iteration: 1, attempt: 1 });
+
+test.describe("drafts in the Inbox", () => {
+ test.beforeAll(() => {
+ // The build fixture's manifest as the template (nothing rewrites it), with a
+ // timeline of three drafted fields: one on-screen text, two narrations.
+ const template = JSON.parse(readFileSync(path.join(FIXTURE, "reports", "draft-review-build-fixture", "video.manifest.json"), "utf8"));
+ const manifest = {
+ ...template,
+ slug: "p2b-drafts",
+ title: "The P2b Drafts Fixture",
+ timeline: [
+ { type: "clip", id: "c01", video: "vid1", start: 3.0, end: 6.0, cite: 3, section: 0, lock: true, quote: "and because", onscreen: { title: "A drafted title" }, drafted: { onscreen: P("onscreen") } },
+ { type: "card", id: "k01", style: "chapter", seconds: "auto", heading: "One", narration: { text: "The first line." }, drafted: { narration: P("narrate") } },
+ { type: "card", id: "k02", style: "chapter", seconds: "auto", heading: "Two", narration: { text: "The second line." }, drafted: { narration: P("narrate") } },
+ ],
+ };
+ rmSync(DRAFTS_DIR, { recursive: true, force: true });
+ mkdirSync(DRAFTS_DIR, { recursive: true });
+ writeFileSync(path.join(DRAFTS_DIR, "video.manifest.json"), JSON.stringify(manifest, null, 2) + "\n");
+ });
+ test.afterAll(() => {
+ rmSync(DRAFTS_DIR, { recursive: true, force: true });
+ });
+
+ test("a cut with unreviewed drafts is one Review card; approving them on the review page clears it", async ({ page, request }) => {
+ // The API: one row per drafted field, in Review, the action the review page.
+ const rows = ((await (await request.get("/api/browse/decisions")).json()) as {
+ items: { kind: string; project: string; group: string; target: string; action: { label: string; href: string } }[];
+ }).items.filter((d) => d.kind === "drafts-unreviewed" && d.project === DRAFTS);
+ expect(rows.map((d) => d.target).sort()).toEqual(["narrate/k01/narration", "narrate/k02/narration", "onscreen/c01/onscreen"]);
+ expect(rows.every((d) => d.group === "review")).toBe(true);
+ expect(rows[0].action).toEqual({ label: "Review drafts", href: `/projects/${DRAFTS}/review` });
+
+ await page.goto("/");
+ const card = page.locator("[data-group=review] [data-card=drafts-unreviewed]").filter({ hasText: "The P2b Drafts Fixture" });
+ await expect(card).toHaveCount(1);
+ await expect(card.locator("[data-count]")).toHaveText("3");
+ await expect(card).toContainText("On-screen text and narration drafts · 3 fields · by qwen3:8b");
+ await card.locator("[data-action-link]").click();
+ await expect(page).toHaveURL(new RegExp(`/projects/${DRAFTS}/review$`));
+
+ for (const address of ["onscreen/c01/onscreen", "narrate/k01/narration", "narrate/k02/narration"]) {
+ const row = page.locator(`[data-draft-row="${address}"]`);
+ await row.locator('[data-draft-action="approve"]').click();
+ await expect(row).toHaveAttribute("data-state", "approved");
+ }
+
+ // Only drafts.review.json was written; the card is gone on the next read.
+ await page.goto("/");
+ await expect(page.locator("[data-group=review] [data-card=drafts-unreviewed]").filter({ hasText: "The P2b Drafts Fixture" })).toHaveCount(0);
+ const after = ((await (await request.get("/api/browse/decisions")).json()) as { items: { kind: string; project: string }[] }).items;
+ expect(after.filter((d) => d.kind === "drafts-unreviewed" && d.project === DRAFTS)).toEqual([]);
+ });
+});
diff --git a/umtool/lib/inbox.ts b/umtool/lib/inbox.ts
@@ -5,7 +5,11 @@ import { ARTICLES_KEY } from "./paths";
import { readArticleIterations, type IterationRow } from "./articles/generation";
import { sitesPaths } from "./articles/sites";
import { decisionsForSong, type Decision } from "./decisions";
-import { openDecisions } from "./projects";
+import { openDecisions, projectRefs, summariseProject, type ProjectRef } from "./projects";
+import { readManifest, reportSignature } from "./projects/report.mjs";
+import { draftsView } from "./report/drafts.mjs";
+import { reviewHref } from "./hrefs";
+import { draftsDecisions } from "./inbox/drafts.mjs";
import { pieceOfDecision, readPieceGraph, type Piece, type PieceGraph } from "./pieces";
import { lifecycleOf, readLifecycle, type LifecycleRead } from "./lifecycle";
import { isMuted, readMutes } from "./mutes";
@@ -26,14 +30,19 @@ import { GROUPS, annotate, rankDecisions, summarizeGroups } from "./inbox/groups
// link-ambiguous an article whose video only a slug suggests
// looks-done a piece every signal says is finished (a suggestion:
// it never sets the lifecycle)
+// drafts-unreviewed a report cut's field a model drafted that nobody has
+// reviewed (r28's draftsView; lib/inbox/drafts.mjs), one
+// row per field, kept per project against
+// reportSignature -- which signs the review files, so an
+// approve drops the card on the next read
//
// -- each row given its piece, category, group, one action, lifecycle and
// `hidden` (lib/inbox/groups.mjs), ranked. One row per decision, never dropped:
// the MCP reads `items[]` (mcp/src/archivalTools.ts).
//
// No editor call anywhere here: there is no "waiting on a cap" state (the daily
-// cap refuses at start, a per-job cap ends the run), and running jobs are
-// P2b's.
+// cap refuses at start, a per-job cap ends the run), and running jobs are the
+// rail's (lib/activity.ts readRunning).
//
// SERVER ONLY.
// ---------------------------------------------------------------------------
@@ -218,11 +227,48 @@ async function spendByJob(): Promise<Map<string, number>> {
return out;
}
-/** The decisions read from disk beside openDecisions(): iterations, research, links, looks-done. */
+// One project's drafts decisions, kept against its reportSignature (on
+// globalThis: one cache per process, not per Next bundle).
+type DraftsMemo = Map<string, { sig: string; value: Decision[] }>;
+const gd = globalThis as typeof globalThis & { __umtoolDraftsMemo?: DraftsMemo };
+const draftsMemo: DraftsMemo = (gd.__umtoolDraftsMemo ??= new Map());
+
+async function projectDrafts(ref: ProjectRef): Promise<Decision[]> {
+ const sig = String(await reportSignature(ref.dir));
+ const hit = draftsMemo.get(ref.id);
+ if (hit && hit.sig === sig) return hit.value;
+ let value: Decision[] = [];
+ const manifest = await readManifest(ref.dir);
+ if (manifest) {
+ const view = await draftsView(ref.dir, manifest);
+ if (view.rows.some((r) => r.drafted && (r.state === "unreviewed" || r.state === "edited"))) {
+ const title = (await summariseProject(ref)).title;
+ // When: the manifest's mtime (reportSignature's first field) -- a draft is written there.
+ const at = Number(sig.split(":")[0]) || Date.now();
+ value = draftsDecisions({ project: ref.id, projectTitle: title, href: reviewHref(ref.id), at, view }).map((d) => ({
+ ...d,
+ projectKind: ref.kind,
+ })) as Decision[];
+ }
+ }
+ draftsMemo.set(ref.id, { sig, value });
+ return value;
+}
+
+/** Every project's unreviewed drafts. A project that cannot be read adds nothing. */
+export async function draftsDecisionsAll(): Promise<Decision[]> {
+ const refs = await projectRefs();
+ const live = new Set(refs.map((r) => r.id));
+ for (const id of draftsMemo.keys()) if (!live.has(id)) draftsMemo.delete(id);
+ const per = await Promise.all(refs.map((r) => projectDrafts(r).catch(() => [] as Decision[])));
+ return per.flat();
+}
+
+/** The decisions read from disk beside openDecisions(): iterations, research, links, looks-done, drafts. */
export async function diskDecisions(graph: PieceGraph, life: LifecycleRead): Promise<Decision[]> {
- const spend = await spendByJob();
+ const [spend, drafts] = await Promise.all([spendByJob(), draftsDecisionsAll().catch(() => [] as Decision[])]);
const perArticle = await Promise.all(storeArticles(graph).map((p) => iterationDecisions(p, spend)));
- return [...perArticle.flat(), ...pieceDecisions(graph, life)];
+ return [...perArticle.flat(), ...pieceDecisions(graph, life), ...drafts];
}
/**
diff --git a/umtool/lib/inbox/drafts.mjs b/umtool/lib/inbox/drafts.mjs
@@ -0,0 +1,64 @@
+// DRAFTS AS DECISIONS (plans/umtool-redesign.md, P2b): a report project whose
+// fields a model drafted and nobody has reviewed is a call in the Inbox's
+// Review group -- one row per field (the API keeps one row per decision), one
+// card per piece ("narration draft · 5 fields"), its action the project's
+// review page. Pure: lib/inbox.ts reads r28's draftsView() and hands its rows
+// here.
+//
+// "Not yet reviewed" is what a final build would refuse for want of an
+// approval: `unreviewed` (never judged) and `edited` (judged, then the field
+// changed under the verdict). A rejected draft is a ruling already made.
+
+/** The review states that wait on the operator. */
+export const WAITING = new Set(["unreviewed", "edited"]);
+
+/**
+ * The card's sentence: which kinds of field, how many, and who drafted them.
+ *
+ * @param {{ label: string, state: string, drafted: { model?: string } | null }[]} rows the waiting rows
+ */
+export function draftsWhy(rows) {
+ const byLabel = new Map();
+ for (const r of rows) byLabel.set(r.label, (byLabel.get(r.label) ?? 0) + 1);
+ const labels = [...byLabel.keys()];
+ const head =
+ labels.length === 1
+ ? `${labels[0]} draft`
+ : labels.length === 2
+ ? `${labels[0]} and ${labels[1]} drafts`
+ : `${labels[0]}, ${labels[1]} and ${labels.length - 2} more drafts`;
+ const n = rows.length;
+ const models = [...new Set(rows.map((r) => r.drafted?.model).filter(Boolean))];
+ const edited = rows.filter((r) => r.state === "edited").length;
+ return [
+ `${head[0].toUpperCase()}${head.slice(1)} · ${n} field${n === 1 ? "" : "s"}`,
+ models.length ? `by ${models.join(", ")}` : null,
+ edited ? `${edited} changed since approved` : null,
+ ]
+ .filter(Boolean)
+ .join(" · ");
+}
+
+/**
+ * The `drafts-unreviewed` rows of one project.
+ *
+ * @param {{
+ * project: string, projectTitle: string, href: string, at: number,
+ * view: { rows: { address: string, label: string, state: string, drafted: { model?: string } | null }[] },
+ * }} o
+ */
+export function draftsDecisions({ project, projectTitle, href, at, view }) {
+ const waiting = (view?.rows ?? []).filter((r) => r.drafted && WAITING.has(r.state));
+ if (!waiting.length) return [];
+ const why = draftsWhy(waiting);
+ return waiting.map((r) => ({
+ project,
+ projectTitle,
+ kind: "drafts-unreviewed",
+ target: r.address,
+ why,
+ href,
+ severity: "open",
+ at,
+ }));
+}
diff --git a/umtool/lib/inbox/drafts.test.mjs b/umtool/lib/inbox/drafts.test.mjs
@@ -0,0 +1,79 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { mkdtemp, rm, writeFile, utimes } from "node:fs/promises";
+import os from "node:os";
+import path from "node:path";
+import { draftsDecisions, draftsWhy } from "./drafts.mjs";
+import { annotate, summarizeGroups } from "./groups.mjs";
+import { reportSignature } from "../projects/report.mjs";
+
+const row = (address, label, state, model = "qwen3:8b") => ({ address, label, state, drafted: { model } });
+
+test("one row per waiting field; approved, rejected and the operator's own are not waiting", () => {
+ const view = {
+ rows: [
+ row("narrate/k01/narration", "narration", "unreviewed"),
+ row("narrate/k02/narration", "narration", "edited"),
+ row("onscreen/c02/onscreen", "on-screen text", "approved"),
+ row("teaser/t01/lines", "teaser lines", "rejected"),
+ { address: "narrate/k03/narration", label: "narration", state: "unreviewed", drafted: null },
+ ],
+ };
+ const out = draftsDecisions({ project: "reports/x", projectTitle: "X", href: "/projects/reports/x/review", at: 5, view });
+ assert.deepEqual(out.map((d) => d.target), ["narrate/k01/narration", "narrate/k02/narration"]);
+ assert.ok(out.every((d) => d.kind === "drafts-unreviewed" && d.severity === "open" && d.href === "/projects/reports/x/review"));
+ assert.equal(out[0].why, "Narration draft · 2 fields · by qwen3:8b · 1 changed since approved");
+ assert.deepEqual(draftsDecisions({ project: "p", projectTitle: "p", href: "/", at: 0, view: { rows: [row("a", "narration", "approved")] } }), []);
+});
+
+test("the sentence names the kinds of field and the models", () => {
+ assert.equal(draftsWhy([row("a", "narration", "unreviewed")]), "Narration draft · 1 field · by qwen3:8b");
+ assert.equal(
+ draftsWhy([row("a", "narration", "unreviewed"), row("b", "on-screen text", "unreviewed", "claude-sonnet-5-5")]),
+ "Narration and on-screen text drafts · 2 fields · by qwen3:8b, claude-sonnet-5-5",
+ );
+ assert.equal(
+ draftsWhy([row("a", "narration", "unreviewed"), row("b", "teaser lines", "unreviewed"), row("c", "flips", "unreviewed"), row("d", "threads", "unreviewed")]),
+ "Narration, teaser lines and 2 more drafts · 4 fields · by qwen3:8b",
+ );
+});
+
+test("drafts are Review calls: one card per piece, the action Review drafts", () => {
+ const view = { rows: [row("narrate/k01/narration", "narration", "unreviewed"), row("narrate/k02/narration", "narration", "unreviewed")] };
+ const rows = annotate(draftsDecisions({ project: "reports/x", projectTitle: "X", href: "/projects/reports/x/review", at: 1, view }), {
+ pieceOf: () => "p:reports/x",
+ lifecycleOf: () => "active",
+ });
+ assert.ok(rows.every((d) => d.group === "review" && d.category === "review"));
+ assert.deepEqual(rows[0].action, { label: "Review drafts", href: "/projects/reports/x/review" });
+ const review = summarizeGroups(rows).find((g) => g.id === "review");
+ assert.equal(review.cards.length, 1);
+ assert.equal(review.cards[0].count, 2);
+});
+
+test("reportSignature moves when a review or a draft file is written, not only the manifest", async () => {
+ const dir = await mkdtemp(path.join(os.tmpdir(), "umtool-sig-"));
+ try {
+ await writeFile(path.join(dir, "video.manifest.json"), "{}\n");
+ const a = await reportSignature(dir);
+ await writeFile(path.join(dir, "drafts.review.json"), '{"rows":{}}\n');
+ const b = await reportSignature(dir);
+ assert.notEqual(b, a, "drafts.review.json");
+ await writeFile(path.join(dir, "narration.review.json"), "{}\n");
+ const c = await reportSignature(dir);
+ assert.notEqual(c, b, "narration.review.json");
+ await writeFile(path.join(dir, "onscreen-draft.json"), "{}\n");
+ const d = await reportSignature(dir);
+ assert.notEqual(d, c, "a <task>-draft.json");
+ // A rewrite of the same size is still seen: the mtime is signed.
+ const later = new Date(Date.now() + 5000);
+ await utimes(path.join(dir, "drafts.review.json"), later, later);
+ assert.notEqual(await reportSignature(dir), d, "the review's mtime");
+ // A file that only looks like one is not signed.
+ const e = await reportSignature(dir);
+ await writeFile(path.join(dir, "notes-draft.txt"), "x");
+ assert.equal(await reportSignature(dir), e);
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
diff --git a/umtool/lib/inbox/groups.mjs b/umtool/lib/inbox/groups.mjs
@@ -8,8 +8,8 @@
//
// your-call research proposals, then failed runs: money is waiting
// on a yes or no ("spend")
-// review a finished iteration that is not current (r28's drafts
-// join here in P2b)
+// review a finished iteration that is not current; a cut whose
+// drafted fields nobody has reviewed (r28's drafts, P2b)
// blocking something downstream would lie, on an ACTIVE piece
// notes the operator's open notes
// open every other open decision (a variant with no verdict, a
@@ -43,6 +43,7 @@ const KIND_CATEGORY = {
"research-proposal": "spend",
"iteration-failed": "spend",
"iteration-ready": "review",
+ "drafts-unreviewed": "review",
"open-note": "note",
"unreadable-notes": "fix",
"link-ambiguous": "choose",
@@ -75,7 +76,7 @@ export function groupOf(d) {
// Within a group: the brief's order first (proposals before failed runs), then
// everything else as equals.
-const KIND_RANK = { "research-proposal": 0, "iteration-failed": 1, "iteration-ready": 0, "unreadable-notes": 0 };
+const KIND_RANK = { "research-proposal": 0, "iteration-failed": 1, "iteration-ready": 0, "drafts-unreviewed": 1, "unreadable-notes": 0 };
const SEVERITY_RANK = { blocking: 0, open: 1, info: 2 };
// ONE primary action per decision, its button copy naming the result.
@@ -83,6 +84,7 @@ const ACTION_LABEL = {
"research-proposal": "Approve acquisition",
"iteration-failed": "Retry run",
"iteration-ready": (d) => `Make ${d.target} current`,
+ "drafts-unreviewed": "Review drafts",
"open-note": "Answer note",
"unreadable-notes": "Repair notes.json",
"link-ambiguous": "Link the video",
diff --git a/umtool/lib/projects/report.mjs b/umtool/lib/projects/report.mjs
@@ -19,6 +19,7 @@ import { deliverablesState, finishCommand, outDirState, leftoversOf } from "../r
import { CHANNELS_DIR, inside } from "../paths.mjs";
import { channelName, cleanTitle } from "umtool-report-to-video/attribution";
import { teaserTitle } from "umtool-report-to-video/deck";
+import { DRAFTS_REVIEW_FILE, NARRATION_REVIEW_FILE } from "umtool-report-to-video/drafts-review";
/**
* Where a build's per-entry segments live.
@@ -489,9 +490,22 @@ export async function buildStateOf(dir, manifest) {
};
}
-/** The signature the summary and the decisions are cached against. */
+/** A task's draft file beside the manifest (lib/report/drafts.mjs DRAFT_FILE_RE). */
+const DRAFT_FILE = /^[a-z0-9][a-z0-9-]{0,62}-draft\.json$/;
+
+/**
+ * The signature the summary and the decisions are cached against.
+ *
+ * It signs the drafts review too (release 28; P2b): `drafts.review.json`,
+ * release 25's `narration.review.json` and every `<task>-draft.json`. An
+ * approve on the review page writes only the first, never the manifest -- so
+ * without them a cache keyed on this would keep a card for drafts that were
+ * approved a minute ago.
+ */
export async function reportSignature(dir) {
- const [man, out, avail, rev] = await Promise.all([
+ const names = await readdir(dir).catch(() => []);
+ const drafts = names.filter((n) => DRAFT_FILE.test(n)).sort();
+ const [man, out, avail, rev, review, narration, ...draftStats] = await Promise.all([
stat0(manifestPath(dir)),
stat0(path.join(dir, "out")),
// Rewritten IN PLACE by every preflight, which leaves out/'s own mtime
@@ -499,13 +513,20 @@ export async function reportSignature(dir) {
// never reach the index.
stat0(path.join(dir, "out", "availability.json")),
stat0(path.join(dir, "revisions")),
+ stat0(path.join(dir, DRAFTS_REVIEW_FILE)),
+ stat0(path.join(dir, NARRATION_REVIEW_FILE)),
+ ...drafts.map((n) => stat0(path.join(dir, n))),
]);
+ const signed = (s) => `${Math.round(s?.mtimeMs ?? 0)}.${s?.size ?? 0}`;
return [
Math.round(man?.mtimeMs ?? 0),
man?.size ?? 0,
Math.round(out?.mtimeMs ?? 0),
Math.round(avail?.mtimeMs ?? 0),
Math.round(rev?.mtimeMs ?? 0),
+ signed(review),
+ signed(narration),
+ drafts.map((n, i) => `${n}@${signed(draftStats[i])}`).join(","),
].join(":");
}