refactor(permission-system): simplify policy and autoreview flow

This commit is contained in:
云服务部-叶林立
2026-09-03 02:01:06 +08:00
parent 180da95ab7
commit 6e7effa792
112 changed files with 911 additions and 10346 deletions
@@ -13,12 +13,10 @@ import { createInMemoryPolicyLoader } from "#test/helpers/manager-harness";
function makeManager(
global: Record<string, unknown>,
isYoloEnabled: () => boolean,
project?: ScopeConfig,
): PermissionManager {
return new PermissionManager({
policyLoader: createInMemoryPolicyLoader({
global: { permission: global } as ScopeConfig,
project,
}),
isYoloEnabled,
});
@@ -95,34 +93,3 @@ describe("PermissionManager yolo rewrite", () => {
expect(manager.getToolPermission("bash")).toBe("ask");
});
});
describe("PermissionManager fail-closed clamp under yolo (#646)", () => {
it("yolo re-permits a fail-closed floored allow (allow→ask→allow)", () => {
// Invalid project scope floors global's `allow` to `ask` at composition;
// yolo then rewrites the `ask` back to `allow`. yolo is an explicit
// full-permissive opt-in, so yolo users are unaffected by the clamp.
const manager = makeManager({ bash: "allow" }, () => true, {
invalid: true,
});
const result = manager.check({
kind: "tool",
surface: "bash",
input: { command: "echo hi" },
});
expect(result.state).toBe("allow");
expect(result.origin).toBe("yolo");
});
it("preserves a hard deny under yolo even with an invalid scope", () => {
const manager = makeManager({ bash: "deny" }, () => true, {
invalid: true,
});
const result = manager.check({
kind: "tool",
surface: "bash",
input: { command: "rm -rf /" },
});
expect(result.state).toBe("deny");
expect(result.origin).not.toBe("yolo");
});
});