The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: route Desktop source update checks to staged Git main
ethernet792a4e63a144
diff --git a/tests-js/update-ui.test.mjs b/tests-js/update-ui.test.mjsindex 476ede0232a..893eea66f8f 100644--- a/tests-js/update-ui.test.mjs+++ b/tests-js/update-ui.test.mjs@@ -1,6 +1,12 @@+import fs from 'node:fs'+import os from 'node:os'+import path from 'node:path'+import { execFileSync, spawnSync } from 'node:child_process'+import { fileURLToPath } from 'node:url'import { JSDOM } from 'jsdom'import { afterEach, expect, test, vi } from 'vitest'import updateUi from '../tests/install/e2e-assets/update-ui.cjs'+import sourceBranchProbe from '../tests/install/e2e-assets/source-branch-probe.cjs'const windows = []afterEach(() => {@@ -8,7 +14,7 @@ afterEach(() => {vi.useRealTimers()})-function fixture({ details = true, available = true } = {}) {+function fixture({ details = true, available = true, statusOverride } = {}) {vi.useFakeTimers({ toFake: ['Date'] })vi.setSystemTime(0)const { window } = new JSDOM('<body></body>', { runScripts: 'outside-only' })@@ -32,7 +38,7 @@ function fixture({ details = true, available = true } = {}) {revealUpdate()}})- const status = { supported: true, behind: available ? 1 : 0 }+ const status = statusOverride || { supported: true, behind: available ? 1 : 0 }window.hermesDesktop = { updates: { check: async () => status } }const page = {getByRole(role, { name }) {@@ -63,6 +69,93 @@ test.each([true, false])('reveals the actual update button without applying (detexpect(f.shot).toHaveBeenCalledWith(f.page, '04-update-available')})+test('checks the live Desktop bridge against the staged target before opening About', async () => {+ const sha = 'a'.repeat(40)+ const f = fixture({ statusOverride: { supported: true, branch: 'main', targetSha: sha, updateAvailable: true } })+ await updateUi.assertStagedBranch(f.page, sha, f.log)+ expect(f.log).toHaveBeenCalledWith(expect.stringContaining('"targetSha"'))+ for (const statusOverride of [+ { supported: true, error: 'release-unavailable', branch: 'main' },+ { supported: true, branch: 'main', targetSha: 'b'.repeat(40), updateAvailable: true },+ ]) {+ const refused = fixture({ statusOverride })+ await expect(updateUi.assertStagedBranch(refused.page, sha, refused.log)).rejects.toThrow(/refusing to click/)+ }+})++test('test-only source probe pins staged main without changing other Python invocations', () => {+ const root = '/fixture/install'+ const probe = ['-c', 'from pathlib import Path; import runpy; p = Path("hermes_cli/source_check.py"); entry = runpy.run_path(str(p)).get("main") if p.is_file() else None; entry()', '--install-root', root, '--home', '/fixture/home', '--git', '/shim/git', '--force']+ const expected = [...probe]+ expected[expected.indexOf('--git') + 1] = '/real/git'+ expected.push('--branch', 'main')+ expect(sourceBranchProbe.branchProbeArgs(probe, root, '/real/git')).toEqual(expected)+ expect(sourceBranchProbe.branchProbeArgs(probe, '/other/install', '/real/git')).toBe(probe)+ expect(sourceBranchProbe.branchProbeArgs(['-c', 'print("hermes_cli/source_check.py")'], root, '/real/git')).toEqual(['-c', 'print("hermes_cli/source_check.py")'])+ expect(sourceBranchProbe.branchProbeArgs([...probe, '--branch', 'topic'], root, '/real/git')).toEqual([...probe, '--branch', 'topic'])+ expect(sourceBranchProbe.branchProbeArgs(probe, root, '')).toBe(probe)+})++test.skipIf(process.platform === 'win32')('probe Git reaches the staged main even with global Git config isolated', () => {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'desktop-staged-git-'))+ const git = process.env.HERMES_E2E_REAL_GIT || process.env.PATH.split(path.delimiter)+ .map(dir => path.join(dir, process.platform === 'win32' ? 'git.exe' : 'git')).find(file => fs.existsSync(file))+ try {+ const checkout = path.join(root, 'checkout')+ const bare = path.join(root, 'serve.git')+ fs.mkdirSync(checkout)+ const run = (args, cwd = checkout, env = process.env) => execFileSync(git, args, { cwd, env, encoding: 'utf8' }).trim()+ run(['init', '-b', 'main'])+ run(['-c', 'user.name=Fixture', '-c', '[email protected]', '-c', 'commit.gpgsign=false', 'commit', '--allow-empty', '-m', 'base'])+ const base = run(['rev-parse', 'HEAD'])+ run(['-c', 'user.name=Fixture', '-c', '[email protected]', '-c', 'commit.gpgsign=false', 'commit', '--allow-empty', '-m', 'staged'])+ const sha = run(['rev-parse', 'HEAD'])+ run(['clone', '--bare', checkout, bare], root)+ run(['reset', '--hard', base])+ run(['remote', 'add', 'origin', 'https://github.com/NousResearch/hermes-agent.git'])+ const cfg = path.join(root, 'gitconfig')+ run(['config', '--file', cfg, '--add', `url.file://${bare}.insteadOf`, 'https://github.com/NousResearch/hermes-agent.git'])+ const capturedEnv = { ...process.env, GIT_CONFIG_GLOBAL: cfg }+ const launchEnv = { HERMES_DESKTOP_USER_DATA_DIR: root }+ sourceBranchProbe.prepareSourceBranchEnvironment(checkout, sha, git, capturedEnv, launchEnv)+ const env = { ...process.env, GIT_CONFIG_GLOBAL: process.platform === 'win32' ? 'NUL' : '/dev/null' }+ const shim = launchEnv.HERMES_E2E_SOURCE_GIT+ expect(execFileSync(shim, ['remote', 'get-url', 'origin'], { cwd: checkout, env, encoding: 'utf8' }).trim()).toBe(`file://${bare}`)+ expect(execFileSync(shim, ['ls-remote', '--heads', 'origin', 'refs/heads/main'], { cwd: checkout, env, encoding: 'utf8' }).split(/\s+/)[0]).toBe(sha)+ const python = process.env.HERMES_PYTHON || 'python3'+ const source = fileURLToPath(new URL('../', import.meta.url))+ const home = path.join(root, 'profile')+ fs.mkdirSync(home)+ const code = 'import json,sys; from pathlib import Path; from hermes_cli.source_check import check_for_updates; print(json.dumps(check_for_updates(install_root=Path(sys.argv[1]), home=Path(sys.argv[2]), branch="main", force=True, git=sys.argv[3])))'+ const status = JSON.parse(execFileSync(python, ['-c', code, checkout, home, shim], {+ cwd: checkout, encoding: 'utf8', env: { ...env, HERMES_HOME: home, GIT_ALLOW_PROTOCOL: 'file', PYTHONPATH: source },+ }))+ expect(status).toMatchObject({ supported: true, currentSha: base, branch: 'main', targetSha: sha, updateAvailable: true })+ expect(() => sourceBranchProbe.prepareSourceBranchEnvironment(checkout, '0'.repeat(40), git, capturedEnv, launchEnv)).toThrow(/does not match expected/)+ } finally {+ fs.rmSync(root, { recursive: true, force: true })+ }+})++test('preloaded Electron-style execFile transports explicit branch into the checker', () => {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'desktop-branch-probe-'))+ try {+ fs.mkdirSync(path.join(root, 'hermes_cli'))+ fs.writeFileSync(path.join(root, 'hermes_cli', 'source_check.py'), 'import json, sys\ndef main(): print(json.dumps(sys.argv[1:]))\n')+ const probe = 'from pathlib import Path; import runpy; p = Path("hermes_cli/source_check.py"); entry = runpy.run_path(str(p)).get("main") if p.is_file() else None; entry() if callable(entry) else print("null")'+ const python = process.env.HERMES_PYTHON || 'python3'+ const script = 'const {promisify} = require("node:util"); const {execFile} = require("node:child_process"); promisify(execFile)(process.argv[1], ["-c", process.argv[2], "--install-root", process.argv[3], "--home", process.argv[3], "--git", "fixture-shim", "--force"], {cwd:process.argv[3]}).then(r=>console.log(r.stdout), e=>{console.error(e);process.exitCode=1})'+ const result = spawnSync(process.execPath, ['-e', script, python, probe, root], {+ encoding: 'utf8', env: { ...process.env, HERMES_E2E_SOURCE_ROOT: root, HERMES_E2E_SOURCE_GIT: '/real/git',+ NODE_OPTIONS: `--require=${JSON.stringify(fileURLToPath(new URL('../tests/install/e2e-assets/source-branch-probe.cjs', import.meta.url)))}` },+ })+ expect(result.status, result.stderr).toBe(0)+ expect(JSON.parse(result.stdout)).toEqual(['--install-root', root, '--home', root, '--git', '/real/git', '--force', '--branch', 'main'])+ } finally {+ fs.rmSync(root, { recursive: true, force: true })+ }+})+test('does not turn a completed check without an update into success', async () => {const f = fixture({ available: false })await expect(updateUi.waitForUpdate(f.page, f)).rejects.toThrow(/"Update now" never appeared/)diff --git a/tests/install/e2e-assets/launch-from-spec.mjs b/tests/install/e2e-assets/launch-from-spec.mjsindex fdd9b3c070b..edf5a3f324a 100644--- a/tests/install/e2e-assets/launch-from-spec.mjs+++ b/tests/install/e2e-assets/launch-from-spec.mjs@@ -30,7 +30,8 @@ import { execFileSync } from 'node:child_process';import { parseArgs } from 'node:util';import { _electron } from '@playwright/test';import { prepareWindowForInput } from './window-input.cjs';-import { pickAppWindow, openAbout, readManualUpdateCommand, waitForUpdate } from './update-ui.cjs';+import { assertStagedBranch, pickAppWindow, openAbout, readManualUpdateCommand, waitForUpdate } from './update-ui.cjs';+import { prepareSourceBranchEnvironment } from './source-branch-probe.cjs';import { observeSourceUpdate } from './source-update-observer.mjs';import { runUpdateWindowChat } from './update-window-chat.mjs';import { isolateUpdateWindowEnvironment, isolatedElectronArgs, updateWindowEnvironment } from './smoke-env.mjs';@@ -143,6 +144,12 @@ async function main() {const capturedEnv = updateWindowEnvironment(launch.env, values['repo-dir'], 'source');settleSourceRuntime(values['repo-dir'], capturedEnv);const launchEnv = isolateUpdateWindowEnvironment(capturedEnv);+ if (!values['no-update']) {+ // This unpublished E2E target has no R2 channel record. Only the test+ // probe selects the real checker's explicit branch path.+ prepareSourceBranchEnvironment(values['repo-dir'], values['expect-sha'],+ process.env.HERMES_E2E_REAL_GIT, capturedEnv, launchEnv);+ }log(`launching ${launch.executablePath} (shape: ${spec.matchedShape}, isolated userData: ${launchEnv.HERMES_DESKTOP_USER_DATA_DIR})`);phase('launch');@@ -175,6 +182,7 @@ async function main() {if (!values.result && !(values['expect-sha'] && values['repo-dir'])) {throw new Error('need --result and/or --expect-sha + --repo-dir unless --no-update');}+ await assertStagedBranch(window, values['expect-sha'], log);const deadline = Date.now() + Number(values['timeout-ms']);diff --git a/tests/install/e2e-assets/source-branch-probe.cjs b/tests/install/e2e-assets/source-branch-probe.cjsnew file mode 100644index 00000000000..40121ef9352--- /dev/null+++ b/tests/install/e2e-assets/source-branch-probe.cjs@@ -0,0 +1,73 @@+// Test-only preload for the unpublished Git main used by source-install E2E.+// The shipped source checker accepts --branch main, but Desktop's automatic+// check normally resolves the published main channel. Intercept only that+// subprocess invocation; the actual checker, UI, and updater still run.+const childProcess = require('node:child_process')+const fs = require('node:fs')+const path = require('node:path')+const { syncBuiltinESMExports } = require('node:module')++function sourceProbeGit(userData, realGit, stagedUrl, platform = process.platform) {+ if (!/^file:\/\/[^\s]+$/.test(stagedUrl)) throw new Error('source check must use a staged file:// Git origin')+ const file = path.join(userData, platform === 'win32' ? 'source-probe-git.cmd' : 'source-probe-git.sh')+ const args = [+ `url.${stagedUrl}.insteadOf=https://github.com/NousResearch/hermes-agent.git`,+ `url.${stagedUrl}[email protected]:NousResearch/hermes-agent.git`,+ ]+ if (platform === 'win32') {+ const quote = value => `"${value.replace(/"/g, '""')}"`+ fs.writeFileSync(file, `@echo off\r\n${quote(realGit)} ${args.map(value => `-c ${quote(value)}`).join(' ')} %*\r\n`)+ } else {+ const quote = value => `'${value.replace(/'/g, "'\\''")}'`+ fs.writeFileSync(file, `#!/bin/sh\nexec ${quote(realGit)} ${args.map(value => `-c ${quote(value)}`).join(' ')} "$@"\n`, { mode: 0o700 })+ }+ return file+}++function prepareSourceBranchEnvironment(root, expectedSha, realGit, capturedEnv, launchEnv) {+ if (!realGit || !path.isAbsolute(realGit) || !fs.existsSync(realGit)) {+ throw new Error('source app-update requires HERMES_E2E_REAL_GIT for staged main')+ }+ const install = path.resolve(root)+ const staged = childProcess.execFileSync(realGit, ['-C', install, 'remote', 'get-url', 'origin'], {+ encoding: 'utf8', env: capturedEnv,+ }).trim()+ if (!/^file:\/\/[^\s]+$/.test(staged)) throw new Error('source check must use a staged file:// Git origin')+ const advertised = childProcess.execFileSync(realGit, ['ls-remote', '--heads', staged, 'refs/heads/main'], {+ encoding: 'utf8', env: capturedEnv,+ }).trim().split(/\s+/)[0]+ if (advertised !== expectedSha) {+ throw new Error(`staged Git main ${advertised} does not match expected ${expectedSha}`)+ }+ launchEnv.HERMES_E2E_SOURCE_ROOT = install+ launchEnv.HERMES_E2E_SOURCE_GIT = sourceProbeGit(launchEnv.HERMES_DESKTOP_USER_DATA_DIR, realGit, staged)+ launchEnv.NODE_OPTIONS = `--require=${JSON.stringify(__filename)}`+}++function branchProbeArgs(args, root, realGit) {+ if (!root || !realGit || !Array.isArray(args) || args[0] !== '-c'+ || !args[1]?.includes('runpy.run_path(str(p))')+ || !args[1]?.includes('hermes_cli/source_check.py')+ || args[args.indexOf('--install-root') + 1] !== root+ || !args.includes('--git') || args.includes('--branch')) return args+ const selected = [...args]+ selected[selected.indexOf('--git') + 1] = realGit+ return [...selected, '--branch', 'main']+}++if (process.env.HERMES_E2E_SOURCE_ROOT && process.env.HERMES_E2E_SOURCE_GIT) {+ const original = childProcess.execFile+ const select = args => {+ const selected = branchProbeArgs(args, process.env.HERMES_E2E_SOURCE_ROOT, process.env.HERMES_E2E_SOURCE_GIT)+ if (selected !== args) process.stderr.write('[source-branch-probe] checking staged Git main explicitly\n')+ return selected+ }+ childProcess.execFile = function (file, args, options, callback) {+ return original.call(this, file, select(args), options, callback)+ }+ const custom = Symbol.for('nodejs.util.promisify.custom')+ childProcess.execFile[custom] = (file, args, options) => original[custom](file, select(args), options)+ syncBuiltinESMExports()+}++module.exports = { branchProbeArgs, prepareSourceBranchEnvironment, sourceProbeGit }diff --git a/tests/install/e2e-assets/update-ui.cjs b/tests/install/e2e-assets/update-ui.cjsindex 64962fabecd..27f8a0aac2b 100644--- a/tests/install/e2e-assets/update-ui.cjs+++ b/tests/install/e2e-assets/update-ui.cjs@@ -78,6 +78,14 @@ async function openAbout(page, { prepare, log, shot, confirmSettings = false, hi}}+async function assertStagedBranch(page, expectedSha, log) {+ const status = await page.evaluate(() => window.hermesDesktop.updates.check({ force: true }))+ log(`[source-branch-check] ${JSON.stringify(status)}`)+ if (status.error || status.branch !== 'main' || status.targetSha !== expectedSha || !status.updateAvailable) {+ throw new Error('Desktop source check did not offer staged Git main; refusing to click an unrelated update')+ }+}+async function waitForUpdate(page, { log, shot }) {const update = page.getByRole('button', { name: /update now/i }).first()const details = page.getByRole('button', { name: /^see what['’]s new$/i }).first()@@ -119,4 +127,4 @@ async function readManualUpdateCommand(page) {return command}-module.exports = { pickAppWindow, openAbout, readManualUpdateCommand, waitForUpdate }+module.exports = { assertStagedBranch, pickAppWindow, openAbout, readManualUpdateCommand, waitForUpdate }