diff --git a/.agents/rules/testing.md b/.agents/rules/testing.md index 1f6af36d68c..4c82bd7b3b0 100644 --- a/.agents/rules/testing.md +++ b/.agents/rules/testing.md @@ -180,12 +180,15 @@ Available on `PATH` during test execution (from `acceptance/bin/`): - `find.py REGEX [--expect N]`: find files matching regex in current directory. `--expect N` asserts an exact count. - `diff.py DIR1 DIR2` or `diff.py FILE1 FILE2`: recursive diff with test replacements applied. - `print_state.py [-t TARGET] [--backup]`: print deployment state (`resources.json`, or a terraform state left by an older CLI). +- `plan_filter.py [RESOURCE_KEY]`: filter `bundle plan -o json` on stdin for a golden: drops every entry's `remote_state` and the deployment stamp (as `nostamp` does); with RESOURCE_KEY, prints only that entry. Errors if the key is not in the plan. - `edit_resource.py TYPE ID < script.py`: fetch resource by ID, execute Python on it (resource in `r`), then update it. TYPE is `jobs` or `pipelines`. - `gron.py`: flatten JSON into greppable discrete assignments (simpler than `jq` for searching JSON). - `jq` is also available for JSON processing. **RULE: Prefer `gron.py | grep ` over inline `jq` paths for single-value lookups.** The gron output prints the JSON path inline, so the test log explains itself. +**RULE: Record whole plan entries with `plan_filter.py` unless the test asserts on `remote_state` itself.** A narrower projection such as `nostamp | jq '.plan[KEY] | {action, changes}'` is fine as is. `remote_state` is the backend's GET payload as is (status, timestamps, sizes, fields the backend adds), so a golden that records it breaks on backend changes that leave the plan's action and changes untouched, on every cloud at once. `changes[*].remote` still records the remote value of each field with a change entry. + **RULE: Don't pass `--keep` to `print_requests.py` if a later `print_requests.py` call follows.** The buffer accumulates, so the second call double-prints the earlier requests. **RULE: Filter recorded requests with `print_requests.py`, never with a hand-written `jq 'select(...)' out.requests.txt` pipeline** — inline, or hidden inside a local `print_requests()` shell function. The helper already excludes GET, normalizes query strings, optionally sorts, and deletes `out.requests.txt` afterwards. A copy-pasted `jq` wrapper reimplements all of that, drifts from the canonical output format, and is the single most common acceptance-test anti-pattern in this repo. Wrapping `print_requests.py` *itself* in a local function is fine — e.g. to send each variant's output to its own `out.requests..json`. Reach for `jq` on `out.requests.txt` only for what `print_requests.py` genuinely can't express: filtering on request *body* content, or deleting noisy body fields (prefer a `Repls` entry in `test.toml` even then). diff --git a/acceptance/bin/plan_filter.py b/acceptance/bin/plan_filter.py new file mode 100755 index 00000000000..2782e77dd99 --- /dev/null +++ b/acceptance/bin/plan_filter.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""Read `bundle plan -o json` on stdin and write the part of it a golden should record. + +A plan entry's remote_state is the backend's GET payload, copied as is: it carries +backend-computed fields (status, timestamps, sizes, UIDs) and every field the backend +starts or stops returning. Recording it makes a golden fail on backend changes that +leave the CLI's decision (action, new_state, changes) untouched, often on every cloud +and test at once. This drops remote_state from every entry; changes[*].remote still +records the remote value of each field with a change entry. + +Also removes the deployment stamp, as nostamp.py does, so it replaces +`nostamp | jq '.plan["KEY"] | del(.remote_state)'`. + +Usage: + $CLI bundle plan -o json | plan_filter.py # whole plan + $CLI bundle plan -o json | plan_filter.py resources.jobs.foo # one entry + +A test that asserts on remote_state itself should not use this. +""" + +import argparse +import json +import sys + +import nostamp + + +def filter_plan(data, key=None): + entries = data.get("plan") if isinstance(data, dict) else None + if not isinstance(entries, dict): + raise SystemExit("plan_filter.py: input is not a plan: no 'plan' object") + for entry in entries.values(): + if isinstance(entry, dict): + entry.pop("remote_state", None) + if key is None: + return data + if key not in entries: + raise SystemExit(f"plan_filter.py: no plan entry {key!r}; entries: {sorted(entries)}") + return entries[key] + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("key", nargs="?", help="resource key of the one entry to print, e.g. resources.jobs.foo") + args = parser.parse_args() + text = sys.stdin.read() + try: + data = json.loads(text) + except json.JSONDecodeError as ex: + raise SystemExit(f"plan_filter.py: input is not JSON ({ex}): {text[:200]!r}") from None + data = filter_plan(data, args.key) + sys.stdout.write(nostamp.render(data, 2) + "\n") + + +if __name__ == "__main__": + main() 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 35984abba61..8ce0136dad7 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 @@ -5,25 +5,5 @@ "label": "${resources.postgres_projects.my_project.id}" } ], - "action": "skip", - "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", - "current_state": "READY", - "default": false, - "is_protected": false, - "source_branch": "projects/test-pg-proj-[UNIQUE_NAME]/branches/production", - "source_branch_lsn": "[LSN]", - "source_branch_time": "[TIMESTAMP]", - "state_change_time": "[TIMESTAMP]" - }, - "uid": "[BRANCH_UID]", - "update_time": "[TIMESTAMP]" - } + "action": "skip" } 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 8c543fd4230..af2bda86ad0 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 @@ -14,26 +14,6 @@ "parent": "projects/test-pg-proj-[UNIQUE_NAME]" } }, - "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", - "current_state": "READY", - "default": false, - "is_protected": true, - "source_branch": "projects/test-pg-proj-[UNIQUE_NAME]/branches/production", - "source_branch_lsn": "[LSN]", - "source_branch_time": "[TIMESTAMP]", - "state_change_time": "[TIMESTAMP]" - }, - "uid": "[BRANCH_UID]", - "update_time": "[TIMESTAMP]" - }, "changes": { "is_protected": { "action": "update", 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 d05e254629a..00a53a0975c 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 @@ -14,26 +14,6 @@ "parent": "projects/test-pg-proj-[UNIQUE_NAME]" } }, - "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", - "current_state": "READY", - "default": false, - "is_protected": false, - "source_branch": "projects/test-pg-proj-[UNIQUE_NAME]/branches/production", - "source_branch_lsn": "[LSN]", - "source_branch_time": "[TIMESTAMP]", - "state_change_time": "[TIMESTAMP]" - }, - "uid": "[BRANCH_UID]", - "update_time": "[TIMESTAMP]" - }, "changes": { "is_protected": { "action": "update", diff --git a/acceptance/bundle/resources/postgres_branches/update_protected/script b/acceptance/bundle/resources/postgres_branches/update_protected/script index a773aef576b..9e3d3184846 100755 --- a/acceptance/bundle/resources/postgres_branches/update_protected/script +++ b/acceptance/bundle/resources/postgres_branches/update_protected/script @@ -15,7 +15,7 @@ print_requests() { title "Initial deployment" trace $CLI bundle validate trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_branches.dev_branch" // .' > out.plan.create.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_branches.dev_branch > out.plan.create.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -28,7 +28,7 @@ trace $CLI postgres get-branch "${branch_name}" | branch_fields title "Verify no_change (no changes)" trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '(.plan."resources.postgres_branches.dev_branch" // .) | del(.remote_state.status.logical_size_bytes)' > out.plan.no_change.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_branches.dev_branch > out.plan.no_change.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -39,7 +39,7 @@ trace update_file.py databricks.yml "is_protected: false" "is_protected: true" trace cat databricks.yml trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '(.plan."resources.postgres_branches.dev_branch" // .) | del(.remote_state.status.logical_size_bytes)' > out.plan.update.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_branches.dev_branch > out.plan.update.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -51,7 +51,7 @@ trace $CLI postgres get-branch "${branch_name}" | branch_fields title "Restore is_protected to false" trace update_file.py databricks.yml "is_protected: true" "is_protected: false" trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '(.plan."resources.postgres_branches.dev_branch" // .) | del(.remote_state.status.logical_size_bytes)' > out.plan.restore.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_branches.dev_branch > out.plan.restore.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy 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 29c2d77a396..9e4252f970d 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 @@ -9,19 +9,5 @@ "label": "${resources.postgres_roles.owner.id}" } ], - "action": "skip", - "remote_state": { - "create_time": "[TIMESTAMP]", - "database_id": "my-database", - "name": "[MY_DATABASE_ID]", - "parent": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main", - "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]" - } + "action": "skip" } 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 fdcd3a5c407..c3540964cf5 100644 --- a/acceptance/bundle/resources/postgres_databases/update/out.plan.restore.json +++ b/acceptance/bundle/resources/postgres_databases/update/out.plan.restore.json @@ -18,20 +18,6 @@ "role": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner" } }, - "remote_state": { - "create_time": "[TIMESTAMP]", - "database_id": "my-database", - "name": "[MY_DATABASE_ID]", - "parent": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main", - "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", - "role": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner" - }, - "update_time": "[TIMESTAMP]" - }, "changes": { "postgres_database": { "action": "update", 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 07f974b0725..b6ce8f88373 100644 --- a/acceptance/bundle/resources/postgres_databases/update/out.plan.update.json +++ b/acceptance/bundle/resources/postgres_databases/update/out.plan.update.json @@ -18,20 +18,6 @@ "role": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main/roles/app-owner" } }, - "remote_state": { - "create_time": "[TIMESTAMP]", - "database_id": "my-database", - "name": "[MY_DATABASE_ID]", - "parent": "projects/test-pg-proj-[UNIQUE_NAME]/branches/main", - "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": "update", diff --git a/acceptance/bundle/resources/postgres_databases/update/script b/acceptance/bundle/resources/postgres_databases/update/script index 96afa5b6714..93042db7f09 100644 --- a/acceptance/bundle/resources/postgres_databases/update/script +++ b/acceptance/bundle/resources/postgres_databases/update/script @@ -15,7 +15,7 @@ print_requests() { title "Initial deployment" trace $CLI bundle validate trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_databases.my_database" // .' > out.plan.create.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_databases.my_database > out.plan.create.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -29,7 +29,7 @@ trace $CLI postgres get-database "${database_name}" | database_fields title "Verify no changes" trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_databases.my_database" // .' > out.plan.no_change.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_databases.my_database > out.plan.no_change.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -40,7 +40,7 @@ trace update_file.py databricks.yml "postgres_database: initial_db_name" "postgr trace cat databricks.yml trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_databases.my_database" // .' > out.plan.update.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_databases.my_database > out.plan.update.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -52,7 +52,7 @@ trace $CLI postgres get-database "${database_name}" | database_fields title "Restore postgres_database to original value" trace update_file.py databricks.yml "postgres_database: renamed_db_name" "postgres_database: initial_db_name" trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_databases.my_database" // .' > out.plan.restore.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_databases.my_database > out.plan.restore.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy diff --git a/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/script b/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/script index cb2e58e132e..52d4f092df3 100755 --- a/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/script +++ b/acceptance/bundle/resources/postgres_endpoints/update_autoscaling/script @@ -15,7 +15,7 @@ print_requests() { title "Initial deployment" trace $CLI bundle validate trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_endpoints.my_endpoint" // . | del(.remote_state)' > out.plan.create.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_endpoints.my_endpoint > out.plan.create.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -29,7 +29,7 @@ trace $CLI postgres get-endpoint "${endpoint_name}" | endpoint_fields title "Verify no changes" trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_endpoints.my_endpoint" // . | del(.remote_state)' > out.plan.no_change.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_endpoints.my_endpoint > out.plan.no_change.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -40,7 +40,7 @@ trace update_file.py databricks.yml "autoscaling_limit_max_cu: 8" "autoscaling_l trace cat databricks.yml trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_endpoints.my_endpoint" // . | del(.remote_state)' > out.plan.update.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_endpoints.my_endpoint > out.plan.update.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -52,7 +52,7 @@ trace $CLI postgres get-endpoint "${endpoint_name}" | endpoint_fields title "Restore endpoint autoscaling to original value" trace update_file.py databricks.yml "autoscaling_limit_max_cu: 4" "autoscaling_limit_max_cu: 8" trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_endpoints.my_endpoint" // . | del(.remote_state)' > out.plan.restore.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_endpoints.my_endpoint > out.plan.restore.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy 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 5c66eb28b29..e0a36346d9a 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 @@ -1,7 +1,7 @@ { "plan_version": [PLAN_VERSION], "cli_version": "[CLI_VERSION]", - "lineage": "[UUID][0]", + "lineage": "[UUID]", "serial": 1, "plan": { "resources.postgres_projects.my_project": { @@ -18,31 +18,6 @@ "project_id": "test-pg-proj-[UNIQUE_NAME]" } }, - "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": { - "branch_logical_size_limit_bytes": [BRANCH_SIZE_LIMIT], - "default_branch": "projects/test-pg-proj-[UNIQUE_NAME]/branches/production", - "default_endpoint_settings": { - "autoscaling_limit_max_cu": 1, - "autoscaling_limit_min_cu": 1, - "suspend_timeout_duration": "86400s" - }, - "display_name": "Test Project for Adding Default Endpoint Settings", - "enable_pg_native_login": false, - "history_retention_duration": "604800s", - "owner": "[USERNAME]", - "pg_version": 16, - "project_id": "test-pg-proj-[UNIQUE_NAME]", - "synthetic_storage_size_bytes": 0 - }, - "uid": "[UUID][1]", - "update_time": "[TIMESTAMP]" - }, "changes": { "default_endpoint_settings": { "action": "update", diff --git a/acceptance/bundle/resources/postgres_projects/add_default_endpoint_settings/script b/acceptance/bundle/resources/postgres_projects/add_default_endpoint_settings/script index 7c442d6aae7..ff5a57ce67b 100644 --- a/acceptance/bundle/resources/postgres_projects/add_default_endpoint_settings/script +++ b/acceptance/bundle/resources/postgres_projects/add_default_endpoint_settings/script @@ -14,7 +14,7 @@ trace update_file.py databricks.yml "#TO_ADD: " "" # The direct plan's "changes" map is the structdiff artifact: it records one # change at path default_endpoint_settings (the whole block) instead of descending # to its leaves. (The top-level plan verdict is 'update' on both engines.) -$CLI bundle plan -o json | nostamp > out.plan.json +$CLI bundle plan -o json | plan_filter.py > out.plan.json # The consequence shows up at deploy time, which diverges by engine, so route it to # per-engine files. Masking the whole message means the API requires the suspension diff --git a/acceptance/bundle/resources/postgres_projects/update_display_name/script b/acceptance/bundle/resources/postgres_projects/update_display_name/script index 918b85ac07d..f4d4ab3e73e 100755 --- a/acceptance/bundle/resources/postgres_projects/update_display_name/script +++ b/acceptance/bundle/resources/postgres_projects/update_display_name/script @@ -15,7 +15,7 @@ print_requests() { title "Initial deployment" trace $CLI bundle validate trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_projects.my_project" // .' > out.plan.create.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_projects.my_project > out.plan.create.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -26,10 +26,8 @@ project_id_1=`read_id.py my_project` trace $CLI postgres get-project "${project_name}" | project_fields title "Verify no changes" -# remote_state is the full GetProject payload, whose backend-computed status fields -# (e.g. compute_last_active_time) come and go; changes[*].remote still records the remote value. trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '(.plan."resources.postgres_projects.my_project" // .) | del(.remote_state)' > out.plan.no_change.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_projects.my_project > out.plan.no_change.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -40,7 +38,7 @@ trace update_file.py databricks.yml "Original Name" "Updated Name" trace cat databricks.yml trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '(.plan."resources.postgres_projects.my_project" // .) | del(.remote_state)' > out.plan.update.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_projects.my_project > out.plan.update.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -52,7 +50,7 @@ trace $CLI postgres get-project "${project_name}" | project_fields title "Restore display_name to original value" trace update_file.py databricks.yml "Updated Name" "Original Name" trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '(.plan."resources.postgres_projects.my_project" // .) | del(.remote_state)' > out.plan.restore.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_projects.my_project > out.plan.restore.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy 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 83c14867ea2..92092a8a785 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 @@ -6,27 +6,6 @@ } ], "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", - "role_id": "test-role", - "status": { - "attributes": { - "bypassrls": false, - "createdb": false, - "createrole": false - }, - "auth_method": "PG_PASSWORD_SCRAM_SHA_256", - "identity_type": "IDENTITY_TYPE_UNSPECIFIED", - "postgres_role": "app_role", - "role_id": "test-role" - }, - "update_time": "[TIMESTAMP]" - }, "changes": { "postgres_role": { "action": "skip", 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 65b18bf839c..9bd2addb9a3 100644 --- a/acceptance/bundle/resources/postgres_roles/update/out.plan.restore.json +++ b/acceptance/bundle/resources/postgres_roles/update/out.plan.restore.json @@ -16,27 +16,6 @@ "role_id": "test-role" } }, - "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", - "role_id": "test-role", - "status": { - "attributes": { - "bypassrls": false, - "createdb": true, - "createrole": false - }, - "auth_method": "PG_PASSWORD_SCRAM_SHA_256", - "identity_type": "IDENTITY_TYPE_UNSPECIFIED", - "postgres_role": "app_role", - "role_id": "test-role" - }, - "update_time": "[TIMESTAMP]" - }, "changes": { "attributes.createdb": { "action": "update", 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 5112db7c1b5..f8c748ef95c 100644 --- a/acceptance/bundle/resources/postgres_roles/update/out.plan.update.json +++ b/acceptance/bundle/resources/postgres_roles/update/out.plan.update.json @@ -16,27 +16,6 @@ "role_id": "test-role" } }, - "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", - "role_id": "test-role", - "status": { - "attributes": { - "bypassrls": false, - "createdb": false, - "createrole": false - }, - "auth_method": "PG_PASSWORD_SCRAM_SHA_256", - "identity_type": "IDENTITY_TYPE_UNSPECIFIED", - "postgres_role": "app_role", - "role_id": "test-role" - }, - "update_time": "[TIMESTAMP]" - }, "changes": { "attributes.createdb": { "action": "update", diff --git a/acceptance/bundle/resources/postgres_roles/update/script b/acceptance/bundle/resources/postgres_roles/update/script index 0c81dd423e0..c8bc0c7a46c 100644 --- a/acceptance/bundle/resources/postgres_roles/update/script +++ b/acceptance/bundle/resources/postgres_roles/update/script @@ -15,7 +15,7 @@ print_requests() { title "Initial deployment" trace $CLI bundle validate trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_roles.my_role" // .' > out.plan.create.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_roles.my_role > out.plan.create.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -28,7 +28,7 @@ trace $CLI postgres get-role "${role_name}" | role_fields title "Verify no changes" trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_roles.my_role" // .' > out.plan.no_change.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_roles.my_role > out.plan.no_change.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -39,7 +39,7 @@ trace update_file.py databricks.yml "createdb: false" "createdb: true" trace cat databricks.yml trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_roles.my_role" // .' > out.plan.update.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_roles.my_role > out.plan.update.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy @@ -50,7 +50,7 @@ trace $CLI postgres get-role "${role_name}" | role_fields title "Restore attributes.createdb to original value" trace update_file.py databricks.yml "createdb: true" "createdb: false" trace $CLI bundle plan -trace $CLI bundle plan -o json | nostamp | jq '.plan."resources.postgres_roles.my_role" // .' > out.plan.restore.json +trace $CLI bundle plan -o json | plan_filter.py resources.postgres_roles.my_role > out.plan.restore.json rm -f "$OUT_REQUESTS" trace $CLI bundle deploy diff --git a/acceptance/selftest/plan_filter/out.test.toml b/acceptance/selftest/plan_filter/out.test.toml new file mode 100644 index 00000000000..18b1a88417e --- /dev/null +++ b/acceptance/selftest/plan_filter/out.test.toml @@ -0,0 +1 @@ +Cloud = false diff --git a/acceptance/selftest/plan_filter/output.txt b/acceptance/selftest/plan_filter/output.txt new file mode 100644 index 00000000000..fdb44a7611f --- /dev/null +++ b/acceptance/selftest/plan_filter/output.txt @@ -0,0 +1,75 @@ + +=== Whole plan: remote_state and the deployment stamp are dropped from every entry + +>>> plan_filter.py +{ + "plan_version": [PLAN_VERSION], + "cli_version": "0.0.0-dev", + "lineage": "lineage-1", + "serial": 3, + "plan": { + "resources.jobs.foo": { + "action": "update", + "new_state": { + "value": { + "name": "new name" + } + }, + "changes": { + "name": { + "action": "update", + "old": "old name", + "new": "new name", + "remote": "old name" + } + } + }, + "resources.jobs.bar": { + "action": "create", + "new_state": { + "value": { + "name": "bar" + } + } + } + } +} + +=== One entry + +>>> plan_filter.py resources.jobs.foo +{ + "action": "update", + "new_state": { + "value": { + "name": "new name" + } + }, + "changes": { + "name": { + "action": "update", + "old": "old name", + "new": "new name", + "remote": "old name" + } + } +} + +=== A missing entry is an error, not an empty golden + +>>> errcode plan_filter.py resources.jobs.missing +plan_filter.py: no plan entry 'resources.jobs.missing'; entries: ['resources.jobs.bar', 'resources.jobs.foo'] + +Exit code: 1 + +=== Input that is not a plan is an error + +>>> errcode plan_filter.py +plan_filter.py: input is not a plan: no 'plan' object + +Exit code: 1 + +>>> errcode plan_filter.py +plan_filter.py: input is not JSON (Expecting value: line 1 column 1 (char 0)): '' + +Exit code: 1 diff --git a/acceptance/selftest/plan_filter/plan.json b/acceptance/selftest/plan_filter/plan.json new file mode 100644 index 00000000000..f63a5ccfb54 --- /dev/null +++ b/acceptance/selftest/plan_filter/plan.json @@ -0,0 +1,22 @@ +{ + "plan_version": 2, + "cli_version": "0.0.0-dev", + "lineage": "lineage-1", + "serial": 3, + "features": {"deployment_history_shadow": {}}, + "plan": { + "resources.jobs.foo": { + "action": "update", + "new_state": {"value": {"name": "new name"}}, + "remote_state": {"job_id": 123, "name": "old name", "created_time": 1700000000000}, + "changes": { + "name": {"action": "update", "old": "old name", "new": "new name", "remote": "old name"}, + "deployment.version_id": {"action": "update", "old": "1", "new": "2"} + } + }, + "resources.jobs.bar": { + "action": "create", + "new_state": {"value": {"name": "bar"}} + } + } +} diff --git a/acceptance/selftest/plan_filter/script b/acceptance/selftest/plan_filter/script new file mode 100644 index 00000000000..6a0ed188838 --- /dev/null +++ b/acceptance/selftest/plan_filter/script @@ -0,0 +1,12 @@ +title "Whole plan: remote_state and the deployment stamp are dropped from every entry" +trace plan_filter.py < plan.json + +title "One entry" +trace plan_filter.py resources.jobs.foo < plan.json + +title "A missing entry is an error, not an empty golden" +trace errcode plan_filter.py resources.jobs.missing < plan.json + +title "Input that is not a plan is an error" +trace errcode plan_filter.py <<< '{"summary": {}}' +trace errcode plan_filter.py < /dev/null