Unit
Unit
The unit command runs unit tests on Trilogy scripts with mocked datasources. It always uses DuckDB internally.
Usage
trilogy unit <input> [options]
Arguments
| Argument | Description |
|---|---|
input | Path to a Trilogy script or directory. |
Options
| Option | Description |
|---|---|
--param key=value | Environment parameters. Repeatable. |
-p, --parallelism INTEGER | Maximum parallel workers for directory execution. |
--config PATH | Path to a trilogy.toml configuration file. |
-e, --env TEXT | Set env vars as KEY=VALUE, or pass an env file path. |
--skip-type [datasources/concepts/agent] | Skip a test type. Repeatable. |
--include-type [datasources/concepts/agent] | Include a test type beyond the defaults. Agent checks are opt-in. Repeatable. |
--report, --no-report | Enable/disable agent validation reports under .trilogy/validate_runs/; enabled by default. |
Full Examples
# Test single file
trilogy unit test_query.preql
# Test entire directory
trilogy unit tests/ -p 4
# Test with parameters
trilogy unit script.preql --param batch_size=100
# Test with config file
trilogy unit . --config trilogy.toml
What It Does
- Parses the script(s)
- Validates datasources with mocked data (no real database connection needed)
- Reports validation results and any errors
Notes
- No dialect argument needed - always uses DuckDB
- No connection arguments needed - all datasources are mocked
- Fast feedback loop for development and CI/CD
- Exercises model structure and syntax without requiring warehouse access
- Generated range, enum, and supported regex values respect their declared domains; unsupported regex constructs such as lookaround and backreferences raise an error
- Use integration validation and explicit fixtures to verify production data quality and business expectations
Datasource and concept checks run by default. --include-type agent also runs embedded validate ... matches questions against the mock data, using the configured agent provider and its tokens.