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
This commit is contained in:
2025-10-20 10:19:07 -04:00
parent c54c417671
commit 00deda4347
2 changed files with 26 additions and 2 deletions

View File

@@ -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');
});
});
});