DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(shell): expose recovery state and iframe watchdog diagnostics (#1082)
Hairyc50876d7dfae
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.jsonindex 3b1952ab..99bbdd94 100644--- a/src/i18n/locales/en-US.json+++ b/src/i18n/locales/en-US.json@@ -15,6 +15,9 @@"status.loading_internal": "Loading internal plugins…","status.loading_process": "Starting Harness…","status.loading_client_modules": "Waiting for Harness…",+ "status.service_restarting": "Restarting the Harness service; waiting for readiness…",+ "status.service_waiting": "The Harness service is not ready yet…",+ "status.document_waiting": "The service passed its readiness check; waiting for the embedded page to respond…","status.internal_waiting": "Waiting to check internal plugins.","status.internal_checking": "Checking {{total}} internal plugins.","status.internal_installing": "Installing {{total}} internal plugins.",diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.jsonindex 4d658abb..03eb6768 100644--- a/src/i18n/locales/zh-CN.json+++ b/src/i18n/locales/zh-CN.json@@ -15,6 +15,9 @@"status.loading_internal": "Loading internal plugins…","status.loading_process": "Starting Harness…","status.loading_client_modules": "Waiting for Harness…",+ "status.service_restarting": "正在重启 Harness 服务,等待就绪…",+ "status.service_waiting": "Harness 服务尚未就绪…",+ "status.document_waiting": "服务已通过就绪检查,等待内嵌页面响应…","status.internal_waiting": "Waiting for internal plugins…","status.internal_checking": "Checking {{total}} internal plugins…","status.internal_installing": "Installing {{total}} internal plugins…",diff --git a/src/layout/components/iframe.test.tsx b/src/layout/components/iframe.test.tsxnew file mode 100644index 00000000..6948ced0--- /dev/null+++ b/src/layout/components/iframe.test.tsx@@ -0,0 +1,104 @@+// @vitest-environment jsdom+import { act, cleanup, render, screen } from '@testing-library/react'+import { createRef } from 'react'+import { afterEach, beforeEach, expect, it, vi } from 'vitest'+import { store } from '@/store'+import { Iframe } from './iframe'++vi.mock('@choochmeque/tauri-plugin-notifications-api', () => ({}))+vi.mock('@overlastic/react', () => ({ useOverlay: () => vi.fn() }))+vi.mock('@/ui/dialog/config', () => ({ ConfigDialog: () => null }))+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }))+vi.mock('@/hooks/use-dsh-style', () => ({ useDshStyle: () => [{}, vi.fn()] }))+vi.mock('@/hooks/use-invoke-iframe', () => ({ useInvokeIframe: vi.fn() }))+vi.mock('@/hooks/use-notification-action', () => ({ useNotificationAction: vi.fn() }))+vi.mock('@/hooks/use-notification-clicked', () => ({ useNotificationClicked: vi.fn() }))+vi.mock('@/hooks/use-sync-visibility', () => ({ useSyncVisibility: vi.fn() }))+vi.mock('@/hooks/use-zoom-factor', () => ({ useZoomFactor: vi.fn() }))++beforeEach(() => {+ vi.useFakeTimers()+ vi.spyOn(console, 'warn').mockImplementation(() => {})+ Object.assign(store.harness, {+ status: 'ready',+ serviceHealthy: false,+ serviceRunning: true,+ busyAction: 'restart',+ iframeKey: 1077,+ iframeAliveKey: null,+ iframeLoaded: false,+ iframeError: false,+ iframeSrc: 'http://127.0.0.1:3081/?token=secret',+ })+})++afterEach(async () => {+ cleanup()+ store.harness.serviceHealthy = false+ await vi.advanceTimersByTimeAsync(0)+ vi.useRealTimers()+ vi.restoreAllMocks()+})++it('distinguishes service restart, unhealthy service and embedded document waiting on the existing fallback', async () => {+ const view = render(<Iframe iframeRef={createRef()} />)+ expect(screen.getByRole('status').textContent).toBe('status.service_restarting')+ expect(screen.queryByTestId('dsh-shell-iframe')).toBeNull()+ expect(console.warn).toHaveBeenCalledWith('[Iframe] view', expect.objectContaining({+ branch: 'service-wait',+ serviceHealthy: false,+ serviceRunning: true,+ iframeKey: 1077,+ }))+ view.rerender(<Iframe iframeRef={createRef()} />)+ expect(vi.mocked(console.warn).mock.calls.filter(([tag]) => tag === '[Iframe] view')).toHaveLength(1)++ await act(async () => {+ store.harness.busyAction = null+ })+ expect(screen.getByRole('status').textContent).toBe('status.service_waiting')+ await act(async () => {+ store.harness.serviceHealthy = true+ })+ const frame = screen.getByTestId<HTMLIFrameElement>('dsh-shell-iframe')+ expect(screen.getByRole('status').textContent).toBe('status.document_waiting')+ expect(console.warn).toHaveBeenCalledWith('[Iframe] view', expect.objectContaining({ branch: 'document-wait', iframeAlive: false }))++ await act(async () => {+ store.harness.markIframeAlive()+ })+ expect(screen.queryByRole('status')).toBeNull()+ expect(screen.getByTestId('dsh-shell-iframe')).toBe(frame)+ await act(async () => {+ store.harness.markIframeError()+ })+ expect(screen.getByText('ui.iframe_error')).not.toBeNull()+ expect(console.warn).toHaveBeenCalledWith('[Iframe] view', expect.objectContaining({ branch: 'iframe-error', iframeError: true }))+ expect(JSON.stringify(vi.mocked(console.warn).mock.calls)).not.toContain('secret')+})++it('diagnoses remote frame visibility across local health and error transitions without changing it', async () => {+ render(<Iframe iframeRef={createRef()} srcOverride="https://example.test/?token=secret" />)+ expect(screen.getByTestId('dsh-shell-iframe').getAttribute('src')).toBe('https://example.test/?token=secret')+ expect(screen.queryByRole('status')).toBeNull()+ expect(console.warn).toHaveBeenCalledWith('[Iframe] view', expect.objectContaining({ branch: 'remote-loading', remoteMode: true, serviceHealthy: false, iframeHidden: true }))+ const frame = screen.getByTestId<HTMLIFrameElement>('dsh-shell-iframe')+ await act(async () => {+ frame.dispatchEvent(new Event('load'))+ })+ expect(frame.style.visibility).toBe('visible')+ expect(console.warn).toHaveBeenCalledWith('[Iframe] view', expect.objectContaining({ branch: 'remote-frame', iframeHidden: false }))+ await act(async () => {+ store.harness.serviceHealthy = true+ store.harness.markIframeError()+ })+ expect(frame.style.visibility).toBe('hidden')+ expect(screen.queryByText('ui.iframe_error')).toBeNull()+ expect(console.warn).toHaveBeenLastCalledWith('[Iframe] view', expect.objectContaining({+ branch: 'remote-frame',+ serviceHealthy: true,+ iframeError: true,+ iframeHidden: true,+ }))+ expect(JSON.stringify(vi.mocked(console.warn).mock.calls)).not.toContain('secret')+})diff --git a/src/layout/components/iframe.tsx b/src/layout/components/iframe.tsxindex 006d674c..15df842d 100644--- a/src/layout/components/iframe.tsx+++ b/src/layout/components/iframe.tsx@@ -227,6 +227,30 @@ export function Iframe({ iframeRef, srcOverride = null, borderTint = null }: Ifrconst post = useIframePost(iframeRef)// 握手兜底:帧内接收器异常时不能让 iframe 永久藏住,超时后按「未确认」直接揭开。const appearancePending = translucent && bootFrame !== frameKey+ const iframeHidden = appearancePending || remoteLoading || harness.showIframeError+ const mounted = remoteMode || harness.serviceHealthy+ const showIframeError = !remoteMode && harness.showIframeError+ const documentWaiting = !remoteMode && mounted && !harness.iframeAlive && !showIframeError && !appearancePending+ const serviceStatusKey = harness.busyAction === 'restart' ? 'status.service_restarting' : 'status.service_waiting'+ const branch = !mounted ? 'service-wait' : showIframeError ? 'iframe-error' : remoteLoading ? 'remote-loading' : appearancePending ? 'appearance-wait' : documentWaiting ? 'document-wait' : remoteMode ? 'remote-frame' : 'local-frame'+ useWatch([branch, harness.status, remoteMode, harness.serviceHealthy, harness.serviceRunning, harness.iframeKey, harness.iframeLoaded, harness.iframeAlive, harness.iframeError, harness.startupPhase, harness.busyAction, appearancePending, documentWaiting, iframeHidden], () => {+ console.warn('[Iframe] view', {+ branch,+ status: harness.status,+ remoteMode,+ serviceHealthy: harness.serviceHealthy,+ serviceRunning: harness.serviceRunning,+ iframeKey: harness.iframeKey,+ iframeLoaded: harness.iframeLoaded,+ iframeAlive: harness.iframeAlive,+ iframeError: harness.iframeError,+ startupPhase: harness.startupPhase,+ busyAction: harness.busyAction,+ appearancePending,+ documentWaiting,+ iframeHidden,+ })+ }, { immediate: true })const { start: armAppearanceFallback, stop: stopAppearanceFallback } = useTimeoutFn(() => setBootFrame(frameKey),APPEARANCE_HANDSHAKE_TIMEOUT,@@ -581,8 +605,12 @@ export function Iframe({ iframeRef, srcOverride = null, borderTint = null }: Ifrreturn (<div className="relative min-h-0 flex-1"><If- cond={remoteMode || harness.serviceHealthy}- else={<Loadable subtitle={t(harness.startupStatusKey)} />}+ cond={mounted}+ else={(+ <Loadable subtitle={t(harness.startupStatusKey)}>+ <p role="status" className="text-xs leading-[18px] text-load-muted">{t(serviceStatusKey)}</p>+ </Loadable>+ )}><iframekey={remoteMode ? `remote-${srcOverride}` : harness.iframeKey}@@ -592,7 +620,7 @@ export function Iframe({ iframeRef, srcOverride = null, borderTint = null }: Ifr// 未确认收到启动期外观前先藏起来:帧内 boot 页(HARNESS + Loading plugins…)// 会先按不透明画一帧,露出那一下比等待更刺眼。上面的 Loadable 与之逐项同构,// 揭开时视觉无跳变,且有 4s 兜底不会永久藏住。- style={{ visibility: appearancePending || remoteLoading || harness.showIframeError ? 'hidden' : 'visible' }}+ style={{ visibility: iframeHidden ? 'hidden' : 'visible' }}src={remoteMode ? srcOverride : harness.iframeSrc}allow="accelerometer; ambient-light-sensor; autoplay; battery; camera; clipboard-read; clipboard-write; display-capture; document-domain; encrypted-media; fullscreen; gamepad; geolocation; gyroscope; hid; idle-detection; keyboard-map; magnetometer; microphone; midi; payment; picture-in-picture; publickey-credentials-get; screen-wake-lock; serial; speaker-selection; usb; web-share; xr-spatial-tracking"sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals allow-downloads allow-storage-access-by-user-activation"@@ -606,6 +634,12 @@ export function Iframe({ iframeRef, srcOverride = null, borderTint = null }: Ifr/></If>+ <If cond={documentWaiting}>+ <p role="status" className="absolute bottom-4 inset-x-4 text-center text-xs leading-[18px] text-load-muted pointer-events-none">+ {t('status.document_waiting')}+ </p>+ </If>+{/* 远端机器勾选「边框着色」时,用标识色给内容区描边:当前处于远端一眼可辨 */}<If cond={borderTint !== null}><divdiff --git a/src/layout/components/webview.test.tsx b/src/layout/components/webview.test.tsxindex 39b1bfaa..aaf368a9 100644--- a/src/layout/components/webview.test.tsx+++ b/src/layout/components/webview.test.tsx@@ -9,13 +9,15 @@ const mocks = vi.hoisted(() => ({navbar: vi.fn<(props: NavbarProps) => void>(),shortcuts: { rows: [] },setShortcuts: vi.fn(),+ harness: { status: 'ready', serviceHealthy: true, serviceRunning: true, iframeKey: 0, iframeLoaded: false, iframeAlive: false, iframeError: false, startupPhase: 'process-boot', busyAction: null },+ recovery: { recovery: { required: false } },}))vi.mock('@tauri-apps/api/window', () => ({ getCurrentWindow: () => ({ label: 'window-2' }) }))vi.mock('@tauri-apps/plugin-os', () => ({ type: () => 'windows' }))vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }))vi.mock('valtio-define', () => ({ useStore: (value: unknown) => value }))-vi.mock('@/store', () => ({ store: { harness: { status: 'ready', serviceHealthy: true }, recovery: {} } }))+vi.mock('@/store', () => ({ store: { harness: mocks.harness, recovery: mocks.recovery } }))vi.mock('@/hooks/use-appearance', () => ({ useAppearance: () => '' }))vi.mock('@/hooks/use-dsh-style', () => ({ useDshStyle: () => [{}] }))vi.mock('@/hooks/use-dsh-shortcuts', () => ({@@ -40,6 +42,39 @@ vi.mock('./iframe', () => ({}))vi.mock('./loadable', () => ({ Loadable: () => <div data-testid="session-pending" /> }))+it('logs the selected shell branch and deduplicates unrelated rerenders without exposing remote URLs', () => {+ window.location.hash = ''+ const view = render(<Webview />)+ expect(console.warn).toHaveBeenLastCalledWith('[Webview] shell view', expect.objectContaining({+ branch: 'iframe',+ status: 'ready',+ remoteMode: false,+ serviceHealthy: true,+ iframeKey: 0,+ iframeLoaded: false,+ iframeAlive: false,+ iframeError: false,+ }))+ view.rerender(<Webview />)+ expect(console.warn).toHaveBeenCalledTimes(1)+ mocks.harness.status = 'error'+ view.rerender(<Webview />)+ expect(console.warn).toHaveBeenLastCalledWith('[Webview] shell view', expect.objectContaining({ branch: 'setup' }))+ mocks.recovery.recovery.required = true+ view.rerender(<Webview />)+ expect(console.warn).toHaveBeenLastCalledWith('[Webview] shell view', expect.objectContaining({ branch: 'recovery' }))+ mocks.harness.status = 'preinstall'+ view.rerender(<Webview />)+ expect(console.warn).toHaveBeenLastCalledWith('[Webview] shell view', expect.objectContaining({ branch: 'preinstall' }))+ mocks.harness.status = 'ready'+ mocks.harness.serviceHealthy = false+ view.rerender(<Webview />)+ act(() => navbar().onRemoteChange('https://example.test/?token=secret', null))+ expect(console.warn).toHaveBeenLastCalledWith('[Webview] shell view', expect.objectContaining({ branch: 'iframe', remoteMode: true, serviceHealthy: false }))+ expect(JSON.stringify(vi.mocked(console.warn).mock.calls)).not.toContain('secret')+ expect(console.warn).toHaveBeenCalledTimes(6)+})+function navbar() {return mocks.navbar.mock.lastCall![0]}@@ -57,6 +92,9 @@ function acknowledge(frame: HTMLIFrameElement, sessionId: string) {beforeEach(() => {vi.useFakeTimers()window.location.hash = new URLSearchParams({ sessionId: 'target', iframeUrl: 'http://127.0.0.1:4001/' }).toString()+ Object.assign(mocks.harness, { status: 'ready', serviceHealthy: true })+ mocks.recovery.recovery.required = false+ vi.spyOn(console, 'warn').mockImplementation(() => {})mocks.navbar.mockClear()mocks.setShortcuts.mockClear()})diff --git a/src/layout/components/webview.tsx b/src/layout/components/webview.tsxindex ead921af..56c7f4ab 100644--- a/src/layout/components/webview.tsx+++ b/src/layout/components/webview.tsx@@ -49,7 +49,7 @@ export function Webview() {const [dshStyle] = useDshStyle()const [{ rows: shortcutRows }, setDshShortcuts] = useDshShortcuts()- const { status, serviceHealthy } = useStore(store.harness)+ const { status, serviceHealthy, serviceRunning, iframeKey, iframeLoaded, iframeAlive, iframeError, startupPhase, busyAction } = useStore(store.harness)const { recovery } = useStore(store.recovery)const [remoteView, setRemoteView] = useState({ url: '', tint: null as string | null })const [sessionSource, setSessionSource] = useState(sessionTarget?.url ?? '')@@ -57,6 +57,24 @@ export function Webview() {const borderTint = remoteView.tintconst remoteMode = activeTunnelUrl !== ''const live = status === 'ready' && (remoteMode || serviceHealthy)+ const branch = status === 'ready' ? 'iframe' : status === 'preinstall' ? 'preinstall' : status === 'error' && recovery.required ? 'recovery' : 'setup'+ useWatch([branch, status, remoteMode, serviceHealthy, serviceRunning, iframeKey, iframeLoaded, iframeAlive, iframeError, startupPhase, busyAction, sessionPending, Boolean(sessionError)], () => {+ console.warn('[Webview] shell view', {+ branch,+ status,+ remoteMode,+ serviceHealthy,+ serviceRunning,+ iframeKey,+ iframeLoaded,+ iframeAlive,+ iframeError,+ startupPhase,+ busyAction,+ sessionPending,+ sessionError: Boolean(sessionError),+ })+ }, { immediate: true })function syncViewMenu() {if (type() !== 'macos')diff --git a/src/store/modules/harness/store.ts b/src/store/modules/harness/store.tsindex cc282f09..ca540a77 100644--- a/src/store/modules/harness/store.ts+++ b/src/store/modules/harness/store.ts@@ -939,8 +939,18 @@ let iframeWatch: { loaded: boolean, timer: ReturnType<typeof setTimeout> } | nulharness.$subscribe(() => {const { status, serviceHealthy, iframeLoaded, iframeError } = harness.$stateconst watching = status === 'ready' && serviceHealthy && !harness.iframeAlive && !iframeError+ const context = {+ status,+ serviceHealthy,+ serviceRunning: harness.serviceRunning,+ iframeKey: harness.iframeKey,+ iframeLoaded,+ iframeAlive: harness.iframeAlive,+ iframeError,+ }if (!watching) {if (iframeWatch) {+ console.warn('[Harness] iframe watchdog cancelled', context)clearTimeout(iframeWatch.timer)iframeWatch = null}@@ -953,13 +963,24 @@ harness.$subscribe(() => {if (iframeWatch) {clearTimeout(iframeWatch.timer)}+ const timeoutMs = iframeLoaded ? IFRAME_FRAME_GRACE_TIMEOUT : IFRAME_LOAD_TIMEOUT+ console.warn('[Harness] iframe watchdog armed', { ...context, timeoutMs })iframeWatch = {loaded: iframeLoaded,timer: setTimeout(() => {iframeWatch = null- console.warn('[Harness] iframe never confirmed a dsh document, showing retryable error')+ console.warn('[Harness] iframe watchdog expired', {+ status: harness.status,+ serviceHealthy: harness.serviceHealthy,+ serviceRunning: harness.serviceRunning,+ iframeKey: harness.iframeKey,+ iframeLoaded: harness.iframeLoaded,+ iframeAlive: harness.iframeAlive,+ iframeError: harness.iframeError,+ timeoutMs,+ })harness.iframeLoaded = falseharness.iframeError = true- }, iframeLoaded ? IFRAME_FRAME_GRACE_TIMEOUT : IFRAME_LOAD_TIMEOUT),+ }, timeoutMs),}})diff --git a/test/iframe-watchdog.test.ts b/test/iframe-watchdog.test.tsindex ab3bd051..79a5bdc7 100644--- a/test/iframe-watchdog.test.ts+++ b/test/iframe-watchdog.test.ts@@ -54,11 +54,63 @@ beforeEach(async () => {await mountIframe({ serviceHealthy: false, iframeLoaded: true, iframeError: true })})-afterEach(() => {+afterEach(async () => {+ harness.serviceHealthy = false+ await vi.advanceTimersByTimeAsync(0)vi.useRealTimers()+ vi.restoreAllMocks()})describe('iframe dsh document watchdog', () => {+ it('logs arm, load rearm and expiry once with the current recovery flags', async () => {+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})+ await mountIframe({ iframeKey: 1077 })+ const context = {+ status: 'ready',+ serviceRunning: true,+ serviceHealthy: true,+ iframeKey: 1077,+ iframeAlive: false,+ iframeLoaded: false,+ iframeError: false,+ }+ expect(warn).toHaveBeenCalledWith('[Harness] iframe watchdog armed', { ...context, timeoutMs: 20000 })+ harness.startupReason = 'unrelated activity'+ await vi.advanceTimersByTimeAsync(0)+ expect(warn).toHaveBeenCalledTimes(1)++ harness.markIframeLoaded()+ await vi.advanceTimersByTimeAsync(0)+ expect(warn).toHaveBeenLastCalledWith('[Harness] iframe watchdog armed', { ...context, iframeLoaded: true, timeoutMs: 5000 })+ expect(warn).toHaveBeenCalledTimes(2)+ await vi.advanceTimersByTimeAsync(4999)+ expect(harness.iframeError).toBe(false)+ await vi.advanceTimersByTimeAsync(1)+ expect(warn).toHaveBeenLastCalledWith('[Harness] iframe watchdog expired', { ...context, iframeLoaded: true, timeoutMs: 5000 })+ expect(harness.showIframeError).toBe(true)+ expect(warn).toHaveBeenCalledTimes(3)+ })++ it.each(['alive', 'unhealthy', 'error'] as const)('logs cancellation when the frame becomes %s without changing the deadline', async (reason) => {+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})+ await mountIframe()+ if (reason === 'alive')+ harness.markIframeAlive()+ else if (reason === 'unhealthy')+ harness.serviceHealthy = false+ else+ harness.fail('startup failure', undefined, undefined, undefined, true)+ await vi.advanceTimersByTimeAsync(0)+ expect(warn).toHaveBeenLastCalledWith('[Harness] iframe watchdog cancelled', expect.objectContaining({+ status: reason === 'error' ? 'error' : 'ready',+ serviceHealthy: reason !== 'unhealthy',+ iframeAlive: reason === 'alive',+ }))+ expect(warn).toHaveBeenCalledTimes(2)+ await vi.advanceTimersByTimeAsync(20000)+ expect(harness.iframeError).toBe(false)+ })+// issue #705:浏览器内部错误页(代理拦截、DNS 失败等)同样触发 iframe 的 load,// 只按 load 判定就会把它当成加载成功,用户看不到任何重试入口。it('shows the retryable error screen when the frame commits a document but never reports a dsh page', async () => {@@ -166,6 +218,15 @@ describe('iframe dsh document watchdog', () => {})describe('iframe unreachable i18n contract', () => {+ it('defines distinct service and document waiting messages in both locales', () => {+ for (const file of ['zh-CN.json', 'en-US.json'] as const) {+ const messages = locale(file)+ const values = ['status.service_restarting', 'status.service_waiting', 'status.document_waiting'].map(key => messages[key])+ expect(values.every(value => typeof value === 'string' && value.length > 0)).toBe(true)+ expect(new Set(values).size).toBe(3)+ }+ })+it('defines the unreachable hint in both locales', () => {expect(locale('zh-CN.json')['ui.iframe_unreachable_hint']).toBeTypeOf('string')expect(locale('en-US.json')['ui.iframe_unreachable_hint']).toBeTypeOf('string')