Commit Graph

15 Commits

Author SHA1 Message Date
303b5cf8b8 test: add comprehensive search-utils tests 2025-10-25 22:14:29 -04:00
f9634a7b2a test: add comprehensive waypoint-utils tests
- Test extractWaypointBlock() with valid/invalid waypoints, unclosed blocks, multiple links
- Test hasWaypointMarker() with all marker combinations
- Test isFolderNote() with basename match, waypoint marker, both, neither, file read errors
- Test wouldAffectWaypoint() detecting removal, content changes, acceptable moves
- Test getParentFolderPath() and getBasename() helper methods
- Achieve 100% coverage on waypoint-utils.ts (52 tests)
2025-10-25 22:14:29 -04:00
3360790149 refactor: update VaultTools to pass adapters to utils
Updated VaultTools to use adapters for all utility method calls:
- SearchUtils.searchWaypoints() now receives vault adapter
- WaypointUtils.isFolderNote() now receives vault adapter
- LinkUtils.validateWikilinks() now receives vault and metadata adapters
- LinkUtils.resolveLink() now receives vault and metadata adapters
- LinkUtils.getBacklinks() now receives vault and metadata adapters

Removed App dependency from VaultTools constructor - now only requires
vault and metadata adapters. Updated factory and all test files accordingly.

All tests passing (336/336).
2025-10-25 22:14:29 -04:00
26b8c2bd77 test: add comprehensive frontmatter-utils tests
Add 82 comprehensive tests for frontmatter-utils.ts achieving 96.58% coverage.

Test coverage:
- extractFrontmatter(): All delimiters, line endings, parse errors, edge cases
- extractFrontmatterSummary(): Field extraction, normalization, null handling
- hasFrontmatter(): Quick detection with various formats
- serializeFrontmatter(): All data types, special characters, quoting rules
- parseExcalidrawMetadata(): JSON extraction, compression detection, error handling

Mock parseYaml from obsidian module for isolated testing.

Uncovered lines (253-255, 310) are unreachable defensive code paths.
2025-10-25 22:14:29 -04:00
5023a4dc7e test: add comprehensive glob-utils tests
- Test all glob pattern types: *, **, ?, [abc], {a,b}
- Test edge cases: unclosed brackets, unclosed braces
- Test all public methods: matches(), matchesIncludes(), matchesExcludes(), shouldInclude()
- Test special regex character escaping: . / ( ) + ^ $ | \
- Test complex pattern combinations and real-world scenarios
- Achieve 100% coverage on glob-utils.ts (52 tests)
2025-10-25 22:14:29 -04:00
5760ac9b8b test: add comprehensive VaultTools coverage tests
Added extensive test coverage for VaultTools to increase coverage from 54.9% to 93.83%:

getVaultInfo tests:
- Return vault info with total notes and size
- Handle empty vault
- Handle files with missing stat info
- Handle errors gracefully
- Format large file sizes correctly (KB, MB, GB)

search tests:
- Search for literal text
- Search with regex pattern
- Handle invalid regex pattern
- Filter by folder
- Respect maxResults limit
- Handle file read errors gracefully
- Handle case sensitive search
- Extract snippets correctly
- Handle zero-width regex matches
- Handle general search errors

Waypoint tests (searchWaypoints, getFolderWaypoint, isFolderNote):
- Search for waypoints in vault
- Filter waypoints by folder
- Extract waypoint from file
- Detect folder notes
- Handle file not found errors
- Handle general errors

resolveWikilink tests:
- Resolve wikilink successfully
- Provide suggestions for unresolved links
- Handle errors gracefully
- Handle invalid source path

getBacklinks unlinked mentions tests:
- Find unlinked mentions
- Skip files that already have linked backlinks
- Skip target file itself in unlinked mentions
- Not return unlinked mentions when includeUnlinked is false

list edge case tests:
- Handle invalid path
- Handle non-existent folder
- Handle path pointing to file instead of folder
- Handle cursor not found in pagination

