Archilyzer · Source

archilyzer

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

commit a627767792aea8f47a0e7432e8d8712f3daabd13
parent b719d8ad3172b3c17c8d041294bc87c092f6b4f6
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 14 Oct 2026 08:51:00 -0400

umtool: one stage rule — the piece stepper and Work's stage facet read the same function

- pieceSteps({kind, reached, lifecycle}) (lib/pieces/tabs.mjs) replaces
  stepsOf/articleSteps: the furthest stage reached is current (a built video
  not yet delivered is at Video, as the canvas has it); a skipped stage is to
  do with its reason ("no report yet"); `na` with its reason as before.
  stageOfPiece is its current step.
- The pieces graph records each piece's `reached` (iterations or a board,
  a report, a claimed video, looks done) and an article's `stage` is
  stageOfPiece; Work's stageOf reads `reached`; both piece frames read the
  graph's facts (with the board, iterations and report read fresh). The
  graph's memo signature includes the research cases.
- Unit: the four cases (a standalone video, a board's video, an article in
  the making with a video, a published article with its video) give the same
  stage from the stepper and from Work's facet. Specs: zeta is at Video.

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

Diffstat:
Mumtool/e2e/article-iterations.spec.ts | 5+++--
Mumtool/e2e/inbox-engine.spec.ts | 2+-
Mumtool/e2e/piece.spec.ts | 14++++++++++----
Mumtool/lib/pieces.ts | 58+++++++++++++++++++++++++++++++++++++++++++++++++---------
Mumtool/lib/pieces/article.ts | 27++++++++++++++-------------
Aumtool/lib/pieces/cases.ts | 14++++++++++++++
Mumtool/lib/pieces/frame.ts | 25+++++++++----------------
Mumtool/lib/pieces/tabs.mjs | 113++++++++++++++++++++++++++++++++++---------------------------------------------
Mumtool/lib/pieces/tabs.test.mjs | 82++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mumtool/lib/work.ts | 4++--
Mumtool/lib/work/facets.mjs | 13++++++++++---
Mumtool/lib/work/facets.test.mjs | 3+++
12 files changed, 203 insertions(+), 157 deletions(-)

