Skip to content

Conversation

@pyramation
Copy link
Contributor

Summary

Fixes a bug in the pgpm package command where the AST round-trip diff check was always reporting a mismatch due to comparing incompatible types. Also adds a new --outputDiff flag to export the AST diff files for debugging.

Bug fix: The original code compared tree1 (an array of RawStmt[]) to tree2 (a full ParseResult object), which would always show a diff even when the ASTs were identical. The fix now correctly compares tree1 to reparsed.stmts with the same filterStatements applied to both.

New feature: Added --outputDiff flag that writes orig.*.tree.json and parsed.*.tree.json files when a diff is detected, making it easier to debug AST mismatches.

Review & Testing Checklist for Human

  • Verify the comparison fix is correct: Confirm that tree2 = filterStatements(reparsed.stmts as any, extension) properly mirrors the filtering applied to tree1 at line 62
  • Test the --outputDiff flag: Run pgpm package --outputDiff on a module and verify the JSON files are written correctly when a diff exists
  • Test without --outputDiff: Verify the warning message suggests using --outputDiff when a diff is detected

Recommended test plan:

  1. Find or create a module that triggers an AST diff (or temporarily break the deparser)
  2. Run pgpm package and verify you see the new warning message suggesting --outputDiff
  3. Run pgpm package --outputDiff and verify the JSON files are written to the sql/ folder
  4. Compare the two JSON files to understand the diff

Notes

  • The TypeScript build has pre-existing errors due to missing @pgpmjs/* module declarations - these are unrelated to this change
  • No tests were added as the user did not request them

Link to Devin run: https://app.devin.ai/sessions/369b1b00cb84494d93307674f0b9fb0e
Requested by: Dan Lynch (@pyramation)

…f flag

- Fix bug where tree1 (array of stmts) was compared to tree2 (full ParseResult object)
  Now correctly compares tree1 to tree2.stmts with same filterStatements applied
- Add --outputDiff flag to pgpm package command to export AST diff files when mismatch detected
- Update warning message to suggest using --outputDiff flag
- When --outputDiff is used, writes orig.*.tree.json and parsed.*.tree.json files
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 68c9552 into main Dec 27, 2025
35 checks passed
@pyramation pyramation deleted the devin/1766877641-fix-sql-diff-warning branch December 27, 2025 23:26
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.

2 participants