()
| 6 | import { startGatewayServer } from '../tools/model-gateway/server.mjs' |
| 7 | |
| 8 | async function main() { |
| 9 | const upstreamPort = await getFreePort() |
| 10 | const workspaceDir = await fs.mkdtemp( |
| 11 | path.join(os.tmpdir(), 'compatible-shell-smoke-'), |
| 12 | ) |
| 13 | await fs.writeFile( |
| 14 | path.join(workspaceDir, 'hello.txt'), |
| 15 | 'hello from smoke test\n', |
| 16 | 'utf8', |
| 17 | ) |
| 18 | |
| 19 | let requestCount = 0 |
| 20 | const upstreamServer = http.createServer(async (req, res) => { |
| 21 | if (req.method !== 'POST' || req.url !== '/chat/completions') { |
| 22 | res.writeHead(404) |
| 23 | res.end() |
| 24 | return |
| 25 | } |
| 26 | |
| 27 | const body = await readJson(req) |
| 28 | requestCount += 1 |
| 29 | |
| 30 | if (requestCount === 1) { |
| 31 | writeJson(res, { |
| 32 | id: 'chatcmpl_smoke_tool', |
| 33 | choices: [ |
| 34 | { |
| 35 | index: 0, |
| 36 | finish_reason: 'tool_calls', |
| 37 | message: { |
| 38 | role: 'assistant', |
| 39 | content: null, |
| 40 | tool_calls: [ |
| 41 | { |
| 42 | id: 'call_read_1', |
| 43 | type: 'function', |
| 44 | function: { |
| 45 | name: 'read_file', |
| 46 | arguments: JSON.stringify({ path: 'hello.txt' }), |
| 47 | }, |
| 48 | }, |
| 49 | ], |
| 50 | }, |
| 51 | }, |
| 52 | ], |
| 53 | usage: { |
| 54 | prompt_tokens: 10, |
| 55 | completion_tokens: 5, |
| 56 | }, |
| 57 | }) |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | const toolMessage = [...(body.messages || [])] |
| 62 | .reverse() |
| 63 | .find(message => message.role === 'tool') |
| 64 | const toolContent = |
| 65 | typeof toolMessage?.content === 'string' ? toolMessage.content.trim() : 'missing' |
no test coverage detected