From b87bc556f3d4cf1f2e0b1de01c5c2f382dc77d5a Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Fri, 13 Nov 2026 09:34:09 +0000 Subject: [PATCH 1/2] acc: match postgres GET now echoing spec Since 2026-11-12 the Lakebase postgres API returns spec on GET for projects, branches, endpoints, databases and roles, not only status. Plans now record remote values for spec fields, and fields that match no longer appear as "skip spec:input_only" changes. The testserver now echoes spec the way the cloud does: as sent on create, merged by update_mask on update (a masked field missing from the body keeps its value, and one oneof member replaces the others), without fields that stay input-only (project pg_version, branch source_branch*, role postgres_role/auth_method/identity_type). Goldens regenerated on AWS and checked locally. cloud: TestAccept/bundle/resources/postgres_projects TestAccept/bundle/resources/postgres_branches TestAccept/bundle/resources/postgres_endpoints TestAccept/bundle/resources/postgres_databases TestAccept/bundle/resources/postgres_roles Co-authored-by: Isaac --- .../recreate_source_branch_time/out.plan.json | 6 - .../update_expire_time/out.plan.json | 3 +- .../update_protected/out.plan.no_change.json | 16 +- .../update_protected/out.plan.restore.json | 11 +- .../update_protected/out.plan.update.json | 11 +- .../update_ttl/out.plan.json | 3 +- .../update/out.plan.no_change.json | 18 +-- .../update/out.plan.restore.json | 13 +- .../update/out.plan.update.json | 13 +- .../out.plan.drift.json | 22 +-- .../remove_suspend_timeout/out.plan.json | 22 +-- .../out.plan.no_change.json | 29 +--- .../update_autoscaling/out.plan.restore.json | 22 +-- .../update_autoscaling/out.plan.update.json | 22 +-- .../update_pg_settings/out.plan.json | 35 +--- .../update_suspend_timeout/out.plan.json | 22 +-- .../out.plan.json | 14 +- .../out.plan.drift.json | 9 +- .../remove_history_retention/out.plan.json | 9 +- .../out.plan.json | 22 +-- .../out.plan.no_change.json | 33 +--- .../update_display_name/out.plan.restore.json | 30 ++-- .../update_display_name/out.plan.update.json | 30 ++-- .../update_history_retention/out.plan.json | 9 +- .../update/out.plan.no_change.json | 13 +- .../update/out.plan.restore.json | 15 +- .../update/out.plan.update.json | 15 +- bundle/direct/dresources/postgres_branch.go | 5 +- bundle/direct/dresources/postgres_database.go | 5 +- bundle/direct/dresources/postgres_endpoint.go | 5 +- bundle/direct/dresources/postgres_project.go | 5 +- bundle/direct/dresources/postgres_role.go | 5 +- libs/testserver/postgres.go | 29 ++-- libs/testserver/postgres_spec.go | 150 ++++++++++++++++++ libs/testserver/postgres_spec_test.go | 40 +++++ 35 files changed, 300 insertions(+), 411 deletions(-) create mode 100644 libs/testserver/postgres_spec.go create mode 100644 libs/testserver/postgres_spec_test.go diff --git a/acceptance/bundle/resources/postgres_branches/recreate_source_branch_time/out.plan.json b/acceptance/bundle/resources/postgres_branches/recreate_source_branch_time/out.plan.json index b3ad19c1b68..5ccb696a8d6 100644 --- a/acceptance/bundle/resources/postgres_branches/recreate_source_branch_time/out.plan.json +++ b/acceptance/bundle/resources/postgres_branches/recreate_source_branch_time/out.plan.json @@ -1,12 +1,6 @@ { "action": "recreate", "changes": { - "no_expiry": { - "action": "skip", - "reason": "spec:input_only", - "old": true, - "new": true - }, "source_branch": { "action": "skip", "reason": "spec:input_only", diff --git a/acceptance/bundle/resources/postgres_branches/update_expire_time/out.plan.json b/acceptance/bundle/resources/postgres_branches/update_expire_time/out.plan.json index bfab97ba09a..e35c1cf5e46 100644 --- a/acceptance/bundle/resources/postgres_branches/update_expire_time/out.plan.json +++ b/acceptance/bundle/resources/postgres_branches/update_expire_time/out.plan.json @@ -4,7 +4,8 @@ "expire_time": { "action": "update", "old": "[EXPIRE_TIME_BEFORE]", - "new": "[EXPIRE_TIME_AFTER]" + "new": "[EXPIRE_TIME_AFTER]", + "remote": "[EXPIRE_TIME_BEFORE]" } } } diff --git a/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.no_change.json b/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.no_change.json index ff7df005d4e..35984abba61 100644 --- a/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.no_change.json +++ b/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.no_change.json @@ -9,7 +9,9 @@ "remote_state": { "branch_id": "dev-branch", "create_time": "[TIMESTAMP]", + "is_protected": false, "name": "[DEV_BRANCH_ID]", + "no_expiry": true, "parent": "projects/test-pg-proj-[UNIQUE_NAME]", "status": { "branch_id": "dev-branch", @@ -23,19 +25,5 @@ }, "uid": "[BRANCH_UID]", "update_time": "[TIMESTAMP]" - }, - "changes": { - "is_protected": { - "action": "skip", - "reason": "empty", - "old": false, - "new": false - }, - "no_expiry": { - "action": "skip", - "reason": "spec:input_only", - "old": true, - "new": true - } } } diff --git a/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.restore.json b/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.restore.json index 64acdc88a68..8c543fd4230 100644 --- a/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.restore.json +++ b/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.restore.json @@ -17,7 +17,9 @@ "remote_state": { "branch_id": "dev-branch", "create_time": "[TIMESTAMP]", + "is_protected": true, "name": "[DEV_BRANCH_ID]", + "no_expiry": true, "parent": "projects/test-pg-proj-[UNIQUE_NAME]", "status": { "branch_id": "dev-branch", @@ -36,13 +38,8 @@ "is_protected": { "action": "update", "old": true, - "new": false - }, - "no_expiry": { - "action": "skip", - "reason": "spec:input_only", - "old": true, - "new": true + "new": false, + "remote": true } } } diff --git a/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.update.json b/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.update.json index 6cc645dede6..d05e254629a 100644 --- a/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.update.json +++ b/acceptance/bundle/resources/postgres_branches/update_protected/out.plan.update.json @@ -17,7 +17,9 @@ "remote_state": { "branch_id": "dev-branch", "create_time": "[TIMESTAMP]", + "is_protected": false, "name": "[DEV_BRANCH_ID]", + "no_expiry": true, "parent": "projects/test-pg-proj-[UNIQUE_NAME]", "status": { "branch_id": "dev-branch", @@ -36,13 +38,8 @@ "is_protected": { "action": "update", "old": false, - "new": true - }, - "no_expiry": { - "action": "skip", - "reason": "spec:input_only", - "old": true, - "new": true + "new": true, + "remote": false } } } diff --git a/acceptance/bundle/resources/postgres_branches/update_ttl/out.plan.json b/acceptance/bundle/resources/postgres_branches/update_ttl/out.plan.json index adac047f0ce..a04d24e1103 100644 --- a/acceptance/bundle/resources/postgres_branches/update_ttl/out.plan.json +++ b/acceptance/bundle/resources/postgres_branches/update_ttl/out.plan.json @@ -4,7 +4,8 @@ "ttl": { "action": "update", "old": "604800s", - "new": "259200s" + "new": "259200s", + "remote": "604800s" } } } diff --git a/acceptance/bundle/resources/postgres_databases/update/out.plan.no_change.json b/acceptance/bundle/resources/postgres_databases/update/out.plan.no_change.json index 002cec83a0e..29c2d77a396 100644 --- a/acceptance/bundle/resources/postgres_databases/update/out.plan.no_change.json +++ b/acceptance/bundle/resources/postgres_databases/update/out.plan.no_change.json @@ -15,27 +15,13 @@ "database_id": "my-database", "name": "[MY_DATABASE_ID]", "parent": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main", - "role": "", + "postgres_database": "initial_db_name", + "role": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner", "status": { "database_id": "my-database", "postgres_database": "initial_db_name", "role": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner" }, "update_time": "[TIMESTAMP]" - }, - "changes": { - "postgres_database": { - "action": "skip", - "reason": "spec:input_only", - "old": "initial_db_name", - "new": "initial_db_name" - }, - "role": { - "action": "skip", - "reason": "spec:input_only", - "old": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner", - "new": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner", - "remote": "" - } } } diff --git a/acceptance/bundle/resources/postgres_databases/update/out.plan.restore.json b/acceptance/bundle/resources/postgres_databases/update/out.plan.restore.json index 1bd727c8de9..fdcd3a5c407 100644 --- a/acceptance/bundle/resources/postgres_databases/update/out.plan.restore.json +++ b/acceptance/bundle/resources/postgres_databases/update/out.plan.restore.json @@ -23,7 +23,8 @@ "database_id": "my-database", "name": "[MY_DATABASE_ID]", "parent": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main", - "role": "", + "postgres_database": "renamed_db_name", + "role": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner", "status": { "database_id": "my-database", "postgres_database": "renamed_db_name", @@ -35,14 +36,8 @@ "postgres_database": { "action": "update", "old": "renamed_db_name", - "new": "initial_db_name" - }, - "role": { - "action": "skip", - "reason": "spec:input_only", - "old": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner", - "new": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner", - "remote": "" + "new": "initial_db_name", + "remote": "renamed_db_name" } } } diff --git a/acceptance/bundle/resources/postgres_databases/update/out.plan.update.json b/acceptance/bundle/resources/postgres_databases/update/out.plan.update.json index 9f104b5772c..07f974b0725 100644 --- a/acceptance/bundle/resources/postgres_databases/update/out.plan.update.json +++ b/acceptance/bundle/resources/postgres_databases/update/out.plan.update.json @@ -23,7 +23,8 @@ "database_id": "my-database", "name": "[MY_DATABASE_ID]", "parent": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main", - "role": "", + "postgres_database": "initial_db_name", + "role": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner", "status": { "database_id": "my-database", "postgres_database": "initial_db_name", @@ -35,14 +36,8 @@ "postgres_database": { "action": "update", "old": "initial_db_name", - "new": "renamed_db_name" - }, - "role": { - "action": "skip", - "reason": "spec:input_only", - "old": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner", - "new": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner", - "remote": "" + "new": "renamed_db_name", + "remote": "initial_db_name" } } } diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_suspend_timeout/out.plan.drift.json b/acceptance/bundle/resources/postgres_endpoints/remove_suspend_timeout/out.plan.drift.json index 77467bdb5d0..f7478579457 100644 --- a/acceptance/bundle/resources/postgres_endpoints/remove_suspend_timeout/out.plan.drift.json +++ b/acceptance/bundle/resources/postgres_endpoints/remove_suspend_timeout/out.plan.drift.json @@ -1,28 +1,10 @@ { "action": "update", "changes": { - "autoscaling_limit_max_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 8, - "new": 8 - }, - "autoscaling_limit_min_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 0.5, - "new": 0.5 - }, - "endpoint_type": { - "action": "skip", - "reason": "spec:input_only", - "old": "ENDPOINT_TYPE_READ_ONLY", - "new": "ENDPOINT_TYPE_READ_ONLY", - "remote": "" - }, "suspend_timeout_duration": { "action": "update", - "old": "300s" + "old": "300s", + "remote": "300s" } } } diff --git a/acceptance/bundle/resources/postgres_endpoints/remove_suspend_timeout/out.plan.json b/acceptance/bundle/resources/postgres_endpoints/remove_suspend_timeout/out.plan.json index 77467bdb5d0..f7478579457 100644 --- a/acceptance/bundle/resources/postgres_endpoints/remove_suspend_timeout/out.plan.json +++ b/acceptance/bundle/resources/postgres_endpoints/remove_suspend_timeout/out.plan.json @@ -1,28 +1,10 @@ { "action": "update", "changes": { - "autoscaling_limit_max_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 8, - "new": 8 - }, - "autoscaling_limit_min_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 0.5, - "new": 0.5 - }, - "endpoint_type": { - "action": "skip", - "reason": "spec:input_only", - "old": "ENDPOINT_TYPE_READ_ONLY", - "new": "ENDPOINT_TYPE_READ_ONLY", - "remote": "" - }, "suspend_timeout_duration": { "action": "update", - "old": "300s" + "old": "300s", + "remote": "300s" } } } diff --git a/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.no_change.json b/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.no_change.json index 10c8affb555..a8d0e19c543 100644 --- a/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.no_change.json +++ b/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.no_change.json @@ -5,32 +5,5 @@ "label": "${resources.postgres_branches.main.id}" } ], - "action": "skip", - "changes": { - "autoscaling_limit_max_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 8, - "new": 8 - }, - "autoscaling_limit_min_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 0.5, - "new": 0.5 - }, - "endpoint_type": { - "action": "skip", - "reason": "spec:input_only", - "old": "ENDPOINT_TYPE_READ_ONLY", - "new": "ENDPOINT_TYPE_READ_ONLY", - "remote": "" - }, - "suspend_timeout_duration": { - "action": "skip", - "reason": "spec:input_only", - "old": "300s", - "new": "300s" - } - } + "action": "skip" } diff --git a/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.restore.json b/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.restore.json index 9228fd22296..080ab2d3b9d 100644 --- a/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.restore.json +++ b/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.restore.json @@ -20,26 +20,8 @@ "autoscaling_limit_max_cu": { "action": "update", "old": 4, - "new": 8 - }, - "autoscaling_limit_min_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 0.5, - "new": 0.5 - }, - "endpoint_type": { - "action": "skip", - "reason": "spec:input_only", - "old": "ENDPOINT_TYPE_READ_ONLY", - "new": "ENDPOINT_TYPE_READ_ONLY", - "remote": "" - }, - "suspend_timeout_duration": { - "action": "skip", - "reason": "spec:input_only", - "old": "300s", - "new": "300s" + "new": 8, + "remote": 4 } } } diff --git a/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.update.json b/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.update.json index af255584b89..018d27c54ac 100644 --- a/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.update.json +++ b/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/out.plan.update.json @@ -20,26 +20,8 @@ "autoscaling_limit_max_cu": { "action": "update", "old": 8, - "new": 4 - }, - "autoscaling_limit_min_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 0.5, - "new": 0.5 - }, - "endpoint_type": { - "action": "skip", - "reason": "spec:input_only", - "old": "ENDPOINT_TYPE_READ_ONLY", - "new": "ENDPOINT_TYPE_READ_ONLY", - "remote": "" - }, - "suspend_timeout_duration": { - "action": "skip", - "reason": "spec:input_only", - "old": "300s", - "new": "300s" + "new": 4, + "remote": 8 } } } diff --git a/acceptance/bundle/resources/postgres_endpoints/update_pg_settings/out.plan.json b/acceptance/bundle/resources/postgres_endpoints/update_pg_settings/out.plan.json index 1cb37958265..ae50d6180c5 100644 --- a/acceptance/bundle/resources/postgres_endpoints/update_pg_settings/out.plan.json +++ b/acceptance/bundle/resources/postgres_endpoints/update_pg_settings/out.plan.json @@ -1,42 +1,11 @@ { "action": "update", "changes": { - "autoscaling_limit_max_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 8, - "new": 8 - }, - "autoscaling_limit_min_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 0.5, - "new": 0.5 - }, - "endpoint_type": { - "action": "skip", - "reason": "spec:input_only", - "old": "ENDPOINT_TYPE_READ_ONLY", - "new": "ENDPOINT_TYPE_READ_ONLY", - "remote": "" - }, - "settings": { - "action": "update", - "old": { - "pg_settings": { - "statement_timeout": "8000" - } - }, - "new": { - "pg_settings": { - "statement_timeout": "16000" - } - } - }, "settings.pg_settings['statement_timeout']": { "action": "update", "old": "8000", - "new": "16000" + "new": "16000", + "remote": "8000" } } } diff --git a/acceptance/bundle/resources/postgres_endpoints/update_suspend_timeout/out.plan.json b/acceptance/bundle/resources/postgres_endpoints/update_suspend_timeout/out.plan.json index 0ec428d2dab..ff41085096b 100644 --- a/acceptance/bundle/resources/postgres_endpoints/update_suspend_timeout/out.plan.json +++ b/acceptance/bundle/resources/postgres_endpoints/update_suspend_timeout/out.plan.json @@ -1,29 +1,11 @@ { "action": "update", "changes": { - "autoscaling_limit_max_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 8, - "new": 8 - }, - "autoscaling_limit_min_cu": { - "action": "skip", - "reason": "spec:input_only", - "old": 0.5, - "new": 0.5 - }, - "endpoint_type": { - "action": "skip", - "reason": "spec:input_only", - "old": "ENDPOINT_TYPE_READ_ONLY", - "new": "ENDPOINT_TYPE_READ_ONLY", - "remote": "" - }, "suspend_timeout_duration": { "action": "update", "old": "300s", - "new": "600s" + "new": "600s", + "remote": "300s" } } } diff --git a/acceptance/bundle/resources/postgres_projects/add_default_endpoint_settings/out.plan.json b/acceptance/bundle/resources/postgres_projects/add_default_endpoint_settings/out.plan.json index 39cc2aef2f3..5c66eb28b29 100644 --- a/acceptance/bundle/resources/postgres_projects/add_default_endpoint_settings/out.plan.json +++ b/acceptance/bundle/resources/postgres_projects/add_default_endpoint_settings/out.plan.json @@ -20,6 +20,8 @@ }, "remote_state": { "create_time": "[TIMESTAMP]", + "display_name": "Test Project for Adding Default Endpoint Settings", + "history_retention_duration": "604800s", "name": "projects/test-pg-proj-[UNIQUE_NAME]", "project_id": "test-pg-proj-[UNIQUE_NAME]", "status": { @@ -49,18 +51,6 @@ "autoscaling_limit_min_cu": 0.5 } }, - "display_name": { - "action": "skip", - "reason": "spec:input_only", - "old": "Test Project for Adding Default Endpoint Settings", - "new": "Test Project for Adding Default Endpoint Settings" - }, - "history_retention_duration": { - "action": "skip", - "reason": "spec:input_only", - "old": "604800s", - "new": "604800s" - }, "pg_version": { "action": "skip", "reason": "spec:input_only", diff --git a/acceptance/bundle/resources/postgres_projects/remove_history_retention/out.plan.drift.json b/acceptance/bundle/resources/postgres_projects/remove_history_retention/out.plan.drift.json index 156a5dd37d3..77bde21b0fc 100644 --- a/acceptance/bundle/resources/postgres_projects/remove_history_retention/out.plan.drift.json +++ b/acceptance/bundle/resources/postgres_projects/remove_history_retention/out.plan.drift.json @@ -1,15 +1,10 @@ { "action": "update", "changes": { - "display_name": { - "action": "skip", - "reason": "spec:input_only", - "old": "Test Project for History Retention Update", - "new": "Test Project for History Retention Update" - }, "history_retention_duration": { "action": "update", - "old": "604800s" + "old": "604800s", + "remote": "604800s" }, "pg_version": { "action": "skip", diff --git a/acceptance/bundle/resources/postgres_projects/remove_history_retention/out.plan.json b/acceptance/bundle/resources/postgres_projects/remove_history_retention/out.plan.json index 156a5dd37d3..77bde21b0fc 100644 --- a/acceptance/bundle/resources/postgres_projects/remove_history_retention/out.plan.json +++ b/acceptance/bundle/resources/postgres_projects/remove_history_retention/out.plan.json @@ -1,15 +1,10 @@ { "action": "update", "changes": { - "display_name": { - "action": "skip", - "reason": "spec:input_only", - "old": "Test Project for History Retention Update", - "new": "Test Project for History Retention Update" - }, "history_retention_duration": { "action": "update", - "old": "604800s" + "old": "604800s", + "remote": "604800s" }, "pg_version": { "action": "skip", diff --git a/acceptance/bundle/resources/postgres_projects/update_default_endpoint_suspend/out.plan.json b/acceptance/bundle/resources/postgres_projects/update_default_endpoint_suspend/out.plan.json index 2ea5de81e29..340a930047b 100644 --- a/acceptance/bundle/resources/postgres_projects/update_default_endpoint_suspend/out.plan.json +++ b/acceptance/bundle/resources/postgres_projects/update_default_endpoint_suspend/out.plan.json @@ -1,29 +1,11 @@ { "action": "update", "changes": { - "default_endpoint_settings": { - "action": "update", - "old": { - "autoscaling_limit_max_cu": 4, - "autoscaling_limit_min_cu": 0.5, - "suspend_timeout_duration": "300s" - }, - "new": { - "autoscaling_limit_max_cu": 4, - "autoscaling_limit_min_cu": 0.5, - "suspend_timeout_duration": "600s" - } - }, "default_endpoint_settings.suspend_timeout_duration": { "action": "update", "old": "300s", - "new": "600s" - }, - "display_name": { - "action": "skip", - "reason": "spec:input_only", - "old": "Test Project for Default Endpoint Suspend Update", - "new": "Test Project for Default Endpoint Suspend Update" + "new": "600s", + "remote": "300s" }, "pg_version": { "action": "skip", diff --git a/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.no_change.json b/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.no_change.json index 0336f39f4a1..aef35a8e1f1 100644 --- a/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.no_change.json +++ b/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.no_change.json @@ -2,6 +2,13 @@ "action": "skip", "remote_state": { "create_time": "[TIMESTAMP]", + "default_endpoint_settings": { + "autoscaling_limit_max_cu": 4, + "autoscaling_limit_min_cu": 0.5, + "suspend_timeout_duration": "300s" + }, + "display_name": "Original Name", + "history_retention_duration": "604800s", "name": "[MY_PROJECT_ID]", "project_id": "test-pg-proj-[UNIQUE_NAME]", "status": { @@ -24,32 +31,6 @@ "update_time": "[TIMESTAMP]" }, "changes": { - "default_endpoint_settings": { - "action": "skip", - "reason": "spec:input_only", - "old": { - "autoscaling_limit_max_cu": 4, - "autoscaling_limit_min_cu": 0.5, - "suspend_timeout_duration": "300s" - }, - "new": { - "autoscaling_limit_max_cu": 4, - "autoscaling_limit_min_cu": 0.5, - "suspend_timeout_duration": "300s" - } - }, - "display_name": { - "action": "skip", - "reason": "spec:input_only", - "old": "Original Name", - "new": "Original Name" - }, - "history_retention_duration": { - "action": "skip", - "reason": "spec:input_only", - "old": "604800s", - "new": "604800s" - }, "pg_version": { "action": "skip", "reason": "spec:input_only", diff --git a/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.restore.json b/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.restore.json index 92ddb203f42..c508cf75a50 100644 --- a/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.restore.json +++ b/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.restore.json @@ -15,6 +15,13 @@ }, "remote_state": { "create_time": "[TIMESTAMP]", + "default_endpoint_settings": { + "autoscaling_limit_max_cu": 4, + "autoscaling_limit_min_cu": 0.5, + "suspend_timeout_duration": "300s" + }, + "display_name": "Updated Name", + "history_retention_duration": "604800s", "name": "[MY_PROJECT_ID]", "project_id": "test-pg-proj-[UNIQUE_NAME]", "status": { @@ -37,30 +44,11 @@ "update_time": "[TIMESTAMP]" }, "changes": { - "default_endpoint_settings": { - "action": "skip", - "reason": "spec:input_only", - "old": { - "autoscaling_limit_max_cu": 4, - "autoscaling_limit_min_cu": 0.5, - "suspend_timeout_duration": "300s" - }, - "new": { - "autoscaling_limit_max_cu": 4, - "autoscaling_limit_min_cu": 0.5, - "suspend_timeout_duration": "300s" - } - }, "display_name": { "action": "update", "old": "Updated Name", - "new": "Original Name" - }, - "history_retention_duration": { - "action": "skip", - "reason": "spec:input_only", - "old": "604800s", - "new": "604800s" + "new": "Original Name", + "remote": "Updated Name" }, "pg_version": { "action": "skip", diff --git a/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.update.json b/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.update.json index 771d76a009f..ebed0764efe 100644 --- a/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.update.json +++ b/acceptance/bundle/resources/postgres_projects/update_display_name/out.plan.update.json @@ -15,6 +15,13 @@ }, "remote_state": { "create_time": "[TIMESTAMP]", + "default_endpoint_settings": { + "autoscaling_limit_max_cu": 4, + "autoscaling_limit_min_cu": 0.5, + "suspend_timeout_duration": "300s" + }, + "display_name": "Original Name", + "history_retention_duration": "604800s", "name": "[MY_PROJECT_ID]", "project_id": "test-pg-proj-[UNIQUE_NAME]", "status": { @@ -37,30 +44,11 @@ "update_time": "[TIMESTAMP]" }, "changes": { - "default_endpoint_settings": { - "action": "skip", - "reason": "spec:input_only", - "old": { - "autoscaling_limit_max_cu": 4, - "autoscaling_limit_min_cu": 0.5, - "suspend_timeout_duration": "300s" - }, - "new": { - "autoscaling_limit_max_cu": 4, - "autoscaling_limit_min_cu": 0.5, - "suspend_timeout_duration": "300s" - } - }, "display_name": { "action": "update", "old": "Original Name", - "new": "Updated Name" - }, - "history_retention_duration": { - "action": "skip", - "reason": "spec:input_only", - "old": "604800s", - "new": "604800s" + "new": "Updated Name", + "remote": "Original Name" }, "pg_version": { "action": "skip", diff --git a/acceptance/bundle/resources/postgres_projects/update_history_retention/out.plan.json b/acceptance/bundle/resources/postgres_projects/update_history_retention/out.plan.json index 20a9729d18d..cca799a2e3e 100644 --- a/acceptance/bundle/resources/postgres_projects/update_history_retention/out.plan.json +++ b/acceptance/bundle/resources/postgres_projects/update_history_retention/out.plan.json @@ -1,16 +1,11 @@ { "action": "update", "changes": { - "display_name": { - "action": "skip", - "reason": "spec:input_only", - "old": "Test Project for History Retention Update", - "new": "Test Project for History Retention Update" - }, "history_retention_duration": { "action": "update", "old": "604800s", - "new": "259200s" + "new": "259200s", + "remote": "604800s" }, "pg_version": { "action": "skip", diff --git a/acceptance/bundle/resources/postgres_roles/update/out.plan.no_change.json b/acceptance/bundle/resources/postgres_roles/update/out.plan.no_change.json index 16cc6bd6a72..83c14867ea2 100644 --- a/acceptance/bundle/resources/postgres_roles/update/out.plan.no_change.json +++ b/acceptance/bundle/resources/postgres_roles/update/out.plan.no_change.json @@ -7,6 +7,9 @@ ], "action": "skip", "remote_state": { + "attributes": { + "createdb": false + }, "create_time": "[TIMESTAMP]", "name": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/test-role", "parent": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main", @@ -25,16 +28,6 @@ "update_time": "[TIMESTAMP]" }, "changes": { - "attributes": { - "action": "skip", - "reason": "spec:input_only", - "old": { - "createdb": false - }, - "new": { - "createdb": false - } - }, "postgres_role": { "action": "skip", "reason": "spec:input_only", diff --git a/acceptance/bundle/resources/postgres_roles/update/out.plan.restore.json b/acceptance/bundle/resources/postgres_roles/update/out.plan.restore.json index e6ff6664b92..65b18bf839c 100644 --- a/acceptance/bundle/resources/postgres_roles/update/out.plan.restore.json +++ b/acceptance/bundle/resources/postgres_roles/update/out.plan.restore.json @@ -17,6 +17,9 @@ } }, "remote_state": { + "attributes": { + "createdb": true + }, "create_time": "[TIMESTAMP]", "name": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/test-role", "parent": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main", @@ -35,19 +38,11 @@ "update_time": "[TIMESTAMP]" }, "changes": { - "attributes": { - "action": "update", - "old": { - "createdb": true - }, - "new": { - "createdb": false - } - }, "attributes.createdb": { "action": "update", "old": true, - "new": false + "new": false, + "remote": true }, "postgres_role": { "action": "skip", diff --git a/acceptance/bundle/resources/postgres_roles/update/out.plan.update.json b/acceptance/bundle/resources/postgres_roles/update/out.plan.update.json index 76b67ee2de5..5112db7c1b5 100644 --- a/acceptance/bundle/resources/postgres_roles/update/out.plan.update.json +++ b/acceptance/bundle/resources/postgres_roles/update/out.plan.update.json @@ -17,6 +17,9 @@ } }, "remote_state": { + "attributes": { + "createdb": false + }, "create_time": "[TIMESTAMP]", "name": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/test-role", "parent": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main", @@ -35,19 +38,11 @@ "update_time": "[TIMESTAMP]" }, "changes": { - "attributes": { - "action": "update", - "old": { - "createdb": false - }, - "new": { - "createdb": true - } - }, "attributes.createdb": { "action": "update", "old": false, - "new": true + "new": true, + "remote": false }, "postgres_role": { "action": "skip", diff --git a/bundle/direct/dresources/postgres_branch.go b/bundle/direct/dresources/postgres_branch.go index 19fac982f08..73c8b72c103 100644 --- a/bundle/direct/dresources/postgres_branch.go +++ b/bundle/direct/dresources/postgres_branch.go @@ -76,9 +76,8 @@ func (*ResourcePostgresBranch) RemapState(remote *PostgresBranchRemote) *Postgre } // makePostgresBranchRemote converts the SDK Branch into the embedded remote shape. -// GET does not echo spec today (only status is returned); the embedded spec fields -// stay at their zero values, and postgres_branches.yml suppresses phantom drift via -// ignore_remote_changes with reason spec:input_only. +// Since 2026-11 GET echoes spec, except for fields still marked spec:input_only +// in postgres_branches.yml, whose remote values stay empty. func makePostgresBranchRemote(branch *postgres.Branch) *PostgresBranchRemote { var spec postgres.BranchSpec if branch.Spec != nil { diff --git a/bundle/direct/dresources/postgres_database.go b/bundle/direct/dresources/postgres_database.go index 154163b4c8f..de50d0ecb81 100644 --- a/bundle/direct/dresources/postgres_database.go +++ b/bundle/direct/dresources/postgres_database.go @@ -70,9 +70,8 @@ func (*ResourcePostgresDatabase) RemapState(remote *PostgresDatabaseRemote) *Pos } // makePostgresDatabaseRemote converts the SDK Database into the embedded remote -// shape. GET does not echo spec today (only status is returned); the embedded -// spec fields stay at their zero values, and postgres_databases.yml suppresses phantom -// drift via ignore_remote_changes with reason spec:input_only. +// shape. Since 2026-11 GET echoes spec, except for fields still marked +// spec:input_only in postgres_databases.yml, whose remote values stay empty. func makePostgresDatabaseRemote(database *postgres.Database) *PostgresDatabaseRemote { var spec postgres.DatabaseDatabaseSpec if database.Spec != nil { diff --git a/bundle/direct/dresources/postgres_endpoint.go b/bundle/direct/dresources/postgres_endpoint.go index 48ea312005a..ff4fd9d05a0 100644 --- a/bundle/direct/dresources/postgres_endpoint.go +++ b/bundle/direct/dresources/postgres_endpoint.go @@ -79,9 +79,8 @@ func (*ResourcePostgresEndpoint) RemapState(remote *PostgresEndpointRemote) *Pos } // makePostgresEndpointRemote converts the SDK Endpoint into the embedded remote shape. -// GET does not echo spec today (only status is returned); the embedded spec fields -// stay at their zero values, and postgres_endpoints.yml suppresses phantom drift via -// ignore_remote_changes with reason spec:input_only. +// Since 2026-11 GET echoes spec, except for fields still marked spec:input_only +// in postgres_endpoints.yml, whose remote values stay empty. func makePostgresEndpointRemote(endpoint *postgres.Endpoint) *PostgresEndpointRemote { var spec postgres.EndpointSpec if endpoint.Spec != nil { diff --git a/bundle/direct/dresources/postgres_project.go b/bundle/direct/dresources/postgres_project.go index e62b87906cc..85851a26270 100644 --- a/bundle/direct/dresources/postgres_project.go +++ b/bundle/direct/dresources/postgres_project.go @@ -70,9 +70,8 @@ func (*ResourcePostgresProject) RemapState(remote *PostgresProjectRemote) *Postg } // makePostgresProjectRemote converts the SDK Project into the embedded remote shape. -// GET does not echo spec today (only status is returned); the embedded spec fields -// stay at their zero values, and postgres_projects.yml suppresses phantom drift via -// ignore_remote_changes with reason spec:input_only. +// Since 2026-11 GET echoes spec, except for fields still marked spec:input_only +// in postgres_projects.yml, whose remote values stay empty. func makePostgresProjectRemote(project *postgres.Project) *PostgresProjectRemote { var spec postgres.ProjectSpec if project.Spec != nil { diff --git a/bundle/direct/dresources/postgres_role.go b/bundle/direct/dresources/postgres_role.go index 43eef50a657..437c6088fe8 100644 --- a/bundle/direct/dresources/postgres_role.go +++ b/bundle/direct/dresources/postgres_role.go @@ -95,9 +95,8 @@ func (*ResourcePostgresRole) RemapState(remote *PostgresRoleRemote) *PostgresRol } // makePostgresRoleRemote converts the SDK Role into the embedded remote shape. -// GET does not echo spec today (only status is returned); the embedded spec fields -// stay at their zero values, and postgres_roles.yml suppresses phantom drift via -// ignore_remote_changes with reason spec:input_only. +// Since 2026-11 GET echoes spec, except for fields still marked spec:input_only +// in postgres_roles.yml, whose remote values stay empty. func makePostgresRoleRemote(role *postgres.Role) *PostgresRoleRemote { var spec postgres.RoleRoleSpec if role.Spec != nil { diff --git a/libs/testserver/postgres.go b/libs/testserver/postgres.go index f5848c58444..2c61b0f3114 100644 --- a/libs/testserver/postgres.go +++ b/libs/testserver/postgres.go @@ -152,8 +152,7 @@ func (s *FakeWorkspace) PostgresProjectCreate(req Request, projectID string) Res project.Status.DefaultEndpointSettings.SuspendTimeoutDuration = project.Spec.DefaultEndpointSettings.SuspendTimeoutDuration } } - // Clear spec so it's not returned in response (API only returns status) - project.Spec = nil + project.Spec = echoedSpec[postgres.ProjectSpec](nil, req.Body, "", projectOneofGroups, "pg_version") } s.PostgresProjects[name] = project @@ -249,6 +248,7 @@ func (s *FakeWorkspace) PostgresProjectUpdate(req Request, name string) Response } } + project.Spec = echoedSpec(project.Spec, req.Body, req.URL.Query().Get("update_mask"), projectOneofGroups, "pg_version") project.UpdateTime = nowTime() s.PostgresProjects[name] = project @@ -372,8 +372,7 @@ func (s *FakeWorkspace) PostgresBranchCreate(req Request, parent, branchID strin branch.Status.ExpireTime = branch.Spec.ExpireTime } - // Clear spec - API only returns status - branch.Spec = nil + branch.Spec = echoedSpec[postgres.BranchSpec](nil, req.Body, "", branchOneofGroups, "source_branch", "source_branch_lsn", "source_branch_time") s.PostgresBranches[name] = branch @@ -469,6 +468,7 @@ func (s *FakeWorkspace) PostgresBranchUpdate(req Request, name string) Response } } + branch.Spec = echoedSpec(branch.Spec, req.Body, req.URL.Query().Get("update_mask"), branchOneofGroups, "source_branch", "source_branch_lsn", "source_branch_time") branch.UpdateTime = nowTime() s.PostgresBranches[name] = branch @@ -678,8 +678,7 @@ func (s *FakeWorkspace) PostgresEndpointCreate(req Request, parent, endpointID s endpoint.Status.Disabled = endpoint.Spec.Disabled } - // Clear spec - API only returns status - endpoint.Spec = nil + endpoint.Spec = echoedSpec[postgres.EndpointSpec](nil, req.Body, "", endpointOneofGroups) s.PostgresEndpoints[name] = endpoint @@ -1061,6 +1060,7 @@ func (s *FakeWorkspace) PostgresEndpointUpdate(req Request, name string) Respons endpoint.Status.Disabled = updateEndpoint.Spec.Disabled } + endpoint.Spec = echoedSpec(endpoint.Spec, req.Body, req.URL.Query().Get("update_mask"), endpointOneofGroups) endpoint.UpdateTime = nowTime() s.PostgresEndpoints[name] = endpoint @@ -1147,7 +1147,7 @@ func (s *FakeWorkspace) PostgresDatabaseCreate(req Request, parent, databaseID s } existing.UpdateTime = now existing.Status = status - existing.Spec = nil + existing.Spec = echoedSpec[postgres.DatabaseDatabaseSpec](nil, req.Body, "", nil) s.PostgresDatabases[name] = existing return Response{ @@ -1161,14 +1161,14 @@ func (s *FakeWorkspace) PostgresDatabaseCreate(req Request, parent, databaseID s database.CreateTime = now database.UpdateTime = now - // Mirror spec onto status; the real API only echoes Status on GET. + // Mirror spec onto status. status := &postgres.DatabaseDatabaseStatus{ DatabaseId: databaseID, PostgresDatabase: database.Spec.PostgresDatabase, Role: database.Spec.Role, } database.Status = status - database.Spec = nil + database.Spec = echoedSpec[postgres.DatabaseDatabaseSpec](nil, req.Body, "", nil) s.PostgresDatabases[name] = database @@ -1264,6 +1264,7 @@ func (s *FakeWorkspace) PostgresDatabaseUpdate(req Request, name string) Respons database.Status.DatabaseId = databaseID } + database.Spec = echoedSpec(database.Spec, req.Body, req.URL.Query().Get("update_mask"), nil) database.UpdateTime = nowTime() s.PostgresDatabases[name] = database @@ -1273,7 +1274,7 @@ func (s *FakeWorkspace) PostgresDatabaseUpdate(req Request, name string) Respons } // databaseStatusFromSpec mirrors the real Postgres Database server's behavior of -// echoing the spec onto Status while leaving Spec=nil on GET responses. +// echoing the spec onto Status. func databaseStatusFromSpec(spec *postgres.DatabaseDatabaseSpec) *postgres.DatabaseDatabaseStatus { status := &postgres.DatabaseDatabaseStatus{} if spec == nil { @@ -1661,8 +1662,7 @@ func (s *FakeWorkspace) PostgresCatalogDelete(name string) Response { var roleIDPattern = regexp.MustCompile(`^[a-z][a-z0-9-]{3,62}$`) // roleStatusFromSpec mirrors the real Postgres Role server's behavior of echoing -// the spec onto Status (plus default-deriving fields the user did not specify) -// while leaving Spec=nil on GET responses. +// the spec onto Status (plus default-deriving fields the user did not specify). func roleStatusFromSpec(spec *postgres.RoleRoleSpec) *postgres.RoleRoleStatus { status := &postgres.RoleRoleStatus{} if spec == nil { @@ -1750,7 +1750,7 @@ func (s *FakeWorkspace) PostgresRoleCreate(req Request, parent, roleID string, r existing.UpdateTime = now existing.Status = roleStatusFromSpec(role.Spec) existing.Status.RoleId = roleID - existing.Spec = nil + existing.Spec = echoedSpec[postgres.RoleRoleSpec](nil, req.Body, "", nil, "postgres_role", "auth_method", "identity_type") s.PostgresRoles[name] = existing return Response{ @@ -1766,7 +1766,7 @@ func (s *FakeWorkspace) PostgresRoleCreate(req Request, parent, roleID string, r role.Status = roleStatusFromSpec(role.Spec) role.Status.RoleId = roleID - role.Spec = nil + role.Spec = echoedSpec[postgres.RoleRoleSpec](nil, req.Body, "", nil, "postgres_role", "auth_method", "identity_type") s.PostgresRoles[name] = role @@ -1865,6 +1865,7 @@ func (s *FakeWorkspace) PostgresRoleUpdate(req Request, name string) Response { role.Status.RoleId = roleID } + role.Spec = echoedSpec(role.Spec, req.Body, req.URL.Query().Get("update_mask"), nil, "postgres_role", "auth_method", "identity_type") role.UpdateTime = nowTime() s.PostgresRoles[name] = role diff --git a/libs/testserver/postgres_spec.go b/libs/testserver/postgres_spec.go new file mode 100644 index 00000000000..6efd59a2a77 --- /dev/null +++ b/libs/testserver/postgres_spec.go @@ -0,0 +1,150 @@ +package testserver + +import ( + "encoding/json" + "strings" +) + +// echoedSpec returns the spec the real API echoes back on GET after a create or +// update. Since 2026-11-12 the Lakebase API returns spec as stored: the fields the +// caller set (a field masked but absent from the body keeps its previous value), +// minus inputOnly fields that are consulted once and never echoed. Defaults the +// backend materializes appear only in status, not in spec. +// +// mask is the update_mask ("" on create, which takes the body's spec as is). +// oneofGroups uses the same "spec."-prefixed paths as the update mask validators; +// setting one member of a group clears its siblings. +func echoedSpec[T any](stored *T, body []byte, mask string, oneofGroups map[string][]string, inputOnly ...string) *T { + var req map[string]any + if err := json.Unmarshal(body, &req); err != nil { + return stored + } + bodySpec, ok := req["spec"].(map[string]any) + if !ok { + return stored + } + + result := map[string]any{} + if mask == "" { + result = bodySpec + } else { + if stored != nil { + raw, err := json.Marshal(stored) + if err != nil { + return stored + } + if err := json.Unmarshal(raw, &result); err != nil { + return stored + } + } + for path := range strings.SplitSeq(mask, ",") { + path = strings.TrimSpace(path) + if path == "spec" || path == "*" { + mergeSpecMap(result, bodySpec) + continue + } + rel, ok := strings.CutPrefix(path, "spec.") + if !ok { + continue + } + if members, isGroup := oneofGroups[path]; isGroup { + for _, m := range members { + parts := strings.Split(strings.TrimPrefix(m, "spec."), ".") + if v, ok := specMapGet(bodySpec, parts); ok { + specMapSet(result, parts, v) + } + } + continue + } + parts := strings.Split(rel, ".") + if v, ok := specMapGet(bodySpec, parts); ok { + specMapSet(result, parts, v) + } + } + } + + // A oneof holds one member: whichever the body set wins over the stored sibling. + for _, members := range oneofGroups { + var set []string + for _, m := range members { + if _, ok := specMapGet(bodySpec, strings.Split(strings.TrimPrefix(m, "spec."), ".")); ok { + set = append(set, m) + } + } + if len(set) == 0 { + continue + } + for _, m := range members { + if m != set[0] { + specMapDelete(result, strings.Split(strings.TrimPrefix(m, "spec."), ".")) + } + } + } + + for _, field := range inputOnly { + delete(result, field) + } + if len(result) == 0 { + return nil + } + + raw, err := json.Marshal(result) + if err != nil { + return stored + } + var spec T + if err := json.Unmarshal(raw, &spec); err != nil { + return stored + } + return &spec +} + +func mergeSpecMap(dst, src map[string]any) { + for k, v := range src { + srcChild, srcIsMap := v.(map[string]any) + dstChild, dstIsMap := dst[k].(map[string]any) + if srcIsMap && dstIsMap { + mergeSpecMap(dstChild, srcChild) + continue + } + dst[k] = v + } +} + +func specMapGet(m map[string]any, parts []string) (any, bool) { + var node any = m + for _, p := range parts { + mm, ok := node.(map[string]any) + if !ok { + return nil, false + } + node, ok = mm[p] + if !ok { + return nil, false + } + } + return node, true +} + +func specMapSet(m map[string]any, parts []string, v any) { + for _, p := range parts[:len(parts)-1] { + child, ok := m[p].(map[string]any) + if !ok { + child = map[string]any{} + m[p] = child + } + m = child + } + m[parts[len(parts)-1]] = v +} + +func specMapDelete(m map[string]any, parts []string) { + for _, p := range parts[:len(parts)-1] { + child, ok := m[p].(map[string]any) + if !ok { + return + } + m = child + } + delete(m, parts[len(parts)-1]) +} diff --git a/libs/testserver/postgres_spec_test.go b/libs/testserver/postgres_spec_test.go new file mode 100644 index 00000000000..d7bff18df0a --- /dev/null +++ b/libs/testserver/postgres_spec_test.go @@ -0,0 +1,40 @@ +package testserver + +import ( + "testing" + + "github.com/databricks/databricks-sdk-go/service/postgres" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestEchoedSpecCreateDropsInputOnly(t *testing.T) { + spec := echoedSpec[postgres.ProjectSpec](nil, []byte(`{"spec":{"display_name":"a","pg_version":16}}`), "", projectOneofGroups, "pg_version") + require.NotNil(t, spec) + assert.Equal(t, "a", spec.DisplayName) + assert.Equal(t, 0, spec.PgVersion) +} + +func TestEchoedSpecCreateKeepsExplicitFalse(t *testing.T) { + spec := echoedSpec[postgres.BranchSpec](nil, []byte(`{"spec":{"is_protected":false,"no_expiry":true}}`), "", branchOneofGroups) + require.NotNil(t, spec) + assert.Contains(t, spec.ForceSendFields, "IsProtected") + assert.True(t, spec.NoExpiry) +} + +func TestEchoedSpecUpdateOneofReplacesSibling(t *testing.T) { + stored := echoedSpec[postgres.BranchSpec](nil, []byte(`{"spec":{"is_protected":true,"no_expiry":true}}`), "", branchOneofGroups) + spec := echoedSpec(stored, []byte(`{"spec":{"ttl":"3600s"}}`), "spec.expiration", branchOneofGroups) + require.NotNil(t, spec) + assert.False(t, spec.NoExpiry) + require.NotNil(t, spec.Ttl) + assert.True(t, spec.IsProtected, "fields outside the mask keep their stored value") +} + +func TestEchoedSpecUpdateMaskedButAbsentKeepsPrevious(t *testing.T) { + stored := echoedSpec[postgres.ProjectSpec](nil, []byte(`{"spec":{"display_name":"a","history_retention_duration":"604800s"}}`), "", projectOneofGroups) + spec := echoedSpec(stored, []byte(`{"spec":{"display_name":"b"}}`), "spec", projectOneofGroups) + require.NotNil(t, spec) + assert.Equal(t, "b", spec.DisplayName) + require.NotNil(t, spec.HistoryRetentionDuration) +} From e86837fb354f56f30ff590c33efed83d0f857c70 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Fri, 13 Nov 2026 09:43:23 +0000 Subject: [PATCH 2/2] testserver: keep a oneof member the update mask does not cover Review follow-ups: clear a stored oneof sibling only when the update mask covers the group; name the input-only spec field lists once; document the spec map helpers; say in the dresources comments that the input_only marks live in the generated configs and still suppress remote changes. cloud: TestAccept/bundle/resources/postgres_projects TestAccept/bundle/resources/postgres_branches TestAccept/bundle/resources/postgres_endpoints TestAccept/bundle/resources/postgres_databases TestAccept/bundle/resources/postgres_roles Co-authored-by: Isaac --- bundle/direct/dresources/postgres_branch.go | 5 +- bundle/direct/dresources/postgres_database.go | 5 +- bundle/direct/dresources/postgres_endpoint.go | 5 +- bundle/direct/dresources/postgres_project.go | 5 +- bundle/direct/dresources/postgres_role.go | 5 +- libs/testserver/postgres.go | 14 ++--- libs/testserver/postgres_spec.go | 59 +++++++++++++++---- libs/testserver/postgres_spec_test.go | 9 +++ 8 files changed, 79 insertions(+), 28 deletions(-) diff --git a/bundle/direct/dresources/postgres_branch.go b/bundle/direct/dresources/postgres_branch.go index 73c8b72c103..ffcd648d964 100644 --- a/bundle/direct/dresources/postgres_branch.go +++ b/bundle/direct/dresources/postgres_branch.go @@ -76,8 +76,9 @@ func (*ResourcePostgresBranch) RemapState(remote *PostgresBranchRemote) *Postgre } // makePostgresBranchRemote converts the SDK Branch into the embedded remote shape. -// Since 2026-11 GET echoes spec, except for fields still marked spec:input_only -// in postgres_branches.yml, whose remote values stay empty. +// Since 2026-11 GET echoes spec. Fields still marked spec:input_only in +// postgres_branches.generated.yml keep remote changes ignored until the OpenAPI +// annotations, and the config generated from them, catch up. func makePostgresBranchRemote(branch *postgres.Branch) *PostgresBranchRemote { var spec postgres.BranchSpec if branch.Spec != nil { diff --git a/bundle/direct/dresources/postgres_database.go b/bundle/direct/dresources/postgres_database.go index de50d0ecb81..b3b732fe45a 100644 --- a/bundle/direct/dresources/postgres_database.go +++ b/bundle/direct/dresources/postgres_database.go @@ -70,8 +70,9 @@ func (*ResourcePostgresDatabase) RemapState(remote *PostgresDatabaseRemote) *Pos } // makePostgresDatabaseRemote converts the SDK Database into the embedded remote -// shape. Since 2026-11 GET echoes spec, except for fields still marked -// spec:input_only in postgres_databases.yml, whose remote values stay empty. +// shape. Since 2026-11 GET echoes spec. Fields still marked spec:input_only in +// postgres_databases.generated.yml keep remote changes ignored until the OpenAPI +// annotations, and the config generated from them, catch up. func makePostgresDatabaseRemote(database *postgres.Database) *PostgresDatabaseRemote { var spec postgres.DatabaseDatabaseSpec if database.Spec != nil { diff --git a/bundle/direct/dresources/postgres_endpoint.go b/bundle/direct/dresources/postgres_endpoint.go index ff4fd9d05a0..b2e305d3ef3 100644 --- a/bundle/direct/dresources/postgres_endpoint.go +++ b/bundle/direct/dresources/postgres_endpoint.go @@ -79,8 +79,9 @@ func (*ResourcePostgresEndpoint) RemapState(remote *PostgresEndpointRemote) *Pos } // makePostgresEndpointRemote converts the SDK Endpoint into the embedded remote shape. -// Since 2026-11 GET echoes spec, except for fields still marked spec:input_only -// in postgres_endpoints.yml, whose remote values stay empty. +// Since 2026-11 GET echoes spec. Fields still marked spec:input_only in +// postgres_endpoints.generated.yml keep remote changes ignored until the OpenAPI +// annotations, and the config generated from them, catch up. func makePostgresEndpointRemote(endpoint *postgres.Endpoint) *PostgresEndpointRemote { var spec postgres.EndpointSpec if endpoint.Spec != nil { diff --git a/bundle/direct/dresources/postgres_project.go b/bundle/direct/dresources/postgres_project.go index 85851a26270..8d96a480b67 100644 --- a/bundle/direct/dresources/postgres_project.go +++ b/bundle/direct/dresources/postgres_project.go @@ -70,8 +70,9 @@ func (*ResourcePostgresProject) RemapState(remote *PostgresProjectRemote) *Postg } // makePostgresProjectRemote converts the SDK Project into the embedded remote shape. -// Since 2026-11 GET echoes spec, except for fields still marked spec:input_only -// in postgres_projects.yml, whose remote values stay empty. +// Since 2026-11 GET echoes spec. Fields still marked spec:input_only in +// postgres_projects.generated.yml keep remote changes ignored until the OpenAPI +// annotations, and the config generated from them, catch up. func makePostgresProjectRemote(project *postgres.Project) *PostgresProjectRemote { var spec postgres.ProjectSpec if project.Spec != nil { diff --git a/bundle/direct/dresources/postgres_role.go b/bundle/direct/dresources/postgres_role.go index 437c6088fe8..e18380ebcd6 100644 --- a/bundle/direct/dresources/postgres_role.go +++ b/bundle/direct/dresources/postgres_role.go @@ -95,8 +95,9 @@ func (*ResourcePostgresRole) RemapState(remote *PostgresRoleRemote) *PostgresRol } // makePostgresRoleRemote converts the SDK Role into the embedded remote shape. -// Since 2026-11 GET echoes spec, except for fields still marked spec:input_only -// in postgres_roles.yml, whose remote values stay empty. +// Since 2026-11 GET echoes spec. Fields still marked spec:input_only in +// postgres_roles.generated.yml keep remote changes ignored until the OpenAPI +// annotations, and the config generated from them, catch up. func makePostgresRoleRemote(role *postgres.Role) *PostgresRoleRemote { var spec postgres.RoleRoleSpec if role.Spec != nil { diff --git a/libs/testserver/postgres.go b/libs/testserver/postgres.go index 2c61b0f3114..05169390ac5 100644 --- a/libs/testserver/postgres.go +++ b/libs/testserver/postgres.go @@ -152,7 +152,7 @@ func (s *FakeWorkspace) PostgresProjectCreate(req Request, projectID string) Res project.Status.DefaultEndpointSettings.SuspendTimeoutDuration = project.Spec.DefaultEndpointSettings.SuspendTimeoutDuration } } - project.Spec = echoedSpec[postgres.ProjectSpec](nil, req.Body, "", projectOneofGroups, "pg_version") + project.Spec = echoedSpec[postgres.ProjectSpec](nil, req.Body, "", projectOneofGroups, projectInputOnlySpecFields...) } s.PostgresProjects[name] = project @@ -248,7 +248,7 @@ func (s *FakeWorkspace) PostgresProjectUpdate(req Request, name string) Response } } - project.Spec = echoedSpec(project.Spec, req.Body, req.URL.Query().Get("update_mask"), projectOneofGroups, "pg_version") + project.Spec = echoedSpec(project.Spec, req.Body, req.URL.Query().Get("update_mask"), projectOneofGroups, projectInputOnlySpecFields...) project.UpdateTime = nowTime() s.PostgresProjects[name] = project @@ -372,7 +372,7 @@ func (s *FakeWorkspace) PostgresBranchCreate(req Request, parent, branchID strin branch.Status.ExpireTime = branch.Spec.ExpireTime } - branch.Spec = echoedSpec[postgres.BranchSpec](nil, req.Body, "", branchOneofGroups, "source_branch", "source_branch_lsn", "source_branch_time") + branch.Spec = echoedSpec[postgres.BranchSpec](nil, req.Body, "", branchOneofGroups, branchInputOnlySpecFields...) s.PostgresBranches[name] = branch @@ -468,7 +468,7 @@ func (s *FakeWorkspace) PostgresBranchUpdate(req Request, name string) Response } } - branch.Spec = echoedSpec(branch.Spec, req.Body, req.URL.Query().Get("update_mask"), branchOneofGroups, "source_branch", "source_branch_lsn", "source_branch_time") + branch.Spec = echoedSpec(branch.Spec, req.Body, req.URL.Query().Get("update_mask"), branchOneofGroups, branchInputOnlySpecFields...) branch.UpdateTime = nowTime() s.PostgresBranches[name] = branch @@ -1750,7 +1750,7 @@ func (s *FakeWorkspace) PostgresRoleCreate(req Request, parent, roleID string, r existing.UpdateTime = now existing.Status = roleStatusFromSpec(role.Spec) existing.Status.RoleId = roleID - existing.Spec = echoedSpec[postgres.RoleRoleSpec](nil, req.Body, "", nil, "postgres_role", "auth_method", "identity_type") + existing.Spec = echoedSpec[postgres.RoleRoleSpec](nil, req.Body, "", nil, roleInputOnlySpecFields...) s.PostgresRoles[name] = existing return Response{ @@ -1766,7 +1766,7 @@ func (s *FakeWorkspace) PostgresRoleCreate(req Request, parent, roleID string, r role.Status = roleStatusFromSpec(role.Spec) role.Status.RoleId = roleID - role.Spec = echoedSpec[postgres.RoleRoleSpec](nil, req.Body, "", nil, "postgres_role", "auth_method", "identity_type") + role.Spec = echoedSpec[postgres.RoleRoleSpec](nil, req.Body, "", nil, roleInputOnlySpecFields...) s.PostgresRoles[name] = role @@ -1865,7 +1865,7 @@ func (s *FakeWorkspace) PostgresRoleUpdate(req Request, name string) Response { role.Status.RoleId = roleID } - role.Spec = echoedSpec(role.Spec, req.Body, req.URL.Query().Get("update_mask"), nil, "postgres_role", "auth_method", "identity_type") + role.Spec = echoedSpec(role.Spec, req.Body, req.URL.Query().Get("update_mask"), nil, roleInputOnlySpecFields...) role.UpdateTime = nowTime() s.PostgresRoles[name] = role diff --git a/libs/testserver/postgres_spec.go b/libs/testserver/postgres_spec.go index 6efd59a2a77..f55a2952085 100644 --- a/libs/testserver/postgres_spec.go +++ b/libs/testserver/postgres_spec.go @@ -2,16 +2,20 @@ package testserver import ( "encoding/json" + "slices" "strings" ) // echoedSpec returns the spec the real API echoes back on GET after a create or -// update. Since 2026-11-12 the Lakebase API returns spec as stored: the fields the +// update. Since 2026-11-12 the API returns spec as stored for projects, branches, +// endpoints, databases and roles (catalogs, data APIs and synced tables were not +// observed to change and still return status only): the fields the // caller set (a field masked but absent from the body keeps its previous value), // minus inputOnly fields that are consulted once and never echoed. Defaults the // backend materializes appear only in status, not in spec. // -// mask is the update_mask ("" on create, which takes the body's spec as is). +// mask is the update_mask. "" takes the body's spec as is: on create, and on an +// unmasked update, matching how the status of databases and roles is replaced. // oneofGroups uses the same "spec."-prefixed paths as the update mask validators; // setting one member of a group clears its siblings. func echoedSpec[T any](stored *T, body []byte, mask string, oneofGroups map[string][]string, inputOnly ...string) *T { @@ -49,7 +53,7 @@ func echoedSpec[T any](stored *T, body []byte, mask string, oneofGroups map[stri } if members, isGroup := oneofGroups[path]; isGroup { for _, m := range members { - parts := strings.Split(strings.TrimPrefix(m, "spec."), ".") + parts := specPathParts(m) if v, ok := specMapGet(bodySpec, parts); ok { specMapSet(result, parts, v) } @@ -63,20 +67,25 @@ func echoedSpec[T any](stored *T, body []byte, mask string, oneofGroups map[stri } } - // A oneof holds one member: whichever the body set wins over the stored sibling. - for _, members := range oneofGroups { - var set []string + // A oneof holds one member: when the request sets the group, its member replaces + // the stored sibling. A group the mask does not cover keeps its stored member. + for group, members := range oneofGroups { + if mask != "" && !maskSetsGroup(mask, group, members) { + continue + } + var set string for _, m := range members { - if _, ok := specMapGet(bodySpec, strings.Split(strings.TrimPrefix(m, "spec."), ".")); ok { - set = append(set, m) + if _, ok := specMapGet(bodySpec, specPathParts(m)); ok { + set = m + break } } - if len(set) == 0 { + if set == "" { continue } for _, m := range members { - if m != set[0] { - specMapDelete(result, strings.Split(strings.TrimPrefix(m, "spec."), ".")) + if m != set { + specMapDelete(result, specPathParts(m)) } } } @@ -99,6 +108,24 @@ func echoedSpec[T any](stored *T, body []byte, mask string, oneofGroups map[stri return &spec } +// maskSetsGroup reports whether update_mask covers the oneof group: the whole spec, +// the group itself, or one of its members. +func maskSetsGroup(mask, group string, members []string) bool { + for path := range strings.SplitSeq(mask, ",") { + path = strings.TrimSpace(path) + if path == "spec" || path == "*" || path == group || slices.Contains(members, path) { + return true + } + } + return false +} + +// specPathParts splits a "spec."-prefixed mask path into keys relative to the spec. +func specPathParts(path string) []string { + return strings.Split(strings.TrimPrefix(path, "spec."), ".") +} + +// mergeSpecMap deep-merges src into dst; keys absent from src keep their dst value. func mergeSpecMap(dst, src map[string]any) { for k, v := range src { srcChild, srcIsMap := v.(map[string]any) @@ -111,6 +138,7 @@ func mergeSpecMap(dst, src map[string]any) { } } +// specMapGet returns the value at parts in m, if present. func specMapGet(m map[string]any, parts []string) (any, bool) { var node any = m for _, p := range parts { @@ -126,6 +154,7 @@ func specMapGet(m map[string]any, parts []string) (any, bool) { return node, true } +// specMapSet sets the value at parts in m, creating intermediate maps. func specMapSet(m map[string]any, parts []string, v any) { for _, p := range parts[:len(parts)-1] { child, ok := m[p].(map[string]any) @@ -138,6 +167,7 @@ func specMapSet(m map[string]any, parts []string, v any) { m[parts[len(parts)-1]] = v } +// specMapDelete removes the value at parts from m, if present. func specMapDelete(m map[string]any, parts []string) { for _, p := range parts[:len(parts)-1] { child, ok := m[p].(map[string]any) @@ -148,3 +178,10 @@ func specMapDelete(m map[string]any, parts []string) { } delete(m, parts[len(parts)-1]) } + +// Spec fields the API consults once and does not echo back on GET. +var ( + projectInputOnlySpecFields = []string{"pg_version"} + branchInputOnlySpecFields = []string{"source_branch", "source_branch_lsn", "source_branch_time"} + roleInputOnlySpecFields = []string{"postgres_role", "auth_method", "identity_type"} +) diff --git a/libs/testserver/postgres_spec_test.go b/libs/testserver/postgres_spec_test.go index d7bff18df0a..5262de35fe4 100644 --- a/libs/testserver/postgres_spec_test.go +++ b/libs/testserver/postgres_spec_test.go @@ -38,3 +38,12 @@ func TestEchoedSpecUpdateMaskedButAbsentKeepsPrevious(t *testing.T) { assert.Equal(t, "b", spec.DisplayName) require.NotNil(t, spec.HistoryRetentionDuration) } + +func TestEchoedSpecUpdateKeepsOneofOutsideMask(t *testing.T) { + stored := echoedSpec[postgres.BranchSpec](nil, []byte(`{"spec":{"ttl":"3600s"}}`), "", branchOneofGroups) + spec := echoedSpec(stored, []byte(`{"spec":{"is_protected":true,"no_expiry":true}}`), "spec.is_protected", branchOneofGroups) + require.NotNil(t, spec) + assert.True(t, spec.IsProtected) + assert.NotNil(t, spec.Ttl, "a oneof the mask does not cover keeps its stored member") + assert.False(t, spec.NoExpiry) +}