Skip to content

Commit 56c79bd

Browse files
cliffhallclaude
andcommitted
test(filesystem): drive the device-name validatePath cases through the tools
Calling validatePath directly ties the test to its signature, which the read-only-directories change (#5348) extends with an access mode. The two cases (an absolute device path reports the device refusal rather than 'outside allowed directories'; a relative trailing-dot path is refused) now go through read_text_file over the in-memory client, so they hold in either merge order. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent f5925bd commit 56c79bd

1 file changed

Lines changed: 33 additions & 15 deletions

File tree

‎src/filesystem/__tests__/windows-reserved-names.test.ts‎

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const {
2121
isPathWithinAllowedDirectories,
2222
namesWindowsDevice,
2323
} = await import("../path-validation.js");
24-
const { validatePath } = await import("../lib.js");
2524
const { call, connect, quietStderr, textOf } = await import("./helpers.js");
2625

2726
const realPlatform = process.platform;
@@ -207,20 +206,6 @@ describe("isPathWithinAllowedDirectories on win32 refuses device names and trail
207206
});
208207
});
209208

210-
describe("validatePath on win32 refuses device names and trailing dots or spaces", () => {
211-
it("reports the device refusal, not 'outside allowed directories'", async () => {
212-
await expect(validatePath("C:\\work\\NUL", ["C:\\work"])).rejects.toThrow(
213-
DEVICE,
214-
);
215-
});
216-
217-
it("refuses a relative path with a trailing dot", async () => {
218-
await expect(validatePath("notes.txt.", ["C:\\work"])).rejects.toThrow(
219-
TRAILING,
220-
);
221-
});
222-
});
223-
224209
describe("the tools on win32 refuse device names and trailing dots or spaces", () => {
225210
it("returns each refusal as a tool error", async () => {
226211
quietStderr();
@@ -243,4 +228,37 @@ describe("the tools on win32 refuse device names and trailing dots or spaces", (
243228
vi.restoreAllMocks();
244229
}
245230
});
231+
232+
// validatePath runs these checks before the containment check, so the
233+
// error names the reason rather than "outside allowed directories".
234+
it("reports the device refusal, not 'outside allowed directories'", async () => {
235+
quietStderr();
236+
const conn = await connect(["C:\\work"]);
237+
try {
238+
const result = await call(conn.client, "read_text_file", {
239+
path: "C:\\work\\NUL",
240+
});
241+
expect(result.isError).toBe(true);
242+
expect(textOf(result)).toMatch(DEVICE);
243+
expect(textOf(result)).not.toMatch(/outside allowed directories/);
244+
} finally {
245+
await conn.close();
246+
vi.restoreAllMocks();
247+
}
248+
});
249+
250+
it("refuses a relative path with a trailing dot", async () => {
251+
quietStderr();
252+
const conn = await connect(["C:\\work"]);
253+
try {
254+
const result = await call(conn.client, "read_text_file", {
255+
path: "notes.txt.",
256+
});
257+
expect(result.isError).toBe(true);
258+
expect(textOf(result)).toMatch(TRAILING);
259+
} finally {
260+
await conn.close();
261+
vi.restoreAllMocks();
262+
}
263+
});
246264
});

0 commit comments

Comments
 (0)