Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

2.6 KB
Raw Blame
// Runs under the pinned Node: load the staged node-pty, open a PTY, echo, and exit.
const { join } = require('node:path')
const { tmpdir } = require('node:os')

const [nodePtyDir, expectedVersion, ...addons] = process.argv.slice(2)
if (!nodePtyDir || !expectedVersion) {
  throw new Error('usage: orcad-prebuild-smoke-child.cjs <node-pty dir> <expected node version>')
}
if (process.version !== `v${expectedVersion}`) {
  throw new Error(`smoke must run on the pinned Node v${expectedVersion}, got ${process.version}`)
}

const pty = require(nodePtyDir)
// A compat slot's own addons: loading proves their glibc and C++ runtime needs resolve here.
for (const addon of addons) {
  require(addon)
}
if (process.platform === 'win32') {
  // Loaded only by the non-DLL kill path; prove the shipped module still loads under this Node.
  const { loadNativeModule } = require(join(nodePtyDir, 'lib', 'utils'))
  loadNativeModule('conpty_console_list')
}

const token = 'orca-prebuild-smoke-ok'

function smokeSpawn(backend, windowsOptions) {
  return new Promise((resolve) => {
    let output = ''
    let settled = false
    // Why the pinned node as the child: no shell, so no platform quoting and no cmd.exe /c.
    const child = pty.spawn(
      process.execPath,
      ['-e', `process.stdout.write(${JSON.stringify(token)})`],
      {
        name: 'xterm-color',
        cols: 80,
        rows: 24,
        cwd: tmpdir(),
        env: process.env,
        ...(process.platform === 'win32' ? windowsOptions : {})
      }
    )
    const timeout = setTimeout(() => {
      settled = true
      child.kill()
      process.stderr.write(
        `${backend} prebuild smoke timed out; output so far: ${JSON.stringify(output)}\n`
      )
      process.exit(1)
    }, 20_000)
    child.onData((data) => {
      output = `${output}${data}`.slice(-4096)
    })
    child.onExit(({ exitCode }) => {
      if (settled) {
        return
      }
      settled = true
      clearTimeout(timeout)
      if (exitCode !== 0 || !output.includes(token)) {
        process.stderr.write(
          `${backend} prebuild smoke failed: exit=${exitCode} output=${JSON.stringify(output)}\n`
        )
        process.exit(1)
      }
      resolve()
    })
  })
}

void (async () => {
  await smokeSpawn('pty', { useConptyDll: true })
  if (process.platform === 'win32') {
    // node-pty picks winpty below build 18309 (#30906); `useConpty: false` forces it on this runner.
    await smokeSpawn('winpty', { useConpty: false })
  }
  process.stdout.write(`${token} node=${process.version} napi=${process.versions.napi}\n`)
  process.exit(0)
})()