@gotgenes/pi-permission-system 18.1.0 → 18.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/docs/assets/logo.png +0 -0
- package/docs/assets/logo.svg +213 -0
- package/docs/configuration.md +700 -0
- package/docs/cross-extension-api.md +525 -0
- package/docs/guides/permission-frontmatter-for-subagent-extensions.md +201 -0
- package/docs/guides/upstream-issue-template.md +113 -0
- package/docs/migration/legacy-to-flat.md +365 -0
- package/docs/opencode-compatibility.md +213 -0
- package/docs/session-approvals.md +68 -0
- package/docs/subagent-integration.md +102 -0
- package/docs/troubleshooting.md +53 -0
- package/package.json +5 -2
- package/src/access-intent/access-path.ts +29 -4
- package/src/access-intent/bash/bash-path-resolver.ts +39 -18
- package/src/access-intent/bash/msys-bash-tokens.ts +64 -0
- package/src/path-normalizer.ts +105 -2
- package/test/access-intent/access-path.test.ts +0 -277
- package/test/access-intent/bash/node-text.test.ts +0 -148
- package/test/access-intent/bash/parser.test.ts +0 -19
- package/test/access-intent/bash/program.test.ts +0 -673
- package/test/access-intent/bash/token-classification.test.ts +0 -363
- package/test/access-intent/bash/token-collection.test.ts +0 -300
- package/test/active-agent.test.ts +0 -155
- package/test/async-cache.test.ts +0 -48
- package/test/bash-arity.test.ts +0 -144
- package/test/bash-external-directory.test.ts +0 -1022
- package/test/builtin-tool-input-formatters.test.ts +0 -109
- package/test/canonicalize-path.test.ts +0 -119
- package/test/composition-root.test.ts +0 -698
- package/test/config-loader.test.ts +0 -740
- package/test/config-modal.test.ts +0 -320
- package/test/config-paths.test.ts +0 -83
- package/test/config-pipeline.test.ts +0 -90
- package/test/config-reporter.test.ts +0 -147
- package/test/config-store.test.ts +0 -466
- package/test/decision-audit.test.ts +0 -72
- package/test/decision-reporter.test.ts +0 -112
- package/test/denial-messages.test.ts +0 -714
- package/test/detect-permissive-bash-fallback.test.ts +0 -56
- package/test/expand-home.test.ts +0 -93
- package/test/extension-config.test.ts +0 -129
- package/test/extension-paths.test.ts +0 -108
- package/test/forwarded-permissions/io.test.ts +0 -251
- package/test/forwarding-manager.test.ts +0 -200
- package/test/handlers/before-agent-start.test.ts +0 -314
- package/test/handlers/external-directory-integration.test.ts +0 -515
- package/test/handlers/external-directory-session-dedup.test.ts +0 -175
- package/test/handlers/external-directory-symlink-acceptance.test.ts +0 -167
- package/test/handlers/gates/bash-command-metamorphic.test.ts +0 -88
- package/test/handlers/gates/bash-command.test.ts +0 -257
- package/test/handlers/gates/bash-external-directory.test.ts +0 -268
- package/test/handlers/gates/bash-path.test.ts +0 -346
- package/test/handlers/gates/candidate-check.test.ts +0 -52
- package/test/handlers/gates/external-directory-messages.test.ts +0 -85
- package/test/handlers/gates/external-directory-policy.test.ts +0 -134
- package/test/handlers/gates/external-directory.test.ts +0 -267
- package/test/handlers/gates/helpers.test.ts +0 -165
- package/test/handlers/gates/path.test.ts +0 -369
- package/test/handlers/gates/runner.test.ts +0 -408
- package/test/handlers/gates/skill-input-gate-pipeline.test.ts +0 -176
- package/test/handlers/gates/skill-input.test.ts +0 -128
- package/test/handlers/gates/skill-read.test.ts +0 -161
- package/test/handlers/gates/tool-call-gate-pipeline.test.ts +0 -356
- package/test/handlers/gates/tool.test.ts +0 -244
- package/test/handlers/input-events.test.ts +0 -168
- package/test/handlers/input.test.ts +0 -199
- package/test/handlers/lifecycle.test.ts +0 -221
- package/test/handlers/tool-call-boundary.test.ts +0 -145
- package/test/handlers/tool-call-events.test.ts +0 -277
- package/test/handlers/tool-call.test.ts +0 -395
- package/test/handlers/validate-requested-tool.test.ts +0 -92
- package/test/helpers/external-directory-fixtures.ts +0 -269
- package/test/helpers/gate-fixtures.ts +0 -316
- package/test/helpers/handler-fixtures.ts +0 -335
- package/test/helpers/make-fake-pi.ts +0 -100
- package/test/helpers/manager-harness.ts +0 -112
- package/test/helpers/session-fixtures.ts +0 -199
- package/test/input-normalizer.test.ts +0 -325
- package/test/logging.test.ts +0 -51
- package/test/mcp-targets.test.ts +0 -233
- package/test/node-modules-discovery.test.ts +0 -97
- package/test/normalize.test.ts +0 -247
- package/test/path-containment.test.ts +0 -161
- package/test/path-normalization.test.ts +0 -233
- package/test/path-normalizer.test.ts +0 -196
- package/test/path-surfaces.test.ts +0 -55
- package/test/pattern-suggest.test.ts +0 -248
- package/test/permission-dialog.test.ts +0 -205
- package/test/permission-event-rpc.test.ts +0 -560
- package/test/permission-events.test.ts +0 -400
- package/test/permission-forwarder.test.ts +0 -370
- package/test/permission-forwarding.test.ts +0 -315
- package/test/permission-gate.test.ts +0 -269
- package/test/permission-manager-unified.test.ts +0 -3714
- package/test/permission-merge.test.ts +0 -61
- package/test/permission-prompter.test.ts +0 -518
- package/test/permission-prompts.test.ts +0 -363
- package/test/permission-resolver.test.ts +0 -277
- package/test/permission-session.test.ts +0 -404
- package/test/permission-ui-prompt.test.ts +0 -146
- package/test/permissions-service.test.ts +0 -192
- package/test/pi-infrastructure-read.test.ts +0 -432
- package/test/policy-loader.test.ts +0 -561
- package/test/prompting-gateway.test.ts +0 -231
- package/test/rule.test.ts +0 -650
- package/test/safe-system-paths.test.ts +0 -46
- package/test/scope-merge.test.ts +0 -116
- package/test/service-lifecycle.test.ts +0 -163
- package/test/service.test.ts +0 -261
- package/test/session-approval.test.ts +0 -75
- package/test/session-logger.test.ts +0 -200
- package/test/session-rules.test.ts +0 -321
- package/test/session-start.test.ts +0 -112
- package/test/skill-prompt-sanitizer.test.ts +0 -418
- package/test/status.test.ts +0 -10
- package/test/subagent-context.test.ts +0 -372
- package/test/subagent-lifecycle-events.test.ts +0 -132
- package/test/subagent-registry.test.ts +0 -145
- package/test/synthesize.test.ts +0 -302
- package/test/system-prompt-sanitizer.test.ts +0 -382
- package/test/tool-access-extractor-registry.test.ts +0 -77
- package/test/tool-input-formatter-registry.test.ts +0 -75
- package/test/tool-input-path.test.ts +0 -84
- package/test/tool-input-preview.test.ts +0 -129
- package/test/tool-input-prompt-formatters.test.ts +0 -115
- package/test/tool-preview-formatter.test.ts +0 -458
- package/test/tool-registry.test.ts +0 -197
- package/test/value-guards.test.ts +0 -193
- package/test/wildcard-matcher.test.ts +0 -424
- package/test/yaml-frontmatter.test.ts +0 -91
- package/test/yolo-mode.test.ts +0 -188
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, test } from "vitest";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
getNonEmptyString,
|
|
5
|
-
isDenyWithReason,
|
|
6
|
-
isPermissionState,
|
|
7
|
-
normalizeOptionalPositiveInt,
|
|
8
|
-
normalizeOptionalStringArray,
|
|
9
|
-
toRecord,
|
|
10
|
-
} from "#src/value-guards";
|
|
11
|
-
|
|
12
|
-
describe("toRecord", () => {
|
|
13
|
-
test("returns empty object for null", () => {
|
|
14
|
-
expect(toRecord(null)).toEqual({});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test("returns empty object for undefined", () => {
|
|
18
|
-
expect(toRecord(undefined)).toEqual({});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("returns empty object for a string", () => {
|
|
22
|
-
expect(toRecord("hello")).toEqual({});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("returns empty object for a number", () => {
|
|
26
|
-
expect(toRecord(42)).toEqual({});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("returns empty object for an array", () => {
|
|
30
|
-
expect(toRecord(["a", "b"])).toEqual({});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("returns the object itself for a plain object", () => {
|
|
34
|
-
const input = { a: 1, b: "two" };
|
|
35
|
-
expect(toRecord(input)).toBe(input);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("returns the object for a nested object", () => {
|
|
39
|
-
const input = { x: { y: 3 } };
|
|
40
|
-
expect(toRecord(input)).toBe(input);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("getNonEmptyString", () => {
|
|
45
|
-
test("returns null for non-string values", () => {
|
|
46
|
-
expect(getNonEmptyString(null)).toBeNull();
|
|
47
|
-
expect(getNonEmptyString(undefined)).toBeNull();
|
|
48
|
-
expect(getNonEmptyString(42)).toBeNull();
|
|
49
|
-
expect(getNonEmptyString({})).toBeNull();
|
|
50
|
-
expect(getNonEmptyString([])).toBeNull();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("returns null for empty string", () => {
|
|
54
|
-
expect(getNonEmptyString("")).toBeNull();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("returns null for whitespace-only string", () => {
|
|
58
|
-
expect(getNonEmptyString(" ")).toBeNull();
|
|
59
|
-
expect(getNonEmptyString("\t\n")).toBeNull();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("returns trimmed string for valid string", () => {
|
|
63
|
-
expect(getNonEmptyString("hello")).toBe("hello");
|
|
64
|
-
expect(getNonEmptyString(" hello ")).toBe("hello");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test("returns single non-whitespace character", () => {
|
|
68
|
-
expect(getNonEmptyString("a")).toBe("a");
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("isPermissionState", () => {
|
|
73
|
-
test("returns true for 'allow'", () => {
|
|
74
|
-
expect(isPermissionState("allow")).toBe(true);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("returns true for 'deny'", () => {
|
|
78
|
-
expect(isPermissionState("deny")).toBe(true);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("returns true for 'ask'", () => {
|
|
82
|
-
expect(isPermissionState("ask")).toBe(true);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("returns false for unrecognized strings", () => {
|
|
86
|
-
expect(isPermissionState("ALLOW")).toBe(false);
|
|
87
|
-
expect(isPermissionState("permit")).toBe(false);
|
|
88
|
-
expect(isPermissionState("")).toBe(false);
|
|
89
|
-
expect(isPermissionState("block")).toBe(false);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("returns false for non-string types", () => {
|
|
93
|
-
expect(isPermissionState(null)).toBe(false);
|
|
94
|
-
expect(isPermissionState(undefined)).toBe(false);
|
|
95
|
-
expect(isPermissionState(1)).toBe(false);
|
|
96
|
-
expect(isPermissionState({})).toBe(false);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("isDenyWithReason", () => {
|
|
101
|
-
test("returns true for { action: 'deny' } without a reason", () => {
|
|
102
|
-
expect(isDenyWithReason({ action: "deny" })).toBe(true);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("returns true for { action: 'deny', reason: '...' }", () => {
|
|
106
|
-
expect(isDenyWithReason({ action: "deny", reason: "Use pnpm" })).toBe(true);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("returns false for non-deny actions", () => {
|
|
110
|
-
expect(isDenyWithReason({ action: "allow" })).toBe(false);
|
|
111
|
-
expect(isDenyWithReason({ action: "ask" })).toBe(false);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test("returns false for a non-string reason", () => {
|
|
115
|
-
expect(isDenyWithReason({ action: "deny", reason: 42 })).toBe(false);
|
|
116
|
-
expect(isDenyWithReason({ action: "deny", reason: null })).toBe(false);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test("returns false for non-object types", () => {
|
|
120
|
-
expect(isDenyWithReason(null)).toBe(false);
|
|
121
|
-
expect(isDenyWithReason(undefined)).toBe(false);
|
|
122
|
-
expect(isDenyWithReason("deny")).toBe(false);
|
|
123
|
-
expect(isDenyWithReason(["deny"])).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("normalizeOptionalStringArray", () => {
|
|
128
|
-
it("returns the array for a valid string array", () => {
|
|
129
|
-
expect(normalizeOptionalStringArray(["a", "b", "c"])).toEqual([
|
|
130
|
-
"a",
|
|
131
|
-
"b",
|
|
132
|
-
"c",
|
|
133
|
-
]);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("returns an empty array for an empty array", () => {
|
|
137
|
-
expect(normalizeOptionalStringArray([])).toEqual([]);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("returns undefined for a plain string", () => {
|
|
141
|
-
expect(normalizeOptionalStringArray("x")).toBeUndefined();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("returns undefined for a number", () => {
|
|
145
|
-
expect(normalizeOptionalStringArray(42)).toBeUndefined();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("returns undefined for a plain object", () => {
|
|
149
|
-
expect(normalizeOptionalStringArray({ a: "b" })).toBeUndefined();
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("returns undefined for a mixed-type array", () => {
|
|
153
|
-
expect(normalizeOptionalStringArray(["a", 1])).toBeUndefined();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("returns undefined for undefined", () => {
|
|
157
|
-
expect(normalizeOptionalStringArray(undefined)).toBeUndefined();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it("returns undefined for null", () => {
|
|
161
|
-
expect(normalizeOptionalStringArray(null)).toBeUndefined();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
describe("normalizeOptionalPositiveInt", () => {
|
|
166
|
-
it("returns the value for a valid positive integer", () => {
|
|
167
|
-
expect(normalizeOptionalPositiveInt(1)).toBe(1);
|
|
168
|
-
expect(normalizeOptionalPositiveInt(200)).toBe(200);
|
|
169
|
-
expect(normalizeOptionalPositiveInt(9999)).toBe(9999);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("returns undefined for zero", () => {
|
|
173
|
-
expect(normalizeOptionalPositiveInt(0)).toBeUndefined();
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("returns undefined for negative integers", () => {
|
|
177
|
-
expect(normalizeOptionalPositiveInt(-1)).toBeUndefined();
|
|
178
|
-
expect(normalizeOptionalPositiveInt(-100)).toBeUndefined();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("returns undefined for non-integer numbers (floats)", () => {
|
|
182
|
-
expect(normalizeOptionalPositiveInt(400.5)).toBeUndefined();
|
|
183
|
-
expect(normalizeOptionalPositiveInt(1.1)).toBeUndefined();
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("returns undefined for non-number types", () => {
|
|
187
|
-
expect(normalizeOptionalPositiveInt("200")).toBeUndefined();
|
|
188
|
-
expect(normalizeOptionalPositiveInt(true)).toBeUndefined();
|
|
189
|
-
expect(normalizeOptionalPositiveInt(null)).toBeUndefined();
|
|
190
|
-
expect(normalizeOptionalPositiveInt(undefined)).toBeUndefined();
|
|
191
|
-
expect(normalizeOptionalPositiveInt({})).toBeUndefined();
|
|
192
|
-
});
|
|
193
|
-
});
|
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
3
|
-
|
|
4
|
-
const mockHomedir = vi.hoisted(() => vi.fn(() => "/home/testuser"));
|
|
5
|
-
|
|
6
|
-
vi.mock("node:os", () => ({
|
|
7
|
-
homedir: mockHomedir,
|
|
8
|
-
default: { homedir: mockHomedir },
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
const FAKE_HOME = "/home/testuser";
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
compileWildcardPattern,
|
|
15
|
-
compileWildcardPatternEntries,
|
|
16
|
-
findCompiledWildcardMatch,
|
|
17
|
-
findCompiledWildcardMatchForNames,
|
|
18
|
-
wildcardMatch,
|
|
19
|
-
} from "#src/wildcard-matcher";
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
mockHomedir.mockClear();
|
|
23
|
-
vi.restoreAllMocks();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe("compileWildcardPatternEntries", () => {
|
|
27
|
-
test("returns empty array for empty iterable", () => {
|
|
28
|
-
const result = compileWildcardPatternEntries([]);
|
|
29
|
-
expect(result).toEqual([]);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("compiles a single exact pattern", () => {
|
|
33
|
-
const result = compileWildcardPatternEntries([["read", "allow"]]);
|
|
34
|
-
expect(result).toHaveLength(1);
|
|
35
|
-
expect(result[0].pattern).toBe("read");
|
|
36
|
-
expect(result[0].state).toBe("allow");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("compiles multiple patterns in order", () => {
|
|
40
|
-
const entries: [string, string][] = [
|
|
41
|
-
["read", "allow"],
|
|
42
|
-
["write", "deny"],
|
|
43
|
-
["bash *", "ask"],
|
|
44
|
-
];
|
|
45
|
-
const result = compileWildcardPatternEntries(entries);
|
|
46
|
-
expect(result).toHaveLength(3);
|
|
47
|
-
expect(result.map((r) => r.pattern)).toEqual(["read", "write", "bash *"]);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe("findCompiledWildcardMatch", () => {
|
|
52
|
-
test("returns null for empty patterns array", () => {
|
|
53
|
-
const result = findCompiledWildcardMatch([], "read");
|
|
54
|
-
expect(result).toBeNull();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("matches exact pattern", () => {
|
|
58
|
-
const patterns = compileWildcardPatternEntries([["read", "allow"]]);
|
|
59
|
-
const result = findCompiledWildcardMatch(patterns, "read");
|
|
60
|
-
expect(result).not.toBeNull();
|
|
61
|
-
expect(result?.state).toBe("allow");
|
|
62
|
-
expect(result?.matchedPattern).toBe("read");
|
|
63
|
-
expect(result?.matchedName).toBe("read");
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("returns null when no pattern matches", () => {
|
|
67
|
-
const patterns = compileWildcardPatternEntries([["read", "allow"]]);
|
|
68
|
-
const result = findCompiledWildcardMatch(patterns, "write");
|
|
69
|
-
expect(result).toBeNull();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("matches glob * pattern", () => {
|
|
73
|
-
const patterns = compileWildcardPatternEntries([["git *", "allow"]]);
|
|
74
|
-
const result = findCompiledWildcardMatch(patterns, "git status");
|
|
75
|
-
expect(result).not.toBeNull();
|
|
76
|
-
expect(result?.state).toBe("allow");
|
|
77
|
-
expect(result?.matchedPattern).toBe("git *");
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("glob * matches zero or more characters", () => {
|
|
81
|
-
const patterns = compileWildcardPatternEntries([["git*", "allow"]]);
|
|
82
|
-
expect(findCompiledWildcardMatch(patterns, "git")).not.toBeNull();
|
|
83
|
-
expect(findCompiledWildcardMatch(patterns, "git status")).not.toBeNull();
|
|
84
|
-
expect(findCompiledWildcardMatch(patterns, "npm install")).toBeNull();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("last-match-wins precedence: later pattern overrides earlier", () => {
|
|
88
|
-
const patterns = compileWildcardPatternEntries([
|
|
89
|
-
["git *", "allow"],
|
|
90
|
-
["git push *", "deny"],
|
|
91
|
-
]);
|
|
92
|
-
const result = findCompiledWildcardMatch(patterns, "git push origin main");
|
|
93
|
-
expect(result).not.toBeNull();
|
|
94
|
-
expect(result?.state).toBe("deny");
|
|
95
|
-
expect(result?.matchedPattern).toBe("git push *");
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("last-match-wins: specific deny before broad allow matches the later one", () => {
|
|
99
|
-
const patterns = compileWildcardPatternEntries([
|
|
100
|
-
["*", "deny"],
|
|
101
|
-
["git status", "allow"],
|
|
102
|
-
]);
|
|
103
|
-
const result = findCompiledWildcardMatch(patterns, "git status");
|
|
104
|
-
expect(result).not.toBeNull();
|
|
105
|
-
expect(result?.state).toBe("allow");
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("exact pattern does not match partial name", () => {
|
|
109
|
-
const patterns = compileWildcardPatternEntries([["read", "allow"]]);
|
|
110
|
-
expect(findCompiledWildcardMatch(patterns, "read ")).toBeNull();
|
|
111
|
-
expect(findCompiledWildcardMatch(patterns, "readonly")).toBeNull();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test("regex special characters in pattern are escaped", () => {
|
|
115
|
-
const patterns = compileWildcardPatternEntries([
|
|
116
|
-
["tool.name", "allow"],
|
|
117
|
-
["tool+extra", "deny"],
|
|
118
|
-
]);
|
|
119
|
-
// "tool.name" should not match "toolXname" (dot is escaped)
|
|
120
|
-
expect(findCompiledWildcardMatch(patterns, "toolXname")).toBeNull();
|
|
121
|
-
// Exact match works
|
|
122
|
-
expect(findCompiledWildcardMatch(patterns, "tool.name")).not.toBeNull();
|
|
123
|
-
expect(findCompiledWildcardMatch(patterns, "tool+extra")).not.toBeNull();
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("findCompiledWildcardMatchForNames", () => {
|
|
128
|
-
test("returns null for empty names array", () => {
|
|
129
|
-
const patterns = compileWildcardPatternEntries([["read", "allow"]]);
|
|
130
|
-
const result = findCompiledWildcardMatchForNames(patterns, []);
|
|
131
|
-
expect(result).toBeNull();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("returns null when all names are whitespace", () => {
|
|
135
|
-
const patterns = compileWildcardPatternEntries([[" ", "allow"]]);
|
|
136
|
-
const result = findCompiledWildcardMatchForNames(patterns, [" ", "\t"]);
|
|
137
|
-
expect(result).toBeNull();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test("matches first name that has a pattern match", () => {
|
|
141
|
-
const patterns = compileWildcardPatternEntries([
|
|
142
|
-
["read", "allow"],
|
|
143
|
-
["write", "deny"],
|
|
144
|
-
]);
|
|
145
|
-
const result = findCompiledWildcardMatchForNames(patterns, [
|
|
146
|
-
"grep",
|
|
147
|
-
"write",
|
|
148
|
-
]);
|
|
149
|
-
expect(result).not.toBeNull();
|
|
150
|
-
expect(result?.matchedName).toBe("write");
|
|
151
|
-
expect(result?.state).toBe("deny");
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("trims whitespace from names before matching", () => {
|
|
155
|
-
const patterns = compileWildcardPatternEntries([["read", "allow"]]);
|
|
156
|
-
const result = findCompiledWildcardMatchForNames(patterns, [" read "]);
|
|
157
|
-
expect(result).not.toBeNull();
|
|
158
|
-
expect(result?.state).toBe("allow");
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test("returns null when no name matches any pattern", () => {
|
|
162
|
-
const patterns = compileWildcardPatternEntries([["read", "allow"]]);
|
|
163
|
-
const result = findCompiledWildcardMatchForNames(patterns, [
|
|
164
|
-
"write",
|
|
165
|
-
"grep",
|
|
166
|
-
]);
|
|
167
|
-
expect(result).toBeNull();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
test("multi-name lookup: returns match for first matching name in order", () => {
|
|
171
|
-
const patterns = compileWildcardPatternEntries([
|
|
172
|
-
["read", "allow"],
|
|
173
|
-
["write", "deny"],
|
|
174
|
-
]);
|
|
175
|
-
// "read" comes before "write" in names array, so "read" should match first
|
|
176
|
-
const result = findCompiledWildcardMatchForNames(patterns, [
|
|
177
|
-
"read",
|
|
178
|
-
"write",
|
|
179
|
-
]);
|
|
180
|
-
expect(result).not.toBeNull();
|
|
181
|
-
expect(result?.matchedName).toBe("read");
|
|
182
|
-
expect(result?.state).toBe("allow");
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
test("compileWildcardPattern produces correct pattern metadata", () => {
|
|
186
|
-
const compiled = compileWildcardPattern("bash *", "ask");
|
|
187
|
-
expect(compiled.pattern).toBe("bash *");
|
|
188
|
-
expect(compiled.state).toBe("ask");
|
|
189
|
-
expect(compiled.regex.test("bash ls -la")).toBe(true);
|
|
190
|
-
expect(compiled.regex.test("echo hello")).toBe(false);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe("wildcardMatch", () => {
|
|
195
|
-
test("'*' pattern matches any value", () => {
|
|
196
|
-
expect(wildcardMatch("*", "anything")).toBe(true);
|
|
197
|
-
expect(wildcardMatch("*", "")).toBe(true);
|
|
198
|
-
expect(wildcardMatch("*", "bash")).toBe(true);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
test("'*' pattern matches values containing newlines", () => {
|
|
202
|
-
expect(wildcardMatch("*", "line1\nline2")).toBe(true);
|
|
203
|
-
expect(wildcardMatch("*", "a\nb\nc")).toBe(true);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test("prefix-wildcard pattern matches value with embedded newlines", () => {
|
|
207
|
-
const command =
|
|
208
|
-
"node -e \"\nimport('x').then(() => {\n console.log('done');\n});\n\"";
|
|
209
|
-
expect(wildcardMatch("node *", command)).toBe(true);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test("compileWildcardPattern regex matches multiline string", () => {
|
|
213
|
-
const compiled = compileWildcardPattern("*", "allow");
|
|
214
|
-
expect(compiled.regex.test("a\nb")).toBe(true);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
test("exact pattern matches identical value", () => {
|
|
218
|
-
expect(wildcardMatch("read", "read")).toBe(true);
|
|
219
|
-
expect(wildcardMatch("external_directory", "external_directory")).toBe(
|
|
220
|
-
true,
|
|
221
|
-
);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test("exact pattern does not match a different value", () => {
|
|
225
|
-
expect(wildcardMatch("read", "write")).toBe(false);
|
|
226
|
-
expect(wildcardMatch("read", "readonly")).toBe(false);
|
|
227
|
-
expect(wildcardMatch("read", "read ")).toBe(false);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
test("glob pattern matches with wildcard", () => {
|
|
231
|
-
expect(wildcardMatch("git *", "git status")).toBe(true);
|
|
232
|
-
expect(wildcardMatch("git *", "git push origin main")).toBe(true);
|
|
233
|
-
expect(wildcardMatch("git *", "npm install")).toBe(false);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
test("glob with no trailing space matches longer string", () => {
|
|
237
|
-
expect(wildcardMatch("git*", "git")).toBe(true);
|
|
238
|
-
expect(wildcardMatch("git*", "git status")).toBe(true);
|
|
239
|
-
expect(wildcardMatch("git*", "npm")).toBe(false);
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
test("regex special characters in pattern are treated as literals", () => {
|
|
243
|
-
expect(wildcardMatch("tool.name", "tool.name")).toBe(true);
|
|
244
|
-
expect(wildcardMatch("tool.name", "toolXname")).toBe(false);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
describe("trailing wildcard optionality", () => {
|
|
248
|
-
test("'git *' matches bare 'git' (trailing space+wildcard is optional)", () => {
|
|
249
|
-
expect(wildcardMatch("git *", "git")).toBe(true);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
test("'git *' still matches 'git status' (existing behaviour preserved)", () => {
|
|
253
|
-
expect(wildcardMatch("git *", "git status")).toBe(true);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test("'git *' still matches 'git status --short'", () => {
|
|
257
|
-
expect(wildcardMatch("git *", "git status --short")).toBe(true);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
test("'git *' does not match an unrelated command", () => {
|
|
261
|
-
expect(wildcardMatch("git *", "npm install")).toBe(false);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
test("'git status *' matches bare 'git status'", () => {
|
|
265
|
-
expect(wildcardMatch("git status *", "git status")).toBe(true);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
test("'git status *' matches 'git status --short'", () => {
|
|
269
|
-
expect(wildcardMatch("git status *", "git status --short")).toBe(true);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
test("non-trailing '*' is unaffected: 'g*t' does not match 'g' or 't'", () => {
|
|
273
|
-
expect(wildcardMatch("g*t", "g")).toBe(false);
|
|
274
|
-
expect(wildcardMatch("g*t", "t")).toBe(false);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
test("non-trailing '*' still matches when content is present: 'g*t' matches 'git'", () => {
|
|
278
|
-
expect(wildcardMatch("g*t", "git")).toBe(true);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
test("'git*' (no space) still matches bare 'git' — unchanged behaviour", () => {
|
|
282
|
-
expect(wildcardMatch("git*", "git")).toBe(true);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
test("'*' alone still matches everything", () => {
|
|
286
|
-
expect(wildcardMatch("*", "git")).toBe(true);
|
|
287
|
-
expect(wildcardMatch("*", "")).toBe(true);
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
describe("match options (Windows path folding)", () => {
|
|
292
|
-
test("caseInsensitive matches a value differing only in case", () => {
|
|
293
|
-
expect(
|
|
294
|
-
wildcardMatch("C:\\Users\\Foo\\*", "c:\\users\\foo\\bar.md", {
|
|
295
|
-
caseInsensitive: true,
|
|
296
|
-
}),
|
|
297
|
-
).toBe(true);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
test("case folding is off by default", () => {
|
|
301
|
-
expect(wildcardMatch("C:\\Users\\Foo\\*", "c:\\users\\foo\\bar.md")).toBe(
|
|
302
|
-
false,
|
|
303
|
-
);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
test("windowsSeparators matches a backslash value against a forward-slash pattern", () => {
|
|
307
|
-
expect(
|
|
308
|
-
wildcardMatch("C:/Users/Foo/*", "C:\\Users\\Foo\\bar.md", {
|
|
309
|
-
windowsSeparators: true,
|
|
310
|
-
}),
|
|
311
|
-
).toBe(true);
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
test("separator normalization is off by default", () => {
|
|
315
|
-
expect(wildcardMatch("C:/Users/Foo/*", "C:\\Users\\Foo\\bar.md")).toBe(
|
|
316
|
-
false,
|
|
317
|
-
);
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
test("both options fold a mixed-case forward-slash pattern onto a lowercased backslash value", () => {
|
|
321
|
-
expect(
|
|
322
|
-
wildcardMatch(
|
|
323
|
-
"C:/Users/Foo/AppData/Roaming/*",
|
|
324
|
-
"c:\\users\\foo\\appdata\\roaming\\npm\\x.md",
|
|
325
|
-
{ caseInsensitive: true, windowsSeparators: true },
|
|
326
|
-
),
|
|
327
|
-
).toBe(true);
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
describe("? single-character wildcard", () => {
|
|
333
|
-
test("'?' matches exactly one character", () => {
|
|
334
|
-
expect(wildcardMatch("?", "a")).toBe(true);
|
|
335
|
-
expect(wildcardMatch("?", "Z")).toBe(true);
|
|
336
|
-
expect(wildcardMatch("?", "5")).toBe(true);
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
test("'?' does not match zero characters", () => {
|
|
340
|
-
expect(wildcardMatch("?", "")).toBe(false);
|
|
341
|
-
expect(wildcardMatch("a?", "a")).toBe(false);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
test("'?' does not match two or more characters", () => {
|
|
345
|
-
expect(wildcardMatch("?", "ab")).toBe(false);
|
|
346
|
-
expect(wildcardMatch("?", "abc")).toBe(false);
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
test("multiple '?' match exactly that many characters", () => {
|
|
350
|
-
expect(wildcardMatch("f??", "foo")).toBe(true);
|
|
351
|
-
expect(wildcardMatch("f??", "fo")).toBe(false);
|
|
352
|
-
expect(wildcardMatch("f??", "fooo")).toBe(false);
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
test("'?' combined with '*'", () => {
|
|
356
|
-
// git + one char + anything
|
|
357
|
-
expect(wildcardMatch("git?*", "git status")).toBe(true);
|
|
358
|
-
// git + zero chars — '?' requires one
|
|
359
|
-
expect(wildcardMatch("git?*", "git")).toBe(false);
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
test("'?' matches path separators and special characters", () => {
|
|
363
|
-
expect(wildcardMatch("a?b", "a/b")).toBe(true);
|
|
364
|
-
expect(wildcardMatch("a?b", "a.b")).toBe(true);
|
|
365
|
-
expect(wildcardMatch("a?b", "a\nb")).toBe(true);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
test("'?' in pattern matches literal '?' in value", () => {
|
|
369
|
-
expect(wildcardMatch("a?c", "a?c")).toBe(true);
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
test("'?' in bash-style patterns", () => {
|
|
373
|
-
expect(wildcardMatch("git statu?", "git status")).toBe(true);
|
|
374
|
-
expect(wildcardMatch("git statu?", "git statux")).toBe(true);
|
|
375
|
-
expect(wildcardMatch("git statu?", "git statu")).toBe(false);
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
describe("home path expansion in patterns", () => {
|
|
380
|
-
test("wildcardMatch expands ~ prefix in pattern before matching", () => {
|
|
381
|
-
const expandedPath = join(FAKE_HOME, "dev/project");
|
|
382
|
-
expect(wildcardMatch("~/dev/project", expandedPath)).toBe(true);
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
test("wildcardMatch expands ~/glob in pattern", () => {
|
|
386
|
-
const expandedFile = join(FAKE_HOME, "dev/project/file.ts");
|
|
387
|
-
expect(wildcardMatch("~/dev/*", expandedFile)).toBe(true);
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
test("wildcardMatch ~/glob does not match a different home directory", () => {
|
|
391
|
-
expect(wildcardMatch("~/dev/*", "/other/user/dev/file.ts")).toBe(false);
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
test("wildcardMatch expands $HOME prefix in pattern before matching", () => {
|
|
395
|
-
const expandedPath = join(FAKE_HOME, "dev/project");
|
|
396
|
-
expect(wildcardMatch("$HOME/dev/project", expandedPath)).toBe(true);
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
test("wildcardMatch expands $HOME/glob in pattern", () => {
|
|
400
|
-
const expandedFile = join(FAKE_HOME, "work/file.ts");
|
|
401
|
-
expect(wildcardMatch("$HOME/work/*", expandedFile)).toBe(true);
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
test("compileWildcardPattern retains original ~ pattern in .pattern field", () => {
|
|
405
|
-
const compiled = compileWildcardPattern("~/dev/*", "allow");
|
|
406
|
-
expect(compiled.pattern).toBe("~/dev/*");
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
test("compileWildcardPattern retains original $HOME pattern in .pattern field", () => {
|
|
410
|
-
const compiled = compileWildcardPattern("$HOME/dev/*", "allow");
|
|
411
|
-
expect(compiled.pattern).toBe("$HOME/dev/*");
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
test("compileWildcardPattern expanded regex matches the expanded path", () => {
|
|
415
|
-
const compiled = compileWildcardPattern("~/dev/*", "allow");
|
|
416
|
-
const expandedFile = join(FAKE_HOME, "dev/file.ts");
|
|
417
|
-
expect(compiled.regex.test(expandedFile)).toBe(true);
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
test("non-home pattern is unaffected", () => {
|
|
421
|
-
expect(wildcardMatch("/absolute/path/*", "/absolute/path/file")).toBe(true);
|
|
422
|
-
expect(wildcardMatch("/absolute/path/*", "/other/file")).toBe(false);
|
|
423
|
-
});
|
|
424
|
-
});
|