Files
orca/src/main/ipc/parcel-watcher-entry-path.test.ts
T
Neil 20c1a61401 fix(orcad): answer host paths honestly and ship the watcher child (#16369)
orcad's AppEnvironment implemented three of seven AppPathNames and returned the
userData directory for the rest — including 'exe', where a data directory is not
an executable. Every name now has a Node answer: 'appData' is the platform's
per-user application-data root, 'logs' lives inside the data root so a headless
deployment stays one removable directory, 'downloads' honours XDG_DOWNLOAD_DIR,
and 'exe' is the Node binary. getAppPath() is the directory orcad was launched
from rather than cwd, so children resolve against the bundle instead of wherever
the supervisor happened to be.

The watcher child was the load-bearing consequence: resolveWatcherProcessEntryPath
probed for the adjacent entry only when !isPackaged, so orcad resolved a desktop
out/main path that no deployment has — and build-orcad never emitted the child
anyway. isPackaged stays true (consumers read it as "production, not a dev
checkout" and it gates HTTPS-only skill downloads); the resolver now asks whether
the app root is an asar archive, which is the question it actually meant. The
child ships beside orcad.js, and the build forks it to prove it runs.
2026-08-24 23:01:17 -07:00

94 lines
3.1 KiB
TypeScript

import path from 'node:path'
import { describe, expect, it } from 'vitest'
import {
resolveWatcherProcessEntryPath,
resolveWatcherProcessEntryPathWithoutApp
} from './parcel-watcher-entry-path'
describe('resolveWatcherProcessEntryPath', () => {
it('uses an adjacent entry when electron-vite appPath is already out/main', () => {
const builtMainPath = path.join(process.cwd(), 'out', 'main')
const adjacentEntry = path.join(builtMainPath, 'parcel-watcher-process-entry.js')
expect(
resolveWatcherProcessEntryPath(
builtMainPath,
false,
(candidate) => candidate === adjacentEntry
)
).toBe(adjacentEntry)
})
it('uses the nested build entry when appPath is the project root', () => {
expect(resolveWatcherProcessEntryPath(process.cwd(), false, () => false)).toBe(
path.join(process.cwd(), 'out', 'main', 'parcel-watcher-process-entry.js')
)
})
it('uses the unpacked nested entry for packaged apps', () => {
const appPath = path.join('C:', 'Orca', 'resources', 'app.asar')
expect(resolveWatcherProcessEntryPath(appPath, true, () => true)).toBe(
path.join(
'C:',
'Orca',
'resources',
'app.asar.unpacked',
'out',
'main',
'parcel-watcher-process-entry.js'
)
)
})
it('uses the adjacent entry for a packaged host whose app root is not an asar', () => {
// orcad: a packaged Node bundle that ships this child beside orcad.js. Gating the
// adjacent probe on isPackaged sent it to a desktop out/main that never exists here.
const orcadRoot = path.join(path.sep, 'opt', 'orca')
const adjacentEntry = path.join(orcadRoot, 'parcel-watcher-process-entry.js')
expect(
resolveWatcherProcessEntryPath(orcadRoot, true, (candidate) => candidate === adjacentEntry)
).toBe(adjacentEntry)
})
it('falls back to the nested entry when a non-asar packaged host ships no adjacent child', () => {
const orcadRoot = path.join(path.sep, 'opt', 'orca')
expect(resolveWatcherProcessEntryPath(orcadRoot, true, () => false)).toBe(
path.join(orcadRoot, 'out', 'main', 'parcel-watcher-process-entry.js')
)
})
it('uses resourcesPath for packaged Electron-as-Node serve processes', () => {
const resourcesPath = path.join('Applications', 'Orca.app', 'Contents', 'Resources')
const packagedEntry = path.join(
resourcesPath,
'app.asar.unpacked',
'out',
'main',
'parcel-watcher-process-entry.js'
)
expect(
resolveWatcherProcessEntryPathWithoutApp(
path.join(resourcesPath, 'unrelated-cwd'),
resourcesPath,
(candidate) => candidate === packagedEntry
)
).toBe(packagedEntry)
})
it('keeps the cwd build fallback when resourcesPath has no packaged entry', () => {
const appRoot = path.join('workspace', 'orca')
expect(
resolveWatcherProcessEntryPathWithoutApp(
appRoot,
path.join('node_modules', 'electron', 'Resources'),
() => false
)
).toBe(path.join(appRoot, 'out', 'main', 'parcel-watcher-process-entry.js'))
})
})