Skip to content

feat: add data integrity tests and persistence utilities (#96)#142

Open
dguido wants to merge 2 commits intomainfrom
issue-96-data-integrity-tests
Open

feat: add data integrity tests and persistence utilities (#96)#142
dguido wants to merge 2 commits intomainfrom
issue-96-data-integrity-tests

Conversation

@dguido
Copy link
Member

@dguido dguido commented Jan 22, 2026

Summary

  • Add 14 tests for 4 previously untested functions in types.ts: createPathOrganizer, createLocationEntry, getEntryIndexFromArray, isOldEntry
  • Create persistenceUtils.ts module with pure parsing/serialization functions for day logs and .weaudit files
  • Add 13 tests for persistence utilities covering parsing, serialization, and roundtrip validation
  • Refactor codeMarker.ts to use the new persistence utilities, improving testability

Test plan

  • All 149 tests pass (npm test)
  • Manual verification: Load extension in VS Code, create a finding, save, reload - data persists correctly
  • Manual verification: Check day log updates after marking files audited

🤖 Generated with Claude Code

Add comprehensive tests for previously untested type functions and extract
persistence logic into testable pure functions.

- Add 14 tests for createPathOrganizer, createLocationEntry, getEntryIndexFromArray, isOldEntry
- Create persistenceUtils.ts with parseDayLogJson, serializeDayLog, parseWeauditFile, serializeWeauditFile
- Add 13 tests for persistence utilities covering parsing, serialization, and roundtrips
- Refactor codeMarker.ts to use the new persistence utilities

Total: 149 passing tests (27 new)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extract pure functions from codeMarker.ts into testable utility modules:
- entryUtils.ts: entry CRUD operations (remove, add, restore)
- locationUtils.ts: location matching and filtering
- auditingUtils.ts: region overlap, merge, and split algorithms

Add 50 unit tests covering entry lifecycle, location management,
and file auditing functionality.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dguido
Copy link
Member Author

dguido commented Jan 22, 2026

Phase 2: Entry Lifecycle Tests

This PR now includes Phase 2 implementation adding 50 new unit tests for entry lifecycle operations.

New Utility Modules

Module Functions Tests
entryUtils.ts 6 6
locationUtils.ts 6 15
auditingUtils.ts 7 29

What was extracted

Entry CRUD (entryUtils.ts):

  • removeEntryFromArray() - Remove entry with result tracking
  • addToResolvedEntries() - Add to resolved with default details
  • restoreEntryFromResolved() - Move from resolved back to tree
  • getUniqueAuthors() - Get unique authors from entries
  • restoreAllEntries() - Bulk restore all resolved entries
  • deleteAllResolvedEntries() - Bulk delete all resolved

Location Management (locationUtils.ts):

  • locationMatches() - 4-property comparison (path, startLine, endLine, rootPath)
  • findLocationIndex() - Find location in array
  • removeLocationFromEntry() - Remove with cascade detection
  • filterEntriesByRootPath() - Filter by workspace root
  • filterEntriesByAuthor() - Filter by author
  • filterEntriesByAuthorAndRootPath() - Combined filter

Auditing (auditingUtils.ts):

  • regionsOverlapOrAdjacent() - Region overlap detection
  • mergeRegions() - Merge two overlapping regions
  • mergePartiallyAuditedRegions() - Merge all regions for a file
  • selectionContainedInRegion() - Check if selection is within region
  • splitRegionOnDeselect() - Split region when deselecting middle
  • adjustSelectionEndLine() - Handle empty line at cursor
  • adjustForEmptyLastLine() - Handle empty last line of file

codeMarker.ts updates

Refactored these methods to use the new utilities:

  • deleteAndResolveFinding()removeEntryFromArray(), addToResolvedEntries()
  • restoreFinding()restoreEntryFromResolved()
  • deleteResolvedFinding()removeEntryFromArray()
  • deleteAllResolvedFindings()deleteAllResolvedEntries()
  • restoreAllResolvedFindings()restoreAllEntries()
  • deleteLocation()removeLocationFromEntry()
  • getFilteredEntriesForSaving()filterEntriesByAuthorAndRootPath()
  • mergePartialAudits()mergePartiallyAuditedRegions()
  • addPartiallyAuditedFileFromEditor()selectionContainedInRegion(), splitRegionOnDeselect()

Test results

199 tests passing (149 existing + 50 new)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant