hermes-agent/apps/desktop/electron/pre-update-backup-config.ts
ethernet 37fd644017 fix(desktop): honour updates.pre_update_backup=off in the Desktop updater preflight again
pre-update-backup-config.ts (4de06d1dbf) survived the rewrite with no
caller: the checkout strategy called preflightStateDb unconditionally, so a
user who turned the pre-update backup family off in config.yaml still got
an emergency state.db snapshot on every Desktop update. Gate the preflight
on `hermes config get updates.pre_update_backup` in the composition root;
an unreadable answer keeps the snapshot, as before.
2026-09-21 18:49:39 -04:00

48 lines
1.4 KiB
TypeScript

import { execFile } from 'node:child_process'
import { promisify } from 'node:util'
const DISABLED_BACKUP_MODES = new Set(['off', 'false', 'none', 'disabled'])
const execFileAsync = promisify(execFile)
export function preUpdateBackupEnabled(value: unknown): boolean {
if (value === false || value === null) {
return false
}
return typeof value !== 'string' || !DISABLED_BACKUP_MODES.has(value.trim().toLowerCase())
}
export interface HermesConfigRuntime {
command?: string | null
args?: string[]
env?: NodeJS.ProcessEnv
shell?: boolean
}
export async function readPreUpdateBackupEnabled(
runtime: HermesConfigRuntime | Promise<HermesConfigRuntime>,
hermesHome: string,
run = execFileAsync
): Promise<boolean> {
try {
const resolvedRuntime = await runtime
if (!resolvedRuntime.command || !resolvedRuntime.args) {
return true
}
const result = await run(resolvedRuntime.command, resolvedRuntime.args, {
encoding: 'utf8',
env: { ...process.env, ...resolvedRuntime.env, HERMES_HOME: hermesHome },
shell: Boolean(resolvedRuntime.shell),
timeout: 15_000,
windowsHide: true
})
return preUpdateBackupEnabled(JSON.parse(String(result.stdout).trim()))
} catch {
// A missing runtime, probe failure, or malformed response must not weaken
// the emergency recovery path.
return true
}
}