fix: harden gateway status rpc smoke
This commit is contained in:
89
src/cli/daemon-cli/status.test.ts
Normal file
89
src/cli/daemon-cli/status.test.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createCliRuntimeCapture } from "../test-runtime-capture.js";
|
||||
|
||||
const gatherDaemonStatus = vi.fn(async (_opts?: unknown) => ({
|
||||
service: {
|
||||
label: "LaunchAgent",
|
||||
loaded: true,
|
||||
loadedText: "loaded",
|
||||
notLoadedText: "not loaded",
|
||||
},
|
||||
rpc: {
|
||||
ok: true,
|
||||
url: "ws://127.0.0.1:18789",
|
||||
},
|
||||
extraServices: [],
|
||||
}));
|
||||
const printDaemonStatus = vi.fn();
|
||||
|
||||
const { runtimeErrors, defaultRuntime, resetRuntimeCapture } = createCliRuntimeCapture();
|
||||
|
||||
vi.mock("../../runtime.js", () => ({
|
||||
defaultRuntime,
|
||||
}));
|
||||
|
||||
vi.mock("../../terminal/theme.js", () => ({
|
||||
colorize: (_rich: boolean, _color: unknown, text: string) => text,
|
||||
isRich: () => false,
|
||||
theme: { error: "error" },
|
||||
}));
|
||||
|
||||
vi.mock("./status.gather.js", () => ({
|
||||
gatherDaemonStatus: (opts: unknown) => gatherDaemonStatus(opts),
|
||||
}));
|
||||
|
||||
vi.mock("./status.print.js", () => ({
|
||||
printDaemonStatus: (...args: unknown[]) => printDaemonStatus(...args),
|
||||
}));
|
||||
|
||||
const { runDaemonStatus } = await import("./status.js");
|
||||
|
||||
describe("runDaemonStatus", () => {
|
||||
beforeEach(() => {
|
||||
gatherDaemonStatus.mockClear();
|
||||
printDaemonStatus.mockClear();
|
||||
resetRuntimeCapture();
|
||||
});
|
||||
|
||||
it("exits when require-rpc is set and the probe fails", async () => {
|
||||
gatherDaemonStatus.mockResolvedValueOnce({
|
||||
service: {
|
||||
label: "LaunchAgent",
|
||||
loaded: true,
|
||||
loadedText: "loaded",
|
||||
notLoadedText: "not loaded",
|
||||
},
|
||||
rpc: {
|
||||
ok: false,
|
||||
url: "ws://127.0.0.1:18789",
|
||||
error: "gateway closed",
|
||||
},
|
||||
extraServices: [],
|
||||
});
|
||||
|
||||
await expect(
|
||||
runDaemonStatus({
|
||||
rpc: {},
|
||||
probe: true,
|
||||
requireRpc: true,
|
||||
json: false,
|
||||
}),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
|
||||
expect(printDaemonStatus).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("rejects require-rpc when probing is disabled", async () => {
|
||||
await expect(
|
||||
runDaemonStatus({
|
||||
rpc: {},
|
||||
probe: false,
|
||||
requireRpc: true,
|
||||
json: false,
|
||||
}),
|
||||
).rejects.toThrow("__exit__:1");
|
||||
|
||||
expect(gatherDaemonStatus).not.toHaveBeenCalled();
|
||||
expect(runtimeErrors.join("\n")).toContain("--require-rpc cannot be used with --no-probe");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user