hermes-agent/apps/desktop/scripts
teknium1 199f558058 fix(windows): verify rebuilt Hermes.exe integrity before shipping it as an update (#69179)
The desktop self-update chain (Desktop -> hermes-setup --update ->
hermes update -> hermes desktop --build-only -> relaunch) rebuilds
Hermes.exe on the user's machine and declared success on bare file
EXISTENCE. A truncated PE (corrupt cached Electron zip / interrupted
extraction or rcedit rewrite / full disk) or a wrong-architecture
unpacked tree therefore shipped as the 'updated' app, which Windows
refuses to load with 'This app can't run on your computer'
(此应用无法在你的电脑上运行) — and the previous working build had
already been wiped by before-pack.mjs, leaving nothing to fall back to.

Fix, in three parts:

- hermes_cli/main.py: post-build integrity gate on Windows
  (_ensure_desktop_exe_launchable). Parses the PE header of the freshly
  built Hermes.exe — MZ/PE magic, section-table completeness vs file
  size (catches truncation), and COFF machine vs the host arch (catches
  arm64/x64 mixups). On failure it purges the (likely corrupt) cached
  Electron zip, invalidates the content-hash build stamp so the
  updater's retry-once genuinely re-downloads and rebuilds, restores
  the previous build from the .bak tree when one exists (keeping the
  corrupt tree as .corrupt for diagnostics), tells the user the update
  was aborted and their old version kept, and exits nonzero.
  _desktop_packaged_executable also now prefers a host-loadable PE over
  pure newest-mtime when multiple win-*-unpacked trees coexist.

- apps/desktop/scripts/before-pack.mjs: on win32, the previous unpacked
  tree is preserved as <appOutDir>.bak (only when it holds the product
  exe — partial/corrupt trees still get the plain wipe) instead of
  being destroyed, providing the rollback material for the gate above.
  Non-Windows behavior is unchanged.

- Behavior-contract tests: tests/hermes_cli/test_desktop_exe_integrity.py
  (23 tests — synthetic PE fixtures for truncation/non-PE/arch-mismatch,
  rollback semantics, and the build-only exit contract) and 6 new vitest
  cases in before-pack.test.mjs for the .bak preservation rules.

Progresses #69179
2026-07-24 19:11:35 -07:00
..
perf bench(desktop): measure representative (warm-cache) cold start (#67733) 2026-07-19 23:21:45 +00:00
.gitignore feat(desktop): Memory Graph — playable radial timeline of memories + skills 2026-06-30 00:54:21 -05:00
after-pack.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
assert-dist-built.mjs cleanup(desktop): remove 'use strict' in ts & mjs 2026-07-13 17:22:17 -04:00
assert-dist-built.test.mjs test(desktop): run scripts/ tests in vitest 2026-07-13 17:22:17 -04:00
assert-root-install.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
before-build.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
before-pack.mjs fix(windows): verify rebuilt Hermes.exe integrity before shipping it as an update (#69179) 2026-07-24 19:11:35 -07:00
before-pack.test.mjs fix(windows): verify rebuilt Hermes.exe integrity before shipping it as an update (#69179) 2026-07-24 19:11:35 -07:00
bundle-electron-main.mjs fix(desktop): stop using tsx to boot Electron main in dev 2026-07-08 22:40:51 -05:00
click-session.mjs Add Hermes desktop app (#20059) 2026-05-31 17:46:56 -05:00
dev-mock.mjs feat(desktop/e2e): Playwright E2E suite with visual regression diffs 2026-07-20 11:44:40 -04:00
dev-no-hmr.mjs Add Hermes desktop app (#20059) 2026-05-31 17:46:56 -05:00
diag-jump.mjs Add Hermes desktop app (#20059) 2026-05-31 17:46:56 -05:00
diag-scroll-reset.mjs fix(desktop): stop chat scroll jumping by disabling native scroll anchoring 2026-06-02 23:08:01 -05:00
eval.mjs Add Hermes desktop app (#20059) 2026-05-31 17:46:56 -05:00
gen-share-codes.ts feat(desktop): Memory Graph — playable radial timeline of memories + skills 2026-06-30 00:54:21 -05:00
notarize-artifact.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
notarize.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
patch-electron-builder-mac-binary.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
probe-renderer.mjs Add Hermes desktop app (#20059) 2026-05-31 17:46:56 -05:00
probe-thread.mjs Add Hermes desktop app (#20059) 2026-05-31 17:46:56 -05:00
profile-typing-lag.md bench(desktop): systematized perf harness; sunset 12 one-off scripts (#67466) 2026-07-19 07:41:00 -04:00
rebuild-native.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
reload-renderer.mjs Add Hermes desktop app (#20059) 2026-05-31 17:46:56 -05:00
reload.mjs Add Hermes desktop app (#20059) 2026-05-31 17:46:56 -05:00
run-electron-builder.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
set-exe-identity.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
stage-native-deps.mjs fix(desktop): preserve node-pty helper in packaged app (#65611) 2026-07-16 11:58:50 +00:00
stage-native-deps.test.mjs fix(desktop): preserve node-pty helper in packaged app (#65611) 2026-07-16 11:58:50 +00:00
test-desktop.mjs change(ci/desktop): move desktop app build into check job 2026-07-13 17:22:17 -04:00
utils.mjs feat(desktop): ts-ify everything 2026-07-08 16:24:16 -07:00
write-build-stamp.mjs fix(desktop): stop hard-failing pack on non-git checkouts + fix ZIP-path autocrlf (supersedes #67643) (#67730) 2026-07-19 19:29:36 -04:00
write-build-stamp.test.mjs fix(desktop): stop hard-failing pack on non-git checkouts + fix ZIP-path autocrlf (supersedes #67643) (#67730) 2026-07-19 19:29:36 -04:00