mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
Extract subprocess execution and process contracts into @orca/process-host with explicit public entry points, independent checks, and one Node 18 compatible CommonJS runtime. Migrate application consumers and integrate package builds, dependency selection, import enforcement, and runtime resource staging. Preserve daemon startup ownership and profile isolation, and qualify development rebuild recovery and concurrent output publication. Remove unnecessary aliases, test forwarding exports, and a duplicate output scan. Validation: full typechecks, changed-code quality, package and artifact checks, native Windows builds/types plus 306 runtime tests, and independent native reviews. Matched full E2E controls on original main and unchanged reviewed head both pass all 17 applicable tests (nine skips). Earlier intermittent E2E failures are documented in the PR; no assertions were weakened. The final combined-tree audit preserves both branches with no import-boundary violations.
73 lines
2.6 KiB
JavaScript
73 lines
2.6 KiB
JavaScript
import { createRequire } from 'node:module'
|
|
import path from 'node:path'
|
|
import { pathToFileURL } from 'node:url'
|
|
import { assertPackagedNodePtyCapability } from './packaged-node-pty-capability-oracle.mjs'
|
|
|
|
const EVIDENCE_PREFIX = 'ORCA_NODE_PTY_CAPABILITY_EVIDENCE='
|
|
const PROBE_TIMEOUT_MS = 45_000
|
|
const MAX_DIAGNOSTIC_CHARS = 8_000
|
|
|
|
function executableArgument(argv) {
|
|
const value = argv.find((arg) => arg.startsWith('--exe='))?.slice('--exe='.length)
|
|
if (!value) {
|
|
throw new Error('usage: windows-pty-native-capability-smoke --exe=<packaged Orca.exe>')
|
|
}
|
|
return path.resolve(value)
|
|
}
|
|
|
|
export function checkoutRunProcessPath() {
|
|
return createRequire(import.meta.url).resolve('@orca/process-host')
|
|
}
|
|
|
|
export function packagedProbeInvocation(executable, environment = process.env) {
|
|
const resolvedExecutable = path.resolve(executable)
|
|
const resourcesDir = path.join(path.dirname(resolvedExecutable), 'resources')
|
|
const probe = path.join(import.meta.dirname, 'packaged-node-pty-capability-probe.cjs')
|
|
return {
|
|
program: resolvedExecutable,
|
|
args: [probe, '--exercise', resourcesDir, process.execPath],
|
|
env: { ...environment, ELECTRON_RUN_AS_NODE: '1' },
|
|
timeoutMs: PROBE_TIMEOUT_MS
|
|
}
|
|
}
|
|
|
|
function diagnosticTail(value) {
|
|
return value.length <= MAX_DIAGNOSTIC_CHARS ? value : value.slice(-MAX_DIAGNOSTIC_CHARS)
|
|
}
|
|
|
|
export function formatProbeFailure(result) {
|
|
return [
|
|
`packaged native capability probe failed (code=${result.code}, timedOut=${result.timedOut})`,
|
|
`stdout:\n${diagnosticTail(result.stdout) || '<empty>'}`,
|
|
`stderr:\n${diagnosticTail(result.stderr) || '<empty>'}`
|
|
].join('\n')
|
|
}
|
|
|
|
function parseEvidence(stdout) {
|
|
const line = stdout.split(/\r?\n/).find((candidate) => candidate.startsWith(EVIDENCE_PREFIX))
|
|
if (!line) {
|
|
throw new Error(`packaged probe did not emit ${EVIDENCE_PREFIX}`)
|
|
}
|
|
return JSON.parse(line.slice(EVIDENCE_PREFIX.length))
|
|
}
|
|
|
|
async function main() {
|
|
if (process.platform !== 'win32') {
|
|
throw new Error('windows-pty-native-capability-smoke requires a physical Windows host')
|
|
}
|
|
const executable = executableArgument(process.argv.slice(2))
|
|
const require = createRequire(import.meta.url)
|
|
const { runProcess } = require(checkoutRunProcessPath())
|
|
const result = await runProcess(packagedProbeInvocation(executable))
|
|
if (result.code !== 0 || result.timedOut) {
|
|
throw new Error(formatProbeFailure(result))
|
|
}
|
|
|
|
assertPackagedNodePtyCapability(parseEvidence(result.stdout))
|
|
process.stdout.write(`[windows-pty-native-capability-smoke] PASS ${executable}\n`)
|
|
}
|
|
|
|
if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
|
|
await main()
|
|
}
|