mirror of
https://github.com/yuangyaa/openclaw.git
synced 2026-07-14 11:07:29 +08:00
test: fix post-merge config and tui command-handler tests
This commit is contained in:
@@ -85,7 +85,17 @@ describe("browser state option collisions", () => {
|
|||||||
it("resolves --url via parent when addGatewayClientOptions captures it", async () => {
|
it("resolves --url via parent when addGatewayClientOptions captures it", async () => {
|
||||||
const program = createBrowserProgram({ withGatewayUrl: true });
|
const program = createBrowserProgram({ withGatewayUrl: true });
|
||||||
await program.parseAsync(
|
await program.parseAsync(
|
||||||
["browser", "--url", "ws://gw", "cookies", "set", "session", "abc", "--url", "https://example.com"],
|
[
|
||||||
|
"browser",
|
||||||
|
"--url",
|
||||||
|
"ws://gw",
|
||||||
|
"cookies",
|
||||||
|
"set",
|
||||||
|
"session",
|
||||||
|
"abc",
|
||||||
|
"--url",
|
||||||
|
"https://example.com",
|
||||||
|
],
|
||||||
{ from: "user" },
|
{ from: "user" },
|
||||||
);
|
);
|
||||||
const call = mocks.callBrowserRequest.mock.calls.at(-1);
|
const call = mocks.callBrowserRequest.mock.calls.at(-1);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import path from "node:path";
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import { withTempHome } from "./home-env.test-harness.js";
|
import { withTempHome } from "./home-env.test-harness.js";
|
||||||
import { createConfigIO } from "./io.js";
|
import { createConfigIO } from "./io.js";
|
||||||
|
import type { OpenClawConfig } from "./types.js";
|
||||||
|
|
||||||
describe("config io write", () => {
|
describe("config io write", () => {
|
||||||
const silentLogger = {
|
const silentLogger = {
|
||||||
@@ -140,7 +141,7 @@ describe("config io write", () => {
|
|||||||
allowFrom: [],
|
allowFrom: [],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
} satisfies OpenClawConfig;
|
||||||
|
|
||||||
await expect(io.writeConfigFile(invalidConfig)).rejects.toThrow(
|
await expect(io.writeConfigFile(invalidConfig)).rejects.toThrow(
|
||||||
"openclaw config set channels.telegram.allowFrom '[\"*\"]'",
|
"openclaw config set channels.telegram.allowFrom '[\"*\"]'",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ function createHarness(params?: {
|
|||||||
resetSession?: ReturnType<typeof vi.fn>;
|
resetSession?: ReturnType<typeof vi.fn>;
|
||||||
loadHistory?: LoadHistoryMock;
|
loadHistory?: LoadHistoryMock;
|
||||||
setActivityStatus?: SetActivityStatusMock;
|
setActivityStatus?: SetActivityStatusMock;
|
||||||
|
isConnected?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const sendChat = params?.sendChat ?? vi.fn().mockResolvedValue({ runId: "r1" });
|
const sendChat = params?.sendChat ?? vi.fn().mockResolvedValue({ runId: "r1" });
|
||||||
const resetSession = params?.resetSession ?? vi.fn().mockResolvedValue({ ok: true });
|
const resetSession = params?.resetSession ?? vi.fn().mockResolvedValue({ ok: true });
|
||||||
@@ -27,6 +28,7 @@ function createHarness(params?: {
|
|||||||
state: {
|
state: {
|
||||||
currentSessionKey: "agent:main:main",
|
currentSessionKey: "agent:main:main",
|
||||||
activeChatRunId: null,
|
activeChatRunId: null,
|
||||||
|
isConnected: params?.isConnected ?? true,
|
||||||
sessionInfo: {},
|
sessionInfo: {},
|
||||||
} as never,
|
} as never,
|
||||||
deliverDefault: false,
|
deliverDefault: false,
|
||||||
@@ -126,4 +128,17 @@ describe("tui command handlers", () => {
|
|||||||
expect(addSystem).toHaveBeenCalledWith("send failed: Error: gateway down");
|
expect(addSystem).toHaveBeenCalledWith("send failed: Error: gateway down");
|
||||||
expect(setActivityStatus).toHaveBeenLastCalledWith("error");
|
expect(setActivityStatus).toHaveBeenLastCalledWith("error");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("reports disconnected status and skips gateway send when offline", async () => {
|
||||||
|
const { handleCommand, sendChat, addUser, addSystem, setActivityStatus } = createHarness({
|
||||||
|
isConnected: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
await handleCommand("/context");
|
||||||
|
|
||||||
|
expect(sendChat).not.toHaveBeenCalled();
|
||||||
|
expect(addUser).not.toHaveBeenCalled();
|
||||||
|
expect(addSystem).toHaveBeenCalledWith("not connected to gateway — message not sent");
|
||||||
|
expect(setActivityStatus).toHaveBeenLastCalledWith("disconnected");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user