fix(remote): group verified instances without dropping authorizations
This commit is contained in:
1 parent
94c137511a
commit
450e455b57
21 files changed
+496
-27
No files matched your search
@@ -65,6 +65,22 @@ async function reviewed() {
|
||||
}
|
||||
|
||||
describe("quick pairing", () => {
|
||||
it("explains an existing instance and saves its additional authorization only on confirmation", async () => {
|
||||
mocks.action.mockImplementation(async (action: string) => {
|
||||
if (action === "remote.pair_preview") return { ...preview, existing_connection: { id: "saved-server", name: "My team", connected: true } };
|
||||
if (action === "remote.pair_finish") return { id: "saved-server" };
|
||||
return {};
|
||||
});
|
||||
returnedView();
|
||||
await screen.findByRole("heading", { name: "This nanobot is already saved" });
|
||||
expect(screen.getByText("My team")).toBeVisible();
|
||||
expect(screen.getByText(i18n.t("remote.sameInstance.pairHint"))).toBeVisible();
|
||||
expect(mocks.action.mock.calls.some(([action]) => action === "remote.pair_finish")).toBe(false);
|
||||
expect(mocks.connect).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save and open" }));
|
||||
await waitFor(() => expect(mocks.connect).toHaveBeenCalledWith("saved-server", expect.any(Function)));
|
||||
expect(mocks.action).toHaveBeenCalledWith("remote.pair_finish", { id: "request-1", code: "nbpc1.encrypted" }, 65000);
|
||||
});
|
||||
it("introduces remote access with the original logo and no duplicate instruction spacer", async () => {
|
||||
view();
|
||||
await waitFor(() => expect(screen.getByRole("button", { name: "Copy command" })).toBeEnabled());
|
||||
|
||||
@@ -91,6 +91,51 @@ function chooseExistingSSH() {
|
||||
}
|
||||
|
||||
describe("remote instance UX", () => {
|
||||
it("shows one verified instance in management and the switcher while retaining both grants in details", async () => {
|
||||
const second = { ...profile, id: "f1b18099-61d5-41d7-9c1d-6f647f7000e5", paired: true, instance_id: profile.id };
|
||||
mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, paired: true, instance_id: profile.id }, second] });
|
||||
view();
|
||||
await openDirectory();
|
||||
expect(screen.getAllByRole("button", { name: "Team server ubuntu@example.test" })).toHaveLength(1);
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Connection details" }));
|
||||
const details = await screen.findByRole("dialog", { name: "Connection details" });
|
||||
expect(within(details).getByRole("button", { name: /^Connection 1 / })).toBeVisible();
|
||||
expect(within(details).getByRole("button", { name: /^Connection 2 / })).toBeVisible();
|
||||
fireEvent.pointerDown(within(details).getByRole("button", { name: "Manage connection 1" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Forget connection" }));
|
||||
expect(await screen.findByRole("dialog", { name: "Forget this connection?" })).toHaveTextContent(i18n.t("remote.sameInstance.forgetHint"));
|
||||
expect(screen.getByRole("button", { name: "Forget", exact: true })).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "Forget", exact: true }).firstElementChild).not.toHaveClass("truncate");
|
||||
expect(screen.queryByRole("button", { name: "Forget server", exact: true })).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel", exact: true }));
|
||||
expect(mocks.request).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back", exact: true }));
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Switch host" }), { button: 0, ctrlKey: false });
|
||||
expect(await screen.findAllByRole("menuitem", { name: "Team server ubuntu@example.test" })).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps same-address unverified instances separate and shows their config paths", async () => {
|
||||
mocks.read.mockResolvedValue({ available: true, profiles: [profile, { ...profile, id: "another", config_path: "/srv/other/config.json" }] });
|
||||
view(); await openDirectory();
|
||||
expect(screen.getAllByRole("button", { name: "Team server ubuntu@example.test" })).toHaveLength(2);
|
||||
expect(screen.getByTitle("/srv/other/config.json")).toBeVisible();
|
||||
expect(screen.getByTitle(profile.config_path)).toBeVisible();
|
||||
});
|
||||
|
||||
it("requires disconnecting before opening another authorization of an already-connected instance", async () => {
|
||||
const second = { ...profile, id: "second-grant", connected: true, paired: true, instance_id: profile.id };
|
||||
mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, paired: true, instance_id: profile.id }, second] });
|
||||
view(); await openDirectory();
|
||||
fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
|
||||
fireEvent.click(screen.getByRole("menuitem", { name: "Connection details" }));
|
||||
const details = await screen.findByRole("dialog", { name: "Connection details" });
|
||||
expect(within(details).getByRole("button", { name: /^Connection 1 / })).toBeDisabled();
|
||||
expect(within(details).getByRole("button", { name: /^Connection 2 / })).toBeEnabled();
|
||||
expect(within(details).getByText(i18n.t("remote.sameInstance.switchHint"))).toBeVisible();
|
||||
expect(within(details).getByRole("button", { name: "Manage connection 1" })).toBeEnabled();
|
||||
expect(mocks.request).not.toHaveBeenCalled();
|
||||
});
|
||||
it("manages connections without changing the remote host, route, frame or authorization", async () => {
|
||||
view();
|
||||
await chooseHost("Team server ubuntu@example.test");
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { groupRemoteProfiles, type RemoteProfile } from "@/lib/remote-instances";
|
||||
|
||||
const profile: RemoteProfile = { id: "one", name: "Team", host: "ubuntu@server", port: 22,
|
||||
ssh_config: "", identity_file: "", config_path: "/srv/bot/config.json", runtime_user: "", connected: false };
|
||||
|
||||
describe("remote instance grouping", () => {
|
||||
it("does not guess from names, addresses, or restart-scoped gateway IDs", () => {
|
||||
expect(groupRemoteProfiles([profile, { ...profile, id: "two" }], null)).toHaveLength(2);
|
||||
expect(groupRemoteProfiles([{ ...profile, gateway_id: "same" }, { ...profile, id: "two", gateway_id: "same" }], null)).toHaveLength(2);
|
||||
});
|
||||
it("keeps all grants but selects the current view before a connected or newer grant", () => {
|
||||
const old = { ...profile, instance_id: "instance" };
|
||||
const renewed = { ...old, id: "two", name: "auto-generated", connected: true };
|
||||
const groups = groupRemoteProfiles([old, renewed], "one");
|
||||
expect(groups).toHaveLength(1);
|
||||
expect(groups[0].connections).toEqual([old, renewed]);
|
||||
expect(groups[0].profile.id).toBe("one");
|
||||
expect(groupRemoteProfiles([old, renewed], null)[0].profile).toMatchObject({ id: "two", name: "Team" });
|
||||
});
|
||||
it("prefers a usable grant when none is selected and does not mutate the directory", () => {
|
||||
const items = [Object.freeze({ ...profile, instance_id: "same", authorized_until: 1 }),
|
||||
Object.freeze({ ...profile, id: "two", instance_id: "same", authorized_until: Date.now() / 1000 + 1000 })];
|
||||
expect(groupRemoteProfiles(items, null)[0].profile.id).toBe("two");
|
||||
expect(items[0].id).toBe("one");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user