mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
Fix the MetaDataScanner.test.ts infinite recursion in its mock setup
This commit is contained in:
parent
876742a887
commit
92c55d542e
1 changed files with 31 additions and 23 deletions
|
|
@ -45,23 +45,6 @@ describe("MetadataScanner", () => {
|
||||||
|
|
||||||
describe("Basic Metadata Scanning", () => {
|
describe("Basic Metadata Scanning", () => {
|
||||||
it("should discover components with English metadata", async () => {
|
it("should discover components with English metadata", async () => {
|
||||||
// Mock directory structure
|
|
||||||
const mockDirents = [
|
|
||||||
{
|
|
||||||
name: "component1",
|
|
||||||
isDirectory: () => true,
|
|
||||||
isFile: () => false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "metadata.en.yml",
|
|
||||||
isDirectory: () => false,
|
|
||||||
isFile: () => true,
|
|
||||||
},
|
|
||||||
] as Dirent[]
|
|
||||||
|
|
||||||
// For subdirectories, return empty to prevent infinite recursion
|
|
||||||
const mockEmptyDirents = [] as Dirent[]
|
|
||||||
|
|
||||||
// Setup mock implementations
|
// Setup mock implementations
|
||||||
const mockStats = {
|
const mockStats = {
|
||||||
isDirectory: () => true,
|
isDirectory: () => true,
|
||||||
|
|
@ -72,14 +55,39 @@ describe("MetadataScanner", () => {
|
||||||
// Mock fs.promises methods using type assertions
|
// Mock fs.promises methods using type assertions
|
||||||
const mockedFs = jest.mocked(fs)
|
const mockedFs = jest.mocked(fs)
|
||||||
mockedFs.stat.mockResolvedValue(mockStats)
|
mockedFs.stat.mockResolvedValue(mockStats)
|
||||||
;(mockedFs.readdir as any).mockImplementation(async (path: any, options?: any) => {
|
|
||||||
// Return empty array for nested component1 directories to prevent recursion
|
// Define specific Dirent objects
|
||||||
if (path.toString().includes("/component1/")) {
|
const componentDirDirent: Dirent = {
|
||||||
return options?.withFileTypes ? mockEmptyDirents : []
|
name: "component1",
|
||||||
|
isDirectory: () => true,
|
||||||
|
isFile: () => false,
|
||||||
|
} as Dirent
|
||||||
|
const metadataFileDirent: Dirent = {
|
||||||
|
name: "metadata.en.yml",
|
||||||
|
isDirectory: () => false,
|
||||||
|
isFile: () => true,
|
||||||
|
} as Dirent
|
||||||
|
|
||||||
|
// Refined mock implementation for fs.readdir
|
||||||
|
;(mockedFs.readdir as any).mockImplementation(async (p: string, options?: any) => {
|
||||||
|
const normalizedP = normalizePath(p)
|
||||||
|
const normalizedBasePath = normalizePath(mockBasePath)
|
||||||
|
const normalizedComponentPath = normalizePath(path.join(mockBasePath, "component1"))
|
||||||
|
|
||||||
|
if (normalizedP === normalizedBasePath) {
|
||||||
|
// For the base path, return only the component directory
|
||||||
|
const baseDirents = [componentDirDirent]
|
||||||
|
return options?.withFileTypes ? baseDirents : baseDirents.map((d) => d.name)
|
||||||
|
} else if (normalizedP === normalizedComponentPath) {
|
||||||
|
// For the component1 directory, return only the metadata file
|
||||||
|
const componentDirents = [metadataFileDirent]
|
||||||
|
return options?.withFileTypes ? componentDirents : componentDirents.map((d) => d.name)
|
||||||
|
} else {
|
||||||
|
// For any other path (deeper recursion), return empty
|
||||||
|
return options?.withFileTypes ? [] : []
|
||||||
}
|
}
|
||||||
// Return full directory listing for base component1 directory
|
|
||||||
return options?.withFileTypes ? mockDirents : mockDirents.map((d) => d.name)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
mockedFs.readFile.mockResolvedValue(
|
mockedFs.readFile.mockResolvedValue(
|
||||||
Buffer.from(`
|
Buffer.from(`
|
||||||
name: Test Component
|
name: Test Component
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue