A local-first multi-agent app development platform, built on PenguinHarness
fix(web): a full command-policy rule list says its ceiling and closes Add rule
lmliheng2c5e2bba2c90
diff --git a/changelog/unreleased/2026-11-14-command-policy-rule-limit.md b/changelog/unreleased/2026-11-14-command-policy-rule-limit.mdnew file mode 100644index 00000000..10b6bab9--- /dev/null+++ b/changelog/unreleased/2026-11-14-command-policy-rule-limit.md@@ -0,0 +1,56 @@+# The security-policy page declares its rule ceiling and closes the add entry point at it++- **Date:** 2026-11-14+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-11-14-command-policy-rule-limit.zh.md)++The server caps a command policy at 64 rules and answers the 65th with `rules exceeds 64 entries.`+The page used to say nothing about that ceiling and stop nothing at it: the count row read+"Rules · 64", "Add rule" stayed live, the form opened, the rule could be typed and saved — and was+refused, the refusal being the first mention that a ceiling existed at all.++The count row now says it at the ceiling and the add entry point goes inert at the same moment:+clicking it there does nothing (not a dimmed button that still opens the form), and deleting a+rule brings both the sentence and the button back together. The number mirrors the route's+`MAX_RULES` — the same way this page's rule fields already mirror the route's per-field length+limits, except that this one's test reads the server source and compares, so the two cannot drift.++## Details++- `packages/web/src/lib/command-policy-rule-limit.ts` (new): `COMMAND_POLICY_RULE_LIMIT` (mirrors+ `MAX_RULES`) and `ruleLimitHint(count)` — `null` while one more rule fits, the sentence at (and+ past) the ceiling. The button and the sentence read one value, so they cannot disagree.+- `packages/web/src/components/layout/project-dialogs.tsx` (`SecurityPolicySection`): the sentence+ is drawn beside the count (`data-testid="command-policy-rule-limit"`, attention ink, two lines+ max) and `disabled` on "Add rule" gains the same condition; "Restore defaults" is untouched (it+ shortens the list). The section's own header comment claimed failures toast — stale since the+ refusal moved beside the button — and is corrected here.+- Dictionaries (`strings.ts` / `strings-en.ts`): one sentence carrying the number.+- No API change, no new dependency, no server-side behaviour change.++## Tests++- `packages/web/test/command-policy-rule-limit.test.ts` (new, 5 cases): nothing is said while one+ more rule fits; the ceiling is named once reached, with the number in the sentence itself; a list+ already past it (stored by an older build) still speaks; the sentence follows the active+ dictionary; the constant equals the route's `MAX_RULES`, read out of the server source the way+ `avatar-image.test.ts` pins the avatar cap.+- `packages/web/e2e/command-policy-rule-limit.spec.mjs` (new, 2 cases, real server + real browser):+ with 64 rules stored, the sentence is there, the button is `disabled`, and pressing it opens no+ form; deleting one rule brings both back and the form really opens. One short of the ceiling,+ nothing is said and the button works.+- `packages/web/e2e/command-policy-save-refusal.spec.mjs` (changed): last round's two refused-Save+ cases were triggered by adding the 65th rule through the form — exactly what this guard makes+ impossible. Their setup is now "store 63 rules, let the form fill it to 64, and let the outgoing+ PUT carry one rule more": the server sees the shape only a build without the guard would store,+ and its validation, status code and words are its own; nothing in the page is stubbed. The+ assertions themselves are unchanged.++## Compatibility++No wire change: the same PUT, the same validation. What changes is that the page states its+ceiling and stops the entry point there, instead of letting the 65th rule reach Save and be+refused.diff --git a/changelog/unreleased/2026-11-14-command-policy-rule-limit.zh.md b/changelog/unreleased/2026-11-14-command-policy-rule-limit.zh.mdnew file mode 100644index 00000000..91348d67--- /dev/null+++ b/changelog/unreleased/2026-11-14-command-policy-rule-limit.zh.md@@ -0,0 +1,46 @@+# 安全策略页说出规则表的上限,并在到顶时把「添加规则」关掉++- **日期:** 2026-11-14+- **类型:** 修复+- **范围:** `web`+- **破坏性变更:** 否++[English](2026-11-14-command-policy-rule-limit.md)++服务端把一份命令策略限制在 64 条规则,第 65 条只能换来一句 `rules exceeds 64 entries.`。页面过去既不+说明有这么一条上限,也不在它那里拦下:计数行只写「规则 · 64」,「添加规则」照样亮着,表单照样打开,规则+照样能填、能保存 —— 然后被拒,而那是整页第一次提到上限,且那句话说在被拒之后。++现在计数那一行在到顶时说出它,添加规则的入口在同一刻变成不可点:到顶时点它什么都不会发生(不是灰着却仍+能打开表单),删掉一条之后句子与按钮一起回来。数字与路由的 `MAX_RULES` 一致 —— 与这一页规则字段早就照着+服务端镜像字段长度上限是同一手法,区别是这次单测直接读服务端的源码对账,免得两边漂移。++## 细节++- `packages/web/src/lib/command-policy-rule-limit.ts`(新增):`COMMAND_POLICY_RULE_LIMIT`(镜像+ `MAX_RULES`)与 `ruleLimitHint(count)` —— 未到顶时是 `null`,到顶(含已经超出)时是那句话。按钮与句子读+ 同一个值,因此两者不会各说各的。+- `packages/web/src/components/layout/project-dialogs.tsx` 的 `SecurityPolicySection`:计数行把句子画在+ 计数旁边(`data-testid="command-policy-rule-limit"`、告警色、最多两行),「添加规则」的 `disabled`+ 加上这一条;「恢复默认」不受影响(它会把列表变短)。模块头注释里那句「失败弹通知」也顺手改正 —— 上一轮+ 已经改成分句了。+- 词典(`strings.ts` / `strings-en.ts`):一句带数字的说明。+- 没有接口变化、没有新依赖、服务端行为没变。++## 测试++- `packages/web/test/command-policy-rule-limit.test.ts`(新增,5 条):还放得下时什么都不说;到顶时说出+ 上限而且句子里有那个数字;已经超出(旧数据)时照样说;跟随当前词典;常量等于服务端路由里的 `MAX_RULES`+ (读服务端源码对账,与 `avatar-image.test.ts` 钉住头像上限同一写法)。+- `packages/web/e2e/command-policy-rule-limit.spec.mjs`(新增,2 条,真服务端 + 真浏览器):项目存着 64+ 条时,句子在、按钮 `disabled`、点它不会开出表单;删掉一条后两者一起回来、表单真能打开。少一条时什么都不+ 说、按钮可点。+- `packages/web/e2e/command-policy-save-refusal.spec.mjs`(改):上一轮那两条「被拒的保存」靠**表单加进+ 第 65 条**触发,而这道护栏正是让它不可能再发生 —— 于是前提改成「项目存 63 条、表单补到 64 条,出站的那+ 次 PUT 再多带一条」:给服务端看到的是旧版本才会存下的形状,校验、状态码与措辞仍是服务端自己的,页面没有+ 被替身顶替。两条用例的断言一字未改。++## 兼容性++线上协议没变:同一个 PUT、同一套校验。变的是这一页在到顶时说清上限并挡住入口,而不是让第 65 条走到保存那+一步才被拒。diff --git a/packages/web/e2e/command-policy-rule-limit.spec.mjs b/packages/web/e2e/command-policy-rule-limit.spec.mjsnew file mode 100644index 00000000..c4f7ea87--- /dev/null+++ b/packages/web/e2e/command-policy-rule-limit.spec.mjs@@ -0,0 +1,131 @@+/**+ * Regression: Project settings → Security policy declares the route's 64-rule ceiling on the+ * count row, and stops "Add rule" at it.+ *+ * The route refuses the 65th rule (`rules exceeds 64 entries.`, `MAX_RULES` in+ * `http/routes/command-policy.ts`), but the page used to keep the add entry point live at 64: the+ * rule could be typed, the list saved, and the refusal was the first mention that any ceiling+ * existed — after the work, as a notification that dismissed itself. The ceiling belongs where+ * the form is opened (`src/lib/command-policy-rule-limit.ts`), so the button goes inert and the+ * row that opens it says why.+ *+ * The state is stored through the API — exactly what a Project with a long deny list already+ * holds — because the point of this spec is the page's own behaviour at that state, not the+ * route's validation (which `command-policy-save-refusal.spec.mjs` covers).+ */+import { test, expect } from "@playwright/test";+import { ADMIN_ID, ADMIN_PASSWORD, login } from "./auth.mjs";++const BASE = process.env.BASE_URL;++/** The route's own ceiling, mirrored here as the situation being tested. */+const MAX_RULES = 64;++async function projectIdOf(page) {+ return (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0].projectId;+}++async function policyOf(page, projectId) {+ return await (await page.request.get(`${BASE}/api/projects/${projectId}/command-policy`)).json();+}++/**+ * A rule list of exactly `count` rules: the Project's own defaults, each cloned under a distinct+ * name past the factory set. Counted rather than pinned, so a data root that outlives a rerun and+ * a factory set that grows both stay valid.+ */+function listOf(defaults, count) {+ const rules = [];+ for (let i = 0; rules.length < count; i += 1) {+ const base = defaults[i % defaults.length];+ const name = i < defaults.length ? base.name : `${base.name}-${i}`;+ rules.push({ name, pattern: `\\b${name.replace(/[^a-zA-Z0-9-]/g, "-")}\\b`, enabled: true });+ }+ return rules;+}++/** Stores a policy directly (the state a Project with a long deny list is already in). */+async function storePolicy(page, projectId, body) {+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/command-policy`, {+ data: body,+ });+ expect(put.ok(), await put.text()).toBeTruthy();+ return put.json();+}++/** Opens Project settings → Security policy through the sidebar, the way a user gets there. */+async function openSecurity(page) {+ // A data root with no model credential yet greets the chat page with its guide, which sits+ // above everything on its own scrim — dismiss it before reaching into the sidebar.+ const guide = page.getByRole("dialog", { name: "尚未配置模型 credential" });+ await guide.waitFor({ state: "visible", timeout: 4000 }).catch(() => {});+ if (await guide.count()) await guide.getByRole("button", { name: "稍后" }).click();++ const projects = await (await page.request.get(`${BASE}/api/projects`)).json();+ const project = projects.projects[0];+ const sidebar = page.getByRole("complementary");+ await expect(sidebar).toBeVisible({ timeout: 20000 });+ await sidebar.getByRole("button", { name: project.name ?? project.projectId }).click();+ // Same DOM click as the members spec: the row closes its menu as it opens the dialog.+ await page.getByRole("button", { name: "项目设置" }).evaluate((el) => el.click());+ const dialog = page.getByRole("dialog", { name: "项目设置" });+ await expect(dialog).toBeVisible();+ await dialog.getByRole("button", { name: "安全策略" }).click();+ // The section arrives with its read: the master switch and the rule count are both there.+ await expect(dialog.getByRole("switch").first()).toBeVisible();+ await expect(dialog.getByText(/^规则 · \d+$/)).toBeVisible();+ await expect(dialog.getByRole("button", { name: "保存" })).toBeVisible();+ return dialog;+}++test("at the ceiling the add entry point is inert and the count row says why", async ({ page }) => {+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);+ const projectId = await projectIdOf(page);+ const factory = await policyOf(page, projectId);+ await storePolicy(page, projectId, {+ enabled: true,+ rules: listOf(factory.defaultRules, MAX_RULES),+ });++ await page.goto(`${BASE}/chat`);+ const dialog = await openSecurity(page);+ await expect(dialog.getByText(new RegExp(`^规则 · ${MAX_RULES}$`))).toBeVisible();++ const hint = dialog.getByTestId("command-policy-rule-limit");+ await expect(hint).toBeVisible();+ await expect(hint).toContainText(String(MAX_RULES));++ const add = dialog.getByRole("button", { name: "添加规则" });+ await expect(add).toBeDisabled();+ // Inert means no form opens, not merely a dimmed button.+ expect(await dialog.getByLabel(/^名称/).count()).toBe(0);++ // Delete one rule: the draft is one short of the ceiling, so the sentence and the entry point+ // come back on the same render.+ await dialog.getByRole("button", { name: "删除" }).last().click();+ await expect(hint).toHaveCount(0);+ await expect(add).toBeEnabled();+ await add.click();+ await expect(dialog.getByLabel(/^名称/)).toBeVisible();+});++test("below the ceiling nothing is said and the form opens", async ({ page }) => {+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);+ const projectId = await projectIdOf(page);+ const factory = await policyOf(page, projectId);+ await storePolicy(page, projectId, {+ enabled: true,+ rules: listOf(factory.defaultRules, MAX_RULES - 1),+ });++ await page.goto(`${BASE}/chat`);+ const dialog = await openSecurity(page);+ await expect(dialog.getByText(new RegExp(`^规则 · ${MAX_RULES - 1}$`))).toBeVisible();++ // One rule still fits: no sentence, and the form opens when asked.+ await expect(dialog.getByTestId("command-policy-rule-limit")).toHaveCount(0);+ const add = dialog.getByRole("button", { name: "添加规则" });+ await expect(add).toBeEnabled();+ await add.click();+ await expect(dialog.getByLabel(/^名称/)).toBeVisible();+});diff --git a/packages/web/e2e/command-policy-save-refusal.spec.mjs b/packages/web/e2e/command-policy-save-refusal.spec.mjsindex c85f2db5..897d56ab 100644--- a/packages/web/e2e/command-policy-save-refusal.spec.mjs+++ b/packages/web/e2e/command-policy-save-refusal.spec.mjs@@ -9,9 +9,10 @@* the 65th rule believed it was enforced.** The refusal here is the server's own answer: the route caps the rule list at 64 entries- * (`MAX_RULES`, `http/routes/command-policy.ts`) and the page never says so and never stops you at- * it. The spec materializes the 64-rule list through the API — exactly what a Project with a long- * deny list already holds — then adds the 65th one through the form, the way a user does.+ * (`MAX_RULES`, `http/routes/command-policy.ts`). Since 7.127 the page declares that ceiling and+ * stops the add entry point at it, so the 65th rule can no longer be typed here — the spec stores+ * the list one short of the ceiling through the API (exactly what such a Project holds) and lets+ * the outgoing PUT carry one more rule, see `saveOnePastCeiling`.*/import { test, expect } from "@playwright/test";import { ADMIN_ID, ADMIN_PASSWORD, login } from "./auth.mjs";@@ -60,8 +61,39 @@ async function storePolicy(page, projectId, body) {return put.json();}+/**+ * Lets the page save a legal draft while the route receives one rule past its ceiling.+ *+ * The rejection this spec is about is the route's own, and since 7.127 the form refuses to grow a+ * 64-rule list — which is the point of that guard. So the draft is stored one rule short, the form+ * fills it to 64, and this interceptor appends one rule to the outgoing PUT only: the route gets+ * the shape a Project from a build without the guard would carry, and answers it with its real+ * validation and its real 400. Nothing else about the page or the server is stubbed; call the+ * returned function before a retry that should land.+ */+async function saveOnePastCeiling(page) {+ const pattern = "**/api/projects/*/command-policy";+ await page.route(pattern, async (route) => {+ if (route.request().method() !== "PUT") return route.continue();+ const body = route.request().postDataJSON();+ await route.continue({+ postData: JSON.stringify({+ ...body,+ rules: [...body.rules, { name: "past-the-ceiling", pattern: "\\bpast-the-ceiling\\b" }],+ }),+ });+ });+ return () => page.unroute(pattern);+}+/** Opens Project settings → Security policy through the sidebar, the way a user gets there. */async function openSecurity(page) {+ // A data root with no model credential yet greets the chat page with its guide, which sits+ // above everything on its own scrim — dismiss it before reaching into the sidebar.+ const guide = page.getByRole("dialog", { name: "尚未配置模型 credential" });+ await guide.waitFor({ state: "visible", timeout: 4000 }).catch(() => {});+ if (await guide.count()) await guide.getByRole("button", { name: "稍后" }).click();+const projects = await (await page.request.get(`${BASE}/api/projects`)).json();const project = projects.projects[0];const sidebar = page.getByRole("complementary");@@ -98,21 +130,26 @@ test("a refused Save that would have switched blocking off says it is still on",await login(page.request, ADMIN_ID, ADMIN_PASSWORD);const projectId = await projectIdOf(page);const factory = await policyOf(page, projectId);- // Normalized first, so a rerun starts from the switch ON and the list at the ceiling.- await storePolicy(page, projectId, { enabled: true, rules: fullList(factory.defaultRules) });+ // Normalized first, so a rerun starts from the switch ON and the list one rule short of the+ // ceiling — the last rule the form can still add (7.127 keeps the entry point inert at 64).+ await storePolicy(page, projectId, {+ enabled: true,+ rules: fullList(factory.defaultRules).slice(0, MAX_RULES - 1),+ });const storedBefore = await policyOf(page, projectId);- expect(storedBefore.rules).toHaveLength(MAX_RULES);+ expect(storedBefore.rules).toHaveLength(MAX_RULES - 1);await page.goto(`${BASE}/chat`);const dialog = await openSecurity(page);await expect(masterSwitch(dialog)).toHaveAttribute("aria-checked", "true");- // The draft asks for two things: a rule past the ceiling, and blocking off. The rule comes- // first because the list goes inert the moment the master switch is off.+ // The draft asks for two things: the rule that fills the list to the ceiling, and blocking off.+ // The rule comes first because the list goes inert the moment the master switch is off.await addRule(page, dialog, "past-the-ceiling");await masterSwitch(dialog).click();await expect(masterSwitch(dialog)).toHaveAttribute("aria-checked", "false");+ const stopIntercepting = await saveOnePastCeiling(page);await dialog.getByRole("button", { name: "保存" }).click();const refusal = dialog.getByTestId("command-policy-refusal");@@ -125,7 +162,7 @@ test("a refused Save that would have switched blocking off says it is still on",// Nothing was reported through a notification instead.await expect(notices(page).getByRole("button")).toHaveCount(0);- // Nothing was written: still ON, still exactly the 64 rules read before.+ // Nothing was written: still ON, still exactly the rules read before.expect(await policyOf(page, projectId)).toEqual(storedBefore);// Six seconds is how long a toast lives: the sentence has to outlive it.@@ -133,6 +170,8 @@ test("a refused Save that would have switched blocking off says it is still on",await expect(refusal).toBeVisible();// Back to a list the route accepts, then press the same button: it lands, the sentence goes.+ // The interceptor comes off first, so the retry carries the list the page really holds.+ await stopIntercepting();await masterSwitch(dialog).click();await expect(masterSwitch(dialog)).toHaveAttribute("aria-checked", "true");await dialog.getByRole("button", { name: "恢复默认" }).click();@@ -148,7 +187,11 @@ test("a refused rule-list edit does not claim the switch moved", async ({ page }await login(page.request, ADMIN_ID, ADMIN_PASSWORD);const projectId = await projectIdOf(page);const factory = await policyOf(page, projectId);- await storePolicy(page, projectId, { enabled: true, rules: fullList(factory.defaultRules) });+ // One rule short of the ceiling, so the form can add the one that fills the list.+ await storePolicy(page, projectId, {+ enabled: true,+ rules: fullList(factory.defaultRules).slice(0, MAX_RULES - 1),+ });const storedBefore = await policyOf(page, projectId);await page.goto(`${BASE}/chat`);@@ -157,6 +200,7 @@ test("a refused rule-list edit does not claim the switch moved", async ({ page }// Only the rule list changes: the switch stays where the Project has it.await addRule(page, dialog, "one-too-many");+ const stopIntercepting = await saveOnePastCeiling(page);await dialog.getByRole("button", { name: "保存" }).click();const refusal = dialog.getByTestId("command-policy-refusal");@@ -169,6 +213,7 @@ test("a refused rule-list edit does not claim the switch moved", async ({ page }expect(await policyOf(page, projectId)).toEqual(storedBefore);// "Restore defaults" brings the list back under the ceiling; the same button lands it.+ await stopIntercepting();await dialog.getByRole("button", { name: "恢复默认" }).click();await dialog.getByRole("button", { name: "保存" }).click();await expect(refusal).toHaveCount(0);diff --git a/packages/web/src/components/layout/project-dialogs.tsx b/packages/web/src/components/layout/project-dialogs.tsxindex 8a5323a2..edb63b30 100644--- a/packages/web/src/components/layout/project-dialogs.tsx+++ b/packages/web/src/components/layout/project-dialogs.tsx@@ -37,6 +37,7 @@ import {chatDefaultsSaveRefused,type ChatDefaultsWrite,} from "../../lib/chat-defaults-save-refusal";+import { ruleLimitHint } from "../../lib/command-policy-rule-limit";import { commandPolicySaveRefused } from "../../lib/command-policy-save-refusal";import { memberWriteRefused, type MemberRefusal } from "../../lib/member-write-refusal";import { toneInk } from "../../lib/tone";@@ -974,9 +975,11 @@ export function RuleEditor({* list — the factory rules are seeded data with no special status (edit / disable /* delete / add all apply), and "restore defaults" re-buffers the factory set served by the* API (buffered like every other edit — Save is what writes it). Owner edits buffer- * locally with ONE explicit Save (dialog convention: failures toast, success toasts- * saved); members see the effective state read-only. The list dims AND disables while the- * master switch is off, but Save stays live so the toggle itself can be saved.+ * locally with ONE explicit Save (a refusal is a sentence beside the button that asked —+ * command-policy-save-refusal.ts; a success toasts "saved"); members see the effective+ * state read-only. The list dims AND disables while the master switch is off, but Save stays+ * live so the toggle itself can be saved. The route's 64-rule ceiling is enforced here too+ * (command-policy-rule-limit.ts): at 64 the count row says so and "Add rule" goes inert.*/function SecurityPolicySection({ projectId, isOwner }: { projectId: string; isOwner: boolean }) {const [saved, setSaved] = useState<CommandPolicyDto | null>(null);@@ -1014,6 +1017,9 @@ function SecurityPolicySection({ projectId, isOwner }: { projectId: string; isOw};}, [projectId]);+ /** At the route's rule ceiling: "Add rule" goes inert and the count row says why (7.127). */+ const ruleLimit = ruleLimitHint(rules.length);+const dirty =saved !== null &&(enabled !== saved.enabled ||@@ -1071,10 +1077,25 @@ function SecurityPolicySection({ projectId, isOwner }: { projectId: string; isOwevery control focusable, so each one below disables on `!enabled` as well. */}<div className={enabled ? "" : "opacity-50"}><div className="flex items-center justify-between gap-2 border-t border-gray-100 py-1.5 dark:border-gray-800/60">- <p className="text-xs font-medium text-gray-500">- {S.project.commandPolicyRules} ·{" "}- <span className="font-semibold">{rules.length}</span>- </p>+ <div className="flex min-w-0 items-center gap-2">+ <p className="shrink-0 text-xs font-medium text-gray-500">+ {S.project.commandPolicyRules} ·{" "}+ <span className="font-semibold">{rules.length}</span>+ </p>+ {/* The route refuses the 65th rule, but nothing in the form said a ceiling+ existed: the list is the one thing here that can outgrow its file silently+ ("Add rule" stayed live at 64 and the Save that followed was the first mention+ of any limit). The line sits on the count's own row — the same row that opens+ the form — and the button below goes inert with it. */}+ {ruleLimit !== null && (+ <p+ data-testid="command-policy-rule-limit"+ className={`line-clamp-2 min-w-0 break-words text-xs ${toneInk.attention}`}+ >+ {ruleLimit}+ </p>+ )}+ </div>{isOwner && (<div className="flex items-center gap-1"><Button@@ -1088,7 +1109,7 @@ function SecurityPolicySection({ projectId, isOwner }: { projectId: string; isOw<Buttonsize="sm"variant="ghost"- disabled={busy || !enabled || editing !== null}+ disabled={busy || !enabled || editing !== null || ruleLimit !== null}onClick={() => setEditing("new")}>{S.project.commandPolicyAddRule}diff --git a/packages/web/src/lib/command-policy-rule-limit.ts b/packages/web/src/lib/command-policy-rule-limit.tsnew file mode 100644index 00000000..ae81a8c9--- /dev/null+++ b/packages/web/src/lib/command-policy-rule-limit.ts@@ -0,0 +1,30 @@+/**+ * The ceiling on a Project's command-policy rule list, and the line the security-policy page+ * shows once the list reaches it (`components/layout/project-dialogs.tsx`).+ *+ * The route caps a PUT at 64 rules (`MAX_RULES`, `packages/server/src/http/routes/command-policy.ts`)+ * and answers a longer one with `rules exceeds 64 entries.` — a refusal the page could only read+ * after the fact: "Add rule" opened at 64, the 65th rule was typed and saved, and the limit was+ * first mentioned by the refusal that rejected it. The page therefore mirrors the number, the same+ * way its rule fields already mirror the route's per-field limits (name 64, pattern 512,+ * description 300): the ceiling belongs at the entry point, so the row that opens the form goes+ * inert and says why instead of letting that 65th rule be written.+ *+ * The two numbers must agree, and nothing at runtime keeps them in step — so the module's test+ * reads the route's own `MAX_RULES` out of the server source and compares.+ */+import { S } from "./strings";++/** Mirrors `MAX_RULES` in the server's command-policy route. */+export const COMMAND_POLICY_RULE_LIMIT = 64;++/**+ * The line beside the rule count once no more rules fit, or null while one still does. It says+ * what to do about it: the count next to it already says how many are stored. The same null is+ * what the add entry point reads, so the sentence and the inert button cannot disagree.+ */+export function ruleLimitHint(count: number): string | null {+ return count >= COMMAND_POLICY_RULE_LIMIT+ ? S.project.commandPolicyRuleLimit(COMMAND_POLICY_RULE_LIMIT)+ : null;+}diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex ab4c893d..b443b044 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -1647,6 +1647,12 @@ export const en: Strings = {commandPolicyRulePattern: "Regular expression",commandPolicyRuleDesc: "Description",commandPolicyInvalidPattern: "Invalid regular expression",+ /**+ * The route's ceiling on the rule list (command-policy-rule-limit.ts), shown on the count row+ * once the buffered list reaches it: the Add button next to it goes inert at the same moment.+ */+ commandPolicyRuleLimit: (limit: number): string =>+ `This list is at its ${limit}-rule limit — delete one to add another.`,/*** A Save this page was refused (command-policy-save-refusal.ts), drawn above the Save button* that asked: one Save writes the switch and the whole rule list, so the sentence says whichdiff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex 06c58e81..65c34d23 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -1693,6 +1693,12 @@ export const zh = {commandPolicyRulePattern: "正则表达式",commandPolicyRuleDesc: "描述",commandPolicyInvalidPattern: "正则表达式无效",+ /**+ * The route's ceiling on the rule list (command-policy-rule-limit.ts), shown on the count row+ * once the buffered list reaches it: the Add button next to it goes inert at the same moment.+ */+ commandPolicyRuleLimit: (limit: number): string =>+ `已达 ${limit} 条规则的上限,删除一条后才能再加。`,/*** A Save this page was refused (command-policy-save-refusal.ts), drawn above the Save button* that asked: one Save writes the switch and the whole rule list, so the sentence has to saydiff --git a/packages/web/test/command-policy-rule-limit.test.ts b/packages/web/test/command-policy-rule-limit.test.tsnew file mode 100644index 00000000..d16bbab1--- /dev/null+++ b/packages/web/test/command-policy-rule-limit.test.ts@@ -0,0 +1,58 @@+/**+ * The rule-list ceiling on the Project settings security page+ * (src/lib/command-policy-rule-limit.ts): the line the count row shows at 64, and the same value+ * the add entry point goes inert on.+ *+ * The route rejects a PUT with more than 64 rules (`MAX_RULES`) and the page mirrors that number+ * rather than receiving it — so the last case reads the route's own constant out of the server+ * source, the way `avatar-image.test.ts` pins its cap. A page that drifted below the route would+ * let the 65th rule be written and refused; one that drifted above would block a rule the server+ * would have taken.+ */+import { readFileSync } from "node:fs";+import { afterEach, describe, expect, it } from "vitest";+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";+import { en as EN } from "../src/lib/strings-en";+import { COMMAND_POLICY_RULE_LIMIT, ruleLimitHint } from "../src/lib/command-policy-rule-limit";++afterEach(() => {+ setActiveStrings(ZH);+});++describe("ruleLimitHint", () => {+ it("says nothing while one more rule still fits", () => {+ expect(ruleLimitHint(0)).toBe(null);+ expect(ruleLimitHint(COMMAND_POLICY_RULE_LIMIT - 1)).toBe(null);+ });++ it("names the ceiling once the list reaches it", () => {+ const hint = ruleLimitHint(COMMAND_POLICY_RULE_LIMIT);+ expect(hint).toBe(S.project.commandPolicyRuleLimit(COMMAND_POLICY_RULE_LIMIT));+ // The number is in the sentence itself, not only in the constant beside it.+ expect(hint).toContain(String(COMMAND_POLICY_RULE_LIMIT));+ });++ it("still speaks for a list already over it (stored before the ceiling was honoured)", () => {+ expect(ruleLimitHint(COMMAND_POLICY_RULE_LIMIT + 1)).toBe(+ S.project.commandPolicyRuleLimit(COMMAND_POLICY_RULE_LIMIT),+ );+ });++ it("follows the active dictionary", () => {+ setActiveStrings(EN);+ expect(ruleLimitHint(COMMAND_POLICY_RULE_LIMIT)).toBe(+ S.project.commandPolicyRuleLimit(COMMAND_POLICY_RULE_LIMIT),+ );+ expect(ruleLimitHint(COMMAND_POLICY_RULE_LIMIT)).toContain("limit");+ });++ it("is the number the server enforces", () => {+ // The server is a type-only dependency of the Web App, so its route is read as text.+ const route = readFileSync(+ new URL("../../server/src/http/routes/command-policy.ts", import.meta.url),+ "utf8",+ );+ const serverCap = Number(/const MAX_RULES = (\d+);/.exec(route)?.[1]);+ expect(COMMAND_POLICY_RULE_LIMIT).toBe(serverCap);+ });+});