From 4ac03f4dbb5bcf4b27684451b00556251723ad84 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 08:47:31 -0600 Subject: [PATCH] feat(pm-stack): Reports: a day, a week or thirty days in words, made when asked for MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More → Reports says what merged and against what, the features by project, issues and the backlog, bugs and the queue, in sentences, for any stretch of the history Cloudflare keeps. Earlier and Later step it by its own length; Copy and Share give it as text. The trends read takes a day to end on and a single day as a window. No machine. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF --- ...rchitecture_pm_platform_cloudflare_core.md | 36 ++++ planning/roadmaps/pm-stack.md | 1 + pm-stack/console/README.md | 18 ++ pm-stack/console/public/app.js | 15 +- pm-stack/console/public/files.json | 5 + pm-stack/console/public/pages/index.js | 3 +- pm-stack/console/public/pages/reports.js | 204 ++++++++++++++++++ pm-stack/console/src/reads.ts | 2 +- pm-stack/console/src/trends.ts | 19 +- pm-stack/console/test/console.test.ts | 6 + pm-stack/console/test/pages.test.ts | 167 ++++++++++++++ pm-stack/console/test/sw.test.ts | 2 + pm-stack/console/test/trends.test.ts | 17 ++ 13 files changed, 489 insertions(+), 6 deletions(-) create mode 100644 pm-stack/console/public/pages/reports.js diff --git a/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md b/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md index 6e3bba949..892aa4033 100644 --- a/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md +++ b/doc/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core/2026-11-23T06-50-00Z_architecture_pm_platform_cloudflare_core.md @@ -1951,3 +1951,39 @@ without asking again. In Chromium on the laptop, on the real repository's numbers, in a dark theme and a light one: the charts draw, the series take the theme's colours, and arrowing to a day reads it out. + +## 2026-11-24T14:46:00Z Feature: reports, made when asked for + +**Asked for.** "To request reports which generate and are accessible +through the app." + +**What was built.** More → Reports: a day, a week or thirty days in +sentences. What merged and how that stands against the time before, the +features by project with the latest three of each to open, issues +opened and closed and what that did to the backlog, bugs, the queue's +finished tasks, and, in a report that ends today, the queue as it +stands. Earlier and Later step a report back and forth by its own +length as far as the history goes. Copy and Share give it as text. + +**Decisions.** + +- _Made from the history, not written and stored._ The history behind + Trends is kept by day, so a report for any stretch of it can be made + at any time; the read was given a day to end on, and a single day as + a window. That leaves nothing to store, nothing to go stale, and no + machine in it. The second page written as a module of its own, it is + one file, a line in the list of pages and a line in the list of + files. +- _It says what it cannot vouch for._ A total is set against the days + before only when those are whole; a report over days not yet read + says from which day on its numbers are whole; one that ends today + says the day is not over. +- _What it does not cover goes to Ask._ A question there is answered by + an agent, with what the answer rests on. A kind of ask that is "a + report" with its own listing on this screen is not built: it needs + the queue task filed, which is still a machine's (#13490). + +**Checked.** 639 tests; every sentence of a report is worked out by +hand from a small history written out in the test. Fourteen faults +planted, the one survivor closed (every feature listed instead of the +latest three). diff --git a/planning/roadmaps/pm-stack.md b/planning/roadmaps/pm-stack.md index 67037ef59..fd39c537c 100644 --- a/planning/roadmaps/pm-stack.md +++ b/planning/roadmaps/pm-stack.md @@ -30,6 +30,7 @@ The roadmap of record is this file and its siblings in `planning/roadmaps/`. The | A machine's console runs main, from GitHub | shipped | The console on a machine runs from its own copy of main, fetched from GitHub and laid out a release per commit, not from a checkout the fleet works in; a release that does not come up is taken out again. | #13833 | | The app looks the way its owner wants | shipped | #13504 | | Trends: what got done, by day | shipped | More → Trends: pull requests merged by kind, features by project with the features themselves, issues and bugs opened against closed, time to merge, tasks finished; over 7 to 90 days, set against the days before. Read and kept by Cloudflare from GitHub and the queue, no machine. A chart kit and pages as modules for the screens that follow. | #13504 | +| Reports, made when asked for | shipped | More → Reports: a day, a week or thirty days in words (merged, features by project, issues and the backlog, the queue), set against the time before, for any stretch of the last ninety days; copied or shared as text. Made from the history Cloudflare keeps; no machine. | #13504 | ## Next diff --git a/pm-stack/console/README.md b/pm-stack/console/README.md index 5cba6076e..97f93ee0b 100644 --- a/pm-stack/console/README.md +++ b/pm-stack/console/README.md @@ -307,6 +307,24 @@ asks GitHub and the queue's store itself (`src/trends.ts`). Days are UTC days, and today's column is drawn fainter: it is not over. +### Reports + +**More → Reports** is the same history in words: a day, a week or thirty +days, with what merged and how that stands against the time before, +the features by project (the latest three of each to open), issues +opened and closed and what that did to the backlog, bugs, and the +queue's finished tasks (and, in a report that ends today, the queue as +it stands). **Earlier** and **Later** step it back and forth by its own +length, as far back as the history goes, so the report for a week gone +by can be made at any time. **Copy** and **Share** give it as text. + +A report is made when it is asked for, on the device, from the Trends +read (`public/pages/reports.js`; the read takes a day to end on). It +needs no machine, and the service worker keeps each one asked for, so +it opens again with no connection. A report says when its numbers are +not whole yet. For anything these do not cover, a question on Ask is +answered by an agent and stays there to read. + ### Charts, and pages of their own `public/charts.js` is a small kit any screen can use: columns stacked by diff --git a/pm-stack/console/public/app.js b/pm-stack/console/public/app.js index 406638fb2..15c7db106 100644 --- a/pm-stack/console/public/app.js +++ b/pm-stack/console/public/app.js @@ -3701,7 +3701,20 @@ const VIEWS = { /** What a page that is a module of its own (public/pages) is handed: * the app's own parts, so that it reads, acts and moves about the same * way as every screen written here. */ -const app = { api, freshly, act, go, toast, empty, ago, sheet, newId, redraw: () => draw() }; +const app = { + api, + freshly, + act, + go, + toast, + empty, + ago, + sheet, + newId, + redraw: () => draw(), + /** The queue as it stands now, by state (or null before it has been read). */ + counts: () => docs.core?.board?.counts ?? null, +}; for (const page of PAGES) VIEWS[page.route] = [page.title, (sub) => page.view(sub, app), page.doc]; /** Every screen's address, for the tests. */ export const routesKnown = () => Object.keys(VIEWS); diff --git a/pm-stack/console/public/files.json b/pm-stack/console/public/files.json index 08b159efe..e99200177 100644 --- a/pm-stack/console/public/files.json +++ b/pm-stack/console/public/files.json @@ -37,6 +37,11 @@ "type": "text/javascript; charset=utf-8", "kept": "installed" }, + { + "path": "pages/reports.js", + "type": "text/javascript; charset=utf-8", + "kept": "installed" + }, { "path": "app.css", "type": "text/css; charset=utf-8", diff --git a/pm-stack/console/public/pages/index.js b/pm-stack/console/public/pages/index.js index 05ba781a8..a334a5031 100644 --- a/pm-stack/console/public/pages/index.js +++ b/pm-stack/console/public/pages/index.js @@ -23,6 +23,7 @@ // To add a page: write its file, add it to PAGES here, and name the // file in ../files.json. The tests check all three agree, and the app // gives it its route, its tile and its copy for offline. +import reports from "./reports.js"; import trends from "./trends.js"; -export const PAGES = [trends]; +export const PAGES = [trends, reports]; diff --git a/pm-stack/console/public/pages/reports.js b/pm-stack/console/public/pages/reports.js new file mode 100644 index 000000000..4abc19483 --- /dev/null +++ b/pm-stack/console/public/pages/reports.js @@ -0,0 +1,204 @@ +// Reports: what got done in a day, a week or thirty days, in words. A +// report is made when it is asked for, from the same history the Trends +// screen draws (so it needs no machine, and one for a week gone by can +// be made at any time), and can be copied or shared as text. +import { compact, dayLong, dayShort, deltaSaid, minutesSaid, windowTotals } from "../charts.js"; +import { h } from "../ui.js"; +import { wholeFrom } from "./trends.js"; + +const SPANS = [ + [1, "A day"], + [7, "A week"], + [30, "30 days"], +]; +/** What was last chosen, while the app is open: how long, and the day it ends on (null is today). */ +let chosen = 7; +let ending = null; + +const plural = (n, one, many = `${one}s`) => `${compact(n)} ${n === 1 ? one : many}`; +/** "a, b and c". */ +const listed = (items) => (items.length <= 1 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`); +const middle = (values) => { + const sorted = values.filter((v) => v !== null && v !== undefined).sort((a, b) => a - b); + if (sorted.length === 0) return null; + const mid = Math.floor(sorted.length / 2); + return sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2; +}; + +/** The day `days` before or after a date. */ +export function dayFrom(date, days) { + return new Date(Date.parse(`${date}T00:00:00Z`) + days * 86_400_000).toISOString().slice(0, 10); +} + +/** A trends document as a report: a title, what it covers, a headline, + * and sections of sentences (some with the things themselves to open). + * `counts` is the queue as it stands now, said only in a report that + * ends today. `text` is the whole of it as plain text. + * @param {any} doc + * @param {{ claimed?: number, queued?: number, blocked?: number } | null} [counts] */ +export function reportOf(doc, counts = null) { + const n = Math.min(doc.window, doc.days.length); + const first = doc.days.length - n; + const cut = (values) => values.slice(first); + const days = cut(doc.days); + const end = days[days.length - 1]; + const today = end === doc.today; + const before = n === 1 ? "the day before" : `the ${n} days before`; + // A total is set against the days before only when those are whole. + const firstWhole = doc.history.whole ? doc.history.from : doc.history.covered ? wholeFrom(doc.history.covered) : null; + const whole = firstWhole !== null && firstWhole <= days[0]; + const beforeWhole = whole && doc.days.length >= n * 2 && firstWhole <= doc.days[doc.days.length - n * 2]; + const against = (values) => { + const totals = windowTotals(values, n); + const delta = beforeWhole ? deltaSaid(totals.now, totals.before) : { text: "" }; + return { n: totals.now, said: delta.text ? ` (${delta.text} on ${before})` : "" }; + }; + const sum = (values) => cut(values).reduce((total, v) => total + (v ?? 0), 0); + + const title = n === 1 ? (today ? "Today so far" : dayLong(end)) : `${n} days to ${dayLong(end)}`; + const period = n === 1 ? dayLong(end) : `${dayLong(days[0])} to ${dayLong(end)}`; + const merged = against(doc.merged.all); + const kinds = [ + ["feat", "feature"], + ["fix", "fix", "fixes"], + ["docs", "of docs", "of docs"], + ["test", "of tests", "of tests"], + ["other", "other"], + ] + .map(([id, one, many]) => [sum(doc.merged.kinds[id] ?? []), one, many]) + .filter(([count]) => count > 0) + .map(([count, one, many]) => plural(count, one, many)); + const featuresAll = doc.days.map((_, i) => doc.projects.reduce((total, p) => total + (doc.features.projects[p.id]?.[i] ?? 0), 0)); + const features = against(featuresAll); + const headline = `${plural(merged.n, "pull request")} merged${merged.said}, ${compact(features.n)} of them features.`; + + const sections = []; + const mergedLines = [`${plural(merged.n, "pull request")} merged${merged.said}.`]; + if (kinds.length > 0) mergedLines.push(`That is ${listed(kinds)}.`); + const typical = middle(cut(doc.merged.minutes)); + if (typical !== null) mergedLines.push(`The middle one waited ${minutesSaid(typical)} from opened to merged.`); + if (n > 1 && merged.n > 0) { + const perDay = cut(doc.merged.all); + const most = Math.max(...perDay); + mergedLines.push(`The busiest day was ${dayLong(days[perDay.indexOf(most)])}, with ${compact(most)}.`); + } + sections.push({ title: "Merged", lines: mergedLines, links: [] }); + + const projects = doc.projects + .map((p) => ({ title: p.title, count: sum(doc.features.projects[p.id] ?? []), latest: doc.features.latest[p.id] ?? [] })) + .filter((p) => p.count > 0) + .sort((a, b) => b.count - a.count || (a.title < b.title ? -1 : 1)); + if (projects.length > 0) { + sections.push({ + title: "Features, by project", + lines: [`${plural(features.n, "feature")} merged${features.said}: ${listed(projects.map((p) => `${compact(p.count)} in ${p.title}`))}.`], + // The latest three of each, to open. + links: projects.flatMap((p) => p.latest.slice(0, 3).map((f) => ({ text: f.title, meta: `${p.title} · #${f.number}`, url: f.url }))), + }); + } + + const opened = sum(doc.issues.opened); + const closed = against(doc.issues.closed); + const net = closed.n > opened ? `the backlog went down by ${compact(closed.n - opened)}` : opened > closed.n ? `the backlog grew by ${compact(opened - closed.n)}` : "the backlog stayed level"; + sections.push({ + title: "Issues", + lines: [ + `${plural(opened, "issue")} opened and ${compact(closed.n)} closed${closed.said}: ${net}.`, + `${plural(sum(doc.bugs.opened), "bug")} reported and ${compact(sum(doc.bugs.closed))} fixed.`, + `${plural(sum(doc.prs.opened), "pull request")} opened; ${compact(sum(doc.prs.closed))} closed without merging.`, + ], + links: [], + }); + + if (!("error" in doc.tasks)) { + const finished = against(doc.tasks.all); + const byKind = doc.tasks.kinds + .map((k) => [k.kind, sum(k.days)]) + .filter(([, count]) => count > 0) + .sort((a, b) => (a[0] === "other" ? 1 : b[0] === "other" ? -1 : b[1] - a[1])) + .map(([kind, count]) => `${compact(count)} ${kind === "other" ? "of other kinds" : kind}`); + const lines = [`${plural(finished.n, "task")} finished${finished.said}${byKind.length > 0 ? `: ${listed(byKind)}` : ""}.`]; + if (today && counts) lines.push(`Right now ${compact(counts.claimed ?? 0)} are in progress, ${compact(counts.queued ?? 0)} queued and ${compact(counts.blocked ?? 0)} blocked.`); + sections.push({ title: "The queue", lines, links: [] }); + } + + const notes = []; + if (!whole) { + notes.push( + firstWhole === null + ? "GitHub's history is still being read for the first time: these numbers are what has been read so far." + : `GitHub's history is whole from ${dayLong(firstWhole)} on: days before that in this report are undercounted. It is still being read.`, + ); + } + if (today) notes.push(n === 1 ? "The day is not over." : "Today is not over."); + if (doc.partial && doc.why) notes.push(doc.why); + + const text = [ + `${title} (${period}, UTC)`, + "", + ...sections.flatMap((s) => [s.title, ...s.lines, ...s.links.map((l) => `- ${l.text} (${l.meta}) ${l.url}`), ""]), + ...notes, + ] + .join("\n") + .trim(); + return { title, period, end, today, whole, headline, sections, notes, text }; +} + +async function view(sub, app) { + const [span, end] = (sub || "").split("/"); + if (SPANS.some(([d]) => String(d) === span)) { + chosen = Number(span); + ending = /^\d{4}-\d{2}-\d{2}$/.test(end || "") ? end : null; + } + const doc = await app.api(app.freshly(`trends?days=${chosen}${ending ? `&end=${ending}` : ""}`)); + const report = reportOf(doc, app.counts()); + const to = (days, last) => `more/reports/${days}${last && last < doc.today ? `/${last}` : ""}`; + const copy = async () => { + try { + await navigator.clipboard.writeText(report.text); + app.toast("Copied."); + } catch { + app.toast("This device would not let it be copied.", true); + } + }; + const share = navigator.share ? () => navigator.share({ title: report.title, text: report.text }).catch(() => {}) : null; + const earliest = doc.history.from; + return [ + h( + "div", + { class: "seg", role: "group", "aria-label": "How long a report" }, + SPANS.map(([d, label]) => h("button", { "aria-pressed": String(d === chosen), onclick: () => app.go(to(d, ending)) }, label)), + ), + h( + "div", + { class: "row" }, + h("button", { class: "ghost small", disabled: dayFrom(report.end, -chosen) < earliest, onclick: () => app.go(to(chosen, dayFrom(report.end, -chosen))) }, "‹ Earlier"), + h("button", { class: "ghost small", disabled: report.today, onclick: () => app.go(to(chosen, dayFrom(report.end, chosen))) }, "Later ›"), + h("span", { class: "grow" }), + h("button", { class: "ghost small", onclick: copy }, "Copy"), + share ? h("button", { class: "small", onclick: share }, "Share") : null, + ), + h("div", { class: "card hot" }, h("h3", {}, report.title), h("p", { class: "meta" }, `${report.period} · UTC`), h("p", {}, report.headline)), + ...report.notes.map((text) => h("div", { class: "card flag" }, h("p", { class: "meta" }, text))), + ...report.sections.map((s) => + h( + "div", + { class: "card" }, + h("h3", {}, s.title), + s.lines.map((line) => h("p", {}, line)), + s.links.map((l) => h("a", { class: "link", href: l.url, target: "_blank", rel: "noopener" }, l.text, h("span", {}, l.meta))), + ), + ), + h("h2", {}, "Something these do not cover"), + h("p", { class: "meta" }, "Ask for it in your own words: a question on Ask is answered by an agent, with what the answer rests on, and the answer stays there to read."), + h("div", { class: "row" }, h("button", { class: "ghost", onclick: () => app.go("ask") }, "Ask a question"), h("button", { class: "ghost", onclick: () => app.go(`more/trends/${chosen === 1 ? 7 : chosen}`) }, "See it as charts")), + ]; +} + +export default { + route: "more/reports", + title: "Reports", + group: "Plan", + says: "a day, a week or thirty days in words, to read, copy or share", + view, +}; diff --git a/pm-stack/console/src/reads.ts b/pm-stack/console/src/reads.ts index c19b043be..5a382f438 100644 --- a/pm-stack/console/src/reads.ts +++ b/pm-stack/console/src/reads.ts @@ -45,7 +45,7 @@ export async function platformRead( case "intake": return plan.intakeList(fresh); case "trends": - return trends ? trends.read(query.get("days"), fresh) : undefined; + return trends ? trends.read(query.get("days"), fresh, query.get("end")) : undefined; } } if (seg.length === 2 && seg[0] === "prs") return ops.pr(seg[1]); diff --git a/pm-stack/console/src/trends.ts b/pm-stack/console/src/trends.ts index f65cc8d3e..ca44ca6ea 100644 --- a/pm-stack/console/src/trends.ts +++ b/pm-stack/console/src/trends.ts @@ -260,6 +260,8 @@ export interface TrendsDoc { window: number; days: string[]; today: string; + /** The last day of `days`: today, unless an earlier one was asked for. */ + end: string; /** `covered`: everything changed since then has been read, so the * days from then on are whole (null until the newest stretch has * been read to its end). */ @@ -479,8 +481,9 @@ export class Trends { /** The document the Trends screen draws: `window` days, set against * the same number before them. */ - async read(asked: string | null, fresh = false): Promise { - const window = (WINDOWS as readonly number[]).includes(Number(asked)) ? Number(asked) : 30; + async read(asked: string | null, fresh = false, ending: string | null = null): Promise { + // The windows the screen offers, and a single day (a report of one). + const window = [1, ...WINDOWS].includes(Number(asked)) ? Number(asked) : 30; let why: string | undefined; // The screen waits for GitHub only when the wait is short or there // is nothing to show without it: the very first reading (until the @@ -500,7 +503,16 @@ export class Trends { } const meta = await this.meta(); const today = this.clock().toISOString().slice(0, 10); - const days = daysBack(today, Math.min(window * 2, HISTORY_DAYS)).filter((d) => d >= meta.from); + // The window ends today, or on an earlier day asked for (a report + // of a week gone by); a day that is not one, or not yet, is today. + const end = + ending !== null && + /^\d{4}-\d{2}-\d{2}$/.test(ending) && + ending <= today && + !Number.isNaN(Date.parse(`${ending}T00:00:00Z`)) + ? ending + : today; + const days = daysBack(end, Math.min(window * 2, HISTORY_DAYS)).filter((d) => d >= meta.from); const kept = await Promise.all(days.map((d) => this.day(d))); const zeros = () => days.map(() => 0); const kinds = Object.fromEntries(KINDS.map((k) => [k, zeros()])) as Record; @@ -571,6 +583,7 @@ export class Trends { window, days, today, + end, history: { from: meta.from, whole: meta.whole, diff --git a/pm-stack/console/test/console.test.ts b/pm-stack/console/test/console.test.ts index 174a09f46..041b0e549 100644 --- a/pm-stack/console/test/console.test.ts +++ b/pm-stack/console/test/console.test.ts @@ -1227,6 +1227,12 @@ describe("HTTP surface", () => { expect(last.bugs.opened[at("2026-11-21")]).toBe(1); expect(last.features.latest.fleet.map((f) => f.number)).toEqual([41]); } + // A window that ends on an earlier day, as a report of a week gone by asks for. + const earlier = (await (await handle(get("/console/api/trends?days=7&end=2026-11-21"), d)).json()) as { + end: string; + days: string[]; + }; + expect([earlier.end, earlier.days[earlier.days.length - 1]]).toEqual(["2026-11-21", "2026-11-21"]); // Whole, and asked again at once: GitHub is not asked. expect((await handle(get("/console/api/trends?days=7"), d)).status).toBe(200); expect(asked()).toBe(9); diff --git a/pm-stack/console/test/pages.test.ts b/pm-stack/console/test/pages.test.ts index 3291226ce..a78f9dcc7 100644 --- a/pm-stack/console/test/pages.test.ts +++ b/pm-stack/console/test/pages.test.ts @@ -12,6 +12,7 @@ import { join } from "node:path"; import "../public/look.js"; import { routesKnown } from "../public/app.js"; import { PAGES } from "../public/pages/index.js"; +import reports, { dayFrom, reportOf } from "../public/pages/reports.js"; import trends, { notes, shape, wholeFrom } from "../public/pages/trends.js"; const PUBLIC = join(import.meta.dir, "../public"); @@ -74,6 +75,7 @@ function doc(window: number, count: number) { window, days, today: "2026-11-24", + end: "2026-11-24", history: { from: "2026-08-26", whole: true, @@ -276,3 +278,168 @@ test("the queue out of reach leaves the tasks out, and what cannot be seen yet i expect(wholeFrom("2026-08-26T00:00:00Z")).toBe("2026-08-26"); expect(wholeFrom("2026-10-31T23:59:59Z")).toBe("2026-11-01"); }); + +test("a week as a report: what merged and against what, the features by project, issues, and the queue, in sentences", () => { + const d = doc(7, 14); + d.merged.all = [10, 10, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 5]; + d.merged.kinds.feat = [4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 2]; + d.merged.kinds.fix = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 3]; + d.features.projects.id = [3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1]; + d.features.projects["pm-stack"] = [1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 1]; + d.features.latest["pm-stack"] = [ + { + number: 14379, + title: "the app's look", + at: "2026-11-24T13:36:00Z", + url: "https://github.com/developing-today/code/pull/14379", + }, + ]; + d.issues.closed = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]; + d.issues.opened = [0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0]; + d.merged.minutes = [null, null, null, null, null, null, null, 30, 60, null, 90, 120, 600, 20]; + d.tasks = { + all: [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2], + kinds: [ + { kind: "small fix", days: [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1] }, + { kind: "feature slice", days: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] }, + ], + since: "2026-11-11", + }; + const r = reportOf(d, { claimed: 118, queued: 99, blocked: 283 }); + expect([r.title, r.period, r.today, r.whole]).toEqual([ + "7 days to Tue 24 Nov", + "Wed 18 Nov to Tue 24 Nov", + true, + true, + ]); + // 77 against 70; 38 features (13 in id, 25 in the PM stack) against 28. + expect(r.headline).toBe("77 pull requests merged (▲ 10% on the 7 days before), 38 of them features."); + expect(r.sections.map((s: { title: string }) => s.title)).toEqual([ + "Merged", + "Features, by project", + "Issues", + "The queue", + ]); + expect(r.sections[0].lines).toEqual([ + "77 pull requests merged (▲ 10% on the 7 days before).", + "That is 38 features and 39 fixes.", + // The middle of 20, 30, 60, 90, 120 and 600. + "The middle one waited 75 min from opened to merged.", + "The busiest day was Wed 18 Nov, with 12.", + ]); + expect(r.sections[1].lines).toEqual([ + "38 features merged (▲ 36% on the 7 days before): 25 in PM stack and 13 in id.", + ]); + expect(r.sections[1].links).toEqual([ + { text: "the app's look", meta: "PM stack · #14379", url: "https://github.com/developing-today/code/pull/14379" }, + ]); + expect(r.sections[2].lines).toEqual([ + "2 issues opened and 7 closed (▲ from none on the 7 days before): the backlog went down by 5.", + "0 bugs reported and 0 fixed.", + "0 pull requests opened; 0 closed without merging.", + ]); + expect(r.sections[3].lines).toEqual([ + "14 tasks finished (▲ 100% on the 7 days before): 7 small fix and 7 feature slice.", + "Right now 118 are in progress, 99 queued and 283 blocked.", + ]); + expect(r.notes).toEqual(["Today is not over."]); + // A project that merged many features lists its latest three to open, not all of them. + const many = doc(7, 14); + many.features.projects.id = many.days.map(() => 1); + many.features.latest.id = [5, 4, 3, 2, 1].map((n) => ({ + number: n, + title: `feature ${n}`, + at: "2026-11-24T10:00:00Z", + url: `u${n}`, + })); + expect(reportOf(many).sections[1].links.map((l: { text: string }) => l.text)).toEqual([ + "feature 5", + "feature 4", + "feature 3", + ]); + // As text, to copy or share: every sentence, and each feature with where it is. + expect(r.text.split("\n").slice(0, 3)).toEqual([ + "7 days to Tue 24 Nov (Wed 18 Nov to Tue 24 Nov, UTC)", + "", + "Merged", + ]); + expect(r.text).toContain("- the app's look (PM stack · #14379) https://github.com/developing-today/code/pull/14379"); + expect(r.text.endsWith("Today is not over.")).toBe(true); + for (const section of r.sections) for (const line of section.lines) expect(r.text).toContain(line); +}); + +test("a day gone by as a report: named by its day, set against the day before, with nothing said of now", () => { + const d = doc(1, 2); + d.days = ["2026-11-22", "2026-11-23"]; + d.end = "2026-11-23"; + d.merged.all = [4, 1]; + d.merged.kinds.other = [4, 1]; + d.issues.opened = [0, 3]; + d.issues.closed = [0, 1]; + d.bugs.opened = [0, 1]; + d.tasks = { error: "queue store http 503" }; + const r = reportOf(d, { claimed: 5, queued: 5, blocked: 5 }); + expect([r.title, r.period, r.today]).toEqual(["Mon 23 Nov", "Mon 23 Nov", false]); + expect(r.headline).toBe("1 pull request merged (▼ 75% on the day before), 0 of them features."); + // One of something is said as one; nothing of a kind is not listed; a day has no busiest day. + expect(r.sections[0].lines).toEqual(["1 pull request merged (▼ 75% on the day before).", "That is 1 other."]); + expect(r.sections.map((s: { title: string }) => s.title)).toEqual(["Merged", "Issues"]); + expect(r.sections[1].lines[0]).toBe( + "3 issues opened and 1 closed (▲ from none on the day before): the backlog grew by 2.", + ); + expect(r.sections[1].lines[1]).toBe("1 bug reported and 0 fixed."); + expect(r.notes).toEqual([]); + // Today, as a day: "so far", and the queue as it stands. + const t = doc(1, 2); + t.tasks = { all: [0, 2], kinds: [{ kind: "triage", days: [0, 2] }], since: "2026-11-24" }; + const now = reportOf(t, { claimed: 1, queued: 2, blocked: 3 }); + expect([now.title, now.notes]).toEqual(["Today so far", ["The day is not over."]]); + expect(now.sections[now.sections.length - 1].lines).toEqual([ + "2 tasks finished (▲ from none on the day before): 2 triage.", + "Right now 1 are in progress, 2 queued and 3 blocked.", + ]); + expect(reportOf(t, null).sections[now.sections.length - 1].lines.length).toBe(1); + // Level, and nothing either way. + const level = doc(7, 14); + level.issues.opened = level.days.map(() => 1); + level.issues.closed = level.days.map(() => 1); + expect(reportOf(level).sections[1].lines[0]).toBe( + "7 issues opened and 7 closed (level on the 7 days before): the backlog stayed level.", + ); +}); + +test("a report says when its numbers are not whole, and sets nothing against days that are not", () => { + const d = doc(7, 14); + d.merged.all = [10, 10, 10, 10, 10, 10, 10, 12, 12, 12, 12, 12, 12, 5]; + d.history.whole = false; + d.history.covered = "2026-11-17T12:00:00Z"; + // The week is whole (from the 18th); the week before is not: no comparison, and nothing to warn of. + const week = reportOf(d); + expect([week.whole, week.headline, week.notes]).toEqual([ + true, + "77 pull requests merged, 0 of them features.", + ["Today is not over."], + ]); + d.history.covered = "2026-11-21T12:00:00Z"; + const part = reportOf(d); + expect(part.whole).toBe(false); + expect(part.notes[0]).toBe( + "GitHub's history is whole from Sun 22 Nov on: days before that in this report are undercounted. It is still being read.", + ); + d.history.covered = null; + d.partial = true; + d.why = "GitHub's history could not be read on: timed out"; + expect(reportOf(d).notes).toEqual([ + "GitHub's history is still being read for the first time: these numbers are what has been read so far.", + "Today is not over.", + "GitHub's history could not be read on: timed out", + ]); + // Stepping a report back and forth by its own length, across a month's end. + expect([ + dayFrom("2026-11-24", -7), + dayFrom("2026-11-03", -7), + dayFrom("2026-11-24", 1), + dayFrom("2026-12-31", 1), + ]).toEqual(["2026-11-17", "2026-10-27", "2026-11-25", "2027-01-01"]); + expect(reports.route).toBe("more/reports"); +}); diff --git a/pm-stack/console/test/sw.test.ts b/pm-stack/console/test/sw.test.ts index 08fd058b6..353e326b4 100644 --- a/pm-stack/console/test/sw.test.ts +++ b/pm-stack/console/test/sw.test.ts @@ -447,6 +447,7 @@ test("installed, the worker has the app's own files, and one it cannot fetch doe "/console/look.js", "/console/outbox.js", "/console/pages/index.js", + "/console/pages/reports.js", "/console/pages/trends.js", "/console/themes.css", "/console/ui.js", @@ -694,6 +695,7 @@ test("asked to forget, the worker drops what the app read and keeps the app itse "/console/look.js", "/console/outbox.js", "/console/pages/index.js", + "/console/pages/reports.js", "/console/pages/trends.js", "/console/themes.css", "/console/ui.js", diff --git a/pm-stack/console/test/trends.test.ts b/pm-stack/console/test/trends.test.ts index 8acaeb63a..7287b59ef 100644 --- a/pm-stack/console/test/trends.test.ts +++ b/pm-stack/console/test/trends.test.ts @@ -717,6 +717,23 @@ describe("the document the Trends screen draws", () => { expect((await w.trends.read("30")).days.length).toBe(60); for (const odd of [null, "", "0", "8", "abc", "-7", "1e2"]) expect([(await w.trends.read(odd)).window, odd]).toEqual([30, odd]); + // A single day, for a report of one: set against the day before. + const day = await w.trends.read("1"); + expect([day.window, day.days, day.end]).toEqual([1, ["2026-11-23", "2026-11-24"], "2026-11-24"]); + // A window that ends on an earlier day: the week to the 23rd, and what merged then. + const earlier = await w.trends.read("7", false, "2026-11-23"); + expect([earlier.end, earlier.today, earlier.days.length, earlier.days[13]]).toEqual([ + "2026-11-23", + "2026-11-24", + 14, + "2026-11-23", + ]); + expect(earlier.merged.all.slice(-2)).toEqual([0, 1]); + expect(earlier.features.latest.id.map((f) => f.number)).toEqual([1]); + // A day that is not one, or has not come, is today. + for (const odd of ["2026-11-25", "2027-01-01", "yesterday", "2026-13-40", "", "2026-11-2"]) { + expect([odd, (await w.trends.read("7", false, odd)).end]).toEqual([odd, "2026-11-24"]); + } // Ninety days back is all the history there is: no day before it is shown. expect((await w.trends.read("90")).days[0]).toBe("2026-08-27"); });