Build a fake handle that records writes, reads, and execs.
(
execResult: ExecResult = { stdout: '', stderr: '', exitCode: 0 },
)
| 45 | |
| 46 | /** Build a fake handle that records writes, reads, and execs. */ |
| 47 | function makeFakeHandle( |
| 48 | execResult: ExecResult = { stdout: '', stderr: '', exitCode: 0 }, |
| 49 | ): FakeHandle { |
| 50 | const writes = new Map<string, string>() |
| 51 | const reads: Array<string> = [] |
| 52 | const execs: Array<RecordedExec> = [] |
| 53 | const existing = new Set<string>() |
| 54 | |
| 55 | const handle = { |
| 56 | fs: { |
| 57 | write: (path: string, data: string | Uint8Array) => { |
| 58 | writes.set(path, typeof data === 'string' ? data : '') |
| 59 | existing.add(path) |
| 60 | return Promise.resolve() |
| 61 | }, |
| 62 | read: (path: string) => { |
| 63 | reads.push(path) |
| 64 | const content = writes.get(path) |
| 65 | if (content === undefined) |
| 66 | return Promise.reject(new Error(`not found: ${path}`)) |
| 67 | return Promise.resolve(content) |
| 68 | }, |
| 69 | exists: (path: string) => Promise.resolve(existing.has(path)), |
| 70 | mkdir: (_path: string) => Promise.resolve(), |
| 71 | }, |
| 72 | process: { |
| 73 | exec: (command: string, options?: { cwd?: string }) => { |
| 74 | execs.push({ command, cwd: options?.cwd }) |
| 75 | return Promise.resolve(execResult) |
| 76 | }, |
| 77 | }, |
| 78 | } as unknown as SandboxHandle |
| 79 | |
| 80 | return { handle, writes, reads, execs, existing } |
| 81 | } |
| 82 | |
| 83 | const ROOT = '/workspace' |
| 84 | const MARKER = `${ROOT}/.tanstack-projected-abc123` |