Skip to content

The agent that grows with you

fix: stage historical Desktop source checks on Git main

ethernet63aa0a48dbd0
diff --git a/tests-js/update-ui.test.mjs b/tests-js/update-ui.test.mjs
index 6e25580efe7..9ea8fc7e0c0 100644
--- a/tests-js/update-ui.test.mjs
+++ b/tests-js/update-ui.test.mjs
@@ -157,6 +157,42 @@ test.skipIf(process.platform === 'win32')('probe Git reaches the staged main eve
}
})
+test.skipIf(process.platform === 'win32')('preloaded historical Desktop Git check reads staged origin rather than the public API', () => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'desktop-historical-probe-'))
+ const git = execFileSync('which', ['git'], { encoding: 'utf8' }).trim()
+ try {
+ const checkout = path.join(root, 'checkout')
+ const bare = path.join(root, 'serve.git')
+ fs.mkdirSync(checkout)
+ const run = (args, cwd = checkout) => execFileSync(git, args, { cwd, encoding: 'utf8' }).trim()
+ run(['init', '-b', 'main'])
+ run(['-c', 'user.name=Fixture', '-c', '[email protected]', '-c', 'commit.gpgsign=false', 'commit', '--allow-empty', '-m', 'base'])
+ 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(['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 shim = path.join(root, 'git')
+ fs.writeFileSync(shim, `#!/bin/sh\nif [ "$1 $2 $3" = "remote get-url origin" ]; then printf '%s\\n' 'https://github.com/NousResearch/hermes-agent.git'; else exec '${git}' "$@"; fi\n`, { mode: 0o700 })
+ const launchEnv = { HERMES_DESKTOP_USER_DATA_DIR: root }
+ sourceBranchProbe.prepareSourceBranchEnvironment(checkout, sha, git, { ...process.env, GIT_CONFIG_GLOBAL: cfg }, launchEnv)
+ const script = 'const {spawn} = require("node:child_process"); const child = spawn(process.argv[1], process.argv.slice(3), {cwd:process.argv[2], env:{...process.env, GIT_CONFIG_GLOBAL:"/dev/null"}}); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); child.on("close", code => process.exitCode=code)'
+ for (const [args, expected] of [
+ [['remote', 'get-url', 'origin'], `file://${bare}`],
+ [['ls-remote', 'origin', 'refs/heads/main'], `${sha}\trefs/heads/main`],
+ ]) {
+ const result = spawnSync(process.execPath, ['-e', script, shim, checkout, ...args], {
+ encoding: 'utf8', env: { ...process.env, ...launchEnv, GIT_CONFIG_GLOBAL: '/dev/null' },
+ })
+ expect(result.status, result.stderr).toBe(0)
+ expect(result.stdout.trim()).toBe(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 {
diff --git a/tests/install/e2e-assets/launch-from-spec.mjs b/tests/install/e2e-assets/launch-from-spec.mjs
index edf5a3f324a..934193cb587 100644
--- a/tests/install/e2e-assets/launch-from-spec.mjs
+++ b/tests/install/e2e-assets/launch-from-spec.mjs
@@ -31,7 +31,7 @@ import { parseArgs } from 'node:util';
import { _electron } from '@playwright/test';
import { prepareWindowForInput } from './window-input.cjs';
import { assertStagedBranch, pickAppWindow, openAbout, readManualUpdateCommand, waitForUpdate } from './update-ui.cjs';
-import { prepareSourceBranchEnvironment } from './source-branch-probe.cjs';
+import { installSourceBranchProbe, 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';
@@ -159,6 +159,7 @@ async function main() {
cwd: launch.cwd,
env: launchEnv,
});
+ if (!values['no-update']) await installSourceBranchProbe(app);
const window = await pickAppWindow(app, log);
await window.screenshot({ path: `${values.spec}.window.png` }).catch(() => {});
diff --git a/tests/install/e2e-assets/source-branch-probe.cjs b/tests/install/e2e-assets/source-branch-probe.cjs
index cc3a797dd1c..1760982b87e 100644
--- a/tests/install/e2e-assets/source-branch-probe.cjs
+++ b/tests/install/e2e-assets/source-branch-probe.cjs
@@ -67,10 +67,21 @@ exec ${quote(original)} "$@"
return
}
launchEnv.HERMES_E2E_SOURCE_ROOT = install
+ launchEnv.HERMES_E2E_SOURCE_URL = staged
+ launchEnv.HERMES_E2E_SOURCE_REAL_GIT = realGit
launchEnv.HERMES_E2E_SOURCE_GIT = sourceProbeGit(launchEnv.HERMES_DESKTOP_USER_DATA_DIR, realGit, staged)
launchEnv.NODE_OPTIONS = `--require=${JSON.stringify(__filename)}`
}
+async function installSourceBranchProbe(app) {
+ // Packaged Electron ignores NODE_OPTIONS=--require. Install the same narrow
+ // test-only subprocess hook in its main process before asking the UI to check.
+ await app.evaluate((_, file) => {
+ process.getBuiltinModule('node:module').createRequire(file)(file)
+ return true
+ }, __filename)
+}
+
function branchProbeArgs(args, root, realGit) {
if (!root || !realGit || !Array.isArray(args)) return args
// PM .cmd launchers are passed to cmd.exe as one screened command string.
@@ -112,7 +123,31 @@ if (process.env.HERMES_E2E_SOURCE_ROOT && process.env.HERMES_E2E_SOURCE_GIT) {
}
const custom = Symbol.for('nodejs.util.promisify.custom')
childProcess.execFile[custom] = (file, args, options) => original[custom](file, select(args), options)
+ // v2026.9.21 does its source check in Electron: remote get-url selects
+ // GitHub's public REST API unless its real Git process sees staged origin.
+ // Redirect only the legacy check's two Git reads, not arbitrary subprocesses.
+ if (process.env.HERMES_E2E_SOURCE_URL) {
+ const spawn = childProcess.spawn
+ const staged = process.env.HERMES_E2E_SOURCE_URL
+ childProcess.spawn = function (file, args, options) {
+ const actual = args?.[0] === '-c' && args[1] === 'windows.appendAtomically=false' ? args.slice(2) : args
+ if (/^git(?:\.exe)?$/i.test(path.basename(file)) &&
+ path.resolve(options?.cwd || '') === process.env.HERMES_E2E_SOURCE_ROOT &&
+ (actual?.join(' ') === 'remote get-url origin' ||
+ (actual?.[0] === 'ls-remote' && actual[1] === 'origin' && actual[2] === 'refs/heads/main'))) {
+ process.stderr.write('[source-branch-probe] historical Desktop checking staged Git origin\n')
+ // The driver shadows git with a fork-detection shim that always
+ // reports the official URL for remote get-url, even with -c flags.
+ return spawn.call(this, process.env.HERMES_E2E_SOURCE_REAL_GIT, [
+ '-c', `url.${staged}.insteadOf=https://github.com/NousResearch/hermes-agent.git`,
+ '-c', `url.${staged}[email protected]:NousResearch/hermes-agent.git`,
+ ...args,
+ ], options)
+ }
+ return spawn.call(this, file, args, options)
+ }
+ }
syncBuiltinESMExports()
}
-module.exports = { branchProbeArgs, prepareSourceBranchEnvironment, sourceProbeGit }
\ No newline at end of file
+module.exports = { branchProbeArgs, installSourceBranchProbe, prepareSourceBranchEnvironment, sourceProbeGit }
\ No newline at end of file