Files
turso/AGENTS.md
Pekka Enberg b596de0d9b testing: move .sqltest corpora to sqlite/conformance
Relocate the SQL conformance test corpora so testing/sqltests holds only
the test-runner crate: testing/sqltests/tests becomes
sqlite/conformance/sqlite-sqltests (SQLite-compatible coverage, also run
against real sqlite3) and testing/sqltests/turso-tests becomes
sqlite/conformance/turso-sqltests (Turso-specific behavior). The
Makefile and the database fixtures move along with them, so the suite
is now driven with make -C sqlite/conformance.

Keeping the fixtures next to the Makefile matters because .sqltest
files reference them with working-directory-relative paths like
database/integrity_*.db. The runner previously generated integrity
fixtures under its own CARGO_MANIFEST_DIR while backends opened them
relative to the working directory; generation now uses the working
directory too, so both sides agree regardless of where the corpora
live.

Tests: make -C sqlite/conformance check and run-rust (1438 passed),
cargo test -p core_tester test_drop_broken_legacy_view_row
2026-07-17 08:38:30 +03:00

6.8 KiB

Turso Agent Guidelines

SQLite rewrite in Rust. 40+ crate workspace.

Quick Reference

cargo build                    # build. never build with --release
cargo test                     # rust unit/integration tests
cargo fmt                      # format (required)
cargo clippy --workspace --all-features --all-targets -- --deny=warnings  # lint
cargo run -q --bin tursodb -- -q # run the interactive cli. never run with --release

make test                      # TCL compat + sqlite3 + extensions + MVCC
make test-single TEST=foo.test # single TCL test
make -C sqlite/conformance run-rust ARGS='--snapshot-filter __never__'  # sqltest runner (preferred for new tests)
CI=1 make -C sqlite/conformance run-rust  # use only if snapshot tests are required

scripts/diff.sh "SQL" [label]  # compare sqlite3 vs tursodb output

Testing

Running Tests

  • cargo test - Rust unit and integration tests
  • make test - broad compatibility suite (TCL, sqlite3, extensions, MVCC)
  • make test-single TEST=foo.test - single legacy TCL test
  • make -C sqlite/conformance run-rust ARGS='--snapshot-filter __never__' - preferred .sqltest runner for new coverage
  • CI=1 make -C sqlite/conformance run-rust - only when snapshot tests are required

Test Organization

Default: add coverage to the narrowest existing test harness that can express the bug. Prefer extending an existing test file or directory over creating a new one.

  • sqlite/conformance/sqlite-sqltests/ - preferred for SQL conformance coverage. These tests run the same scenario against both Turso and SQLite, so use them first for parser, planner, executor, and SQL semantics work that fits the .sqltest DSL.
  • tests/integration/ - primary fallback when the behavior cannot be expressed cleanly in .sqltest. Put API-level regressions, multi-connection orchestration, storage assertions, injected failures, timeout behavior, and other Rust-driven scenarios here.
  • sqlite/conformance/upstream/ - imported upstream SQLite golden tests. Do not modify these for Turso behavior changes; use them as fixed compatibility coverage, and only touch them for intentional upstream sync or harness maintenance.
  • testing/cli_tests/ - CLI-focused Python coverage for shell behavior and end-to-end command workflows.
  • tests/fuzz/ - minimized fuzz regressions and targeted edge cases that are easier to keep as Rust tests.
  • testing/simulator/ and testing/concurrent-simulator/ - deterministic concurrency, scheduling, and failure-injection coverage for state-machine and I/O correctness.
  • testing/differential-oracle/ and testing/stress/ - differential and long-running stress tooling. Use these for deeper investigation or specialized validation, not as the first stop for a focused regression test.

Structure

limbo/
├── core/           # Database engine (translate/, storage/, vdbe/, io/, mvcc/)
├── sqlite/
│   └── parser/     # SQL parser (lexer, AST, grammar)
├── cli/            # tursodb CLI (REPL, MCP server, sync server)
├── bindings/       # Python, JS, Java, .NET, Go, Rust
├── extensions/     # crypto, regexp, csv, fuzzy, ipaddr, percentile
├── testing/        # simulator/, concurrent-simulator/, differential-oracle/
├── sync/           # engine/, sdk-kit/ (Turso Cloud sync)
├── sdk-kit/        # High-level SDK abstraction
└── tools/          # dbhash utility

Where to Look

Task Location Notes
Query execution core/vdbe/execute.rs 12k LOC bytecode interpreter
SQL compilation core/translate/ AST → bytecode, optimizer in optimizer/
B-tree/pages core/storage/btree.rs 10k LOC, SQLite-compatible format
WAL/durability core/storage/wal.rs Write-ahead log, checkpointing
SQL parsing sqlite/parser/src/parser.rs 11k LOC recursive descent
Add extension extensions/core/ ExtensionApi, scalar/aggregate/vtab traits
Add binding bindings/ PyO3, NAPI, JNI, FRB, CGO patterns
Deterministic tests testing/simulator/ Fault injection, differential testing
New SQL tests sqlite/conformance/sqlite-sqltests/ .sqltest format preferred
Quick sqlite3 diff scripts/diff.sh Compare sqlite3 vs tursodb output for a query
MVCC testing REPL cli/mvcc_repl.rs Multi-conn concurrent txn testing REPL

Guides

Commit Messages

Use an optional component scope followed by a lowercase imperative summary with no trailing period:

[scope: ]<imperative summary>

<why the change is needed and what invariant or bug it addresses>

<non-obvious implementation details or tradeoffs, if needed>

Tests: <relevant validation, if useful>

Fixes #1234

For example: core/mvcc: preserve B-tree cleanup markers in commit logs. Explain intent rather than narrating the diff. Omit the body only when the subject fully explains a trivial change. Conventional Commit prefixes such as feat(scope): are not required. See CONTRIBUTING.md for a complete example.

Benchmark Naming

  • Criterion benchmark functions must use #[turso_macros::codspeed_criterion_benchmark] so stable and nightly CodSpeed runs get distinct benchmark names.
  • Divan benchmark functions must use #[turso_macros::divan_bench] for the same stable/nightly naming behavior.

Core Principles

  1. Correctness paramount. Production DB, not a toy. Crash > corrupt
  2. SQLite compatibility. Compare bytecode with EXPLAIN
  3. Every change needs a test. Must fail without change, pass with it
  4. Assert invariants. Don't silently fail. Don't hedge with if-statements
  5. Own your regressions. If tests fail after your change, they are your regressions. Debug them directly. Never stash/revert to "check if they fail on main" — that wastes time and is categorically banned.
  6. Validate your hypotheses.: If you suspect a given cause for a bug, validate it and provide incontrovertible evidence. NEVER make unearned assumptions.

CI Note

Running in GitHub Action? Max-turns limit in .github/workflows/claude.yml. OK to push WIP and continue in another action. Stay focused, avoid rabbit holes.