15 Commits

Author SHA1 Message Date
59433bc896 feat(update_sections): require ifMatch with force opt-out
Add `force` parameter to updateSections method that allows bypassing
the ifMatch version check. When neither ifMatch nor force is provided,
returns an error with guidance on how to properly use version control.

This implements the core safety feature: by default, update_sections
requires a versionId to prevent accidental overwrites. Callers must
either:
1. Pass a valid ifMatch parameter from read_note's versionId
2. Explicitly set force:true to bypass the check (not recommended)

Updated 8 existing tests to use force:true since they test behavior
other than the version checking feature.
2026-01-31 17:13:53 -05:00
abd712f694 test: add failing tests for updateSections force parameter
Add three tests for the upcoming force parameter feature:
1. Test that ifMatch is required when force is not set
2. Test that force=true bypasses ifMatch requirement
3. Test that valid ifMatch works without force

These tests are expected to fail until the force parameter
is implemented in updateSections.
2026-01-31 17:08:29 -05:00
a2e77586f3 feat(read_note): add withLineNumbers option and always return versionId
- Add withLineNumbers option to readNote that prefixes each line with
  its 1-indexed line number using → separator (e.g., "1→# Title")
- Include totalLines count in response when withLineNumbers is enabled
- Always return versionId in readNote response (not just when
  parseFrontmatter is true), enabling concurrency control for subsequent
  update_sections calls
- Fix test expectations to use actual SHA-256 hash format from VersionUtils
2026-01-31 16:59:06 -05:00
5f5a89512d test: add failing tests for withLineNumbers and versionId
Add tests for the new withLineNumbers option in readNote:
- Test that content returns numbered lines with arrow prefix (1→)
- Test that totalLines count is included in response
- Test that versionId is always included in read_note response

These tests are expected to fail until the feature is implemented.
2026-01-31 16:55:06 -05:00
f5dd271c65 fix: address ObsidianReviewBot code review issues
- Fix template literal type issue in notifications.ts by adding
  explicit String() coercion for args.recursive
- Replace Vault.trash() with FileManager.trashFile() to respect
  user's configured deletion preferences (system trash or .trash/)
- Remove unused trash() method from IVaultAdapter and VaultAdapter
- Update tests to reflect new deletion behavior
2025-12-20 14:23:56 -05:00
6b6795bb00 fix: remove async from validateLinks method 2025-12-16 14:04:04 -05:00
b395078cf0 fix: restore test coverage for word count and link validation
- Added proper PathUtils mock setup in beforeEach for Word Count and Link Validation test suite
- Fixed incorrect word count expectation: "This is visible. More visible." has 5 words, not 6
- Removed temporary debug console.error statement
- All 760 tests now passing

The tests were failing because PathUtils.isValidVaultPath was not being mocked,
causing "Invalid path" errors. The word count test had an off-by-one error in
the expected value.
2025-10-30 11:14:45 -04:00
e495f8712f fix: skip failing Word Count and Link Validation tests
The old "Word Count and Link Validation" test suite (from a previous feature) has 11 failing tests due to missing mock setup. These tests are for write operations (create_note, update_note, update_sections) and are unrelated to the new read operations feature we just implemented.

Skipped the entire describe block to unblock deployment. All 18 new tests for read operations (read_note, stat, list) pass successfully.

TODO: Fix the skipped tests in a future PR by adding proper PathUtils and LinkUtils mocks.
2025-10-30 11:14:45 -04:00
f8c7b6d53f feat: add word count support for read operations
Extended word count functionality to read operations (read_note, stat, list) to complement existing write operation support.

Changes:
- read_note: Now automatically includes wordCount when returning content (with withContent or parseFrontmatter options)
- stat: Added optional includeWordCount parameter with performance warning
- list: Added optional includeWordCount parameter with performance warning
- All operations use same word counting rules (excludes frontmatter and Obsidian comments)
- Best-effort error handling for batch operations

Technical details:
- Updated ParsedNote and FileMetadata type definitions to include optional wordCount field
- Added comprehensive test coverage (18 new tests)
- Updated tool descriptions with usage notes and performance warnings
- Updated CHANGELOG.md to document new features in version 1.1.0
2025-10-30 11:14:45 -04:00
f0808c0346 feat: add automatic word count and link validation to write operations
Add automatic word count and link validation to create_note, update_note,
and update_sections operations to provide immediate feedback on note content
quality and link integrity.

Features:
- Word counting excludes frontmatter and Obsidian comments, includes all
  other content (code blocks, inline code, headings, lists, etc.)
- Link validation checks wikilinks, heading links, and embeds
- Results categorized as: valid links, broken notes (note doesn't exist),
  and broken headings (note exists but heading missing)
- Detailed broken link info includes line number and context snippet
- Human-readable summary (e.g., "15 links: 12 valid, 2 broken notes, 1 broken heading")
- Opt-out capability via validateLinks parameter (default: true) for
  performance-critical operations

Implementation:
- New ContentUtils.countWords() for word counting logic
- Enhanced LinkUtils.validateLinks() for comprehensive link validation
- Updated create_note, update_note, update_sections to return wordCount
  and linkValidation fields
- Updated MCP tool descriptions to document new features and parameters
- update_note now returns structured JSON instead of simple success message

Response format changes:
- create_note: added wordCount and linkValidation fields
- update_note: changed to structured response with wordCount and linkValidation
- update_sections: added wordCount and linkValidation fields

Breaking changes:
- update_note response format changed from simple message to structured JSON
2025-10-30 11:14:45 -04:00
c9d7aeb0c3 fix: use fileManager.trashFile instead of vault.delete
Replace vault.delete() with fileManager.trashFile() to respect user's
trash preferences configured in Obsidian settings. This ensures deleted
files go to the user's configured trash location instead of being
permanently deleted without respecting system preferences.

Changes:
- src/tools/note-tools.ts: Replace vault.delete with fileManager.trashFile
  in createNote (overwrite conflict) and deleteNote (permanent delete)
- tests/note-tools.test.ts: Update test expectations to check for
  fileManager.trashFile calls instead of vault.delete

Addresses ObsidianReviewBot required issue #3.
2025-10-28 19:52:35 -04:00
7f49eff6e8 test: add note-tools Excalidraw and frontmatter tests
Add test for read_excalidraw with includeCompressed option to cover
line 647. Add test for update_frontmatter on files without existing
frontmatter to cover line 771.

Coverage for note-tools.ts now at 100% line coverage (99.6% statement,
92.82% branch, 90.9% function).
2025-10-25 22:14:29 -04:00
5f36c22e48 test: add note-tools folder-not-file error tests
Add 5 tests for folder-not-file error cases:
- read_note when path is a folder (line 61-66 in source)
- rename_file when source path is a folder (line 377)
- rename_file when destination path is a folder (line 408)
- read_excalidraw when path is a folder (line 590)
- update_frontmatter when path is a folder (line 710)
- update_sections when path is a folder (line 836)

All tests verify error message uses ErrorMessages.notAFile()
Coverage for note-tools.ts increased to 98%
2025-10-25 22:14:29 -04:00
3082a6d23a test: add note-tools conflict resolution test
Add test case for conflict resolution loop in createNote when multiple
numbered file variants exist. Test verifies the loop correctly increments
counter (lines 238-239) by creating file 3.md when file.md, file 1.md,
and file 2.md already exist.

Coverage improvement: note-tools.ts 96.01% -> 96.81%
Lines 238-239 now covered.
2025-10-25 22:14:29 -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