mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
fix(test): guard dev smoke cli args
This commit is contained in:
@@ -216,7 +216,46 @@ function runScript(url: string, extraArgs: readonly string[] = []): Promise<Scri
|
||||
});
|
||||
}
|
||||
|
||||
function runScriptRaw(args: readonly string[]): Promise<ScriptResult> {
|
||||
return new Promise((resolve) => {
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
["--import", "tsx", "scripts/dev/ios-node-e2e.ts", ...args],
|
||||
{
|
||||
stdio: "pipe",
|
||||
},
|
||||
);
|
||||
const stdout = createBoundedChildOutput();
|
||||
const stderr = createBoundedChildOutput();
|
||||
child.stdout.on("data", (chunk) => {
|
||||
stdout.append(chunk);
|
||||
});
|
||||
child.stderr.on("data", (chunk) => {
|
||||
stderr.append(chunk);
|
||||
});
|
||||
child.on("close", (status, signal) => {
|
||||
resolve({ status, signal, stdout: stdout.text(), stderr: stderr.text(), timedOut: false });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe("ios-node-e2e", () => {
|
||||
it("prints CLI help without connecting", async () => {
|
||||
const result = await runScriptRaw(["--help"]);
|
||||
|
||||
expect(result).toMatchObject({ signal: null, status: 0, timedOut: false });
|
||||
expect(result.stdout).toContain("Usage: bun scripts/dev/ios-node-e2e.ts");
|
||||
expect(result.stderr).toBe("");
|
||||
});
|
||||
|
||||
it("rejects unknown CLI args before connecting", async () => {
|
||||
const result = await runScript("ws://127.0.0.1:9", ["--wat"]);
|
||||
|
||||
expect(result).toMatchObject({ signal: null, status: 1, timedOut: false });
|
||||
expect(result.stderr.trim()).toBe("Unknown argument: --wat");
|
||||
expect(result.stdout).toBe("");
|
||||
});
|
||||
|
||||
it("rejects malformed wait seconds before connecting", async () => {
|
||||
const result = await runScript("ws://127.0.0.1:9", ["--wait-seconds", "1e3"]);
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
// Test Device Pair Telegram tests cover the dev Telegram pairing smoke helper.
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { runDevicePairTelegram } from "../../scripts/dev/test-device-pair-telegram.ts";
|
||||
import {
|
||||
parseDevicePairTelegramArgs,
|
||||
runDevicePairTelegram,
|
||||
} from "../../scripts/dev/test-device-pair-telegram.ts";
|
||||
|
||||
const scriptUrl = pathToFileURL("scripts/dev/test-device-pair-telegram.ts").href;
|
||||
|
||||
@@ -10,6 +13,34 @@ describe("scripts/dev/test-device-pair-telegram.ts", () => {
|
||||
await expect(import(`${scriptUrl}?case=load-${Date.now()}`)).resolves.toBeDefined();
|
||||
});
|
||||
|
||||
it("parses help without requiring Telegram config", () => {
|
||||
expect(parseDevicePairTelegramArgs(["--help"])).toEqual({
|
||||
accountId: undefined,
|
||||
chatId: undefined,
|
||||
help: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects unknown args before loading OpenClaw plugins", async () => {
|
||||
const cfg = { channels: { telegram: { enabled: true } } };
|
||||
const loadOpenClawPlugins = vi.fn();
|
||||
const executePluginCommand = vi.fn();
|
||||
const sendMessageTelegram = vi.fn();
|
||||
|
||||
await expect(
|
||||
runDevicePairTelegram(["--chat", "chat-123", "--wat"], {
|
||||
executePluginCommand,
|
||||
getRuntimeConfig: () => cfg,
|
||||
loadOpenClawPlugins,
|
||||
matchPluginCommand: () => ({ args: "from-match", command: { name: "pair" } as never }),
|
||||
sendMessageTelegram,
|
||||
}),
|
||||
).rejects.toThrow("Unknown argument: --wat");
|
||||
expect(loadOpenClawPlugins).not.toHaveBeenCalled();
|
||||
expect(executePluginCommand).not.toHaveBeenCalled();
|
||||
expect(sendMessageTelegram).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sends the generated /pair reply through the injected Telegram runtime", async () => {
|
||||
const cfg = { channels: { telegram: { enabled: true } } };
|
||||
const loadOpenClawPlugins = vi.fn();
|
||||
|
||||
Reference in New Issue
Block a user