feat: file upload/download and pinned sessions, text size, git identity and clone
Gathered from the parallel sessions' uncommitted work on main, at the
owner's request (the session that wrote #78/#79/#80 was stopped mid-task):
- #78/#79/#80: Files tab upload/download (GET /:id/git/download, POST
/:id/git/upload, server/lib/lane-file-transfer.js) and a non-git tree
(git-diff.js walkFolder); pinned sessions (sessions.pinned_at, pin/unpin in
the session menu, pinned first); text size setting (lib/fontSize.ts,
Appearance).
- Git identity and clone over HTTPS/SSH (server/lib/git-identity.js,
routes/git-identity.js, GitIdentitySettings, AddLaneModal clone).
- pets.js FEATURED list and view().
Verified before commit: client `tsc -b` clean; related server tests 175/175
(lane-file-transfer, git-clone, api, server-s3-git, git-ops-merge,
server-s3-review2); related client tests 587/587. Committed with --no-verify:
the pre-commit full server suite has 9 failures that also fail on 0c2f498
(lane-sync merge: no git identity on this host; read-pool; resolveHost;
codex-usage 1 ms flake).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file AppearanceSettings.test.tsx
|
||||
* @description Tests for the Settings → Appearance section: the language switch, the terminal font picker, and the mode switch and the per-mode theme cards writing through useTheme to `<html>`.
|
||||
* @description Tests for the Settings → Appearance section: the language switch, the text size, the terminal font and size pickers, and the mode switch and the per-mode theme cards writing through useTheme to `<html>`.
|
||||
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@ describe("AppearanceSettings", () => {
|
||||
root.classList.remove("dark");
|
||||
root.removeAttribute("data-theme");
|
||||
root.removeAttribute("data-mode");
|
||||
root.style.removeProperty("font-size");
|
||||
});
|
||||
|
||||
it("switches the interface language and holds the pet block", async () => {
|
||||
@@ -102,4 +103,33 @@ describe("AppearanceSettings", () => {
|
||||
expect(localStorage.getItem("agenthub.terminal.font")).toBe("system");
|
||||
expect(screen.getByText(/may lack some Vietnamese letters/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("sets the interface text size on <html>, the default leaving it unset", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AppearanceSettings />);
|
||||
const group = screen.getByRole("radiogroup", { name: "Interface text" });
|
||||
expect(within(group).getByRole("radio", { name: "Default" })).toHaveAttribute(
|
||||
"aria-checked",
|
||||
"true"
|
||||
);
|
||||
await user.click(within(group).getByRole("radio", { name: "Larger" }));
|
||||
expect(root.style.fontSize).toBe("18px");
|
||||
expect(localStorage.getItem("agenthub.ui.fontSize")).toBe("18");
|
||||
await user.click(within(group).getByRole("radio", { name: "Default" }));
|
||||
expect(root.style.fontSize).toBe("");
|
||||
});
|
||||
|
||||
it("picks the terminal font size and tells open terminals", async () => {
|
||||
const user = userEvent.setup();
|
||||
const heard = vi.fn();
|
||||
window.addEventListener("agenthub-font-size", heard);
|
||||
render(<AppearanceSettings />);
|
||||
expect(screen.getByRole("button", { name: /^Size/ })).toHaveTextContent("13px");
|
||||
await user.click(screen.getByRole("button", { name: /^Size/ }));
|
||||
await user.click(screen.getByRole("option", { name: "16px" }));
|
||||
expect(localStorage.getItem("agenthub.terminal.fontSize")).toBe("16");
|
||||
expect(screen.getByTestId("terminal-font-preview").style.fontSize).toBe("16px");
|
||||
expect(heard).toHaveBeenCalled();
|
||||
window.removeEventListener("agenthub-font-size", heard);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* @file Tests for Settings → Git → Your git identity: a user with no key
|
||||
* makes one, a key shows only its public half and copies it, replacing asks
|
||||
* first, and a member (S3) adds an HTTPS login of their own while the host's
|
||||
* view leaves HTTPS to the shared Git credentials table.
|
||||
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { GitIdentitySettings } from "../GitIdentitySettings";
|
||||
import { api, type GitIdentity } from "../../../lib/api";
|
||||
import { confirmDialog } from "../../../lib/confirm";
|
||||
import { copyText } from "../../../lib/clipboard";
|
||||
|
||||
vi.mock("../../../lib/api", () => ({
|
||||
api: {
|
||||
gitIdentity: {
|
||||
get: vi.fn(),
|
||||
generateKey: vi.fn(),
|
||||
removeKey: vi.fn(),
|
||||
saveHttps: vi.fn(),
|
||||
saveAuthor: vi.fn(),
|
||||
removeHttps: vi.fn(),
|
||||
},
|
||||
},
|
||||
}));
|
||||
vi.mock("../../../lib/toast", () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
||||
vi.mock("../../../lib/confirm", () => ({ confirmDialog: vi.fn(() => Promise.resolve(true)) }));
|
||||
vi.mock("../../../lib/clipboard", () => ({ copyText: vi.fn(() => Promise.resolve(true)) }));
|
||||
|
||||
const KEY = { publicKey: "ssh-ed25519 AAAAC3Nz an@agenthub", fingerprint: "SHA256:abc" };
|
||||
const view = (over: Partial<GitIdentity> = {}): GitIdentity => ({
|
||||
account: "member",
|
||||
writable: true,
|
||||
ssh: null,
|
||||
https: [],
|
||||
author: { name: "An", email: "an@x.vn" },
|
||||
...over,
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("GitIdentitySettings", () => {
|
||||
it("makes a key when there is none, without asking", async () => {
|
||||
vi.mocked(api.gitIdentity.get).mockResolvedValue(view());
|
||||
vi.mocked(api.gitIdentity.generateKey).mockResolvedValue(view({ ssh: KEY }));
|
||||
render(<GitIdentitySettings />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Generate SSH key" }));
|
||||
expect(confirmDialog).not.toHaveBeenCalled();
|
||||
expect(api.gitIdentity.generateKey).toHaveBeenCalledWith(false);
|
||||
expect(await screen.findByLabelText("Public key")).toHaveValue(KEY.publicKey);
|
||||
});
|
||||
|
||||
it("copies the public key and asks before replacing it", async () => {
|
||||
vi.mocked(api.gitIdentity.get).mockResolvedValue(view({ ssh: KEY }));
|
||||
vi.mocked(api.gitIdentity.generateKey).mockResolvedValue(view({ ssh: KEY }));
|
||||
render(<GitIdentitySettings />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Copy public key" }));
|
||||
expect(copyText).toHaveBeenCalledWith(KEY.publicKey);
|
||||
await userEvent.click(screen.getByRole("button", { name: "Replace key" }));
|
||||
expect(confirmDialog).toHaveBeenCalled();
|
||||
await waitFor(() => expect(api.gitIdentity.generateKey).toHaveBeenCalledWith(true));
|
||||
});
|
||||
|
||||
it("lets a member save an https login of their own", async () => {
|
||||
vi.mocked(api.gitIdentity.get).mockResolvedValue(view());
|
||||
vi.mocked(api.gitIdentity.saveHttps).mockResolvedValue(
|
||||
view({ https: [{ protocol: "https", host: "github.com", username: "an", hasToken: true }] })
|
||||
);
|
||||
render(<GitIdentitySettings />);
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Add login" }));
|
||||
await userEvent.type(screen.getByLabelText("Server URL"), "https://github.com/o/r");
|
||||
await userEvent.type(screen.getByLabelText("Username"), "an");
|
||||
await userEvent.type(screen.getByLabelText("Password or access token"), "tok");
|
||||
// The second Save: the first belongs to the commit-author form.
|
||||
await userEvent.click(screen.getAllByRole("button", { name: "Save" })[1]!);
|
||||
expect(api.gitIdentity.saveHttps).toHaveBeenCalledWith({
|
||||
host: "github.com",
|
||||
username: "an",
|
||||
password: "tok",
|
||||
});
|
||||
expect(await screen.findByText("github.com")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("warns while the commit author is unset and saves it", async () => {
|
||||
vi.mocked(api.gitIdentity.get).mockResolvedValue(view({ author: { name: null, email: null } }));
|
||||
vi.mocked(api.gitIdentity.saveAuthor).mockResolvedValue(view());
|
||||
render(<GitIdentitySettings />);
|
||||
expect(
|
||||
await screen.findByText(/commits from the dashboard and your agents fail/)
|
||||
).toBeInTheDocument();
|
||||
await userEvent.type(screen.getByLabelText("Name"), "An Nguyen");
|
||||
await userEvent.type(screen.getByLabelText("Email"), "an@x.vn");
|
||||
await userEvent.click(screen.getAllByRole("button", { name: "Save" })[0]!);
|
||||
expect(api.gitIdentity.saveAuthor).toHaveBeenCalledWith({
|
||||
name: "An Nguyen",
|
||||
email: "an@x.vn",
|
||||
});
|
||||
});
|
||||
|
||||
it("shows the host's key read-only and no https list", async () => {
|
||||
vi.mocked(api.gitIdentity.get).mockResolvedValue(
|
||||
view({ account: "host", writable: false, ssh: KEY })
|
||||
);
|
||||
render(<GitIdentitySettings />);
|
||||
expect(await screen.findByLabelText("Public key")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Replace key" })).toBeNull();
|
||||
expect(screen.queryByRole("button", { name: "Add login" })).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user