Files
hermes-agent/apps/desktop/scripts/after-extract.test.mjs
T
teknium1 7009611013 fix(desktop): document the afterExtract ordering, trim tests, refresh stale hook references
Follow-up to the salvaged #106846 commit (@JoaoMarcos44):

- after-extract.mjs: spell out WHY the stamp moved (electron-builder's
  beforeCopyExtraFiles rebuilds the PE with resedit for the ELECTRONASAR
  resource; rcedit then cannot commit to that exe, deterministically —
  #105629), and why disableAsarIntegrity was not taken.
- after-extract.test.mjs: two invariants — the hook wiring (afterExtract set,
  afterPack unset, ASAR integrity still on) and the stamp target
  (electron.exe on win32, nothing on other platforms). Red on origin/main.
- set-exe-identity.mjs / scripts/install.ps1: comments still named the
  afterPack hook / after-pack.mjs.
2026-09-19 02:31:27 -07:00

45 lines
1.9 KiB
JavaScript

import assert from 'node:assert/strict'
import path from 'node:path'
import { createRequire } from 'node:module'
import { fileURLToPath } from 'node:url'
import { test, vi } from 'vitest'
const stampExeIdentity = vi.hoisted(() => vi.fn().mockResolvedValue(undefined))
vi.mock('./set-exe-identity.mjs', () => ({ stampExeIdentity }))
const { default: afterExtract } = await import('./after-extract.mjs')
const require = createRequire(import.meta.url)
const desktopRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const desktopPackage = require(path.join(desktopRoot, 'package.json'))
// #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 electron.exe on win32 only, before it is renamed to Hermes.exe', async () => {
stampExeIdentity.mockClear()
const appOutDir = path.join('tmp', 'win-unpacked')
await afterExtract({
appOutDir,
electronPlatformName: 'win32',
packager: { appInfo: { productFilename: 'Hermes' } }
})
assert.deepEqual(stampExeIdentity.mock.calls, [[path.join(appOutDir, 'electron.exe'), desktopRoot]])
stampExeIdentity.mockClear()
await afterExtract({
appOutDir: path.join('tmp', 'linux-unpacked'),
electronPlatformName: 'linux',
packager: { appInfo: { productFilename: 'Hermes' } }
})
assert.equal(stampExeIdentity.mock.calls.length, 0)
})