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.9 KB
Raw Blame
import { mkdtempSync, writeFileSync, readFileSync, rmSync, mkdirSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import assert from 'node:assert/strict'
import { runProcess } from '@orca/process-host'
import { withFreshOmpLaunch } from '../../src/shared/omp-fresh-launch'
if (process.platform !== 'win32') {
  throw new Error('Run this smoke on a Windows host')
}
const root = mkdtempSync(join(tmpdir(), 'orca-fresh-windows-'))
const config = join(root, 'fresh settings.yml')
const capture = join(root, 'calls')
const results: { shell: 'cmd' | 'powershell'; state: string; code: number; passed: boolean }[] = []
try {
  writeFileSync(join(root, 'omp.cmd'), '@echo off\r\necho %*>>"%CAPTURE%"\r\nexit /b 17\r\n')
  for (const shell of ['cmd', 'powershell'] as const) {
    for (const state of ['present', 'missing', 'unset', 'directory']) {
      rmSync(config, { force: true, recursive: true })
      rmSync(capture, { force: true })
      if (state === 'present') {
        writeFileSync(config, 'autoResume: false\n')
      }
      if (state === 'directory') {
        mkdirSync(config)
      }
      const env: NodeJS.ProcessEnv = {
        ...process.env,
        ORCA_BACKGROUND_LAUNCH: '1',
        ORCA_OMP_FRESH_CONFIG: config,
        CAPTURE: capture
      }
      if (state === 'unset') {
        delete env.ORCA_OMP_FRESH_CONFIG
      }
      const command = withFreshOmpLaunch('omp', shell, ' "task with spaces"')
      // Typed like a pane: a batch file would need the guard's `%!` written as `%%!`.
      const result = await runProcess({
        program: shell === 'cmd' ? 'cmd.exe' : 'powershell.exe',
        args:
          shell === 'cmd'
            ? ['/d']
            : [
                '-NoProfile',
                '-NonInteractive',
                '-Command',
                `function omp { $args | ConvertTo-Json -Compress | Add-Content -LiteralPath $env:CAPTURE; $global:LASTEXITCODE = 17 }; ${
                  command
                }; exit $global:LASTEXITCODE`
              ],
        input: shell === 'cmd' ? `${command}\r\nexit %errorlevel%\r\n` : undefined,
        cwd: root,
        env
      })
      assert.equal(
        result.code,
        state === 'present' ? 17 : 1,
        JSON.stringify({ shell, state, ...result })
      )
      if (state === 'present') {
        const calls = readFileSync(capture, 'utf8').trim().split(/\r?\n/)
        assert.equal(calls.length, 1)
        assert.ok(calls[0].includes('--config'))
        assert.ok(calls[0].includes('task with spaces'))
      } else {
        assert.ok(
          result.stderr.includes('fresh OMP settings are unavailable'),
          JSON.stringify(result)
        )
        assert.throws(() => readFileSync(capture))
      }
      results.push({ shell, state, code: result.code, passed: true })
    }
  }
  console.log(JSON.stringify(results))
} finally {
  rmSync(root, { recursive: true, force: true })
}