From 707e36e7d8214ca9748f7b8fc621b334c40736ab Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Wed, 7 Jan 2026 01:58:48 +0000 Subject: [PATCH] fix(plpgsql-deparser): fix 2 more failing fixtures (189/190 now pass) - Fix cursor declaration syntax: output 'cursor_name CURSOR FOR query' instead of 'cursor_name refcursor CURSOR FOR query' (fixes plpgsql_transaction-17.sql) - Fix label placement: output label before DECLARE section, not between DECLARE and BEGIN (fixes plpgsql_control-15.sql) - Fix tagged dollar quote handling in test utils: properly match $ delimiters - Preserve qualified variable names (lbl.a) in FOR loops Remaining known failure: plpgsql_varprops-13.sql (nested DECLARE inside FOR loop) --- .../__tests__/plpgsql-deparser.test.ts | 11 +--- .../plpgsql-deparser/src/plpgsql-deparser.ts | 58 +++++++++++++------ packages/plpgsql-deparser/test-utils/index.ts | 32 +++++++--- 3 files changed, 68 insertions(+), 33 deletions(-) diff --git a/packages/plpgsql-deparser/__tests__/plpgsql-deparser.test.ts b/packages/plpgsql-deparser/__tests__/plpgsql-deparser.test.ts index 96bf4291..4cc2cd29 100644 --- a/packages/plpgsql-deparser/__tests__/plpgsql-deparser.test.ts +++ b/packages/plpgsql-deparser/__tests__/plpgsql-deparser.test.ts @@ -33,18 +33,13 @@ describe('PLpgSQLDeparser', () => { describe('round-trip tests using generated.json', () => { // Known failing fixtures due to pre-existing deparser issues: - // - Schema qualification loss (pg_catalog.pg_class%rowtype[] -> pg_class%rowtype[]) - // - Tagged dollar quote reconstruction ($tag$...$tag$ not supported) - // - Exception block handling issues // TODO: Fix these underlying issues and remove from allowlist // Remaining known failing fixtures: - // - plpgsql_varprops-13.sql: nested DECLARE inside FOR loop (loop variable scope issue) - // - plpgsql_transaction-17.sql: CURSOR FOR loop with EXCEPTION block - // - plpgsql_control-15.sql: labeled block with EXIT statement + // - plpgsql_varprops-13.sql: nested DECLARE inside FOR loop - variables declared inside + // the loop body are hoisted to the top-level DECLARE section, changing semantics + // (variables should be reinitialized on each loop iteration) const KNOWN_FAILING_FIXTURES = new Set([ 'plpgsql_varprops-13.sql', - 'plpgsql_transaction-17.sql', - 'plpgsql_control-15.sql', ]); it('should round-trip ALL generated fixtures (excluding known failures)', async () => { diff --git a/packages/plpgsql-deparser/src/plpgsql-deparser.ts b/packages/plpgsql-deparser/src/plpgsql-deparser.ts index d2444e7c..465db3d8 100644 --- a/packages/plpgsql-deparser/src/plpgsql-deparser.ts +++ b/packages/plpgsql-deparser/src/plpgsql-deparser.ts @@ -163,6 +163,18 @@ export class PLpgSQLDeparser { const parts: string[] = []; + // Extract label from action block - it should come before DECLARE + // In PL/pgSQL, the syntax is: <