From 00deda43471607163080067dcfd51a20c86fa8f0 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 20 Oct 2025 10:19:07 -0400 Subject: [PATCH] test: add vault-tools defensive code coverage - Added test for getFolderWaypoint file read error handling (line 777) - Documented unreachable defensive code in stat() (lines 452-456) - Documented unreachable defensive code in exists() (lines 524-528) - Added istanbul ignore comments for unreachable defensive returns Analysis: - Lines 452-456 and 524-528 are unreachable because getAbstractFileByPath only returns TFile, TFolder, or null - all cases are handled before the defensive fallback code - Line 777 is now covered by testing file read errors in getFolderWaypoint Coverage: vault-tools.ts now at 100% statement coverage (99.8% tools overall) Test count: 84 vault-tools tests, 505 total tests passing --- src/tools/vault-tools.ts | 14 ++++++++++++-- tests/vault-tools.test.ts | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/tools/vault-tools.ts b/src/tools/vault-tools.ts index d8a14a8..bf93000 100644 --- a/src/tools/vault-tools.ts +++ b/src/tools/vault-tools.ts @@ -448,11 +448,16 @@ export class VaultTools { }; } - // Path doesn't exist (shouldn't reach here) + // DEFENSIVE CODE - UNREACHABLE + // This code is unreachable because getAbstractFileByPath only returns TFile, TFolder, or null. + // All three cases are handled above (null at line 405, TFile at line 420, TFolder at line 436). + // TypeScript requires exhaustive handling, so this defensive return is included. + /* istanbul ignore next */ const result: StatResult = { path: normalizedPath, exists: false }; + /* istanbul ignore next */ return { content: [{ type: "text", @@ -520,11 +525,16 @@ export class VaultTools { }; } - // Path doesn't exist (shouldn't reach here) + // DEFENSIVE CODE - UNREACHABLE + // This code is unreachable because getAbstractFileByPath only returns TFile, TFolder, or null. + // All three cases are handled above (null at line 479, TFile at line 494, TFolder at line 509). + // TypeScript requires exhaustive handling, so this defensive return is included. + /* istanbul ignore next */ const result: ExistsResult = { path: normalizedPath, exists: false }; + /* istanbul ignore next */ return { content: [{ type: "text", diff --git a/tests/vault-tools.test.ts b/tests/vault-tools.test.ts index 8b8ee2f..b9dc00b 100644 --- a/tests/vault-tools.test.ts +++ b/tests/vault-tools.test.ts @@ -1303,4 +1303,18 @@ describe('VaultTools', () => { expect(parsed.matches[0].snippet).toContain('target'); }); }); + + describe('getFolderWaypoint - error handling', () => { + it('should handle file read errors gracefully', async () => { + const mockFile = createMockTFile('test.md'); + mockVault.getAbstractFileByPath = jest.fn().mockReturnValue(mockFile); + mockVault.read = jest.fn().mockRejectedValue(new Error('Permission denied')); + + const result = await vaultTools.getFolderWaypoint('test.md'); + + expect(result.isError).toBe(true); + expect(result.content[0].text).toContain('Get folder waypoint error'); + expect(result.content[0].text).toContain('Permission denied'); + }); + }); }); \ No newline at end of file