Public: anyone can read this; the crew can change it.
With 'plans need a nod' on, POST …/plan stores one proposal and opens no issues #1860
scout/forge:scout/1813-with-plans-need-a-nod-on-post-plan-store → main 1 commit fork
9 files
changed +223
−16
docs/PLANNING.md +10
| @@ -565,3 +565,13 @@ not confirm its own plan. Split also moves the parent's blocked-by edges to | ||
| 565 | 565 | the issues named in `into` (a child that would make a loop is skipped), and |
| 566 | 566 | the parent waits for nothing. Reopening clears the reason. Closes that |
| 567 | 567 | predate reasons count as done. |
| 568 | ||
| 569 | ## Plans need a nod | |
| 570 | ||
| 571 | A repository setting, `plansNeedNod` (PATCH `/api/v1/repos/:owner/:name`, | |
| 572 | admin only, never an agent), on by default. On, `POST …/plan` and the MCP | |
| 573 | `plan` tool run every check as ever (`no_pillar`, loops, unknown keys) and | |
| 574 | then store one proposal — title, why, the ordered issues with their | |
| 575 | `blockedBy` — answering `proposed` with its id (HTTP 202). No issue is opened. | |
| 576 | Off, the plan opens its linked issues all or none. A person's nod that opens | |
| 577 | a stored proposal is not built yet. |
src/actions/plan.ts +73 −2
| @@ -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 { id as newId } from "../kernel/id.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,22 @@ function loopAt(items: readonly PlanItem[]): string | undefined { | ||
| 186 | 187 | return undefined; |
| 187 | 188 | } |
| 188 | 189 | |
| 189 | export function openPlan( | |
| 190 | /** What a good plan was checked against, for opening it. */ | |
| 191 | interface Vetted { | |
| 192 | readonly actor: User; | |
| 193 | readonly existing: Map<number, Issue>; | |
| 194 | readonly serves: Map<string, Pillar>; | |
| 195 | readonly gate: Issue | undefined; | |
| 196 | readonly later: Issue | undefined; | |
| 197 | } | |
| 198 | ||
| 199 | /** Every refusal a plan can meet, before anything is written. */ | |
| 200 | function vet( | |
| 190 | 201 | app: App, |
| 191 | 202 | actor: User | undefined, |
| 192 | 203 | repo: Repo, |
| 193 | 204 | items: readonly PlanItem[], |
| 194 | ): Result<Planned, PlanError> { | |
| 205 | ): Result<Vetted, PlanError> { | |
| 195 | 206 | if (!actor || !canRead(app.db, repo, actor)) |
| 196 | 207 | return refuse("not_found", "no such app or repository (owner/name)"); |
| 197 | 208 | if (!canWrite(app.db, repo, actor) && !isCrew(app.db, repo.id, actor.id)) |
| @@ -258,6 +269,66 @@ export function openPlan( | ||
| 258 | 269 | `"${item.key}" names no pillar: give it ${namesOf(pillars)}, or later: true and why`, |
| 259 | 270 | ); |
| 260 | 271 | } |
| 272 | return ok({ actor, existing, serves, gate, later }); | |
| 273 | } | |
| 274 | ||
| 275 | export interface Proposed { | |
| 276 | readonly status: "proposed"; | |
| 277 | readonly id: string; | |
| 278 | } | |
| 279 | ||
| 280 | /** | |
| 281 | * "Plans need a nod": the same checks as `openPlan`, then the plan is kept | |
| 282 | * as one proposal (title, why, the ordered issues with their blockedBy) and | |
| 283 | * no issue is opened. A person's nod opens it. | |
| 284 | */ | |
| 285 | export function proposePlan( | |
| 286 | app: App, | |
| 287 | actor: User | undefined, | |
| 288 | repo: Repo, | |
| 289 | items: readonly PlanItem[], | |
| 290 | say: { title?: unknown; why?: unknown } = {}, | |
| 291 | ): Result<Proposed, PlanError> { | |
| 292 | const title = typeof say.title === "string" ? say.title.trim() : ""; | |
| 293 | if (say.title !== undefined && typeof say.title !== "string") | |
| 294 | return refuse("invalid", "title must be text"); | |
| 295 | if (title.length > MAX_TITLE) | |
| 296 | return refuse("title_too_long", `title is over ${MAX_TITLE} characters`); | |
| 297 | if (say.why !== undefined && typeof say.why !== "string") | |
| 298 | return refuse("invalid", "why must be text"); | |
| 299 | const why = ((say.why ?? "") as string).trim(); | |
| 300 | if (why.length > MAX_BODY) | |
| 301 | return refuse("body_too_long", `why is over ${MAX_BODY} characters`); | |
| 302 | const vetted = vet(app, actor, repo, items); | |
| 303 | if (!vetted.ok) return vetted; | |
| 304 | const id = newId(); | |
| 305 | app.db | |
| 306 | .query( | |
| 307 | `INSERT INTO plan_proposal (id, repo_id, author_id, title, why, issues, created_at) | |
| 308 | VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)`, | |
| 309 | ) | |
| 310 | .run( | |
| 311 | id, | |
| 312 | repo.id, | |
| 313 | vetted.value.actor.id, | |
| 314 | title === "" ? items[0]!.title : title, | |
| 315 | why, | |
| 316 | JSON.stringify(items), | |
| 317 | new Date().toISOString(), | |
| 318 | ); | |
| 319 | return ok({ status: "proposed", id }); | |
| 320 | } | |
| 321 | ||
| 322 | export function openPlan( | |
| 323 | app: App, | |
| 324 | actor: User | undefined, | |
| 325 | repo: Repo, | |
| 326 | items: readonly PlanItem[], | |
| 327 | ): Result<Planned, PlanError> { | |
| 328 | const vetted = vet(app, actor, repo, items); | |
| 329 | if (!vetted.ok) return vetted; | |
| 330 | const { existing, serves, gate, later } = vetted.value; | |
| 331 | actor = vetted.value.actor; | |
| 261 | 332 | |
| 262 | 333 | const opened: { key: string; number: number }[] = []; |
| 263 | 334 | /** The links an item's purpose adds: [the issue that waits, what it waits for]. */ |
src/actions/repos.ts +3 −1
| @@ -249,7 +249,8 @@ export async function updateRepoSettings( | ||
| 249 | 249 | // one on a team that administers the repository (`crew/direct.ts`). |
| 250 | 250 | if ( |
| 251 | 251 | (settings.crewOutsiders !== undefined || |
| 252 | settings.decisionsBy !== undefined) && | |
| 252 | settings.decisionsBy !== undefined || | |
| 253 | settings.plansNeedNod !== undefined) && | |
| 253 | 254 | admin.value.kind === "agent" |
| 254 | 255 | ) |
| 255 | 256 | return err("not_found"); |
| @@ -276,6 +277,7 @@ export async function updateRepoSettings( | ||
| 276 | 277 | "requireChecks", |
| 277 | 278 | "crewOutsiders", |
| 278 | 279 | "decisionsBy", |
| 280 | "plansNeedNod", | |
| 279 | 281 | ] as const |
| 280 | 282 | ).filter((k) => settings[k] !== undefined && settings[k] !== repo[k]); |
| 281 | 283 | app.bus.append({ |
src/core/repos.ts +8 −1
| @@ -118,6 +118,8 @@ export interface Repo { | ||
| 118 | 118 | readonly crewOutsiders: boolean; |
| 119 | 119 | /** The standing rule for decisions here: `me`, `decider`, or `decider_tell`. */ |
| 120 | 120 | readonly decisionsBy: DecisionsBy; |
| 121 | /** "Plans need a nod": a plan is stored as a proposal, not opened. */ | |
| 122 | readonly plansNeedNod: boolean; | |
| 121 | 123 | /** The issue the planner is given, when the map has run dry. */ |
| 122 | 124 | readonly directionIssueId: string | null; |
| 123 | 125 | /** The repo this was forked from, or null. */ |
| @@ -163,6 +165,7 @@ interface RepoRow { | ||
| 163 | 165 | autonomy_by: string | null; |
| 164 | 166 | crew_outsiders: number; |
| 165 | 167 | decisions_by: string; |
| 168 | plans_need_nod: number; | |
| 166 | 169 | direction_issue_id: string | null; |
| 167 | 170 | fork_parent_id: string | null; |
| 168 | 171 | sealed_for: string | null; |
| @@ -201,6 +204,7 @@ function toRepo(row: RepoRow): Repo { | ||
| 201 | 204 | autonomyBy: row.autonomy_by, |
| 202 | 205 | crewOutsiders: row.crew_outsiders === 1, |
| 203 | 206 | decisionsBy: isDecisionsBy(row.decisions_by) ? row.decisions_by : "me", |
| 207 | plansNeedNod: row.plans_need_nod === 1, | |
| 204 | 208 | directionIssueId: row.direction_issue_id, |
| 205 | 209 | forkParentId: row.fork_parent_id, |
| 206 | 210 | sealedFor: row.sealed_for, |
| @@ -1036,6 +1040,7 @@ export interface RepoSettings { | ||
| 1036 | 1040 | /** Whether someone who cannot write here may start or steer a run. */ |
| 1037 | 1041 | crewOutsiders?: boolean; |
| 1038 | 1042 | decisionsBy?: DecisionsBy; |
| 1043 | plansNeedNod?: boolean; | |
| 1039 | 1044 | } |
| 1040 | 1045 | |
| 1041 | 1046 | /** Update the mutable repo fields, leaving unspecified ones untouched. */ |
| @@ -1048,7 +1053,8 @@ export function updateRepoSettings( | ||
| 1048 | 1053 | `UPDATE repo SET visibility = ?1, description = ?2, protect_default = ?3, |
| 1049 | 1054 | default_branch = ?4, require_review = ?5, require_checks = ?7, |
| 1050 | 1055 | autonomy = ?8, autonomy_direction = ?9, autonomy_ceiling_usd = ?10, |
| 1051 | autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13, decisions_by = ?14 | |
| 1056 | autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13, decisions_by = ?14, | |
| 1057 | plans_need_nod = ?15 | |
| 1052 | 1058 | WHERE id = ?6`, |
| 1053 | 1059 | ).run( |
| 1054 | 1060 | settings.visibility ?? repo.visibility, |
| @@ -1065,6 +1071,7 @@ export function updateRepoSettings( | ||
| 1065 | 1071 | settings.autonomyBy === undefined ? repo.autonomyBy : settings.autonomyBy, |
| 1066 | 1072 | (settings.crewOutsiders ?? repo.crewOutsiders) ? 1 : 0, |
| 1067 | 1073 | settings.decisionsBy ?? repo.decisionsBy, |
| 1074 | (settings.plansNeedNod ?? repo.plansNeedNod) ? 1 : 0, | |
| 1068 | 1075 | ); |
| 1069 | 1076 | return getRepoById(db, repo.id)!; |
| 1070 | 1077 | } |
src/core/schema.ts +16
| @@ -1794,6 +1794,22 @@ export const migrations: readonly string[] = [ | ||
| 1794 | 1794 | ` |
| 1795 | 1795 | ALTER TABLE issue ADD COLUMN parked INTEGER NOT NULL DEFAULT 0; |
| 1796 | 1796 | `, |
| 1797 | // 90 — plans need a nod (#1813): with the setting on, a plan is stored as | |
| 1798 | // one proposal (its ordered issues as JSON) and opens nothing until a | |
| 1799 | // person nods. On is the default. | |
| 1800 | ` | |
| 1801 | ALTER TABLE repo ADD COLUMN plans_need_nod INTEGER NOT NULL DEFAULT 1; | |
| 1802 | CREATE TABLE plan_proposal ( | |
| 1803 | id TEXT PRIMARY KEY, | |
| 1804 | repo_id TEXT NOT NULL, | |
| 1805 | author_id TEXT NOT NULL, | |
| 1806 | title TEXT NOT NULL, | |
| 1807 | why TEXT NOT NULL, | |
| 1808 | issues TEXT NOT NULL, | |
| 1809 | created_at TEXT NOT NULL | |
| 1810 | ); | |
| 1811 | CREATE INDEX plan_proposal_repo ON plan_proposal(repo_id, created_at); | |
| 1812 | `, | |
| 1797 | 1813 | ]; |
| 1798 | 1814 | |
| 1799 | 1815 | /** |
src/http/api.ts +19 −8
| @@ -274,7 +274,7 @@ import { | ||
| 274 | 274 | unlinkIssue, |
| 275 | 275 | confirmIssue, |
| 276 | 276 | } from "../actions/dependencies.ts"; |
| 277 | import { openPlan, parsePlan } from "../actions/plan.ts"; | |
| 277 | import { openPlan, parsePlan, proposePlan } from "../actions/plan.ts"; | |
| 278 | 278 | import { dependenciesOf, repoGraph } from "../core/dependencies.ts"; |
| 279 | 279 | import { pillarView } from "../core/pillars.ts"; |
| 280 | 280 | import { askToLiveFor } from "../web/ask_to_live.ts"; |
| @@ -1816,6 +1816,10 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 1816 | 1816 | ...(isDecisionsBy(input.decisionsBy) |
| 1817 | 1817 | ? { decisionsBy: input.decisionsBy } |
| 1818 | 1818 | : {}), |
| 1819 | // Whether a plan waits for a nod: an admin's, never an agent's. | |
| 1820 | ...(typeof input.plansNeedNod === "boolean" | |
| 1821 | ? { plansNeedNod: input.plansNeedNod } | |
| 1822 | : {}), | |
| 1819 | 1823 | }); |
| 1820 | 1824 | if (!updated.ok) return respondAccess(updated.error, 422); |
| 1821 | 1825 | return json(repoJson(ctx, updated.value)); |
| @@ -2580,15 +2584,22 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 2580 | 2584 | const items = parsePlan(input.issues); |
| 2581 | 2585 | if (!items.ok) |
| 2582 | 2586 | return apiError(items.error.error, 422, items.error.message); |
| 2583 | const planned = openPlan(ctx.app, ctx.auth.user, repo, items.value); | |
| 2584 | if (!planned.ok) { | |
| 2585 | const { error, message } = planned.error; | |
| 2586 | return apiError( | |
| 2587 | error, | |
| 2588 | error === "not_found" ? 404 : error === "forbidden" ? 403 : 422, | |
| 2589 | message, | |
| 2587 | const failed = (e: { error: string; message: string }) => | |
| 2588 | apiError( | |
| 2589 | e.error, | |
| 2590 | e.error === "not_found" ? 404 : e.error === "forbidden" ? 403 : 422, | |
| 2591 | e.message, | |
| 2590 | 2592 | ); |
| 2593 | // With "plans need a nod" the plan is stored, not opened. | |
| 2594 | if (repo.plansNeedNod) { | |
| 2595 | const proposed = proposePlan(ctx.app, ctx.auth.user, repo, items.value, { | |
| 2596 | title: input.title, | |
| 2597 | why: input.why, | |
| 2598 | }); | |
| 2599 | return proposed.ok ? json(proposed.value, 202) : failed(proposed.error); | |
| 2591 | 2600 | } |
| 2601 | const planned = openPlan(ctx.app, ctx.auth.user, repo, items.value); | |
| 2602 | if (!planned.ok) return failed(planned.error); | |
| 2592 | 2603 | return json(planned.value, 201); |
| 2593 | 2604 | }); |
| 2594 | 2605 | router.add( |
src/http/mcp.ts +16 −2
| @@ -39,7 +39,7 @@ import { | ||
| 39 | 39 | unlinkIssue, |
| 40 | 40 | } from "../actions/dependencies.ts"; |
| 41 | 41 | import { holdPull, releasePull } from "../actions/holds.ts"; |
| 42 | import { openPlan, parsePlan, PLAN_MAX } from "../actions/plan.ts"; | |
| 42 | import { openPlan, parsePlan, PLAN_MAX, proposePlan } from "../actions/plan.ts"; | |
| 43 | 43 | import { cancelRepoRun } from "../actions/runs.ts"; |
| 44 | 44 | import { familyView } from "../spawn/family.ts"; |
| 45 | 45 | import { clientRows } from "../spawn/clients.ts"; |
| @@ -1883,11 +1883,13 @@ const TOOLS: readonly Tool[] = [ | ||
| 1883 | 1883 | }, |
| 1884 | 1884 | { |
| 1885 | 1885 | name: "plan", |
| 1886 | description: `Open several small issues and link them in one call: all of them or none. Each item has a key, a title, a body and optionally blockedBy, a list of keys of this plan or numbers of issues already open. Where the app has pillars (umbrella issues titled like "P0 Trust: …"), each item also says what it is for: pillar, the one it serves, or later: true with why, one sentence, which puts it behind the Later gate instead of on the ready list; an item that says neither is refused. A bad link (loop, unknown key) refuses the whole plan and names the item. At most ${PLAN_MAX} issues. Answers with the numbers opened, by key, what is ready now, and what waits for later.`, | |
| 1886 | description: `Open several small issues and link them in one call: all of them or none. Each item has a key, a title, a body and optionally blockedBy, a list of keys of this plan or numbers of issues already open. Where the app has pillars (umbrella issues titled like "P0 Trust: …"), each item also says what it is for: pillar, the one it serves, or later: true with why, one sentence, which puts it behind the Later gate instead of on the ready list; an item that says neither is refused. A bad link (loop, unknown key) refuses the whole plan and names the item. At most ${PLAN_MAX} issues. Answers with the numbers opened, by key, what is ready now, and what waits for later. Where the app has "plans need a nod" on, the same checks run and one proposal is stored (optional title and why for the whole plan); nothing is opened, and it answers status proposed with the proposal id.`, | |
| 1887 | 1887 | inputSchema: { |
| 1888 | 1888 | type: "object", |
| 1889 | 1889 | properties: { |
| 1890 | 1890 | app: APP_ARG, |
| 1891 | title: { type: "string", maxLength: 256 }, | |
| 1892 | why: { type: "string", maxLength: 65536 }, | |
| 1891 | 1893 | issues: { |
| 1892 | 1894 | type: "array", |
| 1893 | 1895 | minItems: 1, |
| @@ -1934,6 +1936,18 @@ const TOOLS: readonly Tool[] = [ | ||
| 1934 | 1936 | if (isAnswer(repo)) return repo; |
| 1935 | 1937 | const items = parsePlan(args["issues"]); |
| 1936 | 1938 | if (!items.ok) return bad(items.error.error, items.error.message); |
| 1939 | if (repo.plansNeedNod) { | |
| 1940 | const proposed = proposePlan(ctx.app, user, repo, items.value, { | |
| 1941 | title: args["title"], | |
| 1942 | why: args["why"], | |
| 1943 | }); | |
| 1944 | if (!proposed.ok) | |
| 1945 | return bad(proposed.error.error, proposed.error.message); | |
| 1946 | return good({ | |
| 1947 | says: `Proposed plan ${proposed.value.id}: nothing is opened until a person nods.`, | |
| 1948 | ...proposed.value, | |
| 1949 | }); | |
| 1950 | } | |
| 1937 | 1951 | const planned = openPlan(ctx.app, user, repo, items.value); |
| 1938 | 1952 | if (!planned.ok) return bad(planned.error.error, planned.error.message); |
| 1939 | 1953 | const { opened, ready, later, gate } = planned.value; |
test/mcp.test.ts +33 −1
| @@ -13,7 +13,7 @@ import { addToCrew, createAgent } from "../src/actions/crew.ts"; | ||
| 13 | 13 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; |
| 14 | 14 | import { createApp as insertApp } from "../src/core/apps.ts"; |
| 15 | 15 | import { listIssues } from "../src/core/issues.ts"; |
| 16 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 16 | import { getRepoById, updateRepoSettings, type Repo } from "../src/core/repos.ts"; | |
| 17 | 17 | import { createRun, listRuns } from "../src/core/runs.ts"; |
| 18 | 18 | import { createToken } from "../src/core/tokens.ts"; |
| 19 | 19 | import { createUser, type User } from "../src/core/users.ts"; |
| @@ -521,7 +521,39 @@ describe("the forge over MCP", () => { | ||
| 521 | 521 | expect(after.ready.map((i: any) => i.number)).toContain(b); |
| 522 | 522 | }); |
| 523 | 523 | |
| 524 | test("with plans need a nod on, the plan tool stores one proposal and opens nothing", async () => { | |
| 525 | const count = async () => | |
| 526 | (await tool(ro, "map", { app: "alice/game" })).value.issues.length; | |
| 527 | const before = await count(); | |
| 528 | const issues = [ | |
| 529 | { key: "a", title: "First" }, | |
| 530 | { key: "b", title: "Second", blockedBy: ["a"] }, | |
| 531 | ]; | |
| 532 | const done = await tool(rw, "plan", { | |
| 533 | app: "alice/game", | |
| 534 | title: "Two steps", | |
| 535 | why: "worth a look", | |
| 536 | issues, | |
| 537 | }); | |
| 538 | expect(done.value.status).toBe("proposed"); | |
| 539 | const row = app.db | |
| 540 | .query<{ title: string; why: string; issues: string }, [string]>( | |
| 541 | "SELECT title, why, issues FROM plan_proposal WHERE id = ?1", | |
| 542 | ) | |
| 543 | .get(done.value.id)!; | |
| 544 | expect(row.title).toBe("Two steps"); | |
| 545 | expect(JSON.parse(row.issues).map((i: any) => i.key)).toEqual(["a", "b"]); | |
| 546 | expect(await count()).toBe(before); | |
| 547 | // The checks run as ever: a loop is refused and stores nothing. | |
| 548 | const loop = await tool(rw, "plan", { | |
| 549 | app: "alice/game", | |
| 550 | issues: [{ key: "x", title: "X", blockedBy: ["x"] }], | |
| 551 | }); | |
| 552 | expect(loop.error).toContain("self"); | |
| 553 | }); | |
| 554 | ||
| 524 | 555 | test("plan opens linked issues all or none", async () => { |
| 556 | updateRepoSettings(app.db, getRepoById(app.db, game.id)!, { plansNeedNod: false }); | |
| 525 | 557 | const issues = [ |
| 526 | 558 | { key: "a", title: "First" }, |
| 527 | 559 | { key: "b", title: "Second", body: "two" }, |
test/plan-route.test.ts +45 −1
| @@ -12,7 +12,7 @@ import { openIssue } from "../src/actions/issues.ts"; | ||
| 12 | 12 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 13 | 13 | import { listIssues } from "../src/core/issues.ts"; |
| 14 | 14 | import { pillarsOf } from "../src/core/pillars.ts"; |
| 15 | import type { Repo } from "../src/core/repos.ts"; | |
| 15 | import { getRepoById, updateRepoSettings, type Repo } from "../src/core/repos.ts"; | |
| 16 | 16 | import { createToken } from "../src/core/tokens.ts"; |
| 17 | 17 | import { createUser, type User } from "../src/core/users.ts"; |
| 18 | 18 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -68,7 +68,50 @@ describe("POST …/plan", () => { | ||
| 68 | 68 | await rm(dataDir, { recursive: true, force: true }); |
| 69 | 69 | }); |
| 70 | 70 | |
| 71 | const proposals = () => | |
| 72 | app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM plan_proposal").get()!.n; | |
| 73 | const nod = (on: boolean) => | |
| 74 | updateRepoSettings(app.db, getRepoById(app.db, repo.id)!, { plansNeedNod: on }); | |
| 75 | ||
| 76 | test("plans need a nod is on by default: one proposal is stored and no issue is opened", async () => { | |
| 77 | expect(getRepoById(app.db, repo.id)!.plansNeedNod).toBe(true); | |
| 78 | const before = titles().length; | |
| 79 | const stored = proposals(); | |
| 80 | const res = await post(rw, [ | |
| 81 | { key: "a", title: "Prune the roses", pillar: "P0" }, | |
| 82 | { key: "b", title: "Mulch", pillar: "P0", blockedBy: ["a"] }, | |
| 83 | ]); | |
| 84 | expect(res.status).toBe(202); | |
| 85 | const body = (await res.json()) as { status: string; id: string }; | |
| 86 | expect(body.status).toBe("proposed"); | |
| 87 | expect(titles().length).toBe(before); | |
| 88 | expect(proposals()).toBe(stored + 1); | |
| 89 | const row = app.db | |
| 90 | .query<{ issues: string }, [string]>("SELECT issues FROM plan_proposal WHERE id = ?1") | |
| 91 | .get(body.id)!; | |
| 92 | expect(JSON.parse(row.issues).map((i: { key: string }) => i.key)).toEqual(["a", "b"]); | |
| 93 | }); | |
| 94 | ||
| 95 | test("on, a pillarless issue is still refused with no_pillar and nothing is stored", async () => { | |
| 96 | const stored = proposals(); | |
| 97 | const res = await post(rw, [{ key: "a", title: "Prune" }]); | |
| 98 | expect(res.status).toBe(422); | |
| 99 | expect(((await res.json()) as { error: string }).error).toBe("no_pillar"); | |
| 100 | expect(proposals()).toBe(stored); | |
| 101 | }); | |
| 102 | ||
| 103 | test("off, the plan opens its issues as before and stores no proposal", async () => { | |
| 104 | nod(false); | |
| 105 | const stored = proposals(); | |
| 106 | const res = await post(rw, [{ key: "a", title: "Sweep the path", pillar: "P0" }]); | |
| 107 | expect(res.status).toBe(201); | |
| 108 | expect(titles()).toContain("Sweep the path"); | |
| 109 | expect(proposals()).toBe(stored); | |
| 110 | nod(true); | |
| 111 | }); | |
| 112 | ||
| 71 | 113 | test("a plan with a pillarless issue is refused with no_pillar and opens nothing; with the pillar named it opens the issues under the umbrella", async () => { |
| 114 | nod(false); | |
| 72 | 115 | const before = titles().length; |
| 73 | 116 | const first = await post(rw, [{ key: "a", title: "Water the beds" }]); |
| 74 | 117 | expect(((await first.json()) as { error: string }).error).toBe("no_pillar"); |
| @@ -90,6 +133,7 @@ describe("POST …/plan", () => { | ||
| 90 | 133 | }); |
| 91 | 134 | |
| 92 | 135 | test("a person's token plans the same way, all or nothing, and a read token is refused", async () => { |
| 136 | nod(false); | |
| 93 | 137 | const before = titles().length; |
| 94 | 138 | const refused = await post(rw, [ |
| 95 | 139 | { key: "x", title: "Fine", pillar: "P0" }, |
new above
offline