mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 21:21:24 +00:00
chore: Fix types in tests 6/N.
This commit is contained in:
@@ -7,12 +7,23 @@ const loadConfig = vi.fn(() => ({
|
||||
auth: { token: "ltok" },
|
||||
},
|
||||
}));
|
||||
const resolveGatewayPort = vi.fn(() => 18789);
|
||||
const discoverGatewayBeacons = vi.fn(async () => []);
|
||||
const resolveGatewayPort = vi.fn((_cfg?: unknown) => 18789);
|
||||
const discoverGatewayBeacons = vi.fn(
|
||||
async (_opts?: unknown): Promise<Array<{ tailnetDns: string }>> => [],
|
||||
);
|
||||
const pickPrimaryTailnetIPv4 = vi.fn(() => "100.64.0.10");
|
||||
const sshStop = vi.fn(async () => {});
|
||||
const resolveSshConfig = vi.fn(async () => null);
|
||||
const startSshPortForward = vi.fn(async () => ({
|
||||
const resolveSshConfig = vi.fn(
|
||||
async (
|
||||
_opts?: unknown,
|
||||
): Promise<{
|
||||
user: string;
|
||||
host: string;
|
||||
port: number;
|
||||
identityFiles: string[];
|
||||
} | null> => null,
|
||||
);
|
||||
const startSshPortForward = vi.fn(async (_opts?: unknown) => ({
|
||||
parsedTarget: { user: "me", host: "studio", port: 22 },
|
||||
localPort: 18789,
|
||||
remotePort: 18789,
|
||||
@@ -20,7 +31,8 @@ const startSshPortForward = vi.fn(async () => ({
|
||||
stderr: [],
|
||||
stop: sshStop,
|
||||
}));
|
||||
const probeGateway = vi.fn(async ({ url }: { url: string }) => {
|
||||
const probeGateway = vi.fn(async (opts: { url: string }) => {
|
||||
const { url } = opts;
|
||||
if (url.includes("127.0.0.1")) {
|
||||
return {
|
||||
ok: true,
|
||||
@@ -80,32 +92,32 @@ const probeGateway = vi.fn(async ({ url }: { url: string }) => {
|
||||
});
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
loadConfig: () => loadConfig(),
|
||||
resolveGatewayPort: (cfg: unknown) => resolveGatewayPort(cfg),
|
||||
loadConfig,
|
||||
resolveGatewayPort,
|
||||
}));
|
||||
|
||||
vi.mock("../infra/bonjour-discovery.js", () => ({
|
||||
discoverGatewayBeacons: (opts: unknown) => discoverGatewayBeacons(opts),
|
||||
discoverGatewayBeacons,
|
||||
}));
|
||||
|
||||
vi.mock("../infra/tailnet.js", () => ({
|
||||
pickPrimaryTailnetIPv4: () => pickPrimaryTailnetIPv4(),
|
||||
pickPrimaryTailnetIPv4,
|
||||
}));
|
||||
|
||||
vi.mock("../infra/ssh-tunnel.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../infra/ssh-tunnel.js")>();
|
||||
return {
|
||||
...actual,
|
||||
startSshPortForward: (opts: unknown) => startSshPortForward(opts),
|
||||
startSshPortForward,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../infra/ssh-config.js", () => ({
|
||||
resolveSshConfig: (opts: unknown) => resolveSshConfig(opts),
|
||||
resolveSshConfig,
|
||||
}));
|
||||
|
||||
vi.mock("../gateway/probe.js", () => ({
|
||||
probeGateway: (opts: unknown) => probeGateway(opts),
|
||||
probeGateway,
|
||||
}));
|
||||
|
||||
function createRuntimeCapture() {
|
||||
@@ -198,7 +210,8 @@ describe("gateway-status command", () => {
|
||||
loadConfig.mockReturnValueOnce({
|
||||
gateway: {
|
||||
mode: "remote",
|
||||
remote: {},
|
||||
remote: { url: "", token: "" },
|
||||
auth: { token: "ltok" },
|
||||
},
|
||||
});
|
||||
discoverGatewayBeacons.mockResolvedValueOnce([
|
||||
@@ -226,6 +239,7 @@ describe("gateway-status command", () => {
|
||||
gateway: {
|
||||
mode: "remote",
|
||||
remote: { url: "ws://peters-mac-studio-1.sheep-coho.ts.net:18789", token: "rtok" },
|
||||
auth: { token: "ltok" },
|
||||
},
|
||||
});
|
||||
resolveSshConfig.mockResolvedValueOnce({
|
||||
@@ -259,6 +273,7 @@ describe("gateway-status command", () => {
|
||||
gateway: {
|
||||
mode: "remote",
|
||||
remote: { url: "ws://studio.example:18789", token: "rtok" },
|
||||
auth: { token: "ltok" },
|
||||
},
|
||||
});
|
||||
resolveSshConfig.mockResolvedValueOnce(null);
|
||||
@@ -284,6 +299,7 @@ describe("gateway-status command", () => {
|
||||
gateway: {
|
||||
mode: "remote",
|
||||
remote: { url: "ws://studio.example:18789", token: "rtok" },
|
||||
auth: { token: "ltok" },
|
||||
},
|
||||
});
|
||||
resolveSshConfig.mockResolvedValueOnce({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import type { Mock } from "vitest";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
|
||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||
@@ -323,10 +324,12 @@ const runtime = {
|
||||
exit: vi.fn(),
|
||||
};
|
||||
|
||||
const runtimeLogMock = runtime.log as Mock<(...args: unknown[]) => void>;
|
||||
|
||||
describe("statusCommand", () => {
|
||||
it("prints JSON when requested", async () => {
|
||||
await statusCommand({ json: true }, runtime as never);
|
||||
const payload = JSON.parse((runtime.log as vi.Mock).mock.calls[0][0]);
|
||||
const payload = JSON.parse(String(runtimeLogMock.mock.calls[0]?.[0]));
|
||||
expect(payload.linkChannel.linked).toBe(true);
|
||||
expect(payload.memory.agentId).toBe("main");
|
||||
expect(payload.memoryPlugin.enabled).toBe(true);
|
||||
@@ -348,9 +351,9 @@ describe("statusCommand", () => {
|
||||
|
||||
it("surfaces unknown usage when totalTokens is missing", async () => {
|
||||
await withUnknownUsageStore(async () => {
|
||||
(runtime.log as vi.Mock).mockClear();
|
||||
runtimeLogMock.mockClear();
|
||||
await statusCommand({ json: true }, runtime as never);
|
||||
const payload = JSON.parse((runtime.log as vi.Mock).mock.calls.at(-1)?.[0]);
|
||||
const payload = JSON.parse(String(runtimeLogMock.mock.calls.at(-1)?.[0]));
|
||||
expect(payload.sessions.recent[0].totalTokens).toBeNull();
|
||||
expect(payload.sessions.recent[0].totalTokensFresh).toBe(false);
|
||||
expect(payload.sessions.recent[0].percentUsed).toBeNull();
|
||||
@@ -360,37 +363,37 @@ describe("statusCommand", () => {
|
||||
|
||||
it("prints unknown usage in formatted output when totalTokens is missing", async () => {
|
||||
await withUnknownUsageStore(async () => {
|
||||
(runtime.log as vi.Mock).mockClear();
|
||||
runtimeLogMock.mockClear();
|
||||
await statusCommand({}, runtime as never);
|
||||
const logs = (runtime.log as vi.Mock).mock.calls.map((c) => String(c[0]));
|
||||
const logs = runtimeLogMock.mock.calls.map((c: unknown[]) => String(c[0]));
|
||||
expect(logs.some((line) => line.includes("unknown/") && line.includes("(?%)"))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("prints formatted lines otherwise", async () => {
|
||||
(runtime.log as vi.Mock).mockClear();
|
||||
runtimeLogMock.mockClear();
|
||||
await statusCommand({}, runtime as never);
|
||||
const logs = (runtime.log as vi.Mock).mock.calls.map((c) => String(c[0]));
|
||||
expect(logs.some((l) => l.includes("OpenClaw status"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("Overview"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("Security audit"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("Summary:"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("CRITICAL"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("Dashboard"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("macos 14.0 (arm64)"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("Memory"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("Channels"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("WhatsApp"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("Sessions"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("+1000"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("50%"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("LaunchAgent"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("FAQ:"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("Troubleshooting:"))).toBe(true);
|
||||
expect(logs.some((l) => l.includes("Next steps:"))).toBe(true);
|
||||
const logs = runtimeLogMock.mock.calls.map((c: unknown[]) => String(c[0]));
|
||||
expect(logs.some((l: string) => l.includes("OpenClaw status"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("Overview"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("Security audit"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("Summary:"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("CRITICAL"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("Dashboard"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("macos 14.0 (arm64)"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("Memory"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("Channels"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("WhatsApp"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("Sessions"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("+1000"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("50%"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("LaunchAgent"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("FAQ:"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("Troubleshooting:"))).toBe(true);
|
||||
expect(logs.some((l: string) => l.includes("Next steps:"))).toBe(true);
|
||||
expect(
|
||||
logs.some(
|
||||
(l) =>
|
||||
(l: string) =>
|
||||
l.includes("openclaw status --all") ||
|
||||
l.includes("openclaw --profile isolated status --all") ||
|
||||
l.includes("openclaw status --all") ||
|
||||
@@ -414,10 +417,10 @@ describe("statusCommand", () => {
|
||||
presence: [],
|
||||
configSnapshot: null,
|
||||
});
|
||||
(runtime.log as vi.Mock).mockClear();
|
||||
runtimeLogMock.mockClear();
|
||||
await statusCommand({}, runtime as never);
|
||||
const logs = (runtime.log as vi.Mock).mock.calls.map((c) => String(c[0]));
|
||||
expect(logs.some((l) => l.includes("auth token"))).toBe(true);
|
||||
const logs = runtimeLogMock.mock.calls.map((c: unknown[]) => String(c[0]));
|
||||
expect(logs.some((l: string) => l.includes("auth token"))).toBe(true);
|
||||
} finally {
|
||||
if (prevToken === undefined) {
|
||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||
@@ -462,9 +465,9 @@ describe("statusCommand", () => {
|
||||
},
|
||||
});
|
||||
|
||||
(runtime.log as vi.Mock).mockClear();
|
||||
runtimeLogMock.mockClear();
|
||||
await statusCommand({}, runtime as never);
|
||||
const logs = (runtime.log as vi.Mock).mock.calls.map((c) => String(c[0]));
|
||||
const logs = runtimeLogMock.mock.calls.map((c: unknown[]) => String(c[0]));
|
||||
expect(logs.join("\n")).toMatch(/Signal/i);
|
||||
expect(logs.join("\n")).toMatch(/iMessage/i);
|
||||
expect(logs.join("\n")).toMatch(/gateway:/i);
|
||||
@@ -507,7 +510,7 @@ describe("statusCommand", () => {
|
||||
});
|
||||
|
||||
await statusCommand({ json: true }, runtime as never);
|
||||
const payload = JSON.parse((runtime.log as vi.Mock).mock.calls.at(-1)?.[0]);
|
||||
const payload = JSON.parse(String(runtimeLogMock.mock.calls.at(-1)?.[0]));
|
||||
expect(payload.sessions.count).toBe(2);
|
||||
expect(payload.sessions.paths.length).toBe(2);
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user