Files pane
- F16: a drag-out released back inside the app no longer re-imports its own
staged copy over the container original. An in-flight flag (cleared from the
drag plugin's `onEvent` channel, with a watchdog) suppresses the drop and the
"Drop files into …" hint, and an exact staged-path filter is the second line
of defence — the `path|size|modified` cache could otherwise write a
minutes-old snapshot over a file an agent had since rewritten.
- F17: a slow upload/rename no longer yanks the user back to the directory the
operation started in. Every operation captures its target path and re-lists
only if the user is still there; failures go to the toast host either way.
- The grid keeps keyboard focus. Roving tabindex (one tab stop, not one per
row) plus focus restore after navigation, rename commit/cancel and Escape.
- Transient failures now surface in `ToastHost` (z-[60], persistent aria-live)
instead of a `role="alert"` 300 rows down a scroller or behind a modal
overlay. The inline error is kept only for the listing failure.
- `navigate` is sequenced by generation; "Save to host…" sets `busy`.
- Grid a11y: column headers, a text affordance for folder vs file, a live
region that is mounted empty and announces completion, Label-in-Name fixed.
- FileViewerModal: the blob URL is released only once its replacement exists;
the preview is a focusable, named, scrollable region.
Native drop routing
- New `lib/dropTarget.ts`: the hit test now refuses a drop while any
`[aria-modal="true"]` dialog or `[data-blocks-drop]` overlay is up, and
checks z-order where the environment can answer it. Shared by FilesTab and
TerminalView; App's shutdown overlay opts in.
Disk
- A partially failed reclaim says so in words ("… — 2 of 5 failed"), not by hue
alone.
- The scan/reclaim race is closed: every mutation retires an in-flight scan, so
a scan can no longer repaint a pre-reclaim report plus a clickable plan of
objects that are gone. Scan is disabled while working; the status is a live
region; a failed destructive action keeps its dialog open and reports there.
- The "unknown" layer count gets a screen-reader fallback; `--text-disabled`
no longer carries live information.
Terminal / OAuth
- After the toast is dismissed, a truncated heuristic guess can no longer fill
the slot that an exact OSC 8 or relay URL occupied — the detector remembers
every exact URL and drops any candidate that is a strict prefix of one.
- The prompt is reachable by keyboard: Ctrl+Shift+O jumps to the default
action, Escape dismisses, focus returns to the terminal, and auto-dismiss
holds off while focus is inside. It deliberately does not steal focus.
- UrlToast renders through `ui/Button` and `--shadow-overlay`.
Elsewhere
- AuthBridgeRow: a pushed `auth-bridge-changed` status always outranks an older
awaited toggle result.
- The last two ad-hoc byte formatters route through `lib/formatBytes`.
Contract for the backend agent: `upload_file_to_container` refusing to
overwrite must satisfy `isFileExistsError` in `src/lib/uploadErrors.ts` (marker
`FILE_EXISTS`) and accept an `overwrite` argument; the frontend turns that into
an `ui/Modal` Replace/Skip prompt rather than a raw error string.
Tests: 536 -> 627 passing. `npm run build` and `npx tsc --noEmit` green.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GBq2rGum6GX7xXgsas1fDc
253 lines
9.2 KiB
TypeScript
253 lines
9.2 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
import AuthBridgeRow, { bridgeIndicator } from "./AuthBridgeRow";
|
|
import type { AuthBridgeStatus, Project } from "../../../../lib/types";
|
|
|
|
/**
|
|
* The bridge shipped with a working backend, a typed IPC wrapper, and no way to
|
|
* reach either: `setAuthBridgeEnabled` had zero call sites, and the
|
|
* `auth-bridge-changed` event had no listener — so a host port the bridge could
|
|
* not take was a silent failure that presented as a login that simply hung.
|
|
* These tests hold both halves down.
|
|
*/
|
|
|
|
const getAuthBridgeStatus = vi.fn<() => Promise<AuthBridgeStatus>>();
|
|
const setAuthBridgeEnabled = vi.fn<(id: string, on: boolean) => Promise<AuthBridgeStatus>>();
|
|
|
|
vi.mock("../../../../lib/tauri-commands", () => ({
|
|
getAuthBridgeStatus: () => getAuthBridgeStatus(),
|
|
setAuthBridgeEnabled: (id: string, on: boolean) => setAuthBridgeEnabled(id, on),
|
|
}));
|
|
|
|
/** Captured so a test can push an `auth-bridge-changed` payload by hand. */
|
|
let emit: ((payload: unknown) => void) | null = null;
|
|
|
|
vi.mock("@tauri-apps/api/event", () => ({
|
|
listen: vi.fn(async (_name: string, handler: (e: { payload: unknown }) => void) => {
|
|
emit = (payload) => handler({ payload });
|
|
return () => {
|
|
emit = null;
|
|
};
|
|
}),
|
|
}));
|
|
|
|
const OFF: AuthBridgeStatus = { enabled: false, active_ports: [], conflicts: [] };
|
|
|
|
const project = {
|
|
id: "p1",
|
|
name: "api",
|
|
status: "running",
|
|
auth_bridge_enabled: false,
|
|
} as unknown as Project;
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
getAuthBridgeStatus.mockResolvedValue(OFF);
|
|
setAuthBridgeEnabled.mockResolvedValue({ ...OFF, enabled: true });
|
|
});
|
|
|
|
describe("AuthBridgeRow", () => {
|
|
it("turns the bridge on through its own command, not the project save", async () => {
|
|
// The dedicated command exists so this can be flipped while the container
|
|
// runs — which is exactly when a user discovers they need it. Routing it
|
|
// through the Config tab's stopped-only save would make it unreachable at
|
|
// the only moment it matters.
|
|
render(<AuthBridgeRow project={project} />);
|
|
await waitFor(() => expect(getAuthBridgeStatus).toHaveBeenCalled());
|
|
|
|
fireEvent.click(screen.getByRole("switch", { name: "Auth bridge" }));
|
|
|
|
await waitFor(() =>
|
|
expect(setAuthBridgeEnabled).toHaveBeenCalledWith("p1", true),
|
|
);
|
|
});
|
|
|
|
it("stays usable while the container is running", async () => {
|
|
render(<AuthBridgeRow project={project} />);
|
|
await waitFor(() => expect(getAuthBridgeStatus).toHaveBeenCalled());
|
|
expect(screen.getByRole("switch", { name: "Auth bridge" })).not.toBeDisabled();
|
|
});
|
|
|
|
it("reports a port conflict the poller emitted", async () => {
|
|
getAuthBridgeStatus.mockResolvedValue({ ...OFF, enabled: true });
|
|
render(<AuthBridgeRow project={project} />);
|
|
await waitFor(() => expect(emit).not.toBeNull());
|
|
|
|
emit!({
|
|
project_id: "p1",
|
|
status: {
|
|
enabled: true,
|
|
active_ports: [],
|
|
conflicts: [
|
|
{ port: 54545, reason: "Host port 54545 is already in use (…); not bridged." },
|
|
],
|
|
},
|
|
});
|
|
|
|
expect(await screen.findByText(/Port 54545/)).toBeInTheDocument();
|
|
expect(screen.getByText("Port conflict")).toBeInTheDocument();
|
|
});
|
|
|
|
it("ignores an event for a different project", async () => {
|
|
getAuthBridgeStatus.mockResolvedValue({ ...OFF, enabled: true });
|
|
render(<AuthBridgeRow project={project} />);
|
|
await waitFor(() => expect(emit).not.toBeNull());
|
|
|
|
emit!({
|
|
project_id: "other",
|
|
status: { enabled: true, active_ports: [], conflicts: [{ port: 1, reason: "nope" }] },
|
|
});
|
|
|
|
expect(screen.queryByText(/Port 1:/)).not.toBeInTheDocument();
|
|
});
|
|
|
|
/**
|
|
* The two halves of this row disagree about *when*, not about *what*.
|
|
*
|
|
* `set_auth_bridge_enabled` resolves with a status sampled as it returned;
|
|
* the poller's event carries one sampled afterwards. Writing the awaited
|
|
* value unconditionally therefore rolls the row back in time whenever the
|
|
* two overlap — the row says "Watching" while a port is bound, which is the
|
|
* exact silent failure the event subscription was added to end. These two
|
|
* hold the ordering down from both the resolve and the reject side.
|
|
*/
|
|
describe("a pushed event outranks an older awaited result", () => {
|
|
/** A toggle that will not settle until the test says so. */
|
|
function deferToggle() {
|
|
let settle!: (s: AuthBridgeStatus) => void;
|
|
let fail!: (e: unknown) => void;
|
|
setAuthBridgeEnabled.mockImplementation(
|
|
() =>
|
|
new Promise<AuthBridgeStatus>((resolve, reject) => {
|
|
settle = resolve;
|
|
fail = reject;
|
|
}),
|
|
);
|
|
return { settle: (s: AuthBridgeStatus) => settle(s), fail: (e: unknown) => fail(e) };
|
|
}
|
|
|
|
const BRIDGING: AuthBridgeStatus = {
|
|
enabled: true,
|
|
active_ports: [{ port: 54545, family: "v4", bridged_at: "", ipv6_warning: null }],
|
|
conflicts: [],
|
|
};
|
|
|
|
async function startToggleThenPush() {
|
|
render(<AuthBridgeRow project={project} />);
|
|
await waitFor(() => expect(getAuthBridgeStatus).toHaveBeenCalled());
|
|
await waitFor(() => expect(emit).not.toBeNull());
|
|
|
|
fireEvent.click(screen.getByRole("switch", { name: "Auth bridge" }));
|
|
await waitFor(() => expect(setAuthBridgeEnabled).toHaveBeenCalledWith("p1", true));
|
|
|
|
// The poller binds a port while the command is still in flight.
|
|
emit!({ project_id: "p1", status: BRIDGING });
|
|
expect(await screen.findByText("Bridging 1 port")).toBeInTheDocument();
|
|
}
|
|
|
|
it("keeps the newer state when the command settles with the older one", async () => {
|
|
const toggle = deferToggle();
|
|
await startToggleThenPush();
|
|
|
|
// …and only now returns the snapshot it took *before* that port existed.
|
|
toggle.settle({ enabled: true, active_ports: [], conflicts: [] });
|
|
|
|
await waitFor(() =>
|
|
expect(screen.getByRole("switch", { name: "Auth bridge" })).not.toBeDisabled(),
|
|
);
|
|
expect(screen.getByText("Bridging 1 port")).toBeInTheDocument();
|
|
expect(screen.getByText("127.0.0.1:54545")).toBeInTheDocument();
|
|
expect(screen.queryByText("Watching")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("does not let the rollback undo a status pushed while it was failing", async () => {
|
|
// The command failed, so the error belongs on screen — but the bridge
|
|
// demonstrably came up, and reverting the switch to off would contradict
|
|
// the port listed right beside it.
|
|
const toggle = deferToggle();
|
|
await startToggleThenPush();
|
|
|
|
toggle.fail("bridge probe timed out");
|
|
|
|
expect(await screen.findByText(/probe timed out/)).toBeInTheDocument();
|
|
expect(screen.getByText("Bridging 1 port")).toBeInTheDocument();
|
|
expect(screen.getByRole("switch", { name: "Auth bridge" })).toBeChecked();
|
|
});
|
|
});
|
|
|
|
it("puts the switch back if the command rejects", async () => {
|
|
setAuthBridgeEnabled.mockRejectedValue("Project p1 not found");
|
|
render(<AuthBridgeRow project={project} />);
|
|
await waitFor(() => expect(getAuthBridgeStatus).toHaveBeenCalled());
|
|
|
|
fireEvent.click(screen.getByRole("switch", { name: "Auth bridge" }));
|
|
|
|
expect(await screen.findByText(/not found/)).toBeInTheDocument();
|
|
expect(screen.getByRole("switch", { name: "Auth bridge" })).not.toBeChecked();
|
|
});
|
|
});
|
|
|
|
describe("bridgeIndicator", () => {
|
|
// Every branch is a glyph plus a word — status is never colour alone.
|
|
it("says nothing is on when it is off", () => {
|
|
expect(bridgeIndicator(OFF, true)).toEqual({ tone: "off", label: "Off" });
|
|
});
|
|
|
|
it("puts a conflict ahead of everything else", () => {
|
|
expect(
|
|
bridgeIndicator(
|
|
{
|
|
enabled: true,
|
|
active_ports: [
|
|
{ port: 1, family: "v4", bridged_at: "", ipv6_warning: null },
|
|
],
|
|
conflicts: [{ port: 2, reason: "taken" }],
|
|
},
|
|
true,
|
|
).tone,
|
|
).toBe("error");
|
|
});
|
|
|
|
it("flags a port that only took the IPv4 half", () => {
|
|
// Node resolves `localhost` to IPv6 first on Linux, so a v4-only listener
|
|
// is a callback that never arrives in front of a bridge reporting healthy.
|
|
expect(
|
|
bridgeIndicator(
|
|
{
|
|
enabled: true,
|
|
active_ports: [
|
|
{ port: 1, family: "v6", bridged_at: "", ipv6_warning: "no ::1" },
|
|
],
|
|
conflicts: [],
|
|
},
|
|
true,
|
|
).label,
|
|
).toBe("IPv4 only");
|
|
});
|
|
|
|
it("counts the ports it is holding", () => {
|
|
expect(
|
|
bridgeIndicator(
|
|
{
|
|
enabled: true,
|
|
active_ports: [
|
|
{ port: 1, family: "v4", bridged_at: "", ipv6_warning: null },
|
|
{ port: 2, family: "v4", bridged_at: "", ipv6_warning: null },
|
|
],
|
|
conflicts: [],
|
|
},
|
|
true,
|
|
).label,
|
|
).toBe("Bridging 2 ports");
|
|
});
|
|
|
|
it("says it is waiting when the container is not running", () => {
|
|
// Enabled and holding nothing is normal; enabled with no container is a
|
|
// different thing, and saying so stops it reading as a failure.
|
|
expect(bridgeIndicator({ ...OFF, enabled: true }, false).label).toBe(
|
|
"Waiting for the container",
|
|
);
|
|
expect(bridgeIndicator({ ...OFF, enabled: true }, true).label).toBe("Watching");
|
|
});
|
|
});
|