mirror of
https://github.com/stablyai/orca.git
synced 2026-11-04 19:17:28 +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.
106 lines
3.7 KiB
TypeScript
106 lines
3.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { runProcess } from '@orca/process-host'
|
|
import { resolveCommandOnLocalPath } from '../ipc/command-path-resolver'
|
|
import {
|
|
probeOpenCodeModelAvailability,
|
|
resolveOpenCodeDirectModelExecutable
|
|
} from './opencode-model-availability'
|
|
vi.mock('@orca/process-host', () => ({ runProcess: vi.fn() }))
|
|
vi.mock('../ipc/command-path-resolver', () => ({ resolveCommandOnLocalPath: vi.fn() }))
|
|
const options = {
|
|
command: '/private/opencode',
|
|
model: 'opencode/fledge-alpha-free',
|
|
cwd: '/tmp/project',
|
|
env: { OPENCODE_CONFIG_DIR: '/private/config', XDG_DATA_HOME: '/private/account' }
|
|
}
|
|
describe('OpenCode model catalog validation', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
vi.mocked(resolveCommandOnLocalPath).mockResolvedValue('/resolved/opencode')
|
|
vi.mocked(runProcess).mockResolvedValue({
|
|
code: 0,
|
|
timedOut: false,
|
|
stdout: 'opencode/fledge-alpha-free\nopencode/big-pickle\n',
|
|
stderr: '',
|
|
signal: null
|
|
})
|
|
})
|
|
it('checks exact catalog membership using the execution scope', async () => {
|
|
expect(await probeOpenCodeModelAvailability(options)).toBe(true)
|
|
expect(runProcess).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
program: '/resolved/opencode',
|
|
args: ['models'],
|
|
cwd: options.cwd,
|
|
env: options.env
|
|
})
|
|
)
|
|
})
|
|
it('resolves the default PATH executable before checking model availability', async () => {
|
|
expect(await resolveOpenCodeDirectModelExecutable({ ...options, command: 'opencode' })).toBe(
|
|
'/resolved/opencode'
|
|
)
|
|
expect(resolveCommandOnLocalPath).toHaveBeenCalledWith('opencode', {
|
|
env: options.env,
|
|
cwd: options.cwd
|
|
})
|
|
})
|
|
it('rejects the real invalid selector that falls back to Big Pickle', async () => {
|
|
expect(await probeOpenCodeModelAvailability({ ...options, model: 'gpt-5-nano' })).toBe(false)
|
|
})
|
|
it('does not accept substrings or verbose metadata', async () => {
|
|
expect(await probeOpenCodeModelAvailability({ ...options, model: 'fledge-alpha-free' })).toBe(
|
|
false
|
|
)
|
|
})
|
|
it('refuses timed out catalog probes even with matching partial output', async () => {
|
|
vi.mocked(runProcess).mockResolvedValue({
|
|
code: 0,
|
|
timedOut: true,
|
|
stdout: options.model,
|
|
stderr: '',
|
|
signal: null
|
|
})
|
|
expect(await probeOpenCodeModelAvailability(options)).toBe(false)
|
|
})
|
|
it('refuses a truncated catalog even when its retained head contains the model', async () => {
|
|
vi.mocked(runProcess).mockResolvedValue({
|
|
code: 0,
|
|
timedOut: false,
|
|
outputTruncated: true,
|
|
stdout: `${options.model}\n`,
|
|
stderr: '',
|
|
signal: null
|
|
})
|
|
expect(await probeOpenCodeModelAvailability(options)).toBe(false)
|
|
})
|
|
it('refuses the unterminated catalog shape captured from OpenCode 2.0.16', async () => {
|
|
vi.mocked(runProcess).mockResolvedValue({
|
|
code: 0,
|
|
timedOut: false,
|
|
outputTruncated: false,
|
|
stdout: `${options.model}\npriv`,
|
|
stderr: '',
|
|
signal: null
|
|
})
|
|
expect(await probeOpenCodeModelAvailability(options)).toBe(false)
|
|
})
|
|
it.each(['\n', '\r\n'])('accepts a complete catalog with %j line endings', async (ending) => {
|
|
vi.mocked(runProcess).mockResolvedValue({
|
|
code: 0,
|
|
timedOut: false,
|
|
outputTruncated: false,
|
|
stdout: `${options.model}${ending}`,
|
|
stderr: '',
|
|
signal: null
|
|
})
|
|
expect(await probeOpenCodeModelAvailability(options)).toBe(true)
|
|
})
|
|
it('refuses WSL until its exact guest launch environment is available', async () => {
|
|
expect(await probeOpenCodeModelAvailability({ ...options, wsl: { distro: 'Ubuntu' } })).toBe(
|
|
false
|
|
)
|
|
expect(runProcess).not.toHaveBeenCalled()
|
|
})
|
|
})
|