Skip to content

Conversation

@pyramation
Copy link
Collaborator

@pyramation pyramation commented Jan 23, 2026

Summary

This PR adds test fixtures for OUT parameters with SELECT INTO multiple variables, and fixes a pretty-printing bug where the INTO clause insertion left weird whitespace.

Test Fixtures Added:

  • Test 15: OUT parameters with SELECT INTO multiple variables (auth function pattern with 6 OUT params)
  • Test 16: OUT parameters with SELECT INTO STRICT

Bug Fix - Whitespace Normalization:
When PostgreSQL parses SELECT ... INTO var FROM ..., it strips the INTO var but leaves the original whitespace behind. This caused weird formatting like:

SELECT x INTO y                                         FROM z

The fix normalizes whitespace after INTO insertion:

  • If original had newlines → use newline + 4-space indent
  • If original was just spaces/tabs → collapse to single space

Updates since last revision

  • Added packages/plpgsql-deparser/AGENTS.md documenting the complete workflow for adding test fixtures
  • Updated generated.json with the new fixtures (now 192 fixtures total)
  • Added explicit snapshot tests in deparser-fixes.test.ts for the OUT parameters pattern (2 new snapshots)
  • Fixed whitespace normalization in deparseExecSql() - this updates several existing snapshots where FROM clauses now have consistent indentation

Review & Testing Checklist for Human

  • Review the whitespace normalization fix in plpgsql-deparser.ts (lines ~1488-1504) - verify the 4-space indent is appropriate and won't break existing consumers
  • Inspect updated snapshots in hydrate-demo.test.ts.snap, schema-rename-mapped.test.ts.snap, and plpgsql-pretty.test.ts.snap - these show the formatting change impact on existing tests
  • Verify the deparsed output in new snapshots has correct INTO id, user_id, access_token... ordering matching SELECT columns
  • Run cd packages/plpgsql-deparser && pnpm test to confirm all 62 tests pass (192 fixtures round-trip)

Recommended test plan: Parse and deparse a PL/pgSQL function with a long SELECT INTO clause, verify the FROM clause appears on a new line with reasonable indentation rather than excessive spacing.

Notes

This PR is part of a larger effort to support OUT parameters in constructive-db's auth functions. The TypeScript deparser already handles PLpgSQL_row.fields for the (unnamed row) case - these fixtures ensure that pattern continues to work correctly.

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

…bles

Add Test 15 and Test 16 to exercise the pattern used in auth functions
(sign_in, sign_up) where multiple OUT parameters are populated from a
single SELECT statement.

Test 15: OUT parameters with SELECT INTO multiple variables
- Demonstrates plaintext token generation with hash storage
- Uses uuid_generate_v5 for deterministic ID from token
- SELECT INTO populates 6 OUT parameters from tokens table

Test 16: OUT parameters with SELECT INTO STRICT
- Tests STRICT modifier with multiple INTO targets
@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

- Add AGENTS.md documenting the proper workflow for adding test fixtures
- Update generated.json with new fixtures for OUT parameters pattern
- Test 15: OUT parameters with SELECT INTO multiple variables
- Test 16: OUT parameters with SELECT INTO STRICT
… variables

Add explicit test cases to deparser-fixes.test.ts for:
- SELECT INTO multiple OUT parameters (auth function pattern)
- SELECT INTO STRICT with multiple OUT parameters

These tests generate snapshots to verify the deparser correctly handles
PLpgSQL_row.fields for multiple INTO targets.
When the parser strips 'INTO <target>' from a SELECT statement, it leaves
behind the original whitespace. This caused weird formatting like:
  SELECT x INTO y                                         FROM z

Now we normalize the whitespace:
- If original had newlines, use newline + 4-space indent
- If original was just spaces/tabs, collapse to single space

This fixes the pretty-printing issue with long INTO target lists.
@devin-ai-integration devin-ai-integration bot changed the title test: add fixtures for OUT parameters with SELECT INTO multiple variables fix: normalize INTO clause whitespace + add OUT parameter test fixtures Jan 23, 2026
@pyramation pyramation merged commit d83f333 into main Jan 23, 2026
18 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.

2 participants