Skip to content

Commit ba72a4e

Browse files
author
Zoo (VP)
committed
test(webview): cover recovery rejection and watchdog precondition
Address two minor review threads on the watchdog spec: - Cover the reload rejection path: stub the recovery HTML regeneration to reject and assert the failure is logged and webview.html is untouched. - Assert the watchdog interval was actually scheduled before the sidebar disposal test disposes the view, so the post-disposal null check proves the watchdog was stopped rather than never having started.
1 parent ec7d375 commit ba72a4e

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎src/core/webview/__tests__/ClineProvider.spec.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,11 @@ describe("ClineProvider", () => {
749749
await provider.resolveWebviewView(mockWebviewView)
750750
const htmlAfterResolve = mockWebviewView.webview.html
751751

752+
// Precondition: the watchdog interval was actually scheduled, so the
753+
// null check below proves disposal stopped it rather than it never
754+
// having started.
755+
expect(provider["webviewWatchdogInterval"]).not.toBeNull()
756+
752757
// The provider outlives a disposed sidebar view; VS Code re-resolves
753758
// a fresh view later. Disposal must stop the watchdog and drop the
754759
// stale view reference so no recovery reload targets the dead view.
@@ -787,6 +792,22 @@ describe("ClineProvider", () => {
787792
)
788793
})
789794

795+
test("logs and keeps the webview html when the recovery reload rejects", async () => {
796+
await provider.resolveWebviewView(mockWebviewView)
797+
const htmlAfterResolve = mockWebviewView.webview.html
798+
// The watchdog reload no longer goes through a VS Code command; stub
799+
// the recovery HTML regeneration itself to reject.
800+
provider["getWebviewHtml"] = vi.fn().mockRejectedValue(new Error("reload boom"))
801+
;(mockOutputChannel.appendLine as ReturnType<typeof vi.fn>).mockClear()
802+
803+
await vi.advanceTimersByTimeAsync(120_000)
804+
805+
expect(mockOutputChannel.appendLine).toHaveBeenCalledWith(
806+
expect.stringContaining("[Zoo Code] Failed to reload webview: reload boom"),
807+
)
808+
expect(mockWebviewView.webview.html).toBe(htmlAfterResolve)
809+
})
810+
790811
test("does not reassign html when the provider is disposed mid-recovery", async () => {
791812
await provider.resolveWebviewView(mockWebviewView)
792813
const htmlAfterResolve = mockWebviewView.webview.html

0 commit comments

Comments
 (0)