Skip to content

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

fix(web): 文件面板保存被拒时,原因留在标题行下面,不再只活六秒

lmliheng02bf3617cea2
diff --git a/changelog/unreleased/2026-11-06-editor-save-refusal.md b/changelog/unreleased/2026-11-06-editor-save-refusal.md
new file mode 100644
index 00000000..fac70f9b
--- /dev/null
+++ b/changelog/unreleased/2026-11-06-editor-save-refusal.md
@@ -0,0 +1,56 @@
+# A save the Files panel could not write says why above the editor, not in a six-second toast
+
+- **Date:** 2026-11-06
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-11-06-editor-save-refusal.zh.md)
+
+The Files panel edits a text file in place: the preview becomes an editor, and Save writes the draft
+back to the Workspace. When that write did not land — the server refused it, the path had no
+permission, the request never arrived — nothing on the panel changed: the editor stayed open with
+the draft in it, the header's Save was the retry, and the reason went to a notification that
+dismissed itself after six seconds. Afterwards the panel looked exactly as it had before the press,
+the file on disk still held the old text, and what the reader had typed was nowhere but the editor,
+with no word about why.
+
+That sentence now renders between the header and the editor (`role="alert"`, danger colour, two
+lines, the whole sentence on hover), and stays until the draft is edited, the save is pressed again
+or the edit is left. When the draft differs from the file it also says that what was edited is still
+only in the editor — which is the state the reader is left in; when the two are equal (Save pressed
+on an untouched file) it is just the reason.
+
+## Details
+
+- `packages/web/src/features/chat/editor-save-refusal.ts` (new): `editorSaveRefusal(error, sent,
+ baseline)` — the pure decision, so which sentence appears is in one place and testable without the
+ panel.
+- `packages/web/src/features/chat/workspace-browser.tsx`: the editor gains a `saveRefusal` state
+ (carrying the file's path, so it only ever draws over the draft it is about). `save()`'s failure
+ branch no longer calls `toastError` but writes that sentence; opening the editor, editing the
+ draft, the next save and a scope switch each clear it. A `file_changed` (409) still goes to its own
+ overwrite confirmation: that is a question, not a failure.
+- `packages/web/src/lib/strings{,-en}.ts`: one new pair, `files.saveRefused(reason)` /
+ `files.saveRefusedDraftKept(reason)`.
+
+## Tests
+
+- `packages/web/test/editor-save-refusal.test.ts` (new, 6 cases): a server answer is read through its
+ code's own localized sentence, never the wire message; a draft that differs from the file gets the
+ "still only in the editor" half and an unchanged one does not; a value this codebase raised is
+ shown as it wrote it; nothing to say falls back to the generic sentence; the active language is the
+ one used.
+- `packages/web/e2e/editor-save-refusal.spec.mjs` (new, real server, real browser): the write is
+ stubbed to 403, the draft is typed and Save pressed and confirmed. The line appears under the
+ header, the notification region never carries it, the file keeps its old text while the editor
+ keeps the draft and a working Save; **seven seconds later** (past the six an error notification
+ lives) it is still there; one keystroke clears it; with the route allowed through the retry writes
+ the file and the line does not come back. A second case: leaving the editor after a refusal (and
+ confirming the discard) takes the line with the draft.
+
+## Compatibility
+
+No interface change, no new dependency, no Project config change. The editor's own "over the write
+limit" check keeps its notification: it sends nothing and rewrites nothing — what has to change
+there is the content itself.
diff --git a/changelog/unreleased/2026-11-06-editor-save-refusal.zh.md b/changelog/unreleased/2026-11-06-editor-save-refusal.zh.md
new file mode 100644
index 00000000..b82414fc
--- /dev/null
+++ b/changelog/unreleased/2026-11-06-editor-save-refusal.zh.md
@@ -0,0 +1,42 @@
+# 文件面板里没写进去的保存,原因留在编辑器上方,不再只活六秒
+
+- **日期:** 2026-11-06
+- **类型:** fix
+- **范围:** `web`
+- **破坏性:** 否
+
+[English](2026-11-06-editor-save-refusal.md)
+
+文件面板可以在原地编辑文本文件:预览换成编辑框,保存把草稿写回 Workspace。那次写入没落地时 —— 服务端
+拒了、路径没有权限、请求根本没到 —— 面板上什么都没有变:编辑框还开着、草稿还在里面、标题行的保存按钮
+就是重试,而原因只落进一条通知,六秒后自己消失。此后屏幕与按下之前一模一样,磁盘上那份仍是旧内容,用户
+打的字只在编辑框里,却没有任何一句话说明为什么。
+
+那句话现在画在标题行与编辑框之间(`role="alert"`、危险色、限两行、整句挂悬停),一直留到草稿被改动、
+再次保存或退出编辑为止。草稿与文件那份不同时它一并说明「编辑器里的改动没有写进文件」—— 那正是用户被
+留成的状态;两者相同(没改就按了保存)时只念原因。
+
+## 明细
+
+- `packages/web/src/features/chat/editor-save-refusal.ts`(新):`editorSaveRefusal(error, sent, baseline)`
+ —— 纯判断,念哪句话只在这一处,不依赖面板就能测。
+- `packages/web/src/features/chat/workspace-browser.tsx`:编辑器多一个 `saveRefusal` 状态(带文件路径,
+ 只画在它所属的那份草稿上)。`save()` 的失败分支不再走 `toastError`,而是写上那句话;开始编辑、改动草稿、
+ 下一次保存与切换 Session 各自清掉。`file_changed`(409)仍进它自己的覆盖确认框,那是提问不是失败。
+- `packages/web/src/lib/strings{,-en}.ts`:一对新文案 `files.saveRefused(reason)` /
+ `files.saveRefusedDraftKept(reason)`。
+
+## 测试
+
+- `packages/web/test/editor-save-refusal.test.ts`(新,6 条):服务端的答复按错误码念它自己的本地化句子、
+ 不带线上英文原文;草稿与文件不同时补上「没有写进文件」;两者相同时不补;本仓自己抛的值按原话念;无话可
+ 说时退回通用句;用的是当前语言。
+- `packages/web/e2e/editor-save-refusal.spec.mjs`(新,真服务端 + 真浏览器):把这一笔写入在
+ `page.route` 上桩成 403,在编辑框里改字后按保存并确认。那句话出现在标题行下面、通知区里没有它,文件仍是
+ 旧内容而编辑框仍留着草稿、保存按钮仍可再按;**7 秒后**(超过错误通知活着的 6 秒)它仍在;改一个字它就
+ 消失;放行之后重试,内容落盘、那句话不再回来。第二条:被拒之后退出编辑(确认放弃),那句话与草稿一起走。
+
+## 兼容性
+
+不碰接口、不引入新依赖、不改 Project 配置。同一份编辑器里「内容超过写入上限」那条仍在按下保存时的本地
+检查里走通知:它没有发出任何请求、也没有改写什么,要改的是内容本身。
diff --git a/packages/web/e2e/editor-save-refusal.spec.mjs b/packages/web/e2e/editor-save-refusal.spec.mjs
new file mode 100644
index 00000000..853a2933
--- /dev/null
+++ b/packages/web/e2e/editor-save-refusal.spec.mjs
@@ -0,0 +1,170 @@
+/**
+ * Regression: a save the Files panel's editor cannot land keeps its reason under the panel's
+ * header, beside the Save button that retries it — instead of leaving only a toast behind.
+ *
+ * `features/chat/workspace-browser.tsx` wrote nothing and closed nobody on a refused save: the
+ * editor stayed open with the draft in it, the header still carried Save, and the reason fell into
+ * a notification that dismissed itself after six seconds. Afterwards the panel looked exactly as
+ * it had before the press, the file on disk still held the old text, and the text the reader had
+ * typed was nowhere but the textarea — with no word about why.
+ *
+ * The write is stubbed (the real route would need a Workspace that refuses writes, which a test
+ * cannot arrange); everything else — the session, the file, the editor, the draft — is the app's
+ * own.
+ */
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+import { test, expect } from "@playwright/test";
+import { provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const P = "password123";
+const FILE = "notes.md";
+const STORED = "first line\n";
+const DRAFT = "first line\n第二行:先跑起来。\n";
+
+/** The write route, query string and all (the path travels in `?path=`). */
+const WRITE_ROUTE = "**/api/sessions/*/files/content**";
+
+/** The refusal the panel paints: its code has its own Chinese copy, so its English words must not appear. */
+const REFUSAL = {
+ code: "dir_permission_denied",
+ message: "permission denied for the workspace directory",
+};
+/** S.errors.byCode.dir_permission_denied, the sentence that code stands for. */
+const SENTENCE = "没有访问该目录的权限。";
+
+/** A Project with the mock as its model, and one Session whose Workspace holds one file. */
+async function setUp(page, user) {
+ const dir = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "e2e-editor-save-")), "files");
+ fs.mkdirSync(dir, { recursive: true });
+ fs.writeFileSync(path.join(dir, FILE), STORED);
+ await provisionAndLogin(page.request, user, P);
+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]
+ .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").toBeTruthy();
+ const res = await page.request.post(
+ `${BASE}/api/projects/${projectId}/agents/default_agent/sessions`,
+ { data: { workspace: dir } },
+ );
+ expect(res.ok(), "create session").toBeTruthy();
+ return { dir, sessionId: (await res.json()).session.sessionId };
+}
+
+/** The Files panel on the session's page, with the tree loaded. */
+async function openFiles(page, sessionId) {
+ await page.goto(`${BASE}/chat/${sessionId}`);
+ await page.getByPlaceholder(/输入消息/).waitFor();
+ await page.getByTestId("dock-toggle-right").click();
+ await page.getByTestId("dock-pick-workspace").click();
+ const dock = page.getByTestId("dock");
+ await dock.locator('[role="tree"]').waitFor();
+ return dock;
+}
+
+/** The file opened in the editor with the draft typed over. */
+async function openEditor(page, dock) {
+ await dock.locator(`[data-tree-path="${FILE}"]`).click();
+ await dock.getByRole("button", { name: "编辑", exact: true }).click();
+ const editor = dock.getByRole("textbox", { name: `编辑 ${FILE}` });
+ await expect(editor).toBeVisible();
+ await editor.fill(DRAFT);
+ return editor;
+}
+
+/** Save is behind a confirmation whose own button is the write. */
+async function pressSave(page, dock) {
+ await dock.getByRole("button", { name: "保存", exact: true }).click();
+ const dialog = page.getByRole("dialog");
+ await expect(dialog).toBeVisible();
+ await dialog.getByRole("button", { name: "保存", exact: true }).click();
+}
+
+test("a refused save keeps its reason under the header, and Save is the retry", async ({
+ page,
+}) => {
+ const { dir, sessionId } = await setUp(page, "r200edsave");
+ const dock = await openFiles(page, sessionId);
+ const editor = await openEditor(page, dock);
+
+ const writes = [];
+ await page.route(WRITE_ROUTE, async (route) => {
+ if (route.request().method() !== "PUT") return route.fallback();
+ writes.push(route.request().postDataJSON());
+ await route.fulfill({
+ status: 403,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+
+ await pressSave(page, dock);
+
+ // The reason is under the header and it is not a toast: the notification region never carries it.
+ const line = dock.getByRole("alert");
+ await expect(line).toContainText(SENTENCE);
+ await expect(line).toContainText("编辑器里的改动没有写进文件");
+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(SENTENCE);
+ expect(writes).toHaveLength(1);
+
+ // Nothing was written and nothing was lost: the file holds the old text, the editor the draft,
+ // and the Save that retried is still in the header.
+ expect(fs.readFileSync(path.join(dir, FILE), "utf8")).toBe(STORED);
+ await expect(editor).toHaveValue(DRAFT);
+ await expect(dock.getByRole("button", { name: "保存", exact: true })).toBeVisible();
+
+ // Still there after the toast would have gone.
+ await page.waitForTimeout(7000);
+ await expect(line).toContainText(SENTENCE);
+
+ // Typing answers the question the line described: it goes with the text it was about.
+ await editor.fill(`${DRAFT}再补一句。\n`);
+ await expect(dock.getByRole("alert")).toHaveCount(0);
+
+ // The retry lands: the file takes the new text and the line stays gone.
+ await page.unroute(WRITE_ROUTE);
+ await pressSave(page, dock);
+ await expect(dock.getByRole("alert")).toHaveCount(0);
+ // What did land is the write's own success notification — nothing left to keep on the panel.
+ await expect(page.getByRole("region", { name: "通知" })).toContainText("已保存");
+ expect(fs.readFileSync(path.join(dir, FILE), "utf8")).toBe(`${DRAFT}再补一句。\n`);
+});
+
+test("leaving the editor takes a refused save's reason with it", async ({ page }) => {
+ const { sessionId } = await setUp(page, "r200edsave2");
+ const dock = await openFiles(page, sessionId);
+ await openEditor(page, dock);
+
+ await page.route(WRITE_ROUTE, async (route) => {
+ if (route.request().method() !== "PUT") return route.fallback();
+ await route.fulfill({
+ status: 403,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+ await pressSave(page, dock);
+ await expect(dock.getByRole("alert")).toContainText(SENTENCE);
+
+ // × asks first (the draft is unsaved), and answering it drops the draft and the line together.
+ await dock.getByRole("button", { name: "退出编辑", exact: true }).click();
+ await page.getByRole("dialog").getByRole("button", { name: "放弃", exact: true }).click();
+ await expect(dock.getByRole("alert")).toHaveCount(0);
+ await expect(dock.getByRole("textbox", { name: `编辑 ${FILE}` })).toHaveCount(0);
+});
diff --git a/packages/web/src/features/chat/editor-save-refusal.ts b/packages/web/src/features/chat/editor-save-refusal.ts
new file mode 100644
index 00000000..10e9a852
--- /dev/null
+++ b/packages/web/src/features/chat/editor-save-refusal.ts
@@ -0,0 +1,33 @@
+/**
+ * The Files panel's in-place editor: the sentence a refused save leaves under the header, and why
+ * that sentence is drawn on the panel instead of arriving as a toast.
+ *
+ * A refused save changes nothing else on screen — the editor stays open, the draft stays in it,
+ * and the header's Save is the retry — so the reason used to live only in a notification that
+ * dismissed itself after six seconds, leaving a panel that looked as though the button had simply
+ * not been pressed. The file on disk had not moved; what the reader had typed was nowhere but the
+ * textarea. The sentence now stays under the header that carries Save until the draft is edited,
+ * the save is pressed again, or the edit is left.
+ *
+ * The draft differing from the file is worth saying out loud, because that is the state the reader
+ * is left in. When the two are equal (a save pressed with nothing changed) there is nothing
+ * unsaved, so the sentence is just the reason.
+ *
+ * Which words: `refusalText`, the rule every refusal slot in the app follows (7.19) — 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.
+ */
+import { refusalText } from "../../lib/api-error";
+import { S } from "../../lib/strings";
+
+/**
+ * The line the panel draws under the header after a refused save.
+ *
+ * `sent` is the text the write carried (not the textarea's contents at the moment the answer came
+ * back: anything typed while the write was in flight is unsaved anyway), and `baseline` is what
+ * the file holds — the two being equal means there was nothing to write.
+ */
+export function editorSaveRefusal(error: unknown, sent: string, baseline: string): string {
+ const reason = refusalText(error);
+ return sent === baseline ? S.files.saveRefused(reason) : S.files.saveRefusedDraftKept(reason);
+}
diff --git a/packages/web/src/features/chat/workspace-browser.tsx b/packages/web/src/features/chat/workspace-browser.tsx
index 4d1501d1..412b9fa6 100644
--- a/packages/web/src/features/chat/workspace-browser.tsx
+++ b/packages/web/src/features/chat/workspace-browser.tsx
@@ -156,6 +156,7 @@ import { setCloseGuard } from "../dock/close-guard";
import { tabKey } from "../dock/dock-state";
import { PAPERCLIP_ICON } from "./attached-files-banner";
import { PdfPreview } from "./pdf-preview";
+import { editorSaveRefusal } from "./editor-save-refusal";
import { WorkspaceTreeView } from "./workspace-tree-view";
/**
@@ -566,6 +567,13 @@ export function WorkspaceBrowser({
const [sourceError, setSourceError] = useState<string | null>(null);
const [editor, setEditor] = useState<EditorState | null>(null);
const [saving, setSaving] = useState(false);
+ /**
+ * The words of a save the server refused, and the file they are about: the editor stays open
+ * with the draft in it and the header's Save is the retry, so the sentence is drawn under that
+ * header (see editor-save-refusal.ts) rather than in a toast that outlives nothing. Keyed by
+ * path so a different file's editor can never show it.
+ */
+ const [saveRefusal, setSaveRefusal] = useState<{ path: string; text: string } | null>(null);
const [saveConfirm, setSaveConfirm] = useState(false);
/** A save the server refused because the file had changed (non-null shows the conflict dialog). */
const [conflict, setConflict] = useState<{ name: string } | null>(null);
@@ -693,6 +701,7 @@ export function WorkspaceBrowser({
setPreview(null);
setSourceError(null);
setEditor(null);
+ setSaveRefusal(null);
setSaveConfirm(false);
setConflict(null);
setDiscardPrompt(null);
@@ -1444,6 +1453,8 @@ export function WorkspaceBrowser({
}
if (previewRef.current?.path !== current.path) return;
editorOpening.current = at;
+ // A fresh edit of a file starts without the words of another edit's refused save.
+ setSaveRefusal(null);
setEditor({ path: current.path, baseline: content, draft: content, version });
};
@@ -1462,6 +1473,9 @@ export function WorkspaceBrowser({
const current = editorRef.current;
if (current === null) return;
setEditor({ ...current, draft });
+ // The words were about the text that was not written; a different text is a different
+ // save, and answers the old sentence.
+ setSaveRefusal(null);
const key = draftKey(scopeKey, current.path);
if (draft === current.baseline) unsavedDrafts.delete(key);
else unsavedDrafts.set(key, draft);
@@ -1498,6 +1512,8 @@ export function WorkspaceBrowser({
const save = async (opts?: { overwrite?: boolean }): Promise<void> => {
setSaveConfirm(false);
setConflict(null);
+ // Another attempt answers the previous one, whatever it says.
+ setSaveRefusal(null);
const current = editorRef.current;
if (current === null) return;
const sent = current.draft;
@@ -1555,7 +1571,10 @@ export function WorkspaceBrowser({
setConflict({ name: baseName(current.path) });
return;
}
- toastError(apiErrorText(err));
+ // Nothing was written, and the editor is still holding the draft: the reason stays under
+ // the header whose Save retries it (7.19's rule), not in a toast over a panel that then
+ // looks exactly as it did before the press.
+ setSaveRefusal({ path: current.path, text: editorSaveRefusal(err, sent, current.baseline) });
} finally {
if (scopeKeyRef.current === key) setSaving(false);
}
@@ -2701,6 +2720,20 @@ export function WorkspaceBrowser({
{fileRowActions}
</div>
+ {/* A save the server refused: the editor below still holds text the file does not, and the
+ Save in the header above is the retry — so the reason stays between the two. Drawn only
+ for the file the editor is actually on: the words are about that draft. */}
+ {editing !== null && saveRefusal !== null && saveRefusal.path === editing.path && (
+ <p
+ role="alert"
+ data-tooltip={saveRefusal.text}
+ data-tooltip-content="text"
+ className={`shrink-0 border-b border-gray-200 px-3 py-1 line-clamp-2 break-words text-xs dark:border-gray-800 ${toneInk.danger}`}
+ >
+ {saveRefusal.text}
+ </p>
+ )}
+
<div className="relative flex min-h-0 flex-1">
{narrow ? (
// Narrow: one column, tree or preview.
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index a2e9f7d3..a388ed44 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -4389,6 +4389,11 @@ export const en: Strings = {
`The file is larger than ${kb}KB and cannot be edited here — download it instead`,
saveTooLarge: (mb: number): string =>
`The content exceeds the ${mb}MB write limit and was not saved`,
+ /** Under the header after a refused save: the server's reason, and that Save is the retry. */
+ saveRefused: (reason: string): string => `Could not save: ${reason}`,
+ /** The same refusal while the editor holds text the file does not: nothing typed was lost. */
+ saveRefusedDraftKept: (reason: string): string =>
+ `Could not save: ${reason} (what you edited is still in the editor, not in the file)`,
discardTitle: "Discard unsaved changes",
discardBody: (name: string): string => `${name} has unsaved changes. Discard them?`,
discard: "Discard",
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index a7810174..d338aabf 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -4455,6 +4455,11 @@ export const zh = {
saveConfirm: (name: string): string => `保存对 ${name} 的修改?Workspace 中的该文件将被覆盖。`,
editTooLarge: (kb: number): string => `文件超过 ${kb}KB,无法在此编辑,请下载后编辑`,
saveTooLarge: (mb: number): string => `内容超过 ${mb}MB 写入上限,未保存`,
+ /** Under the header after a refused save: the server's reason, and that Save is the retry. */
+ saveRefused: (reason: string): string => `保存失败:${reason}`,
+ /** The same refusal while the editor holds text the file does not: nothing typed was lost. */
+ saveRefusedDraftKept: (reason: string): string =>
+ `保存失败:${reason}(编辑器里的改动没有写进文件)`,
discardTitle: "放弃未保存的修改",
discardBody: (name: string): string => `${name} 有未保存的修改,放弃这些修改?`,
discard: "放弃",
diff --git a/packages/web/test/editor-save-refusal.test.ts b/packages/web/test/editor-save-refusal.test.ts
new file mode 100644
index 00000000..e048885f
--- /dev/null
+++ b/packages/web/test/editor-save-refusal.test.ts
@@ -0,0 +1,67 @@
+/**
+ * The Files panel editor's save branch (src/features/chat/editor-save-refusal.ts): the sentence a
+ * refused write leaves under the header, and whose words it uses.
+ *
+ * A refused save writes nothing, so the editor is still open holding the draft — that surface is
+ * where the sentence belongs, and it is the reason this test exists: a toast would be gone after
+ * six seconds while the text that was not written sits on screen. The draft-versus-file half is
+ * the other thing worth pinning: the reader has to be told the file did not take their text, and
+ * a save pressed on an untouched editor must not claim anything was lost.
+ */
+import { afterEach, describe, expect, it } from "vitest";
+import { ApiError } from "../src/api/client";
+import { en as EN } from "../src/lib/strings-en";
+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";
+import { editorSaveRefusal } from "../src/features/chat/editor-save-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("editorSaveRefusal", () => {
+ it("reads a server answer through its code's own localized sentence", () => {
+ const refused = new ApiError(500, "internal", "RAW ENGLISH SERVER MESSAGE");
+ const line = editorSaveRefusal(refused, "new text", "old text");
+ expect(line).toContain(S.errors.byCode["internal"] as string);
+ expect(line).not.toContain("RAW ENGLISH");
+ // The Chinese UI says so in Chinese; nothing of the wire message leaks through.
+ expect(line.startsWith(S.files.saveRefused(""))).toBe(true);
+ });
+
+ it("says the edits are still only in the editor when the file did not take them", () => {
+ const refused = new ApiError(413, "payload_too_large", "body too large");
+ const line = editorSaveRefusal(refused, "draft text", "stored text");
+ expect(line).toBe(S.files.saveRefusedDraftKept(S.errors.byCode["payload_too_large"] as string));
+ expect(line).toContain("编辑器里的改动没有写进文件");
+ });
+
+ it("claims nothing was lost when the save carried the file's own text", () => {
+ const refused = new ApiError(500, "internal", "RAW ENGLISH");
+ const line = editorSaveRefusal(refused, "same text", "same text");
+ expect(line).toBe(S.files.saveRefused(S.errors.byCode["internal"] as string));
+ expect(line).not.toContain("没有写进文件");
+ });
+
+ it("shows a value this codebase raised itself as it wrote it", () => {
+ // The panel raises its own conditions (a precondition it could not read, most likely); those
+ // sentences are already meant for the reader, so they are not replaced by a generic one.
+ const raised = new Error("读取文件版本失败,请重试");
+ expect(editorSaveRefusal(raised, "draft", "stored")).toBe(
+ S.files.saveRefusedDraftKept("读取文件版本失败,请重试"),
+ );
+ });
+
+ it("falls back to the generic sentence for a value with nothing to say", () => {
+ expect(editorSaveRefusal(undefined, "same", "same")).toBe(
+ S.files.saveRefused(S.common.unknownError),
+ );
+ });
+
+ it("follows the active language", () => {
+ setActiveStrings(EN);
+ const refused = new ApiError(500, "internal", "RAW ENGLISH");
+ const line = editorSaveRefusal(refused, "draft", "stored");
+ expect(line.startsWith("Could not save: ")).toBe(true);
+ expect(line).toContain("still in the editor, not in the file");
+ });
+});