Scenarios are end-to-end tests for coherent slices of your warehouse. You define fixture inputs, SQLBuild builds the real project graph against them in isolated physical relations, and you assert that the result is correct.Documentation Index
Fetch the complete documentation index at: https://docs.sqlbuild.com/llms.txt
Use this file to discover all available pages before exploring further.
When to use scenarios vs unit tests
SQL unit tests compile to a single comparison query. They are fast, inline, and work well for checking individual model transformations. But when you need to test across many models with related entities - customers that have orders, orders that have payments, refunds that reference original orders - a single query can become unwieldy or hit SQL size limits. Scenarios materialize physical relations in the warehouse and build the actual model graph. This means:- Fixture inputs are real tables, not CTEs inside one query
- Models execute with real SQL, real materializations, and real dependency ordering
- You can test end-to-end business logic across an entire pipeline slice
- Debugging is easier because you can inspect intermediate tables with
--retain
Authoring scenarios
Scenario files live undertests/scenarios/ and use one file per scenario:
Scenario format
Each file has aSCENARIO() header followed by CTEs that define inputs, expected outputs, and assertions:
CTE conventions
| Prefix | Purpose |
|---|---|
__source__<name> | Fixture source input. Materializes as a scenario table. |
__ref__<model> | Fixture model boundary. Prevents SQLBuild from building that model upstream. |
__seed__<seed> | Fixture seed data. |
__expected__<model> | Full expected output. Compared order-insensitively against the scenario-built model. |
__assert__<name> | Zero-row assertion. Passes if the query returns no rows; fails with the returned rows as diagnostics. |
__source__raw__orders.
Every scenario must have at least one fixture CTE and at least one __expected__ or __assert__ CTE.
SCENARIO() header
The header is metadata only:| Field | Description |
|---|---|
description | Optional description string |
tags | Optional list of string tags |
How scenarios execute
Graph inference
SQLBuild infers which models to build from your scenario:- Target models come from
__expected__<model>CTE names and__ref(...)calls inside__assert__CTEs - SQLBuild walks upstream from targets, building every required model
__ref__<model>fixtures act as boundaries - upstream traversal stops there- All required sources must be provided by
__source__fixtures - Required project seeds are loaded automatically unless overridden by
__seed__fixtures
Isolation
Scenario artifacts are physically isolated from production:- Every scenario-owned relation uses a deterministic prefixed name (based on a hash of the project and scenario identity)
- All
ref(),source(), andseed()calls resolve to scenario-owned relations, never production tables - Fixture CTEs can read from existing warehouse relations if you choose, but downstream models always read the materialized scenario fixture, not the original
Execution flow
- Clean any existing scenario artifacts from a previous run
- Materialize source, ref, and seed fixtures as physical tables
- Load required project seeds
- Build required models in dependency order (incremental models run as full-refresh in scenarios)
- Run expected-output comparisons (order-insensitive)
- Run zero-row assertions
- Clean up all scenario-owned artifacts (unless
--retain)
Inspecting with —retain
When a scenario fails or you want to inspect intermediate state:target/run/scenarios/<scenario_name>/ regardless of --retain.
Local scenario testing
Scenarios can run locally against DuckDB using captured JSONL snapshots - no warehouse connection needed. This is useful for CI pipelines and fast developer iteration.Capture
First, capture scenario inputs from the real warehouse:- Materializes scenario input fixtures in the warehouse
- Runs a preflight
COUNT(*)on each fixture to check row counts against safety limits - Inspects column types and maps them to DuckDB-compatible types
- Downloads rows as JSONL files (enforcing byte limits during writing)
- Writes a
scenario.jsonmanifest with column metadata, types, row counts, and an input fingerprint - Cleans up warehouse artifacts
tests/_scenario_snapshots/<scenario_name>/ and can be committed to version control. JSONL is human-readable and git-diffable.
Capture safety limits
Capture enforces row and byte limits to prevent accidentally saving large datasets. Limits can be set insqlbuild_project.toml:
--force to bypass all limits:
--force.
Local replay
Run scenarios locally against DuckDB:- Checks snapshot freshness via the input fingerprint (missing/stale snapshots are skipped by default)
- Creates a temporary DuckDB database at
target/run/scenarios/<scenario_name>/local.duckdb - Loads JSONL snapshots into typed DuckDB tables using column metadata from
scenario.json - Transpiles model and check SQL from the project adapter dialect to DuckDB via SQLGlot
- Builds functions, models, and runs expected/assertion checks in DuckDB
- Keeps the local DuckDB file for inspection (it lives under
target/, so it’s always retained)
Sync snapshots
Instead of running capture and test separately, sync snapshots in one command:--sync-snapshots, fresh snapshots are reused. With --refresh, all selected snapshots are recaptured even if fresh.
Strict mode
By default, missing or stale snapshots are skipped with a warning. Use--strict to treat them as errors:
Local type overrides
When SQLGlot’s automatic warehouse-to-DuckDB type conversion produces an incompatible type, you can override it insqlbuild_project.toml:
{1}, {2}, etc:
scenario.json during capture and used when loading snapshots into DuckDB.
Cleanup
By default, remote scenario artifacts are dropped after each run (pass or fail). The janitor command also recognizes scenario artifacts and can clean retained or orphaned scenario relations:Limitations
- Custom materializations are not supported in scenarios yet. Scenario models using custom materializations will fail with a clear error.
- Local replay transpiles SQL from the project adapter dialect to DuckDB via SQLGlot. Adapter-specific SQL that SQLGlot cannot translate will produce a clear error with the failing resource name and reason.

