Repository navigation
fix(test): run model SQL in SQL tests exactly as build sends it - #893
Merged
Merged
Conversation
Split a model's leading WITH into authored CTE and body slices and lift them verbatim instead of parsing, renaming every CTE and regenerating SQL. A CTE name already lifted with different text keeps the existing nested fallback; on T-SQL, which rejects nested WITH, the test is refused with a diagnostic naming the colliding CTEs.
Rendered SQL-test queries now keep the authored function spelling, so the regex that rewrote STARTS_WITH back to STARTSWITH is no longer needed.
Check that rendered SQL tests contain each model's build SQL verbatim, apart from fixture relation substitution, keep Snowflake function synonyms as authored, refuse T-SQL CTE collisions, and run authored CTEs with comments, dollar quotes and nested WITH through the DuckDB CLI.
On T-SQL, rename a CTE whose name collides with an already lifted CTE, together with its relation references, by token span to a fresh name when every other token is provably unchanged; refuse otherwise. Drop trailing statement terminators from lifted bodies, compare lifted CTE text ignoring surrounding whitespace, and name upstream models in collision messages.
A CTE name followed by a dot in a relation position is the leading part of a database or schema qualified object, so it is kept rather than renamed. A column qualifier beside such an object is ambiguous and the rename is refused.
kvlonge
enabled auto-merge (squash)
October 1, 2026 09:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
sqb testdid not run the SQL thatbuildsends. For model bodies starting withWITH, the test renderer parsed the SQL, renamed every CTE and regenerated it with the SQL library, then patched known spelling changes (SnowflakeSTARTS_WITHback toSTARTSWITH) with a regex. Tests could pass on SQL the warehouse never runs (CHI-452, split from CHI-402).Changes
WITH): a colliding CTE is renamed by token span only when provably safe (definition, relation references, column qualifiers), verified against the rest of the token stream; otherwise, and for fixture-vs-model collisions, the test is refused with an error naming both CTEs.STARTS_WITHpatch andsql_test_dialect.pyare removed.Verification
sqb test.make test,make check-ci; one independent review plus a follow-up.