A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 组织日历的保存与删除确认框被拒时留着,原因也留在框里(7.37)
lmliheng3e142b9f4d8c
diff --git a/changelog/unreleased/2026-10-24-calendar-refusal.md b/changelog/unreleased/2026-10-24-calendar-refusal.mdnew file mode 100644index 00000000..82a929c1--- /dev/null+++ b/changelog/unreleased/2026-10-24-calendar-refusal.md@@ -0,0 +1,37 @@+# Calendar: a refused save or delete keeps its question — and the reason++- **Date:** 2026-10-24+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-10-24-calendar-refusal.zh.md)++The organization calendar asks before every write: saving an event rewrites its schedule file, and+deleting one removes it from the rota. The save card used to close on the way into its request's+`catch` — the event was still the one stored, but the reason arrived as a toast that dismissed+itself after a few seconds and sat over the card rather than in it. The delete card stayed open,+yet its reason went into that same toast.++Both cards now close only once their write landed. A refusal leaves the card standing with the+server's words drawn under its sentence (`ConfirmModal`'s `refusal` slot, the app's existing+"Refused:" lead-in), so the retry is the button that was pressed; cancelling lands back on the form+with the values that were refused, and opening either card again drops the previous reason, which+belonged to the attempt it named.++## Details++- `features/company/calendar-page.tsx`: `save()` no longer calls `setConfirmSave(false)` in its+ `catch` — it keeps the server's words in `saveRefusal`, and `remove()` keeps its own in+ `deleteRefusal`; both are rendered through `S.common.refused` into the card that asked. Both+ writes bail out while one is in flight (the cards' buttons are already disabled by `busy`). The+ form's Save and Delete buttons clear the refusal of the card they are about to open.+- New browser test `e2e/calendar-refusal.spec.mjs` (2 cases, one per card): with the write refused+ at `page.route` 500, the card, its sentence and the stored event all stay (nothing to dismiss in+ the notification region); reopening shows no stale reason; the retry on the same card writes it+ — the card and the form close, and the server shows the edit / the missing event.++## Compatibility++- No interface, wire-format, stored-data or dependency change: only *when* the two cards close and+ *where* the reason is drawn. No new copy beyond the existing `S.common.refused` lead-in.diff --git a/changelog/unreleased/2026-10-24-calendar-refusal.zh.md b/changelog/unreleased/2026-10-24-calendar-refusal.zh.mdnew file mode 100644index 00000000..7075558a--- /dev/null+++ b/changelog/unreleased/2026-10-24-calendar-refusal.zh.md@@ -0,0 +1,31 @@+# 日历:保存或删除被拒时,框留着,原因也留在框里++- **Date:** 2026-10-24+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-24-calendar-refusal.md)++组织日历的每一笔写入都先问一句:保存一条日程会改写它的日程文件,删除会把它从排班里拿走。保存那张框过去+在请求进 `catch` 的路上就把自己关掉了 —— 日程还是原来那一条,原因却落进一条几秒后自己消失、还浮在框上方+的通知里。删除那张框倒是留着,原因同样只进了那条通知。++现在两张框都只在自己的写入落地之后才关。被拒时框留着,服务端的原话画在它自己那句话下面(`ConfirmModal` 的+`refusal` 槽,用的是应用既有的「操作被拒绝:」前缀),重试就是刚才按下的那个按钮;取消则回到表单,被拒的值+还在;重开任何一张框都会先清掉上一次的原因 —— 那句话属于上次那次尝试。++## 细节++- `features/company/calendar-page.tsx`:`save()` 不再在 `catch` 里 `setConfirmSave(false)`,而是把服务端+ 原话留在 `saveRefusal` 里;`remove()` 把自己的留在 `deleteRefusal` 里。两者都经 `S.common.refused` 画进+ 提问的那张框。两个写入在另一个写入在途时都不再发(框上两个按钮本来就被 `busy` 置灰)。表单上的「保存」与+ 「删除日程」在打开各自的框之前先清掉上一次的原因。+- 新增浏览器用例 `e2e/calendar-refusal.spec.mjs`(2 条,一张框一条):用 `page.route` 把写入拒成 500 之后,+ 框、框里那句话与服务端上的日程都不变(通知区没有可点的按钮),重开不带旧原因;在同一张框上重试才真正写入+ —— 框与表单都关掉,服务端上是改后的内容 / 已经不存在的那条日程。++## 兼容性++- 没有接口、传输格式、已存数据或依赖变化:只改了这两张框「什么时候关」与「原因画在哪」。除既有的+ `S.common.refused` 前缀外没有新文案。diff --git a/packages/web/e2e/calendar-refusal.spec.mjs b/packages/web/e2e/calendar-refusal.spec.mjsnew file mode 100644index 00000000..da7f7d82--- /dev/null+++ b/packages/web/e2e/calendar-refusal.spec.mjs@@ -0,0 +1,244 @@+/**+ * Regression: the organization calendar asks before every write, and a refused write keeps that+ * question — with the server's words inside it — instead of leaving only a toast.+ *+ * Both cards on `features/company/calendar-page.tsx` used to be dismissed by their own request+ * rather than by its outcome: the save card closed on the way into `catch` (the event was still+ * the one stored, but the reason arrived as a toast that dismissed itself after six seconds and+ * sat over the card rather than in it), and the delete card stayed open while its reason fell+ * into that same toast. Both now close only once their write landed; a refusal leaves the card+ * standing with the refusal drawn under its sentence (`ConfirmModal`'s `refusal` slot), so the+ * retry is the button that was pressed and cancelling lands back on the form with the values+ * that were refused.+ *+ * The organization and its event are made through the API rather than through the dialogs: this+ * spec is about the two confirmations, not about creation. 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 = "calrefuse";+/** The event file's name (and the dialog's subject); the chip shows its title instead. */+const EVENT = "probe_standup";+const TITLE = "站会";+const PROMPT = "检查看板,推进自己的工单";+const EDITED = "检查看板,推进工单并在频道汇报";++/** The writes the page makes; a 500 with its own words proves the reason came back. */+const SAVE_REFUSAL = { code: "calendar_store_locked", message: "calendar store is locked" };+const DELETE_REFUSAL = { code: "calendar_rota_busy", message: "the rota 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, and one calendar+ * event on that CEO. Returns the ids and small readers over the server's own state.+ */+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 org = `${BASE}/api/projects/${projectId}/organizations/${ORG}`;+ const created = await page.request.post(`${BASE}/api/projects/${projectId}/organizations`, {+ data: { orgId: ORG, mission: "Publish the plugin marketplace and reach the top of search." },+ });+ expect(created.ok(), "create organization").toBeTruthy();++ const event = await page.request.post(`${org}/calendar`, {+ data: {+ agentId: `${ORG}_ceo`,+ name: EVENT,+ title: TITLE,+ prompt: PROMPT,+ enabled: true,+ startAt: new Date(Date.now() + 2 * 3600_000).toISOString(),+ period: "1d",+ },+ });+ expect(event.ok(), "create calendar event").toBeTruthy();++ /** The stored event, or null once it is gone. */+ const stored = async () => {+ const res = await page.request.get(`${org}/calendar/${ORG}_ceo/${EVENT}`);+ return res.status() === 200 ? await res.json() : null;+ };+ return { projectId, org, stored };+}++/** Open the calendar and the event's edit dialog by clicking its chip (the month view holds it). */+async function openEvent(page, projectId) {+ await page.goto(`/org/${projectId}/${ORG}/calendar`);+ // A chip is named by its time and title ("17:07 站会"), one per day the event recurs on; the+ // legend row also carries the title but names the employee and the cadence around it.+ const chip = page.getByRole("button", { name: new RegExp(`^\\d{2}:\\d{2} ${TITLE}$`) }).first();+ await expect(chip).toBeVisible();+ await chip.click();+ const edit = page.getByRole("dialog", { name: `编辑日程「${EVENT}」` });+ await expect(edit).toBeVisible();+ return edit;+}++/**+ * 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]*/, "");+}++test("a refused save keeps the card, its sentence and the stored event", async ({ page }) => {+ const { projectId, org, stored } = await setUp(page, "r122save");+ const before = await stored();+ expect(before?.prompt).toBe(PROMPT);++ const edit = await openEvent(page, projectId);+ // The write has to be a real change, so the refused values are visibly not the stored ones.+ await edit.getByRole("textbox", { name: /^提示词/ }).fill(EDITED);++ const writes = [];+ await page.route(+ `**/api/projects/${projectId}/organizations/${ORG}/calendar/**`,+ async (route) => {+ if (route.request().method() !== "PUT") return route.fallback();+ writes.push(route.request().url());+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: SAVE_REFUSAL }),+ });+ },+ );++ await edit.getByRole("button", { name: "保存", exact: true }).click();+ const card = page.getByRole("dialog", { name: "保存修改" });+ await expect(card).toBeVisible();+ const sentence = await card.innerText();+ expect(sentence).toContain(`保存日程「${EVENT}」`);++ 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 holds+ // no dismissible button, and the card reads exactly as before plus the one line.+ await expect(card.getByText(SAVE_REFUSAL.message)).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);+ expect(writes).toHaveLength(1);+ await expect(card).toBeVisible();+ expect(await cardText(card)).toBe(sentence);++ // Nothing was written: the event is still the one the server had, and the form behind the+ // card still holds what was refused.+ expect((await stored())?.prompt).toBe(PROMPT);+ await expect(edit).toBeVisible();+ await expect(edit.getByRole("textbox", { name: /^提示词/ })).toHaveValue(EDITED);++ // 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 edit.getByRole("button", { name: "保存", exact: true }).click();+ const again = page.getByRole("dialog", { name: "保存修改" });+ await expect(again).toBeVisible();+ await expect(again.getByText(SAVE_REFUSAL.message)).toHaveCount(0);+ expect(await again.innerText()).toBe(sentence);++ // Let the retry through on the same card: it lands, the card and the form both go, and the+ // stored event is the edit.+ await page.unroute(`**/api/projects/${projectId}/organizations/${ORG}/calendar/**`);+ await again.getByRole("button", { name: "保存", exact: true }).click();+ await expect(again).toHaveCount(0);+ await expect(edit).toHaveCount(0);+ await expect.poll(async () => (await stored())?.prompt).toBe(EDITED);++ // The open API also lists it: the event is on the calendar, not merely in a file.+ const calendar = await (await page.request.get(`${org}/calendar`)).json();+ expect(calendar.events.some((e) => e.name === EVENT && e.prompt === EDITED)).toBe(true);+});++test("a refused delete keeps the card, its sentence and the event", async ({ page }) => {+ const { projectId, org, stored } = await setUp(page, "r122del");+ expect((await stored())?.prompt).toBe(PROMPT);++ const edit = await openEvent(page, projectId);+ await edit.getByRole("button", { name: "删除日程", exact: true }).click();+ const card = page.getByRole("dialog", { name: "删除日程" });+ await expect(card).toBeVisible();+ const sentence = await card.innerText();+ expect(sentence).toContain(`确认删除日程「${EVENT}」`);++ const deletes = [];+ await page.route(+ `**/api/projects/${projectId}/organizations/${ORG}/calendar/**`,+ async (route) => {+ if (route.request().method() !== "DELETE") return route.fallback();+ deletes.push(route.request().url());+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: DELETE_REFUSAL }),+ });+ },+ );++ await card.getByRole("button", { name: "删除", exact: true }).click();+ await expect(card.getByText(DELETE_REFUSAL.message)).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);+ expect(deletes).toHaveLength(1);+ await expect(card).toBeVisible();+ expect(await cardText(card)).toBe(sentence);++ // Nothing was deleted, and the form behind the card is still the one that asked.+ expect((await stored())?.prompt).toBe(PROMPT);+ await expect(edit).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 edit.getByRole("button", { name: "删除日程", exact: true }).click();+ const again = page.getByRole("dialog", { name: "删除日程" });+ await expect(again).toBeVisible();+ await expect(again.getByText(DELETE_REFUSAL.message)).toHaveCount(0);+ expect(await again.innerText()).toBe(sentence);++ // The retry lands: card and form both go, and the event is gone from the server.+ await page.unroute(`**/api/projects/${projectId}/organizations/${ORG}/calendar/**`);+ await again.getByRole("button", { name: "删除", exact: true }).click();+ await expect(again).toHaveCount(0);+ await expect(edit).toHaveCount(0);+ await expect.poll(stored).toBeNull();+ const calendar = await (await page.request.get(`${org}/calendar`)).json();+ expect(calendar.events.some((e) => e.name === EVENT)).toBe(false);+});diff --git a/packages/web/src/features/company/calendar-page.tsx b/packages/web/src/features/company/calendar-page.tsxindex 28a2c6b8..7481b3e6 100644--- a/packages/web/src/features/company/calendar-page.tsx+++ b/packages/web/src/features/company/calendar-page.tsx@@ -9,7 +9,9 @@* the grid plus an error strip when a refetch fails. A month cell shows a few chips and folds* the rest into a button that opens the whole day in a popover rather than the create dialog.* Past instances carry the outcome the scheduler recorded; every write confirms first, and- * reports back whatever the server has to say about the rota.+ * reports back whatever the server has to say about the rota. A confirmation that asked for a+ * write is dismissed by that write landing: when the server refuses one, its words stay inside+ * the card (`ConfirmModal`'s `refusal` slot) and the retry is the button that was pressed.** An empty slot — a month cell, an hour row — is itself the control that creates there, and it* says so: a real button (CREATE_SLOT_CLASS) that tints with the theme's accent and spells out@@ -203,6 +205,13 @@ export function CalendarPage() {>({});const [confirmSave, setConfirmSave] = useState(false);const [deleting, setDeleting] = useState<{ agentId: string; name: string } | null>(null);+ /**+ * The reason the last save / delete was refused, drawn inside the card that asked for it (see+ * `save` / `remove`). Two states rather than one: the two cards can only be open one at a time,+ * but a refusal belongs to the sentence that was refused.+ */+ const [saveRefusal, setSaveRefusal] = useState<string | null>(null);+ const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);const [busy, setBusy] = useState(false);const scrollRef = useRef<HTMLDivElement>(null);// The empty-calendar note goes away for good once read; the page's "?" carries the same@@ -306,8 +315,15 @@ export function CalendarPage() {return Object.keys(next).length === 0;};+ /**+ * The save card closes only once the write landed. A refusal leaves it standing with the+ * server's words under its sentence (`ConfirmModal`'s `refusal` slot): the toast that used to+ * carry them dismissed itself after a few seconds, out of the card the user was still looking+ * at — and the event, after all, is still what the form says it was. The retry is the same+ * button; cancelling lands back on the form with the values that were refused.+ */const save = async () => {- if (form === null) return;+ if (form === null || busy) return;setBusy(true);try {const body = {@@ -343,15 +359,16 @@ export function CalendarPage() {setForm(null);void load();} catch (e) {- setConfirmSave(false);- toastError(apiErrorText(e));+ // The card stays open: it asked the question, so it holds the answer.+ setSaveRefusal(apiErrorText(e));} finally {setBusy(false);}};+ /** Same rule as `save`: the delete card is dismissed by the delete landing, not by its request. */const remove = async () => {- if (deleting === null) return;+ if (deleting === null || busy) return;setBusy(true);try {await api.deleteOrgCalendarEvent(projectId, orgId, deleting.agentId, deleting.name);@@ -359,7 +376,7 @@ export function CalendarPage() {setForm(null);void load();} catch (e) {- toastError(apiErrorText(e));+ setDeleteRefusal(apiErrorText(e));} finally {setBusy(false);}@@ -862,7 +879,11 @@ export function CalendarPage() {variant="danger"className="mr-auto"disabled={busy}- onClick={() => setDeleting(form.editing)}+ onClick={() => {+ // A new question, not the one the user was just refused: the old reason goes.+ setDeleteRefusal(null);+ setDeleting(form.editing);+ }}>{S.company.calendar.delete}</Button>@@ -875,7 +896,9 @@ export function CalendarPage() {variant="primary"disabled={busy}onClick={() => {- if (validate()) setConfirmSave(true);+ if (!validate()) return;+ setSaveRefusal(null);+ setConfirmSave(true);}}>{form?.editing != null ? S.common.save : S.common.create}@@ -1015,6 +1038,7 @@ export function CalendarPage() {confirmLabel={S.common.save}cancelLabel={S.common.cancel}busy={busy}+ refusal={saveRefusal === null ? undefined : S.common.refused(saveRefusal)}onClose={() => (busy ? undefined : setConfirmSave(false))}onConfirm={() => void save()}>@@ -1028,6 +1052,7 @@ export function CalendarPage() {confirmLabel={S.common.delete}cancelLabel={S.common.cancel}busy={busy}+ refusal={deleteRefusal === null ? undefined : S.common.refused(deleteRefusal)}onClose={() => (busy ? undefined : setDeleting(null))}onConfirm={() => void remove()}>