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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/5566-a-label-s-shape-refusal-lives-in-one-mod → main 1 commit fork 1 thread · 1 unresolved
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 { | ||
| 191 | 191 | OUTSIDERS_NOTE, |
| 192 | 192 | } from "../crew/direct.ts"; |
| 193 | 193 | import { createLabel, deleteLabel, setArchived, setCrewOutsiders, updateRepoSettings, setDecisionsBy, repositoryLimitMessage } from "../actions/repos.ts"; |
| 194 | import { LABEL_WORDS } from "../actions/label_words.ts"; | |
| 194 | 195 | import { |
| 195 | 196 | deleteAppEnvVar, |
| 196 | 197 | listAppEnv, |
| @@ -3754,7 +3755,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 3754 | 3755 | made.error === "taken" |
| 3755 | 3756 | ? "A label with that name already exists." |
| 3756 | 3757 | : made.error === "invalid" |
| 3757 | ? "A label needs a name and a six-digit hex color." | |
| 3758 | ? LABEL_WORDS.shape | |
| 3758 | 3759 | : "no such app or repository (owner/name)", |
| 3759 | 3760 | ); |
| 3760 | 3761 | 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"; | ||
| 121 | 121 | import { checkMemoryAt } from "../../apps/check-memory.ts"; |
| 122 | 122 | import { followUpstreamCard } from "./upstream-follow.ts"; |
| 123 | 123 | import { saveGrants } from "./subscriptions.ts"; |
| 124 | import { LABEL_WORDS } from "../../actions/label_words.ts"; | |
| 124 | 125 | |
| 125 | 126 | type Section = |
| 126 | 127 | | "general" |
| @@ -1839,7 +1840,7 @@ export async function labelCreate(ctx: Ctx): Promise<Response> { | ||
| 1839 | 1840 | message: |
| 1840 | 1841 | created.error === "taken" |
| 1841 | 1842 | ? "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, | |
| 1843 | 1844 | }, |
| 1844 | 1845 | ); |
| 1845 | 1846 | } |
| @@ -1868,7 +1869,7 @@ export async function labelUpdate(ctx: Ctx): Promise<Response> { | ||
| 1868 | 1869 | ? "This repository already has a label by that name." |
| 1869 | 1870 | : updated.error === "not_found" |
| 1870 | 1871 | ? "That label no longer exists." |
| 1871 | : "A label needs a name and a six-digit hex color.", | |
| 1872 | : LABEL_WORDS.shape, | |
| 1872 | 1873 | }, |
| 1873 | 1874 | ); |
| 1874 | 1875 | } |
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. | |
| 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 | }); |
new above
offline
Low, not blocking: this asserts on mcp.ts source text, which is acceptable only because the
invalidbranch is unreachable after the pre-checks above it. If those pre-checks ever move intocreateLabel, replace this with a realtools/callthat triggers the refusal.