validateWikilinks edge case tests:
- Handle invalid path
2025-10-20 00:20:12 -04:00
2e30b81f01 test: comprehensive coverage for NoteTools
Add extensive test suite for note-tools.ts covering all major operations
and error paths. Improves statement coverage from 13.94% to 96.01%.

Tests added:
- readNote: success, errors, frontmatter parsing
- createNote: success, conflict strategies (error/overwrite/rename), parent folder creation
- updateNote: success, errors, waypoint protection
- deleteNote: soft/permanent delete, dry run, version checking
- renameFile: success, errors, version checking, parent folder creation
- readExcalidraw: success, non-Excalidraw files, errors
- updateFrontmatter: success, field removal, version checking
- updateSections: success, invalid ranges, version checking
- Path validation for all methods
- Empty path validation for all methods

Mock enhancements:
- Added modify, delete, trash methods to VaultAdapter mock
- Added parseYaml function to Obsidian mock for frontmatter testing

Coverage improvements for note-tools.ts:
- Statements: 13.94% -> 96.01% (+82.07%)
- Branches: 5.1% -> 88.44% (+83.34%)
- Functions: 27.27% -> 90.9% (+63.63%)
- Lines: 13.94% -> 96.4% (+82.46%)
2025-10-20 00:13:03 -04:00
f5a671e625 refactor: migrate parent-folder-detection tests to mock adapters
Update parent-folder-detection.test.ts to use the new mock adapter
pattern (createMockVaultAdapter, createMockFileManagerAdapter) instead
of manually mocking Obsidian API objects.

Key changes:
- Replace manual vault/app mocks with adapter helpers
- Use createMockTFile and createMockTFolder for consistent fixtures
- Fix mock reference synchronization with getter pattern for App.vault
- Standardize all mock reassignments to use jest.fn() methods
- Update all 14 tests to properly reassign mocks in test setup

This resolves all 7 failing tests and improves test maintainability
by using consistent mock patterns across the test suite.

All tests passing: 14/14 in parent-folder-detection.test.ts
2025-10-20 00:01:48 -04:00
aca4d35944 test: add coverage for VaultTools uncovered paths
Add tests for:
- getBacklinks with snippet options (includeSnippets true/false)
- getBacklinks error handling (file not found, read errors)
- validateWikilinks error paths (file not found, read errors)
- validateWikilinks successful validation with resolved/unresolved links

Improves vault-tools.ts coverage from 35.85% to 54.9% statements.
Adds 7 new tests (27 to 34 total).
2025-10-19 23:48:36 -04:00
d91e478ada test: fix list-notes-sorting tests with proper mocks
Use createMockTFolder helper which includes isRoot() method.
Replace old App mocks with createMockVaultAdapter pattern.
Properly mock getRoot() method to return root folder with children.
Fixes TypeError: item.isRoot is not a function.
2025-10-19 23:38:15 -04:00
862c5533e8 test: update vault-tools tests to use mock adapters
Replace complex App object mocks with clean mock adapter pattern.
Simplifies test setup and improves maintainability.

- Created comprehensive tests for VaultTools methods using mock adapters
- Tests cover listNotes, stat, exists, and list (enhanced) functionality
- Includes tests for frontmatter extraction edge cases
- Fixed mock helpers to use proper prototype chains for instanceof checks
- All 27 VaultTools tests passing
2025-10-19 23:34:28 -04:00
248b3924fe test: add mock adapter factories
Create factory functions for mock adapters to simplify test setup.
Includes helpers for creating mock TFile and TFolder objects.
2025-10-19 23:18:16 -04:00
9d07ec64e2 Phase 2: API Unification & Typed Results + Phase 2.1 Fixes
Phase 2 - Breaking Changes (v2.0.0):
- Added typed result interfaces (FileMetadata, DirectoryMetadata, VaultInfo, SearchResult, SearchMatch)
- Unified parameter naming: list_notes now uses 'path' parameter (removed 'folder')
- Enhanced tool responses with structured JSON for all tools
- list_notes: Returns array of FileMetadata/DirectoryMetadata with full metadata
- search_notes: Returns SearchResult with line numbers, snippets, and match ranges
- get_vault_info: Returns VaultInfo with comprehensive statistics
- Updated all tool descriptions to document structured responses
- Version bumped to 2.0.0 (breaking changes)

