A local-first multi-agent app development platform, built on PenguinHarness
fix(web): a refused member write keeps its reason above the table that asked
lmlihengcf90349a60a4
diff --git a/changelog/unreleased/2026-11-13-member-write-refusal.md b/changelog/unreleased/2026-11-13-member-write-refusal.mdnew file mode 100644index 00000000..e4bd2c53--- /dev/null+++ b/changelog/unreleased/2026-11-13-member-write-refusal.md@@ -0,0 +1,59 @@+# A refused member write in Project settings keeps its reason in the table that asked++- **Date:** 2026-11-13+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-11-13-member-write-refusal.zh.md)++The Members page of the Project settings dialog begins and revokes access with ordinary writes, and+everything stays on screen when one is refused: the add box keeps the name that was typed, a+member's row keeps its 「移除」 button, so the same control is the retry. What was missing was the+reason — it arrived as a notification that dismissed itself after six seconds, above a table that+looked untouched. A member who had in fact NOT been removed looked exactly like one who had, and+the sentence that said otherwise was already gone. That is the rule every write refusal in the app+follows (the sentence belongs where the attempt was made), and this dialog's own General page+already keeps the same fact inside its delete card.++Both directions now leave the sentence above the table (`role="alert"`, danger ink, the whole+reason on hover), naming the account it was about — the page is a list, and two attempts in a row+name two different people — and saying the list did not change. Each attempt clears the sentence+from the attempt before it, a landed retry clears it too, and the toast is gone from this page.++## Details++- `packages/web/src/lib/member-write-refusal.ts` (new): `memberWriteRefused(write, error)` —+ `{ kind: "add" | "remove", userId }` plus the sentence, read through `refusalText` (an answer the+ server gave is spoken through its code's own localized words; a failure this codebase raised is+ shown as written; nothing to say falls back to the generic text). The write comes back with the+ sentence, because which one it was is what a reader retries.+- `packages/web/src/components/layout/project-dialogs.tsx`: `MembersSection` holds one refusal at a+ time and draws it above the table (`data-testid="member-refusal"`, `role="alert"`, two lines with+ the full text on hover); `addMember` / `doRemove` write it instead of calling `toastError`, and+ clear it at the start of every attempt. The page's own comment now says so.+- `packages/web/src/lib/strings.ts` / `strings-en.ts`: `memberAddRefused` and+ `memberRemoveRefused`, in both dictionaries.++## Tests++- `packages/web/test/member-write-refusal.test.ts` (new, 5 cases): the account is named and the+ server's code — not its wire message — is spoken; an addition and a removal are not the same+ sentence; a failure raised before the request keeps its own words; a value with nothing to say+ falls back to the generic text; the active dictionary decides the language.+- `packages/web/e2e/member-write-refusal.spec.mjs` (new, 2 cases, real server + a real browser,+ both refusals the server's own): adding an account that does not exist answers 404+ `user_not_found` — the sentence is above the table, the table's row count does not change, the+ typed name stays, nothing lands in the notification region, the sentence is still there after+ seven seconds, and typing a real account into the same box lands the row and takes the sentence+ with it; removing a member somebody else just removed answers 404 `member_not_found` — the row+ and the sentence both stay, and the same button retries it once the membership is back.+- Against the page as it was before the change (rebuilt from `HEAD`'s `project-dialogs.tsx`), both+ cases fail on the missing refusal line; a two-state probe on the same page reads one notification+ at 1.2 s (「该用户已不存在。」) and an empty screen at 7.5 s, against the refusal line at both+ moments after the change.++## Compatibility++No API change, no new dependency, no stored format change. A write that lands behaves exactly as+before; what changed is a write that does not — it can no longer look as if it did.diff --git a/changelog/unreleased/2026-11-13-member-write-refusal.zh.md b/changelog/unreleased/2026-11-13-member-write-refusal.zh.mdnew file mode 100644index 00000000..dd2c7493--- /dev/null+++ b/changelog/unreleased/2026-11-13-member-write-refusal.zh.md@@ -0,0 +1,48 @@+# 项目设置里的成员写被拒时,原因留在发问的那张表里++- **日期:** 2026-11-13+- **类型:** 修复+- **范围:** `web`+- **破坏性变更:** 否++[English](2026-11-13-member-write-refusal.md)++项目设置对话框的「成员」页用普通写入来授予与收回权限,被拒时屏幕上的东西一样都没少:添加框里还是刚打进去+的那个名字,成员的整行还在、连同它的「移除」按钮 —— 所以重试就是同一个控件。缺的是原因:它落在一条六秒后+自己消失的通知里,飘在看起来没被碰过的表之上。一个其实**没有**被移出的成员,与一个已经移出的看起来一模一样,+而说明真相的那句话早已不见。这正是全应用「被拒的原因留在发问的地方」那条规则,而这个对话框自己的「通用」页+早就把同一件事留在它的删除卡片里。++现在授予与收回都把这句话留在表上方(`role="alert"`、危险色、悬停看全文),说清是哪个账号 —— 这一页是一张+名单,连着两次尝试说的是两个人 —— 并且说名单没有变化。每次尝试先清掉上一次那句,落地的那次重试也一样清掉;+本页不再发通知。++## 细节++- `packages/web/src/lib/member-write-refusal.ts`(新增):`memberWriteRefused(write, error)` ——+ `{ kind: "add" | "remove", userId }` 加上那句话,经 `refusalText` 读出(服务端答的按错误码自己那句本地化+ 文案念;本仓库自己抛出的失败原样显示;什么都没得说就落通用文案)。那次写随句子一起回来,因为读者要重试的+ 正是它。+- `packages/web/src/components/layout/project-dialogs.tsx`:`MembersSection` 一次只留一句拒绝、画在表上方+ (`data-testid="member-refusal"`、`role="alert"`、限两行、悬停看全文);`addMember` / `doRemove` 被拒时+ 写它而不是 `toastError`,每次尝试开始时先清掉。这一页自己的注释也跟着改。+- `packages/web/src/lib/strings.ts` / `strings-en.ts`:`memberAddRefused` / `memberRemoveRefused`,+ 中英各一对。++## 测试++- `packages/web/test/member-write-refusal.test.ts`(新增,5 条):点名那个账号、念的是错误码自己那句而不是+ 线上原文;授予与收回不是同一句话;没走到请求就失败的保留它自己的话;什么都没得说时落通用文案;当前词典决定+ 语言。+- `packages/web/e2e/member-write-refusal.spec.mjs`(新增,2 条,真服务端 + 真浏览器,两次拒绝都是服务端+ 自己给的):加一个不存在的账号答 404 `user_not_found` —— 句子在表上方、表的行数不变、打进去的名字还在、+ 通知区一条都没有、七秒后那句仍在,随后往同一个框里换一个真账号就把行加进去、句子随之消失;移除一个刚被+ 别人移除的成员答 404 `member_not_found` —— 行与句子都还在,把成员身份补回去之后按同一个按钮就落地。+- 拿改动前的页面(`HEAD` 的 `project-dialogs.tsx` 重新构建)跑同一份新用例,两条都死在找不到那行拒绝句;+ 同一页上的两态探针:改前 1.2 s 是通知区一条「该用户已不存在。」、7.5 s 屏幕上一片空白,改后两刻都是表上方+ 那行拒绝句。++## 兼容性++线上接口没变、没有新依赖、已存数据格式没变。落地的写与以前一模一样;变的是没落地的那一种 —— 它再也不能+看起来像落地过。diff --git a/packages/web/e2e/member-write-refusal.spec.mjs b/packages/web/e2e/member-write-refusal.spec.mjsnew file mode 100644index 00000000..cfb55f02--- /dev/null+++ b/packages/web/e2e/member-write-refusal.spec.mjs@@ -0,0 +1,141 @@+/**+ * Regression: a refused member write in the Project settings dialog keeps its reason above the+ * table that asked, instead of in a notification that dismisses itself.+ *+ * Granting and revoking a member leave everything on screen either way — the add row keeps the+ * name that was typed, the member's own row keeps its 「移除」 button — so the retry is the same+ * control and the sentence only has to say who was not added or removed and why. Before, the+ * reason lived six seconds in a toast over a table that looked untouched: a member who had in+ * fact NOT been removed looked exactly like one who had, and nothing said otherwise.+ *+ * Both refusals here are the server's own, not stubs: adding an account that does not exist+ * answers 404 `user_not_found`, and removing a member somebody else just removed answers 404+ * `member_not_found`. The retries are real writes too, so "the same button retries" is measured+ * against the server rather than against a route that was taken over.+ */+import { test, expect } from "@playwright/test";+import { ADMIN_ID, ADMIN_PASSWORD, login, provisionUser } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const P = "password123";++/** The shared notification region: a refusal must not also land in it. */+const notices = (page) => page.getByRole("region", { name: "通知" });++/** The first Project's id, as the page sees it. */+async function projectIdOf(page) {+ return (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0].projectId;+}++/** Makes `userId` a member; "already a member" counts as done (this data root outlives a rerun). */+async function ensureMember(page, projectId, userId) {+ const res = await page.request.post(`${BASE}/api/projects/${projectId}/members`, {+ data: { userId },+ });+ expect(res.ok() || res.status() === 409).toBeTruthy();+}++/** Opens Project settings → Members through the sidebar, the way a user gets there. */+async function openMembers(page) {+ 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();+ // The switcher's rows are plain buttons (its own comment says so: no role="menu").+ // A DOM click: the row closes its menu as it opens the dialog, and the actionability retry+ // that follows that layout change lands on the new scrim. What this spec is about is the+ // dialog's table, not how its menu animates.+ 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 table arrives with the member list; the add row is the last one.+ await expect(dialog.getByPlaceholder("用户名")).toBeVisible();+ return dialog;+}++test("a refused grant names the account above the table, and the same box retries it", async ({+ page,+}) => {+ // A fresh account per run: this data root outlives a rerun, and a retry has to add a row.+ const U = `member_${Date.now()}`;+ await provisionUser(U, P);+ // The members page is the owner's: the signed-in account is the built-in admin.+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);+ await page.goto(`${BASE}/chat`);+ const dialog = await openMembers(page);++ // A username nobody has: the server answers 404 user_not_found.+ const ghost = `ghost_${Date.now()}`;+ const box = dialog.getByPlaceholder("用户名");+ // Counted, not pinned: this data root outlives a rerun, and other members may be in the table.+ const rows = dialog.locator("tbody tr");+ const before = await rows.count();+ await box.fill(ghost);+ await dialog.getByRole("button", { name: "添加成员" }).click();++ const refusal = dialog.getByTestId("member-refusal");+ await expect(refusal).toBeVisible();+ await expect(refusal).toHaveAttribute("role", "alert");+ await expect(refusal).toHaveText(`没能把「${ghost}」加进成员,名单没有变化:该用户已不存在。`);+ // The name that was typed is still there, and the table still holds only the owner's row and+ // the add row: the refused account did not become a row.+ await expect(box).toHaveValue(ghost);+ await expect(rows).toHaveCount(before);+ // Nothing was reported through a notification instead.+ await expect(notices(page).getByRole("button")).toHaveCount(0);++ // Six seconds is how long a toast lives: the sentence has to outlive it.+ await page.waitForTimeout(7000);+ await expect(refusal).toBeVisible();++ // The same box is the retry: a real account goes in, the sentence goes away, the row arrives.+ await box.fill(U);+ await dialog.getByRole("button", { name: "添加成员" }).click();+ await expect(refusal).toHaveCount(0);+ await expect(rows).toHaveCount(before + 1);+ await expect(dialog.getByRole("row", { name: new RegExp(U) })).toBeVisible();+ const members = await (+ await page.request.get(`${BASE}/api/projects/${await projectIdOf(page)}/members`)+ ).json();+ expect(members.members.map((m) => m.userId)).toContain(U);+});++test("a refused revocation keeps the row and its reason, and the same button retries it", async ({+ page,+}) => {+ const U = `target_${Date.now()}`;+ await provisionUser(U, P);+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);+ const projectId = await projectIdOf(page);+ // The row the page will draw: this account IS a member when the dialog opens.+ await ensureMember(page, projectId, U);++ await page.goto(`${BASE}/chat`);+ const dialog = await openMembers(page);+ const row = dialog.getByRole("row", { name: new RegExp(U) });+ await expect(row).toBeVisible();++ // Somebody else revokes it meanwhile (another owner, a second tab): the row on screen is stale,+ // which is exactly what the server answers 404 member_not_found for.+ const drop = await page.request.delete(`${BASE}/api/projects/${projectId}/members/${U}`);+ expect(drop.ok()).toBeTruthy();+ // Scoped to the row the sentence is about: other members' rows have the same button.+ await row.getByRole("button", { name: "移除" }).click();++ const refusal = dialog.getByTestId("member-refusal");+ await expect(refusal).toBeVisible();+ await expect(refusal).toHaveText(+ `没能把「${U}」移出成员,名单没有变化:该用户不是本项目的成员。`,+ );+ // The table still shows the row the sentence is about, and nothing was notified.+ await expect(row).toBeVisible();+ await expect(notices(page).getByRole("button")).toHaveCount(0);++ // Put the membership back and press the same button: it lands, so the row and the reason go.+ await ensureMember(page, projectId, U);+ await row.getByRole("button", { name: "移除" }).click();+ await expect(refusal).toHaveCount(0);+ await expect(row).toHaveCount(0);+});diff --git a/packages/web/src/components/layout/project-dialogs.tsx b/packages/web/src/components/layout/project-dialogs.tsxindex 6bac622a..8f9847f0 100644--- a/packages/web/src/components/layout/project-dialogs.tsx+++ b/packages/web/src/components/layout/project-dialogs.tsx@@ -33,6 +33,8 @@ import {import * as api from "../../api/endpoints";import { S } from "../../lib/strings";import { apiErrorText } from "../../lib/api-error";+import { memberWriteRefused, type MemberRefusal } from "../../lib/member-write-refusal";+import { toneInk } from "../../lib/tone";import {PROJECT_ID_MAX_LENGTH,PROJECT_SUFFIX_PATTERN,@@ -407,14 +409,18 @@ function GeneralSection({/*** Members page: the permission table (username / role / actions; owner adds and removes,- * members read). Only the initial load shows inline (in place of the table); action- * failures pop a toast. Mounted per tab visit, so revisiting refetches.+ * members read). Only the initial load shows inline (in place of the table); a refused write+ * says so above the table, in the account's own name (7.124, `member-write-refusal.ts`) —+ * never in a notification that dismisses itself while the row it is about stays put. Mounted+ * per tab visit, so revisiting refetches.*/function MembersSection({ projectId, isOwner }: { projectId: string; isOwner: boolean }) {const { user } = useAuth();const [members, setMembers] = useState<MemberInfo[] | null>(null);const [newMemberId, setNewMemberId] = useState("");const [loadError, setLoadError] = useState<string | null>(null);+ /** The last refused write, drawn above the table that asked (see the module's own doc). */+ const [refusal, setRefusal] = useState<MemberRefusal | null>(null);useEffect(() => {let cancelled = false;@@ -433,86 +439,104 @@ function MembersSection({ projectId, isOwner }: { projectId: string; isOwner: bo};}, [projectId]);+ // Each attempt starts a new question: the reason from the attempt before it belongs to a+ // sentence the user has already read, and a row it named may be gone from this table by now.const addMember = async () => {- if (!newMemberId.trim()) return;+ const userId = newMemberId.trim();+ if (!userId) return;+ setRefusal(null);try {- await api.addMember(projectId, { userId: newMemberId.trim() });+ await api.addMember(projectId, { userId });setNewMemberId("");const res = await api.listMembers(projectId);setMembers(res.members);} catch (e) {- toastError(apiErrorText(e));+ setRefusal(memberWriteRefused({ kind: "add", userId }, e));}};const doRemove = async (memberId: string) => {+ setRefusal(null);try {await api.removeMember(projectId, memberId);const res = await api.listMembers(projectId);setMembers(res.members);} catch (e) {- toastError(apiErrorText(e));+ setRefusal(memberWriteRefused({ kind: "remove", userId: memberId }, e));}};if (loadError) return <p className="text-xs text-red-600 dark:text-red-400">{loadError}</p>;if (members === null) return <p className="text-xs text-gray-400">{S.common.loading}</p>;return (- // Member permission table: username / role / actions; cells never wrap. Last row- // (owner only) = add member: small username input + add button (new members are- // always the member role).- <div className="overflow-x-auto rounded-md border border-gray-200 dark:border-gray-800">- <table className="w-full text-xs">- <thead>- <tr className="border-b border-gray-100 bg-gray-50 text-left text-gray-500 dark:border-gray-800 dark:bg-gray-900/60 dark:text-gray-400">- <th className="whitespace-nowrap px-2.5 py-1.5 font-medium">{S.common.username}</th>- <th className="whitespace-nowrap px-2.5 py-1.5 font-medium">{S.common.role}</th>- <th className="w-20 whitespace-nowrap px-2.5 py-1.5 text-right font-medium">- {S.common.actions}- </th>- </tr>- </thead>- <tbody className="divide-y divide-gray-100 dark:divide-gray-800/60">- {members.map((m) => (- <tr key={m.userId}>- <td className="whitespace-nowrap px-2.5 py-1.5">{m.userId}</td>- <td className="whitespace-nowrap px-2.5 py-1.5">- <Badge>{m.role}</Badge>- </td>- <td className="whitespace-nowrap px-2.5 py-1 text-right">- {isOwner && m.role !== "owner" && m.userId !== user?.userId && (- <Button size="sm" variant="ghost" onClick={() => void doRemove(m.userId)}>- {S.project.removeMember}- </Button>- )}- </td>- </tr>- ))}- {isOwner && (- <tr>- <td className="px-2.5 py-1.5">- <Input- placeholder={S.common.username}- size="sm"- value={newMemberId}- onChange={(e) => setNewMemberId(e.target.value)}- onKeyDown={(e) => {- if (e.key === "Enter") void addMember();- }}- />- </td>- <td className="whitespace-nowrap px-2.5 py-1.5">- <Badge>member</Badge>- </td>- <td className="whitespace-nowrap px-2.5 py-1 text-right">- <Button size="sm" disabled={!newMemberId.trim()} onClick={() => void addMember()}>- {S.project.addMember}- </Button>- </td>+ <div>+ {refusal !== null && (+ <p+ role="alert"+ data-testid="member-refusal"+ data-tooltip={refusal.text}+ data-tooltip-content="text"+ className={`mb-2 line-clamp-2 break-words text-xs ${toneInk.danger}`}+ >+ {refusal.text}+ </p>+ )}+ {/* Member permission table: username / role / actions; cells never wrap. Last row+ (owner only) = add member: small username input + add button (new members are+ always the member role). */}+ <div className="overflow-x-auto rounded-md border border-gray-200 dark:border-gray-800">+ <table className="w-full text-xs">+ <thead>+ <tr className="border-b border-gray-100 bg-gray-50 text-left text-gray-500 dark:border-gray-800 dark:bg-gray-900/60 dark:text-gray-400">+ <th className="whitespace-nowrap px-2.5 py-1.5 font-medium">{S.common.username}</th>+ <th className="whitespace-nowrap px-2.5 py-1.5 font-medium">{S.common.role}</th>+ <th className="w-20 whitespace-nowrap px-2.5 py-1.5 text-right font-medium">+ {S.common.actions}+ </th></tr>- )}- </tbody>- </table>+ </thead>+ <tbody className="divide-y divide-gray-100 dark:divide-gray-800/60">+ {members.map((m) => (+ <tr key={m.userId}>+ <td className="whitespace-nowrap px-2.5 py-1.5">{m.userId}</td>+ <td className="whitespace-nowrap px-2.5 py-1.5">+ <Badge>{m.role}</Badge>+ </td>+ <td className="whitespace-nowrap px-2.5 py-1 text-right">+ {isOwner && m.role !== "owner" && m.userId !== user?.userId && (+ <Button size="sm" variant="ghost" onClick={() => void doRemove(m.userId)}>+ {S.project.removeMember}+ </Button>+ )}+ </td>+ </tr>+ ))}+ {isOwner && (+ <tr>+ <td className="px-2.5 py-1.5">+ <Input+ placeholder={S.common.username}+ size="sm"+ value={newMemberId}+ onChange={(e) => setNewMemberId(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === "Enter") void addMember();+ }}+ />+ </td>+ <td className="whitespace-nowrap px-2.5 py-1.5">+ <Badge>member</Badge>+ </td>+ <td className="whitespace-nowrap px-2.5 py-1 text-right">+ <Button size="sm" disabled={!newMemberId.trim()} onClick={() => void addMember()}>+ {S.project.addMember}+ </Button>+ </td>+ </tr>+ )}+ </tbody>+ </table>+ </div></div>);}diff --git a/packages/web/src/lib/member-write-refusal.ts b/packages/web/src/lib/member-write-refusal.tsnew file mode 100644index 00000000..ef1b17bd--- /dev/null+++ b/packages/web/src/lib/member-write-refusal.ts@@ -0,0 +1,43 @@+/**+ * The Members page of the Project settings dialog (`components/layout/project-dialogs.tsx`) and+ * the sentence a refused member write leaves above its table.+ *+ * Granting and revoking a member are ordinary writes on a list that stays on screen: the add row+ * keeps what was typed, the member's own row keeps its 「移除」 button, so the retry is the same+ * control. What was missing was the reason — it arrived as a notification that dismissed itself+ * after six seconds, over a table that looked untouched, and a reader who had looked away was left+ * with a member still listed (or still absent) and nothing saying why (7.19's rule, app-wide: the+ * sentence belongs where the attempt was made).+ *+ * Which words: `refusalText`, the rule every refusal in the app follows — an answer the server+ * gave is read through its code's own localized sentence, and a value this codebase raised itself+ * is shown as it wrote it. The sentence names the account it was about (the table is a list, and+ * two attempts in a row name two different people) and says the list did not change, because a+ * refused write is the one moment a reader wonders whether the row moved anyway.+ */+import { refusalText } from "./api-error";+import { S } from "./strings";++/** Which write was refused, and about whom — enough to name it and to retry it. */+export interface MemberWrite {+ readonly kind: "add" | "remove";+ readonly userId: string;+}++/** The sentence one refused member write left, and the write it was for. */+export interface MemberRefusal {+ readonly write: MemberWrite;+ readonly text: string;+}++/** The sentence: which account was not added or removed, and why. */+export function memberWriteRefused(write: MemberWrite, error: unknown): MemberRefusal {+ const reason = refusalText(error);+ return {+ write,+ text:+ write.kind === "add"+ ? S.project.memberAddRefused(write.userId, reason)+ : S.project.memberRemoveRefused(write.userId, reason),+ };+}diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex d9756a26..b64fea3d 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -1594,6 +1594,14 @@ export const en: Strings = {members: "Members",addMember: "Add member",removeMember: "Remove",+ /**+ * A member write this page was refused (member-write-refusal.ts), drawn above the table that+ * asked: the account it was about, and the fact that the list below is still the old one.+ */+ memberAddRefused: (userId: string, reason: string): string =>+ `Could not add "${userId}" as a member; the list below is unchanged: ${reason}`,+ memberRemoveRefused: (userId: string, reason: string): string =>+ `Could not remove "${userId}" from the members; the list below is unchanged: ${reason}`,/** New-chat defaults section (Project settings): prefill for every new chat. */chatDefaultsTitle: "New chat defaults",chatDefaultsHint:diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex 07162994..7a032301 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -1641,6 +1641,14 @@ export const zh = {members: "成员",addMember: "添加成员",removeMember: "移除",+ /**+ * A member write this page was refused (member-write-refusal.ts), drawn above the table that+ * asked: the account it was about, and the fact that the list below is still the old one.+ */+ memberAddRefused: (userId: string, reason: string): string =>+ `没能把「${userId}」加进成员,名单没有变化:${reason}`,+ memberRemoveRefused: (userId: string, reason: string): string =>+ `没能把「${userId}」移出成员,名单没有变化:${reason}`,/** New-conversation defaults section (Project settings): prefills each new conversation's agent / working directory / approval mode / thinking level / default model. */chatDefaultsTitle: "新对话默认值",chatDefaultsHint: "新建对话时预填的默认值:Agent、工作目录、审批模式、思考等级与默认模型。",diff --git a/packages/web/test/member-write-refusal.test.ts b/packages/web/test/member-write-refusal.test.tsnew file mode 100644index 00000000..e81459e7--- /dev/null+++ b/packages/web/test/member-write-refusal.test.ts@@ -0,0 +1,69 @@+/**+ * A member write the Project settings dialog was refused (src/lib/member-write-refusal.ts): the+ * sentence the Members page draws above its table.+ *+ * The table stays on screen whether the grant or the revocation was refused, so the sentence is+ * the only thing saying the list did not change — and it is a list, so it has to name the account+ * it is about. Three things it has to get right: an answer the server gave speaks the interface's+ * own language rather than the wire message (7.19's rule), a failure this codebase raised itself+ * keeps what it knows, and the write it is about comes back with it (the section holds one+ * refusal at a time, and which write it was is what a reader retries).+ */+import { afterEach, describe, expect, it } from "vitest";+import { ApiError } from "../src/api/client";+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";+import { en as EN } from "../src/lib/strings-en";+import { memberWriteRefused } from "../src/lib/member-write-refusal";++afterEach(() => {+ setActiveStrings(ZH);+});++describe("memberWriteRefused", () => {+ it("names the account and reads the refusal through its code's own sentence", () => {+ const refusal = memberWriteRefused(+ { kind: "add", userId: "ghost" },+ new ApiError(404, "user_not_found", "User does not exist: ghost."),+ );+ expect(refusal.write).toEqual({ kind: "add", userId: "ghost" });+ expect(refusal.text).not.toContain("User does not exist");+ expect(refusal.text).toBe(+ S.project.memberAddRefused("ghost", S.errors.byCode.user_not_found as string),+ );+ expect(refusal.text).toContain("ghost");+ });++ it("says which direction was refused: a removal is not called an addition", () => {+ const add = memberWriteRefused(+ { kind: "add", userId: "bob" },+ new ApiError(409, "already_member", "already"),+ );+ const remove = memberWriteRefused(+ { kind: "remove", userId: "bob" },+ new ApiError(404, "member_not_found", "no such member"),+ );+ expect(remove.text).not.toBe(add.text);+ expect(remove.text).toBe(+ S.project.memberRemoveRefused("bob", S.errors.byCode.member_not_found as string),+ );+ });++ it("keeps what a failure that never reached the route has to say", () => {+ expect(+ memberWriteRefused({ kind: "add", userId: "carol" }, new Error("Failed to fetch")).text,+ ).toBe(S.project.memberAddRefused("carol", "Failed to fetch"));+ });++ it("falls back to the generic text when the value has nothing to say", () => {+ expect(memberWriteRefused({ kind: "remove", userId: "dan" }, undefined).text).toBe(+ S.project.memberRemoveRefused("dan", S.common.unknownError),+ );+ });++ it("speaks the language the interface is in, not the one it was built in", () => {+ setActiveStrings(EN);+ expect(memberWriteRefused({ kind: "add", userId: "eve" }, new Error("boom")).text).toBe(+ EN.project.memberAddRefused("eve", "boom"),+ );+ });+});