mirror of
https://github.com/stablyai/orca.git
synced 2026-11-02 18:17:36 +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.
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { readAgentProcess } from './agent-process-presence-probe'
|
|
|
|
const run = vi.hoisted(() => vi.fn())
|
|
const read = vi.hoisted(() => vi.fn())
|
|
vi.mock('@orca/process-host', () => ({ runProcess: run }))
|
|
vi.mock('node:fs/promises', () => ({ readFile: read }))
|
|
const hostProcess = process
|
|
function platform(name: string): void {
|
|
vi.stubGlobal('process', { ...hostProcess, platform: name })
|
|
}
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals()
|
|
vi.resetAllMocks()
|
|
})
|
|
|
|
describe('platform process evidence', () => {
|
|
it('leaves Windows unanswered until a Windows hook captures an identity', async () => {
|
|
platform('win32')
|
|
expect(await readAgentProcess(4242)).toEqual({ verdict: 'unverifiable' })
|
|
expect(run).not.toHaveBeenCalled()
|
|
expect(read).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('treats a missing macOS utility as unanswered', async () => {
|
|
platform('darwin')
|
|
run.mockRejectedValue(Object.assign(new Error('missing ps'), { code: 'ENOENT' }))
|
|
expect(await readAgentProcess(4242)).toEqual({ verdict: 'unverifiable' })
|
|
})
|
|
|
|
it('requires Linux process-file absence rather than an unreadable boot identity', async () => {
|
|
platform('linux')
|
|
read.mockRejectedValueOnce(Object.assign(new Error('gone'), { code: 'ENOENT' }))
|
|
expect(await readAgentProcess(4242)).toEqual({ verdict: 'exited' })
|
|
const fields = ['S', ...Array(18).fill('0'), '100']
|
|
read
|
|
.mockResolvedValueOnce(`4242 (agent (name)) ${fields.join(' ')}`)
|
|
.mockRejectedValueOnce(new Error('permission denied'))
|
|
expect(await readAgentProcess(4242)).toEqual({ verdict: 'unverifiable' })
|
|
read
|
|
.mockResolvedValueOnce(`4242 (agent (name)) ${fields.join(' ')}`)
|
|
.mockResolvedValueOnce('boot-id\n')
|
|
expect(await readAgentProcess(4242)).toEqual({
|
|
verdict: 'live',
|
|
startTime: 'boot-id:100',
|
|
zombie: false,
|
|
stopped: false
|
|
})
|
|
read
|
|
.mockResolvedValueOnce(`4242 (agent) ${['T', ...fields.slice(1)].join(' ')}`)
|
|
.mockResolvedValueOnce('boot-id\n')
|
|
expect(await readAgentProcess(4242)).toMatchObject({ verdict: 'live', stopped: true })
|
|
})
|
|
})
|