mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
Hiding inside the minimize handler wedges the Windows minimized flag, and showInactive() restores a painted window that never takes input. Defer hide until after that dispatch, skip a stale hide if the user already restored, and activate with show()+focus() on Windows. Log main-process event-loop stalls in desktop.log; renderer unresponsive handlers cannot see AppHangB1. Reported in #119252. Co-authored-by: finn763 <[email protected]> Co-authored-by: KoNit-K <[email protected]>
81 lines
1.8 KiB
TypeScript
81 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { createMainProcessLagWatchdog } from './main-process-lag-watchdog'
|
|
|
|
type TimerCallback = () => void
|
|
const TIMER = {} as ReturnType<typeof setInterval>
|
|
|
|
function harness({ now = 0, cadenceMs = 1_000, thresholdMs = 2_000 } = {}) {
|
|
let clock = now
|
|
let callback: TimerCallback | undefined
|
|
let cleared: unknown
|
|
const logs: string[] = []
|
|
|
|
const watchdog = createMainProcessLagWatchdog({
|
|
cadenceMs,
|
|
now: () => clock,
|
|
log: message => logs.push(message),
|
|
setInterval: tick => {
|
|
callback = tick
|
|
|
|
return TIMER
|
|
},
|
|
clearInterval: timer => {
|
|
cleared = timer
|
|
},
|
|
thresholdMs
|
|
})
|
|
|
|
return {
|
|
watchdog,
|
|
logs,
|
|
tick: (at: number) => {
|
|
clock = at
|
|
callback?.()
|
|
},
|
|
cleared: () => cleared
|
|
}
|
|
}
|
|
|
|
describe('createMainProcessLagWatchdog', () => {
|
|
it('does not log while ticks arrive on their expected cadence', () => {
|
|
const subject = harness()
|
|
|
|
subject.watchdog.start()
|
|
subject.tick(1_000)
|
|
subject.tick(2_000)
|
|
|
|
expect(subject.logs).toEqual([])
|
|
})
|
|
|
|
it('records actionable timing when a main-process tick arrives late', () => {
|
|
const subject = harness()
|
|
|
|
subject.watchdog.start()
|
|
subject.tick(3_500)
|
|
|
|
expect(subject.logs).toEqual([
|
|
'[diagnostics] main-process event loop lagged 2500ms (expected tick at 1000ms, observed at 3500ms)'
|
|
])
|
|
})
|
|
|
|
it('cleans up its interval and does not log after stop', () => {
|
|
const subject = harness()
|
|
|
|
subject.watchdog.start()
|
|
subject.watchdog.stop()
|
|
subject.tick(5_000)
|
|
|
|
expect(subject.cleared()).toBe(TIMER)
|
|
expect(subject.logs).toEqual([])
|
|
})
|
|
|
|
it('is safe to stop during shutdown before it has started', () => {
|
|
const subject = harness()
|
|
|
|
subject.watchdog.stop()
|
|
subject.watchdog.stop()
|
|
|
|
expect(subject.cleared()).toBeUndefined()
|
|
})
|
|
})
|