Skip to content

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

fix(web): 文件面板的上传被拒时,原因留在列表上方,不再只活六秒

lmliheng9b5fc76e5253
diff --git a/changelog/unreleased/2026-11-06-upload-refusal.md b/changelog/unreleased/2026-11-06-upload-refusal.md
new file mode 100644
index 00000000..a58e4004
--- /dev/null
+++ b/changelog/unreleased/2026-11-06-upload-refusal.md
@@ -0,0 +1,55 @@
+# An upload the Files panel could not land says why above the listing, not in a six-second toast
+
+- **Date:** 2026-11-06
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-11-06-upload-refusal.zh.md)
+
+The Files panel takes picked or dropped files and writes them into the current Workspace directory.
+When that write did not land — the server refused it, the directory had no permission, the request
+never arrived — nothing on the panel changed: the file never appeared in the tree, the listing still
+held what it held, the picker was ready for the same files again, and the reason went to a
+notification that dismissed itself after six seconds. Afterwards the panel looked exactly as it had
+before the pick, and the files were still only on the reader's own disk, with no word about why.
+
+That sentence now renders between the header and the listing (`role="alert"`, danger colour, two
+lines, the whole sentence on hover), and stays until the next upload starts or the Session switches.
+When nothing landed it says "could not upload to <dir>: <reason>"; when the batch stopped halfway it
+names the files that did not go up instead — the only way to know what to pick again. The sentence
+carries the directory's name, because an upload can go to a folder other than the one in view (the
+row menu's upload).
+
+## Details
+
+- `packages/web/src/features/chat/upload-refusal.ts` (new): `uploadRefusalLine(error, target, sent,
+ unsent)` — 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 Files panel gains an `uploadRefusal`
+ state. `doUpload()`'s failure branch no longer calls `toastError` but writes that sentence; the
+ next upload and a scope switch each clear it.
+- `packages/web/src/lib/strings{,-en}.ts`: one new pair, `files.uploadRefused(dir, reason)` /
+ `files.uploadRefusedPartial(dir, names, reason)`.
+
+## Tests
+
+- `packages/web/test/upload-refusal.test.ts` (new, 7 cases): a server answer is read through its
+ code's own localized sentence, never the wire message; a whole-batch refusal names no files; a
+ half-landed batch names the rest and never counts what landed as a failure; the directory is named
+ as the panel names it (the root is "."); 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/upload-refusal.spec.mjs` (new, real server, real browser): the write is stubbed
+ to 403 and a file is picked through the panel's own picker. The line appears under the header, the
+ notification region never carries it, the directory stays empty and the tree has no row for the
+ file; **seven seconds later** (past the six an error notification lives) it is still there; with
+ the route allowed through, picking the same files again writes the file, the row appears and the
+ line does not come back. A second case: of three files the first really lands and the second is
+ refused — the line names only `b.md, c.md`, and `a.md` is really on disk and not counted as a
+ failure.
+
+## Compatibility
+
+No interface change, no new dependency, no Project config change. The checks made while picking keep
+their notification: oversize files and dropped folders are named and skipped before anything is sent
+— what has to change there is what was picked, not a server's reason.
diff --git a/changelog/unreleased/2026-11-06-upload-refusal.zh.md b/changelog/unreleased/2026-11-06-upload-refusal.zh.md
new file mode 100644
index 00000000..98d0e4aa
--- /dev/null
+++ b/changelog/unreleased/2026-11-06-upload-refusal.zh.md
@@ -0,0 +1,43 @@
+# 文件面板里没上去的上传,原因留在列表上方,不再只活六秒
+
+- **日期:** 2026-11-06
+- **类型:** fix
+- **范围:** `web`
+- **破坏性:** 否
+
+[English](2026-11-06-upload-refusal.md)
+
+文件面板可以选中或拖入文件,写进当前 Workspace 目录。那次写入没落地时 —— 服务端拒了、目录没有权限、
+请求根本没到 —— 面板上什么都没有变:文件没出现在树里、目录还是原来那些行、选择器照旧可以再选同一批
+文件,而原因只落进一条通知,六秒后自己消失。此后屏幕与选中之前一模一样,文件仍只在用户自己的磁盘上,
+却没有任何一句话说明为什么。
+
+那句话现在画在**标题行与列表之间**(`role="alert"`、危险色、限两行、整句挂悬停),一直留到下一次
+上传开始或切换 Session 为止。整批都没上去时它说「上传到 <目录> 失败:<原因>」;半途卡住时改为点名
+**没有上去的那几个文件** —— 那是唯一能知道该重挑什么的方式。句子带着目录名,因为上传也可以去当前
+视图之外的目录(右键菜单的上传)。
+
+## 明细
+
+- `packages/web/src/features/chat/upload-refusal.ts`(新):`uploadRefusalLine(error, target, sent,
+ unsent)` —— 纯判断,念哪句话只在这一处,不依赖面板就能测。
+- `packages/web/src/features/chat/workspace-browser.tsx`:文件面板多一个 `uploadRefusal` 状态。
+ `doUpload()` 的失败分支不再走 `toastError`,而是写上那句话;开始下一次上传与切换 Session 各自清掉。
+- `packages/web/src/lib/strings{,-en}.ts`:一对新文案 `files.uploadRefused(dir, reason)` /
+ `files.uploadRefusedPartial(dir, names, reason)`。
+
+## 测试
+
+- `packages/web/test/upload-refusal.test.ts`(新,7 条):服务端的答复按错误码念它自己的本地化句子、
+ 不带线上英文原文;整批没上去时不点名文件;半途卡住时点名没上去的那几个、不把已经落盘的算作失败;
+ 目录名按面板的叫法(根是 `.`);本仓自己抛的值按原话念;无话可说时退回通用句;用的是当前语言。
+- `packages/web/e2e/upload-refusal.spec.mjs`(新,真服务端 + 真浏览器):把这一笔写入在 `page.route`
+ 上桩成 403,用面板自己的选择器选一个文件。那句话出现在标题行下面、通知区里没有它,目录仍是空的、
+ 树里没有这一行;**7 秒后**(超过错误通知活着的 6 秒)它仍在;放行之后重挑一次,文件落盘、行出现、
+ 那句原因不再回来。第二条:三个文件里第一个真落盘、第二个 403 —— 句子只点名 `b.md, c.md`,`a.md`
+ 真的在磁盘上且不被算作失败。
+
+## 兼容性
+
+不碰接口、不引入新依赖、不改 Project 配置。选中阶段的本地检查仍走通知:超过上传上限的文件与拖进来的
+文件夹在发出任何请求之前就被点名跳过,要改的是选了什么,不是一句服务端的理由。
diff --git a/packages/web/e2e/upload-refusal.spec.mjs b/packages/web/e2e/upload-refusal.spec.mjs
new file mode 100644
index 00000000..d6f421b6
--- /dev/null
+++ b/packages/web/e2e/upload-refusal.spec.mjs
@@ -0,0 +1,161 @@
+/**
+ * Regression: an upload the Files panel cannot land keeps its reason above the listing, instead of
+ * leaving only a toast that dismisses itself after six seconds.
+ *
+ * `features/chat/workspace-browser.tsx` wrote nothing and moved nothing on a refused upload: the
+ * file never appeared in the tree, the directory still held what it held, and the picker was ready
+ * for the same files again — with no word about why. Afterwards the panel looked exactly as it had
+ * before the pick, and the files were still only where they were read from.
+ *
+ * The write is stubbed (the real route would need a Workspace that refuses writes, which a test
+ * cannot arrange); everything else — the session, the directory, the write that lands — 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";
+
+/** 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 = "没有访问该目录的权限。";
+/** The Workspace root as the panel names it (S.files.root). */
+const ROOT = ".";
+
+/** A Project with the mock as its model, and one Session on an empty Workspace. */
+async function setUp(page, user) {
+ const dir = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "e2e-upload-")), "files");
+ fs.mkdirSync(dir, { recursive: true });
+ 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;
+}
+
+/** Picks files through the toolbar's own picker, as a reader would. */
+async function pick(dock, files) {
+ await dock.locator('input[type="file"]:not([aria-hidden])').setInputFiles(
+ files.map(([name, text]) => ({
+ name,
+ mimeType: "text/markdown",
+ buffer: Buffer.from(text),
+ })),
+ );
+}
+
+test("a refused upload keeps its reason above the listing, and picking again is the retry", async ({
+ page,
+}) => {
+ const { dir, sessionId } = await setUp(page, "r201upload");
+ const dock = await openFiles(page, sessionId);
+
+ 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 pick(dock, [["notes.md", "first line\n"]]);
+
+ // The reason is above the listing and it is not a toast: the notification region never carries it.
+ const line = dock.getByRole("alert");
+ await expect(line).toContainText(`上传到 ${ROOT} 失败:${SENTENCE}`);
+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(SENTENCE);
+
+ // Nothing was written: the directory is still empty and the tree has no row for the file.
+ expect(fs.readdirSync(dir)).toEqual([]);
+ await expect(dock.locator('[data-tree-path="notes.md"]')).toHaveCount(0);
+ // The picker still takes the same files again.
+ await expect(dock.locator('input[type="file"]:not([aria-hidden])')).toBeEnabled();
+
+ // Still there after the toast would have gone.
+ await page.waitForTimeout(7000);
+ await expect(line).toContainText(SENTENCE);
+
+ // The retry lands: the file appears, the success is the notification, and the line is gone.
+ await page.unroute(WRITE_ROUTE);
+ await pick(dock, [["notes.md", "first line\n"]]);
+ await expect(dock.getByRole("alert")).toHaveCount(0);
+ await expect(page.getByRole("region", { name: "通知" })).toContainText("已上传 1 个文件");
+ await expect.poll(() => fs.readdirSync(dir)).toEqual(["notes.md"]);
+});
+
+test("a batch that lands halfway names only the files that did not go up", async ({ page }) => {
+ const { dir, sessionId } = await setUp(page, "r201uploadpart");
+ const dock = await openFiles(page, sessionId);
+
+ let writes = 0;
+ await page.route(WRITE_ROUTE, async (route) => {
+ if (route.request().method() !== "PUT") return route.fallback();
+ writes += 1;
+ if (writes === 1) return route.fallback(); // the first file really lands
+ await route.fulfill({
+ status: 403,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+
+ await pick(dock, [
+ ["a.md", "A\n"],
+ ["b.md", "B\n"],
+ ["c.md", "C\n"],
+ ]);
+
+ const line = dock.getByRole("alert");
+ await expect(line).toContainText(`上传到 ${ROOT} 时,b.md, c.md 没有上传:${SENTENCE}`);
+ // The one that landed is not named as a failure.
+ await expect(line).not.toContainText("a.md");
+
+ // a.md is really on disk; the two behind it are not, and the row for the one that landed is there.
+ expect(fs.readdirSync(dir)).toEqual(["a.md"]);
+ await expect(dock.locator('[data-tree-path="a.md"]')).toHaveCount(1);
+ await expect(dock.locator('[data-tree-path="b.md"]')).toHaveCount(0);
+ expect(writes).toBe(2);
+});
diff --git a/packages/web/src/features/chat/upload-refusal.ts b/packages/web/src/features/chat/upload-refusal.ts
new file mode 100644
index 00000000..9b3db4b7
--- /dev/null
+++ b/packages/web/src/features/chat/upload-refusal.ts
@@ -0,0 +1,44 @@
+/**
+ * The Files panel's upload: the sentence a refused write leaves above the listing, and why it is
+ * drawn on the panel instead of arriving as a toast.
+ *
+ * An upload that the server refuses leaves the panel looking untouched — the file is not in the
+ * tree, the directory still holds what it held, and the picker is ready for the same files again —
+ * so the reason used to live only in a notification that dismissed itself after six seconds. What
+ * the reader is left with is a directory that simply does not contain the file they dropped, with
+ * nothing to say whether the box refused it, the path has no permission, or the request never
+ * arrived. The sentence now stays above the rows until the next upload starts or the Session
+ * switches.
+ *
+ * Two states, because they are different losses: nothing landed (the whole batch is still only on
+ * the reader's disk), or some files landed and the rest did not — in which case naming the ones
+ * that did not is the only way to know what to pick again.
+ *
+ * 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 above the listing after a refused upload. Named `…Line` because the
+ * panel's state for it (`uploadRefusal`) holds the sentence itself.
+ *
+ * `target` is the directory as the panel names it (the caller's own label: the Workspace root
+ * reads as ".", a directory as its path — the sentence has to say which directory did not take the
+ * files, since an upload can go to a folder other than the one in view). `sent` counts the files
+ * that did land, and `unsent` names the rest, in picking order — the one that was refused and
+ * every file after it that was never tried.
+ */
+export function uploadRefusalLine(
+ error: unknown,
+ target: string,
+ sent: number,
+ unsent: readonly string[],
+): string {
+ const reason = refusalText(error);
+ return sent === 0
+ ? S.files.uploadRefused(target, reason)
+ : S.files.uploadRefusedPartial(target, unsent.join(", "), reason);
+}
diff --git a/packages/web/src/features/chat/workspace-browser.tsx b/packages/web/src/features/chat/workspace-browser.tsx
index 412b9fa6..32281b83 100644
--- a/packages/web/src/features/chat/workspace-browser.tsx
+++ b/packages/web/src/features/chat/workspace-browser.tsx
@@ -157,6 +157,7 @@ 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 { uploadRefusalLine } from "./upload-refusal";
import { WorkspaceTreeView } from "./workspace-tree-view";
/**
@@ -605,6 +606,12 @@ export function WorkspaceBrowser({
);
// ------------------------------------------------------------------------ upload / drop
const [uploading, setUploading] = useState<{ done: number; total: number } | null>(null);
+ /**
+ * The words of an upload the server refused, drawn above the listing (see upload-refusal.ts):
+ * the file is not in the tree and the panel otherwise looks untouched, so a toast that dismisses
+ * itself would leave the reader with a directory that simply does not hold what they dropped.
+ */
+ const [uploadRefusal, setUploadRefusal] = useState<string | null>(null);
/** Picked files whose names collide with the target directory's listing (non-null shows the overwrite confirm). */
const [pendingUpload, setPendingUpload] = useState<{
files: File[];
@@ -711,6 +718,7 @@ export function WorkspaceBrowser({
// the Session forever. A staged overwrite confirmation is dropped for the same reason:
// answering it after the switch would upload the old Session's files into this one.
setUploading(null);
+ setUploadRefusal(null);
setPendingUpload(null);
setSaving(false);
// An open menu points at a path in the Session that just left; its actions would run
@@ -1597,6 +1605,9 @@ export function WorkspaceBrowser({
const doUpload = async (picked: File[], dir: string): Promise<void> => {
const key = scopeKey;
setUploading({ done: 0, total: picked.length });
+ // A fresh pick answers the last refusal: whatever it said was about files that are no longer
+ // the ones being sent.
+ setUploadRefusal(null);
const uploaded: string[] = [];
try {
for (const [i, file] of picked.entries()) {
@@ -1618,7 +1629,18 @@ export function WorkspaceBrowser({
}
toastSuccess(S.files.uploadedCount(uploaded.length));
} catch (err) {
- toastError(apiErrorText(err));
+ // Nothing else on screen moved: the panel still shows a directory without these files, and
+ // picking them again is the retry — so the reason stays above the rows.
+ if (scopeKeyRef.current === key) {
+ setUploadRefusal(
+ uploadRefusalLine(
+ err,
+ dirLabel(dir),
+ uploaded.length,
+ picked.slice(uploaded.length).map((f) => f.name),
+ ),
+ );
+ }
} finally {
if (scopeKeyRef.current === key) setUploading(null);
}
@@ -2720,6 +2742,19 @@ export function WorkspaceBrowser({
{fileRowActions}
</div>
+ {/* An upload the server refused: nothing was written, so the panel looks untouched and
+ picking the files again is the retry — the reason stays above what it is about. */}
+ {uploadRefusal !== null && (
+ <p
+ role="alert"
+ data-tooltip={uploadRefusal}
+ 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}`}
+ >
+ {uploadRefusal}
+ </p>
+ )}
+
{/* 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. */}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index a388ed44..08514c0d 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -4351,6 +4351,14 @@ export const en: Strings = {
`Over the ${mb}MB upload limit, skipped: ${names}`,
/** A dropped folder is not a file the upload endpoint can take; it is named and skipped. */
folderDropSkipped: (names: string): string => `Folders cannot be uploaded, skipped: ${names}`,
+ /**
+ * Above the listing after an upload the server refused: nothing landed, so the files are still
+ * only where they were picked from, and picking them again is the retry.
+ */
+ uploadRefused: (dir: string, reason: string): string => `Could not upload to ${dir}: ${reason}`,
+ /** The same refusal when part of the batch landed: the rest has to be picked again by name. */
+ uploadRefusedPartial: (dir: string, names: string, reason: string): string =>
+ `Not uploaded to ${dir}: ${names} — ${reason}`,
/** Upload-overwrite confirmation: same-name files in the target directory will be replaced. */
overwriteTitle: "Overwrite existing files",
overwriteConfirm: (n: number): string =>
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index d338aabf..911069b0 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -4421,6 +4421,14 @@ export const zh = {
`超过 ${mb}MB 上传上限,已跳过:${names}`,
/** A dropped folder is not a file the upload endpoint can take; it is named and skipped. */
folderDropSkipped: (names: string): string => `不支持上传文件夹,已跳过:${names}`,
+ /**
+ * Above the listing after an upload the server refused: nothing landed, so the files are still
+ * only where they were picked from, and Save is not the retry — picking them again is.
+ */
+ uploadRefused: (dir: string, reason: string): string => `上传到 ${dir} 失败:${reason}`,
+ /** The same refusal when part of the batch landed: the rest has to be picked again by name. */
+ uploadRefusedPartial: (dir: string, names: string, reason: string): string =>
+ `上传到 ${dir} 时,${names} 没有上传:${reason}`,
/** Upload-overwrite confirmation: same-name files in the target directory will be replaced. */
overwriteTitle: "覆盖同名文件",
overwriteConfirm: (n: number): string => `目标目录已存在以下 ${n} 个同名文件,上传将覆盖:`,
diff --git a/packages/web/test/upload-refusal.test.ts b/packages/web/test/upload-refusal.test.ts
new file mode 100644
index 00000000..46915d57
--- /dev/null
+++ b/packages/web/test/upload-refusal.test.ts
@@ -0,0 +1,80 @@
+/**
+ * The Files panel's upload branch (src/features/chat/upload-refusal.ts): the sentence a refused
+ * upload leaves above the listing, and whose words it uses.
+ *
+ * A refused upload writes nothing, so the panel is still showing the directory without the files —
+ * 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 files sit on the reader's disk and nowhere in the Workspace.
+ * The whole-batch-versus-partly half is the other thing worth pinning: when some files landed and
+ * the rest did not, naming the rest is the only way to know what to pick again.
+ */
+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 { uploadRefusalLine } from "../src/features/chat/upload-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("uploadRefusalLine", () => {
+ it("reads a server answer through its code's own localized sentence", () => {
+ const refused = new ApiError(403, "dir_permission_denied", "RAW ENGLISH SERVER MESSAGE");
+ const line = uploadRefusalLine(refused, "docs", 0, ["notes.md"]);
+ expect(line).toContain(S.errors.byCode["dir_permission_denied"] 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.uploadRefused("docs", ""))).toBe(true);
+ });
+
+ it("says nothing landed when the first file was refused", () => {
+ const refused = new ApiError(500, "internal", "boom");
+ expect(uploadRefusalLine(refused, "docs", 0, ["a.txt", "b.txt"])).toBe(
+ S.files.uploadRefused("docs", S.errors.byCode["internal"] as string),
+ );
+ });
+
+ it("names the files that did not land when part of the batch went through", () => {
+ const refused = new ApiError(413, "payload_too_large", "body too large");
+ const line = uploadRefusalLine(refused, "docs", 2, ["c.txt", "d.txt"]);
+ expect(line).toBe(
+ S.files.uploadRefusedPartial(
+ "docs",
+ "c.txt, d.txt",
+ S.errors.byCode["payload_too_large"] as string,
+ ),
+ );
+ // The files that already landed are not named as failures.
+ expect(line).not.toContain("a.txt");
+ });
+
+ it("names the target directory as the panel labels it", () => {
+ // The Workspace root reaches this module already labelled ("."), which is how the rest of the
+ // panel names it — an upload can go to a folder other than the one in view.
+ const refused = new ApiError(500, "internal", "boom");
+ expect(uploadRefusalLine(refused, S.files.root, 0, ["a.txt"])).toBe(
+ S.files.uploadRefused(S.files.root, S.errors.byCode["internal"] as string),
+ );
+ });
+
+ it("shows a value this codebase raised itself as it wrote it", () => {
+ const raised = new Error("读取文件内容失败,请重试");
+ expect(uploadRefusalLine(raised, "docs", 0, ["a.txt"])).toBe(
+ S.files.uploadRefused("docs", "读取文件内容失败,请重试"),
+ );
+ });
+
+ it("falls back to the generic sentence for a value with nothing to say", () => {
+ expect(uploadRefusalLine(undefined, "docs", 0, ["a.txt"])).toBe(
+ S.files.uploadRefused("docs", S.common.unknownError),
+ );
+ });
+
+ it("follows the active language", () => {
+ setActiveStrings(EN);
+ const refused = new ApiError(403, "dir_permission_denied", "RAW ENGLISH");
+ const line = uploadRefusalLine(refused, "docs", 0, ["a.txt"]);
+ expect(line.startsWith("Could not upload to docs: ")).toBe(true);
+ });
+});