test: micro-optimize slow suites and CLI command setup

This commit is contained in:
Peter Steinberger
2026-03-02 23:00:42 +00:00
parent ba5ae5b4f1
commit 2287d1ec13
7 changed files with 259 additions and 164 deletions

View File

@@ -1,6 +1,5 @@
import { Command } from "commander";
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) => ({
@@ -113,9 +112,13 @@ vi.mock("./discover.js", () => ({
describe("gateway register option collisions", () => {
let registerGatewayCli: typeof import("./register.js").registerGatewayCli;
let sharedProgram: Command;
beforeAll(async () => {
({ registerGatewayCli } = await import("./register.js"));
sharedProgram = new Command();
sharedProgram.exitOverride();
registerGatewayCli(sharedProgram);
});
beforeEach(() => {
@@ -125,9 +128,8 @@ describe("gateway register option collisions", () => {
});
it("forwards --token to gateway call when parent and child option names collide", async () => {
await runRegisteredCli({
register: registerGatewayCli as (program: Command) => void,
argv: ["gateway", "call", "health", "--token", "tok_call", "--json"],
await sharedProgram.parseAsync(["gateway", "call", "health", "--token", "tok_call", "--json"], {
from: "user",
});
expect(callGatewayCli).toHaveBeenCalledWith(
@@ -140,9 +142,8 @@ describe("gateway register option collisions", () => {
});
it("forwards --token to gateway probe when parent and child option names collide", async () => {
await runRegisteredCli({
register: registerGatewayCli as (program: Command) => void,
argv: ["gateway", "probe", "--token", "tok_probe", "--json"],
await sharedProgram.parseAsync(["gateway", "probe", "--token", "tok_probe", "--json"], {
from: "user",
});
expect(gatewayStatusCommand).toHaveBeenCalledWith(

View File

@@ -1,6 +1,5 @@
import { Command } from "commander";
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) => ({
@@ -93,9 +92,14 @@ vi.mock("./run-loop.js", () => ({
describe("gateway run option collisions", () => {
let addGatewayRunCommand: typeof import("./run.js").addGatewayRunCommand;
let sharedProgram: Command;
beforeAll(async () => {
({ addGatewayRunCommand } = await import("./run.js"));
sharedProgram = new Command();
sharedProgram.exitOverride();
const gateway = addGatewayRunCommand(sharedProgram.command("gateway"));
addGatewayRunCommand(gateway.command("run"));
});
beforeEach(() => {
@@ -109,13 +113,7 @@ describe("gateway run option collisions", () => {
});
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 sharedProgram.parseAsync(argv, { from: "user" });
}
function expectAuthOverrideMode(mode: string) {