0c2f49876d
- Users page: one Edit user form (display name, email, role, active, a new or generated password, workspaces given or taken back, sign out everywhere), validated as a whole before anything is written (PATCH /api/users/:id, GET /api/users/:id); users.display_name/email added migration-safe. - Settings → Account for every signed-in user: profile, own password (the current one required, this login kept), sign out other devices (/api/me/account, /api/me/password, /api/me/sign-out-others; login cookie only, never a pane token). - Display names wherever a person is named (sidebar, workspace owner groups, Users page and audit log); owner_display_name / reader_display additive. - Users page: admins add and remove Claude/Codex pool accounts. - Folder browser: an admin with their own Linux account opens in their home; the "Server folder" tick opens the host's (never remembered). - AI Proxy: "Config 9router" beside Add profile when 9router is installed, opened on the dashboard's own host (GET /api/ai-proxies/9router). - Terminal: a tmux selection reaches the clipboard over plain HTTP too (writeClipboard's textarea fallback, focus handed back). - Chat: a file the session touched outside the workspace previews (GET /api/sessions/:id/file). - install-system: `!requiretty` only when visudo accepts it (sudo-rs on Ubuntu 25.10+ rejects the setting). - openapi.yaml regenerated; docs (API, SERVER-MODE, LANES) updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
2.2 KiB
TypeScript
58 lines
2.2 KiB
TypeScript
/**
|
|
* @file clipboard.test.ts
|
|
* @description `writeClipboard` / `copyText`: the async Clipboard API when the
|
|
* origin has one, else the hidden-textarea `execCommand("copy")` — the only
|
|
* path on `http://<lan-ip>`, where a terminal selection must still reach the
|
|
* user's clipboard — and the focus goes back to where it was.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { copyText, writeClipboard } from "../clipboard";
|
|
|
|
const original = Object.getOwnPropertyDescriptor(navigator, "clipboard");
|
|
const setClipboard = (value: unknown) =>
|
|
Object.defineProperty(navigator, "clipboard", { value, configurable: true });
|
|
|
|
afterEach(() => {
|
|
if (original) Object.defineProperty(navigator, "clipboard", original);
|
|
else delete (navigator as { clipboard?: unknown }).clipboard;
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe("writeClipboard", () => {
|
|
it("uses the Clipboard API when the origin has one", async () => {
|
|
const writeText = vi.fn().mockResolvedValue(undefined);
|
|
setClipboard({ writeText });
|
|
expect(await writeClipboard("hello")).toBe(true);
|
|
expect(writeText).toHaveBeenCalledWith("hello");
|
|
});
|
|
|
|
it("falls back to execCommand on a non-secure origin, and gives the focus back", async () => {
|
|
setClipboard(undefined);
|
|
const input = document.createElement("input");
|
|
document.body.appendChild(input);
|
|
input.focus();
|
|
let copied = "";
|
|
const exec = vi.fn((cmd: string) => {
|
|
copied = document.querySelector("textarea")?.value ?? "";
|
|
return cmd === "copy";
|
|
});
|
|
Object.defineProperty(document, "execCommand", { value: exec, configurable: true });
|
|
expect(await writeClipboard("from tmux")).toBe(true);
|
|
expect(exec).toHaveBeenCalledWith("copy");
|
|
expect(copied).toBe("from tmux");
|
|
expect(document.activeElement).toBe(input);
|
|
expect(document.querySelector("textarea")).toBeNull();
|
|
input.remove();
|
|
});
|
|
|
|
it("copyText reports a failed copy", async () => {
|
|
setClipboard(undefined);
|
|
Object.defineProperty(document, "execCommand", {
|
|
value: vi.fn(() => false),
|
|
configurable: true,
|
|
});
|
|
expect(await copyText("x", true)).toBe(false);
|
|
});
|
|
});
|