@dexto/tools-filesystem 1.5.2 → 1.5.3
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/dist/directory-approval.integration.test.cjs +36 -32
- package/dist/directory-approval.integration.test.js +36 -32
- package/dist/edit-file-tool.cjs +43 -19
- package/dist/edit-file-tool.js +43 -19
- package/dist/edit-file-tool.test.cjs +203 -0
- package/dist/edit-file-tool.test.d.cts +2 -0
- package/dist/edit-file-tool.test.d.ts +2 -0
- package/dist/edit-file-tool.test.js +180 -0
- package/dist/filesystem-service.cjs +17 -14
- package/dist/filesystem-service.d.cts +3 -3
- package/dist/filesystem-service.d.ts +3 -3
- package/dist/filesystem-service.js +17 -14
- package/dist/filesystem-service.test.cjs +233 -0
- package/dist/filesystem-service.test.d.cts +2 -0
- package/dist/filesystem-service.test.d.ts +2 -0
- package/dist/filesystem-service.test.js +210 -0
- package/dist/path-validator.cjs +29 -20
- package/dist/path-validator.d.cts +9 -2
- package/dist/path-validator.d.ts +9 -2
- package/dist/path-validator.js +29 -20
- package/dist/path-validator.test.cjs +54 -48
- package/dist/path-validator.test.js +54 -48
- package/dist/read-file-tool.cjs +2 -2
- package/dist/read-file-tool.js +2 -2
- package/dist/tool-provider.cjs +22 -7
- package/dist/tool-provider.d.cts +4 -1
- package/dist/tool-provider.d.ts +4 -1
- package/dist/tool-provider.js +22 -7
- package/dist/types.d.cts +6 -0
- package/dist/types.d.ts +6 -0
- package/dist/write-file-tool.cjs +41 -7
- package/dist/write-file-tool.js +46 -8
- package/dist/write-file-tool.test.cjs +217 -0
- package/dist/write-file-tool.test.d.cts +2 -0
- package/dist/write-file-tool.test.d.ts +2 -0
- package/dist/write-file-tool.test.js +194 -0
- package/package.json +2 -2
package/dist/path-validator.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ declare class PathValidator {
|
|
|
43
43
|
/**
|
|
44
44
|
* Validate a file path for security and policy compliance
|
|
45
45
|
*/
|
|
46
|
-
validatePath(filePath: string): PathValidation
|
|
46
|
+
validatePath(filePath: string): Promise<PathValidation>;
|
|
47
47
|
/**
|
|
48
48
|
* Check if path contains traversal attempts
|
|
49
49
|
*/
|
|
@@ -51,6 +51,7 @@ declare class PathValidator {
|
|
|
51
51
|
/**
|
|
52
52
|
* Check if path is within allowed paths (whitelist check)
|
|
53
53
|
* Also consults the directory approval checker if configured.
|
|
54
|
+
* Uses the sync version since the path is already normalized at this point.
|
|
54
55
|
*/
|
|
55
56
|
private isPathAllowed;
|
|
56
57
|
/**
|
|
@@ -59,8 +60,14 @@ declare class PathValidator {
|
|
|
59
60
|
private isPathBlocked;
|
|
60
61
|
/**
|
|
61
62
|
* Quick check if a path is allowed (for internal use)
|
|
63
|
+
* Note: This assumes the path is already normalized/canonicalized
|
|
62
64
|
*/
|
|
63
65
|
isPathAllowedQuick(normalizedPath: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Synchronous path allowed check (for already-normalized paths)
|
|
68
|
+
* This is used internally when we already have a canonicalized path
|
|
69
|
+
*/
|
|
70
|
+
private isPathAllowedSync;
|
|
64
71
|
/**
|
|
65
72
|
* Check if a file path is within the configured allowed paths (from config only).
|
|
66
73
|
* This method does NOT consult ApprovalManager - it only checks the static config paths.
|
|
@@ -71,7 +78,7 @@ declare class PathValidator {
|
|
|
71
78
|
* @param filePath The file path to check (can be relative or absolute)
|
|
72
79
|
* @returns true if the path is within config-allowed paths, false otherwise
|
|
73
80
|
*/
|
|
74
|
-
isPathWithinAllowed(filePath: string): boolean
|
|
81
|
+
isPathWithinAllowed(filePath: string): Promise<boolean>;
|
|
75
82
|
/**
|
|
76
83
|
* Check if path is within config-allowed paths only (no approval checker).
|
|
77
84
|
* Used for prompting decisions.
|
package/dist/path-validator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
|
-
import
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
3
|
class PathValidator {
|
|
4
4
|
config;
|
|
5
5
|
normalizedAllowedPaths;
|
|
@@ -34,7 +34,7 @@ class PathValidator {
|
|
|
34
34
|
/**
|
|
35
35
|
* Validate a file path for security and policy compliance
|
|
36
36
|
*/
|
|
37
|
-
validatePath(filePath) {
|
|
37
|
+
async validatePath(filePath) {
|
|
38
38
|
if (!filePath || filePath.trim() === "") {
|
|
39
39
|
return {
|
|
40
40
|
isValid: false,
|
|
@@ -46,7 +46,7 @@ class PathValidator {
|
|
|
46
46
|
try {
|
|
47
47
|
normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
|
|
48
48
|
try {
|
|
49
|
-
normalizedPath =
|
|
49
|
+
normalizedPath = await fs.realpath(normalizedPath);
|
|
50
50
|
} catch {
|
|
51
51
|
}
|
|
52
52
|
} catch (error) {
|
|
@@ -102,22 +102,10 @@ class PathValidator {
|
|
|
102
102
|
/**
|
|
103
103
|
* Check if path is within allowed paths (whitelist check)
|
|
104
104
|
* Also consults the directory approval checker if configured.
|
|
105
|
+
* Uses the sync version since the path is already normalized at this point.
|
|
105
106
|
*/
|
|
106
107
|
isPathAllowed(normalizedPath) {
|
|
107
|
-
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
const isInConfigPaths = this.normalizedAllowedPaths.some((allowedPath) => {
|
|
111
|
-
const relative = path.relative(allowedPath, normalizedPath);
|
|
112
|
-
return !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
113
|
-
});
|
|
114
|
-
if (isInConfigPaths) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
if (this.directoryApprovalChecker) {
|
|
118
|
-
return this.directoryApprovalChecker(normalizedPath);
|
|
119
|
-
}
|
|
120
|
-
return false;
|
|
108
|
+
return this.isPathAllowedSync(normalizedPath);
|
|
121
109
|
}
|
|
122
110
|
/**
|
|
123
111
|
* Check if path matches blocked patterns (blacklist check)
|
|
@@ -136,9 +124,30 @@ class PathValidator {
|
|
|
136
124
|
}
|
|
137
125
|
/**
|
|
138
126
|
* Quick check if a path is allowed (for internal use)
|
|
127
|
+
* Note: This assumes the path is already normalized/canonicalized
|
|
139
128
|
*/
|
|
140
129
|
isPathAllowedQuick(normalizedPath) {
|
|
141
|
-
return this.
|
|
130
|
+
return this.isPathAllowedSync(normalizedPath) && !this.isPathBlocked(normalizedPath);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Synchronous path allowed check (for already-normalized paths)
|
|
134
|
+
* This is used internally when we already have a canonicalized path
|
|
135
|
+
*/
|
|
136
|
+
isPathAllowedSync(normalizedPath) {
|
|
137
|
+
if (this.normalizedAllowedPaths.length === 0) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
const isInConfigPaths = this.normalizedAllowedPaths.some((allowedPath) => {
|
|
141
|
+
const relative = path.relative(allowedPath, normalizedPath);
|
|
142
|
+
return !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
143
|
+
});
|
|
144
|
+
if (isInConfigPaths) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
if (this.directoryApprovalChecker) {
|
|
148
|
+
return this.directoryApprovalChecker(normalizedPath);
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
142
151
|
}
|
|
143
152
|
/**
|
|
144
153
|
* Check if a file path is within the configured allowed paths (from config only).
|
|
@@ -150,7 +159,7 @@ class PathValidator {
|
|
|
150
159
|
* @param filePath The file path to check (can be relative or absolute)
|
|
151
160
|
* @returns true if the path is within config-allowed paths, false otherwise
|
|
152
161
|
*/
|
|
153
|
-
isPathWithinAllowed(filePath) {
|
|
162
|
+
async isPathWithinAllowed(filePath) {
|
|
154
163
|
if (!filePath || filePath.trim() === "") {
|
|
155
164
|
return false;
|
|
156
165
|
}
|
|
@@ -159,7 +168,7 @@ class PathValidator {
|
|
|
159
168
|
try {
|
|
160
169
|
normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
|
|
161
170
|
try {
|
|
162
|
-
normalizedPath =
|
|
171
|
+
normalizedPath = await fs.realpath(normalizedPath);
|
|
163
172
|
} catch {
|
|
164
173
|
}
|
|
165
174
|
} catch {
|
|
@@ -16,7 +16,7 @@ const createMockLogger = () => ({
|
|
|
16
16
|
});
|
|
17
17
|
(0, import_vitest.describe)("validatePath", () => {
|
|
18
18
|
(0, import_vitest.describe)("Empty and Invalid Paths", () => {
|
|
19
|
-
(0, import_vitest.it)("should reject empty path", () => {
|
|
19
|
+
(0, import_vitest.it)("should reject empty path", async () => {
|
|
20
20
|
const validator = new import_path_validator.PathValidator(
|
|
21
21
|
{
|
|
22
22
|
allowedPaths: ["/home/user/project"],
|
|
@@ -29,11 +29,11 @@ const createMockLogger = () => ({
|
|
|
29
29
|
},
|
|
30
30
|
mockLogger
|
|
31
31
|
);
|
|
32
|
-
const result = validator.validatePath("");
|
|
32
|
+
const result = await validator.validatePath("");
|
|
33
33
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
34
34
|
(0, import_vitest.expect)(result.error).toBe("Path cannot be empty");
|
|
35
35
|
});
|
|
36
|
-
(0, import_vitest.it)("should reject whitespace-only path", () => {
|
|
36
|
+
(0, import_vitest.it)("should reject whitespace-only path", async () => {
|
|
37
37
|
const validator = new import_path_validator.PathValidator(
|
|
38
38
|
{
|
|
39
39
|
allowedPaths: ["/home/user/project"],
|
|
@@ -46,13 +46,13 @@ const createMockLogger = () => ({
|
|
|
46
46
|
},
|
|
47
47
|
mockLogger
|
|
48
48
|
);
|
|
49
|
-
const result = validator.validatePath(" ");
|
|
49
|
+
const result = await validator.validatePath(" ");
|
|
50
50
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
51
51
|
(0, import_vitest.expect)(result.error).toBe("Path cannot be empty");
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
(0, import_vitest.describe)("Allowed Paths", () => {
|
|
55
|
-
(0, import_vitest.it)("should allow paths within allowed directories", () => {
|
|
55
|
+
(0, import_vitest.it)("should allow paths within allowed directories", async () => {
|
|
56
56
|
const validator = new import_path_validator.PathValidator(
|
|
57
57
|
{
|
|
58
58
|
allowedPaths: ["/home/user/project"],
|
|
@@ -65,11 +65,11 @@ const createMockLogger = () => ({
|
|
|
65
65
|
},
|
|
66
66
|
mockLogger
|
|
67
67
|
);
|
|
68
|
-
const result = validator.validatePath("/home/user/project/src/file.ts");
|
|
68
|
+
const result = await validator.validatePath("/home/user/project/src/file.ts");
|
|
69
69
|
(0, import_vitest.expect)(result.isValid).toBe(true);
|
|
70
70
|
(0, import_vitest.expect)(result.normalizedPath).toBeDefined();
|
|
71
71
|
});
|
|
72
|
-
(0, import_vitest.it)("should allow relative paths within working directory", () => {
|
|
72
|
+
(0, import_vitest.it)("should allow relative paths within working directory", async () => {
|
|
73
73
|
const validator = new import_path_validator.PathValidator(
|
|
74
74
|
{
|
|
75
75
|
allowedPaths: ["/home/user/project"],
|
|
@@ -82,10 +82,10 @@ const createMockLogger = () => ({
|
|
|
82
82
|
},
|
|
83
83
|
mockLogger
|
|
84
84
|
);
|
|
85
|
-
const result = validator.validatePath("src/file.ts");
|
|
85
|
+
const result = await validator.validatePath("src/file.ts");
|
|
86
86
|
(0, import_vitest.expect)(result.isValid).toBe(true);
|
|
87
87
|
});
|
|
88
|
-
(0, import_vitest.it)("should reject paths outside allowed directories", () => {
|
|
88
|
+
(0, import_vitest.it)("should reject paths outside allowed directories", async () => {
|
|
89
89
|
const validator = new import_path_validator.PathValidator(
|
|
90
90
|
{
|
|
91
91
|
allowedPaths: ["/home/user/project"],
|
|
@@ -98,11 +98,11 @@ const createMockLogger = () => ({
|
|
|
98
98
|
},
|
|
99
99
|
mockLogger
|
|
100
100
|
);
|
|
101
|
-
const result = validator.validatePath("/external/project/file.ts");
|
|
101
|
+
const result = await validator.validatePath("/external/project/file.ts");
|
|
102
102
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
103
103
|
(0, import_vitest.expect)(result.error).toContain("not within allowed paths");
|
|
104
104
|
});
|
|
105
|
-
(0, import_vitest.it)("should allow all paths when allowedPaths is empty", () => {
|
|
105
|
+
(0, import_vitest.it)("should allow all paths when allowedPaths is empty", async () => {
|
|
106
106
|
const validator = new import_path_validator.PathValidator(
|
|
107
107
|
{
|
|
108
108
|
allowedPaths: [],
|
|
@@ -115,12 +115,12 @@ const createMockLogger = () => ({
|
|
|
115
115
|
},
|
|
116
116
|
mockLogger
|
|
117
117
|
);
|
|
118
|
-
const result = validator.validatePath("/anywhere/file.ts");
|
|
118
|
+
const result = await validator.validatePath("/anywhere/file.ts");
|
|
119
119
|
(0, import_vitest.expect)(result.isValid).toBe(true);
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
122
|
(0, import_vitest.describe)("Path Traversal Detection", () => {
|
|
123
|
-
(0, import_vitest.it)("should reject path traversal attempts", () => {
|
|
123
|
+
(0, import_vitest.it)("should reject path traversal attempts", async () => {
|
|
124
124
|
const validator = new import_path_validator.PathValidator(
|
|
125
125
|
{
|
|
126
126
|
allowedPaths: ["/home/user/project"],
|
|
@@ -133,13 +133,15 @@ const createMockLogger = () => ({
|
|
|
133
133
|
},
|
|
134
134
|
mockLogger
|
|
135
135
|
);
|
|
136
|
-
const result = validator.validatePath(
|
|
136
|
+
const result = await validator.validatePath(
|
|
137
|
+
"/home/user/project/../../../etc/passwd"
|
|
138
|
+
);
|
|
137
139
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
138
140
|
(0, import_vitest.expect)(result.error).toBe("Path traversal detected");
|
|
139
141
|
});
|
|
140
142
|
});
|
|
141
143
|
(0, import_vitest.describe)("Blocked Paths", () => {
|
|
142
|
-
(0, import_vitest.it)("should reject paths in blocked directories", () => {
|
|
144
|
+
(0, import_vitest.it)("should reject paths in blocked directories", async () => {
|
|
143
145
|
const validator = new import_path_validator.PathValidator(
|
|
144
146
|
{
|
|
145
147
|
allowedPaths: ["/home/user/project"],
|
|
@@ -152,11 +154,11 @@ const createMockLogger = () => ({
|
|
|
152
154
|
},
|
|
153
155
|
mockLogger
|
|
154
156
|
);
|
|
155
|
-
const result = validator.validatePath("/home/user/project/.git/config");
|
|
157
|
+
const result = await validator.validatePath("/home/user/project/.git/config");
|
|
156
158
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
157
159
|
(0, import_vitest.expect)(result.error).toContain("blocked");
|
|
158
160
|
});
|
|
159
|
-
(0, import_vitest.it)("should reject paths in node_modules", () => {
|
|
161
|
+
(0, import_vitest.it)("should reject paths in node_modules", async () => {
|
|
160
162
|
const validator = new import_path_validator.PathValidator(
|
|
161
163
|
{
|
|
162
164
|
allowedPaths: ["/home/user/project"],
|
|
@@ -169,7 +171,7 @@ const createMockLogger = () => ({
|
|
|
169
171
|
},
|
|
170
172
|
mockLogger
|
|
171
173
|
);
|
|
172
|
-
const result = validator.validatePath(
|
|
174
|
+
const result = await validator.validatePath(
|
|
173
175
|
"/home/user/project/node_modules/lodash/index.js"
|
|
174
176
|
);
|
|
175
177
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
@@ -177,7 +179,7 @@ const createMockLogger = () => ({
|
|
|
177
179
|
});
|
|
178
180
|
});
|
|
179
181
|
(0, import_vitest.describe)("Blocked Extensions", () => {
|
|
180
|
-
(0, import_vitest.it)("should reject files with blocked extensions", () => {
|
|
182
|
+
(0, import_vitest.it)("should reject files with blocked extensions", async () => {
|
|
181
183
|
const validator = new import_path_validator.PathValidator(
|
|
182
184
|
{
|
|
183
185
|
allowedPaths: ["/home/user/project"],
|
|
@@ -190,11 +192,11 @@ const createMockLogger = () => ({
|
|
|
190
192
|
},
|
|
191
193
|
mockLogger
|
|
192
194
|
);
|
|
193
|
-
const result = validator.validatePath("/home/user/project/malware.exe");
|
|
195
|
+
const result = await validator.validatePath("/home/user/project/malware.exe");
|
|
194
196
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
195
197
|
(0, import_vitest.expect)(result.error).toContain(".exe is not allowed");
|
|
196
198
|
});
|
|
197
|
-
(0, import_vitest.it)("should handle extensions without leading dot", () => {
|
|
199
|
+
(0, import_vitest.it)("should handle extensions without leading dot", async () => {
|
|
198
200
|
const validator = new import_path_validator.PathValidator(
|
|
199
201
|
{
|
|
200
202
|
allowedPaths: ["/home/user/project"],
|
|
@@ -208,10 +210,10 @@ const createMockLogger = () => ({
|
|
|
208
210
|
},
|
|
209
211
|
mockLogger
|
|
210
212
|
);
|
|
211
|
-
const result = validator.validatePath("/home/user/project/file.exe");
|
|
213
|
+
const result = await validator.validatePath("/home/user/project/file.exe");
|
|
212
214
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
213
215
|
});
|
|
214
|
-
(0, import_vitest.it)("should be case-insensitive for extensions", () => {
|
|
216
|
+
(0, import_vitest.it)("should be case-insensitive for extensions", async () => {
|
|
215
217
|
const validator = new import_path_validator.PathValidator(
|
|
216
218
|
{
|
|
217
219
|
allowedPaths: ["/home/user/project"],
|
|
@@ -224,12 +226,12 @@ const createMockLogger = () => ({
|
|
|
224
226
|
},
|
|
225
227
|
mockLogger
|
|
226
228
|
);
|
|
227
|
-
const result = validator.validatePath("/home/user/project/file.EXE");
|
|
229
|
+
const result = await validator.validatePath("/home/user/project/file.EXE");
|
|
228
230
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
229
231
|
});
|
|
230
232
|
});
|
|
231
233
|
(0, import_vitest.describe)("Directory Approval Checker Integration", () => {
|
|
232
|
-
(0, import_vitest.it)("should consult approval checker for external paths", () => {
|
|
234
|
+
(0, import_vitest.it)("should consult approval checker for external paths", async () => {
|
|
233
235
|
const validator = new import_path_validator.PathValidator(
|
|
234
236
|
{
|
|
235
237
|
allowedPaths: ["/home/user/project"],
|
|
@@ -242,16 +244,16 @@ const createMockLogger = () => ({
|
|
|
242
244
|
},
|
|
243
245
|
mockLogger
|
|
244
246
|
);
|
|
245
|
-
let result = validator.validatePath("/external/project/file.ts");
|
|
247
|
+
let result = await validator.validatePath("/external/project/file.ts");
|
|
246
248
|
(0, import_vitest.expect)(result.isValid).toBe(false);
|
|
247
249
|
const approvalChecker = (filePath) => {
|
|
248
250
|
return filePath.startsWith("/external/project");
|
|
249
251
|
};
|
|
250
252
|
validator.setDirectoryApprovalChecker(approvalChecker);
|
|
251
|
-
result = validator.validatePath("/external/project/file.ts");
|
|
253
|
+
result = await validator.validatePath("/external/project/file.ts");
|
|
252
254
|
(0, import_vitest.expect)(result.isValid).toBe(true);
|
|
253
255
|
});
|
|
254
|
-
(0, import_vitest.it)("should not use approval checker for config-allowed paths", () => {
|
|
256
|
+
(0, import_vitest.it)("should not use approval checker for config-allowed paths", async () => {
|
|
255
257
|
const approvalChecker = import_vitest.vi.fn().mockReturnValue(false);
|
|
256
258
|
const validator = new import_path_validator.PathValidator(
|
|
257
259
|
{
|
|
@@ -266,14 +268,14 @@ const createMockLogger = () => ({
|
|
|
266
268
|
mockLogger
|
|
267
269
|
);
|
|
268
270
|
validator.setDirectoryApprovalChecker(approvalChecker);
|
|
269
|
-
const result = validator.validatePath("/home/user/project/src/file.ts");
|
|
271
|
+
const result = await validator.validatePath("/home/user/project/src/file.ts");
|
|
270
272
|
(0, import_vitest.expect)(result.isValid).toBe(true);
|
|
271
273
|
(0, import_vitest.expect)(approvalChecker).not.toHaveBeenCalled();
|
|
272
274
|
});
|
|
273
275
|
});
|
|
274
276
|
});
|
|
275
277
|
(0, import_vitest.describe)("isPathWithinAllowed", () => {
|
|
276
|
-
(0, import_vitest.it)("should return true for paths within config-allowed directories", () => {
|
|
278
|
+
(0, import_vitest.it)("should return true for paths within config-allowed directories", async () => {
|
|
277
279
|
const validator = new import_path_validator.PathValidator(
|
|
278
280
|
{
|
|
279
281
|
allowedPaths: ["/home/user/project"],
|
|
@@ -286,12 +288,14 @@ const createMockLogger = () => ({
|
|
|
286
288
|
},
|
|
287
289
|
mockLogger
|
|
288
290
|
);
|
|
289
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("/home/user/project/src/file.ts")).toBe(
|
|
290
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("/home/user/project/deep/nested/file.ts")).toBe(
|
|
291
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed("/home/user/project/src/file.ts")).toBe(
|
|
291
292
|
true
|
|
292
293
|
);
|
|
294
|
+
(0, import_vitest.expect)(
|
|
295
|
+
await validator.isPathWithinAllowed("/home/user/project/deep/nested/file.ts")
|
|
296
|
+
).toBe(true);
|
|
293
297
|
});
|
|
294
|
-
(0, import_vitest.it)("should return false for paths outside config-allowed directories", () => {
|
|
298
|
+
(0, import_vitest.it)("should return false for paths outside config-allowed directories", async () => {
|
|
295
299
|
const validator = new import_path_validator.PathValidator(
|
|
296
300
|
{
|
|
297
301
|
allowedPaths: ["/home/user/project"],
|
|
@@ -304,10 +308,10 @@ const createMockLogger = () => ({
|
|
|
304
308
|
},
|
|
305
309
|
mockLogger
|
|
306
310
|
);
|
|
307
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("/external/project/file.ts")).toBe(false);
|
|
308
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("/home/user/other/file.ts")).toBe(false);
|
|
311
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed("/external/project/file.ts")).toBe(false);
|
|
312
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed("/home/user/other/file.ts")).toBe(false);
|
|
309
313
|
});
|
|
310
|
-
(0, import_vitest.it)("should NOT consult approval checker (used for prompting decisions)", () => {
|
|
314
|
+
(0, import_vitest.it)("should NOT consult approval checker (used for prompting decisions)", async () => {
|
|
311
315
|
const approvalChecker = import_vitest.vi.fn().mockReturnValue(true);
|
|
312
316
|
const validator = new import_path_validator.PathValidator(
|
|
313
317
|
{
|
|
@@ -322,10 +326,10 @@ const createMockLogger = () => ({
|
|
|
322
326
|
mockLogger
|
|
323
327
|
);
|
|
324
328
|
validator.setDirectoryApprovalChecker(approvalChecker);
|
|
325
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("/external/project/file.ts")).toBe(false);
|
|
329
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed("/external/project/file.ts")).toBe(false);
|
|
326
330
|
(0, import_vitest.expect)(approvalChecker).not.toHaveBeenCalled();
|
|
327
331
|
});
|
|
328
|
-
(0, import_vitest.it)("should return false for empty path", () => {
|
|
332
|
+
(0, import_vitest.it)("should return false for empty path", async () => {
|
|
329
333
|
const validator = new import_path_validator.PathValidator(
|
|
330
334
|
{
|
|
331
335
|
allowedPaths: ["/home/user/project"],
|
|
@@ -338,10 +342,10 @@ const createMockLogger = () => ({
|
|
|
338
342
|
},
|
|
339
343
|
mockLogger
|
|
340
344
|
);
|
|
341
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("")).toBe(false);
|
|
342
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed(" ")).toBe(false);
|
|
345
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed("")).toBe(false);
|
|
346
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed(" ")).toBe(false);
|
|
343
347
|
});
|
|
344
|
-
(0, import_vitest.it)("should return true when allowedPaths is empty (all paths allowed)", () => {
|
|
348
|
+
(0, import_vitest.it)("should return true when allowedPaths is empty (all paths allowed)", async () => {
|
|
345
349
|
const validator = new import_path_validator.PathValidator(
|
|
346
350
|
{
|
|
347
351
|
allowedPaths: [],
|
|
@@ -354,11 +358,11 @@ const createMockLogger = () => ({
|
|
|
354
358
|
},
|
|
355
359
|
mockLogger
|
|
356
360
|
);
|
|
357
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("/anywhere/file.ts")).toBe(true);
|
|
361
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed("/anywhere/file.ts")).toBe(true);
|
|
358
362
|
});
|
|
359
363
|
});
|
|
360
364
|
(0, import_vitest.describe)("Path Containment (Parent Directory Coverage)", () => {
|
|
361
|
-
(0, import_vitest.it)("should recognize that approving parent covers child paths", () => {
|
|
365
|
+
(0, import_vitest.it)("should recognize that approving parent covers child paths", async () => {
|
|
362
366
|
const validator = new import_path_validator.PathValidator(
|
|
363
367
|
{
|
|
364
368
|
allowedPaths: ["/external/sub"],
|
|
@@ -371,9 +375,11 @@ const createMockLogger = () => ({
|
|
|
371
375
|
},
|
|
372
376
|
mockLogger
|
|
373
377
|
);
|
|
374
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("/external/sub/deep/nested/file.ts")).toBe(
|
|
378
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed("/external/sub/deep/nested/file.ts")).toBe(
|
|
379
|
+
true
|
|
380
|
+
);
|
|
375
381
|
});
|
|
376
|
-
(0, import_vitest.it)("should not allow sibling directories", () => {
|
|
382
|
+
(0, import_vitest.it)("should not allow sibling directories", async () => {
|
|
377
383
|
const validator = new import_path_validator.PathValidator(
|
|
378
384
|
{
|
|
379
385
|
allowedPaths: ["/external/sub"],
|
|
@@ -386,9 +392,9 @@ const createMockLogger = () => ({
|
|
|
386
392
|
},
|
|
387
393
|
mockLogger
|
|
388
394
|
);
|
|
389
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("/external/other/file.ts")).toBe(false);
|
|
395
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed("/external/other/file.ts")).toBe(false);
|
|
390
396
|
});
|
|
391
|
-
(0, import_vitest.it)("should not allow parent directories when child is approved", () => {
|
|
397
|
+
(0, import_vitest.it)("should not allow parent directories when child is approved", async () => {
|
|
392
398
|
const validator = new import_path_validator.PathValidator(
|
|
393
399
|
{
|
|
394
400
|
allowedPaths: ["/external/sub/deep"],
|
|
@@ -401,7 +407,7 @@ const createMockLogger = () => ({
|
|
|
401
407
|
},
|
|
402
408
|
mockLogger
|
|
403
409
|
);
|
|
404
|
-
(0, import_vitest.expect)(validator.isPathWithinAllowed("/external/sub/file.ts")).toBe(false);
|
|
410
|
+
(0, import_vitest.expect)(await validator.isPathWithinAllowed("/external/sub/file.ts")).toBe(false);
|
|
405
411
|
});
|
|
406
412
|
});
|
|
407
413
|
(0, import_vitest.describe)("getAllowedPaths and getBlockedPaths", () => {
|