From 99d0a949e55f19b0f8094b44109bb8ee8fe92c96 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 15 May 2026 10:51:59 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20[Add=20test=20for=20undo=20histo?= =?UTF-8?q?ry=20error=20path=20in=20deleteRows]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎯 What: Added a unit test to cover the catch block when fetching rows for undo history fails in `HostBridge.deleteRows`. 📊 Coverage: The scenario where `executeQuery` throws an error during the undo history preparation in `deleteRows` is now tested. ✨ Result: Ensures that `console.warn` is properly invoked and `deleteRows` execution proceeds even if undo history capture fails, increasing branch coverage. --- tests/unit/hostBridge.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/unit/hostBridge.test.ts b/tests/unit/hostBridge.test.ts index 5838170..50f80e0 100644 --- a/tests/unit/hostBridge.test.ts +++ b/tests/unit/hostBridge.test.ts @@ -120,4 +120,31 @@ describe('HostBridge', () => { const uri = args[1]; assert.ok(uri.path.endsWith('.txt'), `Path should end with .txt, got ${uri.path}`); }); + + it('should catch and log error if fetch rows for undo history fails in deleteRows', async () => { + const consoleWarnMock = mock.method(console, 'warn', () => {}); + const error = new Error('Database disconnected'); + const dbOps = { + executeQuery: mock.fn(async () => { throw error; }), + deleteRows: mock.fn(async () => {}) + }; + const mockDocument = { + uri: vscode.Uri.parse('file:///test.db'), + documentKey: Promise.resolve('test-key'), + recordExternalModification: mock.fn(), + }; + const mockProvider = { webviews: new Map(), context: {} }; + const bridge = new HostBridge(mockProvider as any, mockDocument as any); + bridge.ensureDatabaseInitialized = () => dbOps as any; + + await bridge.deleteRows('table1', [1]); + + assert.strictEqual(consoleWarnMock.mock.callCount(), 1); + assert.deepStrictEqual(consoleWarnMock.mock.calls[0].arguments, [ + 'Failed to fetch rows for undo history:', + error + ]); + + assert.strictEqual(dbOps.deleteRows.mock.callCount(), 1); + }); });