mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +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.
133 lines
4.9 KiB
JavaScript
133 lines
4.9 KiB
JavaScript
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { expect, it } from 'vitest'
|
|
import { runProcessSync } from '@orca/process-host'
|
|
import { FULL_SHARD_COUNT } from './ci-unit-selection.mjs'
|
|
|
|
it.each([
|
|
{ withParent: true, unresolvedPackage: false },
|
|
{ withParent: false, unresolvedPackage: false },
|
|
{ withParent: true, unresolvedPackage: true }
|
|
])(
|
|
'plans from a real Git diff, retaining full coverage for incomplete package evidence: %j',
|
|
({ withParent, unresolvedPackage }) => {
|
|
const root = mkdtempSync(join(tmpdir(), 'orca-unit-plan-'))
|
|
const git = (args) => {
|
|
const result = runProcessSync({ program: 'git', args, cwd: root })
|
|
expect(result.code, result.stderr).toBe(0)
|
|
return result.stdout.trim()
|
|
}
|
|
try {
|
|
mkdirSync(join(root, 'src'))
|
|
writeFileSync(join(root, 'src/value.ts'), 'export const value = 1')
|
|
writeFileSync(
|
|
join(root, 'src/consumer.test.ts'),
|
|
unresolvedPackage ? "import '@orca/missing-package'" : "import './value'"
|
|
)
|
|
writeFileSync(join(root, 'src/unrelated.test.ts'), 'export const unrelated = true')
|
|
git(['init', '--quiet'])
|
|
git(['add', 'src'])
|
|
const commit = [
|
|
'-c',
|
|
'user.name=CI Test',
|
|
'-c',
|
|
'user.email=ci-test@example.invalid',
|
|
'-c',
|
|
'commit.gpgsign=false',
|
|
'commit',
|
|
'--quiet',
|
|
'-m',
|
|
'fixture'
|
|
]
|
|
git(commit)
|
|
if (withParent) {
|
|
writeFileSync(join(root, 'src/value.ts'), 'export const value = 2')
|
|
git(['add', 'src'])
|
|
git(commit)
|
|
}
|
|
const sourceSha = git(['rev-parse', 'HEAD'])
|
|
const eventPath = join(root, 'event.json')
|
|
writeFileSync(eventPath, JSON.stringify({ pull_request: { draft: true } }))
|
|
const result = runProcessSync({
|
|
program: process.execPath,
|
|
args: [fileURLToPath(new URL('./ci-unit-plan.mjs', import.meta.url))],
|
|
cwd: root,
|
|
env: {
|
|
...process.env,
|
|
ORCA_BACKGROUND_LAUNCH: '1',
|
|
ORCA_UNIT_SELECTION_MODE: 'selected',
|
|
GITHUB_EVENT_NAME: 'pull_request',
|
|
GITHUB_EVENT_PATH: eventPath,
|
|
GITHUB_SHA: sourceSha,
|
|
ORCA_SHARD_SOURCE_SHA: sourceSha,
|
|
GITHUB_OUTPUT: join(root, 'outputs'),
|
|
GITHUB_STEP_SUMMARY: join(root, 'summary')
|
|
}
|
|
})
|
|
expect(result.code, result.stderr).toBe(0)
|
|
const plan = JSON.parse(readFileSync(join(root, 'ci-shards/unit-selection.json'), 'utf8'))
|
|
expect(plan.sourceSha).toBe(sourceSha)
|
|
const selected = withParent && !unresolvedPackage
|
|
expect(plan.mode).toBe(selected ? 'selected' : 'shadow')
|
|
expect(plan.executionFiles).toEqual(
|
|
selected ? ['src/consumer.test.ts'] : ['src/consumer.test.ts', 'src/unrelated.test.ts']
|
|
)
|
|
expect(plan.reason).toBe(
|
|
!withParent
|
|
? 'Error: Changed paths unavailable'
|
|
: unresolvedPackage
|
|
? 'Error: No public orca-source export for @orca/missing-package'
|
|
: 'Transitive imports plus indirect-input consumers'
|
|
)
|
|
expect(plan.shards).toHaveLength(selected ? 1 : FULL_SHARD_COUNT)
|
|
} finally {
|
|
rmSync(root, { recursive: true, force: true })
|
|
}
|
|
}
|
|
)
|
|
|
|
it.each(['5', '10', 'invalid'])(
|
|
'validates the requested full shard count and keeps fallback coverage: %s',
|
|
(requestedCount) => {
|
|
const root = mkdtempSync(join(tmpdir(), 'orca-unit-count-'))
|
|
try {
|
|
mkdirSync(join(root, 'src'))
|
|
writeFileSync(join(root, 'src/retained.test.ts'), 'export const retained = true')
|
|
const eventPath = join(root, 'event.json')
|
|
writeFileSync(eventPath, '{}')
|
|
const result = runProcessSync({
|
|
program: process.execPath,
|
|
args: [fileURLToPath(new URL('./ci-unit-plan.mjs', import.meta.url))],
|
|
cwd: root,
|
|
env: {
|
|
...process.env,
|
|
ORCA_BACKGROUND_LAUNCH: '1',
|
|
ORCA_UNIT_FULL_SHARD_COUNT: requestedCount,
|
|
GITHUB_EVENT_NAME: 'workflow_dispatch',
|
|
GITHUB_EVENT_PATH: eventPath,
|
|
ORCA_SHARD_SOURCE_SHA: 'full-count-fixture'
|
|
}
|
|
})
|
|
if (requestedCount === 'invalid') {
|
|
expect(result.code).not.toBe(0)
|
|
expect(result.stderr).toContain('ORCA_UNIT_FULL_SHARD_COUNT must be 5 or 10')
|
|
return
|
|
}
|
|
expect(result.code, result.stderr).toBe(0)
|
|
const plan = JSON.parse(readFileSync(join(root, 'ci-shards/unit-selection.json'), 'utf8'))
|
|
expect(plan.mode).toBe('shadow')
|
|
expect(plan.executionFiles).toEqual(['src/retained.test.ts'])
|
|
expect(plan.shards).toEqual(
|
|
Array.from({ length: Number(requestedCount) }, (_, index) => ({
|
|
index: index + 1,
|
|
count: Number(requestedCount)
|
|
}))
|
|
)
|
|
} finally {
|
|
rmSync(root, { recursive: true, force: true })
|
|
}
|
|
}
|
|
)
|