Skip to content

test: add regression tests for IMMUTABLE plpgsql functions with user-defined return types (#329)#332

Closed
tianzhou wants to merge 1 commit intomainfrom
fix/issue-329-immutable-udt-return
Closed

test: add regression tests for IMMUTABLE plpgsql functions with user-defined return types (#329)#332
tianzhou wants to merge 1 commit intomainfrom
fix/issue-329-immutable-udt-return

Conversation

@tianzhou
Copy link
Contributor

Summary

Test cases added

  • issue_329_immutable_udt_return — IMMUTABLE plpgsql function returning a custom enum type (idempotency check: plan should detect no changes)
  • issue_329_immutable_udt_generated_col — same function used in a GENERATED ALWAYS AS STORED column (verifies both function comparison and generated expression handling)

Fixes #329

Test plan

  • PGSCHEMA_TEST_FILTER="create_function/issue_329" go test -v ./internal/diff -run TestDiffFromFiles — passes
  • PGSCHEMA_TEST_FILTER="create_function/issue_329" go test -v ./cmd -run TestPlanAndApply — passes (including idempotency check)
  • PGSCHEMA_TEST_FILTER="create_function/" go test -v ./cmd -run TestPlanAndApply — all 10 function tests pass
  • Full CI suite validates no regressions

🤖 Generated with Claude Code

…user-defined types (#329)

Add two test cases to prevent regression of perpetual plan drift for
IMMUTABLE plpgsql functions that return user-defined types (e.g. custom
enums). The issue was reported against v1.6.2 but is already fixed in
the current codebase by earlier normalization improvements.

Test cases:
- issue_329_immutable_udt_return: IMMUTABLE function returning custom enum
- issue_329_immutable_udt_generated_col: same function used in GENERATED
  ALWAYS AS STORED column

Fixes #329

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 28, 2026 03:59
@greptile-apps
Copy link

greptile-apps bot commented Feb 28, 2026

Greptile Summary

Adds two regression test cases for issue #329 to prevent perpetual plan drift with IMMUTABLE plpgsql functions returning user-defined types.

Test Coverage:

  • issue_329_immutable_udt_return - Verifies idempotency for IMMUTABLE function returning custom enum type
  • issue_329_immutable_udt_generated_col - Extends test to include GENERATED ALWAYS AS STORED column using the UDT-returning function

Both test cases follow the standard diff test pattern: old.sql and new.sql are identical, and all expected outputs (diff.sql, plan.sql, plan.txt, plan.json) correctly indicate no changes detected. The tests serve as regression guards for normalization fixes in commits 29c1b67 and 0daf757.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • Test-only PR with well-structured regression tests following established project patterns. All test files are correctly formatted with proper idempotency checks (old.sql = new.sql, empty diffs, "No changes detected" outputs). Tests passed in CI per PR description.
  • No files require special attention

Important Files Changed

Filename Overview
testdata/diff/create_function/issue_329_immutable_udt_return/old.sql Defines baseline schema with custom enum type and IMMUTABLE function returning that type
testdata/diff/create_function/issue_329_immutable_udt_return/new.sql Identical to old.sql - tests idempotency (no false drift detection)
testdata/diff/create_function/issue_329_immutable_udt_return/plan.txt Correctly shows "No changes detected." message
testdata/diff/create_function/issue_329_immutable_udt_generated_col/old.sql Extends first test with table having GENERATED column using the UDT-returning function
testdata/diff/create_function/issue_329_immutable_udt_generated_col/new.sql Identical to old.sql - tests idempotency with generated column expressions
testdata/diff/create_function/issue_329_immutable_udt_generated_col/plan.txt Correctly shows "No changes detected." message

Last reviewed commit: 4bc9f01

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds regression coverage for issue #329 to ensure pgschema plan remains idempotent for IMMUTABLE plpgsql functions that return user-defined types, including when referenced by generated columns.

Changes:

  • Adds a no-op plan regression fixture for an IMMUTABLE plpgsql function returning a custom enum.
  • Adds a no-op plan regression fixture for the same function referenced by a GENERATED ALWAYS AS STORED column.
  • Includes expected plan outputs across human (plan.txt), SQL (plan.sql), and JSON (plan.json) formats for CLI/integration tests.

Reviewed changes

Copilot reviewed 8 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
testdata/diff/create_function/issue_329_immutable_udt_return/old.sql Baseline schema defining enum + IMMUTABLE function returning UDT.
testdata/diff/create_function/issue_329_immutable_udt_return/new.sql Target schema identical to old to assert no drift.
testdata/diff/create_function/issue_329_immutable_udt_return/plan.txt Expected human output: no changes detected.
testdata/diff/create_function/issue_329_immutable_udt_return/plan.json Expected JSON output for a no-op plan.
testdata/diff/create_function/issue_329_immutable_udt_return/plan.sql Expected SQL output for a no-op plan (empty).
testdata/diff/create_function/issue_329_immutable_udt_return/diff.sql Expected internal diff output for a no-op migration (empty).
testdata/diff/create_function/issue_329_immutable_udt_generated_col/old.sql Baseline schema adds generated column referencing the function.
testdata/diff/create_function/issue_329_immutable_udt_generated_col/new.sql Target schema identical to old to assert no drift and no planning error.
testdata/diff/create_function/issue_329_immutable_udt_generated_col/plan.txt Expected human output: no changes detected.
testdata/diff/create_function/issue_329_immutable_udt_generated_col/plan.json Expected JSON output for a no-op plan.
testdata/diff/create_function/issue_329_immutable_udt_generated_col/plan.sql Expected SQL output for a no-op plan (empty).
testdata/diff/create_function/issue_329_immutable_udt_generated_col/diff.sql Expected internal diff output for a no-op migration (empty).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Bug: unresolvable plan drift for IMMUTABLE plpgsql functions returning a user-defined type

2 participants