mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-21 04:09:45 +03:00
test(desktop-e2e): a reloaded document's sockets stop counting as live
The transcript oracle's "live sockets to the one host backend" check intermittently saw two native_dial sockets on two ports: the current socket through the test's loopback proxy, plus the direct socket the renderer held BEFORE the `reload` step. Root cause: Playwright forgets a page's WebSockets when a new main-frame document commits (frameManager._clearWebSockets) without emitting their 'close', so recordWebSockets kept the pre-reload socket at closed=false whenever its close event lost the race against the reload's commit. The renderer held one socket; the recorder held a dead one. recordWebSockets now retires every recorded socket at a new-document commit (a main-frame navigation request followed by framenavigated). Hash navigations issue no navigation request, so they never retire a live socket, and any socket the new document dials (a real duplicate to the host backend, #120006) is still counted. Evidence: a standalone Playwright 1.62.1 + Electron 44.9.3 probe (page with one WebSocket, 10 reloads with a hash navigation between each) left 9/10 pre-reload sockets "live" in the old recorder while the server saw exactly one open; the retire-on-commit recorder reported 1 live on 10/10. Local run of the full spec was not possible on this host (electron.launch of the app dies on connect here).
This commit is contained in:
@@ -347,6 +347,35 @@ export interface WsRecorder {
|
||||
export function recordWebSockets(page: Page): WsRecorder {
|
||||
const rec: WsRecorder = { sockets: [], events: [], sent: [] }
|
||||
|
||||
// A new main-frame document (reload, goto) tears down every socket the old
|
||||
// one held, but Playwright forgets its sockets at that commit without
|
||||
// emitting their 'close', so a pre-reload socket would read as live forever.
|
||||
// Retire them at the commit. A same-document (hash) navigation has no
|
||||
// navigation request, so it never retires a live socket.
|
||||
let documentPending = false
|
||||
|
||||
page.on('request', request => {
|
||||
if (request.isNavigationRequest() && request.frame() === page.mainFrame()) {
|
||||
documentPending = true
|
||||
}
|
||||
})
|
||||
page.on('requestfailed', request => {
|
||||
if (request.isNavigationRequest() && request.frame() === page.mainFrame()) {
|
||||
documentPending = false
|
||||
}
|
||||
})
|
||||
page.on('framenavigated', frame => {
|
||||
if (frame !== page.mainFrame() || !documentPending) {
|
||||
return
|
||||
}
|
||||
|
||||
documentPending = false
|
||||
|
||||
for (const entry of rec.sockets) {
|
||||
entry.closed = true
|
||||
}
|
||||
})
|
||||
|
||||
page.on('websocket', ws => {
|
||||
if (!ws.url().includes('/api/ws')) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user