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,4 +1,6 @@
import { Command } from "commander";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { runRegisteredCli } from "../test-utils/command-runner.js";
const githubCopilotLoginCommand = vi.fn();
const modelsStatusCommand = vi.fn().mockResolvedValue(undefined);
@@ -32,12 +34,10 @@ vi.mock("../commands/models.js", () => ({
}));
describe("models cli", () => {
let Command: typeof import("commander").Command;
let registerModelsCli: (typeof import("./models-cli.js"))["registerModelsCli"];
beforeAll(async () => {
// Load once; vi.mock above ensures command handlers are already mocked.
({ Command } = await import("commander"));
({ registerModelsCli } = await import("./models-cli.js"));
});
@@ -52,6 +52,13 @@ describe("models cli", () => {
return program;
}
async function runModelsCommand(args: string[]) {
await runRegisteredCli({
register: registerModelsCli as (program: Command) => void,
argv: args,
});
}
it("registers github-copilot login command", async () => {
const program = createProgram();
const models = program.commands.find((cmd) => cmd.name() === "models");
@@ -74,22 +81,11 @@ describe("models cli", () => {
);
});
it("passes --agent to models status", async () => {
const program = createProgram();
await program.parseAsync(["models", "status", "--agent", "poe"], { from: "user" });
expect(modelsStatusCommand).toHaveBeenCalledWith(
expect.objectContaining({ agent: "poe" }),
expect.any(Object),
);
});
it("passes parent --agent to models status", async () => {
const program = createProgram();
await program.parseAsync(["models", "--agent", "poe", "status"], { from: "user" });
it.each([
{ label: "status flag", args: ["models", "status", "--agent", "poe"] },
{ label: "parent flag", args: ["models", "--agent", "poe", "status"] },
])("passes --agent to models status ($label)", async ({ args }) => {
await runModelsCommand(args);
expect(modelsStatusCommand).toHaveBeenCalledWith(
expect.objectContaining({ agent: "poe" }),
expect.any(Object),