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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user