gmickel / CodeWhisper

CodeWhisper: AI-Powered End-to-End Task Implementation & blazingly fast Codebase-to-LLM Context Bridge
https://discord.com/invite/82mjJkwABQ
MIT License
54 stars 4 forks source link

feat(cache): add FileCache tests and fix Date serialization #12

Closed gmickel closed 3 months ago

gmickel commented 3 months ago

FileCache Tests and Date Serialization Fix

Problem

  1. The FileCache class lacked comprehensive unit tests, making it difficult to verify its behavior and catch potential regressions.
  2. Date objects were not being properly handled during serialization and deserialization in the FileCache, causing inconsistencies between original and cached FileInfo objects.

Solution

This PR addresses both issues:

  1. Comprehensive Unit Tests:

    • Implemented a new test file tests/unit/file-cache.test.ts
    • Added tests covering key FileCache functionalities including:
      • Storing and retrieving file information
      • Handling non-existent files
      • Updating cache when file content changes
      • Persisting cache to disk and loading it
      • Clearing the cache
  2. Date Serialization Fix:

    • Implemented custom JSON parsing and stringifying methods in FileCache to ensure proper handling of Date objects:
      • In loadCache: Added a custom reviver function to JSON.parse to convert ISO date strings back into Date objects
      • In saveCache: Added a custom replacer function to JSON.stringify to convert Date objects to ISO string format

Changes

Testing

The new test suite in file-cache.test.ts covers the core functionality of FileCache, including the proper handling of Date objects. These tests ensure that: