nixos/shared/linked-dotfiles/opencode/llmemory/docs/TDD_SETUP.md
2025-10-29 18:46:16 -06:00

3.1 KiB

TDD Testing Philosophy - Added to LLMemory

What Was Updated

1. Updated IMPLEMENTATION_PLAN.md

  • Rewrote testing strategy section with integration-first philosophy
  • Added TDD workflow to Steps 1.3 (Store) and 1.4 (Search)
  • Each step now has "write test first" as explicit requirement
  • Test code examples included before implementation examples

2. Updated AGENTS.md

  • ⚠️ File doesn't exist in opencode root, skipped
  • Created TESTING.md instead with full testing guide

3. Created docs/TESTING.md

  • Comprehensive testing philosophy document
  • TDD workflow with detailed examples
  • Integration-first approach explained
  • When to write unit tests (rarely!)
  • Realistic data seeding strategies
  • Watch-driven development workflow
  • Good vs bad test examples

4. Created test/integration.test.js

  • Test structure scaffolded with .todo() markers
  • Shows TDD structure before implementation
  • Database layer tests
  • Store command tests
  • Search command tests
  • Performance tests
  • Edge case tests

5. Simplified Dependencies

  • ⚠️ Removed better-sqlite3 temporarily (build issues on NixOS)
  • Installed: commander, chalk, date-fns, vitest
  • Tests run successfully (all .todo() so pass by default)

Current Status

Tests Setup: Complete

npm test          # Runs all tests (currently 0 real tests, 30+ .todo())
npm run test:watch  # Watch mode for TDD workflow

Next Steps (TDD Approach):

  1. Install better-sqlite3 (need native build tools)

    # On NixOS, may need: nix-shell -p gcc gnumake python3
    npm install better-sqlite3
    
  2. Write First Real Test (database schema)

    test('creates memories table with correct schema', () => {
      const db = new Database(':memory:');
      initSchema(db);
    
      const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all();
      expect(tables.map(t => t.name)).toContain('memories');
    });
    
  3. Watch Test Fail (npm run test:watch)

  4. Implement (src/db/schema.js)

  5. Watch Test Pass

  6. Move to Next Test

TDD Philosophy Summary

DO:

  • Write integration tests first
  • Use realistic data (50-100 memories)
  • Test with :memory: or temp file database
  • Run in watch mode
  • See test fail → implement → see test pass

DON'T:

  • Write unit tests for simple functions
  • Test implementation details
  • Use toy data (1-2 memories)
  • Mock the database (test the real thing)

Build Issue Note

better-sqlite3 requires native compilation. On NixOS:

# Option 1: Use nix-shell
nix-shell -p gcc gnumake python3
npm install better-sqlite3

# Option 2: Use in-memory mock for testing
# Implement with native SQLite later

This is documented in test/integration.test.js comments.

Next Session Reminder

Start with: /home/nate/nixos/shared/linked-dotfiles/opencode/llmemory/

  1. Fix better-sqlite3 installation
  2. Remove .todo() from first test
  3. Watch it fail
  4. Implement schema.js
  5. Watch it pass
  6. Continue with TDD approach

All tests are scaffolded and ready!