mirror of
https://github.com/stablyai/orca.git
synced 2026-09-27 08:02:35 +00:00
* feat(search): bundle ripgrep for local, WSL, and SSH search Ship @vscode/ripgrep-universal's prebuilt rg for all six relay platforms in every desktop artifact. Local and WSL searches spawn the bundled binary and drop the git ls-files / git grep fallbacks; SSH deploys upload the remote's binary once per ripgrep version and the relay prefers it over PATH rg. * fix(search): address bundled ripgrep review findings - Key the SSH ripgrep cache on the binary's content hash; a package bump is the only update step - glibc verifier: read arch tokens below the slice root and accept static ELFs (arm64 release blocker) - Ship ripgrep/PCRE2/musl license notices; bundle rg with orcad - Packaged builds never spawn a bare rg; report fd pressure as transient - SSH: install rg before sweep/GC, size-validate installs, back off instead of disabling on launch failure - Scope Dependabot to @vscode/ripgrep-universal; revert unrelated lockfile churn * chore(search): drop bundled-ripgrep reference doc; assert full packaging layout parity * refactor(search): one entry point for spawning the bundled ripgrep Local Quick Open, Quick Open path search, the Explorer name filter, and runtime text search each repeated the same three steps: resolve the bundled command, spread in the WSL distro, spread in the WSL shell expression. Fold that into spawnBundledRipgrep so one place owns the rule that a bare 'rg' must never reach spawn, and simplify the resolver's command/packaged checks. Restore the AGENTS.md ripgrep rule dropped alongside its reference doc in63f4dac, and note why the relay's availability probe may spawn a bare 'rg'. No behaviour change; verified by the existing suites plus a new test that pins the local, WSL-routed, and distro-routed-but-Windows-output cases. * refactor(search): drop the local install-ripgrep path; enforce the rg rule Bundling rg removed the local git/readdir fallback, so nothing can produce the "install ripgrep on the host running the Quick Open scan" guidance any more -- only a remote host an upload never reached still reaches the capped listing. Drop the host parameter, the renderer's local branch and its translation key, and the relay wrapper that existed only to pass 'remote'. Add a ratchet test for bare 'rg' spawns, since the AGENTS.md rule alone had nothing enforcing it. Its one allowlist entry is the relay's PATH probe, which asks about PATH by definition. Verified the guard catches a planted offender rather than passing vacuously. Also stop chaining the remote cleanup sweep behind the ripgrep upload: on a cold host that is a multi-MB transfer, and stale upload stages and superseded version dirs were left on the remote for its whole duration. The two touch different trees, so they now run concurrently. * test(ssh): pin that the cleanup sweep does not wait on the ripgrep upload * fix(search): derive rg spawn types instead of importing node:child_process A type-only import still counts against the child_process ratchet, whose pin and allowlist only ever shrink. Derive both types from wslAwareSpawn instead. * fix(search): surface an unreachable WSL workspace instead of an empty result Inside `bash -c`, a failed `cd` exits 1 -- the same code ripgrep uses for "no matches" -- so a WSL workspace whose directory had gone away reported an empty listing as a successful scan. main did not have this hole: checkRgAvailable ran the same `cd` wrapper first and settled on `code === 0`, diverting to the git fallback that this PR deletes. The WSL wrapper now takes an optional cwdFailureExitCode; rg passes 97, and all four close handlers reject with a clear error before the unavailable check can blame the install. Also from review: - Bound the fire-and-forget ripgrep upload with deploySignal. The controller aborts only on the deploy timeout, never on success, so this cancels a still-running upload when the deploy gives up. - Run the stale-stage sweep before the installed check rather than inside its else branch. Once rg was installed every later deploy took the PRESENT path, so a stage orphaned by a dropped connection was never collected again. - Note in orcad-remote-deploy.ts why wiring it up needs ripgrep work first: build-orcad.mjs copies only the build host's rg, and orcad reports isPackaged() === true, so a remote of another platform would find nothing. ssh-relay-deploy.test.ts sat at the max-lines cap, so any edit to it failed the gate. Split the four Windows named-pipe deploys into their own file (926 -> 737 + 333); both are now well clear of it. * fix(search): name the unreachable root in every handler, not three of four Round-two review caught that the missing-cwd branch in scanRipgrepPaths sat AFTER isRipgrepUnavailableExit, which classifies any code above 2 as a broken install -- so for exit 97 it was dead code and Quick Open still told the user to reinstall Orca. Reordered; all four handlers now check it first. Also from review: - A vanished workspace makes spawn fail with ENOENT, which read as a damaged install on every local path. Confirm the cwd with isRipgrepSpawnCwdUsable -- the guard the relay already applies -- before blaming the binary. The async continuation re-checks `resolved`, because finish() drops its argument once settled and the rejected promise would otherwise go unhandled. - bundledRipgrepCommand returned a bare 'rg' for an arch outside the bundled set, bypassing the guard that exists so Windows cannot resolve a bare name against the repo cwd. A packaged app now always names an absolute path. Drop ci-shards/unit-assignment.json, a 9,425-line CI artifact swept in from reproducing a shard locally, and gitignore the directory that produced it. The "rg genuinely cannot start" test pointed at a synthetic /repo, which the new guard correctly reports as unreachable; it now resolves to a real root so it still tests what its name says. * fix(search): let the error handler own the spawn-failure verdict A failed spawn emits 'error' and THEN 'close' with a negative code. The cwd check added in the error handler did not settle, so the close handler settled first -- synchronously, with the reinstall message -- and won the race every time. The branch was not merely flaky, it was unreachable in all four handlers: it is guarded by pid === undefined, which is exactly the case that always produces a following close(code < 0). Verified against a real spawn: 3/3 runs give error(ENOENT) -> close(-2). The error handler now detaches 'close' before the probe, so it owns the outcome. The probe also had no rejection handler, so a probe that rejected left the search unsettled forever -- a hang, not just a wrong message. It now falls back to the prior verdict rather than inventing one. Tests: filesystem-search-rg-timeout and orca-runtime-files-search already cover error-first and close-first, but against synthetic roots that the new guard correctly calls unreachable; they now resolve to a real root, keeping each test's stated intent. Added a Quick Open case for the vanished-workspace path and confirmed it fails with the old ordering. * test(search): cover exit code 97 in all four ripgrep close handlers Round-four review found the missing-cwd branch had zero handler coverage: no test anywhere emitted close(97), only -2/0/1/2/127. Ordering was correct, but guarded by source-line order alone -- and that exact ordering was wrong in three of four handlers two commits ago. Each suite now drives close(97) through its real handler and expects the unreachable-root message. Verified the tests earn their place: neutering the missing-cwd check fails exactly four tests, one per handler. Also drop a Reflect.get the anti-slop gate rejects, in favour of `in` narrowing. * docs(search): stop claiming the close handler always wins the race The previous commit asserted close "would beat this threadpool round-trip every time", from an n=3 sample that measured event ordering -- which was never in dispute -- rather than probe-vs-close. Two later measurements disagree with each other: 50/50 close-first here, 30/50 probe-first in review. Either way it is a race on a sub-millisecond margin, and the detach is what makes the verdict deterministic. Why this wording matters: "close wins every time" is an argument for deleting the detach as a guard against an impossible race. No test would catch that -- the suites emit error and close in the same synchronous tick. * chore(search): ship the jemalloc and libunwind notices the Linux rg needs The statically linked Linux builds carry jemalloc (BSD-2-Clause) and LLVM libunwind (Apache-2.0 WITH LLVM-exception) in addition to PCRE2 and musl, and both require their notice on binary redistribution. Confirmed with `strings`: their symbols are present in linux-x64 and linux-arm64 and absent from the darwin and win32 builds. Texts taken from the upstream canonical sources. extraResources already copies the whole licenses directory, so these ship without a packaging change. * fix(relay): stop spawning a bare rg, name unreachable roots, collect old builds Three gaps the reviews surfaced on the remote side, all pre-existing on main. Bare `rg` on Windows remotes. Both relay spawn sites pass the user's repo as cwd, and CreateProcessW searches the cwd before PATH -- the same hijack the desktop side already fixes. The relay now walks PATH itself and spawns an absolute rg.exe, skipping relative PATH entries because those resolve against the cwd. No rg on PATH yields null, which callers treat as "ripgrep unavailable" rather than handing spawn a bare name. POSIX keeps the bare name: execvp never consults the cwd, so there is nothing to resolve and nothing to gain. With the last probe converted, the bare-spawn ratchet allowlist is empty. Empty results for an unreachable root. settleLaunchFailure resolved an empty, successful-looking scan when the root was gone but PATH rg existed, and the git/readdir chain never engaged because it only triggers on RipgrepUnavailableError. Both relay paths now reject naming the root, matching local workspaces. Missing-rg keeps precedence over a missing root, because only that verdict engages the fallback chain -- two tests pinned that deliberately and it would have been wrong to flip it. Unbounded ~/.orca-remote/ripgrep/. Nothing collected this tree; the relay's version GC only matches `relay-*`, so every rg bump left another ~5 MB per host forever. The probe command now also drops sibling builds older than two weeks, sparing the current one and live upload stages, on POSIX and PowerShell alike. Two weeks because a client pinned to an older build may still be using it; the cost of collecting one early is that client re-uploading once. * fix(relay): probe the rg that failed, and close the drive-relative PATH hole Five review findings against the previous commit, all reproduced first. The launch-failure classifier probed PATH rg, but the spawn that failed was the bundled binary. On the normal remote setup -- no rg on PATH, which is why Orca uploads one -- the probe failed and a moved workspace was reported as a missing ripgrep, telling the user to install what Orca already ships. So the fix was inert on exactly the hosts the uploader exists for. It now takes a candidate list and asks the binary that actually failed first, then PATH. path.win32.isAbsolute accepts `\tools` and `/tools`: rooted, but carrying no drive, so they resolve against whatever drive the process is on. The probe would have validated one against the relay's drive while the spawn, running with the user's repo as cwd, resolved it against the repo's -- the same cwd-dependence this lookup removes, narrowed from directory to drive. A real drive letter or UNC root is now required. probeRipgrepVersion had lost the timeout's kill in the rewrite, leaking a live process and a ref'd handle per launch failure -- for a hang, which is the very case the bundled-rg back-off exists for. It also spawned without windowsHide, which would flash a console; fixing that made an allowlist entry stale, so the entry is gone and the pin ratchets down 63 -> 62. `windowsPathRipgrep ??= …` never memoised a miss, because null is nullish. The caching was inverted against cost: a hit stops at the first directory, a miss stats every one, and only the miss was repeated -- per spawn. The bare-spawn ratchet claimed "nothing in production spawns a bare rg", which is false on POSIX. It now also matches PATH_RIPGREP_COMMAND at a spawn site, and the comment states plainly what a textual guard cannot see: the POSIX bare name reaches spawn as a parameter, and is safe because execvp ignores the cwd. The drive-rooted predicate is tested directly rather than through the filesystem -- a temp dir on a POSIX CI host has no drive letter to exercise win32 semantics with, so the filesystem test could never have caught this. * test(mobile): repin the session closure past #22452's two shared modules Merging main brought the closure to 4220 against a pin of 4218. The two extra modules are `src/shared/agent-turn-outcome.ts` and `src/shared/main-agent-status.ts` from #22452, which the status projection this route already reaches import. That change was src/shared-only, so the mobile job never ran on it -- the same way the structured tool line slipped past, as the ledger above already records. Repinned here because this PR's file set is what next made the job run, not because this PR reaches either module. Verified: of the 28 source files this branch changes, none appear anywhere in the route's 4220-module closure. * fix(search): preserve remote binaries and complete runtime packaging * test(relay): pin the probe's env now that it inherits the relay's PATH8d6759athreaded the relay env into probeRipgrepVersion -- correctly, since the probe decides whether a launch failure was the binary or the root and so has to resolve the same rg the failed spawn would have. It left the assertion that pins the probe's spawn arguments behind, which is what CI caught. Asserting buildRelayCommandEnv() rather than loosening the match to any object: under process.env the probe could resolve a different rg, or none, which is the regression the change exists to prevent. * feat(ssh): collect remote ripgrep builds by reference, not by age Nothing collected `~/.orca-remote/ripgrep/`: the version GC matches only `relay-*`, so every change to the shipped bytes left another ~5 MB on every SSH host, permanently. The age window this replaces was the wrong instrument -- a directory's mtime is when it was written, not when it was last used, so it cannot tell a superseded build from the one a live relay was launched against. Deleting the latter is not graceful degradation: without a PATH ripgrep remote text search rejects outright, and listing drops to the capped walk this PR exists to remove. So the question is reference. Each relay directory now records the build it runs against in `.ripgrep-ref`, written only once that binary is confirmed present, and the GC collects a build only when no installation names it. The discipline is ssh-relay-native-deps-cache-gc.ts': anything the pass cannot account for blocks the whole pass. A relay directory with no readable marker is an older Orca's, possibly running right now against a binary it never recorded, so the pass declines rather than guessing. Those directories are removed by the version GC in time, which is what makes their builds collectable -- hence running after it, not beside it. Deletion is the same tombstone, recheck under the rename, then remove, so a deploy that takes a reference mid-pass gets its tree restored. Windows has no pass yet, matching the native-deps cache's gate. One test note: the first version of the "unaccountable blocks the pass" test passed against a deliberately broken guard, because the tombstone recheck masked its absence. The test now puts a readable recheck behind an unreadable first scan, which is the only shape that fails when that guard is removed. Recording the reference lives inside ensureRemoteBundledRipgrep rather than at the call site: it is the same concern, and it keeps the deploy's ripgrep surface to one call for the tests that mock it to protect their exec queues. * feat(ssh): collect Windows remotes too, and ship the Rust crate notices Three items previously left documented-but-open. Windows remote accumulation. The cache GC was POSIX-gated, so the leak did not go away -- it moved to the platform with the larger binary (rg.exe is 5.43 MB on win32-x64, against 4.77 MB for linux-arm64). The PowerShell dialect now does the same reference scan: entries and references carry token prefixes, because PowerShell writes every uncaptured value to stdout and an untokenised listing would feed Remove-Item whatever a cmdlet happened to emit. Verified on a real Windows host rather than a mock: the listing emits its ENTRY/LIST_OK tokens, a relay directory carrying a marker yields REF <entry>, and a relay directory without one yields REFS_ERR -- the safety path, on the real interpreter. Rust crate notices. The crate set was read out of the shipped binary's symbols and the licence identifiers taken from crates.io rather than assumed. Where a crate offers the Unlicense, Orca elects it: a public-domain dedication carries no notice obligation, and that covers eight of them. The four that do not offer it get their MIT text reproduced. encoding_rs carries a BSD-3-Clause notice for its WHATWG-derived encoding data that is joined by AND, not OR, so electing MIT does not discharge it. Release-only validation, corrected rather than repeated. Linux AppImage/deb/rpm already runs in CI's package job on every PR, and Windows signing was already rehearsed on this branch. macOS notarization is the only item a release must still exercise, and the exposure is narrow: notarization requires signatures on Mach-O binaries, and of the six bundled builds only the two darwin ones are Mach-O -- `file` reports ELF for linux and PE32+ for win32 -- so signIgnore excludes only files the notary never asks about. orcad-artifacts.test.ts caught the new notice file missing from the standalone runtime's shipped list, which is exactly the gap that test exists to catch: a notice committed to the repo but never actually shipped. * fix(search): protect relay cache references and handle failed spawns * fix(ripgrep): close review gaps and repair deployment fixtures * test(mobile): refresh merged session module census * fix(ssh): preserve ripgrep caches with empty legacy references * test(mobile): assert bundle boundaries instead of global module count
629 lines
26 KiB
JavaScript
629 lines
26 KiB
JavaScript
import { existsSync, readFileSync, readdirSync } from 'node:fs'
|
|
import { cp, mkdir, mkdtemp, readFile, readdir, stat, writeFile } from 'node:fs/promises'
|
|
import { createRequire } from 'node:module'
|
|
import { tmpdir } from 'node:os'
|
|
import { delimiter, dirname, join, relative, resolve } from 'node:path'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { removeTree } from '../../src/shared/windows-transient-lock-removal.ts'
|
|
|
|
const require = createRequire(import.meta.url)
|
|
const projectRoot = resolve(import.meta.dirname, '..', '..')
|
|
const electronBuilderConfig = require('../electron-builder.config.cjs')
|
|
const {
|
|
createPackagedRuntimeNodeModuleResources,
|
|
findAsarEntry,
|
|
isPackagedExternalSpecifier,
|
|
packageNameFromSpecifier,
|
|
prunePackagedNodePty,
|
|
prunePackagedParcelWatcher,
|
|
prunePackagedSherpaOnnx,
|
|
prunePackagedRuntimeTypeAndSourceMapArtifacts,
|
|
prunePackagedZodSources,
|
|
verifyPackagedMainRuntimeDeps
|
|
} = require('../packaged-runtime-node-modules.cjs')
|
|
|
|
// Why this and not process.platform: @vscode/windows-process-tree is the only os: win32 npm
|
|
// addon left, so its presence is what decides whether the win32 plan resolves.
|
|
// @orca/windows-registry is a workspace link present on every host, so it proves nothing.
|
|
const windowsAddonsInstalled = existsSync(
|
|
join(projectRoot, 'node_modules', '@vscode', 'windows-process-tree', 'package.json')
|
|
)
|
|
|
|
describe('packaged runtime resources', () => {
|
|
it('verifies packaged main runtime deps from Windows-style asar entries', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-runtime-deps-'))
|
|
try {
|
|
await writeFile(join(resourcesDir, 'app.asar'), '', 'utf8')
|
|
await mkdir(join(resourcesDir, 'node_modules', 'yaml'), { recursive: true })
|
|
await mkdir(join(resourcesDir, 'node_modules', 'zod'), { recursive: true })
|
|
|
|
const sources = new Map([
|
|
['out\\main\\index.js', 'const z = require("zod")'],
|
|
['out\\main\\agent-hooks\\managed-agent-hook-controls.js', 'const YAML = require("yaml")']
|
|
])
|
|
const asar = {
|
|
listPackage: () => [...sources.keys()].map((entry) => `\\${entry}`),
|
|
extractFile: (_asarPath, internalPath) => Buffer.from(sources.get(internalPath), 'utf8')
|
|
}
|
|
|
|
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).not.toThrow()
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('verifies literal dynamic imports from the packaged main bundle', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-runtime-dynamic-imports-'))
|
|
try {
|
|
await writeFile(join(resourcesDir, 'app.asar'), '', 'utf8')
|
|
|
|
// The first is the exact shape oxc emits for the memoized SDK import in a
|
|
// shipped build; the second is the spaced variant the pattern also accepts.
|
|
const sources = new Map([
|
|
[
|
|
'out/main/index.js',
|
|
'let p=null;function q(){return p??=import(`@anthropic-ai/claude-agent-sdk`),p}'
|
|
],
|
|
[
|
|
'out/main/agent-hooks/managed-agent-hook-controls.js',
|
|
'import (`@anthropic-ai/claude-agent-sdk`)'
|
|
]
|
|
])
|
|
const asar = {
|
|
listPackage: () => [...sources.keys()].map((entry) => `/${entry}`),
|
|
extractFile: (_asarPath, internalPath) => Buffer.from(sources.get(internalPath), 'utf8')
|
|
}
|
|
|
|
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).toThrow(
|
|
/@anthropic-ai\/claude-agent-sdk/
|
|
)
|
|
|
|
await mkdir(join(resourcesDir, 'node_modules', '@anthropic-ai', 'claude-agent-sdk'), {
|
|
recursive: true
|
|
})
|
|
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).not.toThrow()
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('still fails when a required packaged main entry is missing entirely', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-runtime-missing-entry-'))
|
|
try {
|
|
await writeFile(join(resourcesDir, 'app.asar'), '', 'utf8')
|
|
|
|
const asar = {
|
|
listPackage: () => ['/out/main/index.js'],
|
|
extractFile: () => Buffer.from('', 'utf8')
|
|
}
|
|
|
|
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).toThrow(
|
|
/managed-agent-hook-controls\.js was not found/
|
|
)
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('verifies bare imports that rolldown hoisted into a shared main chunk', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-runtime-chunk-imports-'))
|
|
try {
|
|
await writeFile(join(resourcesDir, 'app.asar'), '', 'utf8')
|
|
|
|
// The entry points themselves carry no specifier; only the shared chunk does.
|
|
const sources = new Map([
|
|
['out/main/index.js', ''],
|
|
['out/main/agent-hooks/managed-agent-hook-controls.js', ''],
|
|
['out/main/chunks/managed-agent-hook-controls-CWf8D-KR.js', 'require(`jsonc-parser`)']
|
|
])
|
|
// Real listPackage emits directory nodes too, and extractFile throws on them,
|
|
// so the `.js` anchor is load-bearing -- keep the mock able to catch that.
|
|
const directories = ['/out', '/out/main', '/out/main/chunks']
|
|
const asar = {
|
|
listPackage: () => [...directories, ...[...sources.keys()].map((entry) => `/${entry}`)],
|
|
extractFile: (_asarPath, internalPath) => {
|
|
const source = sources.get(internalPath)
|
|
if (source === undefined) {
|
|
throw new Error(`Expected to find file at: ${internalPath} but found a directory`)
|
|
}
|
|
return Buffer.from(source, 'utf8')
|
|
}
|
|
}
|
|
|
|
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).toThrow(/jsonc-parser/)
|
|
|
|
await mkdir(join(resourcesDir, 'node_modules', 'jsonc-parser'), { recursive: true })
|
|
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).not.toThrow()
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('reads a spread require, whose leading dots are not member access', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-runtime-spread-require-'))
|
|
try {
|
|
await writeFile(join(resourcesDir, 'app.asar'), '', 'utf8')
|
|
|
|
const sources = new Map([
|
|
['out/main/index.js', 'const all=[...require("jsonc-parser")]'],
|
|
['out/main/agent-hooks/managed-agent-hook-controls.js', '']
|
|
])
|
|
const asar = {
|
|
listPackage: () => [...sources.keys()].map((entry) => `/${entry}`),
|
|
extractFile: (_asarPath, internalPath) => Buffer.from(sources.get(internalPath), 'utf8')
|
|
}
|
|
|
|
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).toThrow(/jsonc-parser/)
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('ignores member calls onto Orca methods that are themselves named require', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-runtime-member-require-'))
|
|
try {
|
|
await writeFile(join(resourcesDir, 'app.asar'), '', 'utf8')
|
|
|
|
// electron-sidecar-tab-registry and browser-execution-host-grant-registry both
|
|
// expose require(key); a literal key must never read as a packaged specifier.
|
|
const sources = new Map([
|
|
['out/main/index.js', 'registry.require("public-a");grants.require(`host-key`)'],
|
|
['out/main/agent-hooks/managed-agent-hook-controls.js', 'state.import("android-sdk")']
|
|
])
|
|
const asar = {
|
|
listPackage: () => [...sources.keys()].map((entry) => `/${entry}`),
|
|
extractFile: (_asarPath, internalPath) => Buffer.from(sources.get(internalPath), 'utf8')
|
|
}
|
|
|
|
expect(() => verifyPackagedMainRuntimeDeps(resourcesDir, asar)).not.toThrow()
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('normalizes host-specific asar entry separators', () => {
|
|
expect(findAsarEntry(['\\out\\main\\index.js'], 'out/main/index.js')).toBe(
|
|
'\\out\\main\\index.js'
|
|
)
|
|
expect(findAsarEntry(['/out/main/index.js'], 'out/main/index.js')).toBe('/out/main/index.js')
|
|
})
|
|
|
|
it('prunes non-target node-pty architecture outputs from packaged runtime resources', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-node-pty-prune-'))
|
|
try {
|
|
const nodePtyDir = join(resourcesDir, 'node_modules', 'node-pty')
|
|
const prebuildsDir = join(nodePtyDir, 'prebuilds')
|
|
const binDir = join(nodePtyDir, 'bin')
|
|
await mkdir(join(prebuildsDir, 'darwin-arm64'), { recursive: true })
|
|
await mkdir(join(prebuildsDir, 'darwin-x64'), { recursive: true })
|
|
await mkdir(join(prebuildsDir, 'linux-x64'), { recursive: true })
|
|
await mkdir(join(prebuildsDir, 'win32-x64'), { recursive: true })
|
|
await mkdir(join(binDir, 'darwin-arm64-148'), { recursive: true })
|
|
await mkdir(join(binDir, 'darwin-x64-148'), { recursive: true })
|
|
await mkdir(join(nodePtyDir, 'third_party', 'conpty'), {
|
|
recursive: true
|
|
})
|
|
await mkdir(join(nodePtyDir, 'deps', 'winpty'), { recursive: true })
|
|
|
|
prunePackagedNodePty(resourcesDir, 'darwin', 3)
|
|
|
|
await expect(readdir(prebuildsDir)).resolves.toEqual(['darwin-arm64'])
|
|
await expect(readdir(binDir)).resolves.toEqual(['darwin-arm64-148'])
|
|
await expect(readdir(join(nodePtyDir, 'third_party'))).resolves.toEqual([])
|
|
await expect(readdir(join(nodePtyDir, 'deps'))).resolves.toEqual([])
|
|
expect(() => prunePackagedNodePty(resourcesDir, 'darwin', 4)).toThrow(
|
|
'Unsupported packaged runtime architecture: 4'
|
|
)
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('copies the Windows node-pty ConPTY runtime beside the rebuilt addon', async () => {
|
|
for (const [arch, electronArch] of [
|
|
['x64', 1],
|
|
['arm64', 3]
|
|
]) {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), `orca-node-pty-conpty-${arch}-`))
|
|
try {
|
|
const nodePtyDir = join(resourcesDir, 'node_modules', 'node-pty')
|
|
const releaseDir = join(nodePtyDir, 'build', 'Release')
|
|
const conptyRoot = join(nodePtyDir, 'third_party', 'conpty', '0.1.0')
|
|
await mkdir(releaseDir, { recursive: true })
|
|
await writeFile(join(releaseDir, 'conpty.node'), 'native addon placeholder', 'utf8')
|
|
for (const sourceArch of ['x64', 'arm64']) {
|
|
const sourceDir = join(conptyRoot, `win10-${sourceArch}`)
|
|
await mkdir(sourceDir, { recursive: true })
|
|
await writeFile(join(sourceDir, 'conpty.dll'), `dll payload ${sourceArch}`, 'utf8')
|
|
await writeFile(
|
|
join(sourceDir, 'OpenConsole.exe'),
|
|
`console payload ${sourceArch}`,
|
|
'utf8'
|
|
)
|
|
}
|
|
|
|
prunePackagedNodePty(resourcesDir, 'win32', electronArch)
|
|
|
|
await expect(readFile(join(releaseDir, 'conpty', 'conpty.dll'), 'utf8')).resolves.toBe(
|
|
`dll payload ${arch}`
|
|
)
|
|
await expect(readFile(join(releaseDir, 'conpty', 'OpenConsole.exe'), 'utf8')).resolves.toBe(
|
|
`console payload ${arch}`
|
|
)
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
}
|
|
})
|
|
|
|
it('includes external main dependencies in the packaged runtime closure', () => {
|
|
// Why: the main process imports '@parcel/watcher' for filesystem change
|
|
// events; if it is absent from the packaged closure the serve host silently
|
|
// stops propagating file changes to clients (regression guard for #4851).
|
|
const packaged = createPackagedRuntimeNodeModuleResources()
|
|
const packagedTargets = packaged.map((resource) => resource.to)
|
|
expect(packagedTargets).toContain(join('node_modules', '@parcel', 'watcher'))
|
|
expect(
|
|
packagedTargets.some((target) =>
|
|
target.startsWith(join('node_modules', '@parcel', 'watcher-'))
|
|
)
|
|
).toBe(true)
|
|
expect(packagedTargets).toContain(join('node_modules', 'proper-lockfile'))
|
|
})
|
|
|
|
it('includes the Claude agent SDK in every desktop package plan', () => {
|
|
for (const platform of windowsAddonsInstalled
|
|
? ['darwin', 'linux', 'win32']
|
|
: ['darwin', 'linux']) {
|
|
const packagedTargets = createPackagedRuntimeNodeModuleResources(platform).map(
|
|
(resource) => resource.to
|
|
)
|
|
expect(packagedTargets).toContain(join('node_modules', '@anthropic-ai', 'claude-agent-sdk'))
|
|
}
|
|
})
|
|
|
|
it('prunes non-target @parcel/watcher architecture subpackages', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-parcel-watcher-prune-'))
|
|
try {
|
|
const parcelDir = join(resourcesDir, 'node_modules', '@parcel')
|
|
await mkdir(join(parcelDir, 'watcher'), { recursive: true })
|
|
await mkdir(join(parcelDir, 'watcher-darwin-arm64'), { recursive: true })
|
|
await mkdir(join(parcelDir, 'watcher-darwin-x64'), { recursive: true })
|
|
await mkdir(join(parcelDir, 'watcher-linux-x64-glibc'), { recursive: true })
|
|
await mkdir(join(parcelDir, 'watcher-linux-arm64-glibc'), { recursive: true })
|
|
await mkdir(join(parcelDir, 'watcher-win32-x64'), { recursive: true })
|
|
|
|
prunePackagedParcelWatcher(resourcesDir, 'linux', 'arm64')
|
|
|
|
await expect(readdir(parcelDir).then((entries) => entries.sort())).resolves.toEqual([
|
|
'watcher',
|
|
'watcher-linux-arm64-glibc'
|
|
])
|
|
expect(() => prunePackagedParcelWatcher(resourcesDir, 'linux', 'universal')).toThrow(
|
|
'Unsupported packaged runtime architecture: universal'
|
|
)
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('leaves unrelated @parcel/* runtime deps untouched when pruning the watcher', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-parcel-watcher-prune-unrelated-'))
|
|
try {
|
|
const parcelDir = join(resourcesDir, 'node_modules', '@parcel')
|
|
await mkdir(join(parcelDir, 'watcher'), { recursive: true })
|
|
await mkdir(join(parcelDir, 'watcher-darwin-arm64'), { recursive: true })
|
|
await mkdir(join(parcelDir, 'watcher-linux-x64-glibc'), { recursive: true })
|
|
// A hypothetical future @parcel/* runtime dep that is NOT a watcher subpackage.
|
|
await mkdir(join(parcelDir, 'transformer-js'), { recursive: true })
|
|
|
|
prunePackagedParcelWatcher(resourcesDir, 'linux', 1)
|
|
|
|
await expect(readdir(parcelDir).then((entries) => entries.sort())).resolves.toEqual([
|
|
'transformer-js',
|
|
'watcher',
|
|
'watcher-linux-x64-glibc'
|
|
])
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('prunes type declaration artifacts from packaged runtime node_modules', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-runtime-type-prune-'))
|
|
try {
|
|
const packageDir = join(resourcesDir, 'node_modules', 'example-package')
|
|
await mkdir(join(packageDir, 'dist'), { recursive: true })
|
|
await writeFile(join(packageDir, 'dist', 'index.cjs'), 'module.exports = {}', 'utf8')
|
|
await writeFile(join(packageDir, 'dist', 'index.d.ts'), 'export type Value = string', 'utf8')
|
|
await writeFile(join(packageDir, 'dist', 'index.d.cts'), 'export type Value = string', 'utf8')
|
|
await writeFile(join(packageDir, 'dist', 'index.d.mts.map'), '{}', 'utf8')
|
|
|
|
prunePackagedRuntimeTypeAndSourceMapArtifacts(resourcesDir)
|
|
|
|
await expect(readdir(join(packageDir, 'dist'))).resolves.toEqual(['index.cjs'])
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('prunes duplicate darwin sherpa-onnx runtime dylib aliases', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-sherpa-prune-'))
|
|
try {
|
|
const packageDir = join(resourcesDir, 'node_modules', 'sherpa-onnx-darwin-arm64')
|
|
await mkdir(packageDir, { recursive: true })
|
|
await writeFile(join(packageDir, 'sherpa-onnx.node'), '', 'utf8')
|
|
await writeFile(join(packageDir, 'libonnxruntime.1.23.2.dylib'), '', 'utf8')
|
|
await writeFile(join(packageDir, 'libonnxruntime.dylib'), '', 'utf8')
|
|
|
|
prunePackagedSherpaOnnx(resourcesDir, 'darwin')
|
|
|
|
await expect(readdir(packageDir).then((entries) => entries.sort())).resolves.toEqual([
|
|
'libonnxruntime.1.23.2.dylib',
|
|
'sherpa-onnx.node'
|
|
])
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('prunes zod TypeScript sources from packaged runtime resources', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-zod-prune-'))
|
|
try {
|
|
const packageDir = join(resourcesDir, 'node_modules', 'zod')
|
|
await mkdir(join(packageDir, 'src'), { recursive: true })
|
|
await writeFile(join(packageDir, 'index.cjs'), 'module.exports = {}', 'utf8')
|
|
await writeFile(join(packageDir, 'src', 'index.ts'), 'export const value = true', 'utf8')
|
|
|
|
prunePackagedZodSources(resourcesDir)
|
|
|
|
await expect(readdir(packageDir)).resolves.toEqual(['index.cjs'])
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
|
|
it('fails when the packaged resources directory is missing', async () => {
|
|
const root = await mkdtemp(join(tmpdir(), 'orca-electron-builder-config-'))
|
|
try {
|
|
await expect(
|
|
electronBuilderConfig.afterPack({
|
|
appOutDir: root,
|
|
electronPlatformName: 'win32'
|
|
})
|
|
).rejects.toThrow(/Missing packaged resources directory/)
|
|
} finally {
|
|
await removeTree(root)
|
|
}
|
|
})
|
|
|
|
it.skipIf(process.platform === 'win32')(
|
|
'prunes non-target native packages before the Linux glibc gate',
|
|
async () => {
|
|
const root = await mkdtemp(join(tmpdir(), 'orca-after-pack-prune-order-'))
|
|
const previousPath = process.env.PATH
|
|
try {
|
|
const appOutDir = join(root, 'linux-unpacked')
|
|
const resourcesDir = join(appOutDir, 'resources')
|
|
await cp(
|
|
join(process.cwd(), 'resources', 'plugins', 'launch'),
|
|
join(resourcesDir, 'plugins', 'launch'),
|
|
{ recursive: true }
|
|
)
|
|
await seedBundledRipgrep(resourcesDir)
|
|
|
|
const unpackedMainDir = join(resourcesDir, 'app.asar.unpacked', 'out', 'main')
|
|
await mkdir(unpackedMainDir, { recursive: true })
|
|
await writeFile(join(unpackedMainDir, 'daemon-entry.js'), '', 'utf8')
|
|
await writeFile(
|
|
join(resourcesDir, 'app.asar.unpacked', 'out', 'package.json'),
|
|
`${JSON.stringify({ name: 'orca-compiled-output', type: 'commonjs', private: true })}\n`,
|
|
'utf8'
|
|
)
|
|
|
|
const unpackedCliDir = join(resourcesDir, 'app.asar.unpacked', 'out', 'cli')
|
|
await mkdir(join(unpackedCliDir, 'handlers'), { recursive: true })
|
|
await writeFile(join(unpackedCliDir, 'handlers', 'skills.js'), '', 'utf8')
|
|
await writeFile(join(unpackedCliDir, 'index.js'), '', 'utf8')
|
|
|
|
const target =
|
|
process.arch === 'x64'
|
|
? { electronArch: 3, machine: 0xb7, nonTarget: 'x64' }
|
|
: { electronArch: 1, machine: 0x3e, nonTarget: 'arm64' }
|
|
const wrongArchPackage = join(
|
|
resourcesDir,
|
|
'node_modules',
|
|
'@parcel',
|
|
`watcher-linux-${target.nonTarget}-glibc`
|
|
)
|
|
await mkdir(wrongArchPackage, { recursive: true })
|
|
const wrongArchElf = Buffer.alloc(20)
|
|
wrongArchElf.set([0x7f, 0x45, 0x4c, 0x46])
|
|
wrongArchElf[5] = 1
|
|
wrongArchElf.writeUInt16LE(target.machine, 18)
|
|
await writeFile(join(wrongArchPackage, 'watcher.node'), wrongArchElf)
|
|
|
|
const stubBinDir = join(root, 'bin')
|
|
await mkdir(stubBinDir)
|
|
await writeFile(join(stubBinDir, 'objdump'), '#!/bin/sh\nexit 0\n', { mode: 0o755 })
|
|
process.env.PATH = `${stubBinDir}${delimiter}${previousPath ?? ''}`
|
|
|
|
await expect(
|
|
electronBuilderConfig.afterPack({
|
|
appOutDir,
|
|
electronPlatformName: 'linux',
|
|
arch: target.electronArch,
|
|
packager: { appInfo: { version: '9.9.9' } }
|
|
})
|
|
).resolves.toBeUndefined()
|
|
await expect(stat(wrongArchPackage)).rejects.toMatchObject({ code: 'ENOENT' })
|
|
} finally {
|
|
process.env.PATH = previousPath
|
|
await removeTree(root)
|
|
}
|
|
}
|
|
)
|
|
|
|
it.skipIf(process.platform === 'win32')(
|
|
'marks packaged Unix CLI launchers executable',
|
|
async () => {
|
|
const root = await mkdtemp(join(tmpdir(), 'orca-electron-builder-config-'))
|
|
try {
|
|
const resourcesDir = join(root, 'linux-unpacked', 'resources')
|
|
const launcherPath = join(resourcesDir, 'bin', 'orca-ide')
|
|
await mkdir(join(resourcesDir, 'bin'), { recursive: true })
|
|
await cp(
|
|
join(process.cwd(), 'resources', 'plugins', 'launch'),
|
|
join(resourcesDir, 'plugins', 'launch'),
|
|
{ recursive: true }
|
|
)
|
|
await seedBundledRipgrep(resourcesDir)
|
|
await mkdir(join(resourcesDir, 'node_modules', 'zod', 'src'), { recursive: true })
|
|
// Why: afterPack now fails hard when the unpacked daemon entry is
|
|
// missing, so the fixture must carry one like a real package layout.
|
|
const unpackedMainDir = join(resourcesDir, 'app.asar.unpacked', 'out', 'main')
|
|
await mkdir(unpackedMainDir, { recursive: true })
|
|
await writeFile(
|
|
join(unpackedMainDir, 'daemon-entry.js'),
|
|
'console.error("Usage: daemon-entry <socket>"); process.exit(1)\n',
|
|
'utf8'
|
|
)
|
|
await writeFile(
|
|
join(resourcesDir, 'app.asar.unpacked', 'out', 'package.json'),
|
|
`${JSON.stringify({ name: 'orca-compiled-output', type: 'commonjs', private: true })}\n`,
|
|
'utf8'
|
|
)
|
|
const unpackedCliDir = join(resourcesDir, 'app.asar.unpacked', 'out', 'cli')
|
|
await mkdir(join(unpackedCliDir, 'handlers'), { recursive: true })
|
|
await writeFile(join(unpackedCliDir, 'handlers', 'skills.js'), '', 'utf8')
|
|
await writeFile(
|
|
join(unpackedCliDir, 'index.js'),
|
|
[
|
|
'const args = process.argv.slice(2)',
|
|
"if (args[1] === 'list') console.log(JSON.stringify({ topics: [{ name: 'orca-cli' }, { name: 'computer-use' }] }))",
|
|
"else if (args[1] === 'get') console.log(`---\\nname: ${args[2]}\\n---`)",
|
|
'else console.log(JSON.stringify({ executed: false }))'
|
|
].join('\n'),
|
|
'utf8'
|
|
)
|
|
await writeFile(launcherPath, '#!/usr/bin/env bash\n', { encoding: 'utf8', mode: 0o644 })
|
|
|
|
await electronBuilderConfig.afterPack({
|
|
appOutDir: join(root, 'linux-unpacked'),
|
|
electronPlatformName: 'linux',
|
|
arch: 1,
|
|
packager: { appInfo: { version: '9.9.9' } }
|
|
})
|
|
|
|
expect((await stat(launcherPath)).mode & 0o111).not.toBe(0)
|
|
await expect(
|
|
readFile(join(resourcesDir, 'app.asar.unpacked', 'out', 'package.json'), 'utf8')
|
|
).resolves.toContain('"version": "9.9.9"')
|
|
await expect(readFile(join(resourcesDir, 'package-type'), 'utf8')).resolves.toBe('AppImage')
|
|
} finally {
|
|
await removeTree(root)
|
|
}
|
|
}
|
|
)
|
|
})
|
|
|
|
// Why source-anchored: the bundler renames a createRequire()'d require, so
|
|
// verifyPackagedMainRuntimeDeps' `require("x")` scan cannot see these specifiers — packaging
|
|
// stays green while the packaged app throws MODULE_NOT_FOUND the first time the path runs.
|
|
// Why stubs: afterPack only checks each platform binary exists; non-ELF bytes skip the glibc scan.
|
|
async function seedBundledRipgrep(resourcesDir) {
|
|
const { BUNDLED_RIPGREP_PLATFORMS } = require('../bundled-ripgrep-resources.cjs')
|
|
for (const platform of BUNDLED_RIPGREP_PLATFORMS) {
|
|
const dir = join(resourcesDir, 'ripgrep', platform)
|
|
await mkdir(dir, { recursive: true })
|
|
await writeFile(join(dir, platform.startsWith('win32-') ? 'rg.exe' : 'rg'), '', 'utf8')
|
|
}
|
|
}
|
|
|
|
function collectLazyRequireSpecifiers(directory, found = new Map()) {
|
|
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
const entryPath = join(directory, entry.name)
|
|
if (entry.isDirectory()) {
|
|
collectLazyRequireSpecifiers(entryPath, found)
|
|
continue
|
|
}
|
|
if (!entry.isFile() || !entry.name.endsWith('.ts') || entry.name.includes('.test.')) {
|
|
continue
|
|
}
|
|
const source = readFileSync(entryPath, 'utf8')
|
|
if (!source.includes('createRequire(')) {
|
|
continue
|
|
}
|
|
for (const match of source.matchAll(/\brequire[A-Za-z0-9_]*\(\s*'([^']+)'\s*\)/g)) {
|
|
if (isPackagedExternalSpecifier(match[1])) {
|
|
found.set(match[1], relative(projectRoot, entryPath).replaceAll('\\', '/'))
|
|
}
|
|
}
|
|
}
|
|
return found
|
|
}
|
|
|
|
function packagedResourceDestinations(platform) {
|
|
return new Set(
|
|
(electronBuilderConfig[platform].extraResources ?? []).map((resource) =>
|
|
String(resource.to).replaceAll('\\', '/')
|
|
)
|
|
)
|
|
}
|
|
|
|
describe('lazily required packages reach Resources/node_modules', () => {
|
|
it('copies every createRequire specifier main uses into the packaged resource plan', () => {
|
|
const specifiers = collectLazyRequireSpecifiers(join(projectRoot, 'src', 'main'))
|
|
expect(specifiers.size).toBeGreaterThan(0)
|
|
|
|
const destinations = {
|
|
win: packagedResourceDestinations('win'),
|
|
mac: packagedResourceDestinations('mac'),
|
|
linux: packagedResourceDestinations('linux')
|
|
}
|
|
for (const [specifier, source] of specifiers) {
|
|
const packageName = packageNameFromSpecifier(specifier)
|
|
const covered = (platform) =>
|
|
destinations[platform].has(`node_modules/${packageName}`) ||
|
|
destinations[platform].has(`node_modules/${specifier}`)
|
|
// The Windows CI lane checks the full closure with its native addons installed.
|
|
if (windowsAddonsInstalled) {
|
|
expect(
|
|
covered('win'),
|
|
`${source} lazily requires '${specifier}', but nothing copies it to Resources/node_modules`
|
|
).toBe(true)
|
|
}
|
|
if (covered('mac') && covered('linux')) {
|
|
continue
|
|
}
|
|
// Only the Windows-native loaders may be absent from the mac/linux plans.
|
|
expect(source, `'${specifier}' is packaged for Windows only`).toContain('windows')
|
|
}
|
|
})
|
|
|
|
it('resolves the copied emoji dataset the way the packaged main bundle does', async () => {
|
|
const resourcesDir = await mkdtemp(join(tmpdir(), 'orca-lazy-require-'))
|
|
try {
|
|
const datasetPath = 'node_modules/emojibase-data/en/shortcodes/emojibase.json'
|
|
const entry = electronBuilderConfig.mac.extraResources.find(
|
|
(resource) => String(resource.to) === datasetPath
|
|
)
|
|
expect(entry).toBeDefined()
|
|
const destination = join(resourcesDir, ...datasetPath.split('/'))
|
|
await mkdir(dirname(destination), { recursive: true })
|
|
await cp(join(projectRoot, ...String(entry.from).split('/')), destination)
|
|
|
|
// app.asar's parent is Resources, so main's bare require walks into Resources/node_modules.
|
|
const packagedMainDir = join(resourcesDir, 'app.asar', 'out', 'main')
|
|
await mkdir(packagedMainDir, { recursive: true })
|
|
const probe = join(packagedMainDir, 'probe.cjs')
|
|
await writeFile(probe, 'module.exports = require', 'utf8')
|
|
|
|
const dataset = require(probe)('emojibase-data/en/shortcodes/emojibase.json')
|
|
expect(Object.keys(dataset).length).toBeGreaterThan(1000)
|
|
} finally {
|
|
await removeTree(resourcesDir)
|
|
}
|
|
})
|
|
})
|