Phase 2.1 - Post-Testing Fixes:
- Fixed root listing to exclude vault root folder itself (handles path '', '/', and isRoot())
- Fixed alphabetical sorting to be case-insensitive for stable ordering
- Improved directory metadata with better timestamp detection and error handling
- Fixed parent folder validation order (check if file before checking existence)
- Updated documentation with root path examples and leading slash warnings
- Added comprehensive test suite for sorting and root listing behavior
- Fixed test mocks to use proper TFile/TFolder instances

Tests: All 64 tests passing
Build: Successful, no errors
2025-10-16 22:49:28 -04:00
d074470d11 Release v1.2.0: Enhanced Authentication & Parent Folder Detection
Phase 1.5 Complete:
- Add automatic API key generation with secure random generation
- Add createParents parameter to create_note tool
- Fix authentication vulnerability (auth enabled without key)
- Add MCP client configuration snippet generator
- Improve UI/UX for authentication management
- Add comprehensive test coverage

Security:
- Fixed critical vulnerability in authentication middleware
- Implement three-layer defense (UI, server start, middleware)
- Cryptographically secure key generation (32 chars)

Features:
- Auto-generate API key when authentication enabled
- Copy/regenerate buttons for API key management
- Recursive parent folder creation for nested paths
- Enhanced error messages with actionable guidance
- Selectable connection information and config snippets

Documentation:
- Updated CHANGELOG.md with v1.2.0 release notes
- Updated ROADMAP.md (Phase 1.5 marked complete)
- Created IMPLEMENTATION_NOTES_AUTH.md
- Created RELEASE_NOTES_v1.2.0.md
2025-10-16 22:11:33 -04:00
7524271eaa Release v1.1.0: Phase 1.1 - Path Normalization & Error Handling
- Add PathUtils for cross-platform path normalization and validation
- Add ErrorMessages with context-aware, actionable error messages
- Update all tool implementations with enhanced path handling
- Improve tool descriptions for AI agents with detailed guidance
- Add Jest testing infrastructure with 43 passing tests
- Add comprehensive documentation (Tool Selection Guide, error improvements)
- Fix cross-platform path issues (Windows backslashes, case sensitivity)
- Fix delete folder error message (clear 'cannot delete folders' message)
- Fix parent folder detection with specific error messages
- All changes backward compatible with v1.0.0

New files:
- src/utils/path-utils.ts - Path normalization utilities
- src/utils/error-messages.ts - Enhanced error messages
- tests/__mocks__/obsidian.ts - Mock Obsidian API
- tests/path-utils.test.ts - 43 unit tests
- tests/README.md - Testing guide
- jest.config.js - Jest configuration
- docs/TOOL_SELECTION_GUIDE.md - Comprehensive tool guide
- docs/ERROR_MESSAGE_IMPROVEMENTS.md - Error message documentation
- docs/TOOL_DESCRIPTION_IMPROVEMENTS.md - AI agent improvements
- PHASE_1.1_IMPLEMENTATION.md - Implementation summary
- RELEASE_NOTES_v1.1.0.md - Release notes

Updated:
- CHANGELOG.md - Add v1.1.0 entry
- ROADMAP.md - Mark Phase 1.1 complete, add Phase 1.5 proposal
- manifest.json - Bump to v1.1.0
- package.json - Bump to v1.1.0, add test scripts
- src/tools/index.ts - Enhanced tool descriptions
- src/tools/note-tools.ts - Use PathUtils and ErrorMessages
- src/tools/vault-tools.ts - Use PathUtils and ErrorMessages
2025-10-16 21:27:23 -04:00