Repository navigation
fix(test): rewrite references in helper CTEs and order them after their dependencies - #1019
Merged
Merged
Conversation
…ir dependencies Helper CTEs in SQL tests now resolve __ref(), __source(), __seed() and the other reference calls exactly like __assert__ CTEs, are emitted after the mocks and models they read, and count their unmocked __ref() targets when selecting the test. Helper references compile cannot resolve (unknown models, cycles, and mocks or fixtures reading a referencing helper) fail at compile with P013.
Resolve, check and count references only in helpers reachable from the test's expected rows and assertions, so unread helpers and mocks behave as before. Inlined helpers now resolve in expected rows too, relations resolved helpers read win over a step's own copy so assertions and helpers share one mock CTE, nested CTEs shadowing a helper keep the existing redefinition error, and the mock check only covers mocks and fixtures the test uses.
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
In a SQL unit test, a helper CTE that called
__ref("model")was emitted with the call left unresolved and placed before the mock and model CTEs, sosqb compilepassed butsqb testfailed in the database. When only a helper referenced a model, the test was silently skipped (0 selected).Changes
__expected__/__assert__CTEs, through helpers and mocks, respecting nested CTE scope) count; unread helpers behave as on main.__assert__CTEs (mocks, models, sources, seeds), with or without SQL analysis, and emitted after what they read. Output for tests whose helpers call no references is unchanged.__ref()targets of read helpers count as test targets (computed once in Python and passed to the planner), sosqb test --select <model>runs a test even when only a helper reads the model.P013error with exact-syntax help: a read helper's__ref()to an unknown model, a read cycle between test CTEs, and a mock or__table_fn__fixture the test uses reading a helper that calls a reference.P013limits; the failure corpus gains aP013case.Verification
sql_analysis = false, asserting inlined helpers), a mocked model read by a helper and an assertion, unread helpers and mocks ignored, nested CTE shadowing stillP001, and eachP013case.cargo test --workspace --all-features, clippy and fmt on 1.98.0,make compiler-differential,make compiler-differential-shipped,tests/e2e/scripts/compiler_differential,make check-ci,make test.