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.
79 lines
2.8 KiB
JavaScript
79 lines
2.8 KiB
JavaScript
import { mkdtemp, rm } from 'node:fs/promises'
|
|
import { createRequire } from 'node:module'
|
|
import { join, resolve } from 'node:path'
|
|
import { build } from 'vite'
|
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
import { electronViteConfig } from '../../electron.vite.config'
|
|
import { runProcess } from '@orca/process-host'
|
|
|
|
const projectDir = resolve(import.meta.dirname, '../..')
|
|
const require = createRequire(import.meta.url)
|
|
let outputDir
|
|
|
|
const smokeScript = `
|
|
const assert = require('node:assert/strict')
|
|
const { createRequire } = require('node:module')
|
|
const loaderPath = process.argv[1]
|
|
const requireFromLoader = createRequire(loaderPath)
|
|
const sdkEntry = requireFromLoader.resolve('@linear/sdk')
|
|
const { loadLinearSdk } = require(loaderPath)
|
|
assert.equal(require.cache[sdkEntry], undefined, 'SDK must remain lazy')
|
|
|
|
const sdk = loadLinearSdk()
|
|
assert.equal(sdk, requireFromLoader('@linear/sdk'))
|
|
assert.equal(loadLinearSdk(), sdk, 'repeat loads must reuse the SDK')
|
|
const client = new sdk.LinearClient({ apiKey: 'orca-offline-smoke-test' })
|
|
assert.equal(typeof client.issues, 'function')
|
|
assert.equal(typeof client.teams, 'function')
|
|
assert.ok(sdk.AuthenticationLinearError.prototype instanceof Error)
|
|
console.log('Linear SDK loaded')
|
|
`
|
|
|
|
beforeAll(async () => {
|
|
// Keep normal dependency resolution while executing outside Vitest's module loader.
|
|
outputDir = await mkdtemp(join(projectDir, 'node_modules', 'orca-linear-sdk-runtime-'))
|
|
const mainBuild = electronViteConfig.main.build
|
|
await build({
|
|
configFile: false,
|
|
publicDir: false,
|
|
logLevel: 'silent',
|
|
build: {
|
|
ssr: true,
|
|
minify: mainBuild.minify,
|
|
outDir: outputDir,
|
|
rollupOptions: {
|
|
external: mainBuild.rollupOptions.external,
|
|
input: join(projectDir, 'src/main/linear/linear-sdk.ts'),
|
|
output: { format: 'cjs', entryFileNames: 'linear-sdk.cjs' }
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
afterAll(async () => {
|
|
if (outputDir) {
|
|
await rm(outputDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 })
|
|
}
|
|
})
|
|
|
|
describe('resolved Linear SDK through the production CommonJS loader', () => {
|
|
it.each([
|
|
{ name: 'Node', program: process.execPath },
|
|
{ name: 'Electron', program: require('electron') }
|
|
])(
|
|
'loads and constructs the real SDK under $name without network access',
|
|
async ({ program }) => {
|
|
const result = await runProcess({
|
|
program,
|
|
args: ['-e', smokeScript, join(outputDir, 'linear-sdk.cjs')],
|
|
cwd: projectDir,
|
|
env: { ...process.env, ORCA_BACKGROUND_LAUNCH: '1', ELECTRON_RUN_AS_NODE: '1' },
|
|
timeoutMs: 20000
|
|
})
|
|
expect(result.code, result.stderr).toBe(0)
|
|
expect(result.timedOut).toBe(false)
|
|
expect(result.stdout.trim()).toBe('Linear SDK loaded')
|
|
}
|
|
)
|
|
})
|