Public: anyone can read this; the crew can change it.

A label's shape refusal lives in one module, and the settings page and MCP read it from there #5581

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/5566-a-label-s-shape-refusal-lives-in-one-mod → main 1 commit fork 1 thread · 1 unresolved

  • Merged. mason/5566-a-label-s-shape-refusal-lives-in-one-mod was merged into main as 454d61f.

Review

Sign in to review this change.
4 files changed +89 −3
src/actions/label_words.ts added +8
@@ -0,0 +1,8 @@
1 /**
2 * What a label made without a name or a six-digit colour is told, from every
3 * door: the settings form and MCP `repo_labels` read it here, so they cannot drift.
4 */
5
6 export const LABEL_WORDS = {
7 shape: "A label needs a name and a six-digit hex color.",
8 } as const;
src/http/mcp.ts +2 −1
@@ -191,6 +191,7 @@ import {
191191 OUTSIDERS_NOTE,
192192 } from "../crew/direct.ts";
193193 import { createLabel, deleteLabel, setArchived, setCrewOutsiders, updateRepoSettings, setDecisionsBy, repositoryLimitMessage } from "../actions/repos.ts";
194 import { LABEL_WORDS } from "../actions/label_words.ts";
194195 import {
195196 deleteAppEnvVar,
196197 listAppEnv,
@@ -3754,7 +3755,7 @@ const TOOLS: readonly Tool[] = [
37543755 made.error === "taken"
37553756 ? "A label with that name already exists."
37563757 : made.error === "invalid"
3757 ? "A label needs a name and a six-digit hex color."
3758 ? LABEL_WORDS.shape
37583759 : "no such app or repository (owner/name)",
37593760 );
37603761 return good({ says: `Created the label ${made.value.name}.`, label: made.value });
src/web/pages/settings.ts +3 −2
@@ -121,6 +121,7 @@ import { secretsSection } from "./secrets.ts";
121121 import { checkMemoryAt } from "../../apps/check-memory.ts";
122122 import { followUpstreamCard } from "./upstream-follow.ts";
123123 import { saveGrants } from "./subscriptions.ts";
124 import { LABEL_WORDS } from "../../actions/label_words.ts";
124125
125126 type Section =
126127 | "general"
@@ -1839,7 +1840,7 @@ export async function labelCreate(ctx: Ctx): Promise<Response> {
18391840 message:
18401841 created.error === "taken"
18411842 ? "This repository already has a label by that name."
1842 : "A label needs a name and a six-digit hex color.",
1843 : LABEL_WORDS.shape,
18431844 },
18441845 );
18451846 }
@@ -1868,7 +1869,7 @@ export async function labelUpdate(ctx: Ctx): Promise<Response> {
18681869 ? "This repository already has a label by that name."
18691870 : updated.error === "not_found"
18701871 ? "That label no longer exists."
1871 : "A label needs a name and a six-digit hex color.",
1872 : LABEL_WORDS.shape,
18721873 },
18731874 );
18741875 }
test/label-words.test.ts added +76
@@ -0,0 +1,76 @@
1 /**
2 * A label made without a name or a six-digit colour reads the same from every
3 * door, because every door reads it from src/actions/label_words.ts.
4 */
5
6 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
7 import { readdir, mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { LABEL_WORDS } from "../src/actions/label_words.ts";
11 import { createApp, type App } from "../src/app.ts";
12 import { serve, type Servers } from "../src/http/server.ts";
13 import { adminCookie } from "./helpers/admin.ts";
14
15 describe("a label's shape refusal", () => {
16 let dataDir: string;
17 let app: App;
18 let servers: Servers;
19 let base: string;
20 let cookie = "";
21
22 const form = (fields: Record<string, string>) => new URLSearchParams(fields);
23
24 beforeAll(async () => {
25 dataDir = await mkdtemp(join(tmpdir(), "forge-label-words-"));
26 app = createApp({ dataDir, port: 0 });
27 servers = await serve(app);
28 base = servers.url;
29 cookie = await adminCookie(app, { username: "olive", email: "[email protected]", password: "label-words-password" });
30 await fetch(`${base}/new`, {
31 method: "POST",
32 headers: { cookie },
33 body: form({ name: "proj", visibility: "private", description: "" }),
34 redirect: "manual",
35 });
36 });
37
38 afterAll(async () => {
39 servers.stop();
40 app.close();
41 await rm(dataDir, { recursive: true, force: true });
42 });
43
44 test("the settings form answers the module's sentence for a nameless label", async () => {
45 const refused = await fetch(`${base}/olive/proj/settings/labels`, {
46 method: "POST",
47 headers: { cookie },
48 body: form({ name: " ", color: "d73a4a" }),
49 redirect: "manual",
50 });
51 expect(refused.status).toBe(303);
52 const flash = refused.headers.getSetCookie().map((c) => c.split(";")[0]).join("; ");
53 const shown = await (
54 await fetch(new URL(refused.headers.get("location")!, base), { headers: { cookie: `${cookie}; ${flash}` } })
55 ).text();
56 expect(shown).toContain(LABEL_WORDS.shape);
57 });
58
59 // MCP `repo_labels` checks the name and colour itself before createLabel can
60 // answer "invalid", so its branch is held to the module by reading the door.

Low, not blocking: this asserts on mcp.ts source text, which is acceptable only because the invalid branch is unreachable after the pre-checks above it. If those pre-checks ever move into createLabel, replace this with a real tools/call that triggers the refusal.

61 test("MCP repo_labels reads the sentence from the module", async () => {
62 const source = await Bun.file(join(import.meta.dir, "../src/http/mcp.ts")).text();
63 expect(source).toContain('from "../actions/label_words.ts"');
64 expect(source).toContain("LABEL_WORDS.shape");
65 });
66
67 test("no file under src/ but the module types the sentence out", async () => {
68 const root = join(import.meta.dir, "../src");
69 const holders: string[] = [];
70 for (const entry of await readdir(root, { recursive: true })) {
71 if (!entry.endsWith(".ts")) continue;
72 if ((await Bun.file(join(root, entry)).text()).includes(LABEL_WORDS.shape)) holders.push(entry);
73 }
74 expect(holders).toEqual([join("actions", "label_words.ts")]);
75 });
76 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs