This pull request adds a feature that allows users to configure auto-approved commands via a `safeCommands` array in the configuration file. ## Related Issue #380 ## Changes - Added loading and validation of the `safeCommands` array in `src/utils/config.ts` - Implemented auto-approval logic for commands matching `safeCommands` prefixes in `src/approvals.ts` - Added test cases in `src/tests/approvals.test.ts` to verify `safeCommands` behavior - Updated documentation with examples and explanations of the configuration
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import type { SafetyAssessment } from "../src/approvals";
|
||||
|
||||
import { canAutoApprove } from "../src/approvals";
|
||||
import { describe, test, expect } from "vitest";
|
||||
import { describe, test, expect, vi } from "vitest";
|
||||
|
||||
vi.mock("../src/utils/config", () => ({
|
||||
loadConfig: () => ({
|
||||
safeCommands: ["npm test", "sl"],
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("canAutoApprove()", () => {
|
||||
const env = {
|
||||
@@ -89,4 +95,27 @@ describe("canAutoApprove()", () => {
|
||||
|
||||
expect(check(["cargo", "build"])).toEqual({ type: "ask-user" });
|
||||
});
|
||||
|
||||
test("commands in safeCommands config should be safe", async () => {
|
||||
expect(check(["npm", "test"])).toEqual({
|
||||
type: "auto-approve",
|
||||
reason: "User-defined safe command",
|
||||
group: "User config",
|
||||
runInSandbox: false,
|
||||
});
|
||||
|
||||
expect(check(["sl"])).toEqual({
|
||||
type: "auto-approve",
|
||||
reason: "User-defined safe command",
|
||||
group: "User config",
|
||||
runInSandbox: false,
|
||||
});
|
||||
|
||||
expect(check(["npm", "test", "--watch"])).toEqual({
|
||||
type: "auto-approve",
|
||||
reason: "User-defined safe command",
|
||||
group: "User config",
|
||||
runInSandbox: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user