test: dedupe and optimize test suites

This commit is contained in:
Peter Steinberger
2026-02-19 15:18:50 +00:00
parent b0e55283d5
commit a1cb700a05
80 changed files with 2627 additions and 2962 deletions

View File

@@ -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(

View File

@@ -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,