Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
e1963a3
tests: Consolidate and simplify Elixir tests
ocean Jan 8, 2026
08a9fcc
Add transaction rollback test to smoke tests
ocean Jan 8, 2026
cd0209f
Add concurrent prepared statement tests
ocean Jan 8, 2026
737517d
chore: Beads and bv related updates
ocean Jan 8, 2026
5b6afe8
chore: Create beads issues for missing test coverage from TEST_AUDIT_…
ocean Jan 8, 2026
39bab71
feat: add focused tests for savepoint+replication and connection pool…
ocean Jan 8, 2026
4abae3a
chore: update beads state after closing el-crt and el-fd8
ocean Jan 8, 2026
4d8b93d
tests: Consolidate tests but add a few more
ocean Jan 9, 2026
efbeacb
test: add on_exit cleanup hook to cursor_streaming_large_test setup a…
ocean Jan 9, 2026
e8b761a
test: add on_exit disconnect to json_helpers_test setup to avoid conn…
ocean Jan 9, 2026
c716c46
test: relax JSONB size assertion to avoid cross-version flakiness
ocean Jan 9, 2026
041c92d
chore: remove TEST*.md files from tracking and add to gitignore
ocean Jan 9, 2026
ab729d1
fix: use inline format arguments in error handling test
ocean Jan 9, 2026
ca2eebd
test: improve cursor_streaming_large_test assertions and reduce dupli…
ocean Jan 9, 2026
af0b0d7
docs: enhance formatting check guidance in CLAUDE.md
ocean Jan 9, 2026
a8c452a
style: use British English spelling in error_handling_tests.rs
ocean Jan 9, 2026
37bed26
Fix: Improve test robustness and file cleanup
ocean Jan 9, 2026
6fbc3d3
Perf: Optimize test helpers in cursor_streaming_large_test
ocean Jan 9, 2026
fecd161
refactor: RAII guard for reliable SQLite file cleanup in error_handli…
ocean Jan 9, 2026
75ccae9
refactor: Apply TestDbGuard pattern to all Rust test files
ocean Jan 9, 2026
8dd0080
docs: add TestDbGuard RAII implementation verification
ocean Jan 9, 2026
69e259b
tests: Update all tests to use new DB cleanup helper function
ocean Jan 9, 2026
b802b68
tests: Fix more test issues
ocean Jan 9, 2026
6ce4e0a
test: improve error handling in pool_load_test concurrent transaction…
ocean Jan 9, 2026
7e45ec0
test: ensure consistent task result verification across all pool load…
ocean Jan 9, 2026
6aa1371
Optimize test cleanup and accumulator patterns
ocean Jan 9, 2026
e8a5ee6
Standardize variable naming in smoke_test.exs for clarity
ocean Jan 9, 2026
44efc6e
Extract shared test utilities to reduce duplication
ocean Jan 9, 2026
f0ce721
Document test state variable naming conventions
ocean Jan 9, 2026
57ff1f7
Add comprehensive edge-case testing to pool load tests
ocean Jan 9, 2026
f46616a
Add session summary: test conventions and edge-case coverage improvem…
ocean Jan 9, 2026
77e9ef3
Fix Elixir and Rust formatting issues
ocean Jan 9, 2026
00df0d8
Add formatting verification report - all checks pass
ocean Jan 9, 2026
7d1293e
Add edge-case testing for error recovery and resource cleanup
ocean Jan 10, 2026
d03d118
Add Unicode data testing for concurrent connections
ocean Jan 10, 2026
42fd1b1
Add comprehensive session enhancement summary
ocean Jan 10, 2026
6d36431
Add edge case and error handling tests for cursors and pool load
ocean Jan 10, 2026
0fdd088
Add remote table teardown in savepoint_replication_test cleanup
ocean Jan 10, 2026
fbabe9b
docs: Remove unneeded test documents
ocean Jan 10, 2026
9d6ea63
Fix prepared statement leak in edge-case test
ocean Jan 10, 2026
6444c28
Fix prepared statement leak in concurrent load cleanup test
ocean Jan 10, 2026
9973a78
Fix British spelling and tuple patterns in test files
ocean Jan 10, 2026
74cd02f
Improve pool_load_test.exs: Unicode verification and state threading
ocean Jan 10, 2026
855ef7d
Improve savepoint_replication_test.exs
ocean Jan 10, 2026
7c27e64
Merge branch 'main' into consolidate-tests
ocean Jan 11, 2026
cbffa16
Improve test helper efficiency and robustness
ocean Jan 11, 2026
34938b9
Improve test robustness and error handling
ocean Jan 11, 2026
bebf3fe
Fix test helper issues causing test failures
ocean Jan 11, 2026
fe8c959
chore: standardize skipped test tags and enable concurrent test
ocean Jan 11, 2026
4f61f06
fix: improve pool_load_test.exs robustness
ocean Jan 11, 2026
c65eacb
Refactor test error handling: fix blanket rescues and state threading
ocean Jan 11, 2026
0304ed0
Fix pattern matching in error handling clause
ocean Jan 12, 2026
45f06bc
Format: fix indentation in pool_load_test.exs
ocean Jan 12, 2026
e7683a3
fix: improve pool_load_test.exs reliability and correctness
ocean Jan 12, 2026
532699e
fix: improve pool load test robustness and error handling
ocean Jan 12, 2026
825d1e2
fix: ensure isolated test data by clearing tables before assertions
ocean Jan 12, 2026
c80bf1c
refactor: remove redundant alias EctoLibSql
ocean Jan 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .beads/last-touched
Original file line number Diff line number Diff line change
@@ -1 +1 @@
el-ffc
el-6r5
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ z_ecto_libsql_test*

# Local environment variables.
.env.local

# bv (beads viewer) local config and caches
.bv/
TEST_AUDIT_REPORT.md
TEST_COVERAGE_ISSUES_CREATED.md
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ settings = ~s({"theme":"dark","notifications":true,"language":"es"})

#### Comparison: Set vs Replace vs Insert vs Patch

The modification functions have different behaviors:
The modification functions have different behaviours:

```elixir
json = ~s({"a":1,"b":2})
Expand Down
77 changes: 71 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
## Quick Rules

- **British/Australian English** for all code, comments, and documentation (except SQL keywords and compatibility requirements)
- **ALWAYS format before committing**: `mix format --check-formatted` and `cargo fmt`
- **⚠️ CRITICAL: ALWAYS check formatting BEFORE committing**:
1. Run formatters: `mix format && cd native/ecto_libsql && cargo fmt`
2. Verify checks pass: `mix format --check-formatted && cargo fmt --check`
3. **Only then** commit: `git commit -m "..."`
- Formatting issues caught at check time, not after commit
- **NEVER use `.unwrap()` in production Rust code** - use `safe_lock` helpers (see [Error Handling](#error-handling-patterns))
- **Tests MAY use `.unwrap()`** for simplicity

Expand Down Expand Up @@ -46,6 +50,7 @@
- [Architecture](#architecture)
- [Code Structure](#code-structure)
- [Development Workflow](#development-workflow)
- [Issue Tracking with Beads](#issue-tracking-with-beads)
- [Error Handling Patterns](#error-handling-patterns)
- [Testing](#testing)
- [Common Tasks](#common-tasks)
Expand Down Expand Up @@ -258,7 +263,7 @@ This project uses **Beads** (`bd` command) for issue tracking across sessions. B
- **Beads**: Multi-session work, dependencies between tasks, discovered work that needs tracking
- **TodoWrite**: Simple single-session task execution

When in doubt, prefer Beadspersistence you don't need beats lost context.
When in doubt, prefer Beadspersistence you don't need beats lost context.

**Essential commands:**
```bash
Expand Down Expand Up @@ -294,6 +299,14 @@ bd sync --from-main # Pull latest beads
git add . && git commit -m "..." # Commit changes
```

#### Best Practices

- Check `bd ready` at session start to find available work
- Update status as you work (in_progress → closed)
- Create new issues with `bd create` when you discover tasks
- Use descriptive titles and set appropriate priority/type
- Always `bd sync` before ending session

### Adding a New NIF Function

**IMPORTANT**: Modern Rustler auto-detects all `#[rustler::nif]` functions. No manual registration needed.
Expand Down Expand Up @@ -455,6 +468,45 @@ mix test --exclude turso_remote # Skip Turso tests
- Type conversions (Elixir ↔ SQLite)
- Concurrent operations

### Test Variable Naming Conventions

For state threading in tests, use consistent variable names and patterns:

**Variable Naming by Scope**:
```elixir
state # Connection scope
trx_state # Transaction scope
cursor # Cursor scope
stmt_id # Prepared statement ID scope
```

**Error Handling Pattern**:

When an error operation returns updated state, you must decide if that state is needed next:

```elixir
# ✅ If state IS needed for subsequent operations → Rebind
result = EctoLibSql.handle_execute(sql, params, [], trx_state)
assert {:error, _reason, trx_state} = result # Rebind - reuse updated state
:ok = EctoLibSql.Native.rollback_to_savepoint_by_name(trx_state, "sp1")

# ✅ If state is NOT needed → Discard with underscore
result = EctoLibSql.handle_execute(sql, params, [], trx_state)
assert {:error, _reason, _state} = result # Discard - not reused
:ok = EctoLibSql.Native.rollback_to_savepoint_by_name(trx_state, "sp1")

# ✅ For terminal operations → Use underscore variable name
assert {:error, %EctoLibSql.Error{}, _conn} = EctoLibSql.handle_execute(...)
```

