Compatibility Testing Strategy
This document sketches the guard-rails we need while the PostgreSQL compatibility layer comes online. It complements ./roadmap by describing concrete test suites and the automation required to keep us close to upstream behaviour.
Guiding Principles
- Confidence through layers – run fast unit suites on every change, replay realistic SQL traces in CI, and bootstrap heavy regression runs nightly.
- Golden results – anything we emulate from PostgreSQL must be exercised against a real Postgres reference and compared for both results and SQLSTATE/diagnostics.
- Observability baked in – every suite should emit per-query metadata. Tests must assert that
compat/statscounters change as expected and capturecompat/logoutput (or archived JSONL) for post-mortem analysis.
Test Layers
1. Translator Unit Tests (zig test)
- Cover SQL→sydraQL transformation rules directly.
- One fixture per SQL construct (DDL, DML, aggregates, JSONB ops, arrays, etc.).
- Assert the generated sydraQL AST, SQLSTATE metadata when a rule falls back, and the stats/logging side effects (
translations,fallbacks, cache hits when fixtures opt in). - Status: scaffolding landed (
compat/fixtures/translator.zig,tests/translator/cases.jsonl, andquery/translator.zigdriving the fixtures). - Runs automatically via
zig build test.
2. Protocol Wire Tests
- Stand up the PG wire front-end inside a test harness.
- Use synthetic libpq/psql scripts to exercise startup, auth, simple + extended queries, COPY, transactions.
- Assert network-level behaviour (messages, SQLSTATE, parameter status) and verify structured logs capture handshake + query events.
- Execute inside CI using a dedicated
zig build compat-wire-teststep.
3. Trace Replay Harness
- Capture real SQL traffic by proxying a Postgres database during sample application runs (Django, Rails, Prisma, etc.).
- Store anonymised traces in
tests/traces/<app>/trace.jsonlwith metadata (session, parameters, expected results). - Provide a replay tool (
zig build compat-replay --trace tests/traces/...) that feeds the translator and compares results against a local Postgres instance. - Failures should emit diff files with SQLSTATE, payload, execution stats, and include the relevant JSONL log excerpt for debugging.
4. ORM Smoke Suites
- Provision containerised sample apps (Django polls, Rails blog, Prisma todo, SQLAlchemy models).
- Each suite starts the sydra PG endpoint, runs the ORM migrations/tests, and records metrics.
- Capture translator logs + stats snapshots at suite start/end to quantify coverage.
- Managed via Nix flake outputs for reproducibility; triggered nightly and on release branches.
5. Postgres Regression Subset
- Vendor the relevant SQL files from the upstream PG regression suite (
src/test/regress/sql/*.sql). - Execute them through the translator, comparing outputs to a real Postgres run.
- Maintain a skiplist for features we intentionally do not support yet; log changes to keep the matrix updated.
6. Performance Budgets
- pgbench-style workloads (CRUD, COPY bulk load, analytics queries) executed against both sydra and Postgres.
- Capture latency/QPS metrics; fail CI if we regress relative to the baseline by more than a threshold.
- Export results to
./compat-matrix-v0.1(or a future replacement) for transparency.
Tooling & Infrastructure Checklist
tests/README.mddescribing how to run each suite locally.- CLI to record/replay SQL traces (writes JSONL, redacts literals by default).
- Golden-result storage for translator unit tests (JSON fixtures) to simplify review.
- Utility to diff SQLSTATE/error payloads (
compat/sqlstateprovides mapping glue). - Metrics sink (
compat/stats+/debug/compat/stats) must be reset between suites to avoid crosstalk.
Schedule & Ownership
| Milestone | Deliverable | Notes |
|---|---|---|
| M1 | Translator unit suite + golden fixtures | Blocks translator development |
| M2 | Wire protocol harness | Needs PG client libs in CI |
| M3 | Trace replay tooling | Requires anonymisation rules |
| M4 | ORM smoke tests | Use docker-compose or Nix shells |
| M5 | Regression subset integration | Start with parser/aggregates JSON suites |
| M6 | Performance budgets | Reuse loadgen tooling |
Immediate Next Steps
- Scaffold
tests/README.mdwith instructions for running translator and wire tests. - Build the translator unit test harness alongside the upcoming SQL parser work.
- Prototype the trace recorder against a staging Postgres instance to validate data format.
- Add CI jobs for
zig build test(fast) andzig build compat-wire-test(medium) to gate PRs.
Feedback welcome; we will evolve this doc as the compatibility layer matures.