The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): check the packaged working-directory decision on every CI host
Tekniumbf183a39d710
diff --git a/apps/desktop/electron/packaged-working-directory.test.ts b/apps/desktop/electron/packaged-working-directory.test.tsindex f0160a63de1..f827d697ef9 100644--- a/apps/desktop/electron/packaged-working-directory.test.ts+++ b/apps/desktop/electron/packaged-working-directory.test.ts@@ -10,6 +10,8 @@ import { fileURLToPath } from 'node:url'import { build } from 'esbuild'import { test } from 'vitest'+import { packagedWorkingDirectoryTarget } from './packaged-working-directory'+// The resident helper (an IME cloud service, a WSL/ssh helper) that the app spawns// WITHOUT a cwd of its own, so it inherits the app's. It outlives the app and holds// that directory as its cwd for as long as it lives. `detached` keeps it out of@@ -29,6 +31,26 @@ function killPid(pid: number | undefined): void {}}+// The decision itself, on every CI host (the host is data); the live EBUSY proof below needs Windows.+test('a packaged Windows app leaves a CWD inside its install folder and keeps one outside it', () => {+ const app = { platform: 'win32', isPackaged: true, execPath: 'C:\\Hermes\\win-unpacked\\Hermes.exe' } as const+ const home = 'C:\\Users\\ada'++ const target = (cwd: string, facts: Partial<Parameters<typeof packagedWorkingDirectoryTarget>[0]> = {}) =>+ packagedWorkingDirectoryTarget({ ...app, cwd, homedir: home, ...facts })++ assert.equal(target('C:\\Hermes\\win-unpacked'), home, 'the install folder (shortcut "Start in")')+ assert.equal(target('c:\\hermes\\WIN-UNPACKED\\resources'), home, 'below it, any case')+ assert.equal(target('C:\\Hermes'), null, 'the parent folder is a workspace, not the app tree')+ assert.equal(target('D:\\work\\repo'), null, 'a workspace on another drive')+ assert.equal(target('C:\\Hermes\\win-unpacked-old'), null, 'a sibling that shares a name prefix')+ assert.equal(target('C:\\Hermes\\win-unpacked', { isPackaged: false }), null, 'dev runs keep their CWD')++ for (const platform of ['linux', 'darwin'] as const) {+ assert.equal(target('/opt/Hermes', { platform, execPath: '/opt/Hermes/hermes' }), null, platform)+ }+})+// Exercise the real entry point before main loads: the main stand-in spawns the// helper, the app is killed, and the directory swap runs with only the orphaned// helper (exe outside the app tree) still alive.diff --git a/apps/desktop/electron/packaged-working-directory.ts b/apps/desktop/electron/packaged-working-directory.tsindex 6f8f5a6640d..0088e8f5b54 100644--- a/apps/desktop/electron/packaged-working-directory.ts+++ b/apps/desktop/electron/packaged-working-directory.ts@@ -1,18 +1,44 @@import os from 'node:os'import path from 'node:path'-/** Keep resident children from inheriting a CWD that pins the replaceable app tree. */-export function releasePackagedWorkingDirectory(isPackaged: boolean): void {- if (process.platform !== 'win32' || !isPackaged) {- return+export interface WorkingDirectoryFacts {+ platform: NodeJS.Platform+ isPackaged: boolean+ execPath: string+ cwd: string+ homedir: string+}++/**+ * Where a packaged Windows app must move its CWD before main spawns anything, or null to stay.+ * Pure (the host is data) so every CI host checks the decision; the live EBUSY proof runs on Windows.+ */+export function packagedWorkingDirectoryTarget(facts: WorkingDirectoryFacts): string | null {+ if (facts.platform !== 'win32' || !facts.isPackaged) {+ return null}- const relative = path.relative(path.dirname(process.execPath), process.cwd())+ const relative = path.win32.relative(path.win32.dirname(facts.execPath), facts.cwd)// Preserve an explicitly supplied workspace outside the install directory.- if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {- return+ if (relative === '..' || relative.startsWith(`..${path.win32.sep}`) || path.win32.isAbsolute(relative)) {+ return null}- process.chdir(os.homedir())+ return facts.homedir+}++/** Keep resident children from inheriting a CWD that pins the replaceable app tree. */+export function releasePackagedWorkingDirectory(isPackaged: boolean): void {+ const target = packagedWorkingDirectoryTarget({+ platform: process.platform,+ isPackaged,+ execPath: process.execPath,+ cwd: process.cwd(),+ homedir: os.homedir()+ })++ if (target) {+ process.chdir(target)+ }}