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

@@ -20,99 +20,108 @@ installSmokeProgramMocks();
const { buildProgram } = await import("./program.js");
describe("cli program (smoke)", () => {
function createProgram() {
return buildProgram();
}
async function runProgram(argv: string[]) {
const program = createProgram();
await program.parseAsync(argv, { from: "user" });
}
beforeEach(() => {
vi.clearAllMocks();
runTui.mockResolvedValue(undefined);
ensureConfigReady.mockResolvedValue(undefined);
});
it("runs message with required options", async () => {
const program = buildProgram();
await expect(
program.parseAsync(["message", "send", "--target", "+1", "--message", "hi"], {
from: "user",
}),
).rejects.toThrow("exit");
expect(messageCommand).toHaveBeenCalled();
});
it("runs message react with signal author fields", async () => {
const program = buildProgram();
await expect(
program.parseAsync(
[
"message",
"react",
"--channel",
"signal",
"--target",
"signal:group:abc123",
"--message-id",
"1737630212345",
"--emoji",
"✅",
"--target-author-uuid",
"123e4567-e89b-12d3-a456-426614174000",
],
{ from: "user" },
),
).rejects.toThrow("exit");
it.each([
{
label: "runs message with required options",
argv: ["message", "send", "--target", "+1", "--message", "hi"],
},
{
label: "runs message react with signal author fields",
argv: [
"message",
"react",
"--channel",
"signal",
"--target",
"signal:group:abc123",
"--message-id",
"1737630212345",
"--emoji",
"✅",
"--target-author-uuid",
"123e4567-e89b-12d3-a456-426614174000",
],
},
])("$label", async ({ argv }) => {
await expect(runProgram(argv)).rejects.toThrow("exit");
expect(messageCommand).toHaveBeenCalled();
});
it("runs status command", async () => {
const program = buildProgram();
await program.parseAsync(["status"], { from: "user" });
await runProgram(["status"]);
expect(statusCommand).toHaveBeenCalled();
});
it("registers memory command", () => {
const program = buildProgram();
const program = createProgram();
const names = program.commands.map((command) => command.name());
expect(names).toContain("memory");
});
it("runs tui without overriding timeout", async () => {
const program = buildProgram();
await program.parseAsync(["tui"], { from: "user" });
expect(runTui).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: undefined }));
});
it("runs tui with explicit timeout override", async () => {
const program = buildProgram();
await program.parseAsync(["tui", "--timeout-ms", "45000"], {
from: "user",
});
expect(runTui).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: 45000 }));
});
it("warns and ignores invalid tui timeout override", async () => {
const program = buildProgram();
await program.parseAsync(["tui", "--timeout-ms", "nope"], { from: "user" });
expect(runtime.error).toHaveBeenCalledWith('warning: invalid --timeout-ms "nope"; ignoring');
expect(runTui).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: undefined }));
it.each([
{
label: "runs tui without overriding timeout",
argv: ["tui"],
expectedTimeoutMs: undefined,
expectedWarning: undefined,
},
{
label: "runs tui with explicit timeout override",
argv: ["tui", "--timeout-ms", "45000"],
expectedTimeoutMs: 45000,
expectedWarning: undefined,
},
{
label: "warns and ignores invalid tui timeout override",
argv: ["tui", "--timeout-ms", "nope"],
expectedTimeoutMs: undefined,
expectedWarning: 'warning: invalid --timeout-ms "nope"; ignoring',
},
])("$label", async ({ argv, expectedTimeoutMs, expectedWarning }) => {
await runProgram(argv);
if (expectedWarning) {
expect(runtime.error).toHaveBeenCalledWith(expectedWarning);
}
expect(runTui).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: expectedTimeoutMs }));
});
it("runs config alias as configure", async () => {
const program = buildProgram();
await program.parseAsync(["config"], { from: "user" });
await runProgram(["config"]);
expect(configureCommand).toHaveBeenCalled();
});
it("runs setup without wizard flags", async () => {
const program = buildProgram();
await program.parseAsync(["setup"], { from: "user" });
expect(setupCommand).toHaveBeenCalled();
expect(onboardCommand).not.toHaveBeenCalled();
});
it("runs setup wizard when wizard flags are present", async () => {
const program = buildProgram();
await program.parseAsync(["setup", "--remote-url", "ws://example"], {
from: "user",
});
expect(onboardCommand).toHaveBeenCalled();
expect(setupCommand).not.toHaveBeenCalled();
it.each([
{
label: "runs setup without wizard flags",
argv: ["setup"],
expectSetupCalled: true,
expectOnboardCalled: false,
},
{
label: "runs setup wizard when wizard flags are present",
argv: ["setup", "--remote-url", "ws://example"],
expectSetupCalled: false,
expectOnboardCalled: true,
},
])("$label", async ({ argv, expectSetupCalled, expectOnboardCalled }) => {
await runProgram(argv);
expect(setupCommand).toHaveBeenCalledTimes(expectSetupCalled ? 1 : 0);
expect(onboardCommand).toHaveBeenCalledTimes(expectOnboardCalled ? 1 : 0);
});
it("passes auth api keys to onboard", async () => {
@@ -168,11 +177,14 @@ describe("cli program (smoke)", () => {
] as const;
for (const entry of cases) {
const program = buildProgram();
await program.parseAsync(
["onboard", "--non-interactive", "--auth-choice", entry.authChoice, entry.flag, entry.key],
{ from: "user" },
);
await runProgram([
"onboard",
"--non-interactive",
"--auth-choice",
entry.authChoice,
entry.flag,
entry.key,
]);
expect(onboardCommand).toHaveBeenCalledWith(
expect.objectContaining({
nonInteractive: true,
@@ -186,26 +198,22 @@ describe("cli program (smoke)", () => {
});
it("passes custom provider flags to onboard", async () => {
const program = buildProgram();
await program.parseAsync(
[
"onboard",
"--non-interactive",
"--auth-choice",
"custom-api-key",
"--custom-base-url",
"https://llm.example.com/v1",
"--custom-api-key",
"sk-custom-test",
"--custom-model-id",
"foo-large",
"--custom-provider-id",
"my-custom",
"--custom-compatibility",
"anthropic",
],
{ from: "user" },
);
await runProgram([
"onboard",
"--non-interactive",
"--auth-choice",
"custom-api-key",
"--custom-base-url",
"https://llm.example.com/v1",
"--custom-api-key",
"sk-custom-test",
"--custom-model-id",
"foo-large",
"--custom-provider-id",
"my-custom",
"--custom-compatibility",
"anthropic",
]);
expect(onboardCommand).toHaveBeenCalledWith(
expect.objectContaining({
@@ -221,22 +229,27 @@ describe("cli program (smoke)", () => {
);
});
it("runs channels login", async () => {
const program = buildProgram();
await program.parseAsync(["channels", "login", "--account", "work"], {
from: "user",
});
expect(runChannelLogin).toHaveBeenCalledWith(
{ channel: undefined, account: "work", verbose: false },
runtime,
);
});
it("runs channels logout", async () => {
const program = buildProgram();
await program.parseAsync(["channels", "logout", "--account", "work"], {
from: "user",
});
expect(runChannelLogout).toHaveBeenCalledWith({ channel: undefined, account: "work" }, runtime);
it.each([
{
label: "runs channels login",
argv: ["channels", "login", "--account", "work"],
expectCall: () =>
expect(runChannelLogin).toHaveBeenCalledWith(
{ channel: undefined, account: "work", verbose: false },
runtime,
),
},
{
label: "runs channels logout",
argv: ["channels", "logout", "--account", "work"],
expectCall: () =>
expect(runChannelLogout).toHaveBeenCalledWith(
{ channel: undefined, account: "work" },
runtime,
),
},
])("$label", async ({ argv, expectCall }) => {
await runProgram(argv);
expectCall();
});
});