mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-30 22:50:22 +00:00
test: dedupe and optimize test suites
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Command } from "commander";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { runRegisteredCli } from "../../test-utils/command-runner.js";
|
||||
import { createCliRuntimeCapture } from "../test-runtime-capture.js";
|
||||
|
||||
const callGatewayCli = vi.fn(async (_method: string, _opts: unknown, _params?: unknown) => ({
|
||||
@@ -111,6 +112,12 @@ vi.mock("./discover.js", () => ({
|
||||
}));
|
||||
|
||||
describe("gateway register option collisions", () => {
|
||||
let registerGatewayCli: typeof import("./register.js").registerGatewayCli;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ registerGatewayCli } = await import("./register.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRuntimeCapture();
|
||||
callGatewayCli.mockClear();
|
||||
@@ -118,12 +125,9 @@ describe("gateway register option collisions", () => {
|
||||
});
|
||||
|
||||
it("forwards --token to gateway call when parent and child option names collide", async () => {
|
||||
const { registerGatewayCli } = await import("./register.js");
|
||||
const program = new Command();
|
||||
registerGatewayCli(program);
|
||||
|
||||
await program.parseAsync(["gateway", "call", "health", "--token", "tok_call", "--json"], {
|
||||
from: "user",
|
||||
await runRegisteredCli({
|
||||
register: registerGatewayCli as (program: Command) => void,
|
||||
argv: ["gateway", "call", "health", "--token", "tok_call", "--json"],
|
||||
});
|
||||
|
||||
expect(callGatewayCli).toHaveBeenCalledWith(
|
||||
@@ -136,12 +140,9 @@ describe("gateway register option collisions", () => {
|
||||
});
|
||||
|
||||
it("forwards --token to gateway probe when parent and child option names collide", async () => {
|
||||
const { registerGatewayCli } = await import("./register.js");
|
||||
const program = new Command();
|
||||
registerGatewayCli(program);
|
||||
|
||||
await program.parseAsync(["gateway", "probe", "--token", "tok_probe", "--json"], {
|
||||
from: "user",
|
||||
await runRegisteredCli({
|
||||
register: registerGatewayCli as (program: Command) => void,
|
||||
argv: ["gateway", "probe", "--token", "tok_probe", "--json"],
|
||||
});
|
||||
|
||||
expect(gatewayStatusCommand).toHaveBeenCalledWith(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Command } from "commander";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { runRegisteredCli } from "../../test-utils/command-runner.js";
|
||||
import { createCliRuntimeCapture } from "../test-runtime-capture.js";
|
||||
|
||||
const startGatewayServer = vi.fn(async (_port: number, _opts?: unknown) => ({
|
||||
@@ -91,6 +92,12 @@ vi.mock("./run-loop.js", () => ({
|
||||
}));
|
||||
|
||||
describe("gateway run option collisions", () => {
|
||||
let addGatewayRunCommand: typeof import("./run.js").addGatewayRunCommand;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ addGatewayRunCommand } = await import("./run.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resetRuntimeCapture();
|
||||
startGatewayServer.mockClear();
|
||||
@@ -101,25 +108,27 @@ describe("gateway run option collisions", () => {
|
||||
runGatewayLoop.mockClear();
|
||||
});
|
||||
|
||||
it("forwards parent-captured options to `gateway run` subcommand", async () => {
|
||||
const { addGatewayRunCommand } = await import("./run.js");
|
||||
const program = new Command();
|
||||
const gateway = addGatewayRunCommand(program.command("gateway"));
|
||||
addGatewayRunCommand(gateway.command("run"));
|
||||
async function runGatewayCli(argv: string[]) {
|
||||
await runRegisteredCli({
|
||||
register: ((program: Command) => {
|
||||
const gateway = addGatewayRunCommand(program.command("gateway"));
|
||||
addGatewayRunCommand(gateway.command("run"));
|
||||
}) as (program: Command) => void,
|
||||
argv,
|
||||
});
|
||||
}
|
||||
|
||||
await program.parseAsync(
|
||||
[
|
||||
"gateway",
|
||||
"run",
|
||||
"--token",
|
||||
"tok_run",
|
||||
"--allow-unconfigured",
|
||||
"--ws-log",
|
||||
"full",
|
||||
"--force",
|
||||
],
|
||||
{ from: "user" },
|
||||
);
|
||||
it("forwards parent-captured options to `gateway run` subcommand", async () => {
|
||||
await runGatewayCli([
|
||||
"gateway",
|
||||
"run",
|
||||
"--token",
|
||||
"tok_run",
|
||||
"--allow-unconfigured",
|
||||
"--ws-log",
|
||||
"full",
|
||||
"--force",
|
||||
]);
|
||||
|
||||
expect(forceFreePortAndWait).toHaveBeenCalledWith(18789, expect.anything());
|
||||
expect(setGatewayWsLogStyle).toHaveBeenCalledWith("full");
|
||||
@@ -134,14 +143,7 @@ describe("gateway run option collisions", () => {
|
||||
});
|
||||
|
||||
it("starts gateway when token mode has no configured token (startup bootstrap path)", async () => {
|
||||
const { addGatewayRunCommand } = await import("./run.js");
|
||||
const program = new Command();
|
||||
const gateway = addGatewayRunCommand(program.command("gateway"));
|
||||
addGatewayRunCommand(gateway.command("run"));
|
||||
|
||||
await program.parseAsync(["gateway", "run", "--allow-unconfigured"], {
|
||||
from: "user",
|
||||
});
|
||||
await runGatewayCli(["gateway", "run", "--allow-unconfigured"]);
|
||||
|
||||
expect(startGatewayServer).toHaveBeenCalledWith(
|
||||
18789,
|
||||
|
||||
Reference in New Issue
Block a user