Skip to content

ci: check native vs WASM parse parity for PG 18 - #200

Closed
pyramation wants to merge 1 commit into
mainfrom
feat/native-wasm-parity-ci
Closed

pyramation wants to merge 1 commit into
mainfrom
feat/native-wasm-parity-ci

Conversation

@pyramation

@pyramation pyramation commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds a PG 18-only CI step to the WASM build job that checks the WASM build parses SQL the same way as a native build of the same pinned libpg_query source.

  • scripts/native-parity.c / scripts/native-parity.js build libpg_query natively, then parse every statement from the upstream SQL fixtures with both, comparing parse trees and error messages/cursors. Fails on any difference.
  • Keeps the known FETCH ALL platform adjustment; files the scanner rejects are reported separately, not as failures.

Local run (CI's Emscripten image): 49968 statements from 409 files (2 unscannable), 0 differences; an injected WASM mismatch exits 1.

Fresh redo of #187 on current main. Left out: PG 13-17 parity coverage and the PG ≤14 glibc workaround (PG 18 only).


libpg-query and parser opened this PR for Dan
Implemented in session Redo native-vs-WASM parity check in CI
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • Tests
    • Automated build checks now compare native and WebAssembly SQL parsing results for version 18 across available SQL fixtures. Differences can cause the check to fail, helping surface parsing inconsistencies during builds. Unscannable fixtures are skipped, and reported differences include details to help identify where results diverge.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@luxor-code-review

luxor-code-review Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 read_file leaks FILE and buffer on error paths* (native-parity.c:24) — In scripts/native-parity.c:24 a failed fseek returns NULL without fclose; at scripts/native-parity.c:27-28 a failed malloc or short fread returns NULL leaking both the FILE* and the already-allocated buf.

This PR introduces a dev-time parity harness that compiles a small C driver against libpg_query and compares native parse results against the bundled WASM parser, wired into the CI workflow.

Files Change
scripts/native-parity.c New C driver that reads SQL input, invokes libpg_query, and emits JSON parse output for parity comparison.
scripts/native-parity.js New JS orchestration script that builds/runs the native driver and diffs its output against WASM parse results.
.github/workflows/ci.yml Adds a CI step to build and run the parity check.

Reviewed commit: eeb4d51

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pull request adds a native driver and a script that compare native and WASM parser results for SQL fixtures. CI runs the parity check after the WASM build for matrix package version 18.

Changes: Parser parity check

Layer / File(s) Summary
Native scan and parse driver
scripts/native-parity.c
Adds split and parse modes. The driver reads input files and emits JSON results for scanner output or parsed input segments.
Native and WASM result comparison
scripts/native-parity.js
Builds the native driver, processes SQL fixtures, and compares native and WASM results after normalizing howMany values and error cursor positions.
Version 18 CI integration
.github/workflows/ci.yml
Runs the parity script after the WASM build when the matrix package version is 18.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Possibly related PRs

Suggested reviewers: luxor-code-review

Merge Risk: Minimal · up to eeb4d

This adds a PG 18 CI check comparing native and WASM parser results. It does not change shipped package behavior, and no concrete merge-blocking risk was found. A CI failure would only block the PG 18 build job.

Architecture risk: Medium · up to eeb4d

The change affects 1 system.

Changed systems: scripts

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — scripts (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in scripts/native-parity.c: Adds JSON string escaping for quotes, backslashes, and control characters, plus binary file reading that returns a NUL-terminated buffer and its length; file opening, seeking, allocation, or reading failures return NULL.
  • observed — Modified behavior in scripts/native-parity.c: Adds split, which runs the scanner and emits either a JSON error object or a JSON array of statement substrings, then frees the scanner result.
  • observed — Modified behavior in scripts/native-parity.c: Adds parse, which parses each NUL-delimited segment and emits one JSON line per result: a parse tree on success, or the error message and cursor position on failure; each parse result is freed.
  • observed — Modified behavior in scripts/native-parity.c: Adds main argument validation for exactly a mode (split or parse) and a file path. Invalid arguments or file-read failure return 1; otherwise it dispatches to the selected mode, frees the input buffer, and returns 0.

Reliability and maintainability

  • inferred — Risk-relevant change factors for scripts: blast_radius_1; direct_dependents_1
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "ci: check native vs WASM parse parity for PG 18" matches the main change. The PR adds a native-versus-WASM parse parity script that runs in the build-wasm CI job only for PG 18. The title n…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "ci: check native vs WASM parse parity for PG 18" matches the main change. The PR adds a native-versus-WASM parse parity script that runs in the build-wasm CI job only for PG 18. The title names the CI scope, the comparison, and the PG 18 limit. The C utility and the JS script are supporting parts of the same change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4d675e0 and eeb4d51.

Files selected for processing: 3

  • .github/workflows/ci.yml
  • scripts/native-parity.c
  • scripts/native-parity.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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