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
+15 -15
View File
@@ -118,8 +118,8 @@ describe("evaluate", () => {
).toBe("ask");
});
test("last-match-wins: later conflicting rule overrides earlier", () => {
const ruleset: Ruleset = [allowBashGit, denyBashGitPush];
test("specific pattern wins even when declared before a broad match", () => {
const ruleset: Ruleset = [denyBashGitPush, allowBashGit];
const result = evaluate(
"bash",
"git push origin main",
@@ -129,7 +129,7 @@ describe("evaluate", () => {
expect(result).toEqual(denyBashGitPush);
});
test("last-match-wins: broad deny followed by specific allow", () => {
test("specific allow wins over a broad deny", () => {
const denyAll: Rule = {
surface: "bash",
pattern: "*",
@@ -236,7 +236,7 @@ describe("evaluate", () => {
expect(
evaluate("bash", "git status", [withoutLayer], posixPathFlavor).action,
).toBe("allow");
// Layer metadata does not affect last-match-wins ordering.
// Layer metadata does not affect specificity ordering.
const ruleset: Rule[] = [withDefault, withLayer];
expect(evaluate("bash", "git status", ruleset, posixPathFlavor)).toEqual(
withLayer,
@@ -245,7 +245,7 @@ describe("evaluate", () => {
const reversedRuleset: Rule[] = [withLayer, withDefault];
expect(
evaluate("bash", "git status", reversedRuleset, posixPathFlavor),
).toEqual(withDefault);
).toEqual(withLayer);
});
test("evaluate() preserves origin on a matched rule", () => {
@@ -280,7 +280,7 @@ describe("evaluate", () => {
expect(result.reason).toBe("Use pnpm instead");
});
test("evaluate() carries reason through last-match-wins when deny wins", () => {
test("evaluate() carries the reason from the most-specific deny", () => {
const allowAll: Rule = {
surface: "bash",
pattern: "*",
@@ -361,26 +361,26 @@ describe("evaluate", () => {
}
});
// ── Windows: path-surface patterns fold case (last-match-wins) ──────────
// ── Windows: path-surface patterns fold case ────────────────────────────
const denyExternalAll: Rule = {
surface: "external_directory",
surface: "path",
pattern: "*",
action: "deny",
layer: "config",
origin: "global",
};
const allowExternalPi: Rule = {
surface: "external_directory",
surface: "path",
pattern: "C:\\Users\\Foo\\pi\\*",
action: "allow",
layer: "config",
origin: "global",
};
test("win32: external_directory allow override matches a lowercased path over a preceding deny", () => {
test("win32: a specific path allow matches a lowercased value", () => {
const result = evaluate(
"external_directory",
"path",
"c:\\users\\foo\\pi\\docs\\readme.md",
[denyExternalAll, allowExternalPi],
win32PathFlavor,
@@ -390,7 +390,7 @@ describe("evaluate", () => {
test("posix: the same mixed-case override stays case-sensitive (falls through to deny)", () => {
const result = evaluate(
"external_directory",
"path",
"c:\\users\\foo\\pi\\docs\\readme.md",
[denyExternalAll, allowExternalPi],
posixPathFlavor,
@@ -398,16 +398,16 @@ describe("evaluate", () => {
expect(result.action).toBe("deny");
});
test("win32: a forward-slash external_directory pattern matches a backslash value", () => {
test("win32: a forward-slash path pattern matches a backslash value", () => {
const allowForwardSlash: Rule = {
surface: "external_directory",
surface: "path",
pattern: "C:/Users/Foo/pi/*",
action: "allow",
layer: "config",
origin: "global",
};
const result = evaluate(
"external_directory",
"path",
"c:\\users\\foo\\pi\\docs\\readme.md",
[denyExternalAll, allowForwardSlash],
win32PathFlavor,