diff --git a/pm-stack/book/reference/console-views.md b/pm-stack/book/reference/console-views.md index 2a5032b95c..6bfc1416cf 100644 --- a/pm-stack/book/reference/console-views.md +++ b/pm-stack/book/reference/console-views.md @@ -150,7 +150,7 @@ This chapter covers all 21 console hash views in the survey census, one entry ea - **What it is:** The intake routing list (`viewIntake`): kinds note, bug, and change, with their label and rank routes (`plan.ts` `ROUTES`; `INTAKE_LABEL = "owner/intake"`). - **Inputs:** A submission from this view. -- **Behaviour:** Submitting files a GitHub issue and a triage/prompt queue packet, routed by kind through the `ROUTES` table. +- **Behaviour:** Submitting files a GitHub issue and a triage/prompt queue packet, routed by kind through the `ROUTES` table. A change against a capability with a roadmap file is also made by the platform itself, as a pull request against that file alone (`console/src/roadmap-change.ts`), when it can be made mechanically — a row added, moved, marked built, dropped, or retitled; the pull request is recorded on the issue, and a change that cannot be made mechanically says why in the answer and stands as issue and task alone. - **Failure shapes:** None recorded in the survey. Sources: PM-SURVEY website census (`pm-stack/console/public/app.js`, `pm-stack/console/src/server.ts`, `pm-stack/console/src/work.ts`, `pm-stack/console/src/ops.ts`, `pm-stack/console/src/plan.ts`), survey files `website-pages.md` and `disagreements.md` (D4, D12, D13), census date 2026-11-23. diff --git a/pm-stack/console/public/app.js b/pm-stack/console/public/app.js index 405d3437d7..5c9ec01aca 100644 --- a/pm-stack/console/public/app.js +++ b/pm-stack/console/public/app.js @@ -1915,7 +1915,9 @@ export function changeAsked(form) { export function intakeSaid(r) { if (!r) return "Sent"; const task = r.queued ? "" : "; its task follows when a machine is connected"; - return r.commented ? `Note left on #${r.issue}${task}` : `Filed as #${r.issue}${task}`; + if (r.commented) return `Note left on #${r.issue}${task}`; + if (r.pr) return `Filed as #${r.issue}; the roadmap change was made as a pull request: ${r.pr}${task}`; + return `Filed as #${r.issue}${task}`; } /** The heading of one phase of a roadmap page: how many it shows, and diff --git a/pm-stack/console/src/plan.ts b/pm-stack/console/src/plan.ts index f312c02dbf..c3b766ee81 100644 --- a/pm-stack/console/src/plan.ts +++ b/pm-stack/console/src/plan.ts @@ -15,6 +15,7 @@ // Everything here reaches GitHub through Ops.gh, so it runs unchanged on // a machine (the fleet binary's gh) and at the edge (GitHub's REST API). import { OpError } from "./errors.ts"; +import { openRoadmapChangePr } from "./roadmap-change.ts"; import { type Ops, RANK_PRIORITY, RANKS, type Rank, type RunResult, triagePacket } from "./ops.ts"; import type { Work } from "./work.ts"; @@ -342,6 +343,8 @@ export interface IntakeResult { /** A comment was left on an existing issue; no issue was made. */ commented: boolean; queued: boolean; + /** The pull request a change was made as, when the platform made it. */ + pr?: string; note?: string; } @@ -502,6 +505,26 @@ export class Plan { }); } + /** The platform's half of a change asked for in the app (#13497): + * the change made as a pull request against the roadmap file it + * belongs to. What cannot be made mechanically is refused with its + * reason, and the caller carries on with the issue and the task. */ + private async roadmapPr( + cap: Capability, + asked: { action: Change; to: Phase | null; title: string | null }, + row: string | null, + words: string, + issue: number, + ) { + return openRoadmapChangePr( + this.ops, + this.repo, + cap, + { action: asked.action, row, title: asked.title, to: asked.to, intent: words }, + { said: changeSaid(asked, row), words, issue, now: this.clock() }, + ); + } + /** * Take in a note, a bug or a change, in the owner's words. * @@ -659,7 +682,34 @@ export class Plan { kind: "triage.enqueue", args: { issue: made.number, title: made.title, rank: filedRank, at }, }).catch(notQueued); - return { issue: made.number, url: made.html_url, commented: false, ...queuedSaid(queued, "filed") }; + const said = queuedSaid(queued, "filed"); + const notes = [...(said.note ? [said.note] : [])]; + // A change asked for in the app is made by the platform itself, as + // a pull request against the roadmap file (#13497). The issue and + // its task stand either way: with a pull request they are its + // record and its review; without one, they are the work, as before. + let pr: string | undefined; + if (kind === "change" && asked !== null && cap?.file) { + const opened = await this.roadmapPr(cap, asked, aboutRow, words, made.number).catch((e: Error) => e); + if (opened instanceof Error) { + notes.push(`the roadmap change was not made as a pull request: ${opened.message}`); + } else { + pr = opened.url; + await this.ops + .gh(["-X", "POST", `repos/${this.repo}/issues/${made.number}/comments`], { + body: `The platform made this change as a pull request: ${opened.url}\n\nIt changes only \`${cap.file}\`. Reviewing and merging it puts the change on the roadmap; until then the roadmap itself is unchanged.`, + }) + .catch(() => {}); + } + } + return { + issue: made.number, + url: made.html_url, + commented: false, + queued: said.queued, + ...(pr ? { pr } : {}), + ...(notes.length ? { note: notes.join("; ").slice(0, 300) } : {}), + }; } } diff --git a/pm-stack/console/src/roadmap-change.ts b/pm-stack/console/src/roadmap-change.ts new file mode 100644 index 0000000000..ffa0421225 --- /dev/null +++ b/pm-stack/console/src/roadmap-change.ts @@ -0,0 +1,324 @@ +// A roadmap change asked for in the app, made by the platform itself: +// the change applied to the roadmap file where it lives, and opened as +// a pull request against that file and no other (#13497, second half). +// +// The ask arrives already checked by Plan.intake: one of the CHANGES +// against a named row of a capability's file, or a new item to add. +// What can be done mechanically is done here — a row added, moved, +// marked built, dropped, or retitled — and what cannot is refused +// with the reason: a sub-item, whose rows have no rows of their own +// in the file's tables, and a rewrite in the owner's words, which is +// prose and not a cell. A refusal is not a failure of the intake: the +// issue and the task stand, as they did before this path existed. +// +// Everything reaches GitHub through Ops.gh, as everywhere in the +// console, so this runs unchanged on a machine (the fleet binary's gh) +// and at the edge (GitHub's REST API). The pull request is made with +// the contents API — one branch, one write to the one file, one pull +// request — so its diff touches only the roadmap file by construction. +import { OpError } from "./errors.ts"; +import type { Ops } from "./ops.ts"; +import type { Capability, Change, Phase } from "./plan.ts"; + +/** A change to one roadmap file, in the terms Plan.intake checks. */ +export interface RoadmapChange { + action: Change; + /** The row it is about, by its title in the file. */ + row?: string | null; + /** A new item's title (add), or a row's new title (rewrite). */ + title?: string | null; + /** The phase it goes to (add, move). */ + to?: Phase | null; + /** A new item's intent: the owner's words. */ + intent?: string | null; + /** An issue a new item is about, named in its Links. */ + issue?: number | null; +} + +/** Why this change cannot be made mechanically, or null when it can. */ +export function roadmapChangeRefusal(change: RoadmapChange): string | null { + switch (change.action) { + case "add": + return change.title ? null : "an added item needs a title"; + case "add-under": + return "a sub-item has no row of its own in the roadmap file's tables"; + case "move": + return !change.row + ? "a move needs the row it moves" + : !change.to + ? "a move needs where it goes" + : null; + case "built": + return change.row ? null : "marking built needs the row it is about"; + case "drop": + return change.row ? null : "a drop needs the row it is about"; + case "rewrite": + return !change.row + ? "a rewrite needs the row it is about" + : !change.title + ? "only a retitle can be made mechanically; a rewrite in words stays with the issue" + : null; + } +} + +const cells = (line: string): string[] => + line + .trim() + .replace(/^\||\|$/g, "") + .split(/(? c.trim().replace(/\\\|/g, "|")); + +const cellOut = (value: string): string => + value + .replace(/\|/g, "\\|") + .replace(/\s*\n\s*/g, " ") + .trim(); + +const rowLine = (values: string[]): string => `| ${values.map(cellOut).join(" | ")} |`; + +/** The phase a section holds, by its heading, as parseRoadmap reads it. */ +const sectionPhase = (heading: string): Phase | null => { + const word = heading.toLowerCase(); + return word.startsWith("now") + ? "now" + : word.startsWith("next") + ? "next" + : word.startsWith("later") + ? "later" + : word.startsWith("done") || word.startsWith("built") + ? "built" + : null; +}; + +/** The section a phase asked for lives in: work in progress sits under Now. */ +const homeOf = (to: Phase): Phase => (to === "doing" ? "now" : to); + +const SECTION_WORD: Record = { + doing: "Now", + now: "Now", + next: "Next", + later: "Later", + built: "Done", +}; + +interface RowAt { + line: number; + values: string[]; +} +interface TableAt { + header: number; + columns: string[]; + rows: RowAt[]; +} +interface SectionAt { + heading: string; + phase: Phase | null; + tables: TableAt[]; +} + +/** The Title tables of a roadmap file, section by section, with the + * line each row sits on. Mirrors parseRoadmap's reading of the file. */ +function scan(lines: string[]): SectionAt[] { + const sections: SectionAt[] = []; + let section: SectionAt | null = null; + let table: TableAt | null = null; + let inRun = false; + lines.forEach((line, at) => { + const heading = /^##\s+(.*)$/.exec(line); + if (heading) { + const name = heading[1].trim(); + section = { heading: name, phase: sectionPhase(name), tables: [] }; + sections.push(section); + table = null; + inRun = false; + return; + } + if (!line.trim().startsWith("|")) { + table = null; + inRun = false; + return; + } + if (!section) return; + if (!inRun) { + inRun = true; + const columns = cells(line).map((c) => c.toLowerCase()); + table = columns[0] === "title" ? { header: at, columns, rows: [] } : null; + if (table) section.tables.push(table); + return; + } + if (!table) return; + const values = cells(line); + if (values.every((c) => /^:?-+:?$/.test(c))) return; + table.rows.push({ line: at, values }); + }); + return sections; +} + +function tableFor(sections: SectionAt[], phase: Phase): TableAt { + const held = sections.filter((s) => s.phase === phase); + const withTable = held.find((s) => s.tables.length > 0); + if (withTable) return withTable.tables[0]; + if (held.length > 0) throw new OpError(400, `the roadmap's ${held[0].heading} section has no table of rows`); + throw new OpError(400, `the roadmap file has no ${SECTION_WORD[phase]} section`); +} + +function oneRow(sections: SectionAt[], title: string): { row: RowAt; table: TableAt } { + const found: { row: RowAt; table: TableAt }[] = []; + for (const section of sections) + for (const table of section.tables) + for (const row of table.rows) + if ((row.values[0] ?? "").toLowerCase() === title.trim().toLowerCase()) found.push({ row, table }); + if (found.length === 0) throw new OpError(400, `no roadmap row is titled "${title}"`); + if (found.length > 1) throw new OpError(400, `more than one roadmap row is titled "${title}"`); + return found[0]; +} + +const setCell = (row: RowAt, table: TableAt, name: string, value: string) => { + const at = table.columns.indexOf(name); + if (at < 0) throw new OpError(400, `the roadmap table has no ${name} column`); + while (row.values.length <= at) row.values.push(""); + row.values[at] = value; +}; + +/** Where a new row goes in a table: after its last row, or after the + * header's separator when the table is still empty. */ +const insertAt = (lines: string[], table: TableAt): number => { + if (table.rows.length > 0) return table.rows[table.rows.length - 1].line + 1; + const sep = lines[table.header + 1] ?? ""; + return table.header + (cells(sep).every((c) => /^:?-+:?$/.test(c)) ? 2 : 1); +}; + +/** + * Apply one change to a roadmap file's text. Pure: the same reading of + * the file as parseRoadmap, and nothing outside the one row is touched. + */ +export function applyRoadmapChange(markdown: string, change: RoadmapChange): string { + const refusal = roadmapChangeRefusal(change); + if (refusal) throw new OpError(400, refusal); + const lines = markdown.split("\n"); + const sections = scan(lines); + switch (change.action) { + case "add": { + const to = homeOf(change.to ?? "next"); + const table = tableFor(sections, to); + const values = table.columns.map((c) => + c === "title" + ? (change.title as string) + : c === "status" + ? to === "built" + ? "shipped" + : "planned" + : c === "intent" + ? (change.intent ?? "") + : c === "links" + ? change.issue + ? `#${change.issue}` + : "" + : "", + ); + lines.splice(insertAt(lines, table), 0, rowLine(values)); + break; + } + case "move": { + const { row } = oneRow(sections, change.row as string); + const text = lines[row.line]; + lines.splice(row.line, 1); + const table = tableFor(scan(lines), homeOf(change.to as Phase)); + lines.splice(insertAt(lines, table), 0, text); + break; + } + case "built": { + const { row, table } = oneRow(sections, change.row as string); + setCell(row, table, "status", "shipped"); + lines[row.line] = rowLine(row.values); + break; + } + case "drop": { + const { row } = oneRow(sections, change.row as string); + lines.splice(row.line, 1); + break; + } + case "rewrite": { + const { row, table } = oneRow(sections, change.row as string); + setCell(row, table, "title", change.title as string); + lines[row.line] = rowLine(row.values); + break; + } + case "add-under": + throw new OpError(400, "a sub-item has no row of its own in the roadmap file's tables"); + } + const out = lines.join("\n"); + if (out === markdown) throw new OpError(400, "the change leaves the roadmap file as it was"); + return out; +} + +const encode64 = (text: string): string => { + const bytes = new TextEncoder().encode(text); + let bin = ""; + bytes.forEach((b) => { + bin += String.fromCharCode(b); + }); + return btoa(bin); +}; + +const decode64 = (encoded: string): string => { + const bytes = Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0)); + return new TextDecoder().decode(bytes); +}; + +export interface RoadmapPr { + url: string; + number: number; + branch: string; + file: string; +} + +/** + * Make one roadmap change as a pull request: read the file from main, + * apply the change, write the file — and only the file — to a fresh + * branch, and open the pull request against main. + */ +export async function openRoadmapChangePr( + ops: Ops, + repo: string, + cap: Capability, + change: RoadmapChange, + opts: { said: string; words: string; issue: number; now: Date }, +): Promise { + const file = cap.file; + if (!file) throw new OpError(400, `${cap.title} has no roadmap file`); + const refusal = roadmapChangeRefusal(change); + if (refusal) throw new OpError(400, refusal); + const got = (await ops.gh([`repos/${repo}/contents/${file}`])) as { content?: string; sha?: string } | null; + if (typeof got?.content !== "string" || typeof got?.sha !== "string") + throw new OpError(502, "the roadmap file could not be read"); + const after = applyRoadmapChange(decode64(got.content), change); + const base = (await ops.gh([`repos/${repo}/git/ref/heads/main`])) as { object?: { sha?: string } } | null; + if (typeof base?.object?.sha !== "string") + throw new OpError(502, "the repository's main branch could not be read"); + const stamp = opts.now.toISOString().replace(/[^0-9]/g, "").slice(0, 14); + const branch = `roadmap/${cap.id}-${stamp}`; + await ops.gh(["-X", "POST", `repos/${repo}/git/refs`], { ref: `refs/heads/${branch}`, sha: base.object.sha }); + await ops.gh(["-X", "PUT", `repos/${repo}/contents/${file}`], { + message: `${cap.title} roadmap: ${opts.said}`, + content: encode64(after), + branch, + sha: got.sha, + }); + const words = opts.words.length > 1000 ? `${opts.words.slice(0, 1000)}…` : opts.words; + const made = (await ops.gh(["-X", "POST", `repos/${repo}/pulls`], { + title: `${cap.title} roadmap: ${opts.said}`.slice(0, 200), + head: branch, + base: "main", + body: [ + `Asked for in the PM app, and made by the platform itself: ${opts.said}.`, + "", + `The owner's words: ${words}`, + "", + `Filed as #${opts.issue}. This pull request changes only \`${file}\`; merging it puts the change on the roadmap, and the roadmap pages read the file from main.`, + ].join("\n"), + })) as { number?: number; html_url?: string } | null; + if (typeof made?.html_url !== "string" || typeof made?.number !== "number") + throw new OpError(502, "the pull request could not be opened"); + return { url: made.html_url, number: made.number, branch, file }; +} diff --git a/pm-stack/console/test/roadmap-change.test.ts b/pm-stack/console/test/roadmap-change.test.ts new file mode 100644 index 0000000000..3e390bc288 --- /dev/null +++ b/pm-stack/console/test/roadmap-change.test.ts @@ -0,0 +1,238 @@ +// Roadmap changes made by the platform itself (#13497, second half). +// +// Oracles: GitHub is a recorder, so what is asked of it is compared +// exactly. The pull-request oracle is the acceptance test of the +// issue: across every call the path makes, the only file written is +// the roadmap file — one contents write, on the branch the pull +// request is opened from — so the generated diff touches only that +// file. The file edited is in the shape of the real files in +// planning/roadmaps/, and what an edit did is read back with the +// console's own parseRoadmap, not by re-implementing it here. +import { describe, expect, test } from "bun:test"; +import { readConfig } from "../src/config.ts"; +import { Ops, type Run } from "../src/ops.ts"; +import { CAPABILITIES, parseRoadmap, Plan } from "../src/plan.ts"; +import { applyRoadmapChange, openRoadmapChangePr, roadmapChangeRefusal } from "../src/roadmap-change.ts"; +import { Work } from "../src/work.ts"; + +const CFG = readConfig({ HOME: "/h" }); +const REPO = "developing-today/code"; +const START = Date.parse("2026-11-24T07:00:00Z"); +const FLEET = CAPABILITIES.find((c) => c.id === "fleet") as (typeof CAPABILITIES)[number]; +const FILE = "planning/roadmaps/fleet.md"; + +const SAMPLE = `# Roadmap: Fleet + +Written from the programme's epics. + +## Now + +| Title | Status | Intent | Links | +| --- | --- | --- | --- | +| Alpha item | in-progress | The first thing. | #101 | +| Beta item | planned | The second thing. | #102 | + +## Next + +| Title | Status | Intent | Links | +| --- | --- | --- | --- | +| Gamma item | planned | The third thing. | #103 | + +## Later + +| Title | Status | Intent | Links | +| --- | --- | --- | --- | +| Delta item | shaped | The fourth thing. | #104 | +`; + +const b64 = (s: string) => Buffer.from(s, "utf8").toString("base64"); +const unb64 = (s: string) => Buffer.from(s, "base64").toString("utf8"); + +interface Call { + method: string; + path: string; + body?: unknown; +} + +/** GitHub and the queue, standing in: every request kept, answered by + * `answer`. The clock is fixed, so a branch name is known exactly. */ +function world(answer: (c: Call) => unknown) { + const calls: Call[] = []; + const run: Run = async (argv, o) => { + if (argv[1] === "queue" && argv[2] === "enqueue") return { code: 0, stdout: "", stderr: "" }; + if (argv[1] !== "gh" || argv[2] !== "api") throw new Error(`unexpected command ${argv.join(" ")}`); + const rest = argv.slice(3).filter((a) => a !== "--input" && a !== "-"); + const at = rest.indexOf("-X"); + const method = at >= 0 ? rest[at + 1] : "GET"; + const path = rest.find((a) => a.startsWith("repos/") || a.startsWith("search/")) ?? ""; + const call: Call = { method, path, ...(o?.stdin ? { body: JSON.parse(o.stdin) } : {}) }; + calls.push(call); + return { code: 0, stdout: JSON.stringify(answer(call) ?? {}), stderr: "" }; + }; + const clock = () => new Date(START); + const ops = new Ops(CFG, run); + const work = new Work(ops, undefined, clock); + return { plan: new Plan(ops, work, clock), ops, calls }; +} + +/** The repository as the path meets it: the fleet roadmap on main, + * and a pull request that opens as #777. */ +const repoAnswer = (c: Call): unknown => { + if (c.method === "GET" && c.path === `repos/${REPO}/contents/${FILE}`) return { content: b64(SAMPLE), sha: "sha-file" }; + if (c.method === "GET" && c.path === `repos/${REPO}/git/ref/heads/main`) return { object: { sha: "sha-main" } }; + if (c.method === "POST" && c.path === `repos/${REPO}/pulls`) + return { number: 777, html_url: `https://github.com/${REPO}/pull/777` }; + if (c.method === "POST" && c.path === `repos/${REPO}/issues`) + return { number: 4242, html_url: `https://github.com/${REPO}/issues/4242`, title: (c.body as { title: string }).title }; + return {}; +}; + +describe("applyRoadmapChange", () => { + test("add puts a row in the section asked for, and touches nothing else", () => { + const out = applyRoadmapChange(SAMPLE, { + action: "add", + title: "Epsilon item", + to: "next", + intent: "The fifth thing.", + issue: 105, + }); + const rows = parseRoadmap(out); + expect(rows.find((r) => r.title === "Epsilon item")).toMatchObject({ + status: "planned", + intent: "The fifth thing.", + issues: [105], + phase: "next", + section: "Next", + }); + // Apart from the one inserted line, the file is byte for byte itself. + const added = out.split("\n").findIndex((l) => l.includes("Epsilon item")); + const lines = out.split("\n"); + lines.splice(added, 1); + expect(lines.join("\n")).toBe(SAMPLE); + }); + + test("move takes the row, word for word, to the other section", () => { + const out = applyRoadmapChange(SAMPLE, { action: "move", row: "Gamma item", to: "now" }); + expect(parseRoadmap(out).find((r) => r.title === "Gamma item")?.phase).toBe("now"); + expect(out.split("\n").length).toBe(SAMPLE.split("\n").length); + expect([...out.split("\n")].sort()).toEqual([...SAMPLE.split("\n")].sort()); + }); + + test("built marks the row shipped where it sits", () => { + const out = applyRoadmapChange(SAMPLE, { action: "built", row: "Alpha item" }); + expect(parseRoadmap(out).find((r) => r.title === "Alpha item")).toMatchObject({ status: "shipped", phase: "built" }); + }); + + test("drop removes the row and no other", () => { + const out = applyRoadmapChange(SAMPLE, { action: "drop", row: "Beta item" }); + expect(parseRoadmap(out).map((r) => r.title)).toEqual(["Alpha item", "Gamma item", "Delta item"]); + }); + + test("rewrite retitles the row in place", () => { + const out = applyRoadmapChange(SAMPLE, { action: "rewrite", row: "Delta item", title: "Delta item, renamed" }); + const rows = parseRoadmap(out); + expect(rows.map((r) => r.title)).toContain("Delta item, renamed"); + expect(rows.find((r) => r.title === "Delta item, renamed")?.phase).toBe("later"); + }); + + test("what cannot be made mechanically is refused, with the reason", () => { + expect(roadmapChangeRefusal({ action: "add-under", row: "Alpha item", title: "Sub" })).toContain("no row of its own"); + expect(roadmapChangeRefusal({ action: "rewrite", row: "Alpha item" })).toContain("retitle"); + expect(roadmapChangeRefusal({ action: "add", title: "Epsilon item" })).toBeNull(); + expect(() => applyRoadmapChange(SAMPLE, { action: "drop", row: "No such row" })).toThrow(/no roadmap row is titled/); + expect(() => applyRoadmapChange(SAMPLE, { action: "add", title: "X", to: "built" })).toThrow(/no Done section/); + }); +}); + +describe("openRoadmapChangePr", () => { + test("the pull request it opens touches only the roadmap file", async () => { + const w = world(repoAnswer); + const made = await openRoadmapChangePr( + w.ops, + REPO, + FLEET, + { action: "add", title: "Epsilon item", to: "next", intent: "The fifth thing.", issue: 105 }, + { said: 'add an item "Epsilon item"', words: "add epsilon please", issue: 4242, now: new Date(START) }, + ); + expect(made.url).toBe(`https://github.com/${REPO}/pull/777`); + expect(made.file).toBe(FILE); + // One branch, made from main's head. + const refs = w.calls.filter((c) => c.method === "POST" && c.path === `repos/${REPO}/git/refs`); + expect(refs.length).toBe(1); + expect(refs[0].body).toEqual({ ref: `refs/heads/${made.branch}`, sha: "sha-main" }); + // One write, to the roadmap file, on that branch, over main's copy. + const writes = w.calls.filter((c) => c.method === "PUT"); + expect(writes.length).toBe(1); + expect(writes[0].path).toBe(`repos/${REPO}/contents/${FILE}`); + const put = writes[0].body as { branch: string; sha: string; content: string; message: string }; + expect(put.branch).toBe(made.branch); + expect(put.sha).toBe("sha-file"); + // No other contents path is written, or even read, anywhere in the path. + expect(new Set(w.calls.filter((c) => c.path.includes("/contents/")).map((c) => c.path))).toEqual( + new Set([`repos/${REPO}/contents/${FILE}`]), + ); + // What was written is the file with the change in it. + const rows = parseRoadmap(unb64(put.content)); + expect(rows.find((r) => r.title === "Epsilon item")?.phase).toBe("next"); + // The pull request is from that branch to main, and says what it holds. + const pulls = w.calls.filter((c) => c.method === "POST" && c.path === `repos/${REPO}/pulls`); + expect(pulls.length).toBe(1); + const pr = pulls[0].body as { head: string; base: string; body: string }; + expect(pr.head).toBe(made.branch); + expect(pr.base).toBe("main"); + expect(pr.body).toContain("#4242"); + expect(pr.body).toContain(`changes only \`${FILE}\``); + }); + + test("a change the file refuses opens nothing", async () => { + const w = world(repoAnswer); + await expect( + openRoadmapChangePr( + w.ops, + REPO, + FLEET, + { action: "drop", row: "No such row" }, + { said: "drop", words: "x", issue: 1, now: new Date(START) }, + ), + ).rejects.toThrow(/no roadmap row is titled/); + expect(w.calls.filter((c) => c.method !== "GET")).toEqual([]); + }); +}); + +describe("Plan.intake: a change asked for in the app", () => { + test("is filed as an issue, and made as a pull request against the roadmap file", async () => { + const w = world(repoAnswer); + const got = await w.plan.intake({ + kind: "change", + area: "fleet", + text: "add epsilon please", + change: { action: "add", to: "next", title: "Epsilon item" }, + }); + expect(got.issue).toBe(4242); + expect(got.queued).toBe(true); + expect(got.pr).toBe(`https://github.com/${REPO}/pull/777`); + // The issue hears about the pull request. + const comment = w.calls.find((c) => c.method === "POST" && c.path === `repos/${REPO}/issues/4242/comments`); + expect((comment?.body as { body: string }).body).toContain(`https://github.com/${REPO}/pull/777`); + // And the only file written on the way is the roadmap file. + const writes = w.calls.filter((c) => c.method === "PUT"); + expect(writes.map((c) => c.path)).toEqual([`repos/${REPO}/contents/${FILE}`]); + }); + + test("a change that cannot be made mechanically is still filed, and the answer says why not", async () => { + const w = world(repoAnswer); + const got = await w.plan.intake({ + kind: "change", + area: "fleet", + text: "drop the imaginary one", + about: { row: "No such row" }, + change: { action: "drop" }, + }); + expect(got.issue).toBe(4242); + expect(got.queued).toBe(true); + expect(got.pr).toBeUndefined(); + expect(got.note).toContain("not made as a pull request"); + expect(got.note).toContain("no roadmap row is titled"); + expect(w.calls.filter((c) => c.method === "PUT")).toEqual([]); + }); +});