Skip to content

feat: make TEST headers, test modes and trailing SELECT 1 optional - #978

Merged
kvlonge merged 4 commits into
mainfrom
feat/test-file-ceremony
Oct 7, 2026
Merged

kvlonge merged 4 commits into
mainfrom
feat/test-file-ceremony

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Why

SQL test files needed ceremony the compiler could work out: a TEST(); header in every file, an explicit mode that the CTE names already determine, and a trailing SELECT 1 that is ignored.

Changes

  • A single-test file under tests/unit may omit its TEST(); header; files with several blocks still need one per block.
  • TEST mode is inferred from a top-level __macro_actual__, __udf_actual__ or __table_fn_actual__ CTE; an explicit mode is never overridden, and a contradicting one is still an error.
  • Tests and scenarios may end after their last CTE. Compile, Rules and the formatter add the omitted SELECT 1 internally through one shared helper; the formatter never writes it back.
  • The omitted-SELECT 1 check returns early for bodies that end in SELECT 1 and only scans quote, comment and bracket positions otherwise, with a time-limited guard test.
  • Testing, scenarios, macros and visibility docs show the short forms, keeping one explicit example; waffle-shop uses both forms.

Verification

  • Unit, integration and E2E tests for header-less files, mode inference, omitted SELECT 1, formatter and Rules handling; a native extraction test for the optional SELECT 1.
  • Compared with 0.134.8 on a large real project: identical diagnostics, Rules findings, format results, compiled SQL and manifest; compile CPU and memory at parity. Stripping the optional forms from every test file gave identical compiled output.
  • Focused pytest, ruff, fensu check and make check-ci.

@kvlonge
kvlonge enabled auto-merge (squash) October 6, 2026 13:59
… SQL tests

A single-test file under tests/unit may omit its TEST header, a TEST block
infers its mode from __macro_actual__, __udf_actual__ or __table_fn_actual__,
and tests and scenarios may end after their last CTE. Explicit headers, modes
and the ceremonial SELECT 1 keep working, and an explicit mode that
contradicts the CTEs is still rejected. Compile, Rules and the formatter
complete the omitted SELECT 1 internally so each body stays one statement.
Bodies that already end with a ceremonial SELECT 1 now return after a
constant-time tail check, and bodies that omit it are scanned between quote,
comment and parenthesis boundaries instead of character by character. The
duplicate CTE-scan cache is removed. A megabyte-body guard bounds both paths.
@kvlonge
kvlonge force-pushed the feat/test-file-ceremony branch from 7295a24 to 2dea3bd Compare October 7, 2026 06:23
@kvlonge
kvlonge merged commit e1e7e62 into main Oct 7, 2026
36 checks passed
@kvlonge
kvlonge deleted the feat/test-file-ceremony branch October 7, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant