Skip to content

The agent that grows with you

fix(desktop): show after-pack scan and signing progress

ethernet7dea99539dc4
diff --git a/apps/desktop/scripts/after-pack.mjs b/apps/desktop/scripts/after-pack.mjs
index bee90396a11..a1511bd6de8 100644
--- a/apps/desktop/scripts/after-pack.mjs
+++ b/apps/desktop/scripts/after-pack.mjs
@@ -118,6 +118,7 @@ export default async function afterPack(context) {
// one bad payload DLL fails the whole package. Unlike the stamp below this
// is NOT best-effort: shipping past it means shipping an unsignable bundle.
// this is a hack until https://github.com/astral-sh/python-build-standalone/pull/1217 is merged.
+ console.log(`[after-pack] scanning PE certificate headers in ${context.appOutDir}`)
const { scanned, repaired } = sanitizeTree(context.appOutDir)
console.log(`[after-pack] ${scanned} PEs scanned, ${repaired.length} dangling certificate tables cleared`)
for (const file of repaired) {
diff --git a/apps/desktop/scripts/batch-sign-binaries.mjs b/apps/desktop/scripts/batch-sign-binaries.mjs
index 8fab64af992..d0653936b99 100644
--- a/apps/desktop/scripts/batch-sign-binaries.mjs
+++ b/apps/desktop/scripts/batch-sign-binaries.mjs
@@ -216,7 +216,10 @@ export async function timestampChunk(files, opts) {
'/td', 'SHA256',
...files
]
+ let attempt = 0
const run = async () => {
+ attempt += 1
+ console.log(`[batch-sign] timestamp attempt ${attempt}/${opts.timestampAttempts ?? 3} (${files.length} binaries)`)
if (opts.exec) {
await opts.exec(opts.signtool, args, opts.execOptions)
return
@@ -250,6 +253,7 @@ export async function batchSignBinaries(binaries, opts = {}) {
if (binaries.length === 0) {
return { signed: 0, chunks: 0, skipped: false }
}
+ console.log('[batch-sign] preparing Windows signing tools')
// afterPack runs before the per-file Azure signer downloads its tools.
const { signtool, dlib, dotnetRoot } = opts.signtool && opts.dlib
? opts
@@ -259,6 +263,7 @@ export async function batchSignBinaries(binaries, opts = {}) {
root: env.ELECTRON_BUILDER_CACHE ? `${env.ELECTRON_BUILDER_CACHE}-payload-signatures` : null,
env, signtool, dlib, timestampUrl: opts.timestampUrl ?? TIMESTAMP_URL
}) : opts.cache
+ console.log(`[batch-sign] checking signature cache for ${binaries.length} binaries${cache ? '' : ' (cache disabled)'}`)
const plan = cache ? await cache.prepare(binaries) : null
const toSign = plan?.files ?? binaries
console.log(`[batch-sign] ${plan?.restored ?? 0} cache hits, ${toSign.length} to sign, ${plan?.duplicates ?? 0} duplicate copies`)
@@ -278,12 +283,19 @@ export async function batchSignBinaries(binaries, opts = {}) {
const execOptions = { stdio: 'inherit', env: signEnv }
try {
// Pass 1: Azure Authenticode sign — concurrent, no timestamp.
- await runPool(batches, concurrency, (batch) =>
- signChunk(batch, { signtool, dlib, metadataPath, exec: opts.exec, execOptions })
- )
+ console.log(`[batch-sign] Azure signing: ${batches.length} batches, up to ${concurrency} concurrent`)
+ await runPool(batches, concurrency, async (batch, index) => {
+ const start = performance.now()
+ console.log(`[batch-sign] signing batch ${index + 1}/${batches.length} (${batch.length} binaries)`)
+ await signChunk(batch, { signtool, dlib, metadataPath, exec: opts.exec, execOptions })
+ console.log(`[batch-sign] signed batch ${index + 1}/${batches.length} in ${((performance.now() - start) / 1000).toFixed(1)}s`)
+ })
// Pass 2: RFC3161 timestamp — concurrent, no Azure/dlib, retried.
- await runPool(batches, concurrency, (batch) =>
- timestampChunk(batch, {
+ console.log(`[batch-sign] timestamping: ${batches.length} batches`)
+ await runPool(batches, concurrency, async (batch, index) => {
+ const start = performance.now()
+ console.log(`[batch-sign] timestamping batch ${index + 1}/${batches.length} (${batch.length} binaries)`)
+ await timestampChunk(batch, {
signtool,
timestampUrl: opts.timestampUrl,
exec: opts.exec,
@@ -291,8 +303,12 @@ export async function batchSignBinaries(binaries, opts = {}) {
timestampAttempts: opts.timestampAttempts,
timestampRetryDelayMs: opts.timestampRetryDelayMs
})
- )
- if (cache) await cache.publish(plan)
+ console.log(`[batch-sign] timestamped batch ${index + 1}/${batches.length} in ${((performance.now() - start) / 1000).toFixed(1)}s`)
+ })
+ if (cache) {
+ console.log('[batch-sign] verifying signed binaries and publishing signature cache')
+ await cache.publish(plan)
+ }
console.log(`[batch-sign] completed in ${((performance.now() - started) / 1000).toFixed(1)}s`)
return { signed: toSign.length, chunks: batches.length, skipped: false }
} finally {
@@ -325,10 +341,12 @@ export async function batchSignAppTree(appOutDir, productExePath, opts = {}) {
// on dead weight and can FAIL: locally the cache may hold files that
// were removed between pm bundle staging and the afterPack walk.
const inCache = (file) => /(^|[\\/])uv-cache[\\/]/.test(path.resolve(file))
+ console.log(`[batch-sign] collecting signable binaries in ${appOutDir} (excluding product exe and uv-cache)`)
const binaries = getBinaries(appOutDir, {
skip: (file) =>
inCache(file) || (productExe ? path.resolve(file) === productExe : false)
})
+ console.log(`[batch-sign] collected ${binaries.length} binaries`)
if (binaries.length === 0) return { signed: 0, chunks: 0, skipped: false }
const result = await batchSignBinaries(binaries, opts)
console.log(
diff --git a/apps/desktop/scripts/batch-sign-binaries.test.mjs b/apps/desktop/scripts/batch-sign-binaries.test.mjs
index 16e55919432..a1e42a7bf23 100644
--- a/apps/desktop/scripts/batch-sign-binaries.test.mjs
+++ b/apps/desktop/scripts/batch-sign-binaries.test.mjs
@@ -4,7 +4,7 @@ import os from 'node:os'
import path from 'node:path'
import { Arch, Packager, Platform, WinPackager } from 'app-builder-lib'
-import { afterEach, test } from 'vitest'
+import { afterEach, test, vi } from 'vitest'
import builderConfig from '../electron-builder.config.cjs'
@@ -29,6 +29,30 @@ function tmpTree() {
return dir
}
+test('batch phase logs arrive before execution and completion logs only after success', async () => {
+ const root = tmpTree()
+ fs.writeFileSync(path.join(root, 'binary.exe'), 'inert signing fixture')
+ const log = vi.spyOn(console, 'log').mockImplementation(() => {})
+ try {
+ await batchSignAppTree(root, null, {
+ env: { AZURE_SIGN_ENDPOINT: 'https://test.invalid', AZURE_SIGN_ACCOUNT: 'account', AZURE_SIGN_PROFILE: 'profile' },
+ signtool: 'signtool.exe', dlib: 'dlib.dll', cache: null, mkdtemp: () => root,
+ exec: async (tool, args) => {
+ const messages = log.mock.calls.map(([message]) => message)
+ const phase = args[0] === 'sign' ? 'signing' : 'timestamping'
+ const completed = args[0] === 'sign' ? 'signed' : 'timestamped'
+ assert.ok(messages.some(message => message.includes(`${phase} batch 1/1`)))
+ assert.ok(!messages.some(message => message.includes(`${completed} batch 1/1`)))
+ }
+ })
+ const messages = log.mock.calls.map(([message]) => message)
+ assert.ok(messages.some(message => message.includes('signed batch 1/1')))
+ assert.ok(messages.some(message => message.includes('timestamped batch 1/1')))
+ } finally {
+ log.mockRestore()
+ }
+})
+
test('getBinaries collects .exe and .dll recursively, case-insensitive, sorted', () => {
const root = tmpTree()
fs.mkdirSync(path.join(root, 'resources', 'agent-payload', 'tools', 'python', 'bin'), { recursive: true })
diff --git a/apps/desktop/scripts/payload-digests.mjs b/apps/desktop/scripts/payload-digests.mjs
index f2f52380804..193b512d8aa 100644
--- a/apps/desktop/scripts/payload-digests.mjs
+++ b/apps/desktop/scripts/payload-digests.mjs
@@ -6,7 +6,9 @@ import path from 'node:path'
export function rehashPayloadDigests(payload) {
// Light builds have no payload. Present payloads require valid tool facts.
if (!fs.existsSync(path.join(payload, 'manifest.json'))) return
+ console.log(`[after-pack] refreshing payload hashes after signing: ${payload}`)
runPython([
path.resolve(import.meta.dirname, '../../../scripts/bundles/payload.py'), 'rehash', payload],
{ stdio: 'inherit' })
+ console.log('[after-pack] payload hash refresh complete')
}
diff --git a/apps/desktop/scripts/sanitize-pe-signatures.mjs b/apps/desktop/scripts/sanitize-pe-signatures.mjs
index 1eb3b2d9d4d..a5673952428 100644
--- a/apps/desktop/scripts/sanitize-pe-signatures.mjs
+++ b/apps/desktop/scripts/sanitize-pe-signatures.mjs
@@ -178,7 +178,15 @@ function* walkFiles(dir) {
export function sanitizeTree(rootDir) {
const repaired = []
let scanned = 0
+ let visited = 0
+ let nextProgressAt = performance.now() + 5000
for (const file of walkFiles(rootDir)) {
+ visited += 1
+ const now = performance.now()
+ if (now >= nextProgressAt) {
+ console.log(`[sanitize-pe] checked ${visited - 1} files (${scanned} PEs), repaired ${repaired.length}; checking ${path.relative(rootDir, file)}`)
+ nextProgressAt = now + 5000
+ }
let entry
try {
entry = readSecurityDirectory(file)
diff --git a/apps/desktop/scripts/sanitize-pe-signatures.test.mjs b/apps/desktop/scripts/sanitize-pe-signatures.test.mjs
index 43780f7960e..1d7b968d261 100644
--- a/apps/desktop/scripts/sanitize-pe-signatures.test.mjs
+++ b/apps/desktop/scripts/sanitize-pe-signatures.test.mjs
@@ -2,10 +2,28 @@ import assert from 'node:assert/strict'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
-import { test } from 'vitest'
+import { test, vi } from 'vitest'
import { sanitizeTree } from './sanitize-pe-signatures.mjs'
+test('a slow header scan reports its current file without logging every file', () => {
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pe-progress-'))
+ const times = [0, 4999, 5000, 5001, 9999, 10000]
+ const clock = vi.spyOn(performance, 'now').mockImplementation(() => times.shift())
+ const log = vi.spyOn(console, 'log').mockImplementation(() => {})
+ try {
+ for (let i = 0; i < 5; i++) fs.writeFileSync(path.join(root, `${i}.txt`), 'not PE')
+ assert.deepEqual(sanitizeTree(root), { scanned: 0, repaired: [] })
+ assert.equal(log.mock.calls.length, 2, 'report at each five-second boundary, not for each file')
+ assert.match(log.mock.calls[0][0], /checked 1 files .*checking 1\.txt/)
+ assert.match(log.mock.calls[1][0], /checked 4 files .*checking 4\.txt/)
+ } finally {
+ clock.mockRestore()
+ log.mockRestore()
+ fs.rmSync(root, { recursive: true, force: true })
+ }
+})
+
for (const [magic, countOffset, securityOffset] of [[0x10b, 244, 280], [0x20b, 260, 296]]) {
test(`tree sanitization preserves all bytes except dangling PE ${magic.toString(16)} directories`, () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pe-sanitize-'))