Public: anyone can read this; the crew can change it.
A milestone's page draws its issues closed per day as a §5 sparkline and says the date it is on pace to finish #5865
scout/forge:scout/5850-a-milestone-s-page-draws-its-issues-clos → main 8 commits fork 8 threads · 8 unresolved
docs/MCP.md +1 −1
| @@ -91,7 +91,7 @@ for a tunnel and a forge that sleeps. | ||
| 91 | 91 | | `make_it_yours` | `{ repo, name?, visibility?, dryRun? }`: a fork of an app you can see, as your own app, following the original; code and history copied, data and secrets not; private unless `visibility` is public (a public original only); at most 5 copies an account a day; plans unless `dryRun` is false | yes | |
| 92 | 92 | | `map` | an app's plan: ready now, waiting on what, the critical path, where the crew is, parked twice and why (`app`); draws the `ui://forge/map` card | | |
| 93 | 93 | | `migrate` | `{ url, name?, crew? }` brings a public repository in by URL (history only; nothing reaches back) and answers `{ job, state, url }`; `{ job }` alone reads that job. Same validation, scope (`rw`) and private-address refusal as `POST /api/v1/migrate` | yes | |
| 94 | | `milestones` | `{ app, issue? }`: how far each thing asked for is (and, with `issue`, whether you watch it: `watching`), from the dependency tree: the plan's limbs with their weights, or one milestone opened (who is building, what is blocked and on what, what merged in 7 days, an estimate, and for an owner `spend`: dollars, changes landed ever, the costliest three issues) | | | |
| 94 | | `milestones` | `{ app, issue? }`: how far each thing asked for is (and, with `issue`, whether you watch it: `watching`), from the dependency tree: the plan's limbs with their weights, or one milestone opened (who is building, what is blocked and on what, what merged in 7 days, an estimate, `closedPerDay` (issues closed each of the last 14 days), `paceDate` and `pace` (on pace for / no movement / done), and for an owner `spend`: dollars, changes landed ever, the costliest three issues) | | | |
| 95 | 95 | | `mint_invite` | `{ days? }`: mint a single-use invite link that expires in `days` (1–30, default 7) and is shown once; a person admin's, with an admin token | yes | |
| 96 | 96 | | `mirror_set` | `{ action, endpoint?, bucket?, region?, accessKey?, secretKey? }` (forge admin, admin-scope token): `set` seals the off-box snapshot mirror, `forget` clears it; the Backups page's rules and refusals, a blank field keeps what was sealed; answers `{ place, says }`, never a key | yes | |
| 97 | 97 | | `model_ceiling` | `{ username, dailyUsd, perRunUsd, dryRun? }` (a forge admin who is a person): cap an account's daily and per-run model spend in dollars (both `null` clears); planned unless `dryRun` is false, applying takes an admin token | yes | |
docs/PLANNING.md +7 −1
| @@ -267,7 +267,13 @@ dropped and split issues are neither. | ||
| 267 | 267 | `/:owner/:name/milestones/:number` is one milestone opened: who is building |
| 268 | 268 | what, what is blocked and on what, what merged this week, and a plain |
| 269 | 269 | estimate — the open issues at the pace of the last 7 days, or a sentence |
| 270 | saying there is no pace to estimate from. What it waits for directly shows | |
| 270 | saying there is no pace to estimate from. Under the head sits a | |
| 271 | 14-day sparkline of issues closed per day beneath the milestone and one pace | |
| 272 | line: _on pace for <date>_ (the open issues at the last 7 days' rate), _no | |
| 273 | movement in 7 days_, or _done <date>_ once nothing is open. The API route | |
| 274 | (`GET /api/v1/repos/:o/:n/milestones/:n`) and the MCP `milestones` tool with | |
| 275 | `issue` return the same as `closedPerDay` (14 numbers, oldest first), | |
| 276 | `paceDate` (a date or null) and `pace` (the line). What it waits for directly shows | |
| 271 | 277 | as limbs where a child brings a tree of its own, and as leaves where it |
| 272 | 278 | brings none (one that only waits for its siblings is a leaf in an order). |
| 273 | 279 | Leaves show only on the limb they are under, and each issue shows once: |
src/core/milestones.ts +10
| @@ -139,6 +139,8 @@ export interface Plan { | ||
| 139 | 139 | * milestone with nothing beneath it, which says so. |
| 140 | 140 | */ |
| 141 | 141 | milestone(number: number): Milestone | undefined; |
| 142 | /** The ids of the work beneath an issue, open or finished, for a read of its pace. */ | |
| 143 | beneathIds(number: number): string[]; | |
| 142 | 144 | /** |
| 143 | 145 | * A limb as rows, top down — what an action on the whole limb selects. |
| 144 | 146 | * `own` is the issue of that number and everything beneath it that only |
| @@ -532,6 +534,14 @@ export function readPlan( | ||
| 532 | 534 | .filter((i) => i.state === "open" && graph.deferred.has(i.id)) |
| 533 | 535 | .sort((a, b) => a.number - b.number); |
| 534 | 536 | }, |
| 537 | beneathIds(number: number): string[] { | |
| 538 | const issue = byNumber.get(number); | |
| 539 | if (issue === undefined) return []; | |
| 540 | return [...beneath(issue.id)] | |
| 541 | .map((id) => byId.get(id)) | |
| 542 | .filter((i): i is Issue => i !== undefined && counted(i)) | |
| 543 | .map((i) => i.id); | |
| 544 | }, | |
| 535 | 545 | milestone(number: number): Milestone | undefined { |
| 536 | 546 | const issue = byNumber.get(number); |
| 537 | 547 | if (issue === undefined || !waits.has(issue.id)) return undefined; |
src/core/pace.ts added +84
| @@ -0,0 +1,84 @@ | ||
| 1 | /** | |
| 2 | * Pace (#5850): issues closed per day beneath a milestone, and the date it | |
| 3 | * is on pace to finish. One grouped query reads every day anything beneath | |
| 4 | * it closed; the rest is arithmetic on that, so a page and the MCP say the | |
| 5 | * same words. Days are UTC dates. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { Database } from "bun:sqlite"; | |
| 9 | ||
| 10 | /** Days drawn. */ | |
| 11 | export const PACE_DAYS = 14; | |
| 12 | /** Days the rate is taken over. */ | |
| 13 | export const RATE_DAYS = 7; | |
| 14 | ||
| 15 | export interface Pace { | |
| 16 | /** Closed each day, oldest first, today last: `PACE_DAYS` numbers. */ | |
| 17 | readonly closedPerDay: readonly number[]; | |
| 18 | /** `done <date>`, `on pace for <date>` or `no movement in 7 days`. */ | |
| 19 | readonly paceLine: string; | |
| 20 | /** The date it finished, or is on pace to; null when it is neither. */ | |
| 21 | readonly paceDate: string | null; | |
| 22 | } | |
| 23 | ||
| 24 | const DAY_MS = 86_400_000; | |
| 25 | const dayOf = (at: Date): string => at.toISOString().slice(0, 10); | |
| 26 | ||
| 27 | /** Closed per day by UTC date, for the given issues that finished as work. One query. */ | |
| 28 | export function closedByDay(db: Database, ids: readonly string[]): Map<string, number> { | |
| 29 | if (ids.length === 0) return new Map(); | |
| 30 | const rows = db | |
| 31 | .query<{ d: string; n: number }, [string]>( | |
| 32 | `SELECT substr(closed_at, 1, 10) AS d, COUNT(*) AS n | |
| 33 | FROM issue | |
| 34 | WHERE id IN (SELECT value FROM json_each(?1)) | |
| 35 | AND state = 'closed' AND closed_at IS NOT NULL | |
| 36 | AND (close_reason IS NULL OR close_reason = 'done') | |
| 37 | GROUP BY d`, | |
| 38 | ) | |
| 39 | .all(JSON.stringify(ids)); | |
| 40 | return new Map(rows.map((r) => [r.d, r.n])); | |
| 41 | } | |
| 42 | ||
| 43 | /** The words and numbers, from the days read, how many are open and whether anything counts. */ | |
| 44 | export function paceOf( | |
| 45 | byDay: ReadonlyMap<string, number>, | |
| 46 | open: number, | |
| 47 | total: number, | |
| 48 | now: Date = new Date(), | |
| 49 | ): Pace { | |
| 50 | const closedPerDay: number[] = []; | |
| 51 | for (let back = PACE_DAYS - 1; back >= 0; back--) | |
| 52 | closedPerDay.push(byDay.get(dayOf(new Date(now.getTime() - back * DAY_MS))) ?? 0); | |
| 53 | if (total > 0 && open === 0) { | |
| 54 | const last = [...byDay.keys()].sort().pop(); | |
| 55 | if (last !== undefined) return { closedPerDay, paceLine: `done ${last}`, paceDate: last }; | |
| 56 | } | |
| 57 | const week = closedPerDay.slice(-RATE_DAYS).reduce((a, b) => a + b, 0); | |
| 58 | if (week === 0 || open === 0) | |
| 59 | return { closedPerDay, paceLine: `no movement in ${RATE_DAYS} days`, paceDate: null }; | |
| 60 | const days = Math.ceil(open / (week / RATE_DAYS)); | |
| 61 | const date = dayOf(new Date(now.getTime() + days * DAY_MS)); | |
| 62 | return { closedPerDay, paceLine: `on pace for ${date}`, paceDate: date }; | |
| 63 | } | |
| 64 | ||
| 65 | /** The pace of the issues beneath a milestone. */ | |
| 66 | export function paceBeneath( | |
| 67 | db: Database, | |
| 68 | ids: readonly string[], | |
| 69 | open: number, | |
| 70 | now: Date = new Date(), | |
| 71 | ): Pace { | |
| 72 | return paceOf(closedByDay(db, ids), open, ids.length, now); | |
| 73 | } | |
| 74 | ||
| 75 | const BLOCKS = "▁▂▃▄▅▆▇█"; | |
| 76 | ||
| 77 | /** The pace as one line of text, for a terminal: blocks for the days, the counts, then the words. */ | |
| 78 | export function paceText(p: Pace): string { | |
| 79 | const top = Math.max(...p.closedPerDay); | |
| 80 | const blocks = p.closedPerDay | |
| 81 | .map((n) => (n === 0 ? " " : BLOCKS[Math.min(7, Math.ceil((n / top) * 8) - 1)])) | |
| 82 | .join(""); | |
| 83 | return `Closed per day (${PACE_DAYS}d): ${blocks} ${p.closedPerDay.join(",")} · ${p.paceLine}`; | |
| 84 | } |
src/http/mcp/tools/milestones.ts +1 −1
| @@ -3,7 +3,7 @@ import { good, bad, type Tool, APP_ARG, planRepo, isAnswer } from "../shared.ts" | ||
| 3 | 3 | |
| 4 | 4 | export const tool: Tool = { |
| 5 | 5 | name: "milestones", |
| 6 | doc: "`{ app, issue? }`: how far each thing asked for is (and, with `issue`, whether you watch it: `watching`), from the dependency tree: the plan's limbs with their weights, or one milestone opened (who is building, what is blocked and on what, what merged in 7 days, an estimate, and for an owner `spend`: dollars, changes landed ever, the costliest three issues)", | |
| 6 | doc: "`{ app, issue? }`: how far each thing asked for is (and, with `issue`, whether you watch it: `watching`), from the dependency tree: the plan's limbs with their weights, or one milestone opened (who is building, what is blocked and on what, what merged in 7 days, an estimate, `closedPerDay` (issues closed each of the last 14 days), `paceDate` and `pace` (on pace for / no movement / done), and for an owner `spend`: dollars, changes landed ever, the costliest three issues)", | |
| 7 | 7 | description: |
| 8 | 8 | "How far each ask is. With `app`: top-level limbs, done/total, building, recent merges.", |
| 9 | 9 | inputSchema: { |
src/tui/screens/limbs.ts +17 −5
| @@ -29,6 +29,7 @@ import { IN_HAND } from "../../actions/plan_words.ts"; | ||
| 29 | 29 | import { pendingReplans } from "../../core/limb_replan.ts"; |
| 30 | 30 | import { applyLimb, previewLimb, type LimbPreview } from "../../actions/limbs.ts"; |
| 31 | 31 | import { canAdmin, canRead, canSeeOwnerFacts, type Repo } from "../../core/repos.ts"; |
| 32 | import { paceBeneath, paceText } from "../../core/pace.ts"; | |
| 32 | 33 | import { readPlan, type Limb, type Milestone } from "../../core/milestones.ts"; |
| 33 | 34 | import type { Ctx, Screen } from "../app/app.ts"; |
| 34 | 35 | import { binding } from "../app/keys.ts"; |
| @@ -110,6 +111,8 @@ export function limbsScreen( | ||
| 110 | 111 | let loaded = false; |
| 111 | 112 | /** What each limb here cost and landed, by issue number; empty unless owner facts. */ |
| 112 | 113 | let spends = new Map<number, NonNullable<Milestone["spend"]>>(); |
| 114 | /** The pace line of each limb here, by issue number. */ | |
| 115 | let paces = new Map<number, string>(); | |
| 113 | 116 | /** The receipt of the last move made here, which `u` reverses once. */ |
| 114 | 117 | let last: string | undefined; |
| 115 | 118 | /** The limbs with the planner, by issue id (#761). */ |
| @@ -122,6 +125,7 @@ export function limbsScreen( | ||
| 122 | 125 | if (!canRead(f.db, repo, f.user)) { |
| 123 | 126 | limbs = []; |
| 124 | 127 | spends = new Map(); |
| 128 | paces = new Map(); | |
| 125 | 129 | loaded = true; |
| 126 | 130 | ctx.invalidate(); |
| 127 | 131 | return; |
| @@ -129,6 +133,13 @@ export function limbsScreen( | ||
| 129 | 133 | limbs = limbsOf(f, repo, group) ?? []; |
| 130 | 134 | withPlanner = new Set(pendingReplans(f.db, repo).map((r) => r.limbId)); |
| 131 | 135 | spends = new Map(); |
| 136 | paces = new Map(); | |
| 137 | const read = readPlan(f.db, repo); | |
| 138 | for (const l of limbs) { | |
| 139 | const m = read.milestone(l.issue.number); | |
| 140 | if (m !== undefined) | |
| 141 | paces.set(l.issue.number, paceText(paceBeneath(f.db, read.beneathIds(l.issue.number), m.weight.open))); | |
| 142 | } | |
| 132 | 143 | if (canSeeOwnerFacts(f.db, repo, f.user)) { |
| 133 | 144 | const plan = readPlan(f.db, repo, { spend: true }); |
| 134 | 145 | for (const l of limbs) { |
| @@ -289,7 +300,9 @@ export function limbsScreen( | ||
| 289 | 300 | render(area, s) { |
| 290 | 301 | const c = ctx.theme.c; |
| 291 | 302 | const spend = current() === undefined ? undefined : spends.get(current()!.issue.number); |
| 292 | const [head, list, foot] = split(area, "v", [len(1), fill(1), len(spend ? 2 : 0)]); | |
| 303 | const pace = current() === undefined ? undefined : paces.get(current()!.issue.number); | |
| 304 | const lines = [...(pace === undefined ? [] : [pace]), ...(spend === undefined ? [] : spendLines(spend))]; | |
| 305 | const [head, list, foot] = split(area, "v", [len(1), fill(1), len(lines.length)]); | |
| 293 | 306 | const note = !loaded |
| 294 | 307 | ? "Loading…" |
| 295 | 308 | : limbs.length === 0 |
| @@ -297,10 +310,9 @@ export function limbsScreen( | ||
| 297 | 310 | : `${plural(limbs.length, "limb")} in the order the crew takes ready work${may() ? "" : " · you can read this order, not change it"}`; |
| 298 | 311 | s.text(head!.x, head!.y, truncate(note, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); |
| 299 | 312 | drawList(s, list!, c, state, rows()); |
| 300 | if (spend !== undefined) | |
| 301 | spendLines(spend).forEach((text, n) => | |
| 302 | s.text(foot!.x, foot!.y + n, truncate(text, foot!.w), style(c.mutedFg, c.bg), foot!.x + foot!.w), | |
| 303 | ); | |
| 313 | lines.forEach((text, n) => | |
| 314 | s.text(foot!.x, foot!.y + n, truncate(text, foot!.w), style(c.mutedFg, c.bg), foot!.x + foot!.w), | |
| 315 | ); | |
| 304 | 316 | hitList(ctx, list!, state, limbs.length, { open }); |
| 305 | 317 | }, |
| 306 | 318 | key(e) { |
src/web/pages/milestones.ts +29 −4
| @@ -39,6 +39,8 @@ import { replanResult } from "../../actions/limb_replan.ts"; | ||
| 39 | 39 | import { given, pendingFor } from "../../core/limb_replan.ts"; |
| 40 | 40 | import type { Ctx } from "../../http/context.ts"; |
| 41 | 41 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 42 | import { paceBeneath, PACE_DAYS, type Pace } from "../../core/pace.ts"; | |
| 43 | import { daySpark } from "../studio/kpi_row.ts"; | |
| 42 | 44 | import { cachedPlan } from "../map_cache.ts"; |
| 43 | 45 | import { askToLiveFor } from "../ask_to_live.ts"; |
| 44 | 46 | import { |
| @@ -364,6 +366,7 @@ function milestoneBody( | ||
| 364 | 366 | names: boolean, |
| 365 | 367 | actions: Html | null, |
| 366 | 368 | move?: Mover, |
| 369 | pace?: Pace, | |
| 367 | 370 | ): Html { |
| 368 | 371 | const base = repoBase(repo); |
| 369 | 372 | const w = m.weight; |
| @@ -401,6 +404,7 @@ function milestoneBody( | ||
| 401 | 404 | m.trim === undefined ? {} : { tone: "attn" }, |
| 402 | 405 | )} |
| 403 | 406 | <p id="ms-estimate">${m.estimate}</p> |
The terminal's milestone screen ( |
||
| 407 | ${when(pace, (p) => paceRow(p))} | |
| 404 | 408 | ${when( |
| 405 | 409 | m.trim, |
| 406 | 410 | (why) => html`<p class="small">A candidate to trim: ${why}.</p>`, |
| @@ -534,6 +538,18 @@ function milestoneBody( | ||
| 534 | 538 | )}`; |
| 535 | 539 | } |
| 536 | 540 | |
| 541 | /** The last `PACE_DAYS` days of closing as a sparkline, and the one line beside it. */ | |
| 542 | function paceRow(p: Pace): Html { | |
| 543 | const total = p.closedPerDay.reduce((a, b) => a + b, 0); | |
| 544 | const spark = daySpark( | |
| 545 | p.closedPerDay, | |
| 546 | `Issues closed each day over the last ${PACE_DAYS} days: ${total} in all`, | |
| 547 | ); | |
| 548 | return html`<p class="bar small" id="ms-pace"> | |
This row is hand-rolled: a |
||
| 549 | <span class="muted">${spark}</span><span>${p.paceLine}</span> | |
| 550 | </p>`; | |
Nested |
||
| 551 | } | |
| 552 | ||
| 537 | 553 | /** GET /:owner/:name/milestones/:number — one milestone, opened. */ |
| 538 | 554 | export function milestonePage(ctx: Ctx): Response { |
| 539 | 555 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| @@ -548,6 +564,9 @@ export function milestonePage(ctx: Ctx): Response { | ||
| 548 | 564 | if (plan === undefined || milestone === undefined) return notFoundPage(ctx); |
| 549 | 565 | const rendering = performance.now(); |
| 550 | 566 | const viewer = ctx.auth.user; |
| 567 | const pace = timePhase(ctx.request, "pace", () => | |
| 568 | paceBeneath(ctx.app.db, plan.beneathIds(number), milestone.weight.open), | |
| 569 | ); | |
| 551 | 570 | // Watch is each person's own; acting on the whole limb is for whoever |
| 552 | 571 | // administers the repository. One row, Watch first. |
| 553 | 572 | const watch = |
| @@ -581,7 +600,7 @@ export function milestonePage(ctx: Ctx): Response { | ||
| 581 | 600 | crumbs: crumbsFor(repo), |
| 582 | 601 | palette: repoPalette(ctx, repo), |
| 583 | 602 | body: html`${repoHeader(ctx, repo, "map")} |
| 584 | ${milestoneBody(repo, milestone, owner, actions, move)} | |
| 603 | ${milestoneBody(repo, milestone, owner, actions, move, pace)} | |
| 585 | 604 | ${replanChanged(ctx, repo, milestone)} |
| 586 | 605 | ${liveMount({ repo: repoBase(repo) })}`, |
| 587 | 606 | scriptJs: liveClientJs, |
| @@ -654,6 +673,8 @@ function askByUmbrella( | ||
| 654 | 673 | const askOf = (ask: Map<number, AskToLive | null>, number: number) => |
| 655 | 674 | ask.has(number) ? { askToLive: ask.get(number) } : {}; |
| 656 | 675 | |
| 676 | const paceJson = (p: Pace) => ({ closedPerDay: p.closedPerDay, paceDate: p.paceDate, pace: p.paceLine }); | |
| 677 | ||
| 657 | 678 | /** One milestone as data, or nothing for an issue that waits for nothing. */ |
| 658 | 679 | export async function milestoneData( |
| 659 | 680 | ctx: Ctx, |
| @@ -661,15 +682,19 @@ export async function milestoneData( | ||
| 661 | 682 | number: number, |
| 662 | 683 | ): Promise<Record<string, unknown> | undefined> { |
| 663 | 684 | const owner = canSeeOwnerFacts(ctx.app.db, repo, ctx.auth.user); |
| 664 | const milestone = readPlan(ctx.app.db, repo, { spend: owner }).milestone( | |
| 665 | number, | |
| 666 | ); | |
| 685 | const plan = readPlan(ctx.app.db, repo, { spend: owner }); | |
| 686 | const milestone = plan.milestone(number); | |
| 667 | 687 | const viewer = ctx.auth.user; |
| 668 | 688 | return milestone === undefined |
| 669 | 689 | ? undefined |
| 670 | 690 | : { |
| 671 | 691 | repo: { owner: repo.ownerName, name: repo.name }, |
| 672 | 692 | ...milestoneJson(milestone, owner), |
| 693 | ...paceJson( | |
| 694 | timePhase(ctx.request, "pace", () => | |
| 695 | paceBeneath(ctx.app.db, plan.beneathIds(number), milestone.weight.open), | |
| 696 | ), | |
| 697 | ), | |
| 673 | 698 | ...askOf(askByUmbrella(ctx, repo, number), number), |
| 674 | 699 | // Whether the caller watches it; a caller who cannot has no answer. |
| 675 | 700 | ...(viewer?.kind === "user" |
test/api-milestones-timing.test.ts +7 −2
| @@ -80,12 +80,17 @@ test("the proposals read names session, read, render", async () => { | ||
| 80 | 80 | expect(JSON.parse(got.body).items).toBeArray(); |
| 81 | 81 | }); |
| 82 | 82 | |
| 83 | test("one milestone names session, read, render; a miss names session and read", async () => { | |
| 83 | test("one milestone names session, pace, read, render; a miss names session and read", async () => { | |
| 84 | 84 | const list = JSON.parse((await phases("/api/v1/repos/alice/r/milestones")).body); |
| 85 | 85 | expect(list.limbs.length).toBeGreaterThan(0); |
| 86 | 86 | const got = await phases(`/api/v1/repos/alice/r/milestones/${umbrella}`); |
| 87 | 87 | expect(got.status).toBe(200); |
| 88 | expect(got.names).toEqual(["session", "read", "render"]); | |
| 88 | expect(got.names).toEqual(["session", "pace", "read", "render"]); | |
This only pins the phase names. Add a body assertion for closedPerDay (14 numbers) and pace on the API route. |
||
| 89 | const json = JSON.parse(got.body); | |
| 90 | expect(json.closedPerDay).toHaveLength(14); | |
| 91 | expect(json.closedPerDay.every((n: unknown) => Number.isInteger(n))).toBe(true); | |
| 92 | expect(json.pace).toBe("no movement in 7 days"); | |
| 93 | expect(json.paceDate).toBeNull(); | |
| 89 | 94 | const miss = await phases("/api/v1/repos/alice/r/milestones/9999"); |
| 90 | 95 | expect(miss.status).toBe(404); |
| 91 | 96 | expect(miss.names).toEqual(["session", "read"]); |
test/milestones.test.ts +11
| @@ -575,4 +575,15 @@ describe("milestones", () => { | ||
| 575 | 575 | )!; |
| 576 | 576 | expect(reader.spend).toBeUndefined(); |
| 577 | 577 | }); |
| 578 | ||
| 579 | test("a milestone's page draws its closing per day and says its pace; the MCP gives the same", async () => { | |
| 580 | const html = await (await get("alice", `/alice/engine/milestones/${ship.number}`)).text(); | |
| 581 | expect(html).toContain('id="ms-pace"'); | |
| 582 | expect(html).toMatch(/<svg[^>]*role="img"/); | |
| 583 | const data = (await tool({ app: "alice/engine", issue: ship.number })).value; | |
| 584 | expect(data.closedPerDay).toHaveLength(14); | |
| 585 | expect(data.closedPerDay.at(-1)).toBeGreaterThan(0); | |
This test reads the clock twice. The fixture closes an issue at setup and the page reads |
||
| 586 | expect(data.paceDate).toMatch(/^\d{4}-\d{2}-\d{2}$/); | |
| 587 | expect(html).toContain(`on pace for ${data.paceDate}`); | |
| 588 | }); | |
| 578 | 589 | }); |
test/pace.test.ts added +62
| @@ -0,0 +1,62 @@ | ||
| 1 | /** Pace (#5850): closed per day, the date on pace, a stalled milestone, a finished one, and one cheap query. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { Database } from "bun:sqlite"; | |
| 4 | import { closedByDay, paceOf, PACE_DAYS } from "../src/core/pace.ts"; | |
| 5 | ||
| 6 | const now = new Date("2026-10-25T12:00:00Z"); | |
| 7 | ||
| 8 | test("on pace: the 7-day rate and the open count give a date", () => { | |
| 9 | // 7 closed in the last 7 days is 1 a day; 5 open is 5 days. | |
| 10 | const p = paceOf(new Map([["2026-10-25", 3], ["2026-10-22", 4], ["2026-10-01", 9]]), 5, 20, now); | |
| 11 | expect(p.closedPerDay).toHaveLength(PACE_DAYS); | |
| 12 | expect(p.closedPerDay.at(-1)).toBe(3); | |
| 13 | expect(p.closedPerDay.at(-4)).toBe(4); | |
| 14 | expect(p.paceLine).toBe("on pace for 2026-10-30"); | |
| 15 | expect(p.paceDate).toBe("2026-10-30"); | |
| 16 | }); | |
| 17 | ||
| 18 | test("a stalled milestone says no movement, however old its closes", () => { | |
| 19 | const p = paceOf(new Map([["2026-10-10", 5]]), 3, 8, now); | |
| 20 | expect(p.paceLine).toBe("no movement in 7 days"); | |
| 21 | expect(p.paceDate).toBeNull(); | |
| 22 | expect(p.closedPerDay.slice(-7).every((n) => n === 0)).toBe(true); | |
| 23 | }); | |
| 24 | ||
| 25 | test("a finished milestone says the day its last issue closed", () => { | |
| 26 | const p = paceOf(new Map([["2026-10-03", 2], ["2026-10-20", 1]]), 0, 3, now); | |
| 27 | expect(p.paceLine).toBe("done 2026-10-20"); | |
| 28 | expect(p.paceDate).toBe("2026-10-20"); | |
| 29 | }); | |
| 30 | ||
| 31 | test("nothing beneath it is no movement", () => { | |
| 32 | expect(paceOf(new Map(), 0, 0, now).paceLine).toBe("no movement in 7 days"); | |
| 33 | }); | |
| 34 | ||
| 35 | test("one grouped query counts work only, and 500 issues are one statement on the primary key", () => { | |
| 36 | const db = new Database(":memory:"); | |
| 37 | db.exec("CREATE TABLE issue (id TEXT PRIMARY KEY, state TEXT, close_reason TEXT, closed_at TEXT)"); | |
| 38 | const ids: string[] = []; | |
| 39 | const add = db.prepare("INSERT INTO issue VALUES (?1, ?2, ?3, ?4)"); | |
| 40 | for (let i = 0; i < 500; i++) { | |
| 41 | ids.push(`i${i}`); | |
| 42 | add.run(`i${i}`, i % 5 === 0 ? "open" : "closed", i % 7 === 0 ? "dropped" : "done", `2026-10-${String(10 + (i % 15)).padStart(2, "0")}T08:00:00.000Z`); | |
| 43 | } | |
| 44 | const real = db.query.bind(db); | |
| 45 | const asked: string[] = []; | |
| 46 | db.query = ((sql: string) => (asked.push(sql), real(sql))) as typeof db.query; | |
outdated
Wall-clock bound on a shared machine: this flakes under load. Assert one statement (count queries or EXPLAIN QUERY PLAN) and drop the 10 ms bound. |
||
| 47 | const days = closedByDay(db, ids); | |
| 48 | expect(asked).toHaveLength(1); | |
| 49 | db.query = real as typeof db.query; | |
| 50 | const plan = db | |
| 51 | .query<{ detail: string }, [string]>(`EXPLAIN QUERY PLAN ${asked[0]}`) | |
| 52 | .all(JSON.stringify(ids)) | |
| 53 | .map((r) => r.detail) | |
| 54 | .join("\n"); | |
| 55 | expect(plan).toContain("SEARCH issue USING INDEX sqlite_autoindex_issue_1 (id=?)"); | |
| 56 | const total = [...days.values()].reduce((a, b) => a + b, 0); | |
| 57 | let expected = 0; | |
| 58 | for (let i = 0; i < 500; i++) if (i % 5 !== 0 && i % 7 !== 0) expected++; | |
| 59 | expect(total).toBe(expected); | |
| 60 | expect(days.get("2026-10-11")).toBeGreaterThan(0); | |
| 61 | db.close(); | |
| 62 | }); |
test/tui-limbs.test.ts +13
| @@ -21,6 +21,7 @@ import { pendingReplans } from "../src/core/limb_replan.ts"; | ||
| 21 | 21 | import { createApp, type App as Forge } from "../src/app.ts"; |
| 22 | 22 | import { listEvents } from "../src/core/events.ts"; |
| 23 | 23 | import { getIssueById, type Issue } from "../src/core/issues.ts"; |
| 24 | import { paceBeneath, paceText } from "../src/core/pace.ts"; | |
| 24 | 25 | import { readPlan } from "../src/core/milestones.ts"; |
| 25 | 26 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; |
| 26 | 27 | import { getRepoById, type Repo } from "../src/core/repos.ts"; |
| @@ -229,6 +230,18 @@ describe("raise and lower a limb in the terminal", () => { | ||
| 229 | 230 | } |
| 230 | 231 | }); |
| 231 | 232 | |
| 233 | test("the limb under the cursor says its pace in the page's words, to a reader too", async () => { | |
| 234 | const plan = readPlan(forge.db, repo); | |
| 235 | const words = paceText(paceBeneath(forge.db, plan.beneathIds(trust.number), plan.milestone(trust.number)!.weight.open)); | |
| 236 | for (const who of [alice, bob]) { | |
| 237 | const h = boot(who); | |
| 238 | await h.toMilestones("alice/order"); | |
| 239 | expect(h.text()).toContain("Closed per day (14d):"); | |
| 240 | expect(h.text()).toContain(words.slice(0, 80)); | |
| 241 | h.stop(); | |
| 242 | } | |
| 243 | }); | |
| 244 | ||
| 232 | 245 | test("a guest sees a public order, never a private one, and moves nothing", async () => { |
| 233 | 246 | const h = boot(undefined); |
| 234 | 247 | await h.toMilestones("alice/vault"); |
This adds a second full
readPlanon every load. The owner branch below then runs a third, and readPlan has its own 30 ms budget test. Read the plan once, with{ spend: canSeeOwnerFacts(...) }, and reuse it for both the pace and the spend lines.