A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 主页存不下去时,原因留在内置浏览器的地址字段下面,不再只活六秒
lmliheng2dd107404baa
diff --git a/changelog/unreleased/2026-11-04-builtin-browser-homepage-refusal.md b/changelog/unreleased/2026-11-04-builtin-browser-homepage-refusal.mdnew file mode 100644index 00000000..245df077--- /dev/null+++ b/changelog/unreleased/2026-11-04-builtin-browser-homepage-refusal.md@@ -0,0 +1,48 @@+# A homepage that could not be saved says why under the address field, not in a six-second toast++- **Date:** 2026-11-04+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-11-04-builtin-browser-homepage-refusal.zh.md)++The built-in browser's "set homepage" dialog asks one question — the address new tabs and the Home+button open — and its Save sends the entry in the field. A save that fails leaves the dialog open on+exactly that entry, because the entry is what the reader is about to correct and the button beside it+is what retries. What the dialog lost was the reason: it arrived as a notification, sat over the+dialog, dismissed itself after six seconds, and left a dialog that read exactly as it did before the+press — the field unchanged, the Save button unchanged, and the address the sentence named right+there, unmarked.++That sentence is now drawn in the dialog, directly under the address field (`role="alert"`, danger+colour, two lines at most with the whole text on hover), and it stays while the dialog is open on+that entry. It belongs to the attempt that produced it, so any change of the entry — typing, "Use+current page", "Clear" — drops it, and the next press clears it before it is sent so a refusal that+repeats reads as this press's answer rather than as a sentence that never went away. The field's own+hint ("opens https://example.com/") stays visible under the box: the reason is added, not swapped in+for the one thing that tells the reader what the entry will do.++## Details++- `packages/web/src/features/builtin-browser/homepage-dialog.tsx`: one `refusal` state beside the+ entry — `edit()` (typing, "Use current page", "Clear") clears it, `save()` clears it before the+ request and sets it on failure. The failed save no longer raises `toastError`; the sentence is+ `S.builtinBrowser.homepageFailed(refusalText(err))`, the app-wide refusal slot rule (7.19) — a+ request that never reached the route reads its error code's localized sentence rather than the+ generic one.++## Tests++- `packages/web/e2e/builtin-browser-homepage-refusal.spec.mjs` (new, one case on a real server with+ the shell's `<webview>` stubbed and the browser routes inside the page): the settings write is+ stubbed at `page.route` — it is the one thing this dialog sends. A refused save keeps the dialog,+ the entry and the hint, draws the refusal under the field, and puts nothing in the notification+ region; seven seconds later (past the six an error notification lives) the sentence is still there.+ Typing one character drops it; the next press that fails brings it back. Once allowed, the dialog+ closes and the write carried the entry as it stood, read the way the address bar reads it.++## Compatibility++No interface change, no new dependency, no Project config change, no new strings — `homepageFailed`+already existed and keeps its exact wording.diff --git a/changelog/unreleased/2026-11-04-builtin-browser-homepage-refusal.zh.md b/changelog/unreleased/2026-11-04-builtin-browser-homepage-refusal.zh.mdnew file mode 100644index 00000000..41c71a89--- /dev/null+++ b/changelog/unreleased/2026-11-04-builtin-browser-homepage-refusal.zh.md@@ -0,0 +1,38 @@+# 内置浏览器的「设置主页」存不下去时,原因留在地址字段下面,不再只活六秒++- **日期:** 2026-11-04+- **类型:** fix+- **范围:** `web`+- **破坏性:** 否++[English](2026-11-04-builtin-browser-homepage-refusal.md)++内置浏览器的「设置主页」弹窗只问一件事 —— 新建标签页与主页按钮要打开哪个地址 —— 它的「保存」把字段里的+那一条发出去。保存失败时弹窗照旧开着、字段也照旧留着那一条:要改的正是它,旁边那颗按钮正是重试。丢掉的+是**理由**:它过去只落进一条通知,通知浮在弹窗上、六秒后自己消失,屏上留下一张与按键前一模一样的弹窗 ——+字段没变、按钮没变,而那句话点名的地址就在眼前,却没有任何标记。++那句话现在画在弹窗里、就在地址字段的下面(`role="alert"`、危险色、最多两行、整句挂悬停提示),只要弹窗还+开在这条记录上就一直在。它属于产生它的那一次尝试,所以字段的任何变化(打字、「使用当前页面」、「清除」)都+会把它带走,而下一次按键在发出去之前先清掉它 —— 这样一条重复的拒绝读起来是这一次的答复,而不是一句「从没+消失过的话」。字段自己的提示(「将打开 https://example.com/」)照旧留在框下面:理由是加上去的,不是把唯一+告诉读者这条记录会做什么的那一行换掉。++## 明细++- `packages/web/src/features/builtin-browser/homepage-dialog.tsx`:字段旁边多一个 `refusal` 状态 ——+ `edit()`(打字、「使用当前页面」、「清除」)清掉它,`save()` 在发请求之前清掉、失败时写上。失败不再+ 走 `toastError`,那句话是 `S.builtinBrowser.homepageFailed(refusalText(err))`,即全应用拒绝位的同一条+ 规则(7.19):请求根本没到服务端时,念的是错误码自己的本地化句子,而不是那句通用话。++## 测试++- `packages/web/e2e/builtin-browser-homepage-refusal.spec.mjs`(新,一条用例,真服务端 + 把桌面壳提供的+ `<webview>` 桩掉 + 浏览器那几条路由拦在页面内):这条弹窗唯一会写的那个设置接口在 `page.route` 上桩住。+ 被拒绝的保存会留下弹窗、字段与提示,把拒绝画在字段下面,而通知区一条都没有;7 秒后(超过错误通知活着的+ 6 秒)那句话仍在。改一个字它就消失;下一次按键再失败,它回来一次。放行之后弹窗关闭,那次写入带走的正是+ 字段里的那一条,按地址栏的读法读。++## 兼容性++不碰接口、不引入新依赖、不改 Project 配置、无新文案 —— `homepageFailed` 原本就在,措辞一字未改。diff --git a/packages/web/e2e/builtin-browser-homepage-refusal.spec.mjs b/packages/web/e2e/builtin-browser-homepage-refusal.spec.mjsnew file mode 100644index 00000000..dcdea916--- /dev/null+++ b/packages/web/e2e/builtin-browser-homepage-refusal.spec.mjs@@ -0,0 +1,165 @@+/**+ * Regression: the built-in browser's "set homepage" dialog keeps a refused save's reason under the+ * address field it is about, for as long as the dialog is open on that entry.+ *+ * The dialog always stayed open on a failure — what it lost was the reason: the words went to a+ * notification that dismissed itself after six seconds, and what stood under it was the very field+ * the sentence named, so the dialog then read exactly as it did before the press. The reason now+ * renders under the entry, next to the Save button that retries it, and any edit of the entry (and+ * the next press) clears it.+ *+ * The panel normally needs the desktop shell, so this spec stubs the one thing the app asks it for+ * (the `<webview>` element in the custom-element registry) and the browser routes inside the page;+ * the server, the sign-in and the Project are real. The refusal carries a code nothing translates+ * (`homepage_refused`), so the sentence on screen can only be the probe's.+ */+import { test, expect } from "@playwright/test";+import { ADMIN_ID, ADMIN_PASSWORD, login } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;++/** A code no client translation covers, so its message reaches the dialog verbatim. */+const REFUSAL = { code: "homepage_refused", message: "homepage refused by the probe" };+const SHOWN = `无法保存主页:${REFUSAL.message}`;++/** Longer than an error notification stays (6000 ms), so "it left with the toast" is measurable. */+const OUTLIVES_TOAST_MS = 7000;++const TAB = {+ id: 1,+ url: "https://example.com/",+ title: "示例站点",+ loading: false,+ canGoBack: false,+ canGoForward: false,+};++/** What the desktop shell provides and a plain browser does not: a `webview` in the registry. */+const STUB_WEBVIEW = () => {+ class StubView extends HTMLElement {+ loadURL() {+ return Promise.resolve();+ }+ reload() {}+ stop() {}+ goBack() {}+ goForward() {}+ focus() {}+ openDevTools() {}+ }+ const get = CustomElementRegistry.prototype.get;+ CustomElementRegistry.prototype.get = function (name) {+ return name === "webview" ? StubView : get.call(this, name);+ };+};++test("built-in browser: a refused homepage save keeps the dialog and its reason, and retries the same entry", async ({+ page,+}) => {+ // The browser's routes are admin-only, so this runs as the seeded administrator.+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);++ const projects = await (await page.request.get(`${BASE}/api/projects`)).json();+ const projectId = projects.projects[0].projectId;+ // A Project needs a model, or the onboarding overlay covers the toolbar.+ const models = 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(models.ok(), "put models").toBeTruthy();++ // The dock's two toggles live on a conversation's toolbar, not on the new-chat draft.+ const created = await page.request.post(+ `${BASE}/api/projects/${projectId}/agents/default_agent/sessions`,+ { data: { provider: "custom", modelId: "claude-4-8" } },+ );+ expect(created.ok(), "create session").toBeTruthy();+ const sessionId = (await created.json()).session.sessionId;++ await page.addInitScript(STUB_WEBVIEW);+ await page.route("**/api/builtin-browser/status", (route) =>+ route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({ available: true, tabs: [TAB], activeTabId: TAB.id }),+ }),+ );++ /** Every settings write's body, so the retry can be checked against the first attempt. */+ const writes = [];+ let refuse = true;+ await page.route("**/api/builtin-browser/settings", (route) => {+ if (route.request().method() !== "PUT") {+ return route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({ homepage: null }),+ });+ }+ writes.push(route.request().postDataJSON());+ if (!refuse) {+ return route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({ homepage: "https://example.com/" }),+ });+ }+ return route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ });++ await page.goto(`${BASE}/chat/${sessionId}`);+ await page.getByTestId("dock-toggle-right").click();+ const dock = page.locator('[data-testid="dock"][data-position="right"]');+ await dock.getByTestId("dock-pick-builtin-browser").click();+ await dock.getByRole("button", { name: "更多", exact: true }).click();+ await page.getByRole("menuitem", { name: "设置主页…" }).click();++ const dialog = page.getByRole("dialog");+ await expect(dialog).toBeVisible();+ const field = dialog.getByTestId("builtin-browser-homepage-input");+ await field.fill("example.com");+ await field.press("Enter");++ // The refusal lands under the entry, and the dialog keeps the entry that produced it.+ await expect(dialog).toBeVisible();+ await expect(dialog.getByRole("alert")).toHaveText(SHOWN);+ await expect(dialog.getByText("将打开 https://example.com/")).toBeVisible();+ await expect(field).toHaveValue("example.com");+ // Nothing went to the notification stack for it, so there is nothing to expire with.+ expect(writes.length).toBe(1);+ expect(writes[0]).toEqual({ homepage: "https://example.com/" });++ // The claim of this spec: the words are still there after an error notification would be gone.+ await page.waitForTimeout(OUTLIVES_TOAST_MS);+ await expect(dialog.getByRole("alert")).toHaveText(SHOWN);++ // Editing the entry makes the sentence stale at once — it named the address that was there.+ await field.fill("example.org");+ await expect(dialog.getByRole("alert")).toHaveCount(0);+ // And so does a fresh attempt that fails again: the reason comes back, once.+ await field.press("Enter");+ await expect(dialog.getByRole("alert")).toHaveText(SHOWN);++ // Allowed this time: the dialog goes, and so does the reason.+ refuse = false;+ await dialog.getByRole("button", { name: "保存", exact: true }).click();+ await expect(dialog).toBeHidden();+ // The retry sent the entry as it stood, read the way the address bar reads it.+ expect(writes.at(-1)).toEqual({ homepage: "https://example.org/" });+ expect(writes.length).toBe(3);+});diff --git a/packages/web/src/features/builtin-browser/homepage-dialog.tsx b/packages/web/src/features/builtin-browser/homepage-dialog.tsxindex c0412bfa..a8736193 100644--- a/packages/web/src/features/builtin-browser/homepage-dialog.tsx+++ b/packages/web/src/features/builtin-browser/homepage-dialog.tsx@@ -5,14 +5,22 @@* takes the page on screen and "Clear" empties the field; saving an empty field removes the* homepage, so new tabs open blank again and the Home button goes away.*+ * A save that fails keeps the dialog open on the entry, and the reason stays UNDER THE FIELD it+ * is about — the entry is still there to be corrected and the Save button beside it is what+ * retries. A notification said the same words over an open dialog and left six seconds later,+ * after which the dialog read exactly as it did before the press. The sentence belongs to the+ * attempt that produced it, so any edit of the field (typing, "Use current page", "Clear") and+ * the next press each clear it.+ ** Mounted for one opening at a time (the panel renders it only while it is open), so every* opening starts from the homepage as saved.*/import { useState } from "react";-import { Button, Input, Modal, toastError } from "@adelie/ui";+import { Button, Input, Modal } from "@adelie/ui";import * as api from "../../api/endpoints";-import { apiErrorText } from "../../lib/api-error";+import { refusalText } from "../../lib/api-error";import { S } from "../../lib/strings";+import { toneInk } from "../../lib/tone";import { homepageFromInput } from "./address";import { dispatchBrowser } from "./browser-store";@@ -29,18 +37,33 @@ export function HomepageDialog({}) {const [text, setText] = useState(homepage ?? "");const [saving, setSaving] = useState(false);+ /** The last failed save's sentence; belongs to the entry it was about. */+ const [refusal, setRefusal] = useState<string | null>(null);const target = homepageFromInput(text);+ /**+ * Every change of the entry — typing, "Use current page", "Clear" — makes the sentence about+ * the last attempt stale: the words named an address that is no longer in the field.+ */+ const edit = (next: string) => {+ setRefusal(null);+ setText(next);+ };+const save = async () => {if (saving) return;+ // Cleared before the request, so a refusal that repeats reads as the answer to THIS press+ // rather than as a sentence that never went away.+ setRefusal(null);setSaving(true);try {const saved = await api.putBuiltinBrowserSettings({ homepage: target });dispatchBrowser({ type: "settings", settings: saved });onClose();} catch (err) {- // The dialog stays open with the entry, so the save can be tried again.- toastError(S.builtinBrowser.homepageFailed(apiErrorText(err)));+ // The dialog stays open with the entry, so the save can be tried again — and the reason+ // stays beside that entry rather than in a notification over the dialog.+ setRefusal(S.builtinBrowser.homepageFailed(refusalText(err)));setSaving(false);}};@@ -77,7 +100,7 @@ export function HomepageDialog({spellCheck={false}value={text}disabled={saving}- onChange={(e) => setText(e.target.value)}+ onChange={(e) => edit(e.target.value)}onFocus={(e) => e.target.select()}onKeyDown={(e) => {if (e.key !== "Enter" || e.nativeEvent.isComposing) return;@@ -85,12 +108,25 @@ export function HomepageDialog({void save();}}/>+ {/* Right under the entry, inside the dialog that asked: the address it names is the+ field above, and the Save button below is what retries. Clamped to two lines because+ a server's message can run long; the whole sentence stays on hover. */}+ {refusal !== null && (+ <p+ role="alert"+ data-tooltip={refusal}+ data-tooltip-content="text"+ className={`line-clamp-2 break-words text-xs ${toneInk.danger}`}+ >+ {refusal}+ </p>+ )}<div className="flex flex-wrap items-center gap-2"><Buttonsize="sm"disabled={currentPage === null || saving}onClick={() => {- if (currentPage !== null) setText(currentPage);+ if (currentPage !== null) edit(currentPage);}}>{S.builtinBrowser.homepageUseCurrent}@@ -99,7 +135,7 @@ export function HomepageDialog({size="sm"variant="ghost"disabled={text === "" || saving}- onClick={() => setText("")}+ onClick={() => edit("")}>{S.builtinBrowser.homepageClear}</Button>