|
1 | 1 | // pnpm --filter roo-cline test core/webview/__tests__/ClineProvider.spec.ts |
2 | 2 |
|
| 3 | +import fs from "fs" |
3 | 4 | import * as path from "path" |
4 | 5 | import { TaskRegistry } from "../../task/TaskRegistry" |
5 | 6 |
|
@@ -700,31 +701,50 @@ describe("ClineProvider", () => { |
700 | 701 | test("resolveWebviewView builds HMR content against the local dev server when it is reachable", async () => { |
701 | 702 | const originalThemeFixtureProbe = process.env.ROO_CODE_THEME_FIXTURE_PROBE |
702 | 703 | delete process.env.ROO_CODE_THEME_FIXTURE_PROBE |
| 704 | + // getHMRHtmlContent prefers an on-disk .vite-port file when one exists, so a |
| 705 | + // stale dev leftover could silently move the probe (and the HMR URLs) to |
| 706 | + // another port. Establish the default-port branch for this test by hiding |
| 707 | + // exactly that file from the existence check; every other path falls |
| 708 | + // through to the real implementation. |
| 709 | + const realExistsSync = fs.existsSync |
| 710 | + const existsSyncSpy = vi |
| 711 | + .spyOn(fs, "existsSync") |
| 712 | + .mockImplementation((target) => |
| 713 | + path.basename(String(target)) === ".vite-port" ? false : realExistsSync(target), |
| 714 | + ) |
703 | 715 |
|
704 | | - provider = new ClineProvider( |
705 | | - { ...mockContext, extensionMode: vscode.ExtensionMode.Development }, |
706 | | - mockOutputChannel, |
707 | | - "sidebar", |
708 | | - new ContextProxy({ ...mockContext, extensionMode: vscode.ExtensionMode.Development }), |
709 | | - ) |
710 | | - // The default axios mock resolves, so the dev-server probe succeeds and the |
711 | | - // HMR HTML branch (instead of the production fallback) is taken. |
712 | | - vi.mocked(axios.get).mockClear() |
713 | | - await provider.resolveWebviewView(mockWebviewView) |
714 | | - |
715 | | - // Pin the health-check URL itself: the mock resolves for any URL, so only |
716 | | - // this assertion keeps the probe from silently drifting back to |
717 | | - // `localhost` (the IPv6 resolution failure this branch fixes). |
718 | | - expect(axios.get).toHaveBeenCalledWith("http://127.0.0.1:5173") |
| 716 | + try { |
| 717 | + provider = new ClineProvider( |
| 718 | + { ...mockContext, extensionMode: vscode.ExtensionMode.Development }, |
| 719 | + mockOutputChannel, |
| 720 | + "sidebar", |
| 721 | + new ContextProxy({ ...mockContext, extensionMode: vscode.ExtensionMode.Development }), |
| 722 | + ) |
| 723 | + // The default axios mock resolves, so the dev-server probe succeeds and the |
| 724 | + // HMR HTML branch (instead of the production fallback) is taken. |
| 725 | + vi.mocked(axios.get).mockClear() |
| 726 | + await provider.resolveWebviewView(mockWebviewView) |
719 | 727 |
|
720 | | - const html = mockWebviewView.webview.html |
721 | | - // The dev server URL must be baked into the module script tag and CSP directives. |
722 | | - expect(html).toContain("http://127.0.0.1:5173/src/index.tsx") |
723 | | - expect(html).toContain("ws://127.0.0.1:5173") |
724 | | - expect(html).toContain("http://127.0.0.1:5173/@react-refresh") |
| 728 | + // Pin the health-check URL itself: the mock resolves for any URL, so only |
| 729 | + // this assertion keeps the probe from silently drifting back to |
| 730 | + // `localhost` (the IPv6 resolution failure this branch fixes). |
| 731 | + expect(axios.get).toHaveBeenCalledWith("http://127.0.0.1:5173") |
725 | 732 |
|
726 | | - if (originalThemeFixtureProbe !== undefined) { |
727 | | - process.env.ROO_CODE_THEME_FIXTURE_PROBE = originalThemeFixtureProbe |
| 733 | + const html = mockWebviewView.webview.html |
| 734 | + // The dev server URL must be baked into the module script tag and CSP directives. |
| 735 | + expect(html).toContain("http://127.0.0.1:5173/src/index.tsx") |
| 736 | + expect(html).toContain("ws://127.0.0.1:5173") |
| 737 | + expect(html).toContain("http://127.0.0.1:5173/@react-refresh") |
| 738 | + } finally { |
| 739 | + existsSyncSpy.mockRestore() |
| 740 | + // Always restore the probe flag (even when an assertion above throws), |
| 741 | + // so later tests outside the fixture-probe describe block cannot observe |
| 742 | + // this test's deletion. |
| 743 | + if (originalThemeFixtureProbe !== undefined) { |
| 744 | + process.env.ROO_CODE_THEME_FIXTURE_PROBE = originalThemeFixtureProbe |
| 745 | + } else { |
| 746 | + delete process.env.ROO_CODE_THEME_FIXTURE_PROBE |
| 747 | + } |
728 | 748 | } |
729 | 749 | }) |
730 | 750 |
|
|
0 commit comments