mirror of
https://github.com/stablyai/orca.git
synced 2026-10-22 16:03:47 +00:00
The packaged Windows `orca.exe` launcher read `ProcessStartInfo.EnvironmentVariables`, whose lazy getter copies the case-sensitive process block into a case-insensitive dictionary via `.Add`. An inherited block carrying both `PATH` and `Path` threw `ArgumentException: Item has already been added. Key in dictionary: 'PATH'`, so every `orca` invocation exited 1 before Electron started (native/windows-cli-launcher/OrcaCliLauncher.cs:46, printed at :67). The launcher now mutates its own environment with `Environment.SetEnvironmentVariable` and never touches either `ProcessStartInfo` env property, so `CreateProcess` passes a NULL environment block and the child inherits the live one verbatim. Orca was also minting the duplicate itself. `applyTerminalAttributionEnv` read `baseEnv.PATH` and unconditionally wrote `baseEnv.PATH`, so a Windows PTY that inherited `Path` got a second spelling; which one the child resolved was non-deterministic. `createLaunchEnv` did the same and, because its read always missed on Windows, shipped Agent Teams terminals a `PATH` containing only the tmux shim dir. `resolvePathEnvKey` (extracted from the existing precedent in windows-environment-path.ts) now drives every PATH read and write in the PTY env pipeline, and attribution collapses Windows onto the single OS-resolved spelling. Off Windows the resolver always returns `PATH`, so POSIX behavior is unchanged and a case-sensitive POSIX `Path` variable is never touched. Closes #12046
107 lines
4.0 KiB
JavaScript
107 lines
4.0 KiB
JavaScript
import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { dirname, join, resolve } from 'node:path'
|
|
import { spawnSync } from 'node:child_process'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
const itCrossHost = process.platform === 'win32' ? it.skip : it
|
|
const projectRoot = resolve(import.meta.dirname, '../..')
|
|
// Why: cold csc.exe startup exceeds Vitest's 5s unit budget on hosted Windows;
|
|
// keep the larger allowance scoped to the real compiler integration test.
|
|
function itWindows(name, test) {
|
|
const runner = process.platform === 'win32' ? it : it.skip
|
|
runner(name, { timeout: 15_000 }, test)
|
|
}
|
|
|
|
describe('Windows CLI launcher', () => {
|
|
itCrossHost('fails closed when the Windows launcher cannot be compiled on this host', () => {
|
|
const outputRoot = mkdtempSync(join(tmpdir(), 'orca cross-host launcher '))
|
|
try {
|
|
const result = spawnSync(
|
|
process.execPath,
|
|
['config/scripts/build-windows-cli-launcher.mjs', '--output', join(outputRoot, 'orca.exe')],
|
|
{ cwd: projectRoot, encoding: 'utf8' }
|
|
)
|
|
|
|
expect(result.status).not.toBe(0)
|
|
expect(result.stderr).toContain('Windows CLI launcher')
|
|
expect(result.stderr).toContain('Windows host')
|
|
} finally {
|
|
rmSync(outputRoot, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
itCrossHost('never materializes the child environment block from ProcessStartInfo', () => {
|
|
// Why: both ProcessStartInfo env properties copy the process block into a case-insensitive
|
|
// dictionary that throws when the inherited block holds PATH and Path (stablyai/orca#12046).
|
|
const source = readFileSync(
|
|
join(projectRoot, 'native', 'windows-cli-launcher', 'OrcaCliLauncher.cs'),
|
|
'utf8'
|
|
)
|
|
const code = source.replace(/^\s*\/\/.*$/gm, '')
|
|
|
|
expect(code).not.toContain('EnvironmentVariables')
|
|
expect(code).not.toContain('startInfo.Environment')
|
|
expect(code).toContain('Environment.SetEnvironmentVariable')
|
|
})
|
|
|
|
itWindows('preserves a multiline argument from PowerShell through the native launcher', () => {
|
|
const appRoot = mkdtempSync(join(tmpdir(), 'orca cli launcher '))
|
|
try {
|
|
const resourcesPath = join(appRoot, 'resources')
|
|
const launcherPath = join(resourcesPath, 'bin', 'orca.exe')
|
|
const cliPath = join(resourcesPath, 'app.asar.unpacked', 'out', 'cli', 'index.js')
|
|
mkdirSync(join(resourcesPath, 'bin'), { recursive: true })
|
|
mkdirSync(dirname(cliPath), { recursive: true })
|
|
copyFileSync(process.execPath, join(appRoot, 'Orca.exe'))
|
|
writeFileSync(
|
|
cliPath,
|
|
`process.stdout.write(JSON.stringify({
|
|
argv: process.argv.slice(2),
|
|
electronRunAsNode: process.env.ELECTRON_RUN_AS_NODE,
|
|
nodeOptions: process.env.NODE_OPTIONS ?? null,
|
|
orcaNodeOptions: process.env.ORCA_NODE_OPTIONS ?? null
|
|
}))\n`,
|
|
'utf8'
|
|
)
|
|
|
|
const build = spawnSync(
|
|
process.execPath,
|
|
['config/scripts/build-windows-cli-launcher.mjs', '--output', launcherPath],
|
|
{ cwd: projectRoot, encoding: 'utf8' }
|
|
)
|
|
expect(build.status, `${build.stdout}\n${build.stderr}`).toBe(0)
|
|
|
|
const body = 'paragraph one line one\nparagraph one line two\n\nparagraph two'
|
|
const powershell = spawnSync(
|
|
'powershell.exe',
|
|
[
|
|
'-NoProfile',
|
|
'-NonInteractive',
|
|
'-Command',
|
|
'& $env:ORCA_TEST_LAUNCHER orchestration send --body $env:ORCA_TEST_BODY --json'
|
|
],
|
|
{
|
|
encoding: 'utf8',
|
|
env: {
|
|
...process.env,
|
|
NODE_OPTIONS: '--no-warnings',
|
|
ORCA_TEST_BODY: body,
|
|
ORCA_TEST_LAUNCHER: launcherPath
|
|
}
|
|
}
|
|
)
|
|
|
|
expect(powershell.status, powershell.stderr).toBe(0)
|
|
expect(JSON.parse(powershell.stdout)).toEqual({
|
|
argv: ['orchestration', 'send', '--body', body, '--json'],
|
|
electronRunAsNode: '1',
|
|
nodeOptions: null,
|
|
orcaNodeOptions: '--no-warnings'
|
|
})
|
|
} finally {
|
|
rmSync(appRoot, { recursive: true, force: true })
|
|
}
|
|
})
|
|
})
|