Файли
openidea/src/features/plugins/__tests__/ptyBackend.test.ts
T
Deng Liuтаdengliu fbf57bed23 feat(plugins): generic streaming log editor tab for plugin web views (#2043)
A plugin web view can open a read-only editor tab that streams a process's output, with plugin-defined toggles, Find, wrap, zoom and Clear. The process is authorised in the backend against the exact granted `process:<program>` and its pinned executable, output is bounded, and the stream survives tab switches but ends when the tab closes, the plugin is disabled or the window closes. Adds a web-log test fixture and docs. Verified on macOS; Windows/Linux not run.

Co-authored-by: dengliu <[email protected]>
2026-11-08 04:06:04 +08:00

45 рядки
1.6 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import type { PluginInfo } from "@/bindings";
import { commands } from "@/platform/ipc";
import { usePlugins } from "../store";
import { webPtyBackend } from "../views/ptyBackend";
vi.mock("@tauri-apps/api/core", () => ({
Channel: class {
onmessage?: (data: string) => void;
},
}));
vi.mock("@/platform/ipc", async (original) => ({
...(await original<object>()),
isTauri: () => true,
commands: { pluginWebPtySpawn: vi.fn(async () => ({ status: "ok", data: { id: 42 } })) },
}));
afterEach(() => {
usePlugins.setState({ plugins: [] });
vi.clearAllMocks();
});
it("uses the plugin-scoped backend for both log and frame streams, rechecking the current grant", async () => {
const plugin = { id: "probe", enabled: true, capabilities: [{ id: "process:bash", granted: true }] } as PluginInfo;
const command = { program: "bash", args: [], env: {}, cols: 240, rows: 40 };
const backend = webPtyBackend("probe", "logs");
usePlugins.setState({ plugins: [plugin] });
const output = vi.fn();
await expect(backend.spawn(command, output)).resolves.toEqual({ id: 42 });
expect(commands.pluginWebPtySpawn).toHaveBeenCalledWith(
"probe",
"logs",
command,
expect.objectContaining({ onmessage: output }),
);
for (const p of [
{ ...plugin, capabilities: [] },
{ ...plugin, enabled: false },
]) {
usePlugins.setState({ plugins: [p] });
await expect(backend.spawn(command, output)).rejects.toThrow("capability not granted");
}
expect(commands.pluginWebPtySpawn).toHaveBeenCalledOnce();
});