A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 加入频道的确认框被拒时留着,原因也留在框里(7.43)
lmliheng40bf72037abd
diff --git a/changelog/unreleased/2026-10-25-channel-join-refusal.md b/changelog/unreleased/2026-10-25-channel-join-refusal.mdnew file mode 100644index 00000000..c5ee26dc--- /dev/null+++ b/changelog/unreleased/2026-10-25-channel-join-refusal.md@@ -0,0 +1,42 @@+# Channels: a refused join keeps its question — and the reason++- **Date:** 2026-10-25+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-10-25-channel-join-refusal.zh.md)++Joining a channel is asked in one confirmation card reached from two places: the channel view's+"you are not a member" notice and the sidebar row's hover action under "Other channels". Both used+to close the card before the write landed, so a refusal left the server's words in a toast that+dismissed itself after a few seconds and floated above a page that had not changed — the buttons+came alive again and nothing said why the reader was still not in.++The card now closes only on the path where its join landed; a refusal draws the server's words+inside the card, right above the retry button (`ConfirmModal`'s `refusal` slot, the app's existing+"Refused:" lead-in). Opening the card again drops the previous reason, which belonged to the+attempt it named; a write in flight takes one press only, and cancelling decides nothing.++## Details++- `features/company/channel-dialogs.tsx`: the shared `JoinChannelConfirm` takes an optional+ `refusal` and hands it to `ConfirmModal`'s slot (with no reason, the slot is not drawn at all).+- `features/company/channel-view.tsx`: `join()` no longer closes the card before the `await`; the+ success path closes it and clears the reason, a refusal keeps the server's words in+ `joinRefusal`. The notice's Join button clears the previous reason before it opens the card; the+ card's `onClose` stops answering while a write is out (a second line behind the `busy` dimming);+ switching channels clears it too.+- `features/company/channel-sidebar.tsx`: the row's `join()` moves `setPendingJoin(null)` after the+ success as well and keeps a refusal in `joinRefusal`; the row clears the previous reason before+ opening the card, and the card's `onClose` stops answering while a write is out.+- New browser tests `e2e/channel-join-refusal.spec.mjs` (two, one per entry point): with+ `POST …/channels/<channel>/members` refused at `page.route` 500, the card, its sentence and the+ roster on the server all stay (nothing in the notification region carries the words); cancelling+ and reopening shows no stale reason; the retry on the same card really joins — the card closes,+ the roster holds the reader, and both the notice strip and the row's Join action are gone.++## Compatibility++- No interface, wire-format, stored-data or dependency change: only *when* this card closes and+ *where* the reason is drawn. No new copy beyond the existing `S.common.refused` lead-in.diff --git a/changelog/unreleased/2026-10-25-channel-join-refusal.zh.md b/changelog/unreleased/2026-10-25-channel-join-refusal.zh.mdnew file mode 100644index 00000000..03ae6785--- /dev/null+++ b/changelog/unreleased/2026-10-25-channel-join-refusal.zh.md@@ -0,0 +1,36 @@+# 频道:加入被拒时,确认框留着,原因也留在框里++- **Date:** 2026-10-25+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-25-channel-join-refusal.md)++加入频道的那张确认框有两个入口 —— 频道页「你还不是这个频道的成员」那条提示里的「加入」,和侧栏+「其他频道」那一行悬停时露出的「加入」—— 它们问的是同一张框。过去这两处都在写入之前就把框关掉,被拒+时服务端原话只落进一条几秒后自己消失、还浮在页面上的通知里:页面一点没变,读者只看到按钮又亮了,为什+么没加进去却得凭那条一闪而过的通知去想。++现在关框只发生在加入落地那条路径上;被拒时服务端原话画进框里、重试按钮正上方(`ConfirmModal` 的+`refusal` 槽,用的是应用既有的「操作被拒绝:」前缀)。重开这张框会先清掉上一次的原因 —— 那句话属于上次+那次尝试;一个写入在途时只认一次点击,取消不决定任何事。++## 细节++- `features/company/channel-dialogs.tsx`:两个入口共用的 `JoinChannelConfirm` 多一个可选 `refusal`,+ 原样交给 `ConfirmModal` 的那个槽(没有原因时槽根本不画)。+- `features/company/channel-view.tsx`:`join()` 不再在 `await` 之前 `setConfirmJoin(false)`;成功那条+ 路径才关框并清原因,失败把服务端原话留在 `joinRefusal` 里。提示条里那枚「加入」开框前先清掉旧原因;+ 框的 `onClose` 在写入在途时不再响应(`busy` 置灰之外的第二道);换频道时一并清掉。+- `features/company/channel-sidebar.tsx`:侧栏那行 `join()` 同样把 `setPendingJoin(null)` 挪到成功之后,+ 失败留在 `joinRefusal` 里;行的「加入」开框前清旧原因,框的 `onClose` 在写入在途时不再响应。+- 新增浏览器用例 `e2e/channel-join-refusal.spec.mjs`(两条,两个入口各一条):用 `page.route` 把+ `POST …/channels/<频道>/members` 拒成 500 之后,框、框里那句话与服务端上的成员表都不变(通知区里没有+ 那句原话);取消后重开不带旧原因;在同一张框上重试才真正加入 —— 框关掉、成员表里有这个人、提示条与+ 侧栏那行的「加入」都消失。++## 兼容性++- 没有接口、传输格式、已存数据或依赖变化:只改了这张框「什么时候关」与「原因画在哪」。除既有的+ `S.common.refused` 前缀外没有新文案。diff --git a/packages/web/e2e/channel-join-refusal.spec.mjs b/packages/web/e2e/channel-join-refusal.spec.mjsnew file mode 100644index 00000000..190a19d6--- /dev/null+++ b/packages/web/e2e/channel-join-refusal.spec.mjs@@ -0,0 +1,247 @@+/**+ * Regression: joining a channel is asked in a confirmation card, and a refused join keeps that+ * question — with the server's words inside it — instead of leaving only a toast behind.+ *+ * Both entry points into joining (`features/company/channel-view.tsx`'s "you are not a member"+ * notice and `features/company/channel-sidebar.tsx`'s row action) raise the one card in+ * `channel-dialogs.tsx`. Each used to close it before the write landed, so a refusal left the+ * reason in a toast that dismissed itself after a few seconds — on top of a page that had not+ * changed, with the Join button live again and nothing saying why. The card now goes only once+ * its join landed; a refusal leaves it standing with the reason drawn under its sentence+ * (`ConfirmModal`'s `refusal` slot), and reopening it does not carry the old reason.+ *+ * The organization and its channel are made through the API rather than through the dialogs:+ * this spec is about the confirmation, not about creation. The channel is made by the reader and+ * then left through the API, so the reader is a non-member who may read it — which is what puts+ * a Join action in front of them. Company mode is off on a fresh server, so each test turns the+ * admin master switch on first (idempotent), and the Project gets the mock as its model so the+ * onboarding overlay stays off the page.+ */+import { test, expect, request } from "@playwright/test";+import { ADMIN_ID, ADMIN_PASSWORD, login, provisionAndLogin } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;+const P = "password123";+const ORG = "chanjoinrefuse";+const CHANNEL = "site";+const NAME = "站点上线";+/** The notice strip the channel view shows a non-member; its Join button sits at its end. */+const NOT_MEMBER = "你还不是这个频道的成员";++/** The refusal the page paints; a 500 with its own words proves those words came back. */+const REFUSAL = { code: "channel_members_locked", message: "the channel roster is mid-rewrite" };++/** The admin master switch, off by default: turned on server-wide before the flow starts. */+async function enableCompanyMode() {+ const adminCtx = await request.newContext();+ try {+ await login(adminCtx, ADMIN_ID, ADMIN_PASSWORD);+ const res = await adminCtx.put(`${BASE}/api/admin/settings`, { data: { companyMode: true } });+ if (!res.ok()) {+ throw new Error(`enable company mode failed: ${res.status()} ${await res.text()}`);+ }+ } finally {+ await adminCtx.dispose();+ }+}++/**+ * A fresh user with mock-model credentials, an organization with its CEO, one channel holding+ * both — and then the reader taken back out of it, so the sidebar files it under "其他频道" and+ * the view offers Join. Returns the ids and a reader over the channel as stored.+ */+async function setUp(page, tag) {+ await enableCompanyMode();+ const user = `${tag}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;+ await provisionAndLogin(page.request, user, P);+ const project = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0];+ const projectId = project.projectId;+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {+ data: {+ defaultModel: { provider: "custom", modelId: "claude-4-8" },+ models: [+ {+ provider: "custom",+ modelId: "claude-4-8",+ apiKey: "sk-mock",+ baseUrl: MOCK,+ contextWindow: 200000,+ },+ ],+ },+ });+ expect(put.ok(), `put models ${projectId}`).toBeTruthy();++ const orgBase = `${BASE}/api/projects/${projectId}/organizations`;+ const created = await page.request.post(orgBase, {+ data: { orgId: ORG, mission: "Publish the plugin marketplace and reach the top of search." },+ });+ expect(created.ok(), "create organization").toBeTruthy();++ // The creator is the channel's first member; the CEO is invited so the roster holds somebody+ // the reader leaves behind (a channel nobody is in is a different question).+ const channel = await page.request.post(`${orgBase}/${ORG}/channels`, {+ data: { channelId: CHANNEL, name: NAME, purpose: "站点从零到上线的一切" },+ });+ expect(channel.ok(), "create channel").toBeTruthy();+ const invited = await page.request.post(`${orgBase}/${ORG}/channels/${CHANNEL}/members`, {+ data: { principal: `agent:${ORG}_ceo` },+ });+ expect(invited.ok(), "invite the CEO").toBeTruthy();++ const channelUrl = `${orgBase}/${ORG}/channels/${CHANNEL}`;+ const detail = await (await page.request.get(channelUrl)).json();+ const me = detail.members.map((m) => m.principal).find((p) => p.startsWith("user:"));+ expect(me, "the reader is a member").toBeTruthy();+ const left = await page.request.delete(`${channelUrl}/members/${encodeURIComponent(me)}`);+ expect(left.status(), "leave the channel as its creator").toBe(204);++ /** The channel as the server holds it: its roster and whether the reader is on it. */+ const stored = async () => await (await page.request.get(channelUrl)).json();+ expect((await stored()).isMember, "the reader is not a member").toBe(false);+ return { projectId, channelUrl, me, stored };+}++/** Open the channel: the header sits above its stream. */+async function openChannel(page, projectId) {+ await page.goto(`/org/${projectId}/${ORG}/channels/${CHANNEL}`);+ await expect(page.getByRole("heading", { name: new RegExp(NAME) })).toBeVisible();+}++/** The channel view's notice strip — the non-member's own Join lives at its end. */+function notMemberStrip(page) {+ return page.getByText(NOT_MEMBER, { exact: false }).locator("..");+}++/**+ * The card's own text with the refusal line dropped: a refused write adds one line under the+ * sentence ("操作被拒绝:…"), and that line is the only thing the refusal may change.+ */+async function cardText(card) {+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");+}++/**+ * Refuse every join the page attempts, counting them: the write is one POST to the channel's+ * `/members`, and a 500 with its own words is how the test knows whose words came back.+ */+async function refuseJoins(page, projectId, seen) {+ await page.route(+ `**/api/projects/${projectId}/organizations/${ORG}/channels/${CHANNEL}/members`,+ async (route) => {+ if (route.request().method() !== "POST") return route.fallback();+ seen.push(route.request().url());+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ },+ );+ return `**/api/projects/${projectId}/organizations/${ORG}/channels/${CHANNEL}/members`;+}++test("a refused join from the channel view keeps the card, its sentence and the roster", async ({+ page,+}) => {+ const { projectId, me, stored } = await setUp(page, "r128view");+ await openChannel(page, projectId);++ const joins = [];+ const pattern = await refuseJoins(page, projectId, joins);++ await notMemberStrip(page).getByRole("button", { name: "加入", exact: true }).click();+ const card = page.getByRole("dialog", { name: "加入频道" });+ await expect(card).toBeVisible();+ const sentence = await cardText(card);+ expect(sentence).toContain("加入后你会收到这个频道里 @你 的消息");++ await card.getByRole("button", { name: "加入", exact: true }).click();++ // The reason is in the card that asked, and it is not a toast: the notification region (which+ // may still hold the company beta's own notice) never carries the server's words, and the card+ // reads exactly as before plus the one line.+ await expect(card.getByText(REFUSAL.message)).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(REFUSAL.message);+ expect(joins).toHaveLength(1);+ await expect(card).toBeVisible();+ expect(await cardText(card)).toBe(sentence);++ // Nothing was written: the reader is still off the roster, so the view still offers Join.+ expect((await stored()).members.map((m) => m.principal)).not.toContain(me);+ await expect(notMemberStrip(page)).toBeVisible();++ // Closing the card decides nothing, and reopening it does not carry the old reason.+ await card.getByRole("button", { name: "取消" }).click();+ await expect(card).toHaveCount(0);+ await notMemberStrip(page).getByRole("button", { name: "加入", exact: true }).click();+ const again = page.getByRole("dialog", { name: "加入频道" });+ await expect(again).toBeVisible();+ await expect(again.getByText(REFUSAL.message)).toHaveCount(0);+ expect(await again.innerText()).toBe(sentence);++ // The retry lands: the card goes, the roster holds the reader, and the Join strip is gone.+ await page.unroute(pattern);+ await again.getByRole("button", { name: "加入", exact: true }).click();+ await expect(again).toHaveCount(0);+ await expect.poll(async () => (await stored()).isMember).toBe(true);+ expect((await stored()).members.map((m) => m.principal)).toContain(me);+ await expect(page.getByText(NOT_MEMBER, { exact: false })).toHaveCount(0);+});++test("a refused join from the sidebar keeps the card, its sentence and the roster", async ({+ page,+}) => {+ const { projectId, me, stored } = await setUp(page, "r128side");+ await openChannel(page, projectId);++ // The reader is not in it, so its row sits under "其他频道" with the hover-only Join action.+ const row = page.getByRole("link", { name: NAME, exact: true });+ await expect(row).toBeVisible();+ await row.hover();+ const rowJoin = row.locator("xpath=..").getByRole("button", { name: "加入", exact: true });+ await expect(rowJoin).toBeVisible();++ const joins = [];+ const pattern = await refuseJoins(page, projectId, joins);++ await rowJoin.click();+ const card = page.getByRole("dialog", { name: "加入频道" });+ await expect(card).toBeVisible();+ const sentence = await cardText(card);+ expect(sentence).toContain("加入后你会收到这个频道里 @你 的消息");++ await card.getByRole("button", { name: "加入", exact: true }).click();++ await expect(card.getByText(REFUSAL.message)).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(REFUSAL.message);+ expect(joins).toHaveLength(1);+ await expect(card).toBeVisible();+ expect(await cardText(card)).toBe(sentence);++ // Nothing was written: the reader is still off the roster and the row still offers Join.+ expect((await stored()).members.map((m) => m.principal)).not.toContain(me);+ await expect(page.getByText(NOT_MEMBER, { exact: false })).toBeVisible();++ // Closing the card decides nothing, and reopening it does not carry the old reason.+ await card.getByRole("button", { name: "取消" }).click();+ await expect(card).toHaveCount(0);+ await row.hover();+ await rowJoin.click();+ const again = page.getByRole("dialog", { name: "加入频道" });+ await expect(again).toBeVisible();+ await expect(again.getByText(REFUSAL.message)).toHaveCount(0);+ expect(await again.innerText()).toBe(sentence);++ // The retry lands: the card goes, the roster holds the reader, and the row is no longer one to+ // join — the listing reloads and the view's own Join strip goes with it.+ await page.unroute(pattern);+ await again.getByRole("button", { name: "加入", exact: true }).click();+ await expect(again).toHaveCount(0);+ await expect.poll(async () => (await stored()).isMember).toBe(true);+ expect((await stored()).members.map((m) => m.principal)).toContain(me);+ await expect(page.getByText(NOT_MEMBER, { exact: false })).toHaveCount(0);+ await row.hover();+ await expect(rowJoin).toHaveCount(0);+});diff --git a/packages/web/src/features/company/channel-dialogs.tsx b/packages/web/src/features/company/channel-dialogs.tsxindex 3f310277..2b298f60 100644--- a/packages/web/src/features/company/channel-dialogs.tsx+++ b/packages/web/src/features/company/channel-dialogs.tsx@@ -265,17 +265,24 @@ export function ChannelTextDialog({* "Join this channel?". Joining is not a destructive act but it is a standing one: from then* on this channel's @-mentions reach the reader, which is what the body says rather than* "are you sure".+ *+ * A refused join keeps the card standing with the server's words inside it (`refusal`), next to+ * the button that retries it: the toast both entry points used to raise dismissed itself out of+ * the card the reader was still looking at.*/export function JoinChannelConfirm({open,busy,onClose,onConfirm,+ refusal,}: {open: boolean;busy: boolean;onClose: () => void;onConfirm: () => void;+ /** The server's words for a refused join; absent (not empty) when nothing was refused. */+ refusal?: string;}) {return (<ConfirmModal@@ -287,6 +294,7 @@ export function JoinChannelConfirm({busy={busy}onClose={onClose}onConfirm={onConfirm}+ {...(refusal !== undefined ? { refusal } : {})}><p className="text-sm text-gray-600 dark:text-gray-300">{S.company.channels.joinConfirm}</p></ConfirmModal>diff --git a/packages/web/src/features/company/channel-sidebar.tsx b/packages/web/src/features/company/channel-sidebar.tsxindex 2145d3b5..841b28a7 100644--- a/packages/web/src/features/company/channel-sidebar.tsx+++ b/packages/web/src/features/company/channel-sidebar.tsx@@ -2,7 +2,8 @@* Company mode's channel list — the sidebar block that stands where development mode lists* conversations, and the collapsed rail's icon-only twin. The all-hands channel is pinned at* the top under its localized label, then the channels the person is in, then the ones it is- * not (each with a Join action, which asks first — people may join any channel), then the+ * not (each with a Join action, which asks first — people may join any channel — and whose+ * card keeps a refusal inside it, next to the button that retries), then the* archived ones folded away. A row carries its unread count and, when a message names the* reader, an "@me" chip.*@@ -27,7 +28,6 @@ import {SkeletonList,Text,railItemClass,- toastError,toastSuccess,} from "@adelie/ui";import * as api from "../../api/endpoints";@@ -202,22 +202,27 @@ export function ChannelSidebar({const [joining, setJoining] = useState<string | null>(null);/** The channel whose Join was clicked, waiting on the prompt; null when nothing is asked. */const [pendingJoin, setPendingJoin] = useState<OrgChannelItem | null>(null);+ /** The server's own words for a refused join, drawn in the card that asked, next to its retry. */+ const [joinRefusal, setJoinRefusal] = useState<string | null>(null);const channels = company.channels;const join = async (channel: OrgChannelItem) => {if (joining !== null) return;setJoining(channel.channelId);- setPendingJoin(null);try {await api.addOrgChannelMember(projectId, orgId, channel.channelId, {principal: `user:${user?.userId ?? ""}`,});+ // The card goes with its own join landing, never before: a refusal has to stay readable+ // next to the button that retries it.+ setPendingJoin(null);+ setJoinRefusal(null);toastSuccess(S.company.channels.joined);// The listing is what the open channel's view watches to re-read its own detail, so// this one reload replaces the Join prompt there too (channel-stream.joinedElsewhere).await company.reloadChannels();} catch (e) {- toastError(apiErrorText(e));+ setJoinRefusal(apiErrorText(e));} finally {setJoining(null);}@@ -231,7 +236,15 @@ export function ChannelSidebar({orgId={orgId}channel={channel}{...(onNavigate ? { onNavigate } : {})}- {...(joinable ? { join: () => setPendingJoin(channel) } : {})}+ {...(joinable+ ? {+ join: () => {+ // A new question, not the last one: the previous refusal is not its answer.+ setJoinRefusal(null);+ setPendingJoin(channel);+ },+ }+ : {})}/>);@@ -299,10 +312,13 @@ export function ChannelSidebar({<JoinChannelConfirmopen={pendingJoin !== null}busy={joining !== null}- onClose={() => setPendingJoin(null)}+ onClose={() => {+ if (joining === null) setPendingJoin(null);+ }}onConfirm={() => {if (pendingJoin !== null) void join(pendingJoin);}}+ {...(joinRefusal !== null ? { refusal: S.common.refused(joinRefusal) } : {})}/></>);diff --git a/packages/web/src/features/company/channel-view.tsx b/packages/web/src/features/company/channel-view.tsxindex 9f1e91d8..3b618de7 100644--- a/packages/web/src/features/company/channel-view.tsx+++ b/packages/web/src/features/company/channel-view.tsx@@ -29,7 +29,8 @@** A channel the reader has not joined offers Join instead of the composer — people may read* every channel but post only in the ones they are in; joining asks first, because it is what- * puts this channel's @-mentions in front of the reader from then on. An archived channel says+ * puts this channel's @-mentions in front of the reader from then on, and a refused join keeps+ * that card standing with the server's words inside it. An archived channel says* it is read-only. Only the messages are essential: the chart and the Project's member list feed* names and the invite picker, so a hiccup there degrades names to ids rather than blocking* the page.@@ -125,6 +126,8 @@ export function ChannelView() {const [loadingEarlier, setLoadingEarlier] = useState(false);const [joining, setJoining] = useState(false);const [confirmJoin, setConfirmJoin] = useState(false);+ /** The server's own words for a refused join, drawn in the card that asked, next to its retry. */+ const [joinRefusal, setJoinRefusal] = useState<string | null>(null);/** Messages that arrived while the view was scrolled up; shown on the pill. */const [pendingNew, setPendingNew] = useState(0);const [showJump, setShowJump] = useState(false);@@ -160,6 +163,7 @@ export function ChannelView() {setDetailError(null);setPendingNew(0);setConfirmJoin(false);+ setJoinRefusal(null);markedRef.current = null;firstDayRef.current = null;listedMemberRef.current = null;@@ -375,14 +379,17 @@ export function ChannelView() {const join = async () => {if (joining) return;setJoining(true);- setConfirmJoin(false);try {await api.addOrgChannelMember(projectId, orgId, channelId, { principal: myPrincipal });+ // The card goes with its own join landing, never before: a refusal has to stay readable+ // next to the button that retries it.+ setConfirmJoin(false);+ setJoinRefusal(null);toastSuccess(S.company.channels.joined);await loadDetail();void company.reloadChannels();} catch (e) {- toastError(apiErrorText(e));+ setJoinRefusal(apiErrorText(e));} finally {setJoining(false);}@@ -706,7 +713,11 @@ export function ChannelView() {size="sm"variant="primary"disabled={joining}- onClick={() => setConfirmJoin(true)}+ onClick={() => {+ // A new question, not the last one: the previous refusal is not its answer.+ setJoinRefusal(null);+ setConfirmJoin(true);+ }}>{joining ? S.company.channels.joining : S.company.channels.join}</Button>@@ -717,8 +728,11 @@ export function ChannelView() {<JoinChannelConfirmopen={confirmJoin}busy={joining}- onClose={() => setConfirmJoin(false)}+ onClose={() => {+ if (!joining) setConfirmJoin(false);+ }}onConfirm={() => void join()}+ {...(joinRefusal !== null ? { refusal: S.common.refused(joinRefusal) } : {})}/></div></ChannelReaderProvider>