fix feedback
This commit is contained in:
parent
328ff12e65
commit
e614792d31
5 changed files with 17 additions and 53 deletions
|
|
@ -3,33 +3,23 @@ import { DEFAULT_TOOL_POLICIES } from "./defaultPolicies.js";
|
|||
import { checkToolPermission } from "./permissionChecker.js";
|
||||
|
||||
describe("Headless Permissions Integration", () => {
|
||||
describe("precedence resolution with headless mode", () => {
|
||||
it("should use same default policies for both headless and normal modes", () => {
|
||||
const headlessPolicies = resolvePermissionPrecedence({
|
||||
describe("precedence resolution", () => {
|
||||
it("should use default policies", () => {
|
||||
const policies = resolvePermissionPrecedence({
|
||||
useDefaults: true,
|
||||
personalSettings: false, // Disable to avoid file system dependencies
|
||||
headless: true,
|
||||
});
|
||||
|
||||
const normalPolicies = resolvePermissionPrecedence({
|
||||
useDefaults: true,
|
||||
personalSettings: false,
|
||||
headless: false,
|
||||
});
|
||||
|
||||
expect(headlessPolicies).toEqual(DEFAULT_TOOL_POLICIES);
|
||||
expect(normalPolicies).toEqual(DEFAULT_TOOL_POLICIES);
|
||||
expect(headlessPolicies).toEqual(normalPolicies);
|
||||
expect(policies).toEqual(DEFAULT_TOOL_POLICIES);
|
||||
});
|
||||
|
||||
it("should allow CLI overrides to supersede defaults in headless mode", () => {
|
||||
it("should allow CLI overrides to supersede defaults", () => {
|
||||
const policies = resolvePermissionPrecedence({
|
||||
commandLineFlags: {
|
||||
exclude: ["dangerous_tool"],
|
||||
},
|
||||
useDefaults: true,
|
||||
personalSettings: false,
|
||||
headless: true,
|
||||
});
|
||||
|
||||
// CLI exclusion should come first
|
||||
|
|
@ -78,7 +68,7 @@ describe("Headless Permissions Integration", () => {
|
|||
|
||||
describe("real-world headless scenarios", () => {
|
||||
it("should handle typical CLI workflow with permission overrides", () => {
|
||||
// Simulate headless mode with some CLI overrides
|
||||
// Simulate CLI with some overrides
|
||||
const policies = resolvePermissionPrecedence({
|
||||
commandLineFlags: {
|
||||
// Still exclude truly dangerous operations
|
||||
|
|
@ -88,7 +78,6 @@ describe("Headless Permissions Integration", () => {
|
|||
},
|
||||
useDefaults: true,
|
||||
personalSettings: false,
|
||||
headless: true,
|
||||
});
|
||||
|
||||
const permissions = { policies };
|
||||
|
|
@ -115,7 +104,6 @@ describe("Headless Permissions Integration", () => {
|
|||
},
|
||||
useDefaults: true,
|
||||
personalSettings: false,
|
||||
headless: true,
|
||||
});
|
||||
|
||||
const permissions = { policies };
|
||||
|
|
|
|||
|
|
@ -141,26 +141,8 @@ describe("precedenceResolver", () => {
|
|||
expect(readPolicy).toBeDefined();
|
||||
});
|
||||
|
||||
describe("headless mode", () => {
|
||||
it("should use same policies for headless and normal modes", () => {
|
||||
const headlessPolicies = resolvePermissionPrecedence({
|
||||
useDefaults: true,
|
||||
personalSettings: false,
|
||||
headless: true,
|
||||
});
|
||||
|
||||
const normalPolicies = resolvePermissionPrecedence({
|
||||
useDefaults: true,
|
||||
personalSettings: false,
|
||||
headless: false,
|
||||
});
|
||||
|
||||
expect(headlessPolicies).toEqual(DEFAULT_TOOL_POLICIES);
|
||||
expect(normalPolicies).toEqual(DEFAULT_TOOL_POLICIES);
|
||||
expect(headlessPolicies).toEqual(normalPolicies);
|
||||
});
|
||||
|
||||
it("should use default policies when headless is undefined", () => {
|
||||
describe("precedence rules", () => {
|
||||
it("should use default policies when no other sources provided", () => {
|
||||
const policies = resolvePermissionPrecedence({
|
||||
useDefaults: true,
|
||||
personalSettings: false,
|
||||
|
|
@ -169,14 +151,13 @@ describe("precedenceResolver", () => {
|
|||
expect(policies).toEqual(DEFAULT_TOOL_POLICIES);
|
||||
});
|
||||
|
||||
it("should allow CLI flags to override default policies in headless mode", () => {
|
||||
it("should allow CLI flags to override default policies", () => {
|
||||
const policies = resolvePermissionPrecedence({
|
||||
commandLineFlags: {
|
||||
exclude: ["write_file"],
|
||||
},
|
||||
useDefaults: true,
|
||||
personalSettings: false,
|
||||
headless: true,
|
||||
});
|
||||
|
||||
// CLI exclusion should come first
|
||||
|
|
@ -185,7 +166,7 @@ describe("precedenceResolver", () => {
|
|||
expect(policies.slice(1)).toEqual(DEFAULT_TOOL_POLICIES);
|
||||
});
|
||||
|
||||
it("should allow config policies to override defaults in headless mode", () => {
|
||||
it("should allow config policies to override defaults", () => {
|
||||
const configPolicies: ToolPermissionPolicy[] = [
|
||||
{ tool: "run_terminal_command", permission: "allow" },
|
||||
];
|
||||
|
|
@ -194,7 +175,6 @@ describe("precedenceResolver", () => {
|
|||
configPermissions: configPolicies,
|
||||
useDefaults: true,
|
||||
personalSettings: false,
|
||||
headless: true,
|
||||
});
|
||||
|
||||
// Config policy should override default
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ export interface PermissionSources {
|
|||
personalSettings?: boolean; // Whether to load from permissions.yaml
|
||||
/** Default policies - lowest precedence */
|
||||
useDefaults?: boolean;
|
||||
/** Whether running in headless mode - affects default policies */
|
||||
headless?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -23,18 +23,16 @@ export class ToolPermissionService {
|
|||
allow?: string[];
|
||||
ask?: string[];
|
||||
exclude?: string[];
|
||||
}, headless?: boolean): ToolPermissionServiceState {
|
||||
}): ToolPermissionServiceState {
|
||||
logger.debug("Synchronously initializing ToolPermissionService", {
|
||||
hasOverrides: !!runtimeOverrides,
|
||||
headless: !!headless
|
||||
hasOverrides: !!runtimeOverrides
|
||||
});
|
||||
|
||||
// Use the precedence resolver to get properly ordered policies
|
||||
const compiledPolicies = resolvePermissionPrecedence({
|
||||
commandLineFlags: runtimeOverrides,
|
||||
personalSettings: true, // Enable loading from ~/.continue/permissions.yaml
|
||||
useDefaults: true,
|
||||
headless: headless
|
||||
useDefaults: true
|
||||
});
|
||||
|
||||
this.state = {
|
||||
|
|
@ -51,12 +49,12 @@ export class ToolPermissionService {
|
|||
allow?: string[];
|
||||
ask?: string[];
|
||||
exclude?: string[];
|
||||
}, headless?: boolean): Promise<ToolPermissionServiceState> {
|
||||
}): Promise<ToolPermissionServiceState> {
|
||||
// Ensure permissions.yaml exists before loading
|
||||
await ensurePermissionsYamlExists();
|
||||
|
||||
// Use the synchronous version after ensuring the file exists
|
||||
return this.initializeSync(runtimeOverrides, headless);
|
||||
return this.initializeSync(runtimeOverrides);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,13 +31,13 @@ export async function initializeServices(options: ServiceInitOptions = {}) {
|
|||
// Handle tool permissions specially for immediate availability
|
||||
if (options.toolPermissionOverrides) {
|
||||
// Initialize synchronously and register the value immediately
|
||||
const permissionState = toolPermissionService.initializeSync(options.toolPermissionOverrides, options.headless);
|
||||
const permissionState = toolPermissionService.initializeSync(options.toolPermissionOverrides);
|
||||
serviceContainer.registerValue(SERVICE_NAMES.TOOL_PERMISSIONS, permissionState);
|
||||
} else {
|
||||
// Register normal factory for lazy initialization
|
||||
serviceContainer.register(
|
||||
SERVICE_NAMES.TOOL_PERMISSIONS,
|
||||
() => toolPermissionService.initialize(undefined, options.headless),
|
||||
() => toolPermissionService.initialize(),
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue