test: tighten agent CLI registration assertions

This commit is contained in:
Peter Steinberger
2026-05-11 06:11:55 +01:00
parent f1ab8ea171
commit 22f5e99c31

View File

@@ -79,62 +79,57 @@ describe("registerAgentCommands", () => {
createDefaultDepsMock.mockReturnValue({ deps: true });
});
function commandCall(mock: { mock: { calls: unknown[][] } }, index = 0): unknown[] {
const call = mock.mock.calls[index];
if (!call) {
throw new Error(`expected command call ${index + 1}`);
}
return call;
}
it("runs agent command with deps and verbose enabled for --verbose on", async () => {
await runCli(["agent", "--message", "hi", "--verbose", "ON", "--json"]);
expect(setVerboseMock).toHaveBeenCalledWith(true);
expect(createDefaultDepsMock).toHaveBeenCalledTimes(1);
expect(agentCliCommandMock).toHaveBeenCalledWith(
expect.objectContaining({
message: "hi",
verbose: "ON",
json: true,
}),
runtime,
{ deps: true },
);
const [options, callRuntime, deps] = commandCall(agentCliCommandMock);
expect((options as { message?: string }).message).toBe("hi");
expect((options as { verbose?: string }).verbose).toBe("ON");
expect((options as { json?: boolean }).json).toBe(true);
expect(callRuntime).toBe(runtime);
expect(deps).toEqual({ deps: true });
});
it("runs agent command with verbose disabled for --verbose off", async () => {
await runCli(["agent", "--message", "hi", "--verbose", "off"]);
expect(setVerboseMock).toHaveBeenCalledWith(false);
expect(agentCliCommandMock).toHaveBeenCalledWith(
expect.objectContaining({
message: "hi",
verbose: "off",
}),
runtime,
{ deps: true },
);
const [options, callRuntime, deps] = commandCall(agentCliCommandMock);
expect((options as { message?: string }).message).toBe("hi");
expect((options as { verbose?: string }).verbose).toBe("off");
expect(callRuntime).toBe(runtime);
expect(deps).toEqual({ deps: true });
});
it("accepts a model override for one-shot agent runs", async () => {
await runCli(["agent", "--message", "hi", "--agent", "ops", "--model", "openai/gpt-5.4"]);
expect(agentCliCommandMock).toHaveBeenCalledWith(
expect.objectContaining({
message: "hi",
agent: "ops",
model: "openai/gpt-5.4",
}),
runtime,
{ deps: true },
);
const [options, callRuntime, deps] = commandCall(agentCliCommandMock);
expect((options as { message?: string }).message).toBe("hi");
expect((options as { agent?: string }).agent).toBe("ops");
expect((options as { model?: string }).model).toBe("openai/gpt-5.4");
expect(callRuntime).toBe(runtime);
expect(deps).toEqual({ deps: true });
});
it("runs agents add and computes hasFlags based on explicit options", async () => {
await runCli(["agents", "add", "alpha"]);
expect(agentsAddCommandMock).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
name: "alpha",
workspace: undefined,
bind: [],
}),
runtime,
{ hasFlags: false },
);
const [alphaOptions, alphaRuntime, alphaFlags] = commandCall(agentsAddCommandMock, 0);
expect((alphaOptions as { name?: string }).name).toBe("alpha");
expect((alphaOptions as { workspace?: string }).workspace).toBeUndefined();
expect((alphaOptions as { bind?: string[] }).bind).toEqual([]);
expect(alphaRuntime).toBe(runtime);
expect(alphaFlags).toEqual({ hasFlags: false });
await runCli([
"agents",
@@ -149,18 +144,14 @@ describe("registerAgentCommands", () => {
"--non-interactive",
"--json",
]);
expect(agentsAddCommandMock).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
name: "beta",
workspace: "/tmp/ws",
bind: ["telegram", "discord:acct"],
nonInteractive: true,
json: true,
}),
runtime,
{ hasFlags: true },
);
const [betaOptions, betaRuntime, betaFlags] = commandCall(agentsAddCommandMock, 1);
expect((betaOptions as { name?: string }).name).toBe("beta");
expect((betaOptions as { workspace?: string }).workspace).toBe("/tmp/ws");
expect((betaOptions as { bind?: string[] }).bind).toEqual(["telegram", "discord:acct"]);
expect((betaOptions as { nonInteractive?: boolean }).nonInteractive).toBe(true);
expect((betaOptions as { json?: boolean }).json).toBe(true);
expect(betaRuntime).toBe(runtime);
expect(betaFlags).toEqual({ hasFlags: true });
});
it("runs agents list when root agents command is invoked", async () => {
@@ -236,14 +227,11 @@ describe("registerAgentCommands", () => {
it("forwards agents delete options", async () => {
await runCli(["agents", "delete", "worker-a", "--force", "--json"]);
expect(agentsDeleteCommandMock).toHaveBeenCalledWith(
expect.objectContaining({
id: "worker-a",
force: true,
json: true,
}),
runtime,
);
const [options, callRuntime] = commandCall(agentsDeleteCommandMock);
expect((options as { id?: string }).id).toBe("worker-a");
expect((options as { force?: boolean }).force).toBe(true);
expect((options as { json?: boolean }).json).toBe(true);
expect(callRuntime).toBe(runtime);
});
it("forwards set-identity options", async () => {