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
@@ -78,70 +78,6 @@ describe("FilePolicyLoader.loadGlobalConfig", () => {
});
});
// ---------------------------------------------------------------------------
// loadProjectConfig
// ---------------------------------------------------------------------------
describe("FilePolicyLoader.loadProjectConfig", () => {
it("returns empty ScopeConfig when no project path is configured", () => {
const loader = new FilePolicyLoader({
globalConfigPath: "/nonexistent/config.json",
agentsDir: "/nonexistent/agents",
});
const config = loader.loadProjectConfig();
expect(config).toEqual({});
});
it("returns ScopeConfig from a project config file", () => {
const baseDir = makeTempDir();
try {
const projectConfigPath = join(baseDir, "project-config.json");
writeFileSync(
projectConfigPath,
JSON.stringify({ permission: { bash: "allow" } }),
);
const loader = new FilePolicyLoader({
globalConfigPath: "/nonexistent/config.json",
agentsDir: "/nonexistent/agents",
projectGlobalConfigPath: projectConfigPath,
});
const config = loader.loadProjectConfig();
expect(config.permission).toEqual({ bash: "allow" });
expect(config.invalid).toBeUndefined();
} finally {
rmSync(baseDir, { recursive: true, force: true });
}
});
it("marks the scope invalid when the project config file is rejected", () => {
const baseDir = makeTempDir();
try {
const projectConfigPath = join(baseDir, "project-config.json");
// Unrecognized key — schema rejection, the issue's "typo" scenario.
writeFileSync(projectConfigPath, JSON.stringify({ debugLo: true }));
const loader = new FilePolicyLoader({
globalConfigPath: "/nonexistent/config.json",
agentsDir: "/nonexistent/agents",
projectGlobalConfigPath: projectConfigPath,
});
const config = loader.loadProjectConfig();
expect(config.invalid).toBe(true);
} finally {
rmSync(baseDir, { recursive: true, force: true });
}
});
it("leaves invalid unset when no project file is present", () => {
const loader = new FilePolicyLoader({
globalConfigPath: "/nonexistent/config.json",
agentsDir: "/nonexistent/agents",
projectGlobalConfigPath: "/nonexistent/project-config.json",
});
const config = loader.loadProjectConfig();
expect(config.invalid).toBeUndefined();
});
});
// ---------------------------------------------------------------------------
// loadAgentConfig / loadProjectAgentConfig
// ---------------------------------------------------------------------------
@@ -270,8 +206,6 @@ describe("FilePolicyLoader.getResolvedPolicyPaths", () => {
expect(paths.globalConfigExists).toBe(true);
expect(paths.agentsDir).toBe(agentsDir);
expect(paths.agentsDirExists).toBe(true);
expect(paths.projectConfigPath).toBeNull();
expect(paths.projectConfigExists).toBe(false);
expect(paths.projectAgentsDir).toBeNull();
expect(paths.projectAgentsDirExists).toBe(false);
} finally {