@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,337 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, 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
|
+
import { getNonEmptyString, toRecord } from "#src/common";
|
|
13
|
+
import { describeBashPathGate } from "#src/handlers/gates/bash-path";
|
|
14
|
+
import { BashProgram } from "#src/handlers/gates/bash-program";
|
|
15
|
+
import type {
|
|
16
|
+
GateBypass,
|
|
17
|
+
GateDescriptor,
|
|
18
|
+
GateResult,
|
|
19
|
+
} from "#src/handlers/gates/descriptor";
|
|
20
|
+
import { isGateBypass, isGateDescriptor } from "#src/handlers/gates/descriptor";
|
|
21
|
+
import type { ToolCallContext } from "#src/handlers/gates/types";
|
|
22
|
+
import type { ScopedPermissionResolver } from "#src/permission-resolver";
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
makeGateCheckResult as makeCheckResult,
|
|
26
|
+
makePathDispatchResolver,
|
|
27
|
+
makeResolver,
|
|
28
|
+
makeTcc,
|
|
29
|
+
} from "#test/helpers/gate-fixtures";
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
vi.restoreAllMocks();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Mirror the handler's parse-once derivation: parse the bash command into a
|
|
37
|
+
* shared `BashProgram` and inject it, exactly as `permission-gate-handler.ts`
|
|
38
|
+
* does, so the gate is exercised through the production wiring.
|
|
39
|
+
*/
|
|
40
|
+
async function describeGate(
|
|
41
|
+
tcc: ToolCallContext,
|
|
42
|
+
resolver: ScopedPermissionResolver,
|
|
43
|
+
): Promise<GateResult> {
|
|
44
|
+
const command = getNonEmptyString(toRecord(tcc.input).command);
|
|
45
|
+
const bashProgram =
|
|
46
|
+
tcc.toolName === "bash" && command
|
|
47
|
+
? await BashProgram.parse(command)
|
|
48
|
+
: null;
|
|
49
|
+
return describeBashPathGate(tcc, bashProgram, resolver);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ── tests ──────────────────────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
describe("describeBashPathGate", () => {
|
|
55
|
+
it("returns null for non-bash tools", async () => {
|
|
56
|
+
const result = await describeGate(
|
|
57
|
+
makeTcc({ toolName: "read", input: { path: ".env" } }),
|
|
58
|
+
makeResolver(),
|
|
59
|
+
);
|
|
60
|
+
expect(result).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("returns null when no tokens are extracted", async () => {
|
|
64
|
+
const result = await describeGate(
|
|
65
|
+
makeTcc({ input: { command: "echo hello" } }),
|
|
66
|
+
makeResolver(),
|
|
67
|
+
);
|
|
68
|
+
expect(result).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("returns null when all tokens evaluate to allow", async () => {
|
|
72
|
+
const result = await describeGate(
|
|
73
|
+
makeTcc(),
|
|
74
|
+
makeResolver(makeCheckResult({ state: "allow" })),
|
|
75
|
+
);
|
|
76
|
+
expect(result).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("returns GateDescriptor when a token evaluates to deny", async () => {
|
|
80
|
+
const result = await describeGate(
|
|
81
|
+
makeTcc(),
|
|
82
|
+
makeResolver(makeCheckResult({ state: "deny", matchedPattern: "*.env" })),
|
|
83
|
+
);
|
|
84
|
+
expect(result).not.toBeNull();
|
|
85
|
+
expect(isGateDescriptor(result)).toBe(true);
|
|
86
|
+
const desc = result as GateDescriptor;
|
|
87
|
+
expect(desc.surface).toBe("path");
|
|
88
|
+
expect(desc.preCheck?.state).toBe("deny");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("returns GateDescriptor when a token evaluates to ask", async () => {
|
|
92
|
+
const result = await describeGate(
|
|
93
|
+
makeTcc(),
|
|
94
|
+
makeResolver(makeCheckResult({ state: "ask", matchedPattern: "*" })),
|
|
95
|
+
);
|
|
96
|
+
expect(result).not.toBeNull();
|
|
97
|
+
expect(isGateDescriptor(result)).toBe(true);
|
|
98
|
+
const desc = result as GateDescriptor;
|
|
99
|
+
expect(desc.preCheck?.state).toBe("ask");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("descriptor includes triggering token in prompt message", async () => {
|
|
103
|
+
const result = (await describeGate(
|
|
104
|
+
makeTcc(),
|
|
105
|
+
makeResolver(makeCheckResult({ state: "deny", matchedPattern: "*.env" })),
|
|
106
|
+
)) as GateDescriptor;
|
|
107
|
+
expect(result.denialContext).toMatchObject({
|
|
108
|
+
kind: "bash_path",
|
|
109
|
+
command: "cat .env",
|
|
110
|
+
pathValue: ".env",
|
|
111
|
+
});
|
|
112
|
+
expect(result.promptDetails.message).toContain(".env");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("descriptor decision uses surface 'path'", async () => {
|
|
116
|
+
const result = (await describeGate(
|
|
117
|
+
makeTcc(),
|
|
118
|
+
makeResolver(makeCheckResult({ state: "deny", matchedPattern: "*.env" })),
|
|
119
|
+
)) as GateDescriptor;
|
|
120
|
+
expect(result.decision.surface).toBe("path");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("returns GateBypass when session rule covers the path", async () => {
|
|
124
|
+
const result = await describeGate(
|
|
125
|
+
makeTcc(),
|
|
126
|
+
makeResolver(makeCheckResult({ state: "allow", source: "session" })),
|
|
127
|
+
);
|
|
128
|
+
expect(result).not.toBeNull();
|
|
129
|
+
expect(isGateBypass(result)).toBe(true);
|
|
130
|
+
expect((result as GateBypass).action).toBe("allow");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("returns null when command is missing", async () => {
|
|
134
|
+
const result = await describeGate(makeTcc({ input: {} }), makeResolver());
|
|
135
|
+
expect(result).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("evaluates most restrictive across multiple tokens", async () => {
|
|
139
|
+
const resolver = makePathDispatchResolver(
|
|
140
|
+
{ "src/foo.ts": makeCheckResult({ state: "allow" }) },
|
|
141
|
+
makeCheckResult({ state: "deny", matchedPattern: "*.env" }),
|
|
142
|
+
);
|
|
143
|
+
const result = await describeGate(
|
|
144
|
+
makeTcc({ input: { command: "cat src/foo.ts .env" } }),
|
|
145
|
+
resolver,
|
|
146
|
+
);
|
|
147
|
+
expect(result).not.toBeNull();
|
|
148
|
+
expect(isGateDescriptor(result)).toBe(true);
|
|
149
|
+
expect((result as GateDescriptor).preCheck?.state).toBe("deny");
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("deny wins in multi-token: cp .env README.md", async () => {
|
|
153
|
+
const resolver = makePathDispatchResolver(
|
|
154
|
+
{ ".env": makeCheckResult({ state: "deny", matchedPattern: "*.env" }) },
|
|
155
|
+
makeCheckResult({ state: "allow" }),
|
|
156
|
+
);
|
|
157
|
+
const result = await describeGate(
|
|
158
|
+
makeTcc({ input: { command: "cp .env README.md" } }),
|
|
159
|
+
resolver,
|
|
160
|
+
);
|
|
161
|
+
expect(result).not.toBeNull();
|
|
162
|
+
expect(isGateDescriptor(result)).toBe(true);
|
|
163
|
+
const desc = result as GateDescriptor;
|
|
164
|
+
expect(desc.preCheck?.state).toBe("deny");
|
|
165
|
+
expect(desc.decision.value).toBe(".env");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("extracts redirect target: echo test > .env triggers deny", async () => {
|
|
169
|
+
const resolver = makePathDispatchResolver(
|
|
170
|
+
{ ".env": makeCheckResult({ state: "deny", matchedPattern: "*.env" }) },
|
|
171
|
+
makeCheckResult({ state: "allow" }),
|
|
172
|
+
);
|
|
173
|
+
const result = await describeGate(
|
|
174
|
+
makeTcc({ input: { command: "echo test > .env" } }),
|
|
175
|
+
resolver,
|
|
176
|
+
);
|
|
177
|
+
expect(result).not.toBeNull();
|
|
178
|
+
expect(isGateDescriptor(result)).toBe(true);
|
|
179
|
+
expect((result as GateDescriptor).preCheck?.state).toBe("deny");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("returns null when all tokens match only the universal default", async () => {
|
|
183
|
+
const result = await describeGate(
|
|
184
|
+
makeTcc(),
|
|
185
|
+
makeResolver(
|
|
186
|
+
makeCheckResult({
|
|
187
|
+
state: "ask",
|
|
188
|
+
matchedPattern: undefined,
|
|
189
|
+
source: "special",
|
|
190
|
+
origin: "builtin",
|
|
191
|
+
}),
|
|
192
|
+
),
|
|
193
|
+
);
|
|
194
|
+
expect(result).toBeNull();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("ignores tokens matching universal default but fires for explicit rule matches", async () => {
|
|
198
|
+
const resolver = makePathDispatchResolver(
|
|
199
|
+
{ ".env": makeCheckResult({ state: "deny", matchedPattern: "*.env" }) },
|
|
200
|
+
// Other tokens match only the universal default (no matchedPattern)
|
|
201
|
+
makeCheckResult({
|
|
202
|
+
state: "ask",
|
|
203
|
+
matchedPattern: undefined,
|
|
204
|
+
source: "special",
|
|
205
|
+
origin: "builtin",
|
|
206
|
+
}),
|
|
207
|
+
);
|
|
208
|
+
const result = await describeGate(
|
|
209
|
+
makeTcc({ input: { command: "cat src/foo.ts .env" } }),
|
|
210
|
+
resolver,
|
|
211
|
+
);
|
|
212
|
+
expect(result).not.toBeNull();
|
|
213
|
+
expect(isGateDescriptor(result)).toBe(true);
|
|
214
|
+
const desc = result as GateDescriptor;
|
|
215
|
+
expect(desc.preCheck?.state).toBe("deny");
|
|
216
|
+
expect(desc.decision.value).toBe(".env");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("resolves cd-aware policy values while keeping the raw prompt token", async () => {
|
|
220
|
+
const resolver = makeResolver(
|
|
221
|
+
makeCheckResult({ state: "deny", matchedPattern: "*" }),
|
|
222
|
+
);
|
|
223
|
+
const result = (await describeGate(
|
|
224
|
+
makeTcc({
|
|
225
|
+
input: { command: "cd nested && cat src/file.txt" },
|
|
226
|
+
cwd: "/test/project",
|
|
227
|
+
}),
|
|
228
|
+
resolver,
|
|
229
|
+
)) as GateDescriptor;
|
|
230
|
+
|
|
231
|
+
expect(resolver.resolvePathPolicy).toHaveBeenCalledWith(
|
|
232
|
+
[
|
|
233
|
+
"/test/project/nested/src/file.txt",
|
|
234
|
+
"nested/src/file.txt",
|
|
235
|
+
"src/file.txt",
|
|
236
|
+
],
|
|
237
|
+
undefined,
|
|
238
|
+
);
|
|
239
|
+
// The raw token drives the prompt, denial context, and session approval.
|
|
240
|
+
expect(result.denialContext).toMatchObject({ pathValue: "src/file.txt" });
|
|
241
|
+
expect(result.decision.value).toBe("src/file.txt");
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("does not resolve relative policy values through an unknown cd", async () => {
|
|
245
|
+
const resolver = makeResolver(
|
|
246
|
+
makeCheckResult({ state: "deny", matchedPattern: "*" }),
|
|
247
|
+
);
|
|
248
|
+
await describeGate(
|
|
249
|
+
makeTcc({
|
|
250
|
+
input: { command: 'cd "$DIR" && cat src/foo.ts' },
|
|
251
|
+
cwd: "/test/project",
|
|
252
|
+
}),
|
|
253
|
+
resolver,
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
expect(resolver.resolvePathPolicy).toHaveBeenCalledWith(
|
|
257
|
+
["src/foo.ts"],
|
|
258
|
+
undefined,
|
|
259
|
+
);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("binds a current-directory token's session approval to the cwd subtree", async () => {
|
|
263
|
+
const resolver = makeResolver(
|
|
264
|
+
makeCheckResult({ state: "ask", matchedPattern: "*" }),
|
|
265
|
+
);
|
|
266
|
+
const result = (await describeGate(
|
|
267
|
+
makeTcc({
|
|
268
|
+
input: { command: "cat .env" },
|
|
269
|
+
cwd: "/test/project",
|
|
270
|
+
}),
|
|
271
|
+
resolver,
|
|
272
|
+
)) as GateDescriptor;
|
|
273
|
+
|
|
274
|
+
expect(result.decision.value).toBe(".env");
|
|
275
|
+
expect(result.sessionApproval?.surface).toBe("path");
|
|
276
|
+
expect(result.sessionApproval?.representativePattern).toBe(
|
|
277
|
+
"/test/project/*",
|
|
278
|
+
);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// Home-relative path characterization (#350) ──────────────────────────────
|
|
283
|
+
//
|
|
284
|
+
// The parser extracts ~/... tokens from bash commands; the resolver receives
|
|
285
|
+
// the raw token and normalizeInput handles expansion. These tests verify the
|
|
286
|
+
// gate correctly dispatches ~/... tokens through the deny/ask path.
|
|
287
|
+
|
|
288
|
+
describe("describeBashPathGate — home-relative paths", () => {
|
|
289
|
+
it("extracts ~/... token and builds descriptor on deny", async () => {
|
|
290
|
+
// node:os is mocked: homedir() returns "/mock/home".
|
|
291
|
+
// cat ~/.ssh/config → token "~/.ssh/config" extracted.
|
|
292
|
+
const resolver = makePathDispatchResolver(
|
|
293
|
+
{
|
|
294
|
+
"/mock/home/.ssh/config": makeCheckResult({
|
|
295
|
+
state: "deny",
|
|
296
|
+
matchedPattern: "~/.ssh/*",
|
|
297
|
+
}),
|
|
298
|
+
},
|
|
299
|
+
makeCheckResult({ state: "allow" }),
|
|
300
|
+
);
|
|
301
|
+
const result = (await describeGate(
|
|
302
|
+
makeTcc({ input: { command: "cat ~/.ssh/config" } }),
|
|
303
|
+
resolver,
|
|
304
|
+
)) as GateDescriptor;
|
|
305
|
+
|
|
306
|
+
expect(isGateDescriptor(result)).toBe(true);
|
|
307
|
+
expect(result.preCheck?.state).toBe("deny");
|
|
308
|
+
expect(result.denialContext).toMatchObject({
|
|
309
|
+
kind: "bash_path",
|
|
310
|
+
command: "cat ~/.ssh/config",
|
|
311
|
+
pathValue: "~/.ssh/config",
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("extracts $HOME/... token and builds descriptor on deny", async () => {
|
|
316
|
+
const resolver = makePathDispatchResolver(
|
|
317
|
+
{
|
|
318
|
+
"/mock/home/.ssh/config": makeCheckResult({
|
|
319
|
+
state: "deny",
|
|
320
|
+
matchedPattern: "$HOME/.ssh/*",
|
|
321
|
+
}),
|
|
322
|
+
},
|
|
323
|
+
makeCheckResult({ state: "allow" }),
|
|
324
|
+
);
|
|
325
|
+
const result = (await describeGate(
|
|
326
|
+
makeTcc({ input: { command: "cat $HOME/.ssh/config" } }),
|
|
327
|
+
resolver,
|
|
328
|
+
)) as GateDescriptor;
|
|
329
|
+
|
|
330
|
+
expect(isGateDescriptor(result)).toBe(true);
|
|
331
|
+
expect(result.preCheck?.state).toBe("deny");
|
|
332
|
+
expect(result.denialContext).toMatchObject({
|
|
333
|
+
kind: "bash_path",
|
|
334
|
+
pathValue: "$HOME/.ssh/config",
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
});
|