Files
orca/config/scripts/orcad-distribution/server-bundle/session-scanner-service-smoke.mjs
Neil 9bd6272fdf refactor(tooling): organize build, CI, and test owners (#38130)
* refactor(tooling): organize test runtime and maintenance owners

* test(tooling): preserve relocated runtime fixture dependency edges

* refactor(tooling): preserve xterm routing owner checks

* ci(tooling): include routing owner in sparse checkout

* test(tooling): preserve copied workflow dependency closures

* fix(tooling): normalize hashed JSON assets in release parity

* fix(tooling): distinguish asset aliases from literal references

* fix(tooling): frame normalized asset reference payloads

* fix(tooling): normalize decoded JSON asset references

* refactor(tooling): organize build, CI and release owners

* fix(tooling): align moved generator and workflow path contracts

* fix(tooling): update generated plugin bundle owner banners

* test(tooling): create relocated mobile verifier fixture directories

* test(tooling): copy headless detector dependency closure

* test(tooling): align native batch policy fixtures with owner path

* fix(tooling): link moved reliability command to historical evidence

* fix(tooling): preserve nested sandbox owners and canonical guide source

* fix(tooling): target release version owners in checkout fixture
2026-11-04 21:08:19 -08:00

89 lines
3.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join, resolve } from 'node:path'
import { runProcessSync } from '@orca/process-host'
import { describeProcessFailure } from '../../tool-invocation/process-failure-message.mjs'
import { ORCAD_SESSION_SCANNER_SERVICE_ENTRY } from '../../../../src/shared/orcad-artifacts.ts'
import { AI_VAULT_SERVICE_PROTOCOL_VERSION } from '../../../../src/main/ai-vault/scan-service/session-scanner-service-protocol.ts'
// Probe forks with shipped runtime’s execPath; judge exit code, never matched output.
const PROBE = `
const { fork } = require('node:child_process')
const [entry, home, protocol] = process.argv.slice(2)
const fail = (code, message) => {
console.error(message)
process.exit(code)
}
const child = fork(entry, [], {
stdio: ['ignore', 'ignore', 'pipe', 'ipc'],
env: { PATH: process.env.PATH, HOME: home, USERPROFILE: home },
windowsHide: true
})
let stderr = ''
child.stderr.on('data', (chunk) => { stderr += String(chunk) })
setTimeout(() => { child.kill('SIGKILL'); fail(3, 'session scanner did not answer\\n' + stderr) }, 30000).unref()
child.on('error', (error) => fail(4, String(error && error.stack || error)))
child.on('exit', (code, signal) => fail(5, 'session scanner exited ' + code + ' ' + signal + '\\n' + stderr))
child.on('message', (message) => {
if (message && message.type === 'ready') {
child.send({ type: 'request', id: 1, operation: 'scan', options: { limit: 5 } })
return
}
// Progress frames share the request id; only the result or error answers it.
if (!message || message.id !== 1 || (message.type !== 'result' && message.type !== 'error')) {
return
}
const sessions = message.type === 'result' ? message.value.result.sessions : []
if (!sessions.some((session) => session.agent === 'claude' && session.sessionId === 'smoke-session')) {
fail(6, 'scan answered ' + JSON.stringify(message).slice(0, 2000))
}
child.removeAllListeners('exit')
child.kill()
process.exit(0)
})
child.send({ type: 'init', protocol: Number(protocol) })
`
/**
* Fork the built session scanner child and list a seeded Claude session through it.
* @param outDir - orcad output directory holding the entry.
* @param options.runtimePath - Node to run under; the build's own Node when omitted.
*/
export function smokeSessionScannerService(outDir, { runtimePath, timeoutMs = 60_000 } = {}) {
const directory = mkdtempSync(join(tmpdir(), 'orca-session-scanner-smoke-'))
try {
const home = join(directory, 'home')
const project = join(home, '.claude', 'projects', 'smoke-project')
mkdirSync(project, { recursive: true })
writeFileSync(
join(project, 'smoke-session.jsonl'),
`${JSON.stringify({
type: 'user',
sessionId: 'smoke-session',
timestamp: '2026-01-01T00:00:00.000Z',
cwd: '/smoke',
message: { role: 'user', content: 'smoke' }
})}\n`
)
const probe = join(directory, 'probe.cjs')
writeFileSync(probe, PROBE)
const result = runProcessSync({
program: runtimePath ?? process.execPath,
args: [
probe,
resolve(outDir, ORCAD_SESSION_SCANNER_SERVICE_ENTRY),
home,
String(AI_VAULT_SERVICE_PROTOCOL_VERSION)
],
env: { ...process.env, ORCA_BACKGROUND_LAUNCH: '1' },
timeoutMs,
maxOutputBytes: 64 * 1024
})
if (result.code !== 0 || result.timedOut) {
throw new Error(`Session scanner service smoke failed: ${describeProcessFailure(result)}`)
}
} finally {
rmSync(directory, { recursive: true, force: true })
}
}