Skip to content

The agent that grows with you

fix(desktop): document the afterExtract ordering, trim tests, refresh stale hook references

teknium170096110138a
diff --git a/apps/desktop/scripts/after-extract.mjs b/apps/desktop/scripts/after-extract.mjs
index e410a8986dd..1974ab97575 100644
--- a/apps/desktop/scripts/after-extract.mjs
+++ b/apps/desktop/scripts/after-extract.mjs
@@ -3,8 +3,16 @@
*
* Stamps the Hermes icon + identity onto the unpacked Windows Electron binary
* before electron-builder renames it and injects the ASAR integrity resource.
- * Keeping the rcedit mutation before electron-builder's resedit rewrite makes
- * both resource edits compose into the final Hermes.exe.
+ *
+ * WHY afterExtract and not afterPack (#105629): with ASAR integrity on (the
+ * default) electron-builder's `beforeCopyExtraFiles` rebuilds the whole PE in
+ * memory with resedit to push the ELECTRONASAR resource. rcedit cannot commit
+ * changes to that rewritten PE ("Fatal error: Unable to commit changes"),
+ * deterministically, on every build. afterExtract fires on the pristine
+ * electron.exe, before the rename and the integrity rewrite, and resedit then
+ * carries the stamped resources through — so the exe keeps both its identity
+ * and its integrity checksum. Disabling `disableAsarIntegrity` would also
+ * "fix" it, at the cost of the integrity check on every Windows build.
*
* Windows-only: rcedit edits PE resources, irrelevant on macOS/Linux where the
* app identity comes from the bundle Info.plist / desktop entry. Best-effort:
diff --git a/apps/desktop/scripts/after-extract.test.mjs b/apps/desktop/scripts/after-extract.test.mjs
index cae086eb51b..eee0852f46f 100644
--- a/apps/desktop/scripts/after-extract.test.mjs
+++ b/apps/desktop/scripts/after-extract.test.mjs
@@ -13,12 +13,17 @@ const require = createRequire(import.meta.url)
const desktopRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const desktopPackage = require(path.join(desktopRoot, 'package.json'))
-test('configures executable stamping before electron-builder adds ASAR integrity', () => {
+// #105629: the identity stamp must run BEFORE electron-builder's ASAR-integrity
+// rewrite of the exe (beforeCopyExtraFiles), i.e. from afterExtract, never from
+// afterPack — rcedit cannot commit changes to the resedit-rewritten PE. And the
+// fix must keep the integrity check on (no disableAsarIntegrity workaround).
+test('the exe identity stamp is wired to afterExtract, not afterPack, with ASAR integrity kept on', () => {
assert.equal(desktopPackage.build.afterExtract, 'scripts/after-extract.mjs')
assert.equal(desktopPackage.build.afterPack, undefined)
+ assert.equal(desktopPackage.build.disableAsarIntegrity, undefined)
})
-test('stamps the stock Windows executable before it is renamed and rewritten', async () => {
+test('stamps the stock electron.exe on win32 only, before it is renamed to Hermes.exe', async () => {
stampExeIdentity.mockClear()
const appOutDir = path.join('tmp', 'win-unpacked')
@@ -27,18 +32,13 @@ test('stamps the stock Windows executable before it is renamed and rewritten', a
electronPlatformName: 'win32',
packager: { appInfo: { productFilename: 'Hermes' } }
})
-
assert.deepEqual(stampExeIdentity.mock.calls, [[path.join(appOutDir, 'electron.exe'), desktopRoot]])
-})
-test('does not edit non-Windows Electron binaries', async () => {
stampExeIdentity.mockClear()
-
await afterExtract({
appOutDir: path.join('tmp', 'linux-unpacked'),
electronPlatformName: 'linux',
packager: { appInfo: { productFilename: 'Hermes' } }
})
-
assert.equal(stampExeIdentity.mock.calls.length, 0)
})
diff --git a/apps/desktop/scripts/set-exe-identity.mjs b/apps/desktop/scripts/set-exe-identity.mjs
index 03ae85e76c2..d103c6ba872 100644
--- a/apps/desktop/scripts/set-exe-identity.mjs
+++ b/apps/desktop/scripts/set-exe-identity.mjs
@@ -49,7 +49,7 @@ import { isMain } from './utils.mjs'
const RCEDIT_COMMIT_RETRY_DELAYS_MS = [500, 1000, 2000]
// A failure to spawn the rcedit binary itself (missing or not executable) is
-// permanent; waiting 3.5 s on it only delays after-pack.mjs's warning. The npm
+// permanent; waiting 3.5 s on it only delays after-extract.mjs's warning. The npm
// rcedit wrapper surfaces the spawn error as `originalError` on its rejection,
// while a non-zero rcedit exit carries a numeric `code`.
const RCEDIT_PERMANENT_SPAWN_CODES = new Set(['ENOENT', 'EACCES'])
diff --git a/scripts/install.ps1 b/scripts/install.ps1
index 55eb407a800..7294bc20516 100644
--- a/scripts/install.ps1
+++ b/scripts/install.ps1
@@ -4317,12 +4317,13 @@ function Install-Desktop {
}
# 3b. The Hermes icon + identity are stamped onto Hermes.exe by the
- # electron-builder `afterPack` hook (apps/desktop/scripts/after-pack.mjs)
+ # electron-builder `afterExtract` hook (apps/desktop/scripts/after-extract.mjs)
# during `npm run pack` above -- for every build, so the installer's
# --update rebuild stays branded too. No separate stamp step needed here.
- # electron-builder's own rcedit step stays disabled (signAndEditExecutable
- # =false) because enabling it drags in signtool -> winCodeSign -> the
- # unfixable symlink crash; the afterPack hook runs rcedit directly.
+ # It runs BEFORE the ASAR-integrity PE rewrite (rcedit cannot commit to
+ # the rewritten exe, #105629). electron-builder's own rcedit step stays
+ # disabled (signAndEditExecutable=false) because enabling it drags in
+ # signtool -> winCodeSign -> the unfixable symlink crash.
# 3c. Grant ALL APPLICATION PACKAGES (S-1-15-2-2) RX on the unpacked app
# directory. Chromium's GPU/renderer sandboxes CHECK-fail with