MCPcopy Index your code
hub / github.com/TanStack/ai / makeFakeHandle

Function makeFakeHandle

packages/ai-opencode/tests/projection.test.ts:47–81  ·  view source on GitHub ↗

Build a fake handle that records writes, reads, and execs.

(
  execResult: ExecResult = { stdout: '', stderr: '', exitCode: 0 },
)

Source from the content-addressed store, hash-verified

45
46/** Build a fake handle that records writes, reads, and execs. */
47function 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
83const ROOT = '/workspace'
84const MARKER = `${ROOT}/.tanstack-projected-abc123`

Callers 1

projection.test.tsFile · 0.70

Calls 5

resolveMethod · 0.80
hasMethod · 0.80
setMethod · 0.65
getMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected