@gotgenes/pi-permission-system 18.1.1 → 18.2.0
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 +25 -0
- package/docs/configuration.md +11 -0
- package/package.json +1 -2
- package/src/access-intent/access-path.ts +29 -4
- package/src/access-intent/bash/bash-path-resolver.ts +39 -18
- package/src/access-intent/bash/msys-bash-tokens.ts +64 -0
- package/src/extension-config.ts +7 -0
- package/src/forwarded-permissions/permission-forwarder.ts +6 -3
- package/src/handlers/gates/helpers.ts +1 -1
- package/src/handlers/gates/runner.ts +22 -0
- package/src/index.ts +10 -6
- package/src/path-normalizer.ts +105 -2
- package/src/permission-manager.ts +21 -1
- package/src/permission-prompter.ts +10 -16
- package/src/prompting-gateway.ts +13 -17
- package/src/rule.ts +21 -1
- package/src/status.ts +1 -1
- package/src/yolo-mode.ts +0 -30
- package/test/access-intent/access-path.test.ts +0 -277
- package/test/access-intent/bash/node-text.test.ts +0 -148
- package/test/access-intent/bash/parser.test.ts +0 -19
- package/test/access-intent/bash/program.test.ts +0 -673
- package/test/access-intent/bash/token-classification.test.ts +0 -363
- package/test/access-intent/bash/token-collection.test.ts +0 -300
- package/test/active-agent.test.ts +0 -155
- package/test/async-cache.test.ts +0 -48
- package/test/bash-arity.test.ts +0 -144
- package/test/bash-external-directory.test.ts +0 -1022
- package/test/builtin-tool-input-formatters.test.ts +0 -109
- package/test/canonicalize-path.test.ts +0 -119
- package/test/composition-root.test.ts +0 -698
- package/test/config-loader.test.ts +0 -740
- package/test/config-modal.test.ts +0 -320
- package/test/config-paths.test.ts +0 -83
- package/test/config-pipeline.test.ts +0 -90
- package/test/config-reporter.test.ts +0 -147
- package/test/config-store.test.ts +0 -466
- package/test/decision-audit.test.ts +0 -72
- package/test/decision-reporter.test.ts +0 -112
- package/test/denial-messages.test.ts +0 -714
- package/test/detect-permissive-bash-fallback.test.ts +0 -56
- package/test/expand-home.test.ts +0 -93
- package/test/extension-config.test.ts +0 -129
- package/test/extension-paths.test.ts +0 -108
- package/test/forwarded-permissions/io.test.ts +0 -251
- package/test/forwarding-manager.test.ts +0 -200
- package/test/handlers/before-agent-start.test.ts +0 -314
- package/test/handlers/external-directory-integration.test.ts +0 -515
- package/test/handlers/external-directory-session-dedup.test.ts +0 -175
- package/test/handlers/external-directory-symlink-acceptance.test.ts +0 -167
- package/test/handlers/gates/bash-command-metamorphic.test.ts +0 -88
- package/test/handlers/gates/bash-command.test.ts +0 -257
- package/test/handlers/gates/bash-external-directory.test.ts +0 -268
- package/test/handlers/gates/bash-path.test.ts +0 -346
- package/test/handlers/gates/candidate-check.test.ts +0 -52
- package/test/handlers/gates/external-directory-messages.test.ts +0 -85
- package/test/handlers/gates/external-directory-policy.test.ts +0 -134
- package/test/handlers/gates/external-directory.test.ts +0 -267
- package/test/handlers/gates/helpers.test.ts +0 -165
- package/test/handlers/gates/path.test.ts +0 -369
- package/test/handlers/gates/runner.test.ts +0 -408
- package/test/handlers/gates/skill-input-gate-pipeline.test.ts +0 -176
- package/test/handlers/gates/skill-input.test.ts +0 -128
- package/test/handlers/gates/skill-read.test.ts +0 -161
- package/test/handlers/gates/tool-call-gate-pipeline.test.ts +0 -356
- package/test/handlers/gates/tool.test.ts +0 -244
- package/test/handlers/input-events.test.ts +0 -168
- package/test/handlers/input.test.ts +0 -199
- package/test/handlers/lifecycle.test.ts +0 -221
- package/test/handlers/tool-call-boundary.test.ts +0 -145
- package/test/handlers/tool-call-events.test.ts +0 -277
- package/test/handlers/tool-call.test.ts +0 -395
- package/test/handlers/validate-requested-tool.test.ts +0 -92
- package/test/helpers/external-directory-fixtures.ts +0 -269
- package/test/helpers/gate-fixtures.ts +0 -316
- package/test/helpers/handler-fixtures.ts +0 -335
- package/test/helpers/make-fake-pi.ts +0 -100
- package/test/helpers/manager-harness.ts +0 -112
- package/test/helpers/session-fixtures.ts +0 -199
- package/test/input-normalizer.test.ts +0 -325
- package/test/logging.test.ts +0 -51
- package/test/mcp-targets.test.ts +0 -233
- package/test/node-modules-discovery.test.ts +0 -97
- package/test/normalize.test.ts +0 -247
- package/test/path-containment.test.ts +0 -161
- package/test/path-normalization.test.ts +0 -233
- package/test/path-normalizer.test.ts +0 -196
- package/test/path-surfaces.test.ts +0 -55
- package/test/pattern-suggest.test.ts +0 -248
- package/test/permission-dialog.test.ts +0 -205
- package/test/permission-event-rpc.test.ts +0 -560
- package/test/permission-events.test.ts +0 -400
- package/test/permission-forwarder.test.ts +0 -370
- package/test/permission-forwarding.test.ts +0 -315
- package/test/permission-gate.test.ts +0 -269
- package/test/permission-manager-unified.test.ts +0 -3714
- package/test/permission-merge.test.ts +0 -61
- package/test/permission-prompter.test.ts +0 -518
- package/test/permission-prompts.test.ts +0 -363
- package/test/permission-resolver.test.ts +0 -277
- package/test/permission-session.test.ts +0 -404
- package/test/permission-ui-prompt.test.ts +0 -146
- package/test/permissions-service.test.ts +0 -192
- package/test/pi-infrastructure-read.test.ts +0 -432
- package/test/policy-loader.test.ts +0 -561
- package/test/prompting-gateway.test.ts +0 -231
- package/test/rule.test.ts +0 -650
- package/test/safe-system-paths.test.ts +0 -46
- package/test/scope-merge.test.ts +0 -116
- package/test/service-lifecycle.test.ts +0 -163
- package/test/service.test.ts +0 -261
- package/test/session-approval.test.ts +0 -75
- package/test/session-logger.test.ts +0 -200
- package/test/session-rules.test.ts +0 -321
- package/test/session-start.test.ts +0 -112
- package/test/skill-prompt-sanitizer.test.ts +0 -418
- package/test/status.test.ts +0 -10
- package/test/subagent-context.test.ts +0 -372
- package/test/subagent-lifecycle-events.test.ts +0 -132
- package/test/subagent-registry.test.ts +0 -145
- package/test/synthesize.test.ts +0 -302
- package/test/system-prompt-sanitizer.test.ts +0 -382
- package/test/tool-access-extractor-registry.test.ts +0 -77
- package/test/tool-input-formatter-registry.test.ts +0 -75
- package/test/tool-input-path.test.ts +0 -84
- package/test/tool-input-preview.test.ts +0 -129
- package/test/tool-input-prompt-formatters.test.ts +0 -115
- package/test/tool-preview-formatter.test.ts +0 -458
- package/test/tool-registry.test.ts +0 -197
- package/test/value-guards.test.ts +0 -193
- package/test/wildcard-matcher.test.ts +0 -424
- package/test/yaml-frontmatter.test.ts +0 -91
- package/test/yolo-mode.test.ts +0 -188
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type { ConfigReader } from "./config-store";
|
|
3
2
|
import type { ApprovalRequester } from "./forwarded-permissions/permission-forwarder";
|
|
4
3
|
import type { PermissionPromptDecision } from "./permission-dialog";
|
|
5
4
|
import {
|
|
@@ -8,7 +7,6 @@ import {
|
|
|
8
7
|
} from "./permission-events";
|
|
9
8
|
import { buildDirectUiPrompt } from "./permission-ui-prompt";
|
|
10
9
|
import type { ReviewLogger } from "./session-logger";
|
|
11
|
-
import { shouldAutoApprovePermissionState } from "./yolo-mode";
|
|
12
10
|
|
|
13
11
|
export type PermissionReviewSource = "tool_call" | "skill_input" | "skill_read";
|
|
14
12
|
|
|
@@ -40,13 +38,11 @@ export interface PermissionPrompterApi {
|
|
|
40
38
|
/**
|
|
41
39
|
* Dependencies required by PermissionPrompter.
|
|
42
40
|
*
|
|
43
|
-
* Keeps the prompter's external surface narrow: callers provide
|
|
44
|
-
*
|
|
45
|
-
*
|
|
41
|
+
* Keeps the prompter's external surface narrow: callers provide a review
|
|
42
|
+
* logger, the UI-prompt event bus, and the forwarder that owns the
|
|
43
|
+
* UI/subagent-forwarding branching logic.
|
|
46
44
|
*/
|
|
47
45
|
export interface PermissionPrompterDeps {
|
|
48
|
-
/** Read current config for yolo-mode check (called at prompt time). */
|
|
49
|
-
config: ConfigReader;
|
|
50
46
|
/** Write structured entries to the permission review log. */
|
|
51
47
|
logger: ReviewLogger;
|
|
52
48
|
/** Event bus used for UI prompt broadcasts. */
|
|
@@ -57,10 +53,13 @@ export interface PermissionPrompterDeps {
|
|
|
57
53
|
|
|
58
54
|
/**
|
|
59
55
|
* Encapsulates the full permission-prompt flow:
|
|
60
|
-
* 1.
|
|
61
|
-
* 2.
|
|
62
|
-
* 3.
|
|
63
|
-
*
|
|
56
|
+
* 1. Review-log "waiting" entry.
|
|
57
|
+
* 2. UI-present vs. subagent-forwarding branching (via confirmPermission).
|
|
58
|
+
* 3. Review-log "approved" / "denied" entry.
|
|
59
|
+
*
|
|
60
|
+
* Yolo-mode auto-approval happens upstream, at the composition stage
|
|
61
|
+
* (`PermissionManager.check`'s `rewriteAsksToYolo`) — an `ask` never reaches
|
|
62
|
+
* this class under yolo, so this class has no yolo-mode knowledge.
|
|
64
63
|
*
|
|
65
64
|
* Injecting a single PermissionPrompter instance means adding a new prompt
|
|
66
65
|
* parameter (e.g. a future sessionLabel variant) only requires changing
|
|
@@ -73,11 +72,6 @@ export class PermissionPrompter implements PermissionPrompterApi {
|
|
|
73
72
|
ctx: ExtensionContext,
|
|
74
73
|
details: PromptPermissionDetails,
|
|
75
74
|
): Promise<PermissionPromptDecision> {
|
|
76
|
-
if (shouldAutoApprovePermissionState("ask", this.deps.config.current())) {
|
|
77
|
-
this.writeReviewEntry("permission_request.auto_approved", details);
|
|
78
|
-
return { approved: true, state: "approved", autoApproved: true };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
75
|
this.writeReviewEntry("permission_request.waiting", details);
|
|
82
76
|
|
|
83
77
|
// Build the event once. When this session has UI it broadcasts directly;
|
package/src/prompting-gateway.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
|
-
import type { ConfigReader } from "./config-store";
|
|
4
3
|
import type { GatePrompter } from "./gate-prompter";
|
|
5
4
|
import type { PermissionPromptDecision } from "./permission-dialog";
|
|
6
5
|
import type {
|
|
@@ -9,18 +8,15 @@ import type {
|
|
|
9
8
|
} from "./permission-prompter";
|
|
10
9
|
import { isSubagentExecutionContext } from "./subagent-context";
|
|
11
10
|
import type { SubagentSessionRegistry } from "./subagent-registry";
|
|
12
|
-
import { canResolveAskPermissionRequest } from "./yolo-mode";
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* Dependencies required by PromptingGateway.
|
|
16
14
|
*
|
|
17
|
-
* All
|
|
18
|
-
* - `
|
|
15
|
+
* All fields are actively consumed:
|
|
16
|
+
* - `subagentSessionsDir` + `registry` drive `canConfirm()`.
|
|
19
17
|
* - `prompter` is called by `prompt()`.
|
|
20
18
|
*/
|
|
21
19
|
export interface PromptingGatewayDeps {
|
|
22
|
-
/** Read current config for the yolo-mode branch of the can-prompt policy. */
|
|
23
|
-
config: ConfigReader;
|
|
24
20
|
/** Static path used to detect a forwarding subagent context. */
|
|
25
21
|
subagentSessionsDir: string;
|
|
26
22
|
/** Host platform, injected from the composition root, for subagent-context path detection. */
|
|
@@ -46,8 +42,8 @@ export interface PromptingGatewayLifecycle {
|
|
|
46
42
|
* Context-owning implementation of the GatePrompter role.
|
|
47
43
|
*
|
|
48
44
|
* Owns the stored ExtensionContext and the "can we prompt?" policy
|
|
49
|
-
* (UI / subagent
|
|
50
|
-
*
|
|
45
|
+
* (UI / subagent), replacing the four twin methods that previously
|
|
46
|
+
* lived on PermissionSession.
|
|
51
47
|
*
|
|
52
48
|
* Lifecycle: PermissionSession drives activate/deactivate so the stored
|
|
53
49
|
* context mirrors the session context without independent call-site changes.
|
|
@@ -72,22 +68,22 @@ export class PromptingGateway
|
|
|
72
68
|
/**
|
|
73
69
|
* Whether an interactive permission prompt can be shown.
|
|
74
70
|
*
|
|
75
|
-
* Returns false when no context is active. Otherwise
|
|
76
|
-
*
|
|
77
|
-
*
|
|
71
|
+
* Returns false when no context is active. Otherwise true when the
|
|
72
|
+
* context has UI or is a forwarding subagent — the two Authorizer-
|
|
73
|
+
* selection predicates the Phase 9 spine will consume. Yolo-mode never
|
|
74
|
+
* reaches this policy: it is resolved upstream at the composition stage.
|
|
78
75
|
*/
|
|
79
76
|
canConfirm(): boolean {
|
|
80
77
|
if (this.context === null) return false;
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
isSubagent: isSubagentExecutionContext(
|
|
78
|
+
return (
|
|
79
|
+
this.context.hasUI ||
|
|
80
|
+
isSubagentExecutionContext(
|
|
85
81
|
this.context,
|
|
86
82
|
this.deps.subagentSessionsDir,
|
|
87
83
|
this.deps.platform,
|
|
88
84
|
this.deps.registry,
|
|
89
|
-
)
|
|
90
|
-
|
|
85
|
+
)
|
|
86
|
+
);
|
|
91
87
|
}
|
|
92
88
|
|
|
93
89
|
/**
|
package/src/rule.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { wildcardMatch } from "./wildcard-matcher";
|
|
|
9
9
|
* Synthesized: "builtin" (universal default / evaluate() fallback),
|
|
10
10
|
* "baseline" (conditional MCP metadata auto-allow).
|
|
11
11
|
* Runtime: "session" (session approvals).
|
|
12
|
+
* Rewrite: "yolo" (composition-stage ask→allow rewrite under yolo mode).
|
|
12
13
|
*/
|
|
13
14
|
export type RuleOrigin =
|
|
14
15
|
| "global"
|
|
@@ -17,7 +18,8 @@ export type RuleOrigin =
|
|
|
17
18
|
| "project-agent"
|
|
18
19
|
| "builtin"
|
|
19
20
|
| "baseline"
|
|
20
|
-
| "session"
|
|
21
|
+
| "session"
|
|
22
|
+
| "yolo";
|
|
21
23
|
|
|
22
24
|
/** A single permission rule — the atomic unit of policy. */
|
|
23
25
|
export interface Rule {
|
|
@@ -41,6 +43,24 @@ export interface Rule {
|
|
|
41
43
|
/** An ordered list of rules. Later rules take priority (last-match-wins). */
|
|
42
44
|
export type Ruleset = Rule[];
|
|
43
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Rewrite every `ask` rule to `allow`, tagged `origin: "yolo"`.
|
|
48
|
+
*
|
|
49
|
+
* The composition-stage expression of yolo mode as recorded authority: when
|
|
50
|
+
* enabled, an `ask` becomes a standing `allow` grant in the ruleset rather than
|
|
51
|
+
* a live prompt-path concern. `deny` and existing `allow` rules pass through
|
|
52
|
+
* untouched, so yolo suppresses prompts but preserves hard denies.
|
|
53
|
+
*
|
|
54
|
+
* Pure and non-mutating — `surface`, `pattern`, and `layer` are preserved so
|
|
55
|
+
* downstream `matchedPattern` / source derivation is unaffected; only `action`
|
|
56
|
+
* and `origin` change.
|
|
57
|
+
*/
|
|
58
|
+
export function rewriteAsksToYolo(rules: Ruleset): Ruleset {
|
|
59
|
+
return rules.map((rule) =>
|
|
60
|
+
rule.action === "ask" ? { ...rule, action: "allow", origin: "yolo" } : rule,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
/**
|
|
45
65
|
* Pure permission evaluation.
|
|
46
66
|
*
|
package/src/status.ts
CHANGED
|
@@ -5,9 +5,9 @@ import type {
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
EXTENSION_ID,
|
|
8
|
+
isYoloModeEnabled,
|
|
8
9
|
type PermissionSystemExtensionConfig,
|
|
9
10
|
} from "./extension-config";
|
|
10
|
-
import { isYoloModeEnabled } from "./yolo-mode";
|
|
11
11
|
|
|
12
12
|
export const PERMISSION_SYSTEM_STATUS_KEY = EXTENSION_ID;
|
|
13
13
|
export const PERMISSION_SYSTEM_YOLO_STATUS_VALUE = "yolo";
|
package/src/yolo-mode.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { PermissionSystemExtensionConfig } from "./extension-config";
|
|
2
|
-
import type { PermissionState } from "./types";
|
|
3
|
-
|
|
4
|
-
export interface AskPermissionResolutionOptions {
|
|
5
|
-
config: PermissionSystemExtensionConfig;
|
|
6
|
-
hasUI: boolean;
|
|
7
|
-
isSubagent: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isYoloModeEnabled(
|
|
11
|
-
config: PermissionSystemExtensionConfig,
|
|
12
|
-
): boolean {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion -- typed as boolean but may be undefined at runtime (untyped callers); Boolean() guards against that
|
|
14
|
-
return Boolean(config.yoloMode);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function shouldAutoApprovePermissionState(
|
|
18
|
-
state: PermissionState,
|
|
19
|
-
config: PermissionSystemExtensionConfig,
|
|
20
|
-
): boolean {
|
|
21
|
-
return state === "ask" && isYoloModeEnabled(config);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function canResolveAskPermissionRequest(
|
|
25
|
-
options: AskPermissionResolutionOptions,
|
|
26
|
-
): boolean {
|
|
27
|
-
return (
|
|
28
|
-
options.hasUI || options.isSubagent || isYoloModeEnabled(options.config)
|
|
29
|
-
);
|
|
30
|
-
}
|
|
@@ -1,277 +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 tests 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 { AccessPath } from "#src/access-intent/access-path";
|
|
23
|
-
|
|
24
|
-
describe("AccessPath.forPath", () => {
|
|
25
|
-
const cwd = "/projects/my-app";
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
realpathSync.mockReset();
|
|
29
|
-
realpathSync.mockImplementation((p: string) => p);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe("matchValues()", () => {
|
|
33
|
-
test("adds the symlink-resolved alias alongside the typed path", () => {
|
|
34
|
-
// /tmp -> /private/tmp (the macOS symlink from the bug report, #418).
|
|
35
|
-
realpathSync.mockImplementation((p: string) =>
|
|
36
|
-
p.startsWith("/tmp") ? `/private${p}` : p,
|
|
37
|
-
);
|
|
38
|
-
expect(
|
|
39
|
-
AccessPath.forPath("/tmp/x", { cwd, platform: "linux" }).matchValues(),
|
|
40
|
-
).toEqual(["/tmp/x", "/private/tmp/x"]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("deduplicates when the canonical form equals the lexical form", () => {
|
|
44
|
-
expect(
|
|
45
|
-
AccessPath.forPath("/etc/hosts", {
|
|
46
|
-
cwd,
|
|
47
|
-
platform: "linux",
|
|
48
|
-
}).matchValues(),
|
|
49
|
-
).toEqual(["/etc/hosts"]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("keeps the relative aliases for an in-cwd token without duplicating", () => {
|
|
53
|
-
expect(
|
|
54
|
-
AccessPath.forPath("src/foo.ts", {
|
|
55
|
-
cwd,
|
|
56
|
-
platform: "linux",
|
|
57
|
-
}).matchValues(),
|
|
58
|
-
).toEqual(["/projects/my-app/src/foo.ts", "src/foo.ts"]);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test("includes only the lexical aliases when canonical is empty", () => {
|
|
62
|
-
// Force canonicalizePath to return the original (no-op symlink resolution
|
|
63
|
-
// effectively means canonical === lexical, handled by dedup).
|
|
64
|
-
expect(
|
|
65
|
-
AccessPath.forPath("/etc/hosts", {
|
|
66
|
-
cwd,
|
|
67
|
-
platform: "linux",
|
|
68
|
-
}).matchValues(),
|
|
69
|
-
).not.toHaveLength(0);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("resolves a relative token against an explicit resolveBase", () => {
|
|
73
|
-
// The cd-folded effective base differs from cwd (the bash-path case).
|
|
74
|
-
expect(
|
|
75
|
-
AccessPath.forPath("foo.ts", {
|
|
76
|
-
cwd,
|
|
77
|
-
resolveBase: "/projects/my-app/sub",
|
|
78
|
-
platform: "linux",
|
|
79
|
-
}).matchValues(),
|
|
80
|
-
).toEqual(["/projects/my-app/sub/foo.ts", "sub/foo.ts", "foo.ts"]);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("adds the canonical alias resolved against resolveBase", () => {
|
|
84
|
-
realpathSync.mockImplementation((p: string) =>
|
|
85
|
-
p === "/projects/my-app/sub/foo.ts" ? "/real/foo.ts" : p,
|
|
86
|
-
);
|
|
87
|
-
expect(
|
|
88
|
-
AccessPath.forPath("foo.ts", {
|
|
89
|
-
cwd,
|
|
90
|
-
resolveBase: "/projects/my-app/sub",
|
|
91
|
-
platform: "linux",
|
|
92
|
-
}).matchValues(),
|
|
93
|
-
).toEqual([
|
|
94
|
-
"/projects/my-app/sub/foo.ts",
|
|
95
|
-
"sub/foo.ts",
|
|
96
|
-
"foo.ts",
|
|
97
|
-
"/real/foo.ts",
|
|
98
|
-
]);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe("platform option", () => {
|
|
103
|
-
test("win32: builds lexical/match/boundary values with win32 rules", () => {
|
|
104
|
-
const ap = AccessPath.forPath("src\\foo.ts", {
|
|
105
|
-
cwd: "C:\\Projects\\App",
|
|
106
|
-
platform: "win32",
|
|
107
|
-
});
|
|
108
|
-
expect(ap.value()).toBe("c:\\projects\\app\\src\\foo.ts");
|
|
109
|
-
expect(ap.boundaryValue()).toBe("c:\\projects\\app\\src\\foo.ts");
|
|
110
|
-
expect(ap.matchValues()).toEqual([
|
|
111
|
-
"c:\\projects\\app\\src\\foo.ts",
|
|
112
|
-
"src\\foo.ts",
|
|
113
|
-
]);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test("win32: lowercases the symlink-resolved boundary value", () => {
|
|
117
|
-
realpathSync.mockImplementation((p: string) =>
|
|
118
|
-
p === "c:\\projects\\app\\link" ? "C:\\Real\\App" : p,
|
|
119
|
-
);
|
|
120
|
-
expect(
|
|
121
|
-
AccessPath.forPath("link", {
|
|
122
|
-
cwd: "C:\\Projects\\App",
|
|
123
|
-
platform: "win32",
|
|
124
|
-
}).boundaryValue(),
|
|
125
|
-
).toBe("c:\\real\\app");
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe("boundaryValue()", () => {
|
|
130
|
-
test("returns the canonical (symlink-resolved) form", () => {
|
|
131
|
-
realpathSync.mockImplementation((p: string) =>
|
|
132
|
-
p.startsWith("/tmp") ? `/private${p}` : p,
|
|
133
|
-
);
|
|
134
|
-
expect(
|
|
135
|
-
AccessPath.forPath("/tmp/x", {
|
|
136
|
-
cwd,
|
|
137
|
-
platform: "linux",
|
|
138
|
-
}).boundaryValue(),
|
|
139
|
-
).toBe("/private/tmp/x");
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test("returns the lexical form when path has no symlinks", () => {
|
|
143
|
-
expect(
|
|
144
|
-
AccessPath.forPath("/etc/hosts", {
|
|
145
|
-
cwd,
|
|
146
|
-
platform: "linux",
|
|
147
|
-
}).boundaryValue(),
|
|
148
|
-
).toBe("/etc/hosts");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test("returns empty string for empty input", () => {
|
|
152
|
-
expect(
|
|
153
|
-
AccessPath.forPath("", { cwd, platform: "linux" }).boundaryValue(),
|
|
154
|
-
).toBe("");
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe("value()", () => {
|
|
159
|
-
test("returns the lexical (as-typed, normalized) form", () => {
|
|
160
|
-
realpathSync.mockImplementation((p: string) =>
|
|
161
|
-
p.startsWith("/tmp") ? `/private${p}` : p,
|
|
162
|
-
);
|
|
163
|
-
// Even when the path resolves to a different canonical, value() stays lexical.
|
|
164
|
-
expect(
|
|
165
|
-
AccessPath.forPath("/tmp/x", { cwd, platform: "linux" }).value(),
|
|
166
|
-
).toBe("/tmp/x");
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test("normalizes the path against cwd", () => {
|
|
170
|
-
// A relative path becomes an absolute lexical value.
|
|
171
|
-
expect(
|
|
172
|
-
AccessPath.forPath("src/foo.ts", { cwd, platform: "linux" }).value(),
|
|
173
|
-
).toBe("/projects/my-app/src/foo.ts");
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
test("normalizes a relative path against an explicit resolveBase", () => {
|
|
177
|
-
expect(
|
|
178
|
-
AccessPath.forPath("foo.ts", {
|
|
179
|
-
cwd,
|
|
180
|
-
resolveBase: "/projects/my-app/sub",
|
|
181
|
-
platform: "linux",
|
|
182
|
-
}).value(),
|
|
183
|
-
).toBe("/projects/my-app/sub/foo.ts");
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
test("returns empty string for empty input", () => {
|
|
187
|
-
expect(AccessPath.forPath("", { cwd, platform: "linux" }).value()).toBe(
|
|
188
|
-
"",
|
|
189
|
-
);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe("resolvedAlias()", () => {
|
|
195
|
-
const cwd = "/projects/my-app";
|
|
196
|
-
|
|
197
|
-
beforeEach(() => {
|
|
198
|
-
realpathSync.mockReset();
|
|
199
|
-
realpathSync.mockImplementation((p: string) => p);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test("returns the canonical form when a symlink resolves elsewhere", () => {
|
|
203
|
-
realpathSync.mockImplementation((p: string) =>
|
|
204
|
-
p === "/projects/my-app/demo-symlink-passwd" ? "/etc/passwd" : p,
|
|
205
|
-
);
|
|
206
|
-
expect(
|
|
207
|
-
AccessPath.forPath("demo-symlink-passwd", {
|
|
208
|
-
cwd,
|
|
209
|
-
platform: "linux",
|
|
210
|
-
}).resolvedAlias(),
|
|
211
|
-
).toBe("/etc/passwd");
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test("returns undefined when the path has no symlinks (canonical equals lexical)", () => {
|
|
215
|
-
expect(
|
|
216
|
-
AccessPath.forPath("/etc/hosts", {
|
|
217
|
-
cwd,
|
|
218
|
-
platform: "linux",
|
|
219
|
-
}).resolvedAlias(),
|
|
220
|
-
).toBeUndefined();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test("returns undefined for a literal-only path (no canonical)", () => {
|
|
224
|
-
expect(AccessPath.forLiteral("foo.ts").resolvedAlias()).toBeUndefined();
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
test("returns undefined for empty input", () => {
|
|
228
|
-
expect(
|
|
229
|
-
AccessPath.forPath("", { cwd, platform: "linux" }).resolvedAlias(),
|
|
230
|
-
).toBeUndefined();
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
test("win32: returns the lowercased canonical form for a real symlink target", () => {
|
|
234
|
-
realpathSync.mockImplementation((p: string) =>
|
|
235
|
-
p === "c:\\projects\\app\\link" ? "C:\\Real\\App" : p,
|
|
236
|
-
);
|
|
237
|
-
expect(
|
|
238
|
-
AccessPath.forPath("link", {
|
|
239
|
-
cwd: "C:\\Projects\\App",
|
|
240
|
-
platform: "win32",
|
|
241
|
-
}).resolvedAlias(),
|
|
242
|
-
).toBe("c:\\real\\app");
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
test("win32: returns undefined for a case-only difference (both forms lowercased)", () => {
|
|
246
|
-
expect(
|
|
247
|
-
AccessPath.forPath("src\\foo.ts", {
|
|
248
|
-
cwd: "C:\\Projects\\App",
|
|
249
|
-
platform: "win32",
|
|
250
|
-
}).resolvedAlias(),
|
|
251
|
-
).toBeUndefined();
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
describe("AccessPath.forLiteral", () => {
|
|
256
|
-
beforeEach(() => {
|
|
257
|
-
realpathSync.mockReset();
|
|
258
|
-
realpathSync.mockImplementation((p: string) => p);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test("matchValues() carries only the literal — no canonical, no absolute", () => {
|
|
262
|
-
expect(AccessPath.forLiteral("foo.ts").matchValues()).toEqual(["foo.ts"]);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test("boundaryValue() is empty (no outside-cwd notion for an unknown base)", () => {
|
|
266
|
-
expect(AccessPath.forLiteral("foo.ts").boundaryValue()).toBe("");
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
test("value() returns the literal", () => {
|
|
270
|
-
expect(AccessPath.forLiteral("foo.ts").value()).toBe("foo.ts");
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
test("an empty literal yields no match values", () => {
|
|
274
|
-
expect(AccessPath.forLiteral("").matchValues()).toEqual([]);
|
|
275
|
-
expect(AccessPath.forLiteral("").value()).toBe("");
|
|
276
|
-
});
|
|
277
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
resolveNodeText,
|
|
4
|
-
SKIP_SUBTREE_TYPES,
|
|
5
|
-
} from "#src/access-intent/bash/node-text";
|
|
6
|
-
import type { TSNode } from "#src/access-intent/bash/parser";
|
|
7
|
-
|
|
8
|
-
// Minimal fake TSNode builder — only fills the fields resolveNodeText reads.
|
|
9
|
-
function makeNode(type: string, text: string, children: TSNode[] = []): TSNode {
|
|
10
|
-
return {
|
|
11
|
-
type,
|
|
12
|
-
text,
|
|
13
|
-
startIndex: 0,
|
|
14
|
-
childCount: children.length,
|
|
15
|
-
isNamed: true,
|
|
16
|
-
child: (i) => children[i] ?? null,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
describe("SKIP_SUBTREE_TYPES", () => {
|
|
21
|
-
it("contains the three node types that must not be descended", () => {
|
|
22
|
-
expect(SKIP_SUBTREE_TYPES.has("heredoc_body")).toBe(true);
|
|
23
|
-
expect(SKIP_SUBTREE_TYPES.has("heredoc_end")).toBe(true);
|
|
24
|
-
expect(SKIP_SUBTREE_TYPES.has("comment")).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("does not contain common argument node types", () => {
|
|
28
|
-
expect(SKIP_SUBTREE_TYPES.has("word")).toBe(false);
|
|
29
|
-
expect(SKIP_SUBTREE_TYPES.has("string")).toBe(false);
|
|
30
|
-
expect(SKIP_SUBTREE_TYPES.has("raw_string")).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("resolveNodeText", () => {
|
|
35
|
-
describe("word nodes", () => {
|
|
36
|
-
it("returns the node text unchanged", () => {
|
|
37
|
-
expect(resolveNodeText(makeNode("word", "hello"))).toBe("hello");
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe("raw_string nodes (single-quoted)", () => {
|
|
42
|
-
it("strips surrounding single quotes", () => {
|
|
43
|
-
expect(resolveNodeText(makeNode("raw_string", "'content'"))).toBe(
|
|
44
|
-
"content",
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("strips single quotes around a path", () => {
|
|
49
|
-
expect(resolveNodeText(makeNode("raw_string", "'/etc/hosts'"))).toBe(
|
|
50
|
-
"/etc/hosts",
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("returns text as-is when not fully single-quoted", () => {
|
|
55
|
-
// A raw_string node without enclosing quotes (defensive fallback)
|
|
56
|
-
expect(resolveNodeText(makeNode("raw_string", "noquotes"))).toBe(
|
|
57
|
-
"noquotes",
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("string nodes (double-quoted)", () => {
|
|
63
|
-
it("concatenates inner word children, skipping quote delimiters", () => {
|
|
64
|
-
const quoteOpen = makeNode('"', '"');
|
|
65
|
-
const content = makeNode("string_content", "hello world");
|
|
66
|
-
const quoteClose = makeNode('"', '"');
|
|
67
|
-
const node = makeNode("string", '"hello world"', [
|
|
68
|
-
quoteOpen,
|
|
69
|
-
content,
|
|
70
|
-
quoteClose,
|
|
71
|
-
]);
|
|
72
|
-
expect(resolveNodeText(node)).toBe("hello world");
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("concatenates multiple inner children", () => {
|
|
76
|
-
const quoteOpen = makeNode('"', '"');
|
|
77
|
-
const part1 = makeNode("string_content", "foo");
|
|
78
|
-
const part2 = makeNode("simple_expansion", "$BAR");
|
|
79
|
-
const quoteClose = makeNode('"', '"');
|
|
80
|
-
const node = makeNode("string", '"foo$BAR"', [
|
|
81
|
-
quoteOpen,
|
|
82
|
-
part1,
|
|
83
|
-
part2,
|
|
84
|
-
quoteClose,
|
|
85
|
-
]);
|
|
86
|
-
expect(resolveNodeText(node)).toBe("foo$BAR");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("returns empty string for an empty double-quoted string", () => {
|
|
90
|
-
const quoteOpen = makeNode('"', '"');
|
|
91
|
-
const quoteClose = makeNode('"', '"');
|
|
92
|
-
const node = makeNode("string", '""', [quoteOpen, quoteClose]);
|
|
93
|
-
expect(resolveNodeText(node)).toBe("");
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe("string_content, simple_expansion, and expansion nodes", () => {
|
|
98
|
-
it("returns text as-is for string_content", () => {
|
|
99
|
-
expect(resolveNodeText(makeNode("string_content", "plain text"))).toBe(
|
|
100
|
-
"plain text",
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("returns text as-is for simple_expansion (e.g. $HOME)", () => {
|
|
105
|
-
// retro 0350: $HOME returns the literal text of a simple_expansion node
|
|
106
|
-
expect(resolveNodeText(makeNode("simple_expansion", "$HOME"))).toBe(
|
|
107
|
-
"$HOME",
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("returns text as-is for expansion", () => {
|
|
112
|
-
// biome-ignore lint/suspicious/noTemplateCurlyInString: intentional literal — testing that expansion node text is returned verbatim
|
|
113
|
-
expect(resolveNodeText(makeNode("expansion", "${VAR}"))).toBe("${VAR}");
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe("concatenation nodes", () => {
|
|
118
|
-
it("concatenates resolved children", () => {
|
|
119
|
-
const word = makeNode("word", "/etc/");
|
|
120
|
-
const expansion = makeNode("simple_expansion", "$FILE");
|
|
121
|
-
const node = makeNode("concatenation", "/etc/$FILE", [word, expansion]);
|
|
122
|
-
expect(resolveNodeText(node)).toBe("/etc/$FILE");
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("handles nested concatenation-of-string", () => {
|
|
126
|
-
// A concatenation whose child is a double-quoted string
|
|
127
|
-
const quoteOpen = makeNode('"', '"');
|
|
128
|
-
const content = makeNode("string_content", "bar");
|
|
129
|
-
const quoteClose = makeNode('"', '"');
|
|
130
|
-
const inner = makeNode("string", '"bar"', [
|
|
131
|
-
quoteOpen,
|
|
132
|
-
content,
|
|
133
|
-
quoteClose,
|
|
134
|
-
]);
|
|
135
|
-
const prefix = makeNode("word", "foo");
|
|
136
|
-
const node = makeNode("concatenation", 'foo"bar"', [prefix, inner]);
|
|
137
|
-
expect(resolveNodeText(node)).toBe("foobar");
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe("default fallback", () => {
|
|
142
|
-
it("returns the raw text for unknown node types", () => {
|
|
143
|
-
expect(resolveNodeText(makeNode("unknown_type", "rawtext"))).toBe(
|
|
144
|
-
"rawtext",
|
|
145
|
-
);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { getParser } from "#src/access-intent/bash/parser";
|
|
3
|
-
|
|
4
|
-
describe("getParser", () => {
|
|
5
|
-
it("parses a simple bash command and returns a non-null root node", async () => {
|
|
6
|
-
const parser = await getParser();
|
|
7
|
-
const tree = parser.parse("echo hi");
|
|
8
|
-
expect(tree).not.toBeNull();
|
|
9
|
-
expect(tree?.rootNode).toBeDefined();
|
|
10
|
-
expect(tree?.rootNode.type).toBe("program");
|
|
11
|
-
tree?.delete();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("returns the same memoized parser instance on repeated calls", async () => {
|
|
15
|
-
const first = await getParser();
|
|
16
|
-
const second = await getParser();
|
|
17
|
-
expect(first).toBe(second);
|
|
18
|
-
});
|
|
19
|
-
});
|