mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 16:47:34 +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.
111 lines
3.6 KiB
TypeScript
111 lines
3.6 KiB
TypeScript
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
import { createRequire } from 'node:module'
|
|
import { tmpdir } from 'node:os'
|
|
import { join, resolve } from 'node:path'
|
|
import { resolveConfig } from 'electron-vite'
|
|
import { build } from 'vite'
|
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
import { runProcess } from '@orca/process-host'
|
|
import { stagePackagedProcessHost } from './packaged-process-host-fixture.mjs'
|
|
|
|
const projectDir = resolve(import.meta.dirname, '../..')
|
|
const require = createRequire(import.meta.url)
|
|
let outputDir: string
|
|
|
|
beforeAll(async () => {
|
|
outputDir = mkdtempSync(join(tmpdir(), 'orca-account-runtime-'))
|
|
const resolved = await resolveConfig(
|
|
{ configFile: join(projectDir, 'electron.vite.config.ts') },
|
|
'build',
|
|
'production'
|
|
)
|
|
const main = resolved.config?.main
|
|
if (!main?.build) {
|
|
throw new Error('Expected main-process build config')
|
|
}
|
|
await build({
|
|
...main,
|
|
logLevel: 'silent',
|
|
build: {
|
|
...main.build,
|
|
outDir: join(outputDir, 'bundle'),
|
|
sourcemap: false,
|
|
rollupOptions: {
|
|
...main.build.rollupOptions,
|
|
input: join(projectDir, 'src/main/managed-data-accounts/credential-capture.ts'),
|
|
output: { format: 'cjs', entryFileNames: 'credential-capture.cjs' }
|
|
}
|
|
}
|
|
})
|
|
await stagePackagedProcessHost(outputDir)
|
|
mkdirSync(join(outputDir, 'source', 'devin'), { recursive: true })
|
|
writeFileSync(
|
|
join(outputDir, 'source', 'devin', 'credentials.toml'),
|
|
'windsurf_api_key = "offline-account-runtime-fixture"\n'
|
|
)
|
|
})
|
|
|
|
afterAll(() => {
|
|
if (outputDir) {
|
|
rmSync(outputDir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
describe('managed account credentials in the production main bundle', () => {
|
|
it.each([
|
|
{ name: 'Node', program: process.execPath },
|
|
{ name: 'Electron', program: require('electron') }
|
|
])(
|
|
'captures Devin credentials under $name outside the dependency install',
|
|
async ({ name, program }) => {
|
|
const environment: Record<string, string | undefined> = {
|
|
...process.env,
|
|
ORCA_BACKGROUND_LAUNCH: '1',
|
|
NODE_PATH: '',
|
|
NODE_OPTIONS: '',
|
|
ELECTRON_RUN_AS_NODE: '1'
|
|
}
|
|
for (const key of [
|
|
'HOME',
|
|
'XDG_CONFIG_HOME',
|
|
'XDG_DATA_HOME',
|
|
'XDG_STATE_HOME',
|
|
'XDG_CACHE_HOME'
|
|
]) {
|
|
const directory = join(outputDir, name, key)
|
|
mkdirSync(directory, { recursive: true })
|
|
environment[key] = directory
|
|
}
|
|
const script = `
|
|
const assert = require('node:assert/strict')
|
|
const { captureDataAccountCredentials } = require(process.argv[1])
|
|
captureDataAccountCredentials('devin', process.argv[2], process.argv[3])
|
|
.then((integrations) => {
|
|
assert.deepEqual(integrations, ['devin'])
|
|
console.log('Private credentials captured')
|
|
}).catch((error) => { console.error(error); process.exitCode = 1 })
|
|
`
|
|
const destination = join(outputDir, name, 'captured')
|
|
const result = await runProcess({
|
|
program,
|
|
args: [
|
|
'-e',
|
|
script,
|
|
join(outputDir, 'bundle', 'credential-capture.cjs'),
|
|
join(outputDir, 'source'),
|
|
destination
|
|
],
|
|
cwd: outputDir,
|
|
env: environment,
|
|
timeoutMs: 20000
|
|
})
|
|
expect(result.code, result.stderr).toBe(0)
|
|
expect(result.timedOut).toBe(false)
|
|
expect(result.stdout.trim()).toBe('Private credentials captured')
|
|
expect(readFileSync(join(destination, 'devin', 'credentials.toml'), 'utf8')).toContain(
|
|
'offline-account-runtime-fixture'
|
|
)
|
|
}
|
|
)
|
|
})
|