From eb024dadf76c2f09da3685713dce1206cda928e7 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Sun, 22 Jun 2025 22:05:35 -0700 Subject: [PATCH 1/2] setup for issue #47 #48 #50 #52 --- __fixtures__/generated/generated.json | 4 +++ __fixtures__/kitchen-sink/misc/issues.sql | 27 ++++++++++++++++++- .../kitchen-sink/misc-issues.test.ts | 6 ++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/__fixtures__/generated/generated.json b/__fixtures__/generated/generated.json index 9ea4e4c0..4e97507c 100644 --- a/__fixtures__/generated/generated.json +++ b/__fixtures__/generated/generated.json @@ -21090,6 +21090,10 @@ "misc/issues-4.sql": "CREATE TABLE new_style (\n id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,\n val1 TEXT NOT NULL,\n val2 TEXT NULL\n)", "misc/issues-5.sql": "ALTER TABLE new_style ADD CONSTRAINT uq_val1_val2_new UNIQUE NULLS NOT DISTINCT (val1, val2)", "misc/issues-6.sql": "INSERT INTO\n public.people (id, name, epithet, is_great, gender, type_id, date_of_birth, date_of_death, place_of_birth, place_of_death, biography, canonical_status_id, image_url, source_url)\nVALUES\n (1, 'Asterius', 'of Amasea', FALSE, 'M', 1, '0350-01-01', '0410-01-01', 'Cappadocia', 'Amasea', NULL, 1, NULL, NULL),\n (2, 'Ausonius', NULL, FALSE, 'M', 1, '0310-01-01', '0395-01-01', 'Burdigala', NULL, NULL, NULL, NULL, NULL)\nON CONFLICT DO NOTHING", + "misc/issues-7.sql": "CREATE TABLE public.ci_builds_runner_session (\n id bigint NOT NULL,\n build_id integer NOT NULL,\n url character varying NOT NULL,\n certificate character varying,\n \"authorization\" character varying\n)", + "misc/issues-8.sql": "COMMENT ON COLUMN public.posts.reply_to_post_number IS 'If this post is a reply to another, this column is the post_number of the post it''s replying to. [FKEY posts.topic_id, posts.post_number]'", + "misc/issues-9.sql": "CREATE TABLE \"Album\"\n(\n \"AlbumId\" INT NOT NULL,\n \"Title\" VARCHAR(160) NOT NULL,\n \"ArtistId\" INT NOT NULL,\n CONSTRAINT \"PK_Album\" PRIMARY KEY (\"AlbumId\")\n)", + "misc/issues-10.sql": "CREATE INDEX \"existing_undispatched_message\" ON public.messages USING btree (\"context_id\", context_type, notification_name, \"to\", user_id)", "misc/inflection-1.sql": "CREATE SCHEMA inflection", "misc/inflection-2.sql": "GRANT USAGE ON SCHEMA inflection TO PUBLIC", "misc/inflection-3.sql": "ALTER DEFAULT PRIVILEGES IN SCHEMA inflection \n GRANT EXECUTE ON FUNCTIONS TO PUBLIC", diff --git a/__fixtures__/kitchen-sink/misc/issues.sql b/__fixtures__/kitchen-sink/misc/issues.sql index fd281f3e..61325616 100644 --- a/__fixtures__/kitchen-sink/misc/issues.sql +++ b/__fixtures__/kitchen-sink/misc/issues.sql @@ -24,4 +24,29 @@ INSERT INTO VALUES (1, 'Asterius', 'of Amasea', FALSE, 'M', 1, '0350-01-01', '0410-01-01', 'Cappadocia', 'Amasea', NULL, 1, NULL, NULL), (2, 'Ausonius', NULL, FALSE, 'M', 1, '0310-01-01', '0395-01-01', 'Burdigala', NULL, NULL, NULL, NULL, NULL) -ON CONFLICT DO NOTHING; \ No newline at end of file +ON CONFLICT DO NOTHING; + + +-- https://github.com/launchql/pgsql-parser/issues/52 +CREATE TABLE public.ci_builds_runner_session ( + id bigint NOT NULL, + build_id integer NOT NULL, + url character varying NOT NULL, + certificate character varying, + "authorization" character varying +); + +-- https://github.com/launchql/pgsql-parser/issues/50 +COMMENT ON COLUMN public.posts.reply_to_post_number IS 'If this post is a reply to another, this column is the post_number of the post it''s replying to. [FKEY posts.topic_id, posts.post_number]'; + +-- https://github.com/launchql/pgsql-parser/issues/48 +CREATE TABLE "Album" +( + "AlbumId" INT NOT NULL, + "Title" VARCHAR(160) NOT NULL, + "ArtistId" INT NOT NULL, + CONSTRAINT "PK_Album" PRIMARY KEY ("AlbumId") +); + +-- https://github.com/launchql/pgsql-parser/issues/47 +CREATE INDEX "existing_undispatched_message" ON public.messages USING btree ("context_id", context_type, notification_name, "to", user_id); \ No newline at end of file diff --git a/packages/deparser/__tests__/kitchen-sink/misc-issues.test.ts b/packages/deparser/__tests__/kitchen-sink/misc-issues.test.ts index 498079e0..ce53a5de 100644 --- a/packages/deparser/__tests__/kitchen-sink/misc-issues.test.ts +++ b/packages/deparser/__tests__/kitchen-sink/misc-issues.test.ts @@ -9,6 +9,10 @@ it('misc-issues', async () => { "misc/issues-3.sql", "misc/issues-4.sql", "misc/issues-5.sql", - "misc/issues-6.sql" + "misc/issues-6.sql", + "misc/issues-7.sql", + "misc/issues-8.sql", + "misc/issues-9.sql", + "misc/issues-10.sql" ]); }); From 9639d810b11b380c313fce63287b50be3d70d6b8 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Sun, 22 Jun 2025 22:14:58 -0700 Subject: [PATCH 2/2] testing --- AGENTS.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index d74c5445..0451e5ad 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -134,6 +134,19 @@ Example failure: Fix: prevent accidental nested `FuncCall` by inspecting and unwrapping recursively. +## Custom testing strategy + +Please review the test utilities — note that exact SQL string equality is not required. The focus is on comparing the resulting ASTs. + +Refer to `expectAstMatch` to understand how correctness is validated. + +The pipeline is: +parse(sql1) → ast → deparse(ast) → sql2 +While sql2 !== sql1 (textually), a correct round-trip means: +parse(sql1) === parse(sql2) (AST-level equality). + +You can see `expectAstMatch` here: packages/deparser/test-utils/index.ts + --- ### Development Setup