mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 19:14:44 +00:00
test: tighten daemon cli coverage assertions
This commit is contained in:
@@ -154,6 +154,18 @@ async function runDaemonCommand(args: string[]) {
|
||||
await daemonProgram.parseAsync(args, { from: "user" });
|
||||
}
|
||||
|
||||
function requireMockCallArg(
|
||||
mockFn: { mock: { calls: unknown[][] } },
|
||||
label: string,
|
||||
index = 0,
|
||||
): Record<string, unknown> {
|
||||
const arg = mockFn.mock.calls[index]?.[0] as Record<string, unknown> | undefined;
|
||||
if (!arg) {
|
||||
throw new Error(`expected ${label} call #${index + 1}`);
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper lets assertions ascribe logged JSON shape.
|
||||
function parseFirstJsonRuntimeLine<T>() {
|
||||
const jsonLine = runtimeLogs.find((line) => line.trim().startsWith("{"));
|
||||
@@ -195,8 +207,8 @@ describe("daemon-cli coverage", () => {
|
||||
await runDaemonCommand(["daemon", "status"]);
|
||||
|
||||
expect(probeGatewayStatus).toHaveBeenCalledTimes(1);
|
||||
expect(probeGatewayStatus).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ url: "ws://127.0.0.1:18789" }),
|
||||
expect(requireMockCallArg(probeGatewayStatus, "probeGatewayStatus").url).toBe(
|
||||
"ws://127.0.0.1:18789",
|
||||
);
|
||||
expect(findExtraGatewayServices).not.toHaveBeenCalled();
|
||||
expect(inspectPortUsage).toHaveBeenCalled();
|
||||
@@ -220,10 +232,8 @@ describe("daemon-cli coverage", () => {
|
||||
|
||||
await runDaemonCommand(["daemon", "status", "--json"]);
|
||||
|
||||
expect(probeGatewayStatus).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
url: "ws://127.0.0.1:19001",
|
||||
}),
|
||||
expect(requireMockCallArg(probeGatewayStatus, "probeGatewayStatus").url).toBe(
|
||||
"ws://127.0.0.1:19001",
|
||||
);
|
||||
expect(inspectPortUsage).toHaveBeenCalledWith(19001);
|
||||
|
||||
@@ -245,10 +255,9 @@ describe("daemon-cli coverage", () => {
|
||||
|
||||
await runDaemonCommand(["daemon", "status", "--deep"]);
|
||||
|
||||
expect(findExtraGatewayServices).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.objectContaining({ deep: true }),
|
||||
);
|
||||
expect(findExtraGatewayServices).toHaveBeenCalledTimes(1);
|
||||
expect(findExtraGatewayServices.mock.calls[0]?.[0]).toBeDefined();
|
||||
expect(findExtraGatewayServices.mock.calls[0]?.[1]).toEqual({ deep: true });
|
||||
});
|
||||
|
||||
it("installs the daemon (json output)", async () => {
|
||||
@@ -293,18 +302,18 @@ describe("daemon-cli coverage", () => {
|
||||
|
||||
await runDaemonCommand(["daemon", "install", "--force", "--json"]);
|
||||
|
||||
expect(buildGatewayInstallPlan).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
existingEnvironment: {
|
||||
PATH: "/custom/go/bin:/usr/bin",
|
||||
OPENCLAW_WRAPPER: "/usr/local/bin/openclaw-doppler",
|
||||
GOPATH: "/Users/test/.local/gopath",
|
||||
GOBIN: "/Users/test/.local/gopath/bin",
|
||||
},
|
||||
env: expect.objectContaining({
|
||||
OPENCLAW_WRAPPER: "/usr/local/bin/openclaw-doppler",
|
||||
}),
|
||||
}),
|
||||
const installPlanParams = requireMockCallArg(
|
||||
buildGatewayInstallPlan,
|
||||
"buildGatewayInstallPlan",
|
||||
);
|
||||
expect(installPlanParams.existingEnvironment).toEqual({
|
||||
PATH: "/custom/go/bin:/usr/bin",
|
||||
OPENCLAW_WRAPPER: "/usr/local/bin/openclaw-doppler",
|
||||
GOPATH: "/Users/test/.local/gopath",
|
||||
GOBIN: "/Users/test/.local/gopath/bin",
|
||||
});
|
||||
expect((installPlanParams.env as NodeJS.ProcessEnv).OPENCLAW_WRAPPER).toBe(
|
||||
"/usr/local/bin/openclaw-doppler",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -320,10 +329,8 @@ describe("daemon-cli coverage", () => {
|
||||
"--json",
|
||||
]);
|
||||
|
||||
expect(buildGatewayInstallPlan).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
wrapperPath: "/usr/local/bin/openclaw-doppler",
|
||||
}),
|
||||
expect(requireMockCallArg(buildGatewayInstallPlan, "buildGatewayInstallPlan").wrapperPath).toBe(
|
||||
"/usr/local/bin/openclaw-doppler",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -346,6 +353,6 @@ describe("daemon-cli coverage", () => {
|
||||
(entry) => Boolean(entry.ok),
|
||||
(entry) => entry.action,
|
||||
),
|
||||
).toEqual(expect.arrayContaining(["start", "stop"]));
|
||||
).toEqual(["start", "stop"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user