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

Closed opened this
Closed without merging

scout/forge:scout/1621-plans-need-a-nod-with-the-setting-on-pos → main 8 commits fork 4 threads · 4 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
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
423423 on the repository's **crew**, which is the one grant an agent can hold — it
424424 reads and writes that repository and administers nothing.
425425
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
426434 Assign an issue to an agent and it starts: the forge clones the repository,
427435 puts the agent on a branch named after the issue, and runs Claude Code
428436 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[] = [
3535 "test/apps-idle.test.ts",
3636 "test/body-limits.test.ts",
3737 "test/boards-query.test.ts",
38 "test/plan-nod.test.ts",
3839 "test/boards-page.test.ts",
3940 "test/turnstile.test.ts",
4041 "test/variants-deck.test.ts",
src/actions/plan.ts +54 −1
@@ -25,6 +25,7 @@ import {
2525 import { canRead, canWrite, type Repo } from "../core/repos.ts";
2626 import type { User } from "../core/users.ts";
2727 import { transact } from "../kernel/db.ts";
28 import { storeProposal } from "../core/proposals.ts";
2829 import { err, ok, type Result } from "../kernel/result.ts";
2930 import { isMirror } from "../origins/write-through.ts";
3031 import { followLink } from "./pillars.ts";
@@ -186,12 +187,49 @@ function loopAt(items: readonly PlanItem[]): string | undefined {
186187 return undefined;
187188 }
188189
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
189224 export function openPlan(
190225 app: App,
191226 actor: User | undefined,
192227 repo: Repo,
193228 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> {
195233 if (!actor || !canRead(app.db, repo, actor))
196234 return refuse("not_found", "no such app or repository (owner/name)");
197235 if (!canWrite(app.db, repo, actor) && !isCrew(app.db, repo.id, actor.id))
@@ -259,6 +297,21 @@ export function openPlan(
259297 );
260298 }
261299
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) {

Here the plan is held, but nothing anywhere reads plan_proposal back except a test. A stored proposal can't be seen, approved or discarded, so it is effectively dropped.

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
262315 const opened: { key: string; number: number }[] = [];
263316 /** The links an item's purpose adds: [the issue that waits, what it waits for]. */
264317 const purpose: [Issue, Issue][] = [];
src/actions/repos.ts +1
@@ -275,6 +275,7 @@ export async function updateRepoSettings(
275275 "requireReview",
276276 "requireChecks",
277277 "crewOutsiders",
278 "plansNeedNod",
278279 "decisionsBy",
279280 ] as const
280281 ).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 {
116116 * default; on a public repository it hands strangers the owner's budget.
117117 */
118118 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;
119125 /** The standing rule for decisions here: `me`, `decider`, or `decider_tell`. */
120126 readonly decisionsBy: DecisionsBy;
121127 /** The issue the planner is given, when the map has run dry. */
@@ -162,6 +168,7 @@ interface RepoRow {
162168 autonomy_slots: number;
163169 autonomy_by: string | null;
164170 crew_outsiders: number;
171 plans_need_nod: number;
165172 decisions_by: string;
166173 direction_issue_id: string | null;
167174 fork_parent_id: string | null;
@@ -200,6 +207,7 @@ function toRepo(row: RepoRow): Repo {
200207 autonomySlots: row.autonomy_slots,
201208 autonomyBy: row.autonomy_by,
202209 crewOutsiders: row.crew_outsiders === 1,
210 plansNeedNod: row.plans_need_nod === 1,
203211 decisionsBy: isDecisionsBy(row.decisions_by) ? row.decisions_by : "me",
204212 directionIssueId: row.direction_issue_id,
205213 forkParentId: row.fork_parent_id,
@@ -1035,6 +1043,8 @@ export interface RepoSettings {
10351043 autonomyBy?: string | null;
10361044 /** Whether someone who cannot write here may start or steer a run. */
10371045 crewOutsiders?: boolean;
1046 /** Whether a plan is stored as a proposal instead of opening issues. */
1047 plansNeedNod?: boolean;
10381048 decisionsBy?: DecisionsBy;
10391049 }
10401050
@@ -1048,7 +1058,8 @@ export function updateRepoSettings(
10481058 `UPDATE repo SET visibility = ?1, description = ?2, protect_default = ?3,
10491059 default_branch = ?4, require_review = ?5, require_checks = ?7,
10501060 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
10521063 WHERE id = ?6`,
10531064 ).run(
10541065 settings.visibility ?? repo.visibility,
@@ -1065,6 +1076,7 @@ export function updateRepoSettings(
10651076 settings.autonomyBy === undefined ? repo.autonomyBy : settings.autonomyBy,
10661077 (settings.crewOutsiders ?? repo.crewOutsiders) ? 1 : 0,
10671078 settings.decisionsBy ?? repo.decisionsBy,
1079 (settings.plansNeedNod ?? repo.plansNeedNod) ? 1 : 0,
10681080 );
10691081 return getRepoById(db, repo.id)!;
10701082 }
src/core/schema.ts +17
@@ -1741,6 +1741,23 @@ export const migrations: readonly string[] = [
17411741 ALTER TABLE repo ADD COLUMN decisions_by TEXT NOT NULL DEFAULT 'me'
17421742 CHECK (decisions_by IN ('me', 'decider', 'decider_tell'));
outdated

High: DEFAULT 1 turns this on for every existing repository at merge, while no door can list or approve a proposal. Planner runs will then open nothing and be repeated whenever the map is dry. Use DEFAULT 0 until the approve step exists, or add that step in this pull.

17431743 `,
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 `,
17441761 ];
17451762
17461763 /**
src/crew/brief.ts +1
@@ -108,6 +108,7 @@ export function systemPrompt(input: BriefInput): string {
108108 "- A worked example:",
109109 ` 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."}]}'`,
110110 " 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.',
111112 "- 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.",
112113 '- 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.',
113114 "- 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(
229229 blockedBy: [],
230230 ...(pillar ? { pillar } : {}),
231231 },
232 ]);
233 if (opened.ok) {
232 ], {}, false);
233 if (opened.ok && "opened" in opened.value) {
234234 const number = opened.value.opened[0]!.number;
235235 placed.push({ action: "opened", repo: slug, number, ...(pillar ? { pillar } : {}) });
236236 const name = set.pillars.find((p) => p.short === pillar)?.name;
@@ -238,7 +238,7 @@ export async function placeThought(
238238 } else if (direction) {
239239 comment(direction, "A thought that could not be opened as an issue:");
240240 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}.`);
242242 }
243243 } else if (kind === "amendment" && target) {
244244 const issue = here(target.number);
src/http/api.ts +7 −1
@@ -1763,6 +1763,9 @@ export function apiRoutes(router: Router<Handler>): void {
17631763 ...(typeof input.crewOutsiders === "boolean"
17641764 ? { crewOutsiders: input.crewOutsiders }
17651765 : {}),
1766 ...(typeof input.plansNeedNod === "boolean"
1767 ? { plansNeedNod: input.plansNeedNod }
1768 : {}),
17661769 // The standing rule for its decisions: also an admin's, never an agent's.
17671770 ...(isDecisionsBy(input.decisionsBy)
17681771 ? { decisionsBy: input.decisionsBy }
@@ -2531,7 +2534,10 @@ export function apiRoutes(router: Router<Handler>): void {
25312534 const items = parsePlan(input.issues);
25322535 if (!items.ok)
25332536 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 });
25352541 if (!planned.ok) {
25362542 const { error, message } = planned.error;
25372543 return apiError(
src/http/mcp.ts +19 −1
@@ -1859,6 +1859,15 @@ const TOOLS: readonly Tool[] = [
18591859 type: "object",
18601860 properties: {
18611861 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 },
18621871 issues: {
18631872 type: "array",
18641873 minItems: 1,
@@ -1905,8 +1914,17 @@ const TOOLS: readonly Tool[] = [
19051914 if (isAnswer(repo)) return repo;
19061915 const items = parsePlan(args["issues"]);
19071916 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 });
19091921 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 });
19101928 const { opened, ready, later, gate } = planned.value;
19111929 const waits =
19121930 gate === undefined
src/web/pages/settings.ts +17
@@ -284,6 +284,20 @@ export async function settingsPage(ctx: Ctx): Promise<Response> {
284284 >
285285 </label>
286286 </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>
287301 <div class="field">
288302 <input type="hidden" name="crewOutsidersShown" value="1" />
289303 <label class="check">
@@ -349,6 +363,9 @@ export async function settingsUpdate(ctx: Ctx): Promise<Response> {
349363 ...(form.get("crewOutsidersShown") !== null
350364 ? { crewOutsiders: form.get("crewOutsiders") !== null }
351365 : {}),
366 ...(form.get("plansNeedNodShown") !== null

This form branch has no test. Add one that posts the settings form with and without plansNeedNod and checks repo.plansNeedNod.

367 ? { plansNeedNod: form.get("plansNeedNod") !== null }
368 : {}),
352369 ...(branch !== "" ? { defaultBranch: branch } : {}),
353370 };
354371 const updated = await updateRepoSettings(
test/mcp.test.ts +20
@@ -93,6 +93,8 @@ describe("the forge over MCP", () => {
9393 });
9494 if (!made.ok) throw new Error(String(made.error));
9595 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]);
9698 await commitToBranch(app, alice, game, {
9799 message: "seed",
98100 files: [{ path: "README.md", content: "# game\n" }],
@@ -566,6 +568,24 @@ describe("the forge over MCP", () => {
566568 ).toContain("forbidden");
567569 });
568570
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
569589 test("a browser session is not a way in, even signed in", async () => {
570590 const signin = await fetch(`${base}/signin`, {
571591 method: "POST",
test/pillars.test.ts +2
@@ -170,6 +170,8 @@ describe("pillars", () => {
170170 });
171171 if (!made.ok) throw new Error(String(made.error));
172172 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]);
173175 const seeded = await commitToBranch(app, alice, repo, {
174176 message: "Start",
175177 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", () => {
8181 const repo = async (name: string): Promise<Repo> => {
8282 const made = await createRepo(app, alice, { name, visibility: "private" });
8383 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]);
8486 return made.value;
8587 };
8688
@@ -405,6 +407,7 @@ describe("whose issue stands for a pillar", () => {
405407 });
406408 if (!made.ok) throw new Error(String(made.error));
407409 open = made.value;
410 app.db.run("UPDATE repo SET plans_need_nod = 0 WHERE id = ?1", [open.id]);
408411 }, 30_000);
409412
410413 afterAll(async () => {
test/plan-route.test.ts +2
@@ -50,6 +50,8 @@ describe("POST …/plan", () => {
5050 const created = await createRepo(app, alice, { name: "garden", visibility: "private" });
5151 if (!created.ok) throw new Error(String(created.error));
5252 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]);
5355 const seeded = await commitToBranch(app, alice, repo, {
5456 message: "Start",
5557 files: [{ path: "README.md", content: "# garden\n" }],

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs