@gotgenes/pi-permission-system 18.1.1 → 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.
Files changed (122) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/docs/configuration.md +11 -0
  3. package/package.json +1 -2
  4. package/src/access-intent/access-path.ts +29 -4
  5. package/src/access-intent/bash/bash-path-resolver.ts +39 -18
  6. package/src/access-intent/bash/msys-bash-tokens.ts +64 -0
  7. package/src/path-normalizer.ts +105 -2
  8. package/test/access-intent/access-path.test.ts +0 -277
  9. package/test/access-intent/bash/node-text.test.ts +0 -148
  10. package/test/access-intent/bash/parser.test.ts +0 -19
  11. package/test/access-intent/bash/program.test.ts +0 -673
  12. package/test/access-intent/bash/token-classification.test.ts +0 -363
  13. package/test/access-intent/bash/token-collection.test.ts +0 -300
  14. package/test/active-agent.test.ts +0 -155
  15. package/test/async-cache.test.ts +0 -48
  16. package/test/bash-arity.test.ts +0 -144
  17. package/test/bash-external-directory.test.ts +0 -1022
  18. package/test/builtin-tool-input-formatters.test.ts +0 -109
  19. package/test/canonicalize-path.test.ts +0 -119
  20. package/test/composition-root.test.ts +0 -698
  21. package/test/config-loader.test.ts +0 -740
  22. package/test/config-modal.test.ts +0 -320
  23. package/test/config-paths.test.ts +0 -83
  24. package/test/config-pipeline.test.ts +0 -90
  25. package/test/config-reporter.test.ts +0 -147
  26. package/test/config-store.test.ts +0 -466
  27. package/test/decision-audit.test.ts +0 -72
  28. package/test/decision-reporter.test.ts +0 -112
  29. package/test/denial-messages.test.ts +0 -714
  30. package/test/detect-permissive-bash-fallback.test.ts +0 -56
  31. package/test/expand-home.test.ts +0 -93
  32. package/test/extension-config.test.ts +0 -129
  33. package/test/extension-paths.test.ts +0 -108
  34. package/test/forwarded-permissions/io.test.ts +0 -251
  35. package/test/forwarding-manager.test.ts +0 -200
  36. package/test/handlers/before-agent-start.test.ts +0 -314
  37. package/test/handlers/external-directory-integration.test.ts +0 -515
  38. package/test/handlers/external-directory-session-dedup.test.ts +0 -175
  39. package/test/handlers/external-directory-symlink-acceptance.test.ts +0 -167
  40. package/test/handlers/gates/bash-command-metamorphic.test.ts +0 -88
  41. package/test/handlers/gates/bash-command.test.ts +0 -257
  42. package/test/handlers/gates/bash-external-directory.test.ts +0 -268
  43. package/test/handlers/gates/bash-path.test.ts +0 -346
  44. package/test/handlers/gates/candidate-check.test.ts +0 -52
  45. package/test/handlers/gates/external-directory-messages.test.ts +0 -85
  46. package/test/handlers/gates/external-directory-policy.test.ts +0 -134
  47. package/test/handlers/gates/external-directory.test.ts +0 -267
  48. package/test/handlers/gates/helpers.test.ts +0 -165
  49. package/test/handlers/gates/path.test.ts +0 -369
  50. package/test/handlers/gates/runner.test.ts +0 -408
  51. package/test/handlers/gates/skill-input-gate-pipeline.test.ts +0 -176
  52. package/test/handlers/gates/skill-input.test.ts +0 -128
  53. package/test/handlers/gates/skill-read.test.ts +0 -161
  54. package/test/handlers/gates/tool-call-gate-pipeline.test.ts +0 -356
  55. package/test/handlers/gates/tool.test.ts +0 -244
  56. package/test/handlers/input-events.test.ts +0 -168
  57. package/test/handlers/input.test.ts +0 -199
  58. package/test/handlers/lifecycle.test.ts +0 -221
  59. package/test/handlers/tool-call-boundary.test.ts +0 -145
  60. package/test/handlers/tool-call-events.test.ts +0 -277
  61. package/test/handlers/tool-call.test.ts +0 -395
  62. package/test/handlers/validate-requested-tool.test.ts +0 -92
  63. package/test/helpers/external-directory-fixtures.ts +0 -269
  64. package/test/helpers/gate-fixtures.ts +0 -316
  65. package/test/helpers/handler-fixtures.ts +0 -335
  66. package/test/helpers/make-fake-pi.ts +0 -100
  67. package/test/helpers/manager-harness.ts +0 -112
  68. package/test/helpers/session-fixtures.ts +0 -199
  69. package/test/input-normalizer.test.ts +0 -325
  70. package/test/logging.test.ts +0 -51
  71. package/test/mcp-targets.test.ts +0 -233
  72. package/test/node-modules-discovery.test.ts +0 -97
  73. package/test/normalize.test.ts +0 -247
  74. package/test/path-containment.test.ts +0 -161
  75. package/test/path-normalization.test.ts +0 -233
  76. package/test/path-normalizer.test.ts +0 -196
  77. package/test/path-surfaces.test.ts +0 -55
  78. package/test/pattern-suggest.test.ts +0 -248
  79. package/test/permission-dialog.test.ts +0 -205
  80. package/test/permission-event-rpc.test.ts +0 -560
  81. package/test/permission-events.test.ts +0 -400
  82. package/test/permission-forwarder.test.ts +0 -370
  83. package/test/permission-forwarding.test.ts +0 -315
  84. package/test/permission-gate.test.ts +0 -269
  85. package/test/permission-manager-unified.test.ts +0 -3714
  86. package/test/permission-merge.test.ts +0 -61
  87. package/test/permission-prompter.test.ts +0 -518
  88. package/test/permission-prompts.test.ts +0 -363
  89. package/test/permission-resolver.test.ts +0 -277
  90. package/test/permission-session.test.ts +0 -404
  91. package/test/permission-ui-prompt.test.ts +0 -146
  92. package/test/permissions-service.test.ts +0 -192
  93. package/test/pi-infrastructure-read.test.ts +0 -432
  94. package/test/policy-loader.test.ts +0 -561
  95. package/test/prompting-gateway.test.ts +0 -231
  96. package/test/rule.test.ts +0 -650
  97. package/test/safe-system-paths.test.ts +0 -46
  98. package/test/scope-merge.test.ts +0 -116
  99. package/test/service-lifecycle.test.ts +0 -163
  100. package/test/service.test.ts +0 -261
  101. package/test/session-approval.test.ts +0 -75
  102. package/test/session-logger.test.ts +0 -200
  103. package/test/session-rules.test.ts +0 -321
  104. package/test/session-start.test.ts +0 -112
  105. package/test/skill-prompt-sanitizer.test.ts +0 -418
  106. package/test/status.test.ts +0 -10
  107. package/test/subagent-context.test.ts +0 -372
  108. package/test/subagent-lifecycle-events.test.ts +0 -132
  109. package/test/subagent-registry.test.ts +0 -145
  110. package/test/synthesize.test.ts +0 -302
  111. package/test/system-prompt-sanitizer.test.ts +0 -382
  112. package/test/tool-access-extractor-registry.test.ts +0 -77
  113. package/test/tool-input-formatter-registry.test.ts +0 -75
  114. package/test/tool-input-path.test.ts +0 -84
  115. package/test/tool-input-preview.test.ts +0 -129
  116. package/test/tool-input-prompt-formatters.test.ts +0 -115
  117. package/test/tool-preview-formatter.test.ts +0 -458
  118. package/test/tool-registry.test.ts +0 -197
  119. package/test/value-guards.test.ts +0 -193
  120. package/test/wildcard-matcher.test.ts +0 -424
  121. package/test/yaml-frontmatter.test.ts +0 -91
  122. package/test/yolo-mode.test.ts +0 -188
@@ -1,161 +0,0 @@
1
- import { describe, expect, test, vi } from "vitest";
2
-
3
- // Mock node:fs so the discriminator test can assert realpathSync is untouched.
4
- const realpathSync = vi.hoisted(() =>
5
- vi.fn<(path: string) => string>((p) => p),
6
- );
7
- vi.mock("node:fs", () => ({
8
- realpathSync,
9
- default: { realpathSync },
10
- }));
11
-
12
- import {
13
- isPathOutsideWorkingDirectory,
14
- isPathWithinDirectory,
15
- } from "#src/path-containment";
16
-
17
- describe("isPathWithinDirectory", () => {
18
- test("returns true when path equals directory", () => {
19
- expect(isPathWithinDirectory("/a/b", "/a/b", "linux")).toBe(true);
20
- });
21
-
22
- test("returns true when path is a direct child", () => {
23
- expect(isPathWithinDirectory("/a/b/c", "/a/b", "linux")).toBe(true);
24
- });
25
-
26
- test("returns true when path is a deep descendant", () => {
27
- expect(isPathWithinDirectory("/a/b/c/d/e", "/a/b", "linux")).toBe(true);
28
- });
29
-
30
- test("returns false when path is a sibling directory", () => {
31
- expect(isPathWithinDirectory("/a/bc", "/a/b", "linux")).toBe(false);
32
- });
33
-
34
- test("returns false when path is outside the directory", () => {
35
- expect(isPathWithinDirectory("/other/path", "/a/b", "linux")).toBe(false);
36
- });
37
-
38
- test("returns false for empty path", () => {
39
- expect(isPathWithinDirectory("", "/a/b", "linux")).toBe(false);
40
- });
41
-
42
- test("returns false for empty directory", () => {
43
- expect(isPathWithinDirectory("/a/b", "", "linux")).toBe(false);
44
- });
45
-
46
- // ── platform-aware containment (Windows is case-insensitive) ────────────
47
-
48
- test("win32: folds case for a case-different descendant", () => {
49
- expect(
50
- isPathWithinDirectory(
51
- "c:\\users\\foo\\dir\\sub\\x.md",
52
- "C:\\Users\\Foo\\dir",
53
- "win32",
54
- ),
55
- ).toBe(true);
56
- });
57
-
58
- test("win32: folds case when path equals directory in different case", () => {
59
- expect(
60
- isPathWithinDirectory(
61
- "c:\\users\\foo\\dir\\sub",
62
- "C:\\USERS\\foo\\DIR",
63
- "win32",
64
- ),
65
- ).toBe(true);
66
- });
67
-
68
- test("win32: rejects a sibling directory", () => {
69
- expect(
70
- isPathWithinDirectory(
71
- "C:\\Users\\Foo\\other",
72
- "C:\\Users\\Foo\\dir",
73
- "win32",
74
- ),
75
- ).toBe(false);
76
- });
77
-
78
- test("posix platform stays case-sensitive", () => {
79
- expect(isPathWithinDirectory("/a/B/c", "/a/b", "linux")).toBe(false);
80
- });
81
- });
82
-
83
- describe("isPathOutsideWorkingDirectory", () => {
84
- // Pure geometry over already-canonical operands: the caller (PathNormalizer)
85
- // prepares the canonical path and cwd; this predicate never canonicalizes.
86
- const canonicalCwd = "/projects/my-app";
87
-
88
- test("does not canonicalize its operands (no filesystem access)", () => {
89
- realpathSync.mockClear();
90
- isPathOutsideWorkingDirectory(
91
- "/projects/my-app/src",
92
- canonicalCwd,
93
- "linux",
94
- );
95
- expect(realpathSync).not.toHaveBeenCalled();
96
- });
97
-
98
- test("returns false when path is inside cwd", () => {
99
- expect(
100
- isPathOutsideWorkingDirectory(
101
- "/projects/my-app/src",
102
- canonicalCwd,
103
- "linux",
104
- ),
105
- ).toBe(false);
106
- });
107
-
108
- test("returns false when path equals cwd", () => {
109
- expect(
110
- isPathOutsideWorkingDirectory("/projects/my-app", canonicalCwd, "linux"),
111
- ).toBe(false);
112
- });
113
-
114
- test("returns true when path is outside cwd", () => {
115
- expect(
116
- isPathOutsideWorkingDirectory("/etc/passwd", canonicalCwd, "linux"),
117
- ).toBe(true);
118
- });
119
-
120
- test("returns false for an empty canonical path", () => {
121
- expect(isPathOutsideWorkingDirectory("", canonicalCwd, "linux")).toBe(
122
- false,
123
- );
124
- });
125
-
126
- test("returns false for an empty canonical cwd", () => {
127
- expect(isPathOutsideWorkingDirectory("/etc/passwd", "", "linux")).toBe(
128
- false,
129
- );
130
- });
131
-
132
- test("returns false for /dev/null (safe system path)", () => {
133
- expect(
134
- isPathOutsideWorkingDirectory("/dev/null", canonicalCwd, "linux"),
135
- ).toBe(false);
136
- });
137
-
138
- test("returns false for /dev/stdin (safe system path)", () => {
139
- expect(
140
- isPathOutsideWorkingDirectory("/dev/stdin", canonicalCwd, "linux"),
141
- ).toBe(false);
142
- });
143
-
144
- test("returns false for /dev/stdout (safe system path)", () => {
145
- expect(
146
- isPathOutsideWorkingDirectory("/dev/stdout", canonicalCwd, "linux"),
147
- ).toBe(false);
148
- });
149
-
150
- test("returns false for /dev/stderr (safe system path)", () => {
151
- expect(
152
- isPathOutsideWorkingDirectory("/dev/stderr", canonicalCwd, "linux"),
153
- ).toBe(false);
154
- });
155
-
156
- test("returns true for /dev/null/subdir (not a safe path)", () => {
157
- expect(
158
- isPathOutsideWorkingDirectory("/dev/null/subdir", canonicalCwd, "linux"),
159
- ).toBe(true);
160
- });
161
- });
@@ -1,233 +0,0 @@
1
- import { join } from "node:path";
2
- import { beforeEach, describe, expect, test, vi } from "vitest";
3
-
4
- // Mock node:os so tilde-expansion is deterministic across platforms.
5
- vi.mock("node:os", () => {
6
- const homedir = vi.fn(() => "/mock/home");
7
- return {
8
- homedir,
9
- default: { homedir },
10
- };
11
- });
12
-
13
- // Mock node:fs so realpathSync (used by canonicalizePath) is controllable.
14
- // Default implementation is identity — existing lexical tests are unaffected.
15
- const realpathSync = vi.hoisted(() =>
16
- vi.fn<(path: string) => string>((p) => p),
17
- );
18
- vi.mock("node:fs", () => ({
19
- realpathSync,
20
- default: { realpathSync },
21
- }));
22
-
23
- import {
24
- canonicalNormalizePathForComparison,
25
- getPathPolicyValues,
26
- normalizePathForComparison,
27
- normalizePathPolicyLiteral,
28
- } from "#src/access-intent/path-normalization";
29
-
30
- describe("normalizePathForComparison", () => {
31
- const cwd = "/projects/my-app";
32
-
33
- test("resolves absolute path unchanged", () => {
34
- expect(normalizePathForComparison("/usr/local/bin", cwd, "linux")).toBe(
35
- "/usr/local/bin",
36
- );
37
- });
38
-
39
- test("resolves relative path against cwd", () => {
40
- expect(normalizePathForComparison("src/foo.ts", cwd, "linux")).toBe(
41
- "/projects/my-app/src/foo.ts",
42
- );
43
- });
44
-
45
- test("expands bare ~ to homedir", () => {
46
- expect(normalizePathForComparison("~", cwd, "linux")).toBe("/mock/home");
47
- });
48
-
49
- test("expands ~/... to homedir-relative path", () => {
50
- expect(normalizePathForComparison("~/docs/readme.md", cwd, "linux")).toBe(
51
- join("/mock/home", "docs/readme.md"),
52
- );
53
- });
54
-
55
- test("expands bare $HOME to homedir", () => {
56
- expect(normalizePathForComparison("$HOME", cwd, "linux")).toBe(
57
- "/mock/home",
58
- );
59
- });
60
-
61
- test("expands $HOME/... to homedir-relative path", () => {
62
- expect(normalizePathForComparison("$HOME/.ssh/config", cwd, "linux")).toBe(
63
- join("/mock/home", ".ssh/config"),
64
- );
65
- });
66
-
67
- test("strips leading @ before resolving", () => {
68
- expect(normalizePathForComparison("@/usr/local/bin", cwd, "linux")).toBe(
69
- "/usr/local/bin",
70
- );
71
- });
72
-
73
- test("strips surrounding quotes", () => {
74
- expect(normalizePathForComparison("'/usr/local/bin'", cwd, "linux")).toBe(
75
- "/usr/local/bin",
76
- );
77
- expect(normalizePathForComparison('"/usr/local/bin"', cwd, "linux")).toBe(
78
- "/usr/local/bin",
79
- );
80
- });
81
-
82
- test("returns empty string for blank/whitespace-only path", () => {
83
- expect(normalizePathForComparison("", cwd, "linux")).toBe("");
84
- expect(normalizePathForComparison(" ", cwd, "linux")).toBe("");
85
- });
86
-
87
- // ── injected platform flavor (Windows is case-folded, win32-resolved) ────
88
-
89
- test("win32: lowercases the resolved absolute path", () => {
90
- expect(
91
- normalizePathForComparison(
92
- "C:\\Users\\Foo\\Bar.txt",
93
- "C:\\Projects",
94
- "win32",
95
- ),
96
- ).toBe("c:\\users\\foo\\bar.txt");
97
- });
98
-
99
- test("win32: resolves a relative path against cwd with win32 rules", () => {
100
- expect(
101
- normalizePathForComparison("src\\foo.ts", "C:\\Projects\\App", "win32"),
102
- ).toBe("c:\\projects\\app\\src\\foo.ts");
103
- });
104
-
105
- test("posix platform leaves case untouched", () => {
106
- expect(
107
- normalizePathForComparison("/Projects/App/Src.ts", cwd, "linux"),
108
- ).toBe("/Projects/App/Src.ts");
109
- });
110
- });
111
-
112
- describe("canonicalNormalizePathForComparison", () => {
113
- const cwd = "/projects/my-app";
114
-
115
- beforeEach(() => {
116
- realpathSync.mockReset();
117
- realpathSync.mockImplementation((p: string) => p);
118
- });
119
-
120
- test("returns canonical form of an existing path", () => {
121
- realpathSync.mockImplementation((p: string) => {
122
- if (p === "/projects/link") return "/real/projects/app";
123
- return p;
124
- });
125
- expect(
126
- canonicalNormalizePathForComparison("/projects/link", cwd, "linux"),
127
- ).toBe("/real/projects/app");
128
- });
129
-
130
- test("returns empty string for empty input", () => {
131
- expect(canonicalNormalizePathForComparison("", cwd, "linux")).toBe("");
132
- });
133
-
134
- test("returns lexical form when no symlinks (identity realpathSync)", () => {
135
- expect(
136
- canonicalNormalizePathForComparison(
137
- "/projects/my-app/src/index.ts",
138
- cwd,
139
- "linux",
140
- ),
141
- ).toBe("/projects/my-app/src/index.ts");
142
- });
143
-
144
- test("win32: lowercases the canonical form", () => {
145
- expect(
146
- canonicalNormalizePathForComparison(
147
- "C:\\Projects\\App\\Src",
148
- "C:\\Projects\\App",
149
- "win32",
150
- ),
151
- ).toBe("c:\\projects\\app\\src");
152
- });
153
- });
154
-
155
- describe("normalizePathPolicyLiteral", () => {
156
- test("returns a relative token unchanged", () => {
157
- expect(normalizePathPolicyLiteral("src/foo.ts")).toBe("src/foo.ts");
158
- });
159
-
160
- test("trims and strips simple wrapping quotes", () => {
161
- expect(normalizePathPolicyLiteral(" 'src/foo.ts' ")).toBe("src/foo.ts");
162
- expect(normalizePathPolicyLiteral('"a/b"')).toBe("a/b");
163
- });
164
-
165
- test("strips a leading @ prefix", () => {
166
- expect(normalizePathPolicyLiteral("@src/foo.ts")).toBe("src/foo.ts");
167
- });
168
-
169
- test("expands ~ to the home directory", () => {
170
- expect(normalizePathPolicyLiteral("~/docs/readme.md")).toBe(
171
- join("/mock/home", "docs/readme.md"),
172
- );
173
- });
174
-
175
- test("does not resolve a relative value against any cwd", () => {
176
- expect(normalizePathPolicyLiteral("foo.ts")).toBe("foo.ts");
177
- });
178
-
179
- test("returns empty string for blank input", () => {
180
- expect(normalizePathPolicyLiteral(" ")).toBe("");
181
- });
182
-
183
- test("preserves the surface catch-all", () => {
184
- expect(normalizePathPolicyLiteral("*")).toBe("*");
185
- });
186
- });
187
-
188
- describe("getPathPolicyValues", () => {
189
- const cwd = "/projects/my-app";
190
-
191
- test("returns only the literal when no base is available", () => {
192
- expect(getPathPolicyValues("src/foo.ts", {}, "linux")).toEqual([
193
- "src/foo.ts",
194
- ]);
195
- expect(getPathPolicyValues("src/foo.ts", {}, "linux")).toEqual([
196
- "src/foo.ts",
197
- ]);
198
- });
199
-
200
- test("adds absolute and project-relative aliases for a relative token", () => {
201
- expect(getPathPolicyValues("src/foo.ts", { cwd }, "linux")).toEqual([
202
- "/projects/my-app/src/foo.ts",
203
- "src/foo.ts",
204
- ]);
205
- });
206
-
207
- test("omits the relative alias for a token outside cwd", () => {
208
- expect(getPathPolicyValues("/etc/hosts", { cwd }, "linux")).toEqual([
209
- "/etc/hosts",
210
- ]);
211
- });
212
-
213
- test("resolves against resolveBase while aliasing relative to cwd", () => {
214
- expect(
215
- getPathPolicyValues(
216
- "foo.txt",
217
- {
218
- cwd,
219
- resolveBase: "/projects/my-app/nested",
220
- },
221
- "linux",
222
- ),
223
- ).toEqual(["/projects/my-app/nested/foo.txt", "nested/foo.txt", "foo.txt"]);
224
- });
225
-
226
- test("preserves the surface catch-all", () => {
227
- expect(getPathPolicyValues("*", { cwd }, "linux")).toEqual(["*"]);
228
- });
229
-
230
- test("returns empty for blank input", () => {
231
- expect(getPathPolicyValues(" ", { cwd }, "linux")).toEqual([]);
232
- });
233
- });
@@ -1,196 +0,0 @@
1
- import { beforeEach, describe, expect, test, vi } from "vitest";
2
-
3
- // Mock node:os so tilde-expansion is deterministic across platforms.
4
- vi.mock("node:os", () => {
5
- const homedir = vi.fn(() => "/mock/home");
6
- return {
7
- homedir,
8
- default: { homedir },
9
- };
10
- });
11
-
12
- // Mock node:fs so realpathSync (used by canonicalizePath) is controllable.
13
- // Default implementation is identity — lexical assertions are unaffected.
14
- const realpathSync = vi.hoisted(() =>
15
- vi.fn<(path: string) => string>((p) => p),
16
- );
17
- vi.mock("node:fs", () => ({
18
- realpathSync,
19
- default: { realpathSync },
20
- }));
21
-
22
- import { PathNormalizer } from "#src/path-normalizer";
23
-
24
- describe("PathNormalizer", () => {
25
- beforeEach(() => {
26
- realpathSync.mockReset();
27
- realpathSync.mockImplementation((p: string) => p);
28
- });
29
-
30
- describe("posix flavor", () => {
31
- const normalizer = new PathNormalizer("linux", "/projects/my-app");
32
-
33
- test("forPath builds an AccessPath resolved against the baked cwd", () => {
34
- const ap = normalizer.forPath("src/foo.ts");
35
- expect(ap.value()).toBe("/projects/my-app/src/foo.ts");
36
- expect(ap.matchValues()).toEqual([
37
- "/projects/my-app/src/foo.ts",
38
- "src/foo.ts",
39
- ]);
40
- });
41
-
42
- test("forPath honors an explicit resolveBase", () => {
43
- const ap = normalizer.forPath("foo.ts", {
44
- resolveBase: "/projects/my-app/sub",
45
- });
46
- expect(ap.value()).toBe("/projects/my-app/sub/foo.ts");
47
- });
48
-
49
- test("forLiteral builds a literal-only AccessPath", () => {
50
- const ap = normalizer.forLiteral("foo.ts");
51
- expect(ap.matchValues()).toEqual(["foo.ts"]);
52
- expect(ap.boundaryValue()).toBe("");
53
- });
54
-
55
- test("isAbsolute uses posix rules", () => {
56
- expect(normalizer.isAbsolute("/etc/hosts")).toBe(true);
57
- expect(normalizer.isAbsolute("rel/path")).toBe(false);
58
- });
59
-
60
- test("resolveBase resolves an offset against the baked cwd", () => {
61
- expect(normalizer.resolveBase("sub")).toBe("/projects/my-app/sub");
62
- expect(normalizer.resolveBase("/abs")).toBe("/abs");
63
- });
64
-
65
- test("joinBase joins an offset with a relative target", () => {
66
- expect(normalizer.joinBase("sub", "nested")).toBe("sub/nested");
67
- });
68
-
69
- test("isWithinDirectory decides containment", () => {
70
- expect(normalizer.isWithinDirectory("/a/b/c", "/a/b")).toBe(true);
71
- expect(normalizer.isWithinDirectory("/a/x", "/a/b")).toBe(false);
72
- });
73
-
74
- test("isOutsideWorkingDirectory tests against the baked cwd", () => {
75
- expect(normalizer.isOutsideWorkingDirectory("/projects/my-app/src")).toBe(
76
- false,
77
- );
78
- expect(normalizer.isOutsideWorkingDirectory("/etc/hosts")).toBe(true);
79
- });
80
-
81
- test("isOutsideWorkingDirectory expands a home-relative token", () => {
82
- expect(normalizer.isOutsideWorkingDirectory("~/secrets")).toBe(true);
83
- });
84
-
85
- test("isOutsideWorkingDirectory resolves a relative token inside cwd", () => {
86
- expect(normalizer.isOutsideWorkingDirectory("src/index.ts")).toBe(false);
87
- });
88
-
89
- test("isOutsideWorkingDirectory follows an in-cwd symlink to an external target", () => {
90
- // ./link -> /etc: realpathSync resolves the full token in one call.
91
- realpathSync.mockImplementation((p: string) => {
92
- if (p === "/projects/my-app/link/hosts") return "/etc/hosts";
93
- return p;
94
- });
95
- expect(normalizer.isOutsideWorkingDirectory("./link/hosts")).toBe(true);
96
- });
97
-
98
- test("isOutsideWorkingDirectory keeps a path inside a symlinked cwd", () => {
99
- // /tmp -> /private/tmp on macOS; cwd reported as the resolved /private/tmp.
100
- realpathSync.mockImplementation((p: string) => {
101
- if (p.startsWith("/tmp/")) return `/private/tmp${p.slice(4)}`;
102
- if (p === "/tmp") return "/private/tmp";
103
- return p;
104
- });
105
- const symlinkNormalizer = new PathNormalizer("linux", "/private/tmp");
106
- expect(
107
- symlinkNormalizer.isOutsideWorkingDirectory("/tmp/workspace/file.ts"),
108
- ).toBe(false);
109
- });
110
-
111
- test("comparableValue returns the lexical absolute form (no FS)", () => {
112
- expect(normalizer.comparableValue("src/foo.ts")).toBe(
113
- "/projects/my-app/src/foo.ts",
114
- );
115
- expect(normalizer.comparableValue("/etc/hosts")).toBe("/etc/hosts");
116
- });
117
- });
118
-
119
- describe("win32 flavor", () => {
120
- const normalizer = new PathNormalizer("win32", "C:\\Projects\\App");
121
-
122
- test("forPath builds a case-folded AccessPath with win32 rules", () => {
123
- const ap = normalizer.forPath("src\\foo.ts");
124
- expect(ap.value()).toBe("c:\\projects\\app\\src\\foo.ts");
125
- expect(ap.matchValues()).toEqual([
126
- "c:\\projects\\app\\src\\foo.ts",
127
- "src\\foo.ts",
128
- ]);
129
- });
130
-
131
- test("isAbsolute uses win32 rules", () => {
132
- expect(normalizer.isAbsolute("C:\\Users\\foo")).toBe(true);
133
- expect(normalizer.isAbsolute("rel\\path")).toBe(false);
134
- });
135
-
136
- test("resolveBase resolves an offset against the baked cwd", () => {
137
- expect(normalizer.resolveBase("sub")).toBe("C:\\Projects\\App\\sub");
138
- });
139
-
140
- test("joinBase joins an offset with a relative target", () => {
141
- expect(normalizer.joinBase("sub", "nested")).toBe("sub\\nested");
142
- });
143
-
144
- test("isWithinDirectory folds case", () => {
145
- expect(
146
- normalizer.isWithinDirectory(
147
- "c:\\users\\foo\\dir\\sub",
148
- "C:\\Users\\Foo\\dir",
149
- ),
150
- ).toBe(true);
151
- });
152
-
153
- test("isOutsideWorkingDirectory case-folds against the baked cwd", () => {
154
- expect(
155
- normalizer.isOutsideWorkingDirectory("c:\\projects\\app\\src"),
156
- ).toBe(false);
157
- expect(normalizer.isOutsideWorkingDirectory("C:\\Other\\dir")).toBe(true);
158
- });
159
-
160
- test("comparableValue case-folds the lexical absolute form", () => {
161
- expect(normalizer.comparableValue("src\\foo.ts")).toBe(
162
- "c:\\projects\\app\\src\\foo.ts",
163
- );
164
- });
165
- });
166
-
167
- describe("isInfrastructureRead", () => {
168
- const normalizer = new PathNormalizer("linux", "/projects/my-app");
169
-
170
- test("allows a read-only tool targeting a configured infra dir", () => {
171
- const ap = normalizer.forPath("/infra/git/pkg/SKILL.md");
172
- expect(normalizer.isInfrastructureRead("read", ap, ["/infra"])).toBe(
173
- true,
174
- );
175
- });
176
-
177
- test("does not allow a write tool targeting an infra dir", () => {
178
- const ap = normalizer.forPath("/infra/git/pkg/file.ts");
179
- expect(normalizer.isInfrastructureRead("write", ap, ["/infra"])).toBe(
180
- false,
181
- );
182
- });
183
-
184
- test("does not allow a read-only tool outside any infra dir", () => {
185
- const ap = normalizer.forPath("/elsewhere/file.ts");
186
- expect(normalizer.isInfrastructureRead("read", ap, ["/infra"])).toBe(
187
- false,
188
- );
189
- });
190
-
191
- test("allows a read targeting the project-local .pi/npm dir (from baked cwd)", () => {
192
- const ap = normalizer.forPath("/projects/my-app/.pi/npm/dep/index.js");
193
- expect(normalizer.isInfrastructureRead("read", ap, [])).toBe(true);
194
- });
195
- });
196
- });
@@ -1,55 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
-
3
- import {
4
- PATH_BEARING_TOOLS,
5
- PATH_SURFACES,
6
- READ_ONLY_PATH_BEARING_TOOLS,
7
- } from "#src/path-surfaces";
8
-
9
- describe("PATH_BEARING_TOOLS", () => {
10
- test("contains the expected tool names", () => {
11
- for (const tool of ["read", "write", "edit", "find", "grep", "ls"]) {
12
- expect(PATH_BEARING_TOOLS.has(tool)).toBe(true);
13
- }
14
- });
15
-
16
- test("does not contain bash or mcp", () => {
17
- expect(PATH_BEARING_TOOLS.has("bash")).toBe(false);
18
- expect(PATH_BEARING_TOOLS.has("mcp")).toBe(false);
19
- });
20
- });
21
-
22
- describe("READ_ONLY_PATH_BEARING_TOOLS", () => {
23
- test("contains read, find, grep, ls", () => {
24
- for (const tool of ["read", "find", "grep", "ls"]) {
25
- expect(READ_ONLY_PATH_BEARING_TOOLS.has(tool)).toBe(true);
26
- }
27
- });
28
-
29
- test("does not contain write or edit", () => {
30
- expect(READ_ONLY_PATH_BEARING_TOOLS.has("write")).toBe(false);
31
- expect(READ_ONLY_PATH_BEARING_TOOLS.has("edit")).toBe(false);
32
- });
33
- });
34
-
35
- describe("PATH_SURFACES", () => {
36
- test("contains the path-bearing tools plus the cross-cutting gates", () => {
37
- for (const surface of [
38
- "read",
39
- "write",
40
- "edit",
41
- "find",
42
- "grep",
43
- "ls",
44
- "external_directory",
45
- "path",
46
- ]) {
47
- expect(PATH_SURFACES.has(surface)).toBe(true);
48
- }
49
- });
50
-
51
- test("does not contain bash or mcp", () => {
52
- expect(PATH_SURFACES.has("bash")).toBe(false);
53
- expect(PATH_SURFACES.has("mcp")).toBe(false);
54
- });
55
- });