Files
hermes-agent/tests/install/e2e-assets/source-update-observer.mjs
ethernet 53e6f001c7 refactor(pm): consolidate runtime ownership and updater completion
Run historical updater completion in a fresh interpreter so cached imports
cannot revive retired dependency installers. Share Git and ZIP completion,
carry receipt and recovery state, and preserve child exit status.

Route plugin admission, binary acquisition, desktop launch and build paths
through PM. Replace redundant helpers and tests with real worker, package,
publication and launch checks. Keep the shipped compatibility surface fixed.

Targeted Python and desktop checks pass. Native update journeys and fresh
production image qualification remain pending. This is a checkpoint before
those acceptance runs.
2026-09-12 16:30:35 -04:00

34 lines
1.4 KiB
JavaScript

// A checkout reset is the start of preparation, not its completion.
import { existsSync, readFileSync, readdirSync } from 'node:fs'
import { join } from 'node:path'
export function observeSourceUpdate({ home, resultPath, expectSha }) {
const directory = join(home, 'logs/update_receipts')
const files = () => [
...(resultPath && existsSync(resultPath) ? [resultPath] : []),
...(existsSync(directory) ? readdirSync(directory)
.filter(name => name.startsWith('update_') && name.endsWith('.json'))
.map(name => join(directory, name)) : []),
]
const before = new Map(files().map(file => [file, readFileSync(file, 'utf8')]))
return head => {
let complete = false
for (const file of files()) {
const text = readFileSync(file, 'utf8')
if (before.get(file) === text) continue
let data
try { data = JSON.parse(text.replace(/^\uFEFF/, '')) } catch { continue }
if (file === resultPath) {
if (data.ok !== true || (data.exit_code != null && data.exit_code !== 0)) {
throw new Error(`update handoff failed: ${text}`)
}
complete = true
} else if (data.finished_at) {
if (data.outcome !== 'success') throw new Error(`source update failed: ${text}`)
if (!expectSha || data.post_update?.sha === expectSha) complete = true
}
}
return complete && (!expectSha || head === expectSha)
&& !existsSync(join(home, '.hermes-update-in-progress'))
}
}