Files
hermes-agent/apps/desktop/scripts/patch-dev-electron-branding.test.mjs
m4 fb13457f6f
CI / Supply-chain scan (push) Has been cancelled
Docker Build, Test, and Publish / Detect affected areas (push) Has been cancelled
auto-fix lint issues & formatting / Generate eslint --fix patch (push) Has been cancelled
Nix flake check / Detect affected areas (push) Has been cancelled
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
CI / Detect affected areas (push) Has been cancelled
Docker Build, Test, and Publish / build (amd64, type=gha,scope=docker-amd64, type=gha,mode=max,scope=docker-amd64, linux/amd64, ubuntu-latest-32-core) (push) Has been cancelled
CI / Desktop E2E (push) Has been cancelled
CI / Docs Site (push) Has been cancelled
CI / Deny unrelated histories (push) Has been cancelled
CI / Check contributors (push) Has been cancelled
Docker Build, Test, and Publish / build (arm64, type=gha,scope=docker-arm64, type=gha,mode=max,scope=docker-arm64, linux/arm64, ubuntu-latest-32-arm-core) (push) Has been cancelled
CI / Check uv.lock (push) Has been cancelled
CI / Check no committed infographics (push) Has been cancelled
CI / Profile artifact check (push) Has been cancelled
Docker Build, Test, and Publish / publish (amd64, type=gha,scope=docker-amd64, type=gha,mode=max,scope=docker-amd64, linux/amd64, ubuntu-latest-32-core) (push) Has been cancelled
Docker Build, Test, and Publish / publish (arm64, type=gha,scope=docker-arm64, type=gha,mode=max,scope=docker-arm64, linux/arm64, ubuntu-latest-32-arm-core) (push) Has been cancelled
Docker Build, Test, and Publish / merge (push) Has been cancelled
auto-fix lint issues & formatting / Apply patch (push) Has been cancelled
CI / Check no case-colliding filenames (push) Has been cancelled
CI / package-lock.json diff (push) Has been cancelled
CI / Lint Docker scripts (push) Has been cancelled
CI / Review label gate (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
CI / CI timing report (push) Has been cancelled
CI / Python tests (push) Has been cancelled
CI / OS-specific tests (push) Has been cancelled
CI / Python lints (push) Has been cancelled
CI / JS & TS checks (push) Has been cancelled
CI / Installer tests (push) Has been cancelled
CI / Rust tests (push) Has been cancelled
Nix flake check / nix flake check (push) Has been cancelled
feat: consolidate desktop and provider updates
2026-09-27 17:37:19 +08:00

77 lines
3.7 KiB
JavaScript

import assert from 'node:assert/strict'
import { execFileSync } from 'node:child_process'
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readlinkSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import test from 'node:test'
import { prepareBrandedElectron } from './patch-dev-electron-branding.mjs'
const BUDDY = '/usr/libexec/PlistBuddy'
function plistValue(plist, key) {
return execFileSync(BUDDY, ['-c', `Print :${key}`, plist], { encoding: 'utf8' }).trim()
}
test('dev Electron launches from a versioned DeepWork.app without changing the stock bundle', {
skip: process.platform !== 'darwin'
}, () => {
const root = mkdtempSync(path.join(tmpdir(), 'hermes-dock-brand-'))
try {
const electronDist = path.join(root, 'dist')
const cacheRoot = path.join(root, 'cache')
const source = path.join(electronDist, 'Electron.app/Contents')
const sourcePlist = path.join(source, 'Info.plist')
mkdirSync(path.join(source, 'MacOS'), { recursive: true })
mkdirSync(path.join(source, 'Frameworks/Test.framework/Versions/A/Resources'), { recursive: true })
writeFileSync(path.join(source, 'Frameworks/Test.framework/Versions/A/Resources/icudtl.dat'), 'icu')
symlinkSync('A', path.join(source, 'Frameworks/Test.framework/Versions/Current'))
writeFileSync(path.join(source, 'MacOS/Electron'), 'binary')
writeFileSync(sourcePlist, `<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0"><dict>
<key>CFBundleName</key><string>Electron</string>
<key>CFBundleDisplayName</key><string>Electron</string>
<key>CFBundleExecutable</key><string>Electron</string>
<key>CFBundleIdentifier</key><string>com.github.Electron</string>
<key>CFBundleShortVersionString</key><string>1.0</string>
</dict></plist>`)
const options = { electronDist, cacheRoot }
const binary = prepareBrandedElectron(options)
const brandedPlist = path.join(cacheRoot, '1.0/DeepWork.app/Contents/Info.plist')
assert.equal(binary, path.join(cacheRoot, '1.0/DeepWork.app/Contents/MacOS/Electron'))
assert.equal(plistValue(brandedPlist, 'CFBundleDisplayName'), 'DeepWork')
assert.equal(plistValue(brandedPlist, 'CFBundleExecutable'), 'Electron')
assert.equal(plistValue(brandedPlist, 'CFBundleIdentifier'), 'com.nousresearch.hermes.dev')
assert.equal(plistValue(sourcePlist, 'CFBundleName'), 'Electron')
const copiedFramework = path.join(cacheRoot, '1.0/DeepWork.app/Contents/Frameworks/Test.framework/Versions')
assert.equal(readlinkSync(path.join(copiedFramework, 'Current')), 'A')
assert.equal(readFileSync(path.join(copiedFramework, 'Current/Resources/icudtl.dat'), 'utf8'), 'icu')
const sentinel = path.join(cacheRoot, '1.0/DeepWork.app/sentinel')
writeFileSync(sentinel, 'keep')
assert.equal(prepareBrandedElectron(options), binary)
assert.equal(readFileSync(sentinel, 'utf8'), 'keep')
writeFileSync(path.join(cacheRoot, '1.0/DeepWork.app/.hermes-electron-version'), 'stale')
assert.equal(prepareBrandedElectron(options), binary)
assert.equal(existsSync(sentinel), false)
assert.equal(readFileSync(path.join(copiedFramework, 'Current/Resources/icudtl.dat'), 'utf8'), 'icu')
assert.equal(readFileSync(path.join(cacheRoot, '1.0/DeepWork.app/.hermes-electron-version'), 'utf8').startsWith('1.0:'), true)
writeFileSync(sentinel, 'keep')
execFileSync(BUDDY, ['-c', 'Set :CFBundleShortVersionString 2.0', sourcePlist])
const updatedBinary = prepareBrandedElectron(options)
assert.equal(updatedBinary, path.join(cacheRoot, '2.0/DeepWork.app/Contents/MacOS/Electron'))
assert.equal(readFileSync(sentinel, 'utf8'), 'keep')
} finally {
rmSync(root, { recursive: true, force: true })
}
})