**Add clarifying comments** when rebinding state:
```elixir
# Rebind trx_state - error tuple contains updated transaction state needed for recovery
assert {:error, _reason, trx_state} = result
```

See [TEST_STATE_VARIABLE_CONVENTIONS.md](TEST_STATE_VARIABLE_CONVENTIONS.md) for detailed guidance.

### Turso Remote Tests

⚠️ **Cost Warning**: Creates real cloud databases. Only run when developing remote/replica functionality.
Expand Down Expand Up @@ -549,14 +601,27 @@ for i in {1..10}; do mix test test/file.exs:42; done # Race conditions

### Pre-Commit Checklist

**STRICT ORDER (do NOT skip steps or reorder)**:

```bash
mix format && cd native/ecto_libsql && cargo fmt # Format
mix test && cd native/ecto_libsql && cargo test # Test
mix format --check-formatted # Verify format
cd native/ecto_libsql && cargo clippy # Lint (optional)
# 1. Format code (must come FIRST)
mix format && cd native/ecto_libsql && cargo fmt

# 2. Run tests (catch logic errors)
mix test && cd native/ecto_libsql && cargo test

# 3. Verify formatting checks (MUST PASS before commit)
mix format --check-formatted && cd native/ecto_libsql && cargo fmt --check

# 4. Lint checks (optional but recommended)
cd native/ecto_libsql && cargo clippy

# 5. Only commit if all checks above passed
git commit -m "feat: descriptive message"
```

**⚠️ Critical**: If ANY check fails, fix it and re-run that check before proceeding. Never commit with failing checks.

### Release Process

1. Update version in `mix.exs`
Expand Down
71 changes: 71 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,77 @@ jobs:
- Use unique IDs/names (UUIDs)
- Clean up properly between tests

### Edge-Case Testing Guide

EctoLibSql includes comprehensive edge-case testing under concurrent load. These tests verify that the library handles unusual data correctly even when multiple processes are accessing the database simultaneously.

#### What Edge-Cases Are Tested

The test suite covers:

1. **NULL Values**: Ensure NULL is properly handled in concurrent inserts and transactions
2. **Empty Strings**: Verify empty strings aren't converted to NULL or corrupted
3. **Large Strings**: Test 1KB strings under concurrent load for truncation or corruption
4. **Special Characters**: Verify parameterised queries safely handle special characters (`!@#$%^&*()`)
5. **Recovery After Errors**: Confirm connection recovers after query errors without losing edge-case data
6. **Resource Cleanup**: Verify prepared statements with edge-case data are cleaned up correctly

#### Test Locations

- **Pool Load Tests**: `test/pool_load_test.exs`
- `test "concurrent connections with edge-case data"` - 5 concurrent connections, 5 edge-case values each
- `test "connection recovery with edge-case data"` - Error handling with NULL/empty/large strings
- `test "prepared statements with edge-case data"` - Statement cleanup under concurrent load with edge cases

- **Transaction Isolation Tests**: `test/pool_load_test.exs`
- `test "concurrent transactions with edge-case data maintain isolation"` - 4 transactions, edge-case values

#### Helper Functions

The test suite provides reusable helpers for edge-case testing:

```elixir
# Generate edge-case values for testing
defp generate_edge_case_values(task_num) do
[
"normal_value_#{task_num}", # Normal string
nil, # NULL value
"", # Empty string
String.duplicate("x", 1000), # Large string (1KB)
"special_chars_!@#$%^&*()_+-=[]{};" # Special characters
]
end

# Insert edge-case value and return result
defp insert_edge_case_value(state, value) do
EctoLibSql.handle_execute(
"INSERT INTO test_data (value) VALUES (?)",
[value],
[],
state
)
end
```

#### When to Use Edge-Case Tests

Add edge-case tests when:
- Testing concurrent operations
- Adding support for new data types
- Changing query execution paths
- Modifying transaction handling
- Improving connection pooling

#### Expected Coverage

Edge-case tests should verify:
- Data integrity (no corruption, truncation, or loss)
- NULL value preservation
- String encoding correctness
- Parameter binding safety
- Error recovery without data loss
- Resource cleanup (statements, cursors, connections)

### Known Test Limitations

1. **Remote/Replica Mode Testing:**
Expand Down
Loading