Skip to content

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

fix(web): 新建文件夹被拒时原因留在名称框下面,不再只活六秒

lmliheng372aebf6858c
diff --git a/changelog/unreleased/2026-11-01-finder-new-folder-refusal.md b/changelog/unreleased/2026-11-01-finder-new-folder-refusal.md
new file mode 100644
index 00000000..a18a3c8c
--- /dev/null
+++ b/changelog/unreleased/2026-11-01-finder-new-folder-refusal.md
@@ -0,0 +1,53 @@
+# A refused folder name says why under the New folder box, instead of in a toast that expires
+
+- **Date:** 2026-11-01
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-11-01-finder-new-folder-refusal.zh.md)
+
+In the Workspace finder, "New folder" opens a name box at the head of the list. A refused name —
+one the folder already holds, or one that is a path rather than a name — leaves that box open with
+what was typed and puts the caret back in it, because the name is the thing to change and Enter
+again is the retry. The reason, though, arrived as a toast that dismissed after six seconds, so the
+box was left looking untouched and unexplained.
+
+The sentence now stays with the box: under the field, in the danger ink, as a `role="alert"`
+clamped to two lines with the whole of it on hover, until the name changes or another attempt
+starts. It goes when the box goes (Enter on a free name, Escape, or focus moving elsewhere) —
+nothing was written, and nothing on screen is left claiming it was.
+
+The name itself is now checked before the request, with the server's own rule: a separator (either
+spelling), `.` or `..`, or a NUL is a path rather than a name, and would either escape the folder
+on screen or name nothing. Asking it in the browser lets the box say so without a round trip; what
+the filesystem dislikes on its own (`*` on Windows, a name that is too long) still comes back from
+the server as a refusal, since only it can know. No new copy was written: both sentences come from
+the app's existing error table for `dir_exists` and `dir_name_invalid`, through the shared
+`refusalText()`.
+
+## Details
+
+- `packages/web/src/features/chat/workspace-finder.tsx`: a `newFolderRefusal` state, filled by both
+ failure paths instead of `toastError` and cleared at the first keystroke, when the box opens, and
+ when an attempt starts. The box and the sentence share one column inside the row, so the sentence
+ wraps where the name does rather than under the folder glyph.
+- `canMakeFolder(name)` in `workspace-finder-model.ts` — whether a name is one segment, mirroring
+ the route's `dirNameError` — is a function of its own, so the rule is tested without a DOM.
+
+## Tests
+
+- `packages/web/test/workspace-finder.test.ts` (three unit cases added): a plain name, one with a
+ dot or a space, a leading dot and a non-ASCII name are all taken; `a/b`, `a\b`, `.`, `..` and a
+ name holding a NUL are refused; nothing at all is refused.
+- `packages/web/e2e/finder-new-folder-refusal.spec.mjs` (new, two browser cases against the real
+ server): a name the folder already holds leaves the route's own 409 under the box — the typed
+ name still there, nothing in the notification area, still there seven seconds later — and the next
+ name clears it and lands the folder on disk; a name with a separator is refused in place with no
+ create request sent at all, and Escape takes the sentence away with the box.
+
+## Compatibility
+
+- No API or request change: the box sends the same `{parent, name}` to the same route and reads the
+ same answers. A name that would not have worked now fails without a round trip; everything the
+ filesystem alone can judge still goes to the server as before.
diff --git a/changelog/unreleased/2026-11-01-finder-new-folder-refusal.zh.md b/changelog/unreleased/2026-11-01-finder-new-folder-refusal.zh.md
new file mode 100644
index 00000000..80e0d926
--- /dev/null
+++ b/changelog/unreleased/2026-11-01-finder-new-folder-refusal.zh.md
@@ -0,0 +1,42 @@
+# 新建文件夹被拒时,原因留在名称框下面,不再只活六秒
+
+- **日期:** 2026-11-01
+- **类型:** fix
+- **范围:** `web`
+- **破坏性:** 无
+
+[English](2026-11-01-finder-new-folder-refusal.md)
+
+工作区选择器里,「新建文件夹」在列表头部开一个名称框。被拒的名称 —— 文件夹里已经有了的,或名字本身
+是路径的 —— 会让这个框留着、保留输入的名字、把光标放回框里,因为要改的正是那个名字,再按一次 Enter
+就是重试。可原因此前只落进六秒后自己消失的 toast,留下的就是一个看起来没被碰过、也没有解释的框。
+
+现在这句话留在框上:画在输入框下面,danger 色、`role="alert"`、限两行、整句挂悬停,一直留到名字
+被改动或下一次尝试开始;框走它就走(空闲名字按下 Enter、Esc、或焦点移到别处)—— 什么都没有写进去,
+屏幕上也就什么都不留下假装写过。
+
+名字本身改成发请求之前就按服务端那条规则先判:分隔符(两种写法)、`.` / `..`、或 NUL 都是路径而不是
+名字,要么逃出屏幕上这个文件夹,要么什么都没命名。在浏览器里先问一遍,框就能不跑一趟往返就把话说
+出来;而只有文件系统知道的那类(Windows 的 `*`、太长的名字)仍由服务端驳回。没有新增文案 —— 两句都
+取自应用已有的错误表(`dir_exists` / `dir_name_invalid`),经共享的 `refusalText()` 出来。
+
+## 细节
+
+- `packages/web/src/features/chat/workspace-finder.tsx`:多一个 `newFolderRefusal` 状态,两条失败的路
+ 都填它(不再 `toastError`),并在第一次敲键、框打开、以及下一次尝试开始时清空。框与这句话在行内
+ 共用一列,所以句子在名字那一列换行,而不是跑到文件夹图标下面。
+- `workspace-finder-model.ts` 里的 `canMakeFolder(name)` —— 判断名字是不是一段、与服务端路由的
+ `dirNameError` 同一条规则 —— 是独立的一个函数,不必有 DOM 就能测。
+
+## 测试
+
+- `packages/web/test/workspace-finder.test.ts`(新增 3 条):普通名字、带点或空格的名字、点开头的名字
+ 与非 ASCII 名字都放行;`a/b`、`a\b`、`.`、`..` 与含 NUL 的名字都拒绝;空名字拒绝。
+- `packages/web/e2e/finder-new-folder-refusal.spec.mjs`(新,真服务端两条):文件夹里已有的名字留下路由
+ 自己的 409 在那只框下面 —— 输入的名字还在、通知区里什么都没有、七秒后仍在 —— 换一个名字即清掉并把
+ 文件夹真的建到磁盘上;带分隔符的名字就地拒绝、一条新建请求都没发,按 Esc 时句子跟着框一起消失。
+
+## 兼容
+
+- 接口与请求都没变:这个框发的还是同一个 `{parent, name}` 到同一个路由,读的也是同样的答复。本来自
+ 己就建不成的名字现在少跑一趟往返;只有文件系统单独才能判定的,仍照旧交给服务端。
diff --git a/packages/web/e2e/finder-new-folder-refusal.spec.mjs b/packages/web/e2e/finder-new-folder-refusal.spec.mjs
new file mode 100644
index 00000000..a7a86b05
--- /dev/null
+++ b/packages/web/e2e/finder-new-folder-refusal.spec.mjs
@@ -0,0 +1,164 @@
+/**
+ * Regression: a New folder that was REFUSED says why under the name box itself, in the Workspace
+ * finder, and the sentence outlives the six seconds a toast lives.
+ *
+ * The box keeps everything on a refusal — the name that was typed, the caret in it — because the
+ * name is the thing to change, and pressing Enter again is the retry. The reason used to arrive as
+ * a notification over that box, so a reader who looked away was left with a box that looked
+ * untouched and no way to tell a taken name from one the system will not hold.
+ *
+ * Both cases run against the real server: a name the folder already holds is the route's own 409
+ * `dir_exists`, and a name that is a path is refused before any request is sent — the second test
+ * counts the create requests to prove nothing was asked. The finder is walked to a directory the
+ * test made under the system temp dir (its address bar takes an absolute path), so the folders it
+ * makes are the test's own.
+ */
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+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;
+
+/** The lines the box draws: the shared lead-in plus the app's sentence for the code. */
+const TAKEN_REFUSED = "操作被拒绝:这个名称已被占用。";
+const NOT_A_NAME_REFUSED =
+ "操作被拒绝:文件夹名称不能是路径、`.` 或 `..`,也不能含有系统不接受的字符。";
+
+/** A directory of the test's own under the system temp dir, holding the names it is given. */
+function tempDir(...names) {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "e2e-finder-"));
+ for (const name of names) fs.mkdirSync(path.join(dir, name));
+ return dir;
+}
+
+/**
+ * Sign in as the seeded administrator (the finder's create route asks the Project's access) and
+ * give the Project a model — the onboarding card covers the page without one.
+ */
+async function ready(page) {
+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);
+ 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();
+}
+
+/**
+ * The finder, opened the way a person opens it — the sidebar's new-workspace button — then walked
+ * to `dir` through its address bar (Ctrl+L, the path, Enter). It opens at this server's home,
+ * which is a folder no test may write into. The field is typed into rather than filled: it puts
+ * the segments back the moment focus leaves it, and a locator that re-resolves mid-chord is a
+ * different element.
+ */
+async function openFinder(page, dir, ...listed) {
+ await page.goto("/");
+ await page.getByRole("button", { name: "新建工作区" }).click();
+ const finder = page.getByRole("dialog", { name: "Workspace" });
+ await expect(finder).toBeVisible();
+ await expect(finder.getByRole("listbox")).toBeVisible();
+ await finder.getByRole("listbox").focus();
+ await page.keyboard.press("ControlOrMeta+l");
+ await page.keyboard.type(dir);
+ await page.keyboard.press("Enter");
+ // The folder on screen is the test's own: what it lists is what the test put there.
+ for (const name of listed) {
+ await expect(finder.getByRole("option", { name })).toBeVisible();
+ }
+ return finder;
+}
+
+/** The name box at the head of the list, opened from the toolbar. */
+async function openNameBox(finder) {
+ await finder.getByRole("button", { name: "新建文件夹" }).click();
+ const box = finder.getByRole("textbox", { name: "新建文件夹" });
+ await expect(box).toBeVisible();
+ return box;
+}
+
+/** The finder's create call, which is what a taken name refuses. */
+const isCreate = (res) => res.request().method() === "POST" && res.url().endsWith("/dirs");
+
+test("a taken folder name keeps its reason under the box, past the toast it used to be", async ({
+ page,
+}) => {
+ const dir = tempDir("taken");
+ await ready(page);
+ const finder = await openFinder(page, dir, "taken");
+ const notices = page.getByRole("region", { name: "通知" });
+ const box = await openNameBox(finder);
+
+ // A name the folder on screen already holds.
+ const refused = page.waitForResponse(isCreate);
+ await box.fill("taken");
+ await box.press("Enter");
+ expect((await refused).status(), "taken name").toBe(409);
+ // The box says why, keeps what was typed (that is what to change), and no notification is left
+ // standing over it.
+ await expect(finder.getByRole("alert")).toHaveText(TAKEN_REFUSED);
+ await expect(box).toHaveValue("taken");
+ await expect(notices.getByRole("button")).toHaveCount(0);
+
+ // Six seconds is how long a toast lives; this sentence has to still be there after it.
+ await page.waitForTimeout(7_000);
+ await expect(finder.getByRole("alert")).toHaveText(TAKEN_REFUSED);
+ await expect(box).toHaveValue("taken");
+ await expect(notices.getByRole("button")).toHaveCount(0);
+
+ // Typing another name is the retry: the sentence about the taken one goes with the first
+ // keystroke, and Enter makes the folder where the box was.
+ await box.fill("made-here");
+ await expect(finder.getByRole("alert")).toHaveCount(0);
+ const landed = page.waitForResponse(isCreate);
+ await box.press("Enter");
+ expect((await landed).status(), "free name").toBe(201);
+ await expect(finder.getByRole("option", { name: "made-here", selected: true })).toBeVisible();
+ await expect(finder.getByRole("textbox", { name: "新建文件夹" })).toHaveCount(0);
+ expect(fs.existsSync(path.join(dir, "made-here")), "the folder is on disk").toBe(true);
+});
+
+test("a name that is a path is refused in place, without asking the server", async ({ page }) => {
+ const dir = tempDir();
+ /** Every create the finder attempted: a name refused on its own face must not add one. */
+ const creates = [];
+ page.on("request", (req) => {
+ if (req.method() === "POST" && req.url().endsWith("/dirs")) creates.push(req.url());
+ });
+
+ await ready(page);
+ const finder = await openFinder(page, dir);
+ const notices = page.getByRole("region", { name: "通知" });
+ const box = await openNameBox(finder);
+
+ // A separator makes the name a path — the server's own rule, asked before the request, since
+ // what it would make would land outside the folder on screen.
+ await box.fill("a/b");
+ await box.press("Enter");
+ await expect(finder.getByRole("alert")).toHaveText(NOT_A_NAME_REFUSED);
+ await expect(box).toHaveValue("a/b");
+ await expect(notices.getByRole("button")).toHaveCount(0);
+ expect(creates, "a refused name asks the server nothing").toHaveLength(0);
+
+ // The sentence belongs to the box: Escape closes the box, and the sentence goes with it while
+ // the finder stays open.
+ await box.press("Escape");
+ await expect(finder.getByRole("textbox", { name: "新建文件夹" })).toHaveCount(0);
+ await expect(finder.getByRole("alert")).toHaveCount(0);
+ await expect(finder).toBeVisible();
+ expect(creates).toHaveLength(0);
+});
diff --git a/packages/web/src/features/chat/workspace-finder-model.ts b/packages/web/src/features/chat/workspace-finder-model.ts
index 2fd33a03..fe44dcb8 100644
--- a/packages/web/src/features/chat/workspace-finder-model.ts
+++ b/packages/web/src/features/chat/workspace-finder-model.ts
@@ -3,8 +3,8 @@
* DOM: path breadcrumbs, back/forward history, what the list shows and in which order,
* type-to-select, the sidebar's places (Quick access, with the user's own additions and
* removals, and the machine's locations — drives, volumes, mounts — with their names), the
- * context menu's items, the keyboard map, what the box for a folder the server may not read
- * offers, and the footer's no-folder button.
+ * context menu's items, the keyboard map, the rule a new folder's name has to keep, what the box
+ * for a folder the server may not read offers, and the footer's no-folder button.
*
* Paths come from whichever machine is being browsed, so nothing here asks the browser's own
* platform about a path — a Windows server's `C:\Users\me` and a Linux one's `/home/me` both
@@ -82,6 +82,21 @@ export function baseName(path: string): string {
return crumbs[crumbs.length - 1]?.label ?? path;
}
+/**
+ * Whether `name` names one folder, so it can be made inside the folder on screen.
+ *
+ * The server's own rule, asked before the request: `dirs.ts`'s `dirNameError` refuses the
+ * empty string, `.` and `..`, either separator a name may travel with, and a NUL — each of
+ * them is a path rather than a name, and would either escape the folder on screen or name
+ * nothing. Asking it here lets the box say so without a round trip; what the filesystem
+ * dislikes on its own (`*` on Windows, a name that is too long) still comes back from the
+ * server as a refusal, since only it can know.
+ */
+export function canMakeFolder(name: string): boolean {
+ if (name === "" || name === "." || name === "..") return false;
+ return !/[\\/]/.test(name) && !name.includes("\0");
+}
+
/** The separator a path's own family uses: a drive path or a UNC share splits on `\`. */
function separatorOf(path: string): string {
return /^[A-Za-z]:|^\\\\/.test(path) ? "\\" : "/";
diff --git a/packages/web/src/features/chat/workspace-finder.tsx b/packages/web/src/features/chat/workspace-finder.tsx
index 40e67dd2..17e7d693 100644
--- a/packages/web/src/features/chat/workspace-finder.tsx
+++ b/packages/web/src/features/chat/workspace-finder.tsx
@@ -32,6 +32,11 @@
* with anything in it, never the root or the Project's own directory, and only after the
* confirmation card says so (features/chat/workspace-finder-model.ts decides what either menu
* offers).
+ *
+ * A New folder the server refuses keeps its reason where the name is. The box stays open with
+ * the name that was typed, because the name is the thing to change, so the sentence belongs
+ * under that box rather than in a notification that dismisses itself over it: it goes when the
+ * box goes, and nothing on screen then claims a folder was made.
*/
import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import type {
@@ -66,10 +71,11 @@ import * as api from "../../api/endpoints";
import { ApiError } from "../../api/client";
import { writeClipboard } from "../../lib/clipboard";
import { S } from "../../lib/strings";
-import { apiErrorText } from "../../lib/api-error";
+import { apiErrorText, refusalText } from "../../lib/api-error";
import { isElectronRenderer } from "../../lib/desktop-renderer";
import { formatDateTime } from "../../lib/format";
import { STAT_ICONS } from "../../lib/stat-icons";
+import { toneInk } from "../../lib/tone";
import { machineLabel, nameOnMachine, workspaceMachines } from "../../lib/workspace-machines";
import type { WorkspaceMachine } from "../../lib/workspace-machines";
import { useSessions } from "../../state/sessions";
@@ -80,6 +86,7 @@ import {
baseName,
canGoBack,
canGoForward,
+ canMakeFolder,
clearButton,
defaultPlaces,
deniedBox,
@@ -254,6 +261,13 @@ export function WorkspaceFinder({
const [newFolderOpen, setNewFolderOpen] = useState(false);
const [newFolderName, setNewFolderName] = useState("");
const [creating, setCreating] = useState(false);
+ /**
+ * Why the last name was refused, drawn under the box until the name changes or a new attempt
+ * starts. The box keeps the caret there because the name is the thing to change, so the
+ * sentence is about the thing still on screen; it is not toasted, which would leave the same
+ * box looking untouched (7.64's rule for a refused write).
+ */
+ const [newFolderRefusal, setNewFolderRefusal] = useState<string | null>(null);
const newFolderRef = useRef<HTMLInputElement>(null);
/**
* The folder the Delete confirmation is about (null: nothing is being removed), and whether
@@ -563,6 +577,8 @@ export function WorkspaceFinder({
if (!canCreateFolder) return;
setFilter("");
setNewFolderName("");
+ // A fresh box: whatever the last one was refused for is not about this name.
+ setNewFolderRefusal(null);
setNewFolderOpen(true);
};
@@ -570,8 +586,8 @@ export function WorkspaceFinder({
* Makes the folder the box names, then reveals it: the folder on screen is re-read with the
* new one selected, so what was made is on screen rather than merely reported. A refusal —
* a name taken, one the system will not accept — leaves the box open with what was typed,
- * since the name is the thing to change; the reason is shown as a toast, which can speak
- * while the box keeps the caret.
+ * since the name is the thing to change, so the reason is drawn under that box and stays
+ * until the name changes; the box keeps the caret for the same reason.
*/
const createFolder = () => {
const parent = view.listing?.path ?? null;
@@ -581,12 +597,22 @@ export function WorkspaceFinder({
newFolderRef.current?.focus();
return;
}
+ // Any attempt makes the sentence about the last one stale, so it is cleared before this one
+ // can fail — a refusal that repeats then arrives as a fresh sentence rather than as none.
+ setNewFolderRefusal(null);
+ // A name that is a path rather than a name is refused here: the server would say the same
+ // thing, and the box can say it without asking.
+ if (!canMakeFolder(name)) {
+ setNewFolderRefusal(S.errors.byCode.dir_name_invalid);
+ newFolderRef.current?.focus();
+ return;
+ }
setCreating(true);
api
.createDir(projectId, parent, name)
.then((res) => load(parent, { record: false, select: res.path }))
.catch((err: unknown) => {
- toastError(apiErrorText(err));
+ setNewFolderRefusal(refusalText(err));
newFolderRef.current?.focus();
})
.finally(() => setCreating(false));
@@ -1531,39 +1557,62 @@ export function WorkspaceFinder({
);
} else {
// The name box rides at the head of the list, where the folder it will make will appear, and
- // an otherwise-empty folder shows it instead of "this folder is empty".
+ // an otherwise-empty folder shows it instead of "this folder is empty". A refused name is
+ // said under the box itself (`role="alert"`, danger ink, two lines at most with the whole of
+ // it on hover — a server's reason runs long), inside the field's own column so it wraps
+ // where the name does rather than under the folder glyph.
const newFolderRow = newFolderOpen ? (
- <div className="flex select-none items-center gap-1 py-1 pl-3 pr-2">
- <GlyphIcon d={ICONS.folder} size={ICON_SIZE.rowLead} className="shrink-0 text-gray-400" />
- <input
- ref={newFolderRef}
- value={newFolderName}
- aria-label={f.newFolder}
- placeholder={f.newFolderName}
- data-tooltip={f.newFolderHint}
- disabled={creating}
- {...noAutofill}
- onChange={(e) => setNewFolderName(e.target.value)}
- onKeyDown={(e) => {
- if (e.key === "Enter" && !e.nativeEvent.isComposing) {
- e.preventDefault();
- // The finder's own Enter opens the selected folder; this Enter makes the folder.
- e.stopPropagation();
- createFolder();
- } else if (e.key === "Escape") {
- // Escape closes the box, not the finder (see the wrapper's key map).
- e.preventDefault();
- e.stopPropagation();
- setNewFolderOpen(false);
- }
- }}
- // Focus moving away — to the list, to another control — abandons the new folder, the
- // way Explorer's does; a request already in flight is left to finish.
- onBlur={() => {
- if (!creating) setNewFolderOpen(false);
- }}
- className="h-6 min-w-0 flex-1 rounded-sm border border-gray-300 bg-white px-1.5 text-sm text-gray-800 outline-none placeholder:text-gray-400 focus:border-gray-400 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100"
- />
+ <div className="flex select-none items-start gap-1 py-1 pl-3 pr-2">
+ <div className="flex h-6 shrink-0 items-center">
+ <GlyphIcon d={ICONS.folder} size={ICON_SIZE.rowLead} className="text-gray-400" />
+ </div>
+ <div className="flex min-w-0 flex-1 flex-col">
+ <input
+ ref={newFolderRef}
+ value={newFolderName}
+ aria-label={f.newFolder}
+ placeholder={f.newFolderName}
+ data-tooltip={f.newFolderHint}
+ disabled={creating}
+ {...noAutofill}
+ onChange={(e) => {
+ setNewFolderName(e.target.value);
+ // The sentence was about the name that was refused, and this is another one.
+ setNewFolderRefusal(null);
+ }}
+ onKeyDown={(e) => {
+ if (e.key === "Enter" && !e.nativeEvent.isComposing) {
+ e.preventDefault();
+ // The finder's own Enter opens the selected folder; this Enter makes the folder.
+ e.stopPropagation();
+ createFolder();
+ } else if (e.key === "Escape") {
+ // Escape closes the box, not the finder (see the wrapper's key map).
+ e.preventDefault();
+ e.stopPropagation();
+ setNewFolderOpen(false);
+ }
+ }}
+ // Focus moving away — to the list, to another control — abandons the new folder, the
+ // way Explorer's does; a request already in flight is left to finish. The sentence
+ // goes with the box: nothing was written, and nothing is left on screen claiming it
+ // was.
+ onBlur={() => {
+ if (!creating) setNewFolderOpen(false);
+ }}
+ className="h-6 w-full min-w-0 rounded-sm border border-gray-300 bg-white px-1.5 text-sm text-gray-800 outline-none placeholder:text-gray-400 focus:border-gray-400 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-100"
+ />
+ {newFolderRefusal !== null && (
+ <p
+ role="alert"
+ data-tooltip={S.common.refused(newFolderRefusal)}
+ data-tooltip-content="text"
+ className={`line-clamp-2 mt-1 break-words pl-1.5 text-xs ${toneInk.danger}`}
+ >
+ {S.common.refused(newFolderRefusal)}
+ </p>
+ )}
+ </div>
</div>
) : null;
body = (
diff --git a/packages/web/test/workspace-finder.test.ts b/packages/web/test/workspace-finder.test.ts
index e388b62d..1d47d7dc 100644
--- a/packages/web/test/workspace-finder.test.ts
+++ b/packages/web/test/workspace-finder.test.ts
@@ -29,6 +29,8 @@
* names the folder a temporary Workspace would get (a Windows path keeps its separator) —
* none without the Agent's directory, while another machine is browsed, or for an unknown
* layout.
+ * - A new folder's name is one segment: a separator, `.` / `..`, a NUL or nothing at all is
+ * refused before the request, since the server would say the same thing.
*/
import { describe, expect, it } from "vitest";
import type { DirEntryInfo, DirListResponse, DirLocation } from "@adelie/server/api";
@@ -38,6 +40,7 @@ import {
addToQuickAccess,
canGoBack,
canGoForward,
+ canMakeFolder,
clearButton,
defaultPlaces,
deniedBox,
@@ -575,3 +578,21 @@ describe("the footer's no-folder button", () => {
expect(tempWorkspacePath("/")).toBeNull();
});
});
+
+describe("a new folder's name", () => {
+ it("takes any name that is one segment", () => {
+ for (const name of ["docs", "docs 2026", ".config", "..hidden", "a.b", "日本語"]) {
+ expect(canMakeFolder(name), name).toBe(true);
+ }
+ });
+
+ it("refuses a name that is a path rather than a name", () => {
+ for (const name of ["a/b", "a\\b", ".", "..", "a\u0000b"]) {
+ expect(canMakeFolder(name), JSON.stringify(name)).toBe(false);
+ }
+ });
+
+ it("refuses nothing at all, which would name no folder", () => {
+ expect(canMakeFolder("")).toBe(false);
+ });
+});