Public: anyone can read this; the crew can change it.
Plans need a nod: with the setting on, POST …/plan stores one wave proposal and opens no issues #1749
scout/forge:scout/1621-plans-need-a-nod-with-the-setting-on-pos → main 8 commits fork 4 threads · 4 unresolved
17 files
changed +381
−7
README.md +8
| @@ -423,6 +423,14 @@ model, a brief in its own voice and a spend budget; a repository admin puts it | ||
| 423 | 423 | on the repository's **crew**, which is the one grant an agent can hold — it |
| 424 | 424 | reads and writes that repository and administers nothing. |
| 425 | 425 | |
| 426 | **Plans need a nod** (repository settings, or `PATCH …/repos/o/r` with | |
| 427 | `{"plansNeedNod": true}`; off by default): with it on, `POST …/plan` validates | |
| 428 | the wave as always but stores it whole as one proposal and opens no issues, | |
| 429 | answering `{"proposed": true, "proposal": id}`; the planner's brief tells it the | |
| 430 | wave then waits for the owner. The forge's own triage still opens issues. Left | |
| 431 | out for now: reading, approving and discarding a stored proposal — that lands | |
| 432 | with the proposals inbox, and the default turns on with it. | |
| 433 | ||
| 426 | 434 | Assign an issue to an agent and it starts: the forge clones the repository, |
| 427 | 435 | puts the agent on a branch named after the issue, and runs Claude Code |
| 428 | 436 | headless with a brief that says who it is, what the task is, how to finish, |
scripts/gate.ts +1
| @@ -35,6 +35,7 @@ export const GATE: readonly string[] = [ | ||
| 35 | 35 | "test/apps-idle.test.ts", |
| 36 | 36 | "test/body-limits.test.ts", |
| 37 | 37 | "test/boards-query.test.ts", |
| 38 | "test/plan-nod.test.ts", | |
| 38 | 39 | "test/boards-page.test.ts", |
| 39 | 40 | "test/turnstile.test.ts", |
| 40 | 41 | "test/variants-deck.test.ts", |
src/actions/plan.ts +54 −1
| @@ -25,6 +25,7 @@ import { | ||
| 25 | 25 | import { canRead, canWrite, type Repo } from "../core/repos.ts"; |
| 26 | 26 | import type { User } from "../core/users.ts"; |
| 27 | 27 | import { transact } from "../kernel/db.ts"; |
| 28 | import { storeProposal } from "../core/proposals.ts"; | |
| 28 | 29 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 29 | 30 | import { isMirror } from "../origins/write-through.ts"; |
| 30 | 31 | import { followLink } from "./pillars.ts"; |
| @@ -186,12 +187,49 @@ function loopAt(items: readonly PlanItem[]): string | undefined { | ||
| 186 | 187 | return undefined; |
| 187 | 188 | } |
| 188 | 189 | |
| 190 | /** A plan held for a nod: stored whole, no issue opened. */ | |
| 191 | export interface Proposed { | |
| 192 | readonly proposed: true; | |
| 193 | readonly proposal: string; | |
| 194 | } | |
| 195 | ||
| 196 | /** What the sender may say about a plan: a title and a one-line why. */ | |
| 197 | export interface PlanPitch { | |
| 198 | readonly title?: unknown; | |
| 199 | readonly why?: unknown; | |
| 200 | } | |
| 201 | ||
| 202 | function pitchOf( | |
| 203 | items: readonly PlanItem[], | |
| 204 | pitch: PlanPitch, | |
| 205 | ): Result<{ title: string; why: string }, PlanError> { | |
| 206 | const text = (v: unknown) => (typeof v === "string" ? v : undefined); | |
| 207 | if ( | |
| 208 | (pitch.title !== undefined && text(pitch.title) === undefined) || | |
| 209 | (pitch.why !== undefined && text(pitch.why) === undefined) | |
| 210 | ) | |
| 211 | return refuse("invalid", "title and why must be text"); | |
| 212 | const why = (text(pitch.why) ?? "").trim().replace(/\s+/g, " "); | |
| 213 | if (why.length > WHY_MAX) | |
| 214 | return refuse( | |
| 215 | "why_too_long", | |
| 216 | `why is one sentence, at most ${WHY_MAX} characters`, | |
| 217 | ); | |
| 218 | const title = (text(pitch.title) ?? "").trim().replace(/\s+/g, " "); | |
| 219 | if (title.length > MAX_TITLE) | |
| 220 | return refuse("title_too_long", `title is over ${MAX_TITLE} characters`); | |
| 221 | return ok({ title: title || items[0]!.title, why }); | |
| 222 | } | |
| 223 | ||
| 189 | 224 | export function openPlan( |
| 190 | 225 | app: App, |
| 191 | 226 | actor: User | undefined, |
| 192 | 227 | repo: Repo, |
| 193 | 228 | items: readonly PlanItem[], |
| 194 | ): Result<Planned, PlanError> { | |
| 229 | pitch: PlanPitch = {}, | |
| 230 | /** False for the forge's own triage, which places a thought as an issue without a nod. */ | |
| 231 | holdForNod = true, | |
| 232 | ): Result<Planned | Proposed, PlanError> { | |
| 195 | 233 | if (!actor || !canRead(app.db, repo, actor)) |
| 196 | 234 | return refuse("not_found", "no such app or repository (owner/name)"); |
| 197 | 235 | if (!canWrite(app.db, repo, actor) && !isCrew(app.db, repo.id, actor.id)) |
| @@ -259,6 +297,21 @@ export function openPlan( | ||
| 259 | 297 | ); |
| 260 | 298 | } |
| 261 | 299 | |
| 300 | // With "plans need a nod" on, the plan is good and is kept as it is: one | |
| 301 | // proposal, for a person to approve. No issue exists until then. | |
| 302 | if (holdForNod && repo.plansNeedNod) { | |
| 303 | const said = pitchOf(items, pitch); | |
| 304 | if (!said.ok) return err(said.error); | |
| 305 | const proposal = storeProposal(app.db, { | |
| 306 | repoId: repo.id, | |
| 307 | authorId: actor.id, | |
| 308 | title: said.value.title, | |
| 309 | why: said.value.why, | |
| 310 | items, | |
| 311 | }); | |
| 312 | return ok({ proposed: true, proposal }); | |
| 313 | } | |
| 314 | ||
| 262 | 315 | const opened: { key: string; number: number }[] = []; |
| 263 | 316 | /** The links an item's purpose adds: [the issue that waits, what it waits for]. */ |
| 264 | 317 | const purpose: [Issue, Issue][] = []; |
src/actions/repos.ts +1
| @@ -275,6 +275,7 @@ export async function updateRepoSettings( | ||
| 275 | 275 | "requireReview", |
| 276 | 276 | "requireChecks", |
| 277 | 277 | "crewOutsiders", |
| 278 | "plansNeedNod", | |
| 278 | 279 | "decisionsBy", |
| 279 | 280 | ] as const |
| 280 | 281 | ).filter((k) => settings[k] !== undefined && settings[k] !== repo[k]); |
src/core/proposals.ts added +74
| @@ -0,0 +1,74 @@ | ||
| 1 | /** | |
| 2 | * A plan held for a nod: the validated wave kept as one row, with a title, | |
| 3 | * a one-line why, its issues in order and their blockedBy links. Plain data | |
| 4 | * in, plain data out; opening the issues is a later step. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { Database } from "bun:sqlite"; | |
| 8 | import { id } from "../kernel/id.ts"; | |
| 9 | ||
| 10 | export interface ProposedItem { | |
| 11 | readonly key: string; | |
| 12 | readonly title: string; | |
| 13 | readonly body: string; | |
| 14 | readonly blockedBy: readonly (string | number)[]; | |
| 15 | readonly pillar?: string; | |
| 16 | readonly later?: string; | |
| 17 | } | |
| 18 | ||
| 19 | export interface Proposal { | |
| 20 | readonly id: string; | |
| 21 | readonly repoId: string; | |
| 22 | readonly authorId: string; | |
| 23 | readonly title: string; | |
| 24 | readonly why: string; | |
| 25 | readonly items: readonly ProposedItem[]; | |
| 26 | readonly createdAt: string; | |
| 27 | } | |
| 28 | ||
| 29 | export function storeProposal( | |
| 30 | db: Database, | |
| 31 | p: Omit<Proposal, "id" | "createdAt">, | |
| 32 | ): string { | |
| 33 | const newId = id(); | |
| 34 | db.query( | |
| 35 | `INSERT INTO plan_proposal (id, repo_id, author_id, title, why, items, created_at) | |
| 36 | VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)`, | |
| 37 | ).run( | |
| 38 | newId, | |
| 39 | p.repoId, | |
| 40 | p.authorId, | |
| 41 | p.title, | |
| 42 | p.why, | |
| 43 | JSON.stringify(p.items), | |
| 44 | new Date().toISOString(), | |
| 45 | ); | |
| 46 | return newId; | |
| 47 | } | |
| 48 | ||
| 49 | interface Row { | |
| 50 | id: string; | |
| 51 | repo_id: string; | |
| 52 | author_id: string; | |
| 53 | title: string; | |
| 54 | why: string; | |
| 55 | items: string; | |
| 56 | created_at: string; | |
| 57 | } | |
| 58 | ||
| 59 | export function proposalsOf(db: Database, repoId: string): Proposal[] { | |
| 60 | return db | |
| 61 | .query<Row, [string]>( | |
| 62 | "SELECT * FROM plan_proposal WHERE repo_id = ?1 ORDER BY created_at, id", | |
| 63 | ) | |
| 64 | .all(repoId) | |
| 65 | .map((r) => ({ | |
| 66 | id: r.id, | |
| 67 | repoId: r.repo_id, | |
| 68 | authorId: r.author_id, | |
| 69 | title: r.title, | |
| 70 | why: r.why, | |
| 71 | items: JSON.parse(r.items) as ProposedItem[], | |
| 72 | createdAt: r.created_at, | |
| 73 | })); | |
| 74 | } |
src/core/repos.ts +13 −1
| @@ -116,6 +116,12 @@ export interface Repo { | ||
| 116 | 116 | * default; on a public repository it hands strangers the owner's budget. |
| 117 | 117 | */ |
| 118 | 118 | readonly crewOutsiders: boolean; |
| 119 | /** | |
| 120 | * "Plans need a nod": a plan sent to `…/plan` is stored as one proposal | |
| 121 | * (`core/proposals.ts`) for a person to approve, and opens no issues. | |
| 122 | * On by default. | |
| 123 | */ | |
| 124 | readonly plansNeedNod: boolean; | |
| 119 | 125 | /** The standing rule for decisions here: `me`, `decider`, or `decider_tell`. */ |
| 120 | 126 | readonly decisionsBy: DecisionsBy; |
| 121 | 127 | /** The issue the planner is given, when the map has run dry. */ |
| @@ -162,6 +168,7 @@ interface RepoRow { | ||
| 162 | 168 | autonomy_slots: number; |
| 163 | 169 | autonomy_by: string | null; |
| 164 | 170 | crew_outsiders: number; |
| 171 | plans_need_nod: number; | |
| 165 | 172 | decisions_by: string; |
| 166 | 173 | direction_issue_id: string | null; |
| 167 | 174 | fork_parent_id: string | null; |
| @@ -200,6 +207,7 @@ function toRepo(row: RepoRow): Repo { | ||
| 200 | 207 | autonomySlots: row.autonomy_slots, |
| 201 | 208 | autonomyBy: row.autonomy_by, |
| 202 | 209 | crewOutsiders: row.crew_outsiders === 1, |
| 210 | plansNeedNod: row.plans_need_nod === 1, | |
| 203 | 211 | decisionsBy: isDecisionsBy(row.decisions_by) ? row.decisions_by : "me", |
| 204 | 212 | directionIssueId: row.direction_issue_id, |
| 205 | 213 | forkParentId: row.fork_parent_id, |
| @@ -1035,6 +1043,8 @@ export interface RepoSettings { | ||
| 1035 | 1043 | autonomyBy?: string | null; |
| 1036 | 1044 | /** Whether someone who cannot write here may start or steer a run. */ |
| 1037 | 1045 | crewOutsiders?: boolean; |
| 1046 | /** Whether a plan is stored as a proposal instead of opening issues. */ | |
| 1047 | plansNeedNod?: boolean; | |
| 1038 | 1048 | decisionsBy?: DecisionsBy; |
| 1039 | 1049 | } |
| 1040 | 1050 | |
| @@ -1048,7 +1058,8 @@ export function updateRepoSettings( | ||
| 1048 | 1058 | `UPDATE repo SET visibility = ?1, description = ?2, protect_default = ?3, |
| 1049 | 1059 | default_branch = ?4, require_review = ?5, require_checks = ?7, |
| 1050 | 1060 | autonomy = ?8, autonomy_direction = ?9, autonomy_ceiling_usd = ?10, |
| 1051 | autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13, decisions_by = ?14 | |
| 1061 | autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13, decisions_by = ?14, | |
| 1062 | plans_need_nod = ?15 | |
| 1052 | 1063 | WHERE id = ?6`, |
| 1053 | 1064 | ).run( |
| 1054 | 1065 | settings.visibility ?? repo.visibility, |
| @@ -1065,6 +1076,7 @@ export function updateRepoSettings( | ||
| 1065 | 1076 | settings.autonomyBy === undefined ? repo.autonomyBy : settings.autonomyBy, |
| 1066 | 1077 | (settings.crewOutsiders ?? repo.crewOutsiders) ? 1 : 0, |
| 1067 | 1078 | settings.decisionsBy ?? repo.decisionsBy, |
| 1079 | (settings.plansNeedNod ?? repo.plansNeedNod) ? 1 : 0, | |
| 1068 | 1080 | ); |
| 1069 | 1081 | return getRepoById(db, repo.id)!; |
| 1070 | 1082 | } |
src/core/schema.ts +17
| @@ -1741,6 +1741,23 @@ export const migrations: readonly string[] = [ | ||
| 1741 | 1741 | ALTER TABLE repo ADD COLUMN decisions_by TEXT NOT NULL DEFAULT 'me' |
| 1742 | 1742 | CHECK (decisions_by IN ('me', 'decider', 'decider_tell')); |
outdated
High: |
||
| 1743 | 1743 | `, |
| 1744 | // 86 — plans need a nod (#1621): with the setting on, a plan is stored as | |
| 1745 | // one proposal for a person to approve, and opens no issues. It is off by | |
| 1746 | // default until a person can read and approve a proposal. | |
| 1747 | // `items` is the validated plan as JSON; the proposal is plain data. | |
| 1748 | ` | |
| 1749 | ALTER TABLE repo ADD COLUMN plans_need_nod INTEGER NOT NULL DEFAULT 0; | |
| 1750 | CREATE TABLE plan_proposal ( | |
| 1751 | id TEXT PRIMARY KEY, | |
| 1752 | repo_id TEXT NOT NULL REFERENCES repo(id) ON DELETE CASCADE, | |
| 1753 | author_id TEXT NOT NULL, | |
| 1754 | title TEXT NOT NULL, | |
| 1755 | why TEXT NOT NULL, | |
| 1756 | items TEXT NOT NULL, | |
| 1757 | created_at TEXT NOT NULL | |
| 1758 | ); | |
| 1759 | CREATE INDEX plan_proposal_repo ON plan_proposal(repo_id, created_at); | |
| 1760 | `, | |
| 1744 | 1761 | ]; |
| 1745 | 1762 | |
| 1746 | 1763 | /** |
src/crew/brief.ts +1
| @@ -108,6 +108,7 @@ export function systemPrompt(input: BriefInput): string { | ||
| 108 | 108 | "- A worked example:", |
| 109 | 109 | ` curl -sS -X POST -H "authorization: Bearer $FORGE_TOKEN" -H "content-type: application/json" "$FORGE_URL/api/v1/repos/${repo.ownerName}/${repo.name}/plan" -d '{"issues":[{"key":"a","title":"Refuse an unsigned upload","body":"Done: an unsigned upload is a 422.","pillar":"P0"},{"key":"b","title":"Show the upload in the feed","body":"Done: it is listed.","blockedBy":["a"],"pillar":"P1"},{"key":"c","title":"Offer a dark theme","later":true,"why":"No pillar needs it until the feed lands."}]}'`, |
| 110 | 110 | " It answers with what it opened (key and number), the numbers now ready, and those deferred.", |
| 111 | ' Where the owner asks for a nod, it answers {"proposed": true, "proposal": id} instead: the wave is stored whole and waits for the owner, and no issue exists yet. Do not post it again, do not open the issues one by one, and do not report issues that were not opened; say that the wave waits for the owner\'s nod.', | |
| 111 | 112 | "- The direction is never finished. When what it names is built, propose its next increment in the same spirit: what a demanding user would want next, what is fragile, slow, ugly, untested or undocumented, what the pictures and the previews show is off. Leave the map with at least three ready issues, every time.", |
| 112 | 113 | '- An issue with a comment that starts "Parked by the crew" was tried and could not be finished as written. Split it into smaller issues, or rewrite what done looks like, or close it with a word if the direction no longer needs it — never leave it as it was. One the crew parked twice is yours: your task lists it, with what you may do with it.', |
| 113 | 114 | "- Assign nobody and push nothing: the map is the result. The direction issue stays open.", |
src/crew/triage.ts +3 −3
| @@ -229,8 +229,8 @@ export async function placeThought( | ||
| 229 | 229 | blockedBy: [], |
| 230 | 230 | ...(pillar ? { pillar } : {}), |
| 231 | 231 | }, |
| 232 | ]); | |
| 233 | if (opened.ok) { | |
| 232 | ], {}, false); | |
| 233 | if (opened.ok && "opened" in opened.value) { | |
| 234 | 234 | const number = opened.value.opened[0]!.number; |
| 235 | 235 | placed.push({ action: "opened", repo: slug, number, ...(pillar ? { pillar } : {}) }); |
| 236 | 236 | const name = set.pillars.find((p) => p.short === pillar)?.name; |
| @@ -238,7 +238,7 @@ export async function placeThought( | ||
| 238 | 238 | } else if (direction) { |
| 239 | 239 | comment(direction, "A thought that could not be opened as an issue:"); |
| 240 | 240 | placed.push({ action: "amended", repo: slug, number: direction.number }); |
| 241 | say.push(`Could not open it as an issue (${opened.error.message}); kept on #${direction.number}.`); | |
| 241 | say.push(`Could not open it as an issue (${opened.ok ? "held for a nod" : opened.error.message}); kept on #${direction.number}.`); | |
| 242 | 242 | } |
| 243 | 243 | } else if (kind === "amendment" && target) { |
| 244 | 244 | const issue = here(target.number); |
src/http/api.ts +7 −1
| @@ -1763,6 +1763,9 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 1763 | 1763 | ...(typeof input.crewOutsiders === "boolean" |
| 1764 | 1764 | ? { crewOutsiders: input.crewOutsiders } |
| 1765 | 1765 | : {}), |
| 1766 | ...(typeof input.plansNeedNod === "boolean" | |
| 1767 | ? { plansNeedNod: input.plansNeedNod } | |
| 1768 | : {}), | |
| 1766 | 1769 | // The standing rule for its decisions: also an admin's, never an agent's. |
| 1767 | 1770 | ...(isDecisionsBy(input.decisionsBy) |
| 1768 | 1771 | ? { decisionsBy: input.decisionsBy } |
| @@ -2531,7 +2534,10 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 2531 | 2534 | const items = parsePlan(input.issues); |
| 2532 | 2535 | if (!items.ok) |
| 2533 | 2536 | return apiError(items.error.error, 422, items.error.message); |
| 2534 | const planned = openPlan(ctx.app, ctx.auth.user, repo, items.value); | |
| 2537 | const planned = openPlan(ctx.app, ctx.auth.user, repo, items.value, { | |
| 2538 | title: input.title, | |
| 2539 | why: input.why, | |
| 2540 | }); | |
| 2535 | 2541 | if (!planned.ok) { |
| 2536 | 2542 | const { error, message } = planned.error; |
| 2537 | 2543 | return apiError( |
src/http/mcp.ts +19 −1
| @@ -1859,6 +1859,15 @@ const TOOLS: readonly Tool[] = [ | ||
| 1859 | 1859 | type: "object", |
| 1860 | 1860 | properties: { |
| 1861 | 1861 | app: APP_ARG, |
| 1862 | title: { | |
| 1863 | type: "string", | |
| 1864 | description: | |
| 1865 | "With plans-need-a-nod on: the proposal's title (defaults to the first issue's).", | |
| 1866 | }, | |
| 1867 | why: { | |
| 1868 | type: "string", | |
| 1869 | description: "With plans-need-a-nod on: one line saying why this wave.", | |
| 1870 | }, | |
| 1862 | 1871 | issues: { |
| 1863 | 1872 | type: "array", |
| 1864 | 1873 | minItems: 1, |
| @@ -1905,8 +1914,17 @@ const TOOLS: readonly Tool[] = [ | ||
| 1905 | 1914 | if (isAnswer(repo)) return repo; |
| 1906 | 1915 | const items = parsePlan(args["issues"]); |
| 1907 | 1916 | if (!items.ok) return bad(items.error.error, items.error.message); |
| 1908 | const planned = openPlan(ctx.app, user, repo, items.value); | |
| 1917 | const planned = openPlan(ctx.app, user, repo, items.value, { | |
| 1918 | title: args["title"], | |
| 1919 | why: args["why"], | |
| 1920 | }); | |
| 1909 | 1921 | if (!planned.ok) return bad(planned.error.error, planned.error.message); |
| 1922 | if ("proposed" in planned.value) | |
| 1923 | return good({ | |
| 1924 | says: `Proposed ${items.value.length} issue${items.value.length === 1 ? "" : "s"} as proposal ${planned.value.proposal}; nothing is opened until a person nods.`, | |
| 1925 | proposed: true, | |
| 1926 | proposal: planned.value.proposal, | |
| 1927 | }); | |
| 1910 | 1928 | const { opened, ready, later, gate } = planned.value; |
| 1911 | 1929 | const waits = |
| 1912 | 1930 | gate === undefined |
src/web/pages/settings.ts +17
| @@ -284,6 +284,20 @@ export async function settingsPage(ctx: Ctx): Promise<Response> { | ||
| 284 | 284 | > |
| 285 | 285 | </label> |
| 286 | 286 | </div> |
| 287 | <div class="field"> | |
| 288 | <input type="hidden" name="plansNeedNodShown" value="1" /> | |
| 289 | <label class="check"> | |
| 290 | <input | |
| 291 | type="checkbox" | |
| 292 | name="plansNeedNod" | |
| 293 | ${repo.plansNeedNod ? html`checked` : null} | |
| 294 | /> | |
| 295 | <span | |
| 296 | >Plans need a nod — a plan sent to this repository is kept as one | |
| 297 | proposal for you to approve, and opens no issues until then.</span | |
| 298 | > | |
| 299 | </label> | |
| 300 | </div> | |
| 287 | 301 | <div class="field"> |
| 288 | 302 | <input type="hidden" name="crewOutsidersShown" value="1" /> |
| 289 | 303 | <label class="check"> |
| @@ -349,6 +363,9 @@ export async function settingsUpdate(ctx: Ctx): Promise<Response> { | ||
| 349 | 363 | ...(form.get("crewOutsidersShown") !== null |
| 350 | 364 | ? { crewOutsiders: form.get("crewOutsiders") !== null } |
| 351 | 365 | : {}), |
| 366 | ...(form.get("plansNeedNodShown") !== null | |
This form branch has no test. Add one that posts the settings form with and without |
||
| 367 | ? { plansNeedNod: form.get("plansNeedNod") !== null } | |
| 368 | : {}), | |
| 352 | 369 | ...(branch !== "" ? { defaultBranch: branch } : {}), |
| 353 | 370 | }; |
| 354 | 371 | const updated = await updateRepoSettings( |
test/mcp.test.ts +20
| @@ -93,6 +93,8 @@ describe("the forge over MCP", () => { | ||
| 93 | 93 | }); |
| 94 | 94 | if (!made.ok) throw new Error(String(made.error)); |
| 95 | 95 | game = made.value; |
| 96 | // The plan tests below open issues; the nod has its own test (plan-nod.test.ts). | |
| 97 | app.db.run("UPDATE repo SET plans_need_nod = 0 WHERE id = ?1", [game.id]); | |
| 96 | 98 | await commitToBranch(app, alice, game, { |
| 97 | 99 | message: "seed", |
| 98 | 100 | files: [{ path: "README.md", content: "# game\n" }], |
| @@ -566,6 +568,24 @@ describe("the forge over MCP", () => { | ||
| 566 | 568 | ).toContain("forbidden"); |
| 567 | 569 | }); |
| 568 | 570 | |
| 571 | test("plan with the nod on proposes and opens nothing", async () => { | |
| 572 | app.db.run("UPDATE repo SET plans_need_nod = 1 WHERE id = ?1", [game.id]); | |
| 573 | try { | |
| 574 | const count = async () => | |
| 575 | (await tool(ro, "map", { app: "alice/game" })).value.issues.length; | |
| 576 | const before = await count(); | |
| 577 | const res = await tool(rw, "plan", { | |
| 578 | app: "alice/game", | |
| 579 | issues: [{ key: "a", title: "Only proposed" }], | |
| 580 | }); | |
| 581 | expect(res.value.proposed).toBe(true); | |
| 582 | expect(typeof res.value.proposal).toBe("string"); | |
| 583 | expect(await count()).toBe(before); | |
| 584 | } finally { | |
| 585 | app.db.run("UPDATE repo SET plans_need_nod = 0 WHERE id = ?1", [game.id]); | |
| 586 | } | |
| 587 | }); | |
| 588 | ||
| 569 | 589 | test("a browser session is not a way in, even signed in", async () => { |
| 570 | 590 | const signin = await fetch(`${base}/signin`, { |
| 571 | 591 | method: "POST", |
test/pillars.test.ts +2
| @@ -170,6 +170,8 @@ describe("pillars", () => { | ||
| 170 | 170 | }); |
| 171 | 171 | if (!made.ok) throw new Error(String(made.error)); |
| 172 | 172 | repo = made.value; |
| 173 | // These tests open issues through plan; the nod has plan-nod.test.ts. | |
| 174 | app.db.run("UPDATE repo SET plans_need_nod = 0 WHERE id = ?1", [repo.id]); | |
| 173 | 175 | const seeded = await commitToBranch(app, alice, repo, { |
| 174 | 176 | message: "Start", |
| 175 | 177 | files: [{ path: "README.md", content: "# engine\n" }], |
test/plan-nod.test.ts added +139
| @@ -0,0 +1,139 @@ | ||
| 1 | /** | |
| 2 | * Invariant: with "plans need a nod" on (opt-in), `POST …/plan` stores a | |
| 3 | * valid plan as one proposal and opens no issue; off, it opens issues as | |
| 4 | * before; an invalid plan is refused either way. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { openIssue } from "../src/actions/issues.ts"; | |
| 12 | import { createRepo } from "../src/actions/repos.ts"; | |
| 13 | import { listIssues } from "../src/core/issues.ts"; | |
| 14 | import { proposalsOf } from "../src/core/proposals.ts"; | |
| 15 | import { getRepoById, updateRepoSettings, type Repo } from "../src/core/repos.ts"; | |
| 16 | import { createToken } from "../src/core/tokens.ts"; | |
| 17 | import { createUser, type User } from "../src/core/users.ts"; | |
| 18 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 19 | ||
| 20 | describe("plans need a nod", () => { | |
| 21 | let dataDir = ""; | |
| 22 | let app: App; | |
| 23 | let servers: Servers; | |
| 24 | let alice: User; | |
| 25 | let repo: Repo; | |
| 26 | let rw = ""; | |
| 27 | let cookie = ""; | |
| 28 | ||
| 29 | const count = () => listIssues(app.db, repo.id, {}).length; | |
| 30 | const post = (body: unknown) => | |
| 31 | fetch(`${servers.url}/api/v1/repos/alice/nod/plan`, { | |
| 32 | method: "POST", | |
| 33 | headers: { authorization: `Bearer ${rw}`, "content-type": "application/json" }, | |
| 34 | body: JSON.stringify(body), | |
| 35 | }); | |
| 36 | const wave = [ | |
| 37 | { key: "a", title: "Water the beds", pillar: "P0" }, | |
| 38 | { key: "b", title: "Buy a hose", pillar: "P0", blockedBy: ["a"] }, | |
| 39 | ]; | |
| 40 | ||
| 41 | beforeAll(async () => { | |
| 42 | dataDir = await mkdtemp(join(tmpdir(), "forge-plannod-")); | |
| 43 | app = createApp({ dataDir, port: 0 }); | |
| 44 | servers = await serve(app); | |
| 45 | const a = await createUser(app.db, { | |
| 46 | trusted: true, | |
| 47 | username: "alice", | |
| 48 | email: "[email protected]", | |
| 49 | password: "a-good-passphrase", | |
| 50 | adminIfFirst: true, | |
| 51 | }); | |
| 52 | if (!a.ok) throw new Error(a.error); | |
| 53 | alice = a.value; | |
| 54 | const signin = await fetch(`${servers.url}/signin`, { | |
| 55 | method: "POST", | |
| 56 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 57 | redirect: "manual", | |
| 58 | }); | |
| 59 | cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 60 | rw = createToken(app.db, alice.id, "rw", "rw").token; | |
| 61 | const made = await createRepo(app, alice, { name: "nod", visibility: "private" }); | |
| 62 | if (!made.ok) throw new Error(String(made.error)); | |
| 63 | repo = made.value; | |
| 64 | const u = openIssue(app, alice, repo, { title: "P0 Trust: be trusted", body: "" }); | |
| 65 | if (!u.ok) throw new Error(String(u.error)); | |
| 66 | }); | |
| 67 | ||
| 68 | afterAll(async () => { | |
| 69 | servers.stop(); | |
| 70 | app.close(); | |
| 71 | await rm(dataDir, { recursive: true, force: true }); | |
| 72 | }); | |
| 73 | ||
| 74 | test("the setting is off by default, and the API turns it on", async () => { | |
| 75 | expect(repo.plansNeedNod).toBe(false); | |
| 76 | const res = await fetch(`${servers.url}/api/v1/repos/alice/nod`, { | |
| 77 | method: "PATCH", | |
| 78 | headers: { | |
| 79 | authorization: `Bearer ${createToken(app.db, alice.id, "admin", "admin").token}`, | |
| 80 | "content-type": "application/json", | |
| 81 | }, | |
| 82 | body: JSON.stringify({ plansNeedNod: true }), | |
| 83 | }); | |
| 84 | expect(res.status).toBe(200); | |
| 85 | expect(getRepoById(app.db, repo.id)!.plansNeedNod).toBe(true); | |
| 86 | }); | |
| 87 | ||
| 88 | test("the settings form turns it off and on, and a form without it leaves it", async () => { | |
| 89 | const send = (fields: Record<string, string>) => | |
| 90 | fetch(`${servers.url}/alice/nod/settings`, { | |
| 91 | method: "POST", | |
| 92 | headers: { cookie, origin: servers.url }, | |
| 93 | body: new URLSearchParams({ card: "gates", ...fields }), | |
| 94 | redirect: "manual", | |
| 95 | }); | |
| 96 | const now = () => getRepoById(app.db, repo.id)!.plansNeedNod; | |
| 97 | await send({ plansNeedNodShown: "1" }); | |
| 98 | expect(now()).toBe(false); | |
| 99 | await send({ plansNeedNodShown: "1", plansNeedNod: "on" }); | |
| 100 | expect(now()).toBe(true); | |
| 101 | await send({}); | |
| 102 | expect(now()).toBe(true); | |
| 103 | }); | |
| 104 | ||
| 105 | test("on: the plan is stored as one proposal and opens no issues", async () => { | |
| 106 | const before = count(); | |
| 107 | const res = await post({ title: "Garden wave", why: " Beds first,\n then hose. ", issues: wave }); | |
| 108 | expect(res.status).toBe(201); | |
| 109 | const body = (await res.json()) as { proposed: boolean; proposal: string }; | |
| 110 | expect(body.proposed).toBe(true); | |
| 111 | expect(count()).toBe(before); | |
| 112 | const stored = proposalsOf(app.db, repo.id); | |
| 113 | expect(stored.length).toBe(1); | |
| 114 | expect(stored[0]!.id).toBe(body.proposal); | |
| 115 | expect(stored[0]!.title).toBe("Garden wave"); | |
| 116 | expect(stored[0]!.why).toBe("Beds first, then hose."); | |
| 117 | expect(stored[0]!.items.map((i) => i.key)).toEqual(["a", "b"]); | |
| 118 | expect(stored[0]!.items[1]!.blockedBy).toEqual(["a"]); | |
| 119 | }); | |
| 120 | ||
| 121 | test("on: an invalid plan is still refused with no_pillar, and stores nothing", async () => { | |
| 122 | const res = await post({ issues: [{ key: "a", title: "No pillar" }] }); | |
| 123 | expect(res.status).toBe(422); | |
| 124 | expect(((await res.json()) as { error: string }).error).toBe("no_pillar"); | |
| 125 | expect(proposalsOf(app.db, repo.id).length).toBe(1); | |
| 126 | }); | |
| 127 | ||
| 128 | test("off: the plan opens issues as before and stores no proposal", async () => { | |
| 129 | await updateRepoSettings(app.db, getRepoById(app.db, repo.id)!, { plansNeedNod: false }); | |
| 130 | const before = count(); | |
| 131 | const res = await post({ issues: wave }); | |
| 132 | expect(res.status).toBe(201); | |
| 133 | const body = (await res.json()) as { opened: unknown[]; proposed?: boolean }; | |
| 134 | expect(body.opened.length).toBe(2); | |
| 135 | expect(body.proposed).toBeUndefined(); | |
| 136 | expect(count()).toBe(before + 2); | |
| 137 | expect(proposalsOf(app.db, repo.id).length).toBe(1); | |
| 138 | }); | |
| 139 | }); |
test/plan-pillars.test.ts +3
| @@ -81,6 +81,8 @@ describe("a plan says what each issue is for", () => { | ||
| 81 | 81 | const repo = async (name: string): Promise<Repo> => { |
| 82 | 82 | const made = await createRepo(app, alice, { name, visibility: "private" }); |
| 83 | 83 | if (!made.ok) throw new Error(String(made.error)); |
| 84 | // These tests open issues; the nod has its own (plan-nod.test.ts). | |
| 85 | app.db.run("UPDATE repo SET plans_need_nod = 0 WHERE id = ?1", [made.value.id]); | |
| 84 | 86 | return made.value; |
| 85 | 87 | }; |
| 86 | 88 | |
| @@ -405,6 +407,7 @@ describe("whose issue stands for a pillar", () => { | ||
| 405 | 407 | }); |
| 406 | 408 | if (!made.ok) throw new Error(String(made.error)); |
| 407 | 409 | open = made.value; |
| 410 | app.db.run("UPDATE repo SET plans_need_nod = 0 WHERE id = ?1", [open.id]); | |
| 408 | 411 | }, 30_000); |
| 409 | 412 | |
| 410 | 413 | afterAll(async () => { |
test/plan-route.test.ts +2
| @@ -50,6 +50,8 @@ describe("POST …/plan", () => { | ||
| 50 | 50 | const created = await createRepo(app, alice, { name: "garden", visibility: "private" }); |
| 51 | 51 | if (!created.ok) throw new Error(String(created.error)); |
| 52 | 52 | repo = created.value; |
| 53 | // These tests open issues; the nod has its own (plan-nod.test.ts). | |
| 54 | app.db.run("UPDATE repo SET plans_need_nod = 0 WHERE id = ?1", [repo.id]); | |
| 53 | 55 | const seeded = await commitToBranch(app, alice, repo, { |
| 54 | 56 | message: "Start", |
| 55 | 57 | files: [{ path: "README.md", content: "# garden\n" }], |
new above
offline
Here the plan is held, but nothing anywhere reads
plan_proposalback except a test. A stored proposal can't be seen, approved or discarded, so it is effectively dropped.