Skip to content

Check that syntax cases match their receipts on every pull request - #45

Merged
kvlonge merged 3 commits into
mainfrom
cases-fresh-guard
Dec 6, 2026
Merged

kvlonge merged 3 commits into
mainfrom
cases-fresh-guard

Conversation

@kvlonge

@kvlonge kvlonge commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Why

A cases file built before its receipts were recorded merged twice (#40, and the session 4 commit fixed by #41). Each was caught only when SQLBabel pinned the evidence and its dialect-case check failed.

Changes

  • .github/workflows/cases-fresh.yml: the Cases match their receipts check runs on every pull request. It passes at once when no syntax/<dialect>/ changes, so it can be a required check without holding up other pull requests.
  • .github/scripts/cases_fresh.py: lists the touched dialects and resolves the SQLBabel builder commit: a Builder: <40-character SHA> line in the body, or else SQLBabel main's head. It prints the resolved SHA and rejects a branch name or a second Builder line. SQLBabel is checked out with its branches, and the check fails unless a branch contains the builder, so a commit reachable only through a pull request ref cannot be named. It then runs that commit's builder with --check against the pull request's evidence: build_syntax_cases for Snowflake (families from SQLBabel's Makefile), and build_syntax_obligations_<dialect> for each dialect in DIALECT_CASE_DIALECTS. A dialect with no builder fails.
  • The pull request body and SHA reach the shell only through environment variables, and the job reads contents only.
  • README.md: how the check works and when to name a Builder.

Verification

Scratch pull request (since deleted) with #40's lambda case and Builder: 0a8edcc72e937c074e7d1569f456e9e6b0a01f14:

A cases file built before its receipts were recorded merged twice and was
caught only when SQLBabel pinned it. The check rebuilds each touched
dialect's cases with SQLBabel's builder, at main or at the commit a
Builder line names, and fails on any difference.

kvlonge commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Independent review at 463224b: changes requested, one finding. The rest holds.

Finding: the Builder line accepts any commit, so the check can be satisfied by an unreviewed builder (cases_fresh.py:34-36).

  • The script checks only that the value is 40 hex characters, and actions/checkout then fetches it by SHA.
  • GitHub serves any commit in the repository's object store this way, not only branch tips. I fetched e257d21f, which is reachable only through a pull-request ref and is on no branch.
  • So a body line can name a commit no one reviewed, such as one whose builder always passes.
  • Suggested fix: check out SQLBabel with fetch-depth: 0, then fail unless git branch -r --contains <builder> names a branch of sqlstack-io/sqlbabel. main, or the paired PR's branch, then qualifies even after that branch moves on, while fork-only and abandoned commits do not.

What holds

  • The proof runs:
    • 47657104597 fails with "1 stale files" on the stale functions.jsonl.
    • 47657335475 passes with 0, both on Builder 0a8edcc7.
  • The Snowflake arguments match the Makefile's SYNTAX_CASE_ARGS exactly.
  • The builders need no third-party packages.
    • python3 -S (no site-packages) imports build_syntax_cases and all six build_syntax_obligations_* modules.
    • The Snowflake --check against its current pin (9c471bf) passes, "0 files differ", in 4 min 34 s, inside the 30-minute limit. The Snowflake path has not yet run in GitHub.
  • PR_BODY reaches the script only through env, builder is validated or comes from ls-remote before it reaches ref:, and the token is contents: read.
  • Receipt-only changes also trigger the check, which is right, because receipts change how cases settle.
  • An untouched tree passes at once.

Note: the check guards only what the evidence PR ships. The SQLBabel PR that pins it still runs its own dialect-cases, so the two stay paired.

actions/checkout fetches any commit by SHA, including one reachable only
through a pull request ref, so a Builder line could name an unreviewed
builder. The check now fetches SQLBabel's branches and fails unless one
contains the builder.

kvlonge commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Fixes-only check at 765a5a0: the Builder restriction is fixed. One stray file needs removing before merge.

  • on_branch works. I ran it from this head in a SQLBabel clone with every branch fetched, plus e257d21f fetched by SHA.
    • e257d21f, which is on no branch and reachable only through a pull-request ref, is refused: "is on no SQLBabel branch".
    • main's head passes: "on origin/main and 7 other branches".
  • fetch-depth: 0 makes actions/checkout fetch every branch as origin/*. Passing BUILDER in env is right too.
  • Remove before merge: the commit adds .github/scripts/__pycache__/cases_fresh.cpython-311.pyc, a compiled bytecode file from the local test run. The repository has no .gitignore, so a __pycache__/ entry there would keep it from coming back.

kvlonge commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Correction to my last comment: the repository does have a .gitignore, but it has no __pycache__/ entry. Adding that entry would keep the bytecode file from coming back. Removing the .pyc is still the only change needed before merge.

@kvlonge
kvlonge merged commit 1adfaf4 into main Dec 6, 2026
2 checks passed
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