test(web): diagnose Host termination during SVG delivery

This commit is contained in:
Yichen Jiang committed 2026-10-26 19:14:57 +08:00
1 parent 667ef04270
commit dd4706fffe
1 file changed
+10 -1
+10 -1
View File
@@ -4,7 +4,8 @@ import { tmpdir } from 'node:os'
import { join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { chromium, type Browser, type Page } from 'playwright'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
import WebSocket from 'ws'
import type {} from '@deepseek-ai/dsh-tool-present/types'
import { deriveReplayScript, parseSessionLog } from '@deepseek-ai/dsh-llm-replay'
import {
@@ -27,9 +28,16 @@ describe('web e2e: requested SVG is explicitly delivered', () => {
let tripwire: ReturnType<typeof watchConsole>
let cwd: string
let replayRoot: string | undefined
let restoreTransportDiagnostics: (() => void) | undefined
const connectionDiagnostics: string[] = []
beforeAll(async () => {
const terminate = WebSocket.prototype.terminate
const terminated = vi.spyOn(WebSocket.prototype, 'terminate').mockImplementation(function (this: WebSocket) {
connectionDiagnostics.push(`Host terminated WebSocket with ${this.bufferedAmount} buffered bytes: ${new Error('Host termination').stack}`)
terminate.call(this)
})
restoreTransportDiagnostics = () => { terminated.mockRestore() }
let replayOverride: string | undefined
if (MODE !== 'record') {
replayRoot = await mkdtemp(join(tmpdir(), 'dsh-present-svg-replay-'))
@@ -67,6 +75,7 @@ describe('web e2e: requested SVG is explicitly delivered', () => {
})
afterAll(async () => {
restoreTransportDiagnostics?.()
try {
await browser?.close()
} finally {