diff --git a/umtool/e2e/article-iterations.spec.ts b/umtool/e2e/article-iterations.spec.ts @@ -33,11 +33,12 @@ test.afterAll(() => rmSync(path.join(FIXTURE, "articles", ARTICLE), { recursive: const card = (page: Page, n: number) => page.locator(`[data-iteration='${n}']`); test("an article in the making: listed as such on Work, opened as its piece, its iterations a tab", async ({ page }) => { - // /articles is Work's articles since P3: zeta is a piece at the Research stage. + // /articles is Work's articles since P3. zeta is in the making, and its + // iterations already made a video: at Video, by the one stage rule (P4a-2). await page.goto("/articles"); const row = page.locator("[data-lit-line][data-piece='a:articles/zeta']"); await expect(row).toHaveAttribute("data-status", "in the making"); - await expect(row).toHaveAttribute("data-stage", "research"); + await expect(row).toHaveAttribute("data-stage", "video"); await row.getByRole("link", { name: "zeta" }).click(); // The article piece (P4a-2) opens on its Overview, the iterations summarised there. await expect(page).toHaveURL(new RegExp(`${urls.articleHref(ZETA)}$`)); diff --git a/umtool/e2e/inbox-engine.spec.ts b/umtool/e2e/inbox-engine.spec.ts @@ -125,7 +125,7 @@ test("a parked piece's decisions are hidden, never dropped; active again shows t const pieces = await (await request.get("/api/pieces")).json(); const z = pieces.pieces.find((p: { id: string }) => p.id === ZETA); - expect(z).toMatchObject({ kind: "article", site: "articles", report: "zeta", status: "in the making", stage: "research", lifecycle: "parked", lifecycleBy: "operator" }); + expect(z).toMatchObject({ kind: "article", site: "articles", report: "zeta", status: "in the making", stage: "video", lifecycle: "parked", lifecycleBy: "operator" }); expect(z.projects.map((p: { id: string; via: string }) => `${p.id}:${p.via}`).sort()).toEqual(["gen-projects/zeta/i1:iteration", "gen-projects/zeta/i3:iteration"]); expect(z.decisions.hidden).toBe(zetaRows.length); diff --git a/umtool/e2e/piece.spec.ts b/umtool/e2e/piece.spec.ts @@ -185,13 +185,19 @@ test("an article piece: nine tabs, the stepper by what exists, the policy chip, await expect(tab(page, "iterations")).toHaveText("Iterations4"); await expect(tab(page, "cut")).toHaveText("Cut1"); - // Iterations exist (Research done), no report yet (Article current), its - // iterations made a video (Video done), nothing delivered. + // The one stage rule: iterations (Research done), no report yet (Article to + // do, and why), its iterations made a video (Video current), nothing delivered + // -- the stage Work's facet shows too. const steps = page.getByRole("list", { name: "Stage" }).locator("li"); await expect(steps.nth(0)).toHaveAttribute("data-step", "done"); - await expect(steps.nth(1)).toHaveAttribute("aria-current", "step"); - await expect(steps.nth(2)).toHaveAttribute("data-step", "done"); + await expect(steps.nth(1)).toHaveAttribute("data-step", "todo"); + await expect(steps.nth(1)).toHaveAttribute("title", "no report yet"); + await expect(steps.nth(2)).toHaveAttribute("aria-current", "step"); await expect(steps.nth(3)).toHaveAttribute("data-step", "todo"); + await expect(page.locator("[data-piece-frame='a:articles/zeta']")).toHaveAttribute("data-piece-stage", "video"); + await page.goto(urls.workHref({ kind: "article" })); + await expect(page.locator("[data-lit-line][data-piece='a:articles/zeta']")).toHaveAttribute("data-stage", "video"); + await page.goto(urls.articleHref(ZETA)); // The policy is a chip linking its page, not the panel. await expect(page.locator("[data-policy-chip]")).toHaveAttribute("href", urls.generationPolicyHref()); diff --git a/umtool/lib/pieces.ts b/umtool/lib/pieces.ts @@ -1,4 +1,5 @@ -import { readdir } from "node:fs/promises"; +import { readdir, stat } from "node:fs/promises"; +import path from "node:path"; import { listPendingArticles } from "yt-dlp-transcript-common/lib/report/registry"; import { ARTICLES_KEY, REPORTS_ROOT } from "./paths"; import { articleHref } from "./articles/href"; @@ -9,6 +10,9 @@ import type { ProjectSummary } from "./project-types"; import { listBatches } from "./report/deliver.mjs"; import { articleOfDecisionProject, articlePieceId, projectPieceId } from "./pieces/ids.mjs"; import { lifecycleOf, readLifecycle, type LifecycleRead, type LifecycleState } from "./lifecycle"; +import { boardOfArticle, boardOfProject } from "./pieces/board.mjs"; +import { readCases } from "./pieces/cases"; +import { stageOfPiece } from "./pieces/tabs.mjs"; import type { Decision } from "./decisions"; export { articlePieceId, casePieceId, formatPieceId, isPieceId, parsePieceId, projectPieceId } from "./pieces/ids.mjs"; @@ -64,11 +68,14 @@ export type Piece = { /** A store article's audience (public | private); a site's report and a project have none. */ audience: string | null; /** - * Where it is. An article: research (in the making) → article (no video) → - * video → deliver (looks done). A project: its own state (draft, windows, - * fetched, built, shipped, stale). + * Where it is. An article: the step its stepper has current, by the one + * stage rule (lib/pieces/tabs.mjs pieceSteps over `reached`). A project: its + * own state (draft, windows, fetched, built, shipped, stale) -- Work's stage + * facet reads `reached` for it too. */ stage: string; + /** What the piece has reached, the one stage rule's facts (lib/pieces/tabs.mjs pieceSteps). */ + reached: { research: boolean; article: boolean; video: boolean; deliver: boolean }; projects: PieceProject[]; /** Slug matches nobody has chosen between (link-ambiguous). */ possible: { id: string; title: string }[]; @@ -108,11 +115,33 @@ export function clearPiecesCache(): void { * rather than when the memo runs out. */ async function storeSignature(): Promise<string> { + let store = ""; try { - return (await readdir(/* turbopackIgnore: true */ sitesPaths().articlesDir)).sort().join("\u0000"); + store = (await readdir(/* turbopackIgnore: true */ sitesPaths().articlesDir)).sort().join("\u0000"); } catch { - return ""; + store = ""; } + // The research cases too (R2): a board's hand-off makes a piece's Research + // stage, so a new hand-off is seen at once (one stat per case; cases are few). + const dir = path.join(/* turbopackIgnore: true */ REPORTS_ROOT, ".umtool", "research"); + const cases = await readdir(/* turbopackIgnore: true */ dir).catch(() => [] as string[]); + const stamps = await Promise.all( + cases.sort().map((c) => + stat(/* turbopackIgnore: true */ path.join(/* turbopackIgnore: true */ dir, c, "case.json")).then( + (st) => `${c}:${st.mtimeMs}`, + () => "", + ), + ), + ); + return `${store}\u0001${stamps.join("\u0000")}`; +} + +/** How many iterations the article store holds for an article (a readdir). */ +async function hasIterations(id: string): Promise<boolean> { + const names = await readdir(/* turbopackIgnore: true */ path.join(/* turbopackIgnore: true */ sitesPaths().articlesDir, id, "iterations")).catch( + () => [] as string[], + ); + return names.some((n) => /^[1-9][0-9]*$/.test(n)); } export async function readPieceGraph(): Promise<PieceGraph> { @@ -200,12 +229,13 @@ async function projectLooksDone(p: ProjectSummary): Promise<string | null> { async function buildGraph(): Promise<PieceGraph> { // The article side must never take the decisions down with it: a site whose // site.json does not read is an article list without that site, not a 500. - const [sites, store, pending, summaries, its] = await Promise.all([ + const [sites, store, pending, summaries, its, cases] = await Promise.all([ listSiteRows().catch(() => []), readStoreRow().catch(() => ({ articles: [] as ArticleRow[] })), pendingArticles().catch(() => [] as ArticleIn[]), listProjects(), iterationProjects().catch(() => new Map<string, { current: boolean }[]>()), + readCases().catch(() => []), ]); const articles: ArticleIn[] = [ ...sites.flatMap((s) => s.articles.map(fromRow)), @@ -251,6 +281,14 @@ async function buildGraph(): Promise<PieceGraph> { if (why) looksDone.push(why); } const newestMs = Math.max(a.mtimeMs, ...projects.map((p) => summaryOf.get(p.id)?.newestMtimeMs ?? 0)); + const href = articleHref({ site: a.site, id: a.id }); + const owned = projects.filter((p) => pieceOfProject.get(p.id) === id).length; + const reached = { + research: (a.site === ARTICLES_KEY && (a.status === "in the making" || (await hasIterations(a.id)))) || !!boardOfArticle(href, cases), + article: a.status !== "in the making", + video: owned > 0 || a.unreachable.length > 0 || a.hasVideo || currentVideo, + deliver: looksDone.length > 0, + }; pieces.push({ id, kind: "article", @@ -258,10 +296,11 @@ async function buildGraph(): Promise<PieceGraph> { site: a.site, report: a.id, project: null, - href: articleHref({ site: a.site, id: a.id }), + href, status: a.status, audience: a.audience, - stage: a.status === "in the making" ? "research" : !projects.length ? "article" : looksDone.length ? "deliver" : "video", + stage: stageOfPiece({ kind: "article", reached }), + reached, projects, possible: a.possible, unreachable: a.unreachable, @@ -284,6 +323,7 @@ async function buildGraph(): Promise<PieceGraph> { status: null, audience: null, stage: p.state, + reached: { research: !!boardOfProject(p.id, cases), article: false, video: true, deliver: !!why || p.state === "shipped" }, projects: [], possible: [], unreachable: [], diff --git a/umtool/lib/pieces/article.ts b/umtool/lib/pieces/article.ts @@ -6,8 +6,9 @@ import { articleHref, projectHref } from "../hrefs"; import { lifecycleOf, readLifecycle } from "../lifecycle"; import { articlePieceId, readPieceGraph, type Piece, type PieceGraph, type PieceProject } from "../pieces"; import { boardOfArticle } from "./board.mjs"; -import { readCases, type PieceFrame } from "./frame"; -import { PIECE_TAB_IDS, articleStageOf, articleSteps, tabOfNoteAnchor } from "./tabs.mjs"; +import { readCases } from "./cases"; +import type { PieceFrame } from "./frame"; +import { PIECE_TAB_IDS, pieceSteps, stageOfPiece, tabOfNoteAnchor } from "./tabs.mjs"; // --------------------------------------------------------------------------- // THE ARTICLE-ROOTED PIECE (plans/umtool-redesign.md, P4a-2): an article and @@ -123,7 +124,7 @@ export type ArticlePieceFrame = PieceFrame & { /** * An article piece's frame: the piece, its lifecycle, the board that seeded - * it, and the stepper by what is on disk (lib/pieces/tabs.mjs articleSteps). + * it, and the stepper by the one stage rule (lib/pieces/tabs.mjs pieceSteps). */ export async function readArticlePieceFrame( site: string, @@ -135,15 +136,15 @@ export async function readArticlePieceFrame( const piece = graph.byId.get(pieceId) ?? null; const lifecycle = lifecycleOf(life, pieceId); const board = boardOfArticle(articleHref({ site, id: report }), cases); - const owned = piece ? piece.projects.filter((p) => graph.pieceOfProject.get(p.id) === pieceId) : []; - const steps = articleSteps({ - research: hasIterations || !!board, - article: hasReport, - video: owned.length > 0 || (piece?.unreachable.length ?? 0) > 0, - deliver: (piece?.looksDone.length ?? 0) > 0, - lifecycle, - researchNa: "no iterations or research board", - }) as PieceFrame["steps"]; + // The one stage rule (lib/pieces/tabs.mjs pieceSteps), on the graph's facts -- + // the same Work's stage facet reads -- with what this page read fresh: its + // iterations, its report, the board (the graph is memoised). + const reached = { + ...(piece?.reached ?? { video: false, deliver: false }), + ...(hasIterations || board ? { research: true } : {}), + article: hasReport || !!piece?.reached?.article, + }; + const steps = pieceSteps({ kind: "article", reached, lifecycle }) as PieceFrame["steps"]; return { piece, pieceId, @@ -152,7 +153,7 @@ export async function readArticlePieceFrame( lifecycle, lifecycleError: life.error ?? null, steps, - stage: articleStageOf(steps), + stage: stageOfPiece({ kind: "article", reached }), site, report, }; diff --git a/umtool/lib/pieces/cases.ts b/umtool/lib/pieces/cases.ts @@ -0,0 +1,14 @@ +import { listCases, readCase } from "../research/cases.mjs"; +import { REPORTS_ROOT } from "../paths"; + +// Every research case that reads (R2), for the pieces a board's hand-offs made +// (lib/pieces/board.mjs). Cases are few; one that does not read is skipped, +// never an error on a piece page or in the pieces graph. SERVER ONLY. + +export type CaseDoc = { id: string; title: string; handoffs?: { to: string; href: string; at?: string }[] }; + +export async function readCases(): Promise<CaseDoc[]> { + const list = (await listCases(REPORTS_ROOT).catch(() => [])) as { id: string; error?: string }[]; + const cases = await Promise.all(list.filter((c) => !c.error).map((c) => readCase(REPORTS_ROOT, c.id).catch(() => null))); + return cases.filter(Boolean) as CaseDoc[]; +} diff --git a/umtool/lib/pieces/frame.ts b/umtool/lib/pieces/frame.ts @@ -3,11 +3,9 @@ import { summarizeGroups } from "../inbox/groups.mjs"; import { whatOf } from "../inbox/what.mjs"; import { lifecycleOf, readLifecycle, type LifecycleState } from "../lifecycle"; import { projectPieceId, readPieceGraph, type Piece } from "../pieces"; -import { stageOf } from "../work/facets.mjs"; -import { pieceSteps } from "./tabs.mjs"; +import { pieceSteps, stageOfPiece } from "./tabs.mjs"; import { boardOfProject } from "./board.mjs"; -import { listCases, readCase } from "../research/cases.mjs"; -import { REPORTS_ROOT } from "../paths"; +import { readCases } from "./cases"; import type { Decision } from "../decisions"; // --------------------------------------------------------------------------- @@ -43,14 +41,7 @@ export type PieceFrame = { stage: string; }; -type CaseDoc = { id: string; title: string; handoffs?: { to: string; href: string; at?: string }[] }; - -/** Every research case that reads (R2). Cases are few; one that does not read is skipped, never an error on a piece page. */ -export async function readCases(): Promise<CaseDoc[]> { - const list = (await listCases(REPORTS_ROOT).catch(() => [])) as { id: string; error?: string }[]; - const cases = await Promise.all(list.filter((c) => !c.error).map((c) => readCase(REPORTS_ROOT, c.id).catch(() => null))); - return cases.filter(Boolean) as CaseDoc[]; -} +export { readCases } from "./cases"; /** The research board a project was scaffolded from: the case whose video hand-off names it (lib/pieces/board.mjs). */ async function boardOf(projectId: string): Promise<PieceFrame["board"]> { @@ -67,11 +58,13 @@ export async function readPieceFrame(project: { id: string; state?: string | nul piece && piece.kind === "article" && piece.site && piece.report ? { title: piece.title, site: piece.site, report: piece.report, href: piece.href, via: own?.via ?? "slug", cut: own?.cut ?? false } : null; - const stage = piece - ? stageOf({ kind: piece.kind, stage: piece.stage, looksDone: piece.looksDone, projectState: piece.kind === "project" ? piece.stage : null }) - : "video"; + // The one stage rule (lib/pieces/tabs.mjs pieceSteps): the graph's facts, so + // the stepper here and Work's stage facet read the same answer. const kind = piece?.kind ?? "project"; - const steps = pieceSteps({ kind, bucket: stage, lifecycle, fromBoard: kind === "project" && !!board }) as PieceFrame["steps"]; + // The board is read fresh (the graph is memoised): a board's hand-off shows at once. + const reached = { ...(piece?.reached ?? { video: true }), ...(board ? { research: true } : {}) }; + const steps = pieceSteps({ kind, reached, lifecycle }) as PieceFrame["steps"]; + const stage = stageOfPiece({ kind, reached }); return { piece, pieceId, article, board, lifecycle, lifecycleError: life.error ?? null, steps, stage }; } diff --git a/umtool/lib/pieces/tabs.mjs b/umtool/lib/pieces/tabs.mjs @@ -24,39 +24,62 @@ export const STAGE_STEPS = [ ]; /** - * The stepper, lit for one bucket: the stages before it done, it current, the - * rest to do; a stage that does not apply to this piece is `na` (dimmed, with - * its reason as `title`). A piece marked done has walked every stage it has. + * THE ONE STAGE RULE (P4a-2 follow-up): a piece's stepper, and so its stage -- + * the step that is current -- from what the piece has REACHED. The piece page's + * stepper and Work's stage facet (lib/work/facets.mjs stageOf, lib/pieces.ts's + * article `stage`) both read it, so they can never disagree. * - * @param {string} bucket research | article | video | deliver - * @param {string} lifecycle active | parked | done - * @param {Record<string, string>} [na] stage id → why it does not apply - * @returns {{ label: string, state: "done" | "current" | "todo" | "na", title?: string }[]} + * Research reached with iterations, or a research board that seeded it + * Article reached with a report (an article piece's own) + * Video reached with a video project it claims (or a video in the + * report); a project piece IS its video, always reached + * Deliver reached when it looks done (a final video and a share batch, + * or published with its video; a song with every cut) + * + * The current step is the furthest reached (the canvas's: a built video not + * yet delivered is at Video); the steps before it are done, or to do with the + * reason when they were skipped (an article in the making whose iterations + * already made a video has no report yet). A stage that cannot apply is `na` + * with its reason: a project no article claims has no Article stage, nor a + * Research stage unless a board made it; an article with neither iterations + * nor a board (a site's hand-written report) has no Research recorded here. A + * piece marked done has done every stage that applies. + * + * @param {{ kind: string, reached: { research?: boolean, article?: boolean, video?: boolean, deliver?: boolean }, lifecycle: string }} p + * @returns {{ id: string, label: string, state: "done" | "current" | "todo" | "na", title?: string }[]} */ -export function stepsOf(bucket, lifecycle, na = {}) { - const at = STAGE_STEPS.findIndex((s) => s.id === bucket); - return STAGE_STEPS.map((s, i) => - na[s.id] - ? { label: s.label, state: "na", title: na[s.id] } - : { label: s.label, state: lifecycle === "done" || i < at ? "done" : i === at ? "current" : "todo" }, - ); +export function pieceSteps({ kind, reached, lifecycle }) { + const project = kind !== "article"; + const has = { ...reached, ...(project ? { video: true, article: false } : {}) }; + const na = project + ? { ...(has.research ? {} : { research: "no research board" }), article: "no article" } + : has.research + ? {} + : { research: "no iterations or research board" }; + const SKIPPED = { research: "no iterations yet", article: "no report yet", video: "no video project yet" }; + let at = -1; + STAGE_STEPS.forEach((s, i) => { + if (!na[s.id] && has[s.id]) at = i; + }); + if (at < 0) at = STAGE_STEPS.findIndex((s) => !na[s.id]); + return STAGE_STEPS.map((s, i) => { + if (na[s.id]) return { id: s.id, label: s.label, state: "na", title: na[s.id] }; + if (lifecycle === "done") return { id: s.id, label: s.label, state: "done" }; + if (i === at) return { id: s.id, label: s.label, state: "current" }; + if (i < at && has[s.id]) return { id: s.id, label: s.label, state: "done" }; + if (i < at) return { id: s.id, label: s.label, state: "todo", title: SKIPPED[s.id] }; + return { id: s.id, label: s.label, state: "todo" }; + }); } /** - * A piece's stepper. An ARTICLE walks all four stages from its own stage (one - * in the making is at Research, P2a's rule). A PROJECT no article claims has - * no Article stage, and no Research stage either -- unless it was scaffolded - * from a research board (R2's "Start a video from this board"), whose board - * was its research. + * A piece's stage: the step that is current, by the one rule (lifecycle aside -- + * a parked or done piece keeps the stage it is at). * - * @param {{ kind: string, bucket: string, lifecycle: string, fromBoard?: boolean }} p + * @param {{ kind: string, reached: { research?: boolean, article?: boolean, video?: boolean, deliver?: boolean } }} p */ -export function pieceSteps({ kind, bucket, lifecycle, fromBoard = false }) { - if (kind === "article") return stepsOf(bucket, lifecycle); - return stepsOf(bucket, lifecycle, { - ...(fromBoard ? {} : { research: "no research board" }), - article: "no article", - }); +export function stageOfPiece({ kind, reached }) { + return pieceSteps({ kind, reached, lifecycle: "active" }).find((s) => s.state === "current")?.id ?? "video"; } /** The tabs of a report-video piece, in order; the key that opens each is its position. */ @@ -217,41 +240,3 @@ export function articleTabOf(search, { noteTab = null } = {}) { if (search?.all === "1") return "cut"; return "overview"; } - -/** - * An article piece's stepper, each stage by what is on disk rather than one - * bucket walked (P4a-2): - * - * Research done when iterations exist or a research board seeded it; `na` - * (with `researchNa` as the reason) when the article has neither - * -- a site's hand-written report has no research recorded here - * Article done when a report is current (report.json reads) - * Video done when it claims a video project - * Deliver done when it looks done (a final video and a share batch, or - * published with its video) - * - * The first stage not done is current; the rest not done are to do. A piece - * marked done has done every stage that applies. - * - * @param {{ research: boolean, article: boolean, video: boolean, deliver: boolean, lifecycle: string, researchNa?: string | null }} p - * @returns {{ label: string, state: "done" | "current" | "todo" | "na", title?: string }[]} - */ -export function articleSteps({ research, article, video, deliver, lifecycle, researchNa = null }) { - const done = { research, article, video, deliver }; - let current = false; - return STAGE_STEPS.map((s) => { - if (s.id === "research" && !research && researchNa) return { label: s.label, state: "na", title: researchNa }; - if (lifecycle === "done" || done[s.id]) return { label: s.label, state: "done" }; - if (!current) { - current = true; - return { label: s.label, state: "current" }; - } - return { label: s.label, state: "todo" }; - }); -} - -/** The stage id an article piece's stepper has lit (its current step), else `deliver` when every stage is done. */ -export function articleStageOf(steps) { - const i = steps.findIndex((s) => s.state === "current"); - return i >= 0 ? STAGE_STEPS[i].id : "deliver"; -} diff --git a/umtool/lib/pieces/tabs.test.mjs b/umtool/lib/pieces/tabs.test.mjs @@ -1,7 +1,7 @@ // A piece page's tabs: the address decides the tab, every section has one. import assert from "node:assert/strict"; import test from "node:test"; -import { STAGES } from "../work/facets.mjs"; +import { STAGES, stageOf } from "../work/facets.mjs"; import { ARTICLE_PIECE_TAB_IDS, PIECE_TABS, @@ -9,12 +9,10 @@ import { SECTION_TAB, STAGE_STEPS, VIDEO_TAB_IDS, - articleStageOf, - articleSteps, articleTabOf, articleTabOfSection, pieceSteps, - stepsOf, + stageOfPiece, tabOf, tabOfKey, tabOfNoteAnchor, @@ -54,29 +52,51 @@ test("every section is on a real tab; an unknown one throws", () => { assert.throws(() => tabOfSection("nope"), /no section "nope"/); }); -test("the stepper: before the bucket done, it current, after it to do; a done piece walked them all", () => { +test("the one stage rule: the furthest stage reached is current; skipped ones say why; a done piece walked them all", () => { assert.deepEqual(STAGE_STEPS.map((s) => s.id), STAGES); - assert.deepEqual(stepsOf("video", "active").map((s) => s.state), ["done", "done", "current", "todo"]); - assert.deepEqual(stepsOf("research", "parked").map((s) => s.state), ["current", "todo", "todo", "todo"]); - assert.deepEqual(stepsOf("deliver", "active").map((s) => s.state), ["done", "done", "done", "current"]); - assert.deepEqual(stepsOf("video", "done").map((s) => s.state), ["done", "done", "done", "done"]); - assert.deepEqual(stepsOf("video", "active").map((s) => s.label), ["Research", "Article", "Video", "Deliver"]); + const states = (steps) => steps.map((s) => s.state); + const all = { research: true, article: true, video: true, deliver: false }; + assert.deepEqual(pieceSteps({ kind: "article", reached: all, lifecycle: "active" }).map((s) => s.label), ["Research", "Article", "Video", "Deliver"]); + // A report, no video: at Article (the next thing is a video). + assert.deepEqual(states(pieceSteps({ kind: "article", reached: { ...all, video: false }, lifecycle: "parked" })), ["done", "current", "todo", "todo"]); + // Iterations running, nothing else: at Research. + assert.deepEqual(states(pieceSteps({ kind: "article", reached: { research: true }, lifecycle: "active" })), ["current", "todo", "todo", "todo"]); + // A site's hand-written report: no research recorded here. + const site = pieceSteps({ kind: "article", reached: { article: true }, lifecycle: "active" }); + assert.deepEqual(states(site), ["na", "current", "todo", "todo"]); + assert.equal(site[0].title, "no iterations or research board"); + // Marked done: every stage that applies is done; `na` stays. + assert.deepEqual(states(pieceSteps({ kind: "article", reached: { article: true }, lifecycle: "done" })), ["na", "done", "done", "done"]); + assert.deepEqual(states(pieceSteps({ kind: "project", reached: { deliver: true }, lifecycle: "done" })), ["na", "na", "done", "done"]); }); -test("a piece's stepper: an article walks all four; a standalone video has no Research or Article; a board's video has its Research", () => { +test("the stepper and Work's stage facet give the same answer: a standalone video, a board's video, an article in the making with a video, a published article with its video", () => { const states = (steps) => steps.map((s) => s.state); - // An article in the making with a video project already: at Research (P2a's rule). - assert.deepEqual(states(pieceSteps({ kind: "article", bucket: "research", lifecycle: "active" })), ["current", "todo", "todo", "todo"]); - // A report video no article claims: Research and Article do not apply, and say why. - const alone = pieceSteps({ kind: "project", bucket: "video", lifecycle: "active" }); + const both = (piece) => { + const steps = pieceSteps({ ...piece, lifecycle: "active" }); + const current = steps.find((s) => s.state === "current")?.id; + // Work's facet (lib/work/facets.mjs stageOf over the graph's row) and the stepper's current step. + assert.equal(stageOf({ kind: piece.kind, stage: "x", looksDone: [], reached: piece.reached }), current); + assert.equal(stageOfPiece(piece), current); + return steps; + }; + // A report video no article claims, not delivered: at Video; Research and Article do not apply. + const alone = both({ kind: "project", reached: { research: false, article: false, video: true, deliver: false } }); assert.deepEqual(states(alone), ["na", "na", "current", "todo"]); assert.deepEqual(alone.slice(0, 2).map((s) => s.title), ["no research board", "no article"]); - // Scaffolded from a research board: Research done, Article still not applicable. - const board = pieceSteps({ kind: "project", bucket: "video", lifecycle: "active", fromBoard: true }); + assert.equal(stageOfPiece({ kind: "project", reached: { video: true, deliver: true } }), "deliver"); + // Scaffolded from a research board: Research done, Article not applicable, at Video. + const board = both({ kind: "project", reached: { research: true, article: false, video: true, deliver: false } }); assert.deepEqual(states(board), ["done", "na", "current", "todo"]); assert.equal(board[1].title, "no article"); - // Marked done: every stage it has is done; the ones it never had stay not applicable. - assert.deepEqual(states(pieceSteps({ kind: "project", bucket: "deliver", lifecycle: "done" })), ["na", "na", "done", "done"]); + // An article in the making whose iterations made a video: at Video, the report still to do (and why). + const making = both({ kind: "article", reached: { research: true, article: false, video: true, deliver: false } }); + assert.deepEqual(states(making), ["done", "todo", "current", "todo"]); + assert.equal(making[1].title, "no report yet"); + assert.equal(stageOfPiece({ kind: "article", reached: { research: true, article: false, video: true } }), "video"); + // A published article with its video (looks done): at Deliver. + const published = both({ kind: "article", reached: { research: true, article: true, video: true, deliver: true } }); + assert.deepEqual(states(published), ["done", "done", "done", "current"]); }); test("an article piece: nine tabs, the video's seven around the article's two", () => { @@ -104,27 +124,3 @@ test("an article piece's address picks the tab: the reader's keys open the Artic assert.equal(articleTabOf({ status: "resolved" }), "article"); assert.equal(articleTabOf({ all: "1" }), "cut"); }); - -test("an article piece's stepper: each stage by what exists, the first missing one current", () => { - const st = (s) => s.map((x) => x.state); - // Iterations, a report, a video: at Deliver. - let s = articleSteps({ research: true, article: true, video: true, deliver: false, lifecycle: "active" }); - assert.deepEqual(st(s), ["done", "done", "done", "current"]); - assert.equal(articleStageOf(s), "deliver"); - // In the making: research done, the article current. - s = articleSteps({ research: true, article: false, video: false, deliver: false, lifecycle: "active" }); - assert.deepEqual(st(s), ["done", "current", "todo", "todo"]); - assert.equal(articleStageOf(s), "article"); - // A site's hand-written report: no research recorded, at Video. - s = articleSteps({ research: false, article: true, video: false, deliver: false, lifecycle: "active", researchNa: "no iterations or board" }); - assert.deepEqual(st(s), ["na", "done", "current", "todo"]); - assert.equal(s[0].title, "no iterations or board"); - assert.equal(articleStageOf(s), "video"); - // Published with its video: every stage done. - s = articleSteps({ research: true, article: true, video: true, deliver: true, lifecycle: "active" }); - assert.deepEqual(st(s), ["done", "done", "done", "done"]); - assert.equal(articleStageOf(s), "deliver"); - // Marked done: every stage that applies is done; `na` stays. - s = articleSteps({ research: false, article: true, video: false, deliver: false, lifecycle: "done", researchNa: "none" }); - assert.deepEqual(st(s), ["na", "done", "done", "done"]); -}); diff --git a/umtool/lib/work.ts b/umtool/lib/work.ts @@ -89,12 +89,12 @@ export async function readWork(): Promise<{ rows: WorkRow[]; lifecycleError?: st : "article" : (projectKinds.map((k) => label.get(k) ?? k).join(", ") || "project"); const projectState = own?.state ?? null; - const bucket = stageOf({ kind: p.kind, stage: p.stage, looksDone: p.looksDone, projectState }); + const bucket = stageOf({ kind: p.kind, stage: p.stage, looksDone: p.looksDone, projectState, reached: p.reached }); return { ...p, bucket, step: stepOf(bucket), - stageLabel: p.kind === "article" ? p.stage : (projectState ?? p.stage), + stageLabel: p.kind === "article" ? bucket : (projectState ?? p.stage), kinds, kindLabel, templates: [...new Set(mine.map((x) => x.template))], diff --git a/umtool/lib/work/facets.mjs b/umtool/lib/work/facets.mjs @@ -16,18 +16,25 @@ // of every project linked to it, a project piece is its project's kind. So the // old `/browse?kind=<a video kind>` still finds the article whose video it is. +import { stageOfPiece } from "../pieces/tabs.mjs"; + /** The four stages a piece walks, in order (canvas "Work", the stage bar). */ export const STAGES = ["research", "article", "video", "deliver"]; export const LIFECYCLES = ["active", "parked", "done"]; /** - * A piece's stage bucket: an article's own stage; a project's `deliver` when - * it looks done (or ships), else `video` -- its own state word is its label. + * A piece's stage bucket: the step its stepper has current, by THE ONE STAGE + * RULE (lib/pieces/tabs.mjs pieceSteps over the graph's `reached`), so Work's + * stage facet and the piece page's stepper always agree (P4a-2 follow-up). + * A row with no `reached` (an older caller) keeps the old reading: an + * article's own stage; a project's `deliver` when it looks done (or ships), + * else `video`. * - * @param {{ kind: string, stage: string, looksDone: string[], projectState?: string | null }} p + * @param {{ kind: string, stage: string, looksDone: string[], projectState?: string | null, reached?: { research: boolean, article: boolean, video: boolean, deliver: boolean } }} p */ export function stageOf(p) { + if (p.reached) return stageOfPiece({ kind: p.kind, reached: p.reached }); if (p.kind === "article") return STAGES.includes(p.stage) ? p.stage : "article"; if (p.looksDone.length || p.projectState === "shipped") return "deliver"; return "video"; diff --git a/umtool/lib/work/facets.test.mjs b/umtool/lib/work/facets.test.mjs @@ -27,6 +27,9 @@ test("a stage is an article's own, and a project's deliver or video", () => { assert.equal(stageOf({ kind: "project", stage: "built", looksDone: ["final video and share-1"] }), "deliver"); assert.equal(stageOf({ kind: "project", stage: "shipped", looksDone: [], projectState: "shipped" }), "deliver"); assert.deepEqual(["research", "article", "video", "deliver"].map(stepOf), [1, 2, 3, 4]); + // With the graph's facts, the one stage rule (lib/pieces/tabs.mjs pieceSteps) decides. + assert.equal(stageOf({ kind: "article", stage: "research", looksDone: [], reached: { research: true, article: false, video: true, deliver: false } }), "video"); + assert.equal(stageOf({ kind: "project", stage: "built", looksDone: [], reached: { research: false, article: false, video: true, deliver: true } }), "deliver"); }); test("lifecycle defaults to active; all shows every piece", () => {