docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
Build a utility that inspects and analyzes the internal structure of a memory-based filesystem. Your implementation should be able to traverse the filesystem and collect information about different types of nodes (directories, files, and symbolic links), including their properties and relationships.
Your solution should:
Create a module inspector.js that exports a function analyzeFilesystem(fs, rootPath):
fs: An instance of the memory filesystemrootPath: The starting path to analyze (e.g., '/'){
totalDirectories: <number>,
totalFiles: <number>,
totalSymlinks: <number>,
symlinks: [{ path: <string>, target: <string> }, ...],
files: [{ path: <string>, size: <number> }, ...]
}Create a test file inspector.test.js with the following test cases:
// Setup: Create a simple filesystem with one directory, one file, and one symlink
// /testdir/
// /testdir/file.txt (content: "hello world")
// /link -> /testdir/file.txt
// Expected output:
{
totalDirectories: 2, // root + testdir
totalFiles: 1,
totalSymlinks: 1,
symlinks: [{ path: '/link', target: '/testdir/file.txt' }],
files: [{ path: '/testdir/file.txt', size: 11 }]
}// Setup: Create nested directory structure
// /a/
// /a/b/
// /a/b/c/
// /a/b/c/data.txt (content: "test")
// Expected output:
{
totalDirectories: 4, // root + a + b + c
totalFiles: 1,
totalSymlinks: 0,
symlinks: [],
files: [{ path: '/a/b/c/data.txt', size: 4 }]
}// Setup: Mixed filesystem structure
// /docs/
// /docs/readme.md (content: "documentation")
// /docs/guide.md (content: "instructions")
// /config.json (content: "{}")
// /readme -> /docs/readme.md
// Expected output:
{
totalDirectories: 2, // root + docs
totalFiles: 3,
totalSymlinks: 1,
symlinks: [{ path: '/readme', target: '/docs/readme.md' }],
files: [
{ path: '/docs/readme.md', size: 13 },
{ path: '/docs/guide.md', size: 12 },
{ path: '/config.json', size: 2 }
]
}Provides an in-memory filesystem implementation for testing purposes.