@komarspn/pi-permission-system 16.0.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 +2234 -0
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/config/config.example.json +39 -0
- package/package.json +82 -0
- package/schemas/permissions.schema.json +158 -0
- package/src/active-agent.ts +72 -0
- package/src/async-cache.ts +21 -0
- package/src/bash-arity.ts +210 -0
- package/src/builtin-tool-input-formatters.ts +82 -0
- package/src/canonicalize-path.ts +30 -0
- package/src/common.ts +121 -0
- package/src/config-loader.ts +432 -0
- package/src/config-modal.ts +259 -0
- package/src/config-paths.ts +47 -0
- package/src/config-reporter.ts +34 -0
- package/src/config-store.ts +222 -0
- package/src/decision-audit.ts +75 -0
- package/src/decision-reporter.ts +41 -0
- package/src/denial-messages.ts +232 -0
- package/src/expand-home.ts +28 -0
- package/src/extension-config.ts +79 -0
- package/src/extension-paths.ts +66 -0
- package/src/forwarded-permissions/io.ts +404 -0
- package/src/forwarded-permissions/permission-forwarder.ts +580 -0
- package/src/forwarding-manager.ts +74 -0
- package/src/gate-prompter.ts +12 -0
- package/src/handlers/before-agent-start.ts +94 -0
- package/src/handlers/gates/bash-command.ts +75 -0
- package/src/handlers/gates/bash-external-directory.ts +127 -0
- package/src/handlers/gates/bash-path-extractor.ts +15 -0
- package/src/handlers/gates/bash-path.ts +152 -0
- package/src/handlers/gates/bash-program.ts +1143 -0
- package/src/handlers/gates/bash-token-classification.ts +105 -0
- package/src/handlers/gates/candidate-check.ts +32 -0
- package/src/handlers/gates/descriptor.ts +81 -0
- package/src/handlers/gates/external-directory-messages.ts +20 -0
- package/src/handlers/gates/external-directory.ts +133 -0
- package/src/handlers/gates/helpers.ts +76 -0
- package/src/handlers/gates/path.ts +91 -0
- package/src/handlers/gates/runner.ts +186 -0
- package/src/handlers/gates/skill-input-gate-pipeline.ts +104 -0
- package/src/handlers/gates/skill-input.ts +46 -0
- package/src/handlers/gates/skill-read.ts +87 -0
- package/src/handlers/gates/tool-call-gate-pipeline.ts +129 -0
- package/src/handlers/gates/tool.ts +102 -0
- package/src/handlers/gates/types.ts +13 -0
- package/src/handlers/index.ts +3 -0
- package/src/handlers/lifecycle.ts +95 -0
- package/src/handlers/permission-gate-handler.ts +190 -0
- package/src/handlers/tool-call-boundary.ts +91 -0
- package/src/index.ts +225 -0
- package/src/input-normalizer.ts +157 -0
- package/src/logging.ts +113 -0
- package/src/mcp-targets.ts +170 -0
- package/src/node-modules-discovery.ts +76 -0
- package/src/normalize.ts +43 -0
- package/src/path-utils.ts +355 -0
- package/src/pattern-suggest.ts +132 -0
- package/src/permission-dialog.ts +138 -0
- package/src/permission-event-rpc.ts +223 -0
- package/src/permission-events.ts +266 -0
- package/src/permission-forwarding.ts +188 -0
- package/src/permission-gate.ts +94 -0
- package/src/permission-manager.ts +392 -0
- package/src/permission-merge.ts +32 -0
- package/src/permission-prompter.ts +142 -0
- package/src/permission-prompts.ts +93 -0
- package/src/permission-resolver.ts +109 -0
- package/src/permission-session.ts +189 -0
- package/src/permission-ui-prompt.ts +127 -0
- package/src/permissions-service.ts +63 -0
- package/src/persistent-approval-recorder.ts +139 -0
- package/src/policy-loader.ts +350 -0
- package/src/prompting-gateway.ts +104 -0
- package/src/rule.ts +188 -0
- package/src/scope-merge.ts +72 -0
- package/src/service-lifecycle.ts +49 -0
- package/src/service.ts +163 -0
- package/src/session-approval-recorder.ts +6 -0
- package/src/session-approval.ts +43 -0
- package/src/session-logger.ts +91 -0
- package/src/session-rules.ts +79 -0
- package/src/skill-prompt-sanitizer.ts +292 -0
- package/src/status.ts +35 -0
- package/src/subagent-context.ts +104 -0
- package/src/subagent-lifecycle-events.ts +72 -0
- package/src/subagent-registry.ts +105 -0
- package/src/synthesize.ts +92 -0
- package/src/system-prompt-sanitizer.ts +274 -0
- package/src/tool-access-extractor-registry.ts +68 -0
- package/src/tool-input-formatter-registry.ts +67 -0
- package/src/tool-input-preview.ts +34 -0
- package/src/tool-input-prompt-formatters.ts +63 -0
- package/src/tool-preview-formatter.ts +207 -0
- package/src/tool-registry.ts +148 -0
- package/src/types.ts +64 -0
- package/src/wildcard-matcher.ts +120 -0
- package/src/yolo-mode.ts +30 -0
- package/test/active-agent.test.ts +155 -0
- package/test/async-cache.test.ts +48 -0
- package/test/bash-arity.test.ts +144 -0
- package/test/bash-external-directory.test.ts +956 -0
- package/test/builtin-tool-input-formatters.test.ts +109 -0
- package/test/canonicalize-path.test.ts +93 -0
- package/test/common.test.ts +287 -0
- package/test/composition-root.test.ts +603 -0
- package/test/config-loader.test.ts +740 -0
- package/test/config-modal.test.ts +320 -0
- package/test/config-paths.test.ts +83 -0
- package/test/config-pipeline.test.ts +90 -0
- package/test/config-reporter.test.ts +147 -0
- package/test/config-store.test.ts +466 -0
- package/test/decision-audit.test.ts +72 -0
- package/test/decision-reporter.test.ts +112 -0
- package/test/denial-messages.test.ts +656 -0
- package/test/detect-permissive-bash-fallback.test.ts +56 -0
- package/test/expand-home.test.ts +93 -0
- package/test/extension-config.test.ts +129 -0
- package/test/extension-paths.test.ts +108 -0
- package/test/forwarded-permissions/io.test.ts +251 -0
- package/test/forwarding-manager.test.ts +194 -0
- package/test/handlers/before-agent-start.test.ts +317 -0
- package/test/handlers/external-directory-integration.test.ts +623 -0
- package/test/handlers/external-directory-session-dedup.test.ts +430 -0
- package/test/handlers/external-directory-symlink-acceptance.test.ts +149 -0
- package/test/handlers/gates/bash-command-metamorphic.test.ts +83 -0
- package/test/handlers/gates/bash-command.test.ts +191 -0
- package/test/handlers/gates/bash-external-directory.test.ts +269 -0
- package/test/handlers/gates/bash-path.test.ts +337 -0
- package/test/handlers/gates/bash-program.test.ts +410 -0
- package/test/handlers/gates/bash-token-classification.test.ts +241 -0
- package/test/handlers/gates/candidate-check.test.ts +52 -0
- package/test/handlers/gates/external-directory-messages.test.ts +61 -0
- package/test/handlers/gates/external-directory.test.ts +259 -0
- package/test/handlers/gates/helpers.test.ts +177 -0
- package/test/handlers/gates/path.test.ts +294 -0
- package/test/handlers/gates/runner.test.ts +447 -0
- package/test/handlers/gates/skill-input-gate-pipeline.test.ts +176 -0
- package/test/handlers/gates/skill-input.test.ts +131 -0
- package/test/handlers/gates/skill-read.test.ts +158 -0
- package/test/handlers/gates/tool-call-gate-pipeline.test.ts +252 -0
- package/test/handlers/gates/tool.test.ts +223 -0
- package/test/handlers/input-events.test.ts +168 -0
- package/test/handlers/input.test.ts +199 -0
- package/test/handlers/lifecycle.test.ts +221 -0
- package/test/handlers/tool-call-boundary.test.ts +145 -0
- package/test/handlers/tool-call-events.test.ts +277 -0
- package/test/handlers/tool-call.test.ts +395 -0
- package/test/handlers/validate-requested-tool.test.ts +92 -0
- package/test/helpers/gate-fixtures.ts +323 -0
- package/test/helpers/handler-fixtures.ts +335 -0
- package/test/helpers/make-fake-pi.ts +100 -0
- package/test/helpers/manager-harness.ts +112 -0
- package/test/helpers/session-fixtures.ts +204 -0
- package/test/input-normalizer.test.ts +367 -0
- package/test/logging.test.ts +51 -0
- package/test/mcp-targets.test.ts +233 -0
- package/test/node-modules-discovery.test.ts +97 -0
- package/test/normalize.test.ts +247 -0
- package/test/path-utils.test.ts +650 -0
- package/test/pattern-suggest.test.ts +248 -0
- package/test/permission-dialog.test.ts +241 -0
- package/test/permission-event-rpc.test.ts +541 -0
- package/test/permission-events.test.ts +402 -0
- package/test/permission-forwarder.test.ts +369 -0
- package/test/permission-forwarding.test.ts +315 -0
- package/test/permission-gate.test.ts +305 -0
- package/test/permission-manager-unified.test.ts +3368 -0
- package/test/permission-merge.test.ts +61 -0
- package/test/permission-prompter.test.ts +518 -0
- package/test/permission-prompts.test.ts +363 -0
- package/test/permission-resolver.test.ts +265 -0
- package/test/permission-session.test.ts +363 -0
- package/test/permission-ui-prompt.test.ts +146 -0
- package/test/permissions-service.test.ts +177 -0
- package/test/persistent-approval-recorder.test.ts +133 -0
- package/test/pi-infrastructure-read.test.ts +369 -0
- package/test/policy-loader.test.ts +561 -0
- package/test/prompting-gateway.test.ts +230 -0
- package/test/rule.test.ts +604 -0
- package/test/scope-merge.test.ts +116 -0
- package/test/service-lifecycle.test.ts +163 -0
- package/test/service.test.ts +308 -0
- package/test/session-approval.test.ts +75 -0
- package/test/session-logger.test.ts +200 -0
- package/test/session-rules.test.ts +304 -0
- package/test/session-start.test.ts +112 -0
- package/test/skill-prompt-sanitizer.test.ts +374 -0
- package/test/status.test.ts +10 -0
- package/test/subagent-context.test.ts +326 -0
- package/test/subagent-lifecycle-events.test.ts +132 -0
- package/test/subagent-registry.test.ts +145 -0
- package/test/synthesize.test.ts +300 -0
- package/test/system-prompt-sanitizer.test.ts +382 -0
- package/test/tool-access-extractor-registry.test.ts +77 -0
- package/test/tool-input-formatter-registry.test.ts +75 -0
- package/test/tool-input-preview.test.ts +129 -0
- package/test/tool-input-prompt-formatters.test.ts +115 -0
- package/test/tool-preview-formatter.test.ts +458 -0
- package/test/tool-registry.test.ts +197 -0
- package/test/wildcard-matcher.test.ts +424 -0
- package/test/yolo-mode.test.ts +188 -0
|
@@ -0,0 +1,740 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
loadAndMergeConfigs,
|
|
8
|
+
loadUnifiedConfig,
|
|
9
|
+
mergeUnifiedConfigs,
|
|
10
|
+
stripJsonComments,
|
|
11
|
+
} from "#src/config-loader";
|
|
12
|
+
|
|
13
|
+
describe("stripJsonComments", () => {
|
|
14
|
+
it("returns empty string for empty input", () => {
|
|
15
|
+
expect(stripJsonComments("")).toBe("");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("passes through plain JSON unchanged", () => {
|
|
19
|
+
const input = '{"key": true}';
|
|
20
|
+
expect(stripJsonComments(input)).toBe(input);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("drops a line comment body and preserves the trailing newline", () => {
|
|
24
|
+
// The space before // is emitted; the comment body is dropped; \n is kept.
|
|
25
|
+
expect(stripJsonComments('{ // comment\n"k": 1}')).toBe('{ \n"k": 1}');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("drops a line comment that runs to EOF with no trailing newline", () => {
|
|
29
|
+
expect(stripJsonComments('{"k": 1} // trailing')).toBe('{"k": 1} ');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("drops a block comment and nothing else", () => {
|
|
33
|
+
expect(stripJsonComments('{ /* block */ "k": 1}')).toBe('{ "k": 1}');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("drops an unterminated block comment to EOF", () => {
|
|
37
|
+
expect(stripJsonComments("{ /* no close")).toBe("{ ");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("preserves // inside a double-quoted string", () => {
|
|
41
|
+
expect(stripJsonComments('{"url": "http://example.com"}')).toBe(
|
|
42
|
+
'{"url": "http://example.com"}',
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("preserves block-comment markers inside a double-quoted string", () => {
|
|
47
|
+
expect(stripJsonComments('{"v": "a /* b */ c"}')).toBe(
|
|
48
|
+
'{"v": "a /* b */ c"}',
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("preserves // inside a single-quoted string", () => {
|
|
53
|
+
expect(stripJsonComments("{'url': 'http://x.com'}")).toBe(
|
|
54
|
+
"{'url': 'http://x.com'}",
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("preserves block-comment markers inside a single-quoted string", () => {
|
|
59
|
+
expect(stripJsonComments("{'v': 'a /* b */ c'}")).toBe(
|
|
60
|
+
"{'v': 'a /* b */ c'}",
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("honors a backslash-escaped quote so it does not close the string", () => {
|
|
65
|
+
// The string value is: a\"b (backslash-escaped double quote)
|
|
66
|
+
expect(stripJsonComments('{"k": "a\\"b"}')).toBe('{"k": "a\\"b"}');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("emits an unterminated string to EOF verbatim", () => {
|
|
70
|
+
expect(stripJsonComments('{"k": "unterminated')).toBe(
|
|
71
|
+
'{"k": "unterminated',
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("preserves a lone slash that is not part of // or /*", () => {
|
|
76
|
+
expect(stripJsonComments('{"v": 1/2}')).toBe('{"v": 1/2}');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("handles a combined JSONC document that round-trips to valid JSON", () => {
|
|
80
|
+
const jsonc = [
|
|
81
|
+
"{",
|
|
82
|
+
' "debugLog": true, // runtime knob',
|
|
83
|
+
' "permission": { /* the policy */ "*": "ask" }',
|
|
84
|
+
"}",
|
|
85
|
+
].join("\n");
|
|
86
|
+
const stripped = stripJsonComments(jsonc);
|
|
87
|
+
// Must parse without throwing
|
|
88
|
+
const parsed = JSON.parse(stripped) as Record<string, unknown>;
|
|
89
|
+
expect(parsed.debugLog).toBe(true);
|
|
90
|
+
expect(parsed.permission).toEqual({ "*": "ask" });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("loadUnifiedConfig", () => {
|
|
95
|
+
let tempDir: string;
|
|
96
|
+
|
|
97
|
+
beforeEach(() => {
|
|
98
|
+
tempDir = mkdtempSync(join(tmpdir(), "config-loader-test-"));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
afterEach(() => {
|
|
102
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("parses a valid JSON file with runtime knobs and flat permission", () => {
|
|
106
|
+
const configPath = join(tempDir, "config.json");
|
|
107
|
+
writeFileSync(
|
|
108
|
+
configPath,
|
|
109
|
+
JSON.stringify({
|
|
110
|
+
debugLog: true,
|
|
111
|
+
permissionReviewLog: false,
|
|
112
|
+
yoloMode: true,
|
|
113
|
+
permission: {
|
|
114
|
+
"*": "ask",
|
|
115
|
+
read: "allow",
|
|
116
|
+
bash: { "git status": "allow" },
|
|
117
|
+
},
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const result = loadUnifiedConfig(configPath);
|
|
122
|
+
expect(result.issues).toEqual([]);
|
|
123
|
+
expect(result.config.debugLog).toBe(true);
|
|
124
|
+
expect(result.config.permissionReviewLog).toBe(false);
|
|
125
|
+
expect(result.config.yoloMode).toBe(true);
|
|
126
|
+
expect(result.config.permission).toEqual({
|
|
127
|
+
"*": "ask",
|
|
128
|
+
read: "allow",
|
|
129
|
+
bash: { "git status": "allow" },
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("strips JSONC comments before parsing", () => {
|
|
134
|
+
const configPath = join(tempDir, "config.json");
|
|
135
|
+
writeFileSync(
|
|
136
|
+
configPath,
|
|
137
|
+
`{
|
|
138
|
+
// This is a comment
|
|
139
|
+
"debugLog": true,
|
|
140
|
+
/* block comment */
|
|
141
|
+
"permission": { "*": "ask" }
|
|
142
|
+
}`,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const result = loadUnifiedConfig(configPath);
|
|
146
|
+
expect(result.issues).toEqual([]);
|
|
147
|
+
expect(result.config.debugLog).toBe(true);
|
|
148
|
+
expect(result.config.permission).toEqual({ "*": "ask" });
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("ignores unknown keys without emitting issues", () => {
|
|
152
|
+
const configPath = join(tempDir, "config.json");
|
|
153
|
+
writeFileSync(
|
|
154
|
+
configPath,
|
|
155
|
+
JSON.stringify({
|
|
156
|
+
debugLog: false,
|
|
157
|
+
unknownField: "ignored",
|
|
158
|
+
anotherRandom: 42,
|
|
159
|
+
}),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const result = loadUnifiedConfig(configPath);
|
|
163
|
+
expect(result.issues).toEqual([]);
|
|
164
|
+
expect(result.config.debugLog).toBe(false);
|
|
165
|
+
expect(result.config).not.toHaveProperty("unknownField");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("returns empty config and no issues when the file does not exist", () => {
|
|
169
|
+
const configPath = join(tempDir, "nonexistent.json");
|
|
170
|
+
const result = loadUnifiedConfig(configPath);
|
|
171
|
+
expect(result.issues).toEqual([]);
|
|
172
|
+
expect(result.config.debugLog).toBeUndefined();
|
|
173
|
+
expect(result.config.permission).toBeUndefined();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("returns empty config and an issue when the file contains invalid JSON", () => {
|
|
177
|
+
const configPath = join(tempDir, "config.json");
|
|
178
|
+
writeFileSync(configPath, "not valid json {{{");
|
|
179
|
+
|
|
180
|
+
const result = loadUnifiedConfig(configPath);
|
|
181
|
+
expect(result.issues).toHaveLength(1);
|
|
182
|
+
expect(result.issues[0]).toContain(configPath);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("normalizes boolean fields strictly", () => {
|
|
186
|
+
const configPath = join(tempDir, "config.json");
|
|
187
|
+
writeFileSync(
|
|
188
|
+
configPath,
|
|
189
|
+
JSON.stringify({
|
|
190
|
+
debugLog: "yes",
|
|
191
|
+
permissionReviewLog: 1,
|
|
192
|
+
yoloMode: null,
|
|
193
|
+
}),
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const result = loadUnifiedConfig(configPath);
|
|
197
|
+
expect(result.config.debugLog).toBeUndefined();
|
|
198
|
+
expect(result.config.permissionReviewLog).toBeUndefined();
|
|
199
|
+
expect(result.config.yoloMode).toBeUndefined();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("normalizes permission map, keeping only valid PermissionState values", () => {
|
|
203
|
+
const configPath = join(tempDir, "config.json");
|
|
204
|
+
writeFileSync(
|
|
205
|
+
configPath,
|
|
206
|
+
JSON.stringify({
|
|
207
|
+
permission: {
|
|
208
|
+
read: "allow",
|
|
209
|
+
write: "invalid",
|
|
210
|
+
bash: { "git *": "ask", "rm -rf": 42 },
|
|
211
|
+
},
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const result = loadUnifiedConfig(configPath);
|
|
216
|
+
expect(result.config.permission).toEqual({
|
|
217
|
+
read: "allow",
|
|
218
|
+
bash: { "git *": "ask" },
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("accepts permission as object with mixed string and object values", () => {
|
|
223
|
+
const configPath = join(tempDir, "config.json");
|
|
224
|
+
writeFileSync(
|
|
225
|
+
configPath,
|
|
226
|
+
JSON.stringify({
|
|
227
|
+
permission: {
|
|
228
|
+
"*": "ask",
|
|
229
|
+
read: "allow",
|
|
230
|
+
bash: { "*": "ask", "git *": "allow" },
|
|
231
|
+
external_directory: "ask",
|
|
232
|
+
},
|
|
233
|
+
}),
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
const result = loadUnifiedConfig(configPath);
|
|
237
|
+
expect(result.issues).toEqual([]);
|
|
238
|
+
expect(result.config.permission).toEqual({
|
|
239
|
+
"*": "ask",
|
|
240
|
+
read: "allow",
|
|
241
|
+
bash: { "*": "ask", "git *": "allow" },
|
|
242
|
+
external_directory: "ask",
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("preserves a deny-with-reason object inside a pattern map", () => {
|
|
247
|
+
const configPath = join(tempDir, "config.json");
|
|
248
|
+
writeFileSync(
|
|
249
|
+
configPath,
|
|
250
|
+
JSON.stringify({
|
|
251
|
+
permission: {
|
|
252
|
+
bash: {
|
|
253
|
+
"git *": "allow",
|
|
254
|
+
"npm *": { action: "deny", reason: "Use pnpm instead" },
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
}),
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const result = loadUnifiedConfig(configPath);
|
|
261
|
+
expect(result.config.permission).toEqual({
|
|
262
|
+
bash: {
|
|
263
|
+
"git *": "allow",
|
|
264
|
+
"npm *": { action: "deny", reason: "Use pnpm instead" },
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("strips a deny object with a non-string reason (malformed)", () => {
|
|
270
|
+
const configPath = join(tempDir, "config.json");
|
|
271
|
+
writeFileSync(
|
|
272
|
+
configPath,
|
|
273
|
+
JSON.stringify({
|
|
274
|
+
permission: {
|
|
275
|
+
bash: {
|
|
276
|
+
"git *": "allow",
|
|
277
|
+
"npm *": { action: "deny", reason: 42 },
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
}),
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
const result = loadUnifiedConfig(configPath);
|
|
284
|
+
expect(result.config.permission).toEqual({
|
|
285
|
+
bash: { "git *": "allow" },
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("returns no permission when the permission field is absent", () => {
|
|
290
|
+
const configPath = join(tempDir, "config.json");
|
|
291
|
+
writeFileSync(configPath, JSON.stringify({ debugLog: false }));
|
|
292
|
+
|
|
293
|
+
const result = loadUnifiedConfig(configPath);
|
|
294
|
+
expect(result.config.permission).toBeUndefined();
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("ignores a non-object permission field", () => {
|
|
298
|
+
const configPath = join(tempDir, "config.json");
|
|
299
|
+
writeFileSync(configPath, JSON.stringify({ permission: "allow" }));
|
|
300
|
+
|
|
301
|
+
const result = loadUnifiedConfig(configPath);
|
|
302
|
+
expect(result.config.permission).toBeUndefined();
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("parses toolInputPreviewMaxLength when a valid positive integer is present", () => {
|
|
306
|
+
const configPath = join(tempDir, "config.json");
|
|
307
|
+
writeFileSync(
|
|
308
|
+
configPath,
|
|
309
|
+
JSON.stringify({ toolInputPreviewMaxLength: 1000 }),
|
|
310
|
+
);
|
|
311
|
+
const result = loadUnifiedConfig(configPath);
|
|
312
|
+
expect(result.config.toolInputPreviewMaxLength).toBe(1000);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("parses toolTextSummaryMaxLength when a valid positive integer is present", () => {
|
|
316
|
+
const configPath = join(tempDir, "config.json");
|
|
317
|
+
writeFileSync(
|
|
318
|
+
configPath,
|
|
319
|
+
JSON.stringify({ toolTextSummaryMaxLength: 120 }),
|
|
320
|
+
);
|
|
321
|
+
const result = loadUnifiedConfig(configPath);
|
|
322
|
+
expect(result.config.toolTextSummaryMaxLength).toBe(120);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("omits toolInputPreviewMaxLength when absent", () => {
|
|
326
|
+
const configPath = join(tempDir, "config.json");
|
|
327
|
+
writeFileSync(configPath, JSON.stringify({ debugLog: false }));
|
|
328
|
+
const result = loadUnifiedConfig(configPath);
|
|
329
|
+
expect(result.config).not.toHaveProperty("toolInputPreviewMaxLength");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("omits toolTextSummaryMaxLength when absent", () => {
|
|
333
|
+
const configPath = join(tempDir, "config.json");
|
|
334
|
+
writeFileSync(configPath, JSON.stringify({ debugLog: false }));
|
|
335
|
+
const result = loadUnifiedConfig(configPath);
|
|
336
|
+
expect(result.config).not.toHaveProperty("toolTextSummaryMaxLength");
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it.each([
|
|
340
|
+
["zero", 0],
|
|
341
|
+
["negative", -1],
|
|
342
|
+
["float", 1.5],
|
|
343
|
+
["string", "200"],
|
|
344
|
+
["boolean", true],
|
|
345
|
+
] as const)("omits toolInputPreviewMaxLength for invalid value: %s", (_label, value) => {
|
|
346
|
+
const configPath = join(tempDir, "config.json");
|
|
347
|
+
writeFileSync(
|
|
348
|
+
configPath,
|
|
349
|
+
JSON.stringify({ toolInputPreviewMaxLength: value }),
|
|
350
|
+
);
|
|
351
|
+
const result = loadUnifiedConfig(configPath);
|
|
352
|
+
expect(result.config).not.toHaveProperty("toolInputPreviewMaxLength");
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it.each([
|
|
356
|
+
["zero", 0],
|
|
357
|
+
["negative", -1],
|
|
358
|
+
["float", 1.5],
|
|
359
|
+
["string", "80"],
|
|
360
|
+
["boolean", false],
|
|
361
|
+
] as const)("omits toolTextSummaryMaxLength for invalid value: %s", (_label, value) => {
|
|
362
|
+
const configPath = join(tempDir, "config.json");
|
|
363
|
+
writeFileSync(
|
|
364
|
+
configPath,
|
|
365
|
+
JSON.stringify({ toolTextSummaryMaxLength: value }),
|
|
366
|
+
);
|
|
367
|
+
const result = loadUnifiedConfig(configPath);
|
|
368
|
+
expect(result.config).not.toHaveProperty("toolTextSummaryMaxLength");
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("parses piInfrastructureReadPaths when a valid string array is present", () => {
|
|
372
|
+
const configPath = join(tempDir, "config.json");
|
|
373
|
+
writeFileSync(
|
|
374
|
+
configPath,
|
|
375
|
+
JSON.stringify({ piInfrastructureReadPaths: ["/extra/path"] }),
|
|
376
|
+
);
|
|
377
|
+
const result = loadUnifiedConfig(configPath);
|
|
378
|
+
expect(result.config.piInfrastructureReadPaths).toEqual(["/extra/path"]);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("parses piInfrastructureReadPaths as empty array when set to []", () => {
|
|
382
|
+
const configPath = join(tempDir, "config.json");
|
|
383
|
+
writeFileSync(
|
|
384
|
+
configPath,
|
|
385
|
+
JSON.stringify({ piInfrastructureReadPaths: [] }),
|
|
386
|
+
);
|
|
387
|
+
const result = loadUnifiedConfig(configPath);
|
|
388
|
+
expect(result.config.piInfrastructureReadPaths).toEqual([]);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("omits piInfrastructureReadPaths when absent", () => {
|
|
392
|
+
const configPath = join(tempDir, "config.json");
|
|
393
|
+
writeFileSync(configPath, JSON.stringify({ debugLog: false }));
|
|
394
|
+
const result = loadUnifiedConfig(configPath);
|
|
395
|
+
expect(result.config).not.toHaveProperty("piInfrastructureReadPaths");
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it.each([
|
|
399
|
+
["string", "not-an-array"],
|
|
400
|
+
["number", 42],
|
|
401
|
+
["mixed-type array", ["a", 1]],
|
|
402
|
+
["object", { a: "b" }],
|
|
403
|
+
] as const)("omits piInfrastructureReadPaths for invalid value: %s", (_label, value) => {
|
|
404
|
+
const configPath = join(tempDir, "config.json");
|
|
405
|
+
writeFileSync(
|
|
406
|
+
configPath,
|
|
407
|
+
JSON.stringify({ piInfrastructureReadPaths: value }),
|
|
408
|
+
);
|
|
409
|
+
const result = loadUnifiedConfig(configPath);
|
|
410
|
+
expect(result.config).not.toHaveProperty("piInfrastructureReadPaths");
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
describe("mergeUnifiedConfigs", () => {
|
|
415
|
+
it("deep-merges permission objects so project overrides global per-key", () => {
|
|
416
|
+
const merged = mergeUnifiedConfigs(
|
|
417
|
+
{
|
|
418
|
+
permission: {
|
|
419
|
+
"*": "ask",
|
|
420
|
+
read: "allow",
|
|
421
|
+
bash: { "git status": "allow" },
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
permission: {
|
|
426
|
+
"*": "allow",
|
|
427
|
+
bash: { "rm -rf *": "deny" },
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
expect(merged.permission).toEqual({
|
|
433
|
+
"*": "allow",
|
|
434
|
+
read: "allow",
|
|
435
|
+
bash: { "git status": "allow", "rm -rf *": "deny" },
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("string permission value in override replaces base string for same key", () => {
|
|
440
|
+
const merged = mergeUnifiedConfigs(
|
|
441
|
+
{ permission: { read: "ask" } },
|
|
442
|
+
{ permission: { read: "allow" } },
|
|
443
|
+
);
|
|
444
|
+
expect(merged.permission).toEqual({ read: "allow" });
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("object replaces string when override uses object for same surface", () => {
|
|
448
|
+
const merged = mergeUnifiedConfigs(
|
|
449
|
+
{ permission: { bash: "ask" } },
|
|
450
|
+
{ permission: { bash: { "*": "allow", "rm -rf *": "deny" } } },
|
|
451
|
+
);
|
|
452
|
+
expect(merged.permission).toEqual({
|
|
453
|
+
bash: { "*": "allow", "rm -rf *": "deny" },
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it("string replaces object when override uses string for same surface", () => {
|
|
458
|
+
const merged = mergeUnifiedConfigs(
|
|
459
|
+
{ permission: { bash: { "git *": "allow" } } },
|
|
460
|
+
{ permission: { bash: "deny" } },
|
|
461
|
+
);
|
|
462
|
+
expect(merged.permission).toEqual({ bash: "deny" });
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it("replaces scalar runtime knobs (project wins)", () => {
|
|
466
|
+
const merged = mergeUnifiedConfigs(
|
|
467
|
+
{ debugLog: true, permissionReviewLog: true, yoloMode: false },
|
|
468
|
+
{ debugLog: false, yoloMode: true },
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
expect(merged.debugLog).toBe(false);
|
|
472
|
+
expect(merged.permissionReviewLog).toBe(true);
|
|
473
|
+
expect(merged.yoloMode).toBe(true);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it("returns base unchanged when override is empty", () => {
|
|
477
|
+
const base = {
|
|
478
|
+
debugLog: true,
|
|
479
|
+
permission: { read: "allow" as const },
|
|
480
|
+
};
|
|
481
|
+
const merged = mergeUnifiedConfigs(base, {});
|
|
482
|
+
|
|
483
|
+
expect(merged.debugLog).toBe(true);
|
|
484
|
+
expect(merged.permission).toEqual({ read: "allow" });
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
it("returns override unchanged when base is empty", () => {
|
|
488
|
+
const override = {
|
|
489
|
+
yoloMode: true,
|
|
490
|
+
permission: { bash: { "rm -rf *": "deny" as const } },
|
|
491
|
+
};
|
|
492
|
+
const merged = mergeUnifiedConfigs({}, override);
|
|
493
|
+
|
|
494
|
+
expect(merged.yoloMode).toBe(true);
|
|
495
|
+
expect(merged.permission).toEqual({ bash: { "rm -rf *": "deny" } });
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it("does not set undefined keys in the merged result", () => {
|
|
499
|
+
const merged = mergeUnifiedConfigs({ debugLog: true }, { yoloMode: false });
|
|
500
|
+
|
|
501
|
+
expect(merged.debugLog).toBe(true);
|
|
502
|
+
expect(merged.yoloMode).toBe(false);
|
|
503
|
+
expect(merged).not.toHaveProperty("permissionReviewLog");
|
|
504
|
+
expect(merged).not.toHaveProperty("permission");
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it("override toolInputPreviewMaxLength replaces base value", () => {
|
|
508
|
+
const merged = mergeUnifiedConfigs(
|
|
509
|
+
{ toolInputPreviewMaxLength: 200 },
|
|
510
|
+
{ toolInputPreviewMaxLength: 1000 },
|
|
511
|
+
);
|
|
512
|
+
expect(merged.toolInputPreviewMaxLength).toBe(1000);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
it("base toolInputPreviewMaxLength survives when override omits it", () => {
|
|
516
|
+
const merged = mergeUnifiedConfigs(
|
|
517
|
+
{ toolInputPreviewMaxLength: 500 },
|
|
518
|
+
{ debugLog: true },
|
|
519
|
+
);
|
|
520
|
+
expect(merged.toolInputPreviewMaxLength).toBe(500);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it("toolInputPreviewMaxLength is absent when both base and override omit it", () => {
|
|
524
|
+
const merged = mergeUnifiedConfigs({ debugLog: true }, { yoloMode: false });
|
|
525
|
+
expect(merged).not.toHaveProperty("toolInputPreviewMaxLength");
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it("override toolTextSummaryMaxLength replaces base value", () => {
|
|
529
|
+
const merged = mergeUnifiedConfigs(
|
|
530
|
+
{ toolTextSummaryMaxLength: 80 },
|
|
531
|
+
{ toolTextSummaryMaxLength: 200 },
|
|
532
|
+
);
|
|
533
|
+
expect(merged.toolTextSummaryMaxLength).toBe(200);
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
it("base toolTextSummaryMaxLength survives when override omits it", () => {
|
|
537
|
+
const merged = mergeUnifiedConfigs(
|
|
538
|
+
{ toolTextSummaryMaxLength: 120 },
|
|
539
|
+
{ debugLog: false },
|
|
540
|
+
);
|
|
541
|
+
expect(merged.toolTextSummaryMaxLength).toBe(120);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("toolTextSummaryMaxLength is absent when both base and override omit it", () => {
|
|
545
|
+
const merged = mergeUnifiedConfigs({}, { permissionReviewLog: true });
|
|
546
|
+
expect(merged).not.toHaveProperty("toolTextSummaryMaxLength");
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it("override piInfrastructureReadPaths replaces base array", () => {
|
|
550
|
+
const merged = mergeUnifiedConfigs(
|
|
551
|
+
{ piInfrastructureReadPaths: ["/base/path"] },
|
|
552
|
+
{ piInfrastructureReadPaths: ["/override/path"] },
|
|
553
|
+
);
|
|
554
|
+
expect(merged.piInfrastructureReadPaths).toEqual(["/override/path"]);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it("base piInfrastructureReadPaths survives when override omits it", () => {
|
|
558
|
+
const merged = mergeUnifiedConfigs(
|
|
559
|
+
{ piInfrastructureReadPaths: ["/kept/path"] },
|
|
560
|
+
{ debugLog: true },
|
|
561
|
+
);
|
|
562
|
+
expect(merged.piInfrastructureReadPaths).toEqual(["/kept/path"]);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("piInfrastructureReadPaths is absent when both base and override omit it", () => {
|
|
566
|
+
const merged = mergeUnifiedConfigs({ debugLog: true }, { yoloMode: false });
|
|
567
|
+
expect(merged).not.toHaveProperty("piInfrastructureReadPaths");
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
it("override piInfrastructureReadPaths as empty array replaces non-empty base", () => {
|
|
571
|
+
const merged = mergeUnifiedConfigs(
|
|
572
|
+
{ piInfrastructureReadPaths: ["/base/path"] },
|
|
573
|
+
{ piInfrastructureReadPaths: [] },
|
|
574
|
+
);
|
|
575
|
+
expect(merged.piInfrastructureReadPaths).toEqual([]);
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
describe("loadAndMergeConfigs", () => {
|
|
580
|
+
let tempDir: string;
|
|
581
|
+
let agentDir: string;
|
|
582
|
+
let cwd: string;
|
|
583
|
+
let extensionRoot: string;
|
|
584
|
+
|
|
585
|
+
beforeEach(() => {
|
|
586
|
+
tempDir = mkdtempSync(join(tmpdir(), "config-merge-test-"));
|
|
587
|
+
agentDir = join(tempDir, "agent");
|
|
588
|
+
cwd = join(tempDir, "project");
|
|
589
|
+
extensionRoot = join(tempDir, "ext");
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
afterEach(() => {
|
|
593
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
function writeGlobal(content: Record<string, unknown>): void {
|
|
597
|
+
const dir = join(agentDir, "extensions", "pi-permission-system");
|
|
598
|
+
mkdirSync(dir, { recursive: true });
|
|
599
|
+
writeFileSync(join(dir, "config.json"), JSON.stringify(content));
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function writeProject(content: Record<string, unknown>): void {
|
|
603
|
+
const dir = join(cwd, ".pi", "extensions", "pi-permission-system");
|
|
604
|
+
mkdirSync(dir, { recursive: true });
|
|
605
|
+
writeFileSync(join(dir, "config.json"), JSON.stringify(content));
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function writeLegacyGlobalPolicy(content: Record<string, unknown>): void {
|
|
609
|
+
mkdirSync(agentDir, { recursive: true });
|
|
610
|
+
writeFileSync(
|
|
611
|
+
join(agentDir, "pi-permissions.jsonc"),
|
|
612
|
+
JSON.stringify(content),
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function writeLegacyProjectPolicy(content: Record<string, unknown>): void {
|
|
617
|
+
const dir = join(cwd, ".pi", "agent");
|
|
618
|
+
mkdirSync(dir, { recursive: true });
|
|
619
|
+
writeFileSync(join(dir, "pi-permissions.jsonc"), JSON.stringify(content));
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function writeLegacyExtensionConfig(content: Record<string, unknown>): void {
|
|
623
|
+
mkdirSync(extensionRoot, { recursive: true });
|
|
624
|
+
writeFileSync(join(extensionRoot, "config.json"), JSON.stringify(content));
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
it("merges global and project new-layout configs", () => {
|
|
628
|
+
writeGlobal({
|
|
629
|
+
debugLog: true,
|
|
630
|
+
permission: { "*": "ask", read: "allow" },
|
|
631
|
+
});
|
|
632
|
+
writeProject({
|
|
633
|
+
permission: { "*": "allow", write: "deny" },
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
const result = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
|
|
637
|
+
// The merged config leaves a permissive top-level '*' with no bash '*' policy,
|
|
638
|
+
// so the bash-fallback footgun warning is expected.
|
|
639
|
+
expect(result.issues).toHaveLength(1);
|
|
640
|
+
expect(result.issues[0]).toContain("bash");
|
|
641
|
+
expect(result.merged.debugLog).toBe(true);
|
|
642
|
+
expect(result.merged.permission).toEqual({
|
|
643
|
+
"*": "allow",
|
|
644
|
+
read: "allow",
|
|
645
|
+
write: "deny",
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
it("detects legacy global policy and emits migration issue", () => {
|
|
650
|
+
writeLegacyGlobalPolicy({
|
|
651
|
+
defaultPolicy: { tools: "allow" },
|
|
652
|
+
tools: { read: "allow" },
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
const result = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
|
|
656
|
+
expect(result.issues).toHaveLength(1);
|
|
657
|
+
expect(result.issues[0]).toContain("pi-permissions.jsonc");
|
|
658
|
+
expect(result.issues[0]).toContain("extensions/pi-permission-system");
|
|
659
|
+
// Legacy file has no flat-format permission key — no rules extracted
|
|
660
|
+
expect(result.merged.permission).toBeUndefined();
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
it("detects legacy project policy and emits migration issue", () => {
|
|
664
|
+
writeLegacyProjectPolicy({
|
|
665
|
+
bash: { "git status": "allow" },
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
const result = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
|
|
669
|
+
expect(result.issues).toHaveLength(1);
|
|
670
|
+
expect(result.issues[0]).toContain(".pi/agent/pi-permissions.jsonc");
|
|
671
|
+
expect(result.issues[0]).toContain(".pi/extensions/pi-permission-system");
|
|
672
|
+
// Legacy file has no flat-format permission key — no rules extracted
|
|
673
|
+
expect(result.merged.permission).toBeUndefined();
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
it("detects legacy extension runtime config and emits migration issue", () => {
|
|
677
|
+
writeLegacyExtensionConfig({
|
|
678
|
+
debugLog: true,
|
|
679
|
+
yoloMode: true,
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
const result = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
|
|
683
|
+
expect(result.issues).toHaveLength(1);
|
|
684
|
+
expect(result.issues[0]).toContain(extensionRoot);
|
|
685
|
+
expect(result.merged.debugLog).toBe(true);
|
|
686
|
+
expect(result.merged.yoloMode).toBe(true);
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
it("does not emit legacy extension config issue when path equals new global path", () => {
|
|
690
|
+
const newGlobalDir = join(agentDir, "extensions", "pi-permission-system");
|
|
691
|
+
mkdirSync(newGlobalDir, { recursive: true });
|
|
692
|
+
writeFileSync(
|
|
693
|
+
join(newGlobalDir, "config.json"),
|
|
694
|
+
JSON.stringify({ debugLog: true }),
|
|
695
|
+
);
|
|
696
|
+
|
|
697
|
+
const result = loadAndMergeConfigs(agentDir, cwd, newGlobalDir);
|
|
698
|
+
expect(result.issues.filter((i) => i.includes("legacy"))).toHaveLength(0);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
it("emits no issues when no legacy files exist and no new files exist", () => {
|
|
702
|
+
const result = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
|
|
703
|
+
expect(result.issues).toEqual([]);
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
it("new-layout config takes precedence over legacy config at same scope", () => {
|
|
707
|
+
writeGlobal({
|
|
708
|
+
permission: { "*": "deny" },
|
|
709
|
+
});
|
|
710
|
+
writeLegacyGlobalPolicy({
|
|
711
|
+
permission: { "*": "allow" },
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
const result = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
|
|
715
|
+
// New layout wins (legacy loaded first, new layout loaded second → new wins)
|
|
716
|
+
expect(result.merged.permission).toEqual({ "*": "deny" });
|
|
717
|
+
// But legacy still emits a migration warning
|
|
718
|
+
expect(result.issues.some((i) => i.includes("pi-permissions.jsonc"))).toBe(
|
|
719
|
+
true,
|
|
720
|
+
);
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
it("warns when the merged config leaves bash inheriting a permissive top-level '*'", () => {
|
|
724
|
+
writeGlobal({
|
|
725
|
+
permission: { "*": "allow", read: "allow" },
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
const result = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
|
|
729
|
+
expect(result.issues.some((i) => i.includes("bash"))).toBe(true);
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
it("does not warn about bash fallback when bash is explicitly gated", () => {
|
|
733
|
+
writeGlobal({
|
|
734
|
+
permission: { "*": "allow", bash: { "*": "ask" } },
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
const result = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
|
|
738
|
+
expect(result.issues).toEqual([]);
|
|
739
|
+
});
|
|
740
|
+
});
|