Files
replicate/.claude/commands/test-compaction.md
zeekay a485f34a14 rebrand: complete litestream -> replicate rename
- All source files, configs, docs, CI renamed
- Binary: replicate (not litestream)
- Config: replicate.yml (litestream.yml as fallback)
- Env: REPLICATE_* (LITESTREAM_* as fallback)
- Socket: /var/run/replicate.sock
- Image: ghcr.io/hanzoai/replicate
- Module: github.com/hanzoai/replicate
- Package name: replicate (Go), replicate-vfs (npm/pip/gem)
- VFS: registered as "replicate", pragmas replicate_*
- C exports: ReplicateVFSRegister, GoReplicate*
- Windows service: Replicate
- Systemd unit: replicate.service
- Upstream attribution preserved (README, upgrade test scripts)
2026-04-09 18:03:37 -07:00

1.7 KiB

Test Replicate compaction logic. This command helps test and debug compaction issues, especially with eventually consistent storage backends.

First, understand the test scenario:

  • What storage backend needs testing?
  • What size database is involved?
  • Are there eventual consistency concerns?

Then create comprehensive tests:

  1. Test basic compaction:
func TestCompaction_Basic(t *testing.T) {
    // Create multiple LTX files at level 0
    // Run compaction to level 1
    // Verify merged file is correct
}
  1. Test with eventual consistency:
func TestStore_CompactDB_RemotePartialRead(t *testing.T) {
    // Use mock client that returns partial data initially
    // Verify compaction prefers local files
    // Ensure no corruption occurs
}
  1. Test lock page handling during compaction:
func TestCompaction_LockPage(t *testing.T) {
    // Create database > 1GB
    // Compact with data around lock page
    // Verify lock page is skipped (page at 0x40000000)
}
  1. Test timestamp preservation:
func TestCompaction_PreserveTimestamps(t *testing.T) {
    // Compact files with different CreatedAt times
    // Verify earliest timestamp is preserved
}

Key areas to test:

  • Reading from local files first (db.go:1280-1294)
  • Skipping lock page at 1GB boundary
  • Preserving CreatedAt timestamps
  • Handling partial/incomplete remote files
  • Concurrent compaction safety

Run with race detector:

go test -race -v -run TestStore_CompactDB ./...

Use the test harness for large databases:

./bin/replicate-test populate -db test.db -target-size 1.5GB
./bin/replicate-test validate -source-db test.db -replica-url file:///tmp/replica