From 3dffb9dc0d70202994f4977c33d56f3f84fe7e87 Mon Sep 17 00:00:00 2001 From: jackwener Date: Sun, 22 Mar 2026 22:57:15 +0800 Subject: [PATCH] fix: update doctor tests for auto-start daemon and --no-live default - Fix skip message assertion: 'skipped (--no-live)' instead of old text - Fix auto-start test: mock checkDaemonStatus for both initial and final calls --- src/doctor.test.ts | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/doctor.test.ts b/src/doctor.test.ts index 61628db..df28637 100644 --- a/src/doctor.test.ts +++ b/src/doctor.test.ts @@ -84,36 +84,28 @@ describe('doctor report rendering', () => { issues: [], })); - expect(text).toContain('[SKIP] Connectivity: not tested (use --live)'); + expect(text).toContain('[SKIP] Connectivity: skipped (--no-live)'); }); it('reports consistent status when live check auto-starts the daemon', async () => { - // With the reordered flow, checkDaemonStatus is called only ONCE — after - // the connectivity check that may auto-start the daemon. - mockCheckDaemonStatus.mockResolvedValueOnce({ running: true, extensionConnected: false }); - mockConnect.mockRejectedValueOnce(new Error( - 'Daemon is running but the Browser Extension is not connected.\n' + - 'Please install and enable the opencli Browser Bridge extension in Chrome.', - )); - - const report = await runBrowserDoctor({ live: true }); - - // Status reflects the post-connectivity state (daemon running) - expect(report.daemonRunning).toBe(true); + // checkDaemonStatus is called twice: once for auto-start check, once for final status. + // First call: daemon not running (triggers auto-start attempt) + mockCheckDaemonStatus.mockResolvedValueOnce({ running: false, extensionConnected: false }); + // Auto-start attempt via BrowserBridge.connect fails + mockConnect.mockRejectedValueOnce(new Error('Could not start daemon')); + // Second call: daemon still not running after failed auto-start + mockCheckDaemonStatus.mockResolvedValueOnce({ running: false, extensionConnected: false }); + + const report = await runBrowserDoctor({ live: false }); + + // Status reflects daemon not running + expect(report.daemonRunning).toBe(false); expect(report.extensionConnected).toBe(false); - // checkDaemonStatus should only be called once - expect(mockCheckDaemonStatus).toHaveBeenCalledTimes(1); - // Should NOT report "daemon not running" since it IS running after live check - expect(report.issues).not.toContain( - expect.stringContaining('Daemon is not running'), - ); - // Should report extension not connected - expect(report.issues).toEqual(expect.arrayContaining([ - expect.stringContaining('Chrome extension is not connected'), - ])); - // Should report connectivity failure + // checkDaemonStatus called twice (initial + final) + expect(mockCheckDaemonStatus).toHaveBeenCalledTimes(2); + // Should report daemon not running expect(report.issues).toEqual(expect.arrayContaining([ - expect.stringContaining('Browser connectivity test failed'), + expect.stringContaining('Daemon is not running'), ])); }); });