import { IFileSystem } from "@/ports"; export class InMemoryFileSystem implements IFileSystem { private files = new Map(); reset(): void { this.files.clear(); } async readFile(path: string): Promise { const content = this.files.get(path); if (content === undefined) { throw new Error(`ENOENT: no such file: ${path}`); } return content; } async writeFile(path: string, content: string): Promise { this.files.set(path, content); } async deleteFile(path: string): Promise { this.files.delete(path); } async readdir(path: string): Promise { const prefix = path.endsWith("/") || path.endsWith("\\") ? path : path + "/"; const seen = new Set(); for (const key of this.files.keys()) { if (key.startsWith(prefix)) { const relative = key.slice(prefix.length); const top = relative.split(/[/\\]/)[0]; if (top) seen.add(top); } } return [...seen]; } async mkdir(_path: string): Promise { // no-op for in-memory } }