Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): 财务页改预算被拒时,框留着、金额与原因都留着(7.47)

lmliheng467c076d9a5d
diff --git a/changelog/unreleased/2026-10-26-finance-budget-refusal.md b/changelog/unreleased/2026-10-26-finance-budget-refusal.md
new file mode 100644
index 00000000..e79b7ae6
--- /dev/null
+++ b/changelog/unreleased/2026-10-26-finance-budget-refusal.md
@@ -0,0 +1,37 @@
+# Finance: a refused budget keeps the box, the typed amount and the reason
+
+- **Date:** 2026-10-26
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-10-26-finance-budget-refusal.zh.md)
+
+The finance page edits an employee's monthly budget in place: a number box in the reader's own
+currency, save and cancel, with what it will store in USD underneath. Its write used to report a
+refusal through a toast alone, so a few seconds after the attempt the row stood with the typed
+amount still in the box, no explanation anywhere, and a live save button — the reason had gone to
+where nothing else was looking.
+
+The box now holds its own answer: a refusal draws the server's words on one line under it (the
+app's existing "Refused:" lead-in), right where the retry is, and the typed amount stays as typed.
+Text the box cannot read — a negative amount, say — says its piece on that same line instead of in
+a toast. Cancelling lands back on the row as it was; opening the editor again drops the previous
+reason, which belonged to the attempt it named.
+
+## Details
+
+- `features/company/finance-page.tsx`: `BudgetEditor` gains a `refusal` line and its own hint for
+ text it cannot read (the existing `budgetHint` copy, now drawn where it can be read); the page
+ keeps the refusal in `budgetRefusal` keyed by employee, so it is drawn in the row that asked.
+ `saveBudget`'s `catch` no longer toasts, and both the landing path and cancelling clear it.
+- New browser spec `e2e/finance-budget-refusal.spec.mjs`, two cases: with the write refused at
+ `page.route` 500, the reason is under the box, the notification region never carries it, the
+ chart's stored budget is unchanged and the box still holds the typed amount; cancelling and
+ reopening shows the stored budget without a stale reason, and the retry really writes. The
+ second case types an amount the box cannot read and proves it writes nothing at all.
+
+## Compatibility
+
+- No interface, wire-format, stored-data or dependency change: only *where* a refused budget and
+ an unreadable one are reported. No new copy beyond the existing `S.common.refused` lead-in.
diff --git a/changelog/unreleased/2026-10-26-finance-budget-refusal.zh.md b/changelog/unreleased/2026-10-26-finance-budget-refusal.zh.md
new file mode 100644
index 00000000..3b0f4599
--- /dev/null
+++ b/changelog/unreleased/2026-10-26-finance-budget-refusal.zh.md
@@ -0,0 +1,31 @@
+# 财务:预算被拒时,输入框、填过的金额与原因都留着
+
+- **Date:** 2026-10-26
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[English](2026-10-26-finance-budget-refusal.md)
+
+财务页上,员工的每月预算是在行内改的:一个按读者所选货币计价的数量框,保存与取消,下面写着它会以美元
+存成多少。它的写入过去被拒时只落进一条通知 —— 几秒后原因没了,行里还是刚敲进去的金额,保存按钮又亮着,
+没有任何东西说明为什么。
+
+现在这个框自己留着回答:被拒时服务端原话画在框下方那一行(应用既有的「操作被拒绝:」前缀),就在重试
+按钮旁边,敲进去的金额原样留着。框里读不懂的文字(比如负数)也说在同一行,不再弹通知。取消之后回到原来
+那一行;重新打开编辑时不带上一次的原因 —— 那句话属于上次那次尝试。
+
+## 细节
+
+- `features/company/finance-page.tsx`:`BudgetEditor` 多一行 `refusal`,并自带一份「读不懂」的提示
+ (复用既有的 `budgetHint` 文案,只是改画在能读到的地方);页面把拒绝文案存在按员工索引的
+ `budgetRefusal` 里,因此它画在发问的那一行。`saveBudget` 的 `catch` 不再弹通知,落地与取消两条路径都
+ 会清掉它。
+- 新增浏览器用例 `e2e/finance-budget-refusal.spec.mjs`,两条:用 `page.route` 把写入拒成 500 之后,
+ 原因在框下方、通知区里没有那句原话、组织图里存的预算没变、框里还是刚敲的金额;取消后重开是存着的预算、
+ 不带旧原因,重试才真正写进去。第二条填一个框里读不懂的金额,证明它一次写入都没发。
+
+## 兼容性
+
+- 没有接口、传输格式、已存数据或依赖变化:只改了被拒与读不懂这两种情形「原因画在哪」。除既有的
+ `S.common.refused` 前缀外没有新文案。
diff --git a/packages/web/e2e/finance-budget-refusal.spec.mjs b/packages/web/e2e/finance-budget-refusal.spec.mjs
new file mode 100644
index 00000000..cb2fb355
--- /dev/null
+++ b/packages/web/e2e/finance-budget-refusal.spec.mjs
@@ -0,0 +1,181 @@
+/**
+ * Regression: a budget typed in the finance page keeps its own answer — a refused write leaves
+ * the reason in the box that asked, instead of only a toast that dismisses itself.
+ *
+ * `BudgetEditor` (`features/company/finance-page.tsx`) is the budget cell while it is being
+ * typed: the number box, save and cancel, with "empty = unbounded" and the USD it will store
+ * underneath. Its write used to report a refusal through `toastError` alone, so a few seconds
+ * after the attempt the row stood there with the typed amount, no explanation and a live save
+ * button — the retry was a guess. The reason now sits on one line under the box, right where the
+ * retry is, and text the box cannot read says its piece on that same line rather than in a
+ * toast. Cancelling lands back on the row as it was; reopening starts without the old reason.
+ *
+ * The organization is made through the API (this spec is about the box's answer, not about
+ * setting the company up): a fresh organization already has its CEO, whose budget is the row
+ * this test edits. 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 — nothing here needs
+ * the model, but a fresh Project without one would hold the onboarding overlay over 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 = "budgetrefuse";
+/** Typed in the reader's currency (CNY by default) and stored in USD at the App's fixed rate. */
+const TYPED = "42";
+const STORED_USD = 6;
+
+/** The refusal the box paints; a 500 with its own words proves those words came back. */
+const REFUSAL = { code: "org_chart_locked", message: "the org chart 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, and its CEO read off the chart. */
+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: "Keep the plugin marketplace found from the blog." },
+ });
+ expect(created.ok(), "create organization").toBeTruthy();
+
+ /** The chart as the server holds it: the CEO row's name and stored budget (USD). */
+ const ceo = async () => {
+ const chart = await (await page.request.get(`${orgBase}/${ORG}/chart`)).json();
+ const row = chart.employees.find((e) => e.agentId === chart.ceoAgentId);
+ return { agentId: chart.ceoAgentId, name: row.name, budget: row.budget ?? null };
+ };
+ const { agentId, name, budget } = await ceo();
+ return { projectId, agentId, name, budget, ceo };
+}
+
+/** The finance page, and the row's own edit button (the one carrying the employee's name). */
+async function openFinance(page, projectId, name) {
+ await page.goto(`/org/${projectId}/${ORG}/finance`);
+ await expect(page.getByRole("button", { name: `编辑 ${name} 的预算` })).toBeVisible();
+}
+
+test("a refused budget keeps the box, the typed amount and the reason", async ({ page }) => {
+ test.setTimeout(120_000);
+ const { projectId, agentId, name, budget, ceo } = await setUp(page, "r133budget");
+ await openFinance(page, projectId, name);
+
+ // What the box starts with: the stored budget in the reader's currency.
+ const editorLabel = `编辑 ${name} 的预算`;
+ const openEditor = async () => {
+ await page.getByRole("button", { name: editorLabel }).click();
+ const box = page.getByRole("spinbutton", { name: editorLabel });
+ await expect(box).toBeVisible();
+ return box;
+ };
+ const box = await openEditor();
+ const prefilled = await box.inputValue();
+ await box.fill(TYPED);
+
+ // One refusal with the server's own words, counted so the test knows the page wrote once.
+ const writes = [];
+ const pattern = `**/organizations/${ORG}/employees/${encodeURIComponent(agentId)}`;
+ await page.route(pattern, async (route) => {
+ if (route.request().method() !== "PATCH") return route.fallback();
+ writes.push(route.request().url());
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+
+ await page.getByRole("button", { name: "保存预算" }).click();
+
+ // The reason is under the box that asked, and it is not a toast: the notification region
+ // never carries the server's words.
+ await expect(page.getByRole("alert").filter({ hasText: REFUSAL.message })).toHaveCount(1);
+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(REFUSAL.message);
+ expect(writes).toHaveLength(1);
+
+ // Nothing was written, and the box still holds what was typed.
+ expect((await ceo()).budget).toBe(budget);
+ await expect(page.getByRole("spinbutton", { name: editorLabel })).toHaveValue(TYPED);
+
+ // Cancelling decides nothing; reopening starts from the stored budget, without the old reason.
+ await page.getByRole("button", { name: "取消" }).click();
+ await expect(page.getByRole("spinbutton", { name: editorLabel })).toHaveCount(0);
+ const again = await openEditor();
+ await expect(again).toHaveValue(prefilled);
+ await expect(page.getByRole("alert").filter({ hasText: REFUSAL.message })).toHaveCount(0);
+
+ // The retry lands: the editor closes and the chart holds the amount that was typed.
+ await page.unroute(pattern);
+ await again.fill(TYPED);
+ await page.getByRole("button", { name: "保存预算" }).click();
+ await expect(page.getByRole("spinbutton", { name: editorLabel })).toHaveCount(0);
+ await expect.poll(async () => (await ceo()).budget).toBe(STORED_USD);
+});
+
+test("a budget the box cannot read says so under the box, and writes nothing", async ({ page }) => {
+ test.setTimeout(120_000);
+ const { projectId, name, budget, ceo } = await setUp(page, "r133hint");
+ await openFinance(page, projectId, name);
+
+ const editorLabel = `编辑 ${name} 的预算`;
+ await page.getByRole("button", { name: editorLabel }).click();
+ const box = page.getByRole("spinbutton", { name: editorLabel });
+ await expect(box).toBeVisible();
+ await box.fill("-5");
+
+ // Counted so the test can say the refusal never reached the server at all.
+ const writes = [];
+ await page.route(`**/organizations/${ORG}/employees/**`, async (route) => {
+ if (route.request().method() !== "PATCH") return route.fallback();
+ writes.push(route.request().url());
+ await route.fallback();
+ });
+
+ await page.getByRole("button", { name: "保存预算" }).click();
+ await expect(page.getByRole("alert").filter({ hasText: "每月上限" })).toHaveCount(1);
+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText("每月上限");
+ expect(writes).toHaveLength(0);
+ expect((await ceo()).budget).toBe(budget);
+
+ // A readable amount goes through from the same box, and the line goes with the save — once:
+ // disabling the box for the write blurs it, and a blur is also a save.
+ await box.fill(TYPED);
+ await page.getByRole("button", { name: "保存预算" }).click();
+ await expect(page.getByRole("spinbutton", { name: editorLabel })).toHaveCount(0);
+ await expect.poll(async () => (await ceo()).budget).toBe(STORED_USD);
+ expect(writes).toHaveLength(1);
+});
diff --git a/packages/web/src/features/company/finance-page.tsx b/packages/web/src/features/company/finance-page.tsx
index 1989e000..f39ff88b 100644
--- a/packages/web/src/features/company/finance-page.tsx
+++ b/packages/web/src/features/company/finance-page.tsx
@@ -52,7 +52,6 @@ import {
TableHeaderCell,
TableRow,
noAutofill,
- toastError,
toastSuccess,
} from "@adelie/ui";
import * as api from "../../api/endpoints";
@@ -173,12 +172,17 @@ function FinanceCard({
* saves, Escape cancels, and focus leaving the editor saves too — the two buttons keep focus
* on mousedown so clicking cancel never saves first. What goes out is USD, which is what the
* chart file holds, and a box in another currency says so under itself.
+ *
+ * The box holds its own answer: text it cannot read and a write the server refused both land
+ * on one line under it, where the retry is — a toast would be gone seconds later while the
+ * editor still stood there asking the same question.
*/
function BudgetEditor({
initial,
name,
currency,
busy,
+ refusal,
onSave,
onCancel,
}: {
@@ -187,19 +191,36 @@ function BudgetEditor({
name: string;
currency: Currency;
busy: boolean;
+ /** The server's own words for the write it refused, if it refused the last one. */
+ refusal: string | null;
/** The new budget in USD, or null for unbounded. */
onSave: (value: number | null) => void;
onCancel: () => void;
}) {
const [text, setText] = useState(() => fromStoredUsd(initial, currency));
+ /** What the box itself says about its text; the refusal is the server's, on the same line. */
+ const [hint, setHint] = useState<string | null>(null);
+ /**
+ * A write is already on the wire. Disabling the box while it is (below) takes the focus off
+ * it, and focus leaving is one of the ways this editor saves — without this flag one press of
+ * save would write twice.
+ */
+ const asking = useRef(false);
+ useEffect(() => {
+ if (!busy) asking.current = false;
+ }, [busy]);
const wrapRef = useRef<HTMLSpanElement>(null);
const commit = () => {
+ if (asking.current) return;
if (!isBudgetText(text)) {
- toastError(S.company.chart.budgetHint);
+ setHint(S.company.chart.budgetHint);
return;
}
+ setHint(null);
+ asking.current = true;
onSave(toStoredUsd(text, currency));
};
+ const message = hint ?? (refusal === null ? null : S.common.refused(refusal));
return (
<span
ref={wrapRef}
@@ -255,6 +276,11 @@ function BudgetEditor({
<CloseIcon />
</button>
</span>
+ {message !== null && (
+ <span role="alert" className="block max-w-56 text-right text-xs text-tone-danger-fg">
+ {message}
+ </span>
+ )}
<span className="text-xs text-gray-400 dark:text-gray-500">
{S.company.finance.budgetEmptyHint}
</span>
@@ -304,6 +330,13 @@ export function FinancePage() {
const [states, setStates] = useState<ReadonlyMap<string, OrgEmployeeState>>(new Map());
/** The employee whose budget is being typed. */
const [editingId, setEditingId] = useState<string | null>(null);
+ /**
+ * The budget write the server refused, in the row that asked: the editor stays open on a
+ * refusal (it is only dismissed by its own landing), so the reason has to stay with it.
+ */
+ const [budgetRefusal, setBudgetRefusal] = useState<{ agentId: string; text: string } | null>(
+ null,
+ );
/**
* The ticket ledger's opened parents. Deliberately not persisted and not a URL parameter: a
* fold is how the reader is looking at the table right now, and a ledger that reopened
@@ -367,6 +400,7 @@ export function FinancePage() {
const row = data?.employees.find((e) => e.agentId === agentId);
if (row !== undefined && (row.budget ?? null) === value) {
setEditingId(null);
+ setBudgetRefusal(null);
return;
}
setBusy(true);
@@ -374,10 +408,13 @@ export function FinancePage() {
await api.patchOrgEmployee(projectId, orgId, agentId, { budget: value });
toastSuccess(S.company.finance.budgetSaved);
setEditingId(null);
+ setBudgetRefusal(null);
void load();
void company.reloadOrganizations();
} catch (e) {
- toastError(apiErrorText(e));
+ // The editor stays open on a refusal (it closes only on its own landing), so the reason
+ // belongs in it, under the box that was refused — not in a toast of its own.
+ setBudgetRefusal({ agentId, text: apiErrorText(e) });
} finally {
setBusy(false);
}
@@ -595,8 +632,16 @@ export function FinancePage() {
name={employee.name}
currency={currency}
busy={busy}
+ refusal={
+ budgetRefusal?.agentId === employee.agentId
+ ? budgetRefusal.text
+ : null
+ }
onSave={(value) => void saveBudget(employee.agentId, value)}
- onCancel={() => setEditingId(null)}
+ onCancel={() => {
+ setEditingId(null);
+ setBudgetRefusal(null);
+ }}
/>
) : (
<span className={`flex items-center ${ICON_GAP.menu}`}>
@@ -623,7 +668,10 @@ export function FinancePage() {
type="button"
data-tooltip={S.company.finance.editBudget}
aria-label={S.company.finance.editBudgetOf(employee.name)}
- onClick={() => setEditingId(employee.agentId)}
+ onClick={() => {
+ setBudgetRefusal(null);
+ setEditingId(employee.agentId);
+ }}
className={`group inline-flex items-center ${ICON_GAP.tight} rounded px-1 py-0.5 tabular-nums transition-colors duration-150 hover:bg-gray-100 dark:hover:bg-gray-800`}
>
<span