mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 09:07:40 +00:00
* build: share one pnpm virtual store across worktrees, off under CI
Each worktree carried a full node_modules; the global virtual store links
one slot per package version instead. pnpm keeps an explicit setting on
under CI, so a pnpmfile hook turns it off there: CI packages from,
caches and verifies a project-local node_modules.
* fix(build): keep shared electron and windows-process-tree dirs untouched under GVS
Every worktree runs Electron from the one shared electron package, so the
per-repo dist cache must not swap that dist and a foreign-arch install must
not land in it. The relay addon builder now repairs and compiles a private
copy instead of the shared windows-process-tree dir.
* fix(build): accept CLI runtime imports reached through an in-artifact store link
Under the global virtual store node_modules/<pkg> realpaths into a store
outside the repo. The check still rejects anything not reached through a
node_modules link inside the artifact, such as a stray ~/node_modules.
* docs: explain the global virtual store layout and the ~/node_modules hazard
* test: compare CLI closure paths with POSIX separators so the suite passes on Windows
* build: keep Windows on the normal pnpm layout unless ORCA_PNPM_GLOBAL_VIRTUAL_STORE=1
Store links are true symlinks on Windows, and installs without admin or
Developer Mode are unverified; CI still forces the normal layout first.
* fix(build): close the remaining shared-slot gaps under the global virtual store
- verify-skills-cli-runtime resolves each import from the importer's realpath,
as Node does, so an artifact-local copy can't mask a ~/node_modules load.
- A concurrent sibling install of the shared Electron dist is kept, not swapped out.
- rebuild:node goes through ensure-native-runtime, which builds a shared
node-pty beside the slot instead of node-gyp cleaning its build/ dir.
* fix(build): keep pnpm rebuild:node a forced rebuild
It replaced pnpm rebuild node-pty, which always rebuilt; without --force it
only rebuilt a node-pty that failed to load.
* docs: note that the store switches must stay set, since pnpm run relinks
* build: move the pnpmfile under config/ to keep the repo root allowlisted
pnpm-workspace.yaml points pnpm at it; the lockfile checksum is unchanged
because the content is.
* fix(build): enable the global virtual store from the pnpmfile, not the workspace file
pnpm exec derives NODE_PATH from the file setting, so even with the store
forced off under CI every child process got the root node_modules on its
NODE_PATH; a Windows rebuild fixture then resolved the real
@orca/windows-registry it deliberately omits. The hook now sets the store
both ways, and ORCA_PNPM_GLOBAL_VIRTUAL_STORE=0/1 is the one switch.
* test(pty): keep F3's concurrent spawns on the node-pty mock
Two concurrent first import('node-pty') calls race vitest's mock registry
and the loser loads the real addon under the mocked linux platform. It
passed only where a platform-agnostic build/Release happened to exist,
so it failed on every shared-store worktree.
* ci: fail PRs whose packages need a dependency they never declared
A new dependency_isolation job installs with the global virtual store
forced on (ORCA_PNPM_FORCE_GLOBAL_VIRTUAL_STORE_IN_CI), HOME and the store
in an empty temp dir, then runs pnpm tc and the undeclared-dependency test.
Postinstall now warns when a node_modules above the shared store, such as
~/node_modules, would mask the same class of bug locally.
* ci: set the isolation job's HOME and store through GITHUB_ENV
Job-level env cannot read the runner context, which made pr.yml invalid.
272 lines
8.8 KiB
JavaScript
272 lines
8.8 KiB
JavaScript
const { existsSync, readFileSync, realpathSync } = require('node:fs')
|
|
const { builtinModules, createRequire, isBuiltin } = require('node:module')
|
|
const { dirname, isAbsolute, join, relative, resolve, sep } = require('node:path')
|
|
const { spawnSync } = require('node:child_process')
|
|
const ts = require('typescript-api')
|
|
|
|
const BUILTINS = new Set(builtinModules.flatMap((name) => [name, `node:${name}`]))
|
|
const CLI_COMMAND_TIMEOUT_MS = 30_000
|
|
|
|
function artifactPath(outDir, file) {
|
|
return relative(outDir, file).split(sep).join('/')
|
|
}
|
|
|
|
function runtimeImportSpecifiers(source, file) {
|
|
const sourceFile = ts.createSourceFile(
|
|
file,
|
|
source,
|
|
ts.ScriptTarget.Latest,
|
|
false,
|
|
ts.ScriptKind.JS
|
|
)
|
|
const specifiers = []
|
|
|
|
function visit(node) {
|
|
if (ts.isCallExpression(node) && node.arguments.length > 0) {
|
|
const [argument] = node.arguments
|
|
const expression = node.expression
|
|
const isRequire = ts.isIdentifier(expression) && expression.text === 'require'
|
|
const isRequireResolve =
|
|
ts.isPropertyAccessExpression(expression) &&
|
|
ts.isIdentifier(expression.expression) &&
|
|
expression.expression.text === 'require' &&
|
|
expression.name.text === 'resolve'
|
|
const isDynamicImport = expression.kind === ts.SyntaxKind.ImportKeyword
|
|
|
|
if ((isRequire || isRequireResolve || isDynamicImport) && ts.isStringLiteralLike(argument)) {
|
|
specifiers.push(argument.text)
|
|
}
|
|
}
|
|
ts.forEachChild(node, visit)
|
|
}
|
|
|
|
visit(sourceFile)
|
|
return specifiers
|
|
}
|
|
|
|
function isOutsideRoot(root, target) {
|
|
const pathFromRoot = relative(root, target)
|
|
return isAbsolute(pathFromRoot) || pathFromRoot === '..' || pathFromRoot.startsWith(`..${sep}`)
|
|
}
|
|
|
|
function isOptionalPackageImport(artifactRoot, importer, specifier) {
|
|
if (specifier.startsWith('.') || isAbsolute(specifier)) {
|
|
return false
|
|
}
|
|
const packageName = bareSpecifierPackage(specifier)
|
|
let directory = dirname(importer)
|
|
|
|
while (!isOutsideRoot(artifactRoot, directory)) {
|
|
const packageJson = join(directory, 'package.json')
|
|
if (existsSync(packageJson)) {
|
|
try {
|
|
const manifest = JSON.parse(readFileSync(packageJson, 'utf8'))
|
|
return (
|
|
Object.hasOwn(manifest.optionalDependencies ?? {}, packageName) ||
|
|
manifest.peerDependenciesMeta?.[packageName]?.optional === true
|
|
)
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
if (directory === artifactRoot) {
|
|
break
|
|
}
|
|
directory = dirname(directory)
|
|
}
|
|
return false
|
|
}
|
|
|
|
function bareSpecifierPackage(specifier) {
|
|
const segments = specifier.split('/')
|
|
return specifier.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0]
|
|
}
|
|
|
|
/**
|
|
* The in-root path of a package import whose realpath leaves the root.
|
|
*
|
|
* Under pnpm's global virtual store `<root>/node_modules/<pkg>` links into a store shared by every
|
|
* worktree, so Node's realpath lands outside the root even though the artifact does carry the
|
|
* dependency. Accept it only when a node_modules link inside the root really leads there.
|
|
*/
|
|
function linkedPathInsideRoot(artifactRoot, importer, specifier, resolved) {
|
|
const isBare = !specifier.startsWith('.') && !isAbsolute(specifier)
|
|
let directory = dirname(importer)
|
|
while (!isOutsideRoot(artifactRoot, directory)) {
|
|
// A bare import reaches the store through node_modules/<pkg>; a relative one through the
|
|
// linked package dir it sits in.
|
|
const candidates = isBare
|
|
? [join(directory, 'node_modules', bareSpecifierPackage(specifier)), directory]
|
|
: [directory]
|
|
for (const candidate of candidates) {
|
|
if (!existsSync(candidate)) {
|
|
continue
|
|
}
|
|
const physical = realpathSync(candidate)
|
|
if (physical !== candidate && !isOutsideRoot(physical, resolved)) {
|
|
return join(candidate, relative(physical, resolved))
|
|
}
|
|
}
|
|
if (directory === artifactRoot) {
|
|
break
|
|
}
|
|
directory = dirname(directory)
|
|
}
|
|
return null
|
|
}
|
|
|
|
function resolveRuntimeImport(outDir, artifactRoot, importer, specifier) {
|
|
if (BUILTINS.has(specifier) || isBuiltin(specifier)) {
|
|
return null
|
|
}
|
|
let resolved
|
|
try {
|
|
// Why physical: Node resolves from the realpath, so a store-linked importer must not see the artifact's own node_modules.
|
|
resolved = createRequire(realpathSync(importer)).resolve(specifier)
|
|
} catch (error) {
|
|
if (isOptionalPackageImport(artifactRoot, importer, specifier)) {
|
|
return null
|
|
}
|
|
const detail = error instanceof Error ? error.message : String(error)
|
|
throw new Error(
|
|
`[verify-skills-cli-runtime] missing runtime import "${specifier}" from ` +
|
|
`${artifactPath(outDir, importer)}: ${detail}`
|
|
)
|
|
}
|
|
if (isOutsideRoot(artifactRoot, resolved)) {
|
|
const linked = linkedPathInsideRoot(artifactRoot, importer, specifier, resolved)
|
|
if (linked !== null) {
|
|
return linked
|
|
}
|
|
throw new Error(
|
|
`[verify-skills-cli-runtime] import "${specifier}" from ` +
|
|
`${artifactPath(outDir, importer)} resolved outside ${artifactRoot}: ${resolved}`
|
|
)
|
|
}
|
|
return resolved
|
|
}
|
|
|
|
function collectRuntimeClosure(outDir, artifactRoot = dirname(outDir)) {
|
|
outDir = realpathSync(outDir)
|
|
artifactRoot = realpathSync(artifactRoot)
|
|
if (isOutsideRoot(artifactRoot, outDir)) {
|
|
throw new Error(`[verify-skills-cli-runtime] ${outDir} is outside ${artifactRoot}`)
|
|
}
|
|
const entry = resolve(outDir, 'cli', 'index.js')
|
|
if (!existsSync(entry)) {
|
|
throw new Error(`[verify-skills-cli-runtime] missing entry ${entry}`)
|
|
}
|
|
const pending = [entry]
|
|
const visited = new Set()
|
|
|
|
while (pending.length > 0) {
|
|
const file = pending.pop()
|
|
if (!file || visited.has(file)) {
|
|
continue
|
|
}
|
|
visited.add(file)
|
|
const source = readFileSync(file, 'utf8')
|
|
for (const specifier of runtimeImportSpecifiers(source, file)) {
|
|
const resolved = resolveRuntimeImport(outDir, artifactRoot, file, specifier)
|
|
if (resolved && !isOutsideRoot(artifactRoot, resolved) && /\.(?:c|m)?js$/.test(resolved)) {
|
|
pending.push(resolved)
|
|
}
|
|
}
|
|
}
|
|
|
|
return [...visited].sort()
|
|
}
|
|
|
|
function runCli(outDir, args, timeoutMs = CLI_COMMAND_TIMEOUT_MS) {
|
|
const entry = resolve(outDir, 'cli', 'index.js')
|
|
const env = { ...process.env, NODE_PATH: '' }
|
|
delete env.ORCA_CLI_CWD
|
|
const result = spawnSync(process.execPath, [entry, ...args], {
|
|
cwd: dirname(outDir),
|
|
encoding: 'utf8',
|
|
env,
|
|
killSignal: 'SIGKILL',
|
|
maxBuffer: 16 * 1024 * 1024,
|
|
timeout: timeoutMs
|
|
})
|
|
if (result.error || result.signal || result.status !== 0) {
|
|
const detail = [
|
|
result.error?.message,
|
|
result.signal ? `terminated by ${result.signal}` : null,
|
|
result.stdout,
|
|
result.stderr
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n')
|
|
throw new Error(
|
|
`[verify-skills-cli-runtime] ${args.join(' ')} exited ${String(result.status)}\n${detail}`
|
|
)
|
|
}
|
|
return result.stdout
|
|
}
|
|
|
|
function parseJson(label, output) {
|
|
try {
|
|
return JSON.parse(output)
|
|
} catch {
|
|
throw new Error(`[verify-skills-cli-runtime] ${label} emitted invalid JSON:\n${output}`)
|
|
}
|
|
}
|
|
|
|
function verifySkillsCliRuntime(outDir, artifactRoot = dirname(outDir), options = {}) {
|
|
const absoluteOutDir = resolve(outDir)
|
|
const closure = collectRuntimeClosure(absoluteOutDir, resolve(artifactRoot))
|
|
if (options.executeCommands === false) {
|
|
return { closureFiles: closure.length, commands: 0 }
|
|
}
|
|
const list = parseJson('skills list', runCli(absoluteOutDir, ['skills', 'list', '--json']))
|
|
const topicNames = new Set(list.topics?.map((topic) => topic.name))
|
|
for (const topic of ['orca-cli', 'computer-use']) {
|
|
if (!topicNames.has(topic)) {
|
|
throw new Error(`[verify-skills-cli-runtime] skills list omitted ${topic}`)
|
|
}
|
|
const guide = runCli(absoluteOutDir, ['skills', 'get', topic])
|
|
if (!guide.includes(`name: ${topic}`)) {
|
|
throw new Error(`[verify-skills-cli-runtime] skills get ${topic} returned the wrong guide`)
|
|
}
|
|
}
|
|
|
|
const install = parseJson(
|
|
'skills install --dry-run',
|
|
runCli(absoluteOutDir, [
|
|
'skills',
|
|
'install',
|
|
'--skill',
|
|
'orca-cli',
|
|
'--agent',
|
|
'codex',
|
|
'--dry-run',
|
|
'--json'
|
|
])
|
|
)
|
|
const update = parseJson(
|
|
'skills update --dry-run',
|
|
runCli(absoluteOutDir, ['skills', 'update', '--skill', 'orca-cli', '--dry-run', '--json'])
|
|
)
|
|
if (install.executed !== false || update.executed !== false) {
|
|
throw new Error('[verify-skills-cli-runtime] a dry-run reported execution')
|
|
}
|
|
|
|
return { closureFiles: closure.length, commands: 5 }
|
|
}
|
|
|
|
if (require.main === module) {
|
|
try {
|
|
const result = verifySkillsCliRuntime(process.argv[2] ?? 'out')
|
|
console.log(
|
|
`[verify-skills-cli-runtime] ${result.closureFiles} closure files and ` +
|
|
`${result.commands} commands passed`
|
|
)
|
|
} catch (error) {
|
|
console.error(error instanceof Error ? error.message : error)
|
|
process.exitCode = 1
|
|
}
|
|
}
|
|
|
|
module.exports = { collectRuntimeClosure, runCli, verifySkillsCliRuntime }
|