mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
refactor(permission-system): simplify policy and autoreview flow
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user