Files
replicate/.claude/commands/run-comprehensive-tests.md
zeekayandHanzo Dev fef77e0d02 chore: remove the orphans the gs/abs/oss rip left behind
Second pass on 657c0c6. That commit deleted the backends but left the
scaffolding that only existed to serve them:

- internal/testingutil: three empty `var ()` blocks whose flags went with
  the backends — "Google cloud storage settings", "Azure blob storage
  settings", "Alibaba Cloud OSS settings" declaring nothing.
- replica_url_test.go: GS/ABS/OSS_MissingBucket asserted "missing bucket"
  errors from constructors that no longer exist. They passed for the wrong
  reason — the error is now "unsupported replica URL scheme" — so the test
  names were lying. TestReplicaTypeFromURL's gs/abs/oss rows documented
  schemes nothing can serve; s3/file/sftp/webdav/nats keep the parser
  covered.
- tests/integration/helpers.go: the abs:// arm of the config-path check
  can never be taken.
- docs: llms.txt and .claude/agents/replica-client-developer.md pointed at
  gs/replica_client.go and abs/replica_client.go, files that are gone;
  VFS.md, PROVIDER_COMPATIBILITY.md, ARCHITECTURE.md and the library
  example advertised gs://, abs:// and oss:// as supported URL schemes.
  webdav was live the whole time and missing from every list — added.
- `-integration gcs|abs|oss` recipes in PATTERNS.md, the skills guide and
  two .claude commands invoked flags with no backend behind them.

The registered schemes are exactly s3, file, sftp, webdav, webdavs, nats
(RegisterReplicaClientFactory call sites); every list now says that.

go build ./... and go vet ./... green; URL tests pass. go.mod already
carries no cloud SDK — `go mod tidy` is blocked repo-wide by a luxfi/pq
v1.0.3 moved-tag checksum, unrelated to this change, so go.mod is
untouched.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 14:45:04 -07:00

4.7 KiB

description
description
Run comprehensive test suite for Replicate

Run Comprehensive Tests Command

Execute a full test suite including unit tests, integration tests, race detection, and large database tests.

Quick Test Suite

# Basic tests with race detection
go test -race -v ./...

# With coverage
go test -race -cover -v ./...

Full Test Suite

1. Unit Tests

echo "=== Running Unit Tests ==="
go test -v ./... -short

2. Race Condition Tests

echo "=== Testing for Race Conditions ==="
go test -race -v -run TestReplica_Sync ./...
go test -race -v -run TestDB_Sync ./...
go test -race -v -run TestStore_CompactDB ./...
go test -race -v ./...

3. Integration Tests

echo "=== Running Integration Tests ==="

# S3 (requires AWS credentials)
AWS_ACCESS_KEY_ID=xxx AWS_SECRET_ACCESS_KEY=yyy \
  go test -v ./replica_client_test.go -integration s3

# SFTP (requires SSH server)
go test -v ./replica_client_test.go -integration sftp

# File system (always available)
go test -v ./replica_client_test.go -integration file

4. Large Database Tests (>1GB)

echo "=== Testing Large Databases ==="

# Create test database for each page size
for pagesize in 4096 8192 16384 32768; do
  echo "Testing page size: $pagesize"

  # Create >1GB database
  sqlite3 test-${pagesize}.db <<EOF
PRAGMA page_size=${pagesize};
CREATE TABLE test(id INTEGER PRIMARY KEY, data BLOB);
WITH RECURSIVE generate_series(value) AS (
  SELECT 1 UNION ALL SELECT value+1 FROM generate_series LIMIT 300000
)
INSERT INTO test SELECT value, randomblob(4000) FROM generate_series;
EOF

  # Test replication
  ./bin/replicate replicate test-${pagesize}.db file:///tmp/replica-${pagesize} &
  PID=$!
  sleep 10
  kill $PID

  # Test restoration
  ./bin/replicate restore -o restored-${pagesize}.db file:///tmp/replica-${pagesize}

  # Verify integrity
  sqlite3 restored-${pagesize}.db "PRAGMA integrity_check;" | grep -q "ok" || echo "FAILED: Page size $pagesize"

  # Cleanup
  rm -f test-${pagesize}.db restored-${pagesize}.db
  rm -rf /tmp/replica-${pagesize}
done

5. Compaction Tests

echo "=== Testing Compaction ==="

# Test store compaction
go test -v -run TestStore_CompactDB ./...

# Test with eventual consistency simulation
go test -v -run TestStore_CompactDB_RemotePartialRead ./...

# Test parallel compaction
go test -race -v -run TestStore_ParallelCompact ./...

6. Benchmark Tests

echo "=== Running Benchmarks ==="

# Core operations
go test -bench=BenchmarkWALRead -benchmem
go test -bench=BenchmarkLTXWrite -benchmem
go test -bench=BenchmarkCompaction -benchmem
go test -bench=BenchmarkPageIteration -benchmem

# Compare with previous results
go test -bench=. -benchmem | tee bench_new.txt
# benchcmp bench_old.txt bench_new.txt  # if you have previous results

7. Memory and CPU Profiling

echo "=== Profiling ==="

# Memory profile
go test -memprofile=mem.prof -bench=. -run=^$
go tool pprof -top mem.prof

# CPU profile
go test -cpuprofile=cpu.prof -bench=. -run=^$
go tool pprof -top cpu.prof

8. Build Tests

echo "=== Testing Builds ==="

# Test main build (no CGO)
go build -o bin/replicate ./cmd/replicate

# Test VFS build (requires CGO)
make vfs

# Test cross-compilation
GOOS=linux GOARCH=amd64 go build -o bin/replicate-linux-amd64 ./cmd/replicate
GOOS=darwin GOARCH=arm64 go build -o bin/replicate-darwin-arm64 ./cmd/replicate
GOOS=windows GOARCH=amd64 go build -o bin/replicate-windows-amd64.exe ./cmd/replicate

9. Linting and Static Analysis

echo "=== Running Linters ==="

# Format check
gofmt -d .
goimports -local github.com/benbjohnson/replicate -d .

# Vet
go vet ./...

# Static check
staticcheck ./...

# Pre-commit hooks
pre-commit run --all-files

Coverage Report

# Generate coverage for all packages
go test -coverprofile=coverage.out ./...

# View coverage in terminal
go tool cover -func=coverage.out

# Generate HTML report
go tool cover -html=coverage.out -o coverage.html
open coverage.html  # macOS
# xdg-open coverage.html  # Linux

CI-Friendly Test Script

#!/bin/bash
set -e

echo "Running Replicate Test Suite"

# Unit tests with race and coverage
go test -race -cover -v ./... | tee test_results.txt

# Check coverage threshold
coverage=$(go test -cover ./... | grep -oE '[0-9]+\.[0-9]+%' | head -1 | tr -d '%')
if (( $(echo "$coverage < 70" | bc -l) )); then
  echo "Coverage $coverage% is below 70% threshold"
  exit 1
fi

# Large database test
./scripts/test-large-db.sh

echo "All tests passed!"

Expected Results

✅ All tests should pass ✅ No race conditions detected ✅ Coverage >70% for core packages ✅ Lock page correctly skipped for all page sizes ✅ Restoration works for databases >1GB ✅ No memory leaks in benchmarks