Files
orca/src/main/powershell-osc133-bootstrap.test.ts
T
OrcaWinandOrcaWin 7241fd70cf [comment audit] Shorten persistence and PTY root comments (#32303)
* chore: shorten process-host comments

* chore: audit CLI parsing and host-routing comments

* chore: remove stale host-selector restriction comment

* chore: shorten remaining CLI root comments

* Shorten CLI handler comments

* Shorten CLI runtime and command specification comments

* Shorten top-level main process A–G comments

* [comment audit] Shorten main process H–K comments

* [comment audit] Shorten main process L–O comments

* [comment audit] Shorten persistence and PTY root comments

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 11:42:22 -07:00

90 lines
3.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
encodePowerShellCommand,
getPowerShellOsc133Bootstrap
} from './powershell-osc133-bootstrap'
import { getShellLaunchConfig } from './daemon/shell-ready'
import { resolveWindowsShellLaunchArgs } from './providers/windows-shell-args'
import { STARTUP_COMMAND_FEATURES } from './shell-startup-launch-intent-fixtures'
describe('PowerShell OSC 133 bootstrap', () => {
// Bootstrap and startup commands share the EncodedCommand size limit.
it('leaves room for a long startup command to ride in the shell args', () => {
const cwd = `C:\\Users\\alice\\${'nested-project-folder\\'.repeat(5)}repo`
const result = resolveWindowsShellLaunchArgs(
'pwsh.exe',
cwd,
cwd,
undefined,
`orca ${'x'.repeat(1000)}`
)
expect(result.startupCommandDeliveredInShellArgs).toBe(true)
})
it('wraps prompt/readline without bypassing profiles or execution policy', () => {
const script = getPowerShellOsc133Bootstrap()
expect(script).toContain('[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()')
expect(script).toContain('ORCA_OPENCODE_CONFIG_DIR')
expect(script).toContain('ORCA_MIMOCODE_HOME')
expect(script).not.toContain('ORCA_PI_CODING_AGENT_DIR')
expect(script).not.toContain('ORCA_OMP_CODING_AGENT_DIR')
expect(script).toContain('ORCA_OMP_STATUS_EXTENSION')
expect(script).toContain('function Global:omp')
expect(script).toContain('--extension $env:ORCA_OMP_STATUS_EXTENSION')
expect(script).toContain('ORCA_CODEX_HOME')
expect(script).toContain('ORCA_CODEX_LAUNCH_PREFLIGHT')
expect(script).toContain('function Global:codex')
expect(script).not.toContain('$Global:__OrcaCodexExecutable')
expect(script).toContain('function Global:prompt')
expect(script).toContain('function Global:PSConsoleHostReadLine')
expect(script).toContain('Esc = [char]27')
expect(script).toContain('Bel = [char]7')
expect(script).toContain(')]133;D;$fakeExitCode$(')
expect(script).toContain(')]133;A$(')
expect(script).toContain(')]133;B$(')
expect(script).toContain(')]133;C$(')
expect(script).not.toContain('`e]133')
expect(script).not.toContain('$PROFILE')
expect(script).not.toContain('ExecutionPolicy')
expect(script).not.toContain('NoProfile')
const codexHomeRestore = script.indexOf('if ($env:ORCA_CODEX_HOME)')
expect(codexHomeRestore).toBeGreaterThan(-1)
expect(codexHomeRestore).toBeLessThan(script.indexOf('Test-Path variable:global:'))
expect(codexHomeRestore).toBeLessThan(script.indexOf('LanguageMode -eq "FullLanguage"'))
})
it('encodes commands as UTF-16LE base64 for PowerShell -EncodedCommand', () => {
expect(encodePowerShellCommand('Write-Output ok')).toBe(
Buffer.from('Write-Output ok', 'utf16le').toString('base64')
)
})
// Every launcher must deliver quotes, variables, and newlines byte for byte.
describe.each([
[
'daemon shell-ready',
() => getShellLaunchConfig('powershell.exe', STARTUP_COMMAND_FEATURES).args ?? []
],
[
'windows shell args',
() => resolveWindowsShellLaunchArgs('pwsh.exe', 'C:\\repo', 'C:\\repo').shellArgs
]
])('%s PowerShell launch', (_name, getArgs) => {
it('delivers the bootstrap unmangled', () => {
const args = getArgs()
const encodedIndex = args.indexOf('-EncodedCommand')
expect(encodedIndex).toBeGreaterThanOrEqual(0)
expect(args).not.toContain('-Command')
expect(args).not.toContain('-ExecutionPolicy')
const delivered = Buffer.from(args[encodedIndex + 1] ?? '', 'base64').toString('utf16le')
expect(delivered.startsWith(getPowerShellOsc133Bootstrap())).toBe(true)
})
})
})