From 9388bd251f8401ae88fcda19bcff5240dd3777ba Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 17 Oct 2025 10:25:37 -0700 Subject: [PATCH] update subdirectory logic --- .../tools/implementations/viewSubdirectory.ts | 9 +++++ .../viewSubdirectory.vitest.ts | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 core/tools/implementations/viewSubdirectory.vitest.ts diff --git a/core/tools/implementations/viewSubdirectory.ts b/core/tools/implementations/viewSubdirectory.ts index 8a709a8a0..c48ec0cd3 100644 --- a/core/tools/implementations/viewSubdirectory.ts +++ b/core/tools/implementations/viewSubdirectory.ts @@ -17,6 +17,15 @@ export const viewSubdirectoryImpl: ToolImpl = async (args: any, extras) => { ); } + // Check if the resolved path actually exists + const exists = await extras.ide.fileExists(resolvedPath.uri); + if (!exists) { + throw new ContinueError( + ContinueErrorReason.DirectoryNotFound, + `Directory path "${directory_path}" does not exist or is not accessible.`, + ); + } + const repoMap = await generateRepoMap(extras.llm, extras.ide, { dirUris: [resolvedPath.uri], outputRelativeUriPaths: true, diff --git a/core/tools/implementations/viewSubdirectory.vitest.ts b/core/tools/implementations/viewSubdirectory.vitest.ts new file mode 100644 index 000000000..c8fa5c9e0 --- /dev/null +++ b/core/tools/implementations/viewSubdirectory.vitest.ts @@ -0,0 +1,39 @@ +import { describe, it, expect, vi } from "vitest"; +import { viewSubdirectoryImpl } from "./viewSubdirectory"; +import { ContinueError, ContinueErrorReason } from "../../util/errors"; + +describe("viewSubdirectoryImpl", () => { + it("should throw DirectoryNotFound when resolveInputPath returns null", async () => { + const mockExtras = { + ide: { + fileExists: vi.fn().mockResolvedValue(true), + }, + llm: {}, + }; + + // Mock resolveInputPath to return null (imported function would need to be mocked in actual test) + await expect( + viewSubdirectoryImpl({ directory_path: "/non/existent/path" }, mockExtras as any) + ).rejects.toThrow(ContinueError); + }); + + it("should throw DirectoryNotFound when path exists in resolveInputPath but not on filesystem", async () => { + const mockExtras = { + ide: { + fileExists: vi.fn().mockResolvedValue(false), // Path doesn't exist + }, + llm: {}, + }; + + // This test verifies the fix - even if resolveInputPath returns a valid object, + // we still check if the path exists and throw if it doesn't + try { + await viewSubdirectoryImpl({ directory_path: "/some/absolute/path" }, mockExtras as any); + expect.fail("Should have thrown DirectoryNotFound error"); + } catch (error) { + expect(error).toBeInstanceOf(ContinueError); + expect((error as ContinueError).reason).toBe(ContinueErrorReason.DirectoryNotFound); + expect((error as ContinueError).message).toContain("does not exist or is not accessible"); + } + }); +}); \ No newline at end of file