test: dedupe and optimize test suites
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Command } from "commander";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createCliRuntimeCapture } from "./test-runtime-capture.js";
|
||||
|
||||
const callGatewayFromCli = vi.fn(async (method: string, _opts: unknown, params?: unknown) => {
|
||||
@@ -67,27 +67,31 @@ describe("exec approvals CLI", () => {
|
||||
return program;
|
||||
};
|
||||
|
||||
it("routes get command to local, gateway, and node modes", async () => {
|
||||
const runApprovalsCommand = async (args: string[]) => {
|
||||
const program = createProgram();
|
||||
await program.parseAsync(args, { from: "user" });
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
resetLocalSnapshot();
|
||||
resetRuntimeCapture();
|
||||
callGatewayFromCli.mockClear();
|
||||
});
|
||||
|
||||
const localProgram = createProgram();
|
||||
await localProgram.parseAsync(["approvals", "get"], { from: "user" });
|
||||
it("routes get command to local, gateway, and node modes", async () => {
|
||||
await runApprovalsCommand(["approvals", "get"]);
|
||||
|
||||
expect(callGatewayFromCli).not.toHaveBeenCalled();
|
||||
expect(runtimeErrors).toHaveLength(0);
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const gatewayProgram = createProgram();
|
||||
await gatewayProgram.parseAsync(["approvals", "get", "--gateway"], { from: "user" });
|
||||
await runApprovalsCommand(["approvals", "get", "--gateway"]);
|
||||
|
||||
expect(callGatewayFromCli).toHaveBeenCalledWith("exec.approvals.get", expect.anything(), {});
|
||||
expect(runtimeErrors).toHaveLength(0);
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const nodeProgram = createProgram();
|
||||
await nodeProgram.parseAsync(["approvals", "get", "--node", "macbook"], { from: "user" });
|
||||
await runApprovalsCommand(["approvals", "get", "--node", "macbook"]);
|
||||
|
||||
expect(callGatewayFromCli).toHaveBeenCalledWith("exec.approvals.node.get", expect.anything(), {
|
||||
nodeId: "node-1",
|
||||
@@ -96,18 +100,10 @@ describe("exec approvals CLI", () => {
|
||||
});
|
||||
|
||||
it("defaults allowlist add to wildcard agent", async () => {
|
||||
resetLocalSnapshot();
|
||||
resetRuntimeCapture();
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const saveExecApprovals = vi.mocked(execApprovals.saveExecApprovals);
|
||||
saveExecApprovals.mockClear();
|
||||
|
||||
const program = new Command();
|
||||
program.exitOverride();
|
||||
registerExecApprovalsCli(program);
|
||||
|
||||
await program.parseAsync(["approvals", "allowlist", "add", "/usr/bin/uname"], { from: "user" });
|
||||
await runApprovalsCommand(["approvals", "allowlist", "add", "/usr/bin/uname"]);
|
||||
|
||||
expect(callGatewayFromCli).not.toHaveBeenCalledWith(
|
||||
"exec.approvals.set",
|
||||
@@ -124,7 +120,6 @@ describe("exec approvals CLI", () => {
|
||||
});
|
||||
|
||||
it("removes wildcard allowlist entry and prunes empty agent", async () => {
|
||||
resetLocalSnapshot();
|
||||
localSnapshot.file = {
|
||||
version: 1,
|
||||
agents: {
|
||||
@@ -133,16 +128,11 @@ describe("exec approvals CLI", () => {
|
||||
},
|
||||
},
|
||||
};
|
||||
resetRuntimeCapture();
|
||||
callGatewayFromCli.mockClear();
|
||||
|
||||
const saveExecApprovals = vi.mocked(execApprovals.saveExecApprovals);
|
||||
saveExecApprovals.mockClear();
|
||||
|
||||
const program = createProgram();
|
||||
await program.parseAsync(["approvals", "allowlist", "remove", "/usr/bin/uname"], {
|
||||
from: "user",
|
||||
});
|
||||
await runApprovalsCommand(["approvals", "allowlist", "remove", "/usr/bin/uname"]);
|
||||
|
||||
expect(saveExecApprovals).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
||||
Reference in New Issue
Block a user