| 24 | import { buildSshToolSpecs } from '@/executor/handlers/pi/ssh-tools' |
| 25 | |
| 26 | function createSession(files: Record<string, string>): PiSshSession { |
| 27 | const sftp = { |
| 28 | readFile: (path: string, cb: (err: Error | undefined, data: Buffer) => void) => { |
| 29 | if (!(path in files)) { |
| 30 | cb(new Error(`no such file: ${path}`), Buffer.from('')) |
| 31 | return |
| 32 | } |
| 33 | cb(undefined, Buffer.from(files[path])) |
| 34 | }, |
| 35 | writeFile: (path: string, data: string, cb: (err?: Error) => void) => { |
| 36 | files[path] = data |
| 37 | cb(undefined) |
| 38 | }, |
| 39 | } |
| 40 | return { |
| 41 | client: {} as PiSshSession['client'], |
| 42 | sftp: sftp as unknown as PiSshSession['sftp'], |
| 43 | close: vi.fn(), |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | function getTool(repoPath: string, files: Record<string, string>, name: string) { |
| 48 | const tools = buildSshToolSpecs(createSession(files), repoPath) |