Files
openidea/src/features/run/pluginAttach.test.ts
T
l0ng-ai 74e66a5dae feat(plugins): environment and debugger for plugin run configurations (API 1.9) (#3476)
Plugin run configurations could not set environment variables, and Debug
only worked when a source file in the arguments let the IDE infer a
debugger, so a plugin could run `func start` for an Azure Functions app but
not debug the worker it starts.

API 1.9 adds the optional `launch-configurations` export, preferred over
`run-configurations` when a component has both. Each configuration can add
environment variables (only names the IDE's environment doesn't already
have, like `process` commands) and name a debugger: launch the program
under a language's debugger, or run it and attach to the first process of
an Attach to Process kind that the run starts. Only the run's own
descendants are candidates; the IDE waits up to a minute while the run
lasts and otherwise leaves it running without the debugger. Remote projects
resolve the process on the server.

The SDK gets `LaunchConfigurations` / `launch_configurations`, the README
and docs describe the export, and the bundled components and fixtures are
rebuilt for 1.9.
2026-11-15 11:01:12 +08:00

71 lines
2.8 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import type { RunConfig } from "@/platform/ipc";
const mocks = vi.hoisted(() => ({
action: vi.fn(async () => true),
notify: vi.fn(),
startRun: vi.fn(),
target: vi.fn(),
}));
vi.mock("@/platform/actions", () => ({ executeAction: mocks.action }));
vi.mock("@/platform/ipc", () => ({
call: async (p: Promise<unknown>) => p,
commands: { pluginDebugAttachTarget: mocks.target },
}));
vi.mock("@/workbench/contributions", () => ({ notifications: () => ({ notify: mocks.notify }) }));
vi.mock("./store", () => ({ startRun: mocks.startRun }));
import { attachesToChild, debugAttachingToChild } from "./pluginAttach";
const config = {
id: "plugin:acme.functions:func",
name: "Functions host",
kind: "plugin",
command: "func",
args: ["start"],
params: { debugAttach: "dotnet" },
} as unknown as RunConfig;
const worker = { pid: 42, name: "dotnet", commandLine: "dotnet Worker.dll", kind: "dotnet", adapter: "netcoredbg" };
describe("plugin configurations that attach to a child process", () => {
beforeEach(() => vi.clearAllMocks());
it("are plugin configurations with an attach kind", () => {
expect(attachesToChild(config)).toBe(true);
expect(attachesToChild({ ...config, params: {} })).toBe(false);
expect(attachesToChild({ ...config, kind: "shell" })).toBe(false);
});
it("run, then attach the debugger to the process the run started", async () => {
mocks.startRun.mockResolvedValue({ id: "s1", runId: 7, status: "running" });
mocks.target.mockResolvedValue(worker);
const session = await debugAttachingToChild(config, { show: false, prepared: true });
expect(session?.runId).toBe(7);
expect(mocks.startRun).toHaveBeenCalledWith(config, undefined, undefined, { show: false, prepared: true });
expect(mocks.target).toHaveBeenCalledWith(config.id, 7);
await vi.waitFor(() =>
expect(mocks.action).toHaveBeenCalledWith("debug.attach", {
attachable: worker,
process: 7,
runConfig: config,
show: false,
}),
);
});
it("leave the run going and say why when no process turns up", async () => {
mocks.startRun.mockResolvedValue({ id: "s1", runId: 7, status: "running" });
mocks.target.mockRejectedValue(new Error("no dotnet process started by the run within a minute"));
await debugAttachingToChild(config);
await vi.waitFor(() => expect(mocks.notify).toHaveBeenCalled());
expect(mocks.action).not.toHaveBeenCalled();
expect(mocks.notify.mock.calls[0]![0].body).toContain("within a minute");
});
it("don't wait for a process when the run didn't start", async () => {
mocks.startRun.mockResolvedValue({ id: "s1", runId: null, status: "failed" });
await debugAttachingToChild(config);
expect(mocks.target).not.toHaveBeenCalled();
});
});