Skip to content

Commit cb86793

Browse files
test(sdk): cover missing list_directory targets
1 parent b8caa3a commit cb86793

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

sdk/src/__tests__/list-directory.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,39 @@ describe('listDirectory', () => {
8484
})
8585
})
8686

87+
it('returns the normal list error when the requested directory is missing', async () => {
88+
const missingPath = path.join(PROJECT_ROOT, 'missing')
89+
const readdir = mock(async (_path: PathLike) => [] as Dirent[])
90+
const fs = {
91+
realpath: mock(async (requestedPath: PathLike) => {
92+
const requestedPathString = String(requestedPath)
93+
if (requestedPathString === missingPath) {
94+
throw new Error(
95+
`ENOENT: no such file or directory, realpath '${missingPath}'`,
96+
)
97+
}
98+
return requestedPathString
99+
}),
100+
readdir,
101+
} as unknown as CodebuffFileSystem
102+
103+
const result = await listDirectory({
104+
directoryPath: 'missing',
105+
projectPath: PROJECT_ROOT,
106+
fs,
107+
})
108+
109+
expect(result).toEqual([
110+
{
111+
type: 'json',
112+
value: {
113+
errorMessage: `Failed to list directory: ENOENT: no such file or directory, realpath '${missingPath}'`,
114+
},
115+
},
116+
])
117+
expect(readdir).not.toHaveBeenCalled()
118+
})
119+
87120
it('rejects sibling paths that only share the project prefix', async () => {
88121
const siblingPath = path.resolve(PROJECT_ROOT, '..', 'project-evil')
89122
const { fs, readdir } = createFs({

0 commit comments

Comments
 (0)