mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-14 16:07:52 +00:00
Refs #1083 (step B). A local project with a devcontainer.json can be reopened in its dev container (File › Reopen in Container, Find Action): the Dev Containers CLI brings the container up and the window connects to openidea-server inside it, as for WSL, so terminal, language servers, run, debug and git work in the container. The project's identity stays the local folder, so reopening from Recent Projects finds the same container. Missing CLI gives install guidance; trust of the local project carries over. Pure CLI output parsing lives in ide-remote; a failed connection no longer closes the current backend early, saved locations keep the container configuration, and Docker context precedence follows the CLI. Co-authored-by: andreabasile <7715018+andreabasile@users.noreply.github.com>
52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
import { beforeEach, expect, it, vi } from "vitest";
|
|
import { IpcError } from "@/platform/ipc";
|
|
import { useProject } from "@/platform/project";
|
|
import { useRemote } from "@/platform/remote";
|
|
|
|
const mocks = vi.hoisted(() => ({ open: vi.fn(), notify: vi.fn() }));
|
|
vi.mock("@/workbench/projectWindow", () => ({ openRemoteProject: mocks.open }));
|
|
vi.mock("@/workbench/contributions", () => ({ notifications: () => ({ notify: mocks.notify }) }));
|
|
|
|
import { reopenInContainer } from "./container";
|
|
|
|
const project = (root: string) => ({ root, name: "app", trusted: true }) as never;
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
useRemote.setState({ session: null });
|
|
useProject.setState({ project: project("/Users/me/app") });
|
|
});
|
|
|
|
it("opens the local project's dev container", async () => {
|
|
mocks.open.mockResolvedValue(true);
|
|
await reopenInContainer();
|
|
expect(mocks.open).toHaveBeenCalledWith(
|
|
{ kind: "devContainer", folder: "/Users/me/app", config: "" },
|
|
"/Users/me/app",
|
|
);
|
|
expect(mocks.notify).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("does nothing in a remote window or without a project", async () => {
|
|
useRemote.setState({
|
|
session: { target: { kind: "ssh", config: "a" }, root: "/srv/app", host: "a", os: "linux", commands: [] },
|
|
});
|
|
await reopenInContainer();
|
|
useRemote.setState({ session: null });
|
|
useProject.setState({ project: null });
|
|
await reopenInContainer();
|
|
expect(mocks.open).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("reports why the container could not be opened, but not a cancel", async () => {
|
|
mocks.open.mockRejectedValueOnce(new Error("The Dev Containers CLI is not installed."));
|
|
await reopenInContainer();
|
|
expect(mocks.notify).toHaveBeenCalledWith(
|
|
expect.objectContaining({ level: "error", body: "The Dev Containers CLI is not installed." }),
|
|
);
|
|
mocks.notify.mockClear();
|
|
mocks.open.mockRejectedValueOnce(new IpcError({ kind: "cancelled", message: "Project opening cancelled" }));
|
|
await reopenInContainer();
|
|
expect(mocks.notify).not.toHaveBeenCalled();
|
|
});
|