Skip to content

The agent that grows with you

fix(e2e): bridge historical Windows desktop launches

ethernet29f74ab71ce7
diff --git a/tests-js/scripts/desktop-smoke.test.ts b/tests-js/scripts/desktop-smoke.test.ts
index 4e7c79f51e4..0a046e12b37 100644
--- a/tests-js/scripts/desktop-smoke.test.ts
+++ b/tests-js/scripts/desktop-smoke.test.ts
@@ -7,6 +7,8 @@ import yaml from 'js-yaml'
import { expect, test } from 'vitest'
import { candidateSmokeHermesHomes, predictSmokeHermesHome, resolveSmokeLaunch, runInstalledDesktopSmoke, smokeEnvironment } from '../../tests/install/e2e-assets/desktop-smoke.ts'
+import { sourceRuntimeSettleCommand } from '../../tests/install/e2e-assets/source-runtime-settle.mjs'
+import { assertUpdateWindowBackendOrigin } from '../../tests/install/e2e-assets/update-window-chat.mjs'
import { assertChatCommit, newCompletedPair, readMockPrompts, type TranscriptMessage } from './desktop-chat-smoke.ts'
import { assertBackendOrigin, localBackendProcess, readBundledBundleEnv, readInstallationCommit } from './desktop-smoke-process.ts'
@@ -199,6 +201,24 @@ test('a platform that cannot read the backend environment proves ownership by th
} finally { fs.rmSync(home, { recursive: true, force: true }) }
})
+test('OLD update-window source provenance carries its verified app identity to the listener check', (): void => {
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'smoke-old-owner-origin-'))
+ try {
+ const root = path.join(home, 'hermes-agent')
+ const other = path.join(home, 'other-tree')
+ fs.mkdirSync(root, { recursive: true })
+ fs.mkdirSync(other, { recursive: true })
+ const backend = { pid: 2, parentPid: 1, executable: path.join(home, 'python.exe'),
+ command: `"${path.join(home, 'python.exe')}" -m hermes_cli.main dashboard --port 0` }
+ expect((): void => {
+ assertUpdateWindowBackendOrigin(backend, { hermesRoot: root }, root, 'source')
+ }).not.toThrow()
+ expect((): void => {
+ assertUpdateWindowBackendOrigin(backend, { hermesRoot: other }, root, 'source')
+ }).toThrow('resolved another source installation')
+ } finally { fs.rmSync(home, { recursive: true, force: true }) }
+})
+
test('source launch restores only an explicitly captured exact editable root', (): void => {
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'smoke-source-'))
const specPath = path.join(home, 'launch.json')
@@ -344,6 +364,49 @@ printf 'clean source runtime settled\\n'
} finally { fs.rmSync(workspace, { recursive: true, force: true }) }
})
+test('Windows source settle prefers the current cmd launcher over a stale historical exe', (): void => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'smoke-windows-settle-'))
+ try {
+ const bin = path.join(root, '.hermes', 'bin')
+ fs.mkdirSync(bin, { recursive: true })
+ const current = path.join(bin, 'hermes.cmd')
+ fs.writeFileSync(current, '@echo off\r\n')
+ fs.writeFileSync(path.join(bin, 'hermes.exe'), 'locked historical launcher')
+ const invocation = sourceRuntimeSettleCommand(root, { ComSpec: 'C:\\Windows\\System32\\cmd.exe' }, 'win32')
+ expect(invocation).toEqual({
+ launcher: current,
+ command: 'C:\\Windows\\System32\\cmd.exe',
+ args: ['/d', '/s', '/c', `""${current}" status"`],
+ windowsVerbatimArguments: true,
+ })
+ } finally { fs.rmSync(root, { recursive: true, force: true }) }
+})
+
+test.runIf(process.platform === 'win32')('Windows source settle executes a cmd launcher whose path contains spaces', (): void => {
+ const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'smoke-windows-settle-live-'))
+ const root = path.join(workspace, 'source with spaces')
+ try {
+ const bin = path.join(root, '.hermes', 'bin')
+ const witness = path.join(workspace, 'settled.txt')
+ fs.mkdirSync(bin, { recursive: true })
+ fs.writeFileSync(path.join(bin, 'hermes.cmd'), [
+ '@echo off',
+ 'if not "%~1"=="status" exit /b 91',
+ `>"${witness}" echo current-cmd`,
+ 'exit /b 0',
+ '',
+ ].join('\r\n'))
+ fs.writeFileSync(path.join(bin, 'hermes.exe'), 'locked historical launcher')
+ const invocation = sourceRuntimeSettleCommand(root, process.env)
+ const result = spawnSync(invocation.command, invocation.args, {
+ cwd: root, env: process.env, encoding: 'utf8', windowsHide: true,
+ windowsVerbatimArguments: invocation.windowsVerbatimArguments,
+ })
+ expect(result.status, result.stderr || String(result.error)).toBe(0)
+ expect(fs.readFileSync(witness, 'utf8').trim()).toBe('current-cmd')
+ } finally { fs.rmSync(workspace, { recursive: true, force: true }) }
+})
+
test('predictSmokeHermesHome replays the bundle banner through the shared resolver', (): void => {
const launchEnv = { HERMES_HOME: '/pinned/home', HERMES_DESKTOP_USER_DATA_DIR: '/pinned/userdata', LOCALAPPDATA: 'C:/Users/runner/AppData/Local' }
// No baked env: the driver's own HERMES_HOME pin wins.
diff --git a/tests/install/e2e-assets/desktop-smoke.ts b/tests/install/e2e-assets/desktop-smoke.ts
index 46c6c6c635d..b31148ad897 100644
--- a/tests/install/e2e-assets/desktop-smoke.ts
+++ b/tests/install/e2e-assets/desktop-smoke.ts
@@ -17,6 +17,7 @@ import { validateMockUrl, writeEnvFile, writeMockProviderConfig } from '../../..
import { type MockServer, startMockServer } from '../../../tests-js/scripts/mock-server.ts'
import { type SmokeEnvironment, smokeEnvironment, within } from './smoke-env.mjs'
+import { sourceRuntimeSettleCommand } from './source-runtime-settle.mjs'
const require = createRequire(import.meta.url)
const { pickAppWindow }: { pickAppWindow: (app: ElectronApplication, log: (message: string) => void) => Promise<Page> } = require('./update-ui.cjs')
@@ -201,20 +202,10 @@ function captureBackendLogs(homes: readonly string[], outDir: string, phase: str
export function settleSourceDesktopRuntime(options: SmokeOptions, launch: Launch): void {
if (options.origin !== 'source' || options.phase !== 'new') { return }
- const suffix = process.platform === 'win32' ? '.exe' : ''
- const candidates = [
- path.join(options.root, '.hermes', 'bin', `hermes${suffix}`),
- process.platform === 'win32'
- ? path.join(options.root, 'venv', 'Scripts', 'hermes.exe')
- : path.join(options.root, 'venv', 'bin', 'hermes'),
- ]
-
- const launcher = candidates.find((candidate: string): boolean => fs.existsSync(candidate))
- if (!launcher) { throw new Error(`No source launcher available to settle ${options.root}`) }
-
- const result = spawnSync(launcher, ['status'], {
+ const invocation = sourceRuntimeSettleCommand(options.root, launch.env)
+ const result = spawnSync(invocation.command, invocation.args, {
cwd: options.root, env: launch.env, encoding: 'utf8', timeout: 20 * 60_000,
- maxBuffer: 16 * 1024 * 1024,
+ maxBuffer: 16 * 1024 * 1024, windowsVerbatimArguments: invocation.windowsVerbatimArguments,
})
const transcript = [result.stdout, result.stderr].filter(Boolean).join('')
diff --git a/tests/install/e2e-assets/launch-from-spec.mjs b/tests/install/e2e-assets/launch-from-spec.mjs
index 1e566f9c5e4..f0df80e9d0c 100644
--- a/tests/install/e2e-assets/launch-from-spec.mjs
+++ b/tests/install/e2e-assets/launch-from-spec.mjs
@@ -34,6 +34,7 @@ import { pickAppWindow, openAbout, waitForUpdate } from './update-ui.cjs';
import { observeSourceUpdate } from './source-update-observer.mjs';
import { runUpdateWindowChat } from './update-window-chat.mjs';
import { updateWindowEnvironment } from './smoke-env.mjs';
+import { sourceRuntimeSettleCommand } from './source-runtime-settle.mjs';
/**
* @typedef {{argv: string[], cwd: string, env: Record<string, string>,
@@ -92,18 +93,11 @@ function log(msg) {
* @param {Record<string, string>} env
*/
function settleSourceRuntime(root, env) {
- const suffix = process.platform === 'win32' ? '.exe' : '';
- const candidates = [
- path.join(root, '.hermes', 'bin', `hermes${suffix}`),
- process.platform === 'win32'
- ? path.join(root, 'venv', 'Scripts', 'hermes.exe')
- : path.join(root, 'venv', 'bin', 'hermes'),
- ];
- const launcher = candidates.find((candidate) => fs.existsSync(candidate));
- if (!launcher) throw new Error(`no source launcher available to settle ${root}`);
+ const invocation = sourceRuntimeSettleCommand(root, env);
log('settling source runtime under the captured launch environment');
- execFileSync(launcher, ['status'], {
+ execFileSync(invocation.command, invocation.args, {
cwd: root, env, stdio: 'inherit', timeout: 20 * 60_000,
+ windowsVerbatimArguments: invocation.windowsVerbatimArguments,
});
}
diff --git a/tests/install/e2e-assets/source-runtime-settle.d.mts b/tests/install/e2e-assets/source-runtime-settle.d.mts
new file mode 100644
index 00000000000..74c23f8bc66
--- /dev/null
+++ b/tests/install/e2e-assets/source-runtime-settle.d.mts
@@ -0,0 +1,12 @@
+export interface SourceRuntimeSettleCommand {
+ launcher: string
+ command: string
+ args: string[]
+ windowsVerbatimArguments: boolean
+}
+
+export function sourceRuntimeSettleCommand(
+ root: string,
+ env: NodeJS.ProcessEnv | Record<string, string>,
+ platform?: NodeJS.Platform,
+): SourceRuntimeSettleCommand
diff --git a/tests/install/e2e-assets/source-runtime-settle.mjs b/tests/install/e2e-assets/source-runtime-settle.mjs
new file mode 100644
index 00000000000..09b76bdf2dc
--- /dev/null
+++ b/tests/install/e2e-assets/source-runtime-settle.mjs
@@ -0,0 +1,35 @@
+import fs from 'node:fs';
+import path from 'node:path';
+
+/**
+ * Resolve the installation-owned launcher used to finish a source update.
+ *
+ * Windows PM installs can contain two launchers during an update. A locked
+ * executable can remain beside the current command file. Select the command
+ * file explicitly because extensionless lookup would choose the executable.
+ *
+ * @param {string} root
+ * @param {NodeJS.ProcessEnv | Record<string, string>} env
+ * @param {NodeJS.Platform} platform
+ * @returns {{launcher: string, command: string, args: string[], windowsVerbatimArguments: boolean}}
+ */
+export function sourceRuntimeSettleCommand(root, env, platform = process.platform) {
+ const local = path.join(root, '.hermes', 'bin');
+ const candidates = platform === 'win32'
+ ? [path.join(local, 'hermes.cmd'), path.join(local, 'hermes.exe'),
+ path.join(root, 'venv', 'Scripts', 'hermes.exe')]
+ : [path.join(local, 'hermes'), path.join(root, 'venv', 'bin', 'hermes')];
+ const launcher = candidates.find(candidate => fs.existsSync(candidate));
+ if (!launcher) throw new Error(`No source launcher available to settle ${root}`);
+
+ if (platform !== 'win32' || path.extname(launcher).toLowerCase() !== '.cmd') {
+ return { launcher, command: launcher, args: ['status'], windowsVerbatimArguments: false };
+ }
+ if (launcher.includes('"')) throw new Error('Source launcher path contains an invalid quote');
+ const command = env.ComSpec || env.COMSPEC
+ || (env.SystemRoot ? path.join(env.SystemRoot, 'System32', 'cmd.exe') : 'cmd.exe');
+ // /s applies cmd.exe's documented outer-quote stripping to this one command
+ // string. The doubled outer quotes keep a launcher path containing spaces
+ // intact while `status` remains a separate command-file argument.
+ return { launcher, command, args: ['/d', '/s', '/c', `""${launcher}" status"`], windowsVerbatimArguments: true };
+}
diff --git a/tests/install/e2e-assets/update-window-chat.d.mts b/tests/install/e2e-assets/update-window-chat.d.mts
new file mode 100644
index 00000000000..0a37561c217
--- /dev/null
+++ b/tests/install/e2e-assets/update-window-chat.d.mts
@@ -0,0 +1,29 @@
+import type { ElectronApplication, Page } from '@playwright/test'
+
+import type { NativeProcess } from '../../../tests-js/scripts/desktop-smoke-process.ts'
+
+export interface UpdateWindowIdentity {
+ hermesRoot: string
+}
+
+export interface UpdateWindowChatOptions {
+ mockUrl: string
+ outDir: string
+ expectCommit: string
+ origin: 'source' | 'bundled'
+ root: string
+ executable: string
+}
+
+export function assertUpdateWindowBackendOrigin(
+ backend: NativeProcess,
+ identity: UpdateWindowIdentity,
+ root: string,
+ origin: 'source' | 'bundled',
+): void
+
+export function runUpdateWindowChat(
+ app: ElectronApplication,
+ page: Page,
+ options: UpdateWindowChatOptions,
+): Promise<void>
diff --git a/tests/install/e2e-assets/update-window-chat.mjs b/tests/install/e2e-assets/update-window-chat.mjs
index ca6fe87fb10..594a1c4f0bb 100644
--- a/tests/install/e2e-assets/update-window-chat.mjs
+++ b/tests/install/e2e-assets/update-window-chat.mjs
@@ -5,6 +5,18 @@ import path from 'node:path';
import { readChatIdentity, runDesktopChatSmoke, waitForChatReady } from '../../../tests-js/scripts/desktop-chat-smoke.ts';
import { assertBackendOrigin, localBackendProcess, readInstallationCommit } from '../../../tests-js/scripts/desktop-smoke-process.ts';
+/**
+ * Bind an OLD listener to the source tree through the identity from that same
+ * Electron app. Windows CIM exposes neither cwd nor environment for this
+ * module launch. The verified identity and listener ownership prove provenance.
+ */
+export function assertUpdateWindowBackendOrigin(backend, identity, root, origin) {
+ if (origin === 'source' && fs.realpathSync(identity.hermesRoot) !== fs.realpathSync(root)) {
+ throw new Error('OLD update-window chat resolved another source installation');
+ }
+ assertBackendOrigin(backend, root, origin, { appReportedRoot: identity.hermesRoot });
+}
+
/**
* @param {import('@playwright/test').ElectronApplication} app
* @param {import('@playwright/test').Page} page
@@ -36,11 +48,8 @@ export async function runUpdateWindowChat(app, page, options) {
if (connection.mode !== 'local' || !['127.0.0.1', 'localhost', '[::1]'].includes(base.hostname)) {
throw new Error('OLD update-window chat did not use the local installed backend');
}
- if (options.origin === 'source' && fs.realpathSync(identity.hermesRoot) !== fs.realpathSync(options.root)) {
- throw new Error('OLD update-window chat resolved another source installation');
- }
const backend = localBackendProcess(Number(base.port), running.pid);
- assertBackendOrigin(backend, options.root, options.origin);
+ assertUpdateWindowBackendOrigin(backend, identity, options.root, options.origin);
const provenanceCommit = readInstallationCommit(options.root, options.origin);
if (provenanceCommit !== options.expectCommit) throw new Error('Installed OLD commit differs from the expected commit');
const chat = await runDesktopChatSmoke(page, { ...options, phase: 'old', provenanceCommit });