Path settings get Kind::Path, checked by check_path in the engine: the one validator for settings.set from agents, the CLI and the dialog. settings.list marks them with path: true; the dialog uses that flag for Browse and shows the engine's reason (userMessage drops the invalid-params prefix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
/**
|
|
* Tests for the engine bridge: results and every kind of rejection map to
|
|
* a `RunResult` instead of a rejected promise.
|
|
*/
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const invoke = vi.hoisted(() => vi.fn());
|
|
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
|
|
|
import { listCommands, run, runWaiting, toEngineError, userMessage } from "../src/ipc";
|
|
|
|
describe("run", () => {
|
|
beforeEach(() => {
|
|
invoke.mockReset();
|
|
});
|
|
|
|
it("passes command and params to the shell", async () => {
|
|
invoke.mockResolvedValue({ name: "Lutra" });
|
|
const result = await run("app.about", { verbose: true });
|
|
expect(invoke).toHaveBeenCalledWith("engine_execute", {
|
|
command: "app.about",
|
|
params: { verbose: true },
|
|
});
|
|
expect(result).toEqual({ ok: true, value: { name: "Lutra" } });
|
|
});
|
|
|
|
it("returns engine errors instead of rejecting", async () => {
|
|
invoke.mockRejectedValue({ code: "unknown_command", message: "no such command: x" });
|
|
const result = await run("x");
|
|
expect(result).toEqual({
|
|
ok: false,
|
|
error: { code: "unknown_command", message: "no such command: x" },
|
|
});
|
|
});
|
|
|
|
it("wraps unexpected rejections", async () => {
|
|
invoke.mockRejectedValue(new Error("window.__TAURI_INTERNALS__ is undefined"));
|
|
const result = await run("app.about");
|
|
expect(result.ok).toBe(false);
|
|
expect(result.ok ? null : result.error.code).toBe("ipc");
|
|
});
|
|
|
|
it("lists commands", async () => {
|
|
invoke.mockResolvedValue([]);
|
|
expect(await listCommands()).toEqual({ ok: true, value: [] });
|
|
expect(invoke).toHaveBeenCalledWith("engine_list_commands");
|
|
});
|
|
|
|
it("runs waiting commands through the async shell command", async () => {
|
|
invoke.mockResolvedValue({ locations: [] });
|
|
const result = await runWaiting("lsp.definition", { id: 1 });
|
|
expect(result).toEqual({ ok: true, value: { locations: [] } });
|
|
expect(invoke).toHaveBeenCalledWith("engine_execute_waiting", {
|
|
command: "lsp.definition",
|
|
params: { id: 1 },
|
|
});
|
|
invoke.mockRejectedValue({ code: "failed", message: "the PHP language server is not running" });
|
|
const failed = await runWaiting("lsp.definition", { id: 1 });
|
|
expect(failed.ok ? null : failed.error.code).toBe("failed");
|
|
});
|
|
});
|
|
|
|
describe("toEngineError", () => {
|
|
it("handles strings and malformed objects", () => {
|
|
expect(toEngineError("boom")).toEqual({ code: "ipc", message: "boom" });
|
|
expect(toEngineError({ code: 1, message: "x" }).code).toBe("ipc");
|
|
});
|
|
});
|
|
|
|
describe("userMessage", () => {
|
|
it("drops the engine's invalid params prefix and keeps other messages", () => {
|
|
expect(userMessage({ code: "invalid_params", message: "invalid params for search.find: unclosed group" })).toBe(
|
|
"unclosed group",
|
|
);
|
|
expect(userMessage({ code: "failed", message: "invalid params for x.y: z" })).toBe("invalid params for x.y: z");
|
|
expect(userMessage({ code: "invalid_params", message: "missing path" })).toBe("missing path");
|
|
});
|
|
});
|