import assert from 'node:assert/strict'
import { test } from 'vitest'
import { buildRendererLoadErrorPage, loadRendererLoadErrorPage } from './renderer-load-error-page'
test('error page names the failure and carries a Reload button', () => {
const html = buildRendererLoadErrorPage({
errorCode: -6,
errorDescription: 'The desktop renderer bundle is incomplete after the last update (2 missing file(s)).',
missingAssets: ['assets/app-C0ffee.js', 'assets/shiki-block-DeadBeef.js'],
repairHint: 'hermes desktop --force-build'
})
assert.match(html, /Hermes couldn.t start the desktop UI/)
assert.match(html, /incomplete after the last update \(2 missing file\(s\)\)/)
assert.match(html, /-6/)
assert.match(html, /assets\/app-C0ffee\.js/)
assert.match(html, /assets\/shiki-block-DeadBeef\.js/)
assert.match(html, /hermes desktop --force-build/)
assert.match(html, /Reload/)
assert.match(html, /location\.reload\(\)/)
})
test('error page reload button targets the real renderer URL when provided', () => {
const html = buildRendererLoadErrorPage({
errorDescription: 'load failed',
reloadUrl: 'file:///C:/Hermes%20Agent/dist/index.html'
})
// A data: page cannot recover with location.reload() (it would re-render
// the error page) — the button must navigate back to the app URL.
assert.match(html, /location\.replace\("file:\/\/\/C:\/Hermes%20Agent\/dist\/index\.html"\)/)
assert.doesNotMatch(html, /location\.reload\(\)/)
})
test('error page escapes HTML in failure details', () => {
const html = buildRendererLoadErrorPage({
errorDescription: '',
url: 'file:///C:/x/index.html?',
missingAssets: ['assets/
.js']
})
assert.doesNotMatch(html, /'
})
assert.doesNotMatch(html, /<\/script>