smoke-inference.mjs
sha256:c88bf098b52c796e46edc39ec71f9f0627d305439b73972d3fada73cefde0da9
fix: put release binaries before lipo architecture checks
Human
minor
⚠ breaking
26 days ago
| 1 | #!/usr/bin/env node |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { fork } from 'node:child_process'; |
| 4 | import path from 'node:path'; |
| 5 | import process from 'node:process'; |
| 6 | |
| 7 | const runtimeIndex = process.argv.indexOf('--runtime'); |
| 8 | if (runtimeIndex < 0 || !process.argv[runtimeIndex + 1]) throw new Error('missing --runtime'); |
| 9 | const runtimeRoot = path.resolve(process.argv[runtimeIndex + 1]); |
| 10 | const worker = fork(path.join(runtimeRoot, 'companion/runtime/inference-worker.mjs'), [runtimeRoot], { |
| 11 | execPath: path.join(runtimeRoot, 'node/bin/node'), |
| 12 | execArgv: ['--permission', `--allow-fs-read=${runtimeRoot}`], |
| 13 | env: { PATH: '/usr/bin:/bin:/usr/sbin:/sbin', LANG: 'en_US.UTF-8', TMPDIR: '/tmp' }, |
| 14 | stdio: ['ignore', 'ignore', 'inherit', 'ipc'], |
| 15 | }); |
| 16 | |
| 17 | const timeout = setTimeout(() => { |
| 18 | worker.kill('SIGKILL'); |
| 19 | throw new Error('inference smoke test timed out'); |
| 20 | }, 90_000); |
| 21 | |
| 22 | try { |
| 23 | await new Promise((resolve, reject) => { |
| 24 | worker.once('error', reject); |
| 25 | worker.once('exit', (code, signal) => reject(new Error(`worker exited before ready: ${code ?? signal}`))); |
| 26 | const ready = (message) => { |
| 27 | if (message?.ready !== true) return; |
| 28 | worker.off('message', ready); |
| 29 | resolve(); |
| 30 | }; |
| 31 | worker.on('message', ready); |
| 32 | }); |
| 33 | const result = await new Promise((resolve, reject) => { |
| 34 | worker.once('error', reject); |
| 35 | const receive = (message) => { |
| 36 | if (message?.id !== 'smoke') return; |
| 37 | worker.off('message', receive); |
| 38 | if (message.ok) resolve(message.result); |
| 39 | else reject(new Error(message.error)); |
| 40 | }; |
| 41 | worker.on('message', receive); |
| 42 | worker.send({ id: 'smoke', command: 'embed', arguments: { texts: ['Knowtation'] } }); |
| 43 | }); |
| 44 | assert.equal(result.vectors.length, 1); |
| 45 | assert.equal(result.vectors[0].length, 384); |
| 46 | assert.ok(result.vectors[0].every(Number.isFinite)); |
| 47 | const norm = Math.sqrt(result.vectors[0].reduce((sum, value) => sum + value * value, 0)); |
| 48 | assert.ok(Math.abs(norm - 1) < 1e-5); |
| 49 | console.log(JSON.stringify({ ok: true, dimensions: 384 })); |
| 50 | } finally { |
| 51 | clearTimeout(timeout); |
| 52 | worker.kill('SIGTERM'); |
| 53 | } |
File History
1 commit
sha256:c88bf098b52c796e46edc39ec71f9f0627d305439b73972d3fada73cefde0da9
fix: put release binaries before lipo architecture checks
Human
minor
⚠
26 days ago