From 6a09092e3324a70b4f4d6b8cffb925ec8652a324 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 27 Aug 2026 16:04:01 +0200 Subject: [PATCH 1/7] Use source_code_path and git_source on Create/Update --- .nextchanges/bundles/app-source-code-path.md | 1 + .../out.requests.direct.json | 3 +- .../remote_app_url/out.requests.direct.json | 54 +++++++++++++++++++ .../out.requests.terraform.json | 53 ++++++++++++++++++ .../resource_deps/remote_app_url/output.txt | 53 ------------------ .../resource_deps/remote_app_url/script | 4 +- .../apps/config-no-deployment/output.txt | 9 ++-- .../apps/config-no-deployment/script | 4 +- .../out.requests.direct.json | 12 +++++ .../out.requests.terraform.json | 11 ++++ .../apps/default_description/output.txt | 11 ---- .../resources/apps/default_description/script | 4 +- .../apps/git-source-no-deployment/output.txt | 8 +-- .../apps/git-source-no-deployment/script | 6 +-- .../resources/apps/immutable/output.txt | 3 +- .../apps/lifecycle-started-omitted/output.txt | 6 +-- .../apps/lifecycle-started-toggle/output.txt | 6 +-- .../apps/lifecycle-started/output.txt | 22 ++++---- .../resource-refs/out.requests.direct.json | 48 +++++++++++++++++ .../resource-refs/out.requests.terraform.json | 47 ++++++++++++++++ .../resources/apps/resource-refs/output.txt | 47 ---------------- .../resources/apps/resource-refs/script | 4 +- .../apps/source-code-path-update/app/app.py | 1 + .../apps/source-code-path-update/app2/app.py | 1 + .../source-code-path-update/databricks.yml | 9 ++++ .../source-code-path-update/out.test.toml | 2 + .../apps/source-code-path-update/output.txt | 50 +++++++++++++++++ .../apps/source-code-path-update/script | 11 ++++ .../apps/source-code-path-update/test.toml | 7 +++ .../apps/update/out.requests.direct.json | 11 ++-- bundle/appdeploy/app.go | 2 + bundle/config/resources/apps.go | 9 ++-- bundle/deploy/terraform/tfdyn/convert_app.go | 9 ++-- bundle/direct/dresources/app.go | 51 ++++++++---------- libs/testserver/apps.go | 39 +++++++++++--- 35 files changed, 425 insertions(+), 193 deletions(-) create mode 100644 .nextchanges/bundles/app-source-code-path.md create mode 100644 acceptance/bundle/resource_deps/remote_app_url/out.requests.direct.json create mode 100644 acceptance/bundle/resource_deps/remote_app_url/out.requests.terraform.json create mode 100644 acceptance/bundle/resources/apps/default_description/out.requests.direct.json create mode 100644 acceptance/bundle/resources/apps/default_description/out.requests.terraform.json create mode 100644 acceptance/bundle/resources/apps/resource-refs/out.requests.direct.json create mode 100644 acceptance/bundle/resources/apps/resource-refs/out.requests.terraform.json create mode 100644 acceptance/bundle/resources/apps/source-code-path-update/app/app.py create mode 100644 acceptance/bundle/resources/apps/source-code-path-update/app2/app.py create mode 100644 acceptance/bundle/resources/apps/source-code-path-update/databricks.yml create mode 100644 acceptance/bundle/resources/apps/source-code-path-update/out.test.toml create mode 100644 acceptance/bundle/resources/apps/source-code-path-update/output.txt create mode 100644 acceptance/bundle/resources/apps/source-code-path-update/script create mode 100644 acceptance/bundle/resources/apps/source-code-path-update/test.toml diff --git a/.nextchanges/bundles/app-source-code-path.md b/.nextchanges/bundles/app-source-code-path.md new file mode 100644 index 00000000000..7dd8a310794 --- /dev/null +++ b/.nextchanges/bundles/app-source-code-path.md @@ -0,0 +1 @@ +For apps deployed with the direct engine, `source_code_path` and `git_source` are now sent as part of the Create/Update App request instead of only through the app Deploy API, so they are managed at deploy time. The Terraform engine is unchanged (its `databricks_app` resource cannot manage these input-only fields). diff --git a/acceptance/bundle/empty_string_dropped/out.requests.direct.json b/acceptance/bundle/empty_string_dropped/out.requests.direct.json index c9bba29b9fa..54d8e44d45a 100644 --- a/acceptance/bundle/empty_string_dropped/out.requests.direct.json +++ b/acceptance/bundle/empty_string_dropped/out.requests.direct.json @@ -6,7 +6,8 @@ }, "body": { "description": "", - "name": "test-app-direct" + "name": "test-app-direct", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/direct/files/app" } } { diff --git a/acceptance/bundle/resource_deps/remote_app_url/out.requests.direct.json b/acceptance/bundle/resource_deps/remote_app_url/out.requests.direct.json new file mode 100644 index 00000000000..92997feef74 --- /dev/null +++ b/acceptance/bundle/resource_deps/remote_app_url/out.requests.direct.json @@ -0,0 +1,54 @@ +{ + "method": "POST", + "path": "/api/2.0/workspace/mkdirs", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state" + } +} +{ + "method": "POST", + "path": "/api/2.0/workspace/delete", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal", + "recursive": true + } +} +{ + "method": "POST", + "path": "/api/2.0/workspace/mkdirs", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal" + } +} +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "best app", + "name": "myapp", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app" + } +} +{ + "method": "POST", + "path": "/api/2.0/pipelines", + "body": { + "channel": "CURRENT", + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json" + }, + "edition": "ADVANCED", + "name": "app url is myapp-123.cloud.databricksapps.com" + } +} +{ + "method": "POST", + "path": "/api/2.0/workspace/delete", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock" + } +} diff --git a/acceptance/bundle/resource_deps/remote_app_url/out.requests.terraform.json b/acceptance/bundle/resource_deps/remote_app_url/out.requests.terraform.json new file mode 100644 index 00000000000..4e6eb966fe5 --- /dev/null +++ b/acceptance/bundle/resource_deps/remote_app_url/out.requests.terraform.json @@ -0,0 +1,53 @@ +{ + "method": "POST", + "path": "/api/2.0/workspace/mkdirs", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state" + } +} +{ + "method": "POST", + "path": "/api/2.0/workspace/delete", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal", + "recursive": true + } +} +{ + "method": "POST", + "path": "/api/2.0/workspace/mkdirs", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal" + } +} +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "best app", + "name": "myapp" + } +} +{ + "method": "POST", + "path": "/api/2.0/pipelines", + "body": { + "channel": "CURRENT", + "deployment": { + "kind": "BUNDLE", + "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json" + }, + "edition": "ADVANCED", + "name": "app url is myapp-123.cloud.databricksapps.com" + } +} +{ + "method": "POST", + "path": "/api/2.0/workspace/delete", + "body": { + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock" + } +} diff --git a/acceptance/bundle/resource_deps/remote_app_url/output.txt b/acceptance/bundle/resource_deps/remote_app_url/output.txt index 9301329af12..13907cd4a82 100644 --- a/acceptance/bundle/resource_deps/remote_app_url/output.txt +++ b/acceptance/bundle/resource_deps/remote_app_url/output.txt @@ -31,59 +31,6 @@ Files: 1 uploaded, 0 deleted Resources: 2 created, 0 changed, 0 deleted, 0 unchanged >>> print_requests.py ^//import-file/ -{ - "method": "POST", - "path": "/api/2.0/workspace/mkdirs", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state" - } -} -{ - "method": "POST", - "path": "/api/2.0/workspace/delete", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal", - "recursive": true - } -} -{ - "method": "POST", - "path": "/api/2.0/workspace/mkdirs", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal" - } -} -{ - "method": "POST", - "path": "/api/2.0/apps", - "q": { - "no_compute": "true" - }, - "body": { - "description": "best app", - "name": "myapp" - } -} -{ - "method": "POST", - "path": "/api/2.0/pipelines", - "body": { - "channel": "CURRENT", - "deployment": { - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json" - }, - "edition": "ADVANCED", - "name": "app url is myapp-123.cloud.databricksapps.com" - } -} -{ - "method": "POST", - "path": "/api/2.0/workspace/delete", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock" - } -} >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: diff --git a/acceptance/bundle/resource_deps/remote_app_url/script b/acceptance/bundle/resource_deps/remote_app_url/script index d38692366b3..6a4e2a0e316 100644 --- a/acceptance/bundle/resource_deps/remote_app_url/script +++ b/acceptance/bundle/resource_deps/remote_app_url/script @@ -3,7 +3,9 @@ trace $CLI bundle plan trace print_requests.py '^//import-file/' trace $CLI bundle deploy -trace print_requests.py '^//import-file/' +# The app create body diverges by engine (the direct engine sends source_code_path, +# the Terraform provider cannot manage it), so record these requests per engine. +trace print_requests.py '^//import-file/' > out.requests.$DATABRICKS_BUNDLE_ENGINE.json trace $CLI bundle destroy --auto-approve trace print_requests.py --sort '^//import-file/' diff --git a/acceptance/bundle/resources/apps/config-no-deployment/output.txt b/acceptance/bundle/resources/apps/config-no-deployment/output.txt index 81a1f6c8677..78f855877ca 100644 --- a/acceptance/bundle/resources/apps/config-no-deployment/output.txt +++ b/acceptance/bundle/resources/apps/config-no-deployment/output.txt @@ -6,11 +6,11 @@ Created apps.myapp Files: 0 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged -=== Plan is a no-op: config/source_code_path drift is skipped while the app has no active deployment +=== Plan is a no-op: config drift is skipped (no active deployment); source_code_path is input-only >>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged -=== Both deploy-only fields are skipped with reason "no active deployment" +=== config skipped with "no active deployment"; source_code_path skipped as input_only >>> [CLI] bundle plan -o json { "config": { @@ -43,8 +43,9 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged }, "source_code_path": { "action": "skip", - "reason": "no active deployment", + "reason": "spec:input_only", "old": "/Workspace/Users/[USERNAME]/.bundle/app-config-no-deployment/default/files/app", - "new": "/Workspace/Users/[USERNAME]/.bundle/app-config-no-deployment/default/files/app" + "new": "/Workspace/Users/[USERNAME]/.bundle/app-config-no-deployment/default/files/app", + "remote": "" } } diff --git a/acceptance/bundle/resources/apps/config-no-deployment/script b/acceptance/bundle/resources/apps/config-no-deployment/script index f1970999645..7c44942408b 100644 --- a/acceptance/bundle/resources/apps/config-no-deployment/script +++ b/acceptance/bundle/resources/apps/config-no-deployment/script @@ -3,8 +3,8 @@ echo "*" > .gitignore title "Deploy: app created with no_compute; config is not deployed until the app starts" trace $CLI bundle deploy -title "Plan is a no-op: config/source_code_path drift is skipped while the app has no active deployment" +title "Plan is a no-op: config drift is skipped (no active deployment); source_code_path is input-only" trace $CLI bundle plan | contains.py "Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged" -title "Both deploy-only fields are skipped with reason \"no active deployment\"" +title "config skipped with \"no active deployment\"; source_code_path skipped as input_only" trace $CLI bundle plan -o json | jq '.plan[].changes | {config, source_code_path}' diff --git a/acceptance/bundle/resources/apps/default_description/out.requests.direct.json b/acceptance/bundle/resources/apps/default_description/out.requests.direct.json new file mode 100644 index 00000000000..cc9779b7d46 --- /dev/null +++ b/acceptance/bundle/resources/apps/default_description/out.requests.direct.json @@ -0,0 +1,12 @@ +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "", + "name": "myappname", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files" + } +} diff --git a/acceptance/bundle/resources/apps/default_description/out.requests.terraform.json b/acceptance/bundle/resources/apps/default_description/out.requests.terraform.json new file mode 100644 index 00000000000..37ce34a674e --- /dev/null +++ b/acceptance/bundle/resources/apps/default_description/out.requests.terraform.json @@ -0,0 +1,11 @@ +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "", + "name": "myappname" + } +} diff --git a/acceptance/bundle/resources/apps/default_description/output.txt b/acceptance/bundle/resources/apps/default_description/output.txt index 1f78fb9801d..66120057068 100644 --- a/acceptance/bundle/resources/apps/default_description/output.txt +++ b/acceptance/bundle/resources/apps/default_description/output.txt @@ -6,14 +6,3 @@ Files: 5 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged >>> print_requests.py //apps -{ - "method": "POST", - "path": "/api/2.0/apps", - "q": { - "no_compute": "true" - }, - "body": { - "description": "", - "name": "myappname" - } -} diff --git a/acceptance/bundle/resources/apps/default_description/script b/acceptance/bundle/resources/apps/default_description/script index b9d834794d3..a1e67ada078 100644 --- a/acceptance/bundle/resources/apps/default_description/script +++ b/acceptance/bundle/resources/apps/default_description/script @@ -1,2 +1,4 @@ trace $CLI bundle deploy -trace print_requests.py //apps +# The create body diverges by engine: the direct engine sends source_code_path, the +# Terraform provider cannot manage it (input_only), so record requests per engine. +trace print_requests.py //apps > out.requests.$DATABRICKS_BUNDLE_ENGINE.json diff --git a/acceptance/bundle/resources/apps/git-source-no-deployment/output.txt b/acceptance/bundle/resources/apps/git-source-no-deployment/output.txt index 7b6337e33dd..07a1cd92b86 100644 --- a/acceptance/bundle/resources/apps/git-source-no-deployment/output.txt +++ b/acceptance/bundle/resources/apps/git-source-no-deployment/output.txt @@ -1,21 +1,21 @@ -=== Deploy: app created with no_compute; git_source is not deployed until the app starts +=== Deploy: git_source is sent on Create; the app has no_compute so nothing is deployed yet >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-git-source-no-deployment/default/files... Created apps.myapp Files: 0 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged -=== Plan is a no-op: git_source drift is skipped while the app has no active deployment +=== Plan is a no-op: git_source is input-only, so its drift is suppressed >>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged -=== git_source is skipped with reason "no active deployment" +=== git_source is skipped as input_only >>> [CLI] bundle plan -o json { "git_source": { "action": "skip", - "reason": "no active deployment", + "reason": "spec:input_only", "old": { "branch": "main" }, diff --git a/acceptance/bundle/resources/apps/git-source-no-deployment/script b/acceptance/bundle/resources/apps/git-source-no-deployment/script index 63cce6312c3..ce89140d5a1 100644 --- a/acceptance/bundle/resources/apps/git-source-no-deployment/script +++ b/acceptance/bundle/resources/apps/git-source-no-deployment/script @@ -1,10 +1,10 @@ echo "*" > .gitignore -title "Deploy: app created with no_compute; git_source is not deployed until the app starts" +title "Deploy: git_source is sent on Create; the app has no_compute so nothing is deployed yet" trace $CLI bundle deploy -title "Plan is a no-op: git_source drift is skipped while the app has no active deployment" +title "Plan is a no-op: git_source is input-only, so its drift is suppressed" trace $CLI bundle plan | contains.py "Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged" -title "git_source is skipped with reason \"no active deployment\"" +title "git_source is skipped as input_only" trace $CLI bundle plan -o json | jq '.plan[].changes | {git_source}' diff --git a/acceptance/bundle/resources/apps/immutable/output.txt b/acceptance/bundle/resources/apps/immutable/output.txt index 4b25ae82b8b..f88893b676f 100644 --- a/acceptance/bundle/resources/apps/immutable/output.txt +++ b/acceptance/bundle/resources/apps/immutable/output.txt @@ -24,7 +24,8 @@ You can access the app at my-immutable-app-123.cloud.databricksapps.com }, "body": { "description": "", - "name": "my-immutable-app" + "name": "my-immutable-app", + "source_code_path": "/Workspace/Users/[UUID]/.snapshots/[UUID]/[SNAPSHOT_HASH]/files/app" } } { diff --git a/acceptance/bundle/resources/apps/lifecycle-started-omitted/output.txt b/acceptance/bundle/resources/apps/lifecycle-started-omitted/output.txt index abe37f235f8..1a73661eda9 100644 --- a/acceptance/bundle/resources/apps/lifecycle-started-omitted/output.txt +++ b/acceptance/bundle/resources/apps/lifecycle-started-omitted/output.txt @@ -15,7 +15,8 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged }, "body": { "description": "my_app_description", - "name": "[UNIQUE_NAME]" + "name": "[UNIQUE_NAME]", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-omitted-[UNIQUE_NAME]/default/files/app" } } @@ -52,8 +53,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments", "body": { - "mode": "SNAPSHOT", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-omitted-[UNIQUE_NAME]/default/files/app" + "mode": "SNAPSHOT" } } diff --git a/acceptance/bundle/resources/apps/lifecycle-started-toggle/output.txt b/acceptance/bundle/resources/apps/lifecycle-started-toggle/output.txt index ef03a4541d9..d4d51294238 100644 --- a/acceptance/bundle/resources/apps/lifecycle-started-toggle/output.txt +++ b/acceptance/bundle/resources/apps/lifecycle-started-toggle/output.txt @@ -10,7 +10,8 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged { "body": { "description": "my_app_description", - "name": "[UNIQUE_NAME]" + "name": "[UNIQUE_NAME]", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-toggle-[UNIQUE_NAME]/default/files/app" }, "method": "POST", "path": "/api/2.0/apps", @@ -39,8 +40,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged } { "body": { - "mode": "SNAPSHOT", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-toggle-[UNIQUE_NAME]/default/files/app" + "mode": "SNAPSHOT" }, "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments" diff --git a/acceptance/bundle/resources/apps/lifecycle-started/output.txt b/acceptance/bundle/resources/apps/lifecycle-started/output.txt index 6e0d5e5d7f5..ba5bbb201bc 100644 --- a/acceptance/bundle/resources/apps/lifecycle-started/output.txt +++ b/acceptance/bundle/resources/apps/lifecycle-started/output.txt @@ -12,15 +12,15 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged "path": "/api/2.0/apps", "body": { "description": "my_app_description", - "name": "[UNIQUE_NAME]" + "name": "[UNIQUE_NAME]", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" } } { "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments", "body": { - "mode": "SNAPSHOT", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" + "mode": "SNAPSHOT" } } @@ -41,8 +41,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments", "body": { - "mode": "SNAPSHOT", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" + "mode": "SNAPSHOT" } } @@ -88,9 +87,10 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "body": { "app": { "description": "MY_APP_DESCRIPTION_2", - "name": "[UNIQUE_NAME]" + "name": "[UNIQUE_NAME]", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,forward_user_access_token,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,forward_user_access_token,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" } } @@ -115,9 +115,10 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "body": { "app": { "description": "MY_APP_DESCRIPTION_3", - "name": "[UNIQUE_NAME]" + "name": "[UNIQUE_NAME]", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,forward_user_access_token,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,forward_user_access_token,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" } } { @@ -129,8 +130,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments", "body": { - "mode": "SNAPSHOT", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" + "mode": "SNAPSHOT" } } diff --git a/acceptance/bundle/resources/apps/resource-refs/out.requests.direct.json b/acceptance/bundle/resources/apps/resource-refs/out.requests.direct.json new file mode 100644 index 00000000000..194f2e69940 --- /dev/null +++ b/acceptance/bundle/resources/apps/resource-refs/out.requests.direct.json @@ -0,0 +1,48 @@ +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "A Streamlit app that uses a SQL warehouse", + "name": "data-app", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/resource-refs/default/files/app" + } +} +{ + "method": "POST", + "path": "/api/2.0/apps/data-app/start", + "body": {} +} +{ + "method": "POST", + "path": "/api/2.0/apps/data-app/deployments", + "body": { + "command": [ + "streamlit", + "run", + "app.py" + ], + "env_vars": [ + { + "name": "MY_EXAMPLE_SCHEMA", + "value": "main" + }, + { + "name": "MY_EXAMPLE_JOB", + "value": "example_job" + }, + { + "name": "MY_EXAMPLE_JOB_ID", + "value": "[NUMID]" + }, + { + "name": "MY_EXAMPLE_VAR", + "value": "example_value" + } + ], + "mode": "SNAPSHOT", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/resource-refs/default/files/app" + } +} diff --git a/acceptance/bundle/resources/apps/resource-refs/out.requests.terraform.json b/acceptance/bundle/resources/apps/resource-refs/out.requests.terraform.json new file mode 100644 index 00000000000..e6292cf773f --- /dev/null +++ b/acceptance/bundle/resources/apps/resource-refs/out.requests.terraform.json @@ -0,0 +1,47 @@ +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "A Streamlit app that uses a SQL warehouse", + "name": "data-app" + } +} +{ + "method": "POST", + "path": "/api/2.0/apps/data-app/start", + "body": {} +} +{ + "method": "POST", + "path": "/api/2.0/apps/data-app/deployments", + "body": { + "command": [ + "streamlit", + "run", + "app.py" + ], + "env_vars": [ + { + "name": "MY_EXAMPLE_SCHEMA", + "value": "main" + }, + { + "name": "MY_EXAMPLE_JOB", + "value": "example_job" + }, + { + "name": "MY_EXAMPLE_JOB_ID", + "value": "[NUMID]" + }, + { + "name": "MY_EXAMPLE_VAR", + "value": "example_value" + } + ], + "mode": "SNAPSHOT", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/resource-refs/default/files/app" + } +} diff --git a/acceptance/bundle/resources/apps/resource-refs/output.txt b/acceptance/bundle/resources/apps/resource-refs/output.txt index 14fcdcb0972..6eb5eb0ca96 100644 --- a/acceptance/bundle/resources/apps/resource-refs/output.txt +++ b/acceptance/bundle/resources/apps/resource-refs/output.txt @@ -18,50 +18,3 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged You can access the app at data-app-123.cloud.databricksapps.com >>> print_requests.py //apps -{ - "method": "POST", - "path": "/api/2.0/apps", - "q": { - "no_compute": "true" - }, - "body": { - "description": "A Streamlit app that uses a SQL warehouse", - "name": "data-app" - } -} -{ - "method": "POST", - "path": "/api/2.0/apps/data-app/start", - "body": {} -} -{ - "method": "POST", - "path": "/api/2.0/apps/data-app/deployments", - "body": { - "command": [ - "streamlit", - "run", - "app.py" - ], - "env_vars": [ - { - "name": "MY_EXAMPLE_SCHEMA", - "value": "main" - }, - { - "name": "MY_EXAMPLE_JOB", - "value": "example_job" - }, - { - "name": "MY_EXAMPLE_JOB_ID", - "value": "[NUMID]" - }, - { - "name": "MY_EXAMPLE_VAR", - "value": "example_value" - } - ], - "mode": "SNAPSHOT", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/resource-refs/default/files/app" - } -} diff --git a/acceptance/bundle/resources/apps/resource-refs/script b/acceptance/bundle/resources/apps/resource-refs/script index ace337470da..1d023779d65 100644 --- a/acceptance/bundle/resources/apps/resource-refs/script +++ b/acceptance/bundle/resources/apps/resource-refs/script @@ -1,3 +1,5 @@ trace $CLI bundle deploy trace $CLI bundle run data_app -trace print_requests.py //apps +# The create body diverges by engine: the direct engine sends source_code_path, the +# Terraform provider cannot manage it (input_only), so record requests per engine. +trace print_requests.py //apps > out.requests.$DATABRICKS_BUNDLE_ENGINE.json diff --git a/acceptance/bundle/resources/apps/source-code-path-update/app/app.py b/acceptance/bundle/resources/apps/source-code-path-update/app/app.py new file mode 100644 index 00000000000..c471b2f5ecf --- /dev/null +++ b/acceptance/bundle/resources/apps/source-code-path-update/app/app.py @@ -0,0 +1 @@ +print("v1") diff --git a/acceptance/bundle/resources/apps/source-code-path-update/app2/app.py b/acceptance/bundle/resources/apps/source-code-path-update/app2/app.py new file mode 100644 index 00000000000..3d6edeb28df --- /dev/null +++ b/acceptance/bundle/resources/apps/source-code-path-update/app2/app.py @@ -0,0 +1 @@ +print("v2") diff --git a/acceptance/bundle/resources/apps/source-code-path-update/databricks.yml b/acceptance/bundle/resources/apps/source-code-path-update/databricks.yml new file mode 100644 index 00000000000..7c707baa0a4 --- /dev/null +++ b/acceptance/bundle/resources/apps/source-code-path-update/databricks.yml @@ -0,0 +1,9 @@ +bundle: + name: app-source-code-path-update + +resources: + apps: + myapp: + name: test-app-source-code-path-update + description: my_app_description + source_code_path: ./app diff --git a/acceptance/bundle/resources/apps/source-code-path-update/out.test.toml b/acceptance/bundle/resources/apps/source-code-path-update/out.test.toml new file mode 100644 index 00000000000..0938e678987 --- /dev/null +++ b/acceptance/bundle/resources/apps/source-code-path-update/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] diff --git a/acceptance/bundle/resources/apps/source-code-path-update/output.txt b/acceptance/bundle/resources/apps/source-code-path-update/output.txt new file mode 100644 index 00000000000..4377365da60 --- /dev/null +++ b/acceptance/bundle/resources/apps/source-code-path-update/output.txt @@ -0,0 +1,50 @@ + +=== Deploy: source_code_path is sent on Create +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files... +Created apps.myapp +Files: 7 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //apps +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "my_app_description", + "name": "test-app-source-code-path-update", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files/app" + } +} + +=== Change source_code_path: plan detects an update +>>> update_file.py databricks.yml source_code_path: ./app source_code_path: ./app2 + +>>> [CLI] bundle plan +update apps.myapp + +Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged + +=== Redeploy: App Update sends the new source_code_path in the update mask +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files... +Updated apps.myapp +Files: 3 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //apps +{ + "method": "POST", + "path": "/api/2.0/apps/test-app-source-code-path-update/update", + "body": { + "app": { + "description": "my_app_description", + "name": "test-app-source-code-path-update", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files/app2" + }, + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,forward_user_access_token,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" + } +} diff --git a/acceptance/bundle/resources/apps/source-code-path-update/script b/acceptance/bundle/resources/apps/source-code-path-update/script new file mode 100644 index 00000000000..9766c0933b9 --- /dev/null +++ b/acceptance/bundle/resources/apps/source-code-path-update/script @@ -0,0 +1,11 @@ +title "Deploy: source_code_path is sent on Create" +trace $CLI bundle deploy +trace print_requests.py //apps + +title "Change source_code_path: plan detects an update" +trace update_file.py databricks.yml "source_code_path: ./app" "source_code_path: ./app2" +trace $CLI bundle plan + +title "Redeploy: App Update sends the new source_code_path in the update mask" +trace $CLI bundle deploy +trace print_requests.py //apps diff --git a/acceptance/bundle/resources/apps/source-code-path-update/test.toml b/acceptance/bundle/resources/apps/source-code-path-update/test.toml new file mode 100644 index 00000000000..bebd818be7b --- /dev/null +++ b/acceptance/bundle/resources/apps/source-code-path-update/test.toml @@ -0,0 +1,7 @@ +Cloud = false + +Ignore = [".databricks"] + +# source_code_path is managed via Create/Update App, which only the direct engine +# supports (the Terraform databricks_app resource cannot manage this input_only field). +EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] diff --git a/acceptance/bundle/resources/apps/update/out.requests.direct.json b/acceptance/bundle/resources/apps/update/out.requests.direct.json index faf9c2bbca4..8ab3c9fb7df 100644 --- a/acceptance/bundle/resources/apps/update/out.requests.direct.json +++ b/acceptance/bundle/resources/apps/update/out.requests.direct.json @@ -6,7 +6,8 @@ }, "body": { "description": "my_app_description", - "name": "myappname" + "name": "myappname", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app" } } { @@ -15,9 +16,10 @@ "body": { "app": { "description": "MY_APP_DESCRIPTION", - "name": "myappname" + "name": "myappname", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,forward_user_access_token,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,forward_user_access_token,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" } } { @@ -32,7 +34,8 @@ }, "body": { "description": "MY_APP_DESCRIPTION", - "name": "mynewappname" + "name": "mynewappname", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app" } } { diff --git a/bundle/appdeploy/app.go b/bundle/appdeploy/app.go index 4f590be60ac..4fe7376ff60 100644 --- a/bundle/appdeploy/app.go +++ b/bundle/appdeploy/app.go @@ -19,6 +19,8 @@ func logProgress(ctx context.Context, msg string) { } // BuildDeployment constructs an AppDeployment from the app's source code path, inline config and git source. +// The direct engine passes an empty sourcePath and nil gitSource because it sends those on Create/Update; +// bundle run and the Terraform path still deploy them here. func BuildDeployment(sourcePath string, config *resources.AppConfig, gitSource *sdkapps.GitSource) sdkapps.AppDeployment { // GitRepository is not supported in the Deploy API, only as part of Create, so we need to remove it. if gitSource != nil { diff --git a/bundle/config/resources/apps.go b/bundle/config/resources/apps.go index a26670c4897..c3ccdf2f26a 100644 --- a/bundle/config/resources/apps.go +++ b/bundle/config/resources/apps.go @@ -41,10 +41,11 @@ type App struct { // Lifecycle shadows BaseResource.Lifecycle to add support for lifecycle.started. Lifecycle *LifecycleWithStarted `json:"lifecycle,omitempty"` - // SourceCodePath and GitSource come from the embedded apps.App. DABs treats them as - // deploy-only: source_code_path points at app source on local disk and is translated to - // its workspace path, and both are passed to the Deploy API rather than sent as resource - // attributes. Declaring them here too would duplicate their json tags and break diffing. + // SourceCodePath and GitSource come from the embedded apps.App and are sent as part of + // the Create/Update App request. source_code_path points at app source on local disk and + // is translated to its workspace path. The API accepts both on write but does not echo + // them on read (input_only), so drift for them is suppressed via ignore_remote_changes. + // Declaring them here too would duplicate their json tags and break diffing. // Config represents inline app.yaml configuration for the app. // When specified, this configuration is written to an app.yaml file in the source code path during deployment. diff --git a/bundle/deploy/terraform/tfdyn/convert_app.go b/bundle/deploy/terraform/tfdyn/convert_app.go index edc6073a89d..ed9d02a1bce 100644 --- a/bundle/deploy/terraform/tfdyn/convert_app.go +++ b/bundle/deploy/terraform/tfdyn/convert_app.go @@ -27,10 +27,11 @@ func convertAppResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) { log.Debugf(ctx, "app normalization diagnostic: %s", diag.Summary) } - // SDK v0.175 added source_code_path, git_source, and default_git_source to - // apps.App. These are deploy-only fields DABs handles via source upload (see - // bundle/direct/dresources/app.go), not databricks_app resource attributes, so - // keep them out of the Terraform state. + // SDK v0.175 added source_code_path, git_source, and default_git_source to apps.App. + // The databricks_app resource cannot manage source_code_path/git_source: the API accepts + // them on write but does not echo them on read (input_only), so the provider fails with + // "inconsistent result after apply" (the applied value reads back empty). DABs deploys + // them via the Deploy API instead (bundle run), so keep all three out of the TF state. vout, err := dyn.DropKeys(vout, []string{"source_code_path", "git_source", "default_git_source"}) if err != nil { return vout, err diff --git a/bundle/direct/dresources/app.go b/bundle/direct/dresources/app.go index c7108f87997..a8f1125e6a1 100644 --- a/bundle/direct/dresources/app.go +++ b/bundle/direct/dresources/app.go @@ -97,31 +97,21 @@ func (r *ResourceApp) DoRead(ctx context.Context, id string) (*AppRemote, error) Lifecycle: &StateLifecycle{Started: &started}, } if app.ActiveDeployment != nil { - // The source code path in active deployment is snapshotted version of the source code path in the app. - // We need to use the default source code path to get the correct source code path for drift detection. - remote.SourceCodePath = app.DefaultSourceCodePath - remote.GitSource = app.ActiveDeployment.GitSource + // config (command/env) is not part of apps.App, so it is read back from the + // active deployment for drift detection. source_code_path and git_source are + // sent on Create/Update and classified input_only, so their remote value is + // ignored (see resources.generated.yml) and does not need populating here. remote.Config = deploymentToAppConfig(app.ActiveDeployment) } return remote, nil } -// appRequestBody returns config.App with the deploy-only fields cleared. source_code_path -// and git_source became part of apps.App in SDK v0.175, but DABs applies them through the -// Deploy API (see manageLifecycle), so they must not ride along in create/update bodies. -func appRequestBody(config *AppState) apps.App { - app := config.App - app.SourceCodePath = "" - app.GitSource = nil - return app -} - func (r *ResourceApp) DoCreate(ctx context.Context, config *AppState) (string, *AppRemote, error) { // Start app compute only when lifecycle.started=true is explicit. // For nil (omitted) or false, use no_compute=true (do not start compute). noCompute := config.Lifecycle == nil || config.Lifecycle.Started == nil || !*config.Lifecycle.Started request := apps.CreateAppRequest{ - App: appRequestBody(config), + App: config.App, NoCompute: noCompute, ForceSendFields: nil, } @@ -168,16 +158,18 @@ var UpdateMaskFields = []string{ "compute_min_instances", "compute_max_instances", "git_repository", + "git_source", + "source_code_path", "telemetry_export_destinations", } var updateMask = strings.Join(UpdateMaskFields, ",") func (r *ResourceApp) DoUpdate(ctx context.Context, id string, config *AppState, entry *PlanEntry) (*AppRemote, error) { - // Deploy-only fields (source_code_path, config, git_source, lifecycle) are excluded - // from the request body; see appRequestBody. + // source_code_path and git_source are sent as part of the App body (in the update + // mask). Only config (command/env) is deploy-only and applied via manageLifecycle. if hasAppChanges(entry) { - app := appRequestBody(config) + app := config.App request := apps.AsyncUpdateAppRequest{ App: &app, AppName: id, @@ -222,7 +214,10 @@ func (r *ResourceApp) manageLifecycle(ctx context.Context, id string, config *Ap return err } } - deployment := appdeploy.BuildDeployment(config.SourceCodePath, config.Config, config.GitSource) + // source_code_path and git_source are set on the app via Create/Update, so the + // deployment carries only the inline config (command/env); the backend deploys + // from the app's configured source. + deployment := appdeploy.BuildDeployment("", config.Config, nil) if err := appdeploy.Deploy(ctx, r.client, id, deployment); err != nil { return err } @@ -243,19 +238,19 @@ func (r *ResourceApp) manageLifecycle(ctx context.Context, id string, config *Ap } // hasAppChanges reports whether the plan entry contains any Update changes -// to fields that belong to the App Update API (i.e., not deploy-only fields). +// to fields that belong to the App Update API. config (command/env) is deploy-only +// and applied via manageLifecycle; lifecycle drives compute start/stop. func hasAppChanges(entry *PlanEntry) bool { - return entry.Changes.HasChangeExcept("source_code_path", "config", "git_source", "lifecycle", "lifecycle.started") + return entry.Changes.HasChangeExcept("config", "lifecycle", "lifecycle.started") } -// OverrideChangeDesc skips drift on the deploy-only fields (source_code_path, config, -// git_source) while the app has no active deployment. DoRead reads them only from the -// active deployment, so before the first deploy (or once a stop clears it) the remote -// side is empty and the diff is spurious; it applies on the next start (manageLifecycle). +// OverrideChangeDesc skips drift on config (command/env) while the app has no active +// deployment. config is read only from the active deployment (DoRead), so before the +// first deploy (or once a stop clears it) the remote side is empty and the diff is +// spurious; it applies on the next start (manageLifecycle). func (*ResourceApp) OverrideChangeDesc(_ context.Context, path *structpath.PathNode, change *ChangeDesc, remote *AppRemote) error { // Prefix(1) so a nested diff (e.g. config.command) matches its top-level field. - switch path.Prefix(1).String() { - case "source_code_path", "config", "git_source": + if path.Prefix(1).String() == "config" { if remote.ActiveDeployment == nil { change.Action = deployplan.Skip change.Reason = "no active deployment" @@ -372,8 +367,6 @@ func (r *ResourceApp) waitForApp(ctx context.Context, w *databricks.WorkspaceCli Lifecycle: &StateLifecycle{Started: &started}, } if app.ActiveDeployment != nil { - remote.SourceCodePath = app.DefaultSourceCodePath - remote.GitSource = app.ActiveDeployment.GitSource remote.Config = deploymentToAppConfig(app.ActiveDeployment) } return remote, nil diff --git a/libs/testserver/apps.go b/libs/testserver/apps.go index 7ef32ae1920..fefbfd1a6fb 100644 --- a/libs/testserver/apps.go +++ b/libs/testserver/apps.go @@ -28,6 +28,16 @@ func setUcSecurableKinds(app *apps.App) { } } +// maskInputOnly clears the fields the Apps API accepts on write but never echoes +// on read (source_code_path, git_source are input_only per the API spec; the read +// side exposes default_source_code_path / default_git_source instead). The stored +// app keeps the real values so deployments can resolve the configured source. +func maskInputOnly(app apps.App) apps.App { + app.SourceCodePath = "" + app.GitSource = nil + return app +} + func (s *FakeWorkspace) AppsCreateUpdate(req Request, name string) Response { var updateReq apps.AsyncUpdateAppRequest if err := json.Unmarshal(req.Body, &updateReq); err != nil { @@ -120,6 +130,13 @@ func (s *FakeWorkspace) AppsCreateDeployment(req Request, name string) Response return Response{StatusCode: 500, Body: fmt.Sprintf("internal error: %s", err)} } + // A config-only deployment omits source_code_path/git_source; the backend + // deploys from the app's configured source, so resolve them from the app. + if deployment.SourceCodePath == "" && deployment.GitSource == nil { + deployment.SourceCodePath = app.SourceCodePath + deployment.GitSource = app.GitSource + } + deployment.DeploymentId = fmt.Sprintf("deploy-%d", nextID()) deployment.Status = &apps.AppDeploymentStatus{ State: apps.AppDeploymentStateSucceeded, @@ -128,6 +145,7 @@ func (s *FakeWorkspace) AppsCreateDeployment(req Request, name string) Response app.ActiveDeployment = &deployment app.DefaultSourceCodePath = deployment.SourceCodePath + app.DefaultGitSource = deployment.GitSource s.Apps[name] = app return Response{Body: deployment} @@ -179,7 +197,7 @@ func (s *FakeWorkspace) AppsStart(_ Request, name string) Response { } s.Apps[name] = app - return Response{Body: app} + return Response{Body: maskInputOnly(app)} } func (s *FakeWorkspace) AppsStop(_ Request, name string) Response { @@ -205,7 +223,7 @@ func (s *FakeWorkspace) AppsStop(_ Request, name string) Response { app.PendingDeployment = nil s.Apps[name] = app - return Response{Body: app} + return Response{Body: maskInputOnly(app)} } // AppsGet returns the app, keeping DELETING resources visible so callers can @@ -221,7 +239,7 @@ func (s *FakeWorkspace) AppsGet(name string) Response { } } - return Response{Body: app} + return Response{Body: maskInputOnly(app)} } // AppsDelete simulates the real Apps DELETE lifecycle: the first DELETE flips @@ -320,9 +338,17 @@ func (s *FakeWorkspace) AppsUpsert(req Request, name string) Response { Message: "App compute is active.", } - // Simulate the apps platform side effect: when an app is created, it is deployed with the default source code path. + // Simulate the apps platform side effect: when an app with running compute + // is created, it is deployed from its configured source. source_code_path and + // git_source now arrive on the Create request; fall back to the default path + // for apps that configure neither. + sourceCodePath := app.SourceCodePath + if sourceCodePath == "" && app.GitSource == nil { + sourceCodePath = "/Workspace/Users/tester@databricks.com/" + name + } deployment := apps.AppDeployment{ - SourceCodePath: "/Workspace/Users/tester@databricks.com/" + name, + SourceCodePath: sourceCodePath, + GitSource: app.GitSource, } deployment.DeploymentId = fmt.Sprintf("deploy-%d", nextID()) @@ -333,6 +359,7 @@ func (s *FakeWorkspace) AppsUpsert(req Request, name string) Response { app.ActiveDeployment = &deployment app.DefaultSourceCodePath = deployment.SourceCodePath + app.DefaultGitSource = app.GitSource } app.Url = name + "-123.cloud.databricksapps.com" @@ -373,6 +400,6 @@ func (s *FakeWorkspace) AppsUpsert(req Request, name string) Response { s.Apps[name] = app return Response{ - Body: app, + Body: maskInputOnly(app), } } From 4f489ac0fd5df075ec33e139d6f3f79f91fbb33e Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 27 Aug 2026 18:04:22 +0200 Subject: [PATCH 2/7] fix cloud test --- .nextchanges/bundles/app-source-code-path.md | 2 +- .../resources/apps/lifecycle-started-omitted/output.txt | 3 ++- .../resources/apps/lifecycle-started-toggle/output.txt | 3 ++- .../bundle/resources/apps/lifecycle-started/output.txt | 9 ++++++--- bundle/appdeploy/app.go | 2 -- bundle/config/resources/apps.go | 9 +++++---- bundle/direct/dresources/app.go | 8 ++++---- libs/testserver/apps.go | 7 ------- 8 files changed, 20 insertions(+), 23 deletions(-) diff --git a/.nextchanges/bundles/app-source-code-path.md b/.nextchanges/bundles/app-source-code-path.md index 7dd8a310794..4872fc6c021 100644 --- a/.nextchanges/bundles/app-source-code-path.md +++ b/.nextchanges/bundles/app-source-code-path.md @@ -1 +1 @@ -For apps deployed with the direct engine, `source_code_path` and `git_source` are now sent as part of the Create/Update App request instead of only through the app Deploy API, so they are managed at deploy time. The Terraform engine is unchanged (its `databricks_app` resource cannot manage these input-only fields). +For apps deployed with the direct engine, `source_code_path` and `git_source` are now also sent as part of the Create/Update App request (in addition to the app Deploy API), so they are recorded on the app and drift-detected. The Terraform engine is unchanged (its `databricks_app` resource cannot manage these input-only fields). diff --git a/acceptance/bundle/resources/apps/lifecycle-started-omitted/output.txt b/acceptance/bundle/resources/apps/lifecycle-started-omitted/output.txt index 1a73661eda9..874abae1905 100644 --- a/acceptance/bundle/resources/apps/lifecycle-started-omitted/output.txt +++ b/acceptance/bundle/resources/apps/lifecycle-started-omitted/output.txt @@ -53,7 +53,8 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments", "body": { - "mode": "SNAPSHOT" + "mode": "SNAPSHOT", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-omitted-[UNIQUE_NAME]/default/files/app" } } diff --git a/acceptance/bundle/resources/apps/lifecycle-started-toggle/output.txt b/acceptance/bundle/resources/apps/lifecycle-started-toggle/output.txt index d4d51294238..d8822539be4 100644 --- a/acceptance/bundle/resources/apps/lifecycle-started-toggle/output.txt +++ b/acceptance/bundle/resources/apps/lifecycle-started-toggle/output.txt @@ -40,7 +40,8 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged } { "body": { - "mode": "SNAPSHOT" + "mode": "SNAPSHOT", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-toggle-[UNIQUE_NAME]/default/files/app" }, "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments" diff --git a/acceptance/bundle/resources/apps/lifecycle-started/output.txt b/acceptance/bundle/resources/apps/lifecycle-started/output.txt index ba5bbb201bc..56466936d2a 100644 --- a/acceptance/bundle/resources/apps/lifecycle-started/output.txt +++ b/acceptance/bundle/resources/apps/lifecycle-started/output.txt @@ -20,7 +20,8 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments", "body": { - "mode": "SNAPSHOT" + "mode": "SNAPSHOT", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" } } @@ -41,7 +42,8 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments", "body": { - "mode": "SNAPSHOT" + "mode": "SNAPSHOT", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" } } @@ -130,7 +132,8 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "method": "POST", "path": "/api/2.0/apps/[UNIQUE_NAME]/deployments", "body": { - "mode": "SNAPSHOT" + "mode": "SNAPSHOT", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" } } diff --git a/bundle/appdeploy/app.go b/bundle/appdeploy/app.go index 4fe7376ff60..4f590be60ac 100644 --- a/bundle/appdeploy/app.go +++ b/bundle/appdeploy/app.go @@ -19,8 +19,6 @@ func logProgress(ctx context.Context, msg string) { } // BuildDeployment constructs an AppDeployment from the app's source code path, inline config and git source. -// The direct engine passes an empty sourcePath and nil gitSource because it sends those on Create/Update; -// bundle run and the Terraform path still deploy them here. func BuildDeployment(sourcePath string, config *resources.AppConfig, gitSource *sdkapps.GitSource) sdkapps.AppDeployment { // GitRepository is not supported in the Deploy API, only as part of Create, so we need to remove it. if gitSource != nil { diff --git a/bundle/config/resources/apps.go b/bundle/config/resources/apps.go index c3ccdf2f26a..20442755980 100644 --- a/bundle/config/resources/apps.go +++ b/bundle/config/resources/apps.go @@ -42,10 +42,11 @@ type App struct { Lifecycle *LifecycleWithStarted `json:"lifecycle,omitempty"` // SourceCodePath and GitSource come from the embedded apps.App and are sent as part of - // the Create/Update App request. source_code_path points at app source on local disk and - // is translated to its workspace path. The API accepts both on write but does not echo - // them on read (input_only), so drift for them is suppressed via ignore_remote_changes. - // Declaring them here too would duplicate their json tags and break diffing. + // the Create/Update App request so they are recorded on the app. source_code_path points + // at app source on local disk and is translated to its workspace path. The API accepts + // both on write but does not echo them on read (input_only), so drift is suppressed via + // ignore_remote_changes. They are also passed to the Deploy API, which requires a + // deployment source. Declaring them here too would duplicate their json tags and break diffing. // Config represents inline app.yaml configuration for the app. // When specified, this configuration is written to an app.yaml file in the source code path during deployment. diff --git a/bundle/direct/dresources/app.go b/bundle/direct/dresources/app.go index a8f1125e6a1..d9fd0a5f381 100644 --- a/bundle/direct/dresources/app.go +++ b/bundle/direct/dresources/app.go @@ -214,10 +214,10 @@ func (r *ResourceApp) manageLifecycle(ctx context.Context, id string, config *Ap return err } } - // source_code_path and git_source are set on the app via Create/Update, so the - // deployment carries only the inline config (command/env); the backend deploys - // from the app's configured source. - deployment := appdeploy.BuildDeployment("", config.Config, nil) + // source_code_path and git_source are also sent on Create/Update (so they are + // recorded on the app and drift-detected), but the Deploy API requires a + // deployment source, so the deployment carries them too. + deployment := appdeploy.BuildDeployment(config.SourceCodePath, config.Config, config.GitSource) if err := appdeploy.Deploy(ctx, r.client, id, deployment); err != nil { return err } diff --git a/libs/testserver/apps.go b/libs/testserver/apps.go index fefbfd1a6fb..7d6b104b54d 100644 --- a/libs/testserver/apps.go +++ b/libs/testserver/apps.go @@ -130,13 +130,6 @@ func (s *FakeWorkspace) AppsCreateDeployment(req Request, name string) Response return Response{StatusCode: 500, Body: fmt.Sprintf("internal error: %s", err)} } - // A config-only deployment omits source_code_path/git_source; the backend - // deploys from the app's configured source, so resolve them from the app. - if deployment.SourceCodePath == "" && deployment.GitSource == nil { - deployment.SourceCodePath = app.SourceCodePath - deployment.GitSource = app.GitSource - } - deployment.DeploymentId = fmt.Sprintf("deploy-%d", nextID()) deployment.Status = &apps.AppDeploymentStatus{ State: apps.AppDeploymentStateSucceeded, From 1cd08961dc1504a3f350239122355632b636da7b Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Wed, 11 Nov 2026 11:57:25 +0100 Subject: [PATCH 3/7] Fix changelog fragment format for app source_code_path change The bundles fragment was not a "* " bullet with a trailing PR link, so the Changelog Preview and the lint check-changelog step both failed. Rewrite it as a single bullet line that ends with the PR link. Co-authored-by: Isaac --- .nextchanges/bundles/app-source-code-path.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/bundles/app-source-code-path.md b/.nextchanges/bundles/app-source-code-path.md index 4872fc6c021..04e4a558351 100644 --- a/.nextchanges/bundles/app-source-code-path.md +++ b/.nextchanges/bundles/app-source-code-path.md @@ -1 +1 @@ -For apps deployed with the direct engine, `source_code_path` and `git_source` are now also sent as part of the Create/Update App request (in addition to the app Deploy API), so they are recorded on the app and drift-detected. The Terraform engine is unchanged (its `databricks_app` resource cannot manage these input-only fields). +* For apps deployed with the direct engine, `source_code_path` and `git_source` are now also sent as part of the Create/Update App request (in addition to the app Deploy API), so they are recorded on the app and drift-detected. The Terraform engine is unchanged (its `databricks_app` resource cannot manage these input-only fields). ([#6399](https://github.com/databricks/cli/pull/6399)) From 160bdfd651b40f9f0eac9a0649ca455e8295827b Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Wed, 11 Nov 2026 12:50:22 +0100 Subject: [PATCH 4/7] Send source_code_path and git_source on app Create and Update The Apps API accepts a non-empty source_code_path on UpdateApp (verified against a real workspace in the update-source-code-path-cloud test). Keep sending it on Create and Update so the app records and drift-detects it. An empty source_code_path is still never sent: #6401 showed the API rejects "source_code_path": "" and #6404 guards against it. The fake server now models both rules. Co-authored-by: Isaac --- .../remote_app_url/out.requests.direct.json | 54 ------------------- .../out.requests.terraform.json | 53 ------------------ .../resource_deps/remote_app_url/output.txt | 3 +- .../apps/config-no-deployment/output.txt | 4 +- .../out.requests.direct.json | 12 ----- .../out.requests.terraform.json | 11 ---- .../apps/default_description/output.txt | 12 +++++ .../resources/apps/default_description/script | 4 +- .../apps/git-source-no-deployment/output.txt | 6 +-- .../resources/apps/immutable/output.txt | 2 +- .../apps/lifecycle-started/output.txt | 4 +- .../resource-refs/out.requests.direct.json | 48 ----------------- .../resource-refs/out.requests.terraform.json | 47 ---------------- .../resources/apps/resource-refs/output.txt | 50 ++++++++++++++++- .../resources/apps/resource-refs/script | 4 +- .../source-code-path-update/out.test.toml | 2 +- .../apps/source-code-path-update/output.txt | 6 +-- .../apps/source-code-path-update/test.toml | 4 -- .../update-source-code-path-cloud/app/app.py | 1 + .../update-source-code-path-cloud/app2/app.py | 1 + .../databricks.yml.tmpl | 9 ++++ .../out.test.toml | 2 + .../update-source-code-path-cloud/output.txt | 52 ++++++++++++++++++ .../apps/update-source-code-path-cloud/script | 17 ++++++ .../update-source-code-path-cloud/test.toml | 12 +++++ .../resources/apps/update/out.requests.json | 2 +- bundle/direct/dresources/app.go | 36 +++++++------ bundle/direct/dresources/app_test.go | 44 ++++++++++----- libs/testserver/apps.go | 5 +- 29 files changed, 228 insertions(+), 279 deletions(-) delete mode 100644 acceptance/bundle/resource_deps/remote_app_url/out.requests.direct.json delete mode 100644 acceptance/bundle/resource_deps/remote_app_url/out.requests.terraform.json delete mode 100644 acceptance/bundle/resources/apps/default_description/out.requests.direct.json delete mode 100644 acceptance/bundle/resources/apps/default_description/out.requests.terraform.json delete mode 100644 acceptance/bundle/resources/apps/resource-refs/out.requests.direct.json delete mode 100644 acceptance/bundle/resources/apps/resource-refs/out.requests.terraform.json create mode 100644 acceptance/bundle/resources/apps/update-source-code-path-cloud/app/app.py create mode 100644 acceptance/bundle/resources/apps/update-source-code-path-cloud/app2/app.py create mode 100644 acceptance/bundle/resources/apps/update-source-code-path-cloud/databricks.yml.tmpl create mode 100644 acceptance/bundle/resources/apps/update-source-code-path-cloud/out.test.toml create mode 100644 acceptance/bundle/resources/apps/update-source-code-path-cloud/output.txt create mode 100755 acceptance/bundle/resources/apps/update-source-code-path-cloud/script create mode 100644 acceptance/bundle/resources/apps/update-source-code-path-cloud/test.toml diff --git a/acceptance/bundle/resource_deps/remote_app_url/out.requests.direct.json b/acceptance/bundle/resource_deps/remote_app_url/out.requests.direct.json deleted file mode 100644 index 92997feef74..00000000000 --- a/acceptance/bundle/resource_deps/remote_app_url/out.requests.direct.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "method": "POST", - "path": "/api/2.0/workspace/mkdirs", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state" - } -} -{ - "method": "POST", - "path": "/api/2.0/workspace/delete", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal", - "recursive": true - } -} -{ - "method": "POST", - "path": "/api/2.0/workspace/mkdirs", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal" - } -} -{ - "method": "POST", - "path": "/api/2.0/apps", - "q": { - "no_compute": "true" - }, - "body": { - "description": "best app", - "name": "myapp", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app" - } -} -{ - "method": "POST", - "path": "/api/2.0/pipelines", - "body": { - "channel": "CURRENT", - "deployment": { - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json" - }, - "edition": "ADVANCED", - "name": "app url is myapp-123.cloud.databricksapps.com" - } -} -{ - "method": "POST", - "path": "/api/2.0/workspace/delete", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock" - } -} diff --git a/acceptance/bundle/resource_deps/remote_app_url/out.requests.terraform.json b/acceptance/bundle/resource_deps/remote_app_url/out.requests.terraform.json deleted file mode 100644 index 4e6eb966fe5..00000000000 --- a/acceptance/bundle/resource_deps/remote_app_url/out.requests.terraform.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "method": "POST", - "path": "/api/2.0/workspace/mkdirs", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state" - } -} -{ - "method": "POST", - "path": "/api/2.0/workspace/delete", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal", - "recursive": true - } -} -{ - "method": "POST", - "path": "/api/2.0/workspace/mkdirs", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/artifacts/.internal" - } -} -{ - "method": "POST", - "path": "/api/2.0/apps", - "q": { - "no_compute": "true" - }, - "body": { - "description": "best app", - "name": "myapp" - } -} -{ - "method": "POST", - "path": "/api/2.0/pipelines", - "body": { - "channel": "CURRENT", - "deployment": { - "kind": "BUNDLE", - "metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json" - }, - "edition": "ADVANCED", - "name": "app url is myapp-123.cloud.databricksapps.com" - } -} -{ - "method": "POST", - "path": "/api/2.0/workspace/delete", - "body": { - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock" - } -} diff --git a/acceptance/bundle/resource_deps/remote_app_url/output.txt b/acceptance/bundle/resource_deps/remote_app_url/output.txt index 23808c5a896..7aad3166273 100644 --- a/acceptance/bundle/resource_deps/remote_app_url/output.txt +++ b/acceptance/bundle/resource_deps/remote_app_url/output.txt @@ -65,7 +65,8 @@ Resources: 2 created, 0 changed, 0 deleted, 0 unchanged }, "body": { "description": "best app", - "name": "myapp" + "name": "myapp", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app" } } { diff --git a/acceptance/bundle/resources/apps/config-no-deployment/output.txt b/acceptance/bundle/resources/apps/config-no-deployment/output.txt index a712e631cde..b1ea6a3bcda 100644 --- a/acceptance/bundle/resources/apps/config-no-deployment/output.txt +++ b/acceptance/bundle/resources/apps/config-no-deployment/output.txt @@ -6,11 +6,11 @@ Created apps.myapp Files: 3 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged -=== Plan is a no-op: config drift is skipped (no active deployment); source_code_path is input-only +=== Plan is a no-op: config/source_code_path drift is skipped while the app has no active deployment >>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged -=== config skipped with "no active deployment"; source_code_path skipped as input_only +=== Both deploy-only fields are skipped with reason "no active deployment" >>> [CLI] bundle plan -o json { "config": { diff --git a/acceptance/bundle/resources/apps/default_description/out.requests.direct.json b/acceptance/bundle/resources/apps/default_description/out.requests.direct.json deleted file mode 100644 index cc9779b7d46..00000000000 --- a/acceptance/bundle/resources/apps/default_description/out.requests.direct.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "method": "POST", - "path": "/api/2.0/apps", - "q": { - "no_compute": "true" - }, - "body": { - "description": "", - "name": "myappname", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files" - } -} diff --git a/acceptance/bundle/resources/apps/default_description/out.requests.terraform.json b/acceptance/bundle/resources/apps/default_description/out.requests.terraform.json deleted file mode 100644 index 37ce34a674e..00000000000 --- a/acceptance/bundle/resources/apps/default_description/out.requests.terraform.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "method": "POST", - "path": "/api/2.0/apps", - "q": { - "no_compute": "true" - }, - "body": { - "description": "", - "name": "myappname" - } -} diff --git a/acceptance/bundle/resources/apps/default_description/output.txt b/acceptance/bundle/resources/apps/default_description/output.txt index 4855cc04f6f..f669b91c679 100644 --- a/acceptance/bundle/resources/apps/default_description/output.txt +++ b/acceptance/bundle/resources/apps/default_description/output.txt @@ -6,3 +6,15 @@ Files: 2 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged >>> print_requests.py //apps +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "", + "name": "myappname", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files" + } +} diff --git a/acceptance/bundle/resources/apps/default_description/script b/acceptance/bundle/resources/apps/default_description/script index a1e67ada078..b9d834794d3 100644 --- a/acceptance/bundle/resources/apps/default_description/script +++ b/acceptance/bundle/resources/apps/default_description/script @@ -1,4 +1,2 @@ trace $CLI bundle deploy -# The create body diverges by engine: the direct engine sends source_code_path, the -# Terraform provider cannot manage it (input_only), so record requests per engine. -trace print_requests.py //apps > out.requests.$DATABRICKS_BUNDLE_ENGINE.json +trace print_requests.py //apps diff --git a/acceptance/bundle/resources/apps/git-source-no-deployment/output.txt b/acceptance/bundle/resources/apps/git-source-no-deployment/output.txt index a76204c014f..a6c809759a9 100644 --- a/acceptance/bundle/resources/apps/git-source-no-deployment/output.txt +++ b/acceptance/bundle/resources/apps/git-source-no-deployment/output.txt @@ -1,16 +1,16 @@ -=== Deploy: git_source is sent on Create; the app has no_compute so nothing is deployed yet +=== Deploy: app created with no_compute; git_source is not deployed until the app starts >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-git-source-no-deployment/default/files... Created apps.myapp Files: 1 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged -=== Plan is a no-op: git_source is input-only, so its drift is suppressed +=== Plan is a no-op: git_source drift is skipped while the app has no active deployment >>> [CLI] bundle plan Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged -=== git_source is skipped as input_only +=== git_source is skipped with reason "no active deployment" >>> [CLI] bundle plan -o json { "git_source": { diff --git a/acceptance/bundle/resources/apps/immutable/output.txt b/acceptance/bundle/resources/apps/immutable/output.txt index 6a66e055396..b9d91399c08 100644 --- a/acceptance/bundle/resources/apps/immutable/output.txt +++ b/acceptance/bundle/resources/apps/immutable/output.txt @@ -25,7 +25,7 @@ You can access the app at my-immutable-app-123.cloud.databricksapps.com "body": { "description": "", "name": "my-immutable-app", - "source_code_path": "/Workspace/Users/[UUID]/.snapshots/[UUID]/[SNAPSHOT_HASH]/files/app" + "source_code_path": "/Workspace/Users/[UUID][0]/.snapshots/[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID][1]/snapshot/files/app" } } { diff --git a/acceptance/bundle/resources/apps/lifecycle-started/output.txt b/acceptance/bundle/resources/apps/lifecycle-started/output.txt index e342a80bb7c..ee3ff917206 100644 --- a/acceptance/bundle/resources/apps/lifecycle-started/output.txt +++ b/acceptance/bundle/resources/apps/lifecycle-started/output.txt @@ -92,7 +92,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "name": "[UNIQUE_NAME]", "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" } } @@ -120,7 +120,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "name": "[UNIQUE_NAME]", "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" } } { diff --git a/acceptance/bundle/resources/apps/resource-refs/out.requests.direct.json b/acceptance/bundle/resources/apps/resource-refs/out.requests.direct.json deleted file mode 100644 index 194f2e69940..00000000000 --- a/acceptance/bundle/resources/apps/resource-refs/out.requests.direct.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "method": "POST", - "path": "/api/2.0/apps", - "q": { - "no_compute": "true" - }, - "body": { - "description": "A Streamlit app that uses a SQL warehouse", - "name": "data-app", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/resource-refs/default/files/app" - } -} -{ - "method": "POST", - "path": "/api/2.0/apps/data-app/start", - "body": {} -} -{ - "method": "POST", - "path": "/api/2.0/apps/data-app/deployments", - "body": { - "command": [ - "streamlit", - "run", - "app.py" - ], - "env_vars": [ - { - "name": "MY_EXAMPLE_SCHEMA", - "value": "main" - }, - { - "name": "MY_EXAMPLE_JOB", - "value": "example_job" - }, - { - "name": "MY_EXAMPLE_JOB_ID", - "value": "[NUMID]" - }, - { - "name": "MY_EXAMPLE_VAR", - "value": "example_value" - } - ], - "mode": "SNAPSHOT", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/resource-refs/default/files/app" - } -} diff --git a/acceptance/bundle/resources/apps/resource-refs/out.requests.terraform.json b/acceptance/bundle/resources/apps/resource-refs/out.requests.terraform.json deleted file mode 100644 index e6292cf773f..00000000000 --- a/acceptance/bundle/resources/apps/resource-refs/out.requests.terraform.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "method": "POST", - "path": "/api/2.0/apps", - "q": { - "no_compute": "true" - }, - "body": { - "description": "A Streamlit app that uses a SQL warehouse", - "name": "data-app" - } -} -{ - "method": "POST", - "path": "/api/2.0/apps/data-app/start", - "body": {} -} -{ - "method": "POST", - "path": "/api/2.0/apps/data-app/deployments", - "body": { - "command": [ - "streamlit", - "run", - "app.py" - ], - "env_vars": [ - { - "name": "MY_EXAMPLE_SCHEMA", - "value": "main" - }, - { - "name": "MY_EXAMPLE_JOB", - "value": "example_job" - }, - { - "name": "MY_EXAMPLE_JOB_ID", - "value": "[NUMID]" - }, - { - "name": "MY_EXAMPLE_VAR", - "value": "example_value" - } - ], - "mode": "SNAPSHOT", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/resource-refs/default/files/app" - } -} diff --git a/acceptance/bundle/resources/apps/resource-refs/output.txt b/acceptance/bundle/resources/apps/resource-refs/output.txt index 6eb5eb0ca96..57da4c9bcb7 100644 --- a/acceptance/bundle/resources/apps/resource-refs/output.txt +++ b/acceptance/bundle/resources/apps/resource-refs/output.txt @@ -4,7 +4,7 @@ Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/resource-refs/defa Created apps.data_app Created jobs.example_job Created schemas.example -Files: 5 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 3 created, 0 changed, 0 deleted, 0 unchanged >>> [CLI] bundle run data_app @@ -18,3 +18,51 @@ Resources: 3 created, 0 changed, 0 deleted, 0 unchanged You can access the app at data-app-123.cloud.databricksapps.com >>> print_requests.py //apps +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "A Streamlit app that uses a SQL warehouse", + "name": "data-app", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/resource-refs/default/files/app" + } +} +{ + "method": "POST", + "path": "/api/2.0/apps/data-app/start", + "body": {} +} +{ + "method": "POST", + "path": "/api/2.0/apps/data-app/deployments", + "body": { + "command": [ + "streamlit", + "run", + "app.py" + ], + "env_vars": [ + { + "name": "MY_EXAMPLE_SCHEMA", + "value": "main" + }, + { + "name": "MY_EXAMPLE_JOB", + "value": "example_job" + }, + { + "name": "MY_EXAMPLE_JOB_ID", + "value": "[EXAMPLE_JOB_ID]" + }, + { + "name": "MY_EXAMPLE_VAR", + "value": "example_value" + } + ], + "mode": "SNAPSHOT", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/resource-refs/default/files/app" + } +} diff --git a/acceptance/bundle/resources/apps/resource-refs/script b/acceptance/bundle/resources/apps/resource-refs/script index 9713b0e4a9d..79ad39f683a 100644 --- a/acceptance/bundle/resources/apps/resource-refs/script +++ b/acceptance/bundle/resources/apps/resource-refs/script @@ -1,6 +1,4 @@ trace $CLI bundle deploy read_id.py example_job > /dev/null trace $CLI bundle run data_app -# The create body diverges by engine: the direct engine sends source_code_path, the -# Terraform provider cannot manage it (input_only), so record requests per engine. -trace print_requests.py //apps > out.requests.$DATABRICKS_BUNDLE_ENGINE.json +trace print_requests.py //apps diff --git a/acceptance/bundle/resources/apps/source-code-path-update/out.test.toml b/acceptance/bundle/resources/apps/source-code-path-update/out.test.toml index 0938e678987..a927a5fbc06 100644 --- a/acceptance/bundle/resources/apps/source-code-path-update/out.test.toml +++ b/acceptance/bundle/resources/apps/source-code-path-update/out.test.toml @@ -1,2 +1,2 @@ Cloud = false -EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/apps/source-code-path-update/output.txt b/acceptance/bundle/resources/apps/source-code-path-update/output.txt index 4377365da60..7c197d0b908 100644 --- a/acceptance/bundle/resources/apps/source-code-path-update/output.txt +++ b/acceptance/bundle/resources/apps/source-code-path-update/output.txt @@ -3,7 +3,7 @@ >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files... Created apps.myapp -Files: 7 uploaded, 0 deleted +Files: 3 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged >>> print_requests.py //apps @@ -32,7 +32,7 @@ Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files... Updated apps.myapp -Files: 3 uploaded, 0 deleted +Files: 1 uploaded, 0 deleted Resources: 0 created, 1 changed, 0 deleted, 0 unchanged >>> print_requests.py //apps @@ -45,6 +45,6 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "name": "test-app-source-code-path-update", "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files/app2" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,forward_user_access_token,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" } } diff --git a/acceptance/bundle/resources/apps/source-code-path-update/test.toml b/acceptance/bundle/resources/apps/source-code-path-update/test.toml index bebd818be7b..731086bc182 100644 --- a/acceptance/bundle/resources/apps/source-code-path-update/test.toml +++ b/acceptance/bundle/resources/apps/source-code-path-update/test.toml @@ -1,7 +1,3 @@ Cloud = false Ignore = [".databricks"] - -# source_code_path is managed via Create/Update App, which only the direct engine -# supports (the Terraform databricks_app resource cannot manage this input_only field). -EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/app/app.py b/acceptance/bundle/resources/apps/update-source-code-path-cloud/app/app.py new file mode 100644 index 00000000000..c471b2f5ecf --- /dev/null +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/app/app.py @@ -0,0 +1 @@ +print("v1") diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/app2/app.py b/acceptance/bundle/resources/apps/update-source-code-path-cloud/app2/app.py new file mode 100644 index 00000000000..3d6edeb28df --- /dev/null +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/app2/app.py @@ -0,0 +1 @@ +print("v2") diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/databricks.yml.tmpl b/acceptance/bundle/resources/apps/update-source-code-path-cloud/databricks.yml.tmpl new file mode 100644 index 00000000000..2c88975cf7f --- /dev/null +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/databricks.yml.tmpl @@ -0,0 +1,9 @@ +bundle: + name: update-source-code-path-cloud-$UNIQUE_NAME + +resources: + apps: + myapp: + name: $UNIQUE_NAME + description: my_app_description + source_code_path: ./app diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/out.test.toml b/acceptance/bundle/resources/apps/update-source-code-path-cloud/out.test.toml new file mode 100644 index 00000000000..0f167effef1 --- /dev/null +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/out.test.toml @@ -0,0 +1,2 @@ +Cloud = true +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/output.txt b/acceptance/bundle/resources/apps/update-source-code-path-cloud/output.txt new file mode 100644 index 00000000000..ad758528ad4 --- /dev/null +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/output.txt @@ -0,0 +1,52 @@ + +=== Deploy: create the app with source_code_path +>>> errcode [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/update-source-code-path-cloud-[UNIQUE_NAME]/default/files... +Created apps.myapp +Files: 4 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //apps +{ + "method": "POST", + "path": "/api/2.0/apps", + "q": { + "no_compute": "true" + }, + "body": { + "description": "my_app_description", + "name": "[UNIQUE_NAME]", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/update-source-code-path-cloud-[UNIQUE_NAME]/default/files/app" + } +} + +=== Update an existing app with a new non-empty source_code_path +>>> update_file.py databricks.yml source_code_path: ./app source_code_path: ./app2 + +>>> errcode [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/update-source-code-path-cloud-[UNIQUE_NAME]/default/files... +Updated apps.myapp +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //apps +{ + "method": "POST", + "path": "/api/2.0/apps/[UNIQUE_NAME]/update", + "body": { + "app": { + "description": "my_app_description", + "name": "[UNIQUE_NAME]", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/update-source-code-path-cloud-[UNIQUE_NAME]/default/files/app2" + }, + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" + } +} + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.apps.myapp + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/update-source-code-path-cloud-[UNIQUE_NAME]/default + +Destroy: 1 deleted diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/script b/acceptance/bundle/resources/apps/update-source-code-path-cloud/script new file mode 100755 index 00000000000..8c50b7f92ef --- /dev/null +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/script @@ -0,0 +1,17 @@ +envsubst < databricks.yml.tmpl > databricks.yml + +cleanup() { + trace $CLI bundle destroy --auto-approve + rm -f out.requests.txt +} +trap cleanup EXIT + +title "Deploy: create the app with source_code_path" +trace errcode $CLI bundle deploy +trace print_requests.py //apps +rm -f out.requests.txt + +title "Update an existing app with a new non-empty source_code_path" +trace update_file.py databricks.yml "source_code_path: ./app" "source_code_path: ./app2" +trace errcode $CLI bundle deploy +trace print_requests.py //apps diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/test.toml b/acceptance/bundle/resources/apps/update-source-code-path-cloud/test.toml new file mode 100644 index 00000000000..18e2fffc5d0 --- /dev/null +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/test.toml @@ -0,0 +1,12 @@ +# Runs against a real workspace to establish whether UpdateApp accepts a non-empty +# source_code_path. Locally the fake server enforces the rule from #6404; see libs/testserver/apps.go. +Cloud = true +RecordRequests = true + +Ignore = [".databricks", "databricks.yml"] + +# App deployment progress messages are non-deterministic on cloud (different status messages +# per poll), so filter them out entirely. +[[Repls]] +Old = '(?m)^✓ [^\n]*\n' +New = "" diff --git a/acceptance/bundle/resources/apps/update/out.requests.json b/acceptance/bundle/resources/apps/update/out.requests.json index 5fe2b27eb95..3a5f6352d7f 100644 --- a/acceptance/bundle/resources/apps/update/out.requests.json +++ b/acceptance/bundle/resources/apps/update/out.requests.json @@ -19,7 +19,7 @@ "name": "myappname", "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" } } { diff --git a/bundle/direct/dresources/app.go b/bundle/direct/dresources/app.go index c7269a4c284..5955294d4ff 100644 --- a/bundle/direct/dresources/app.go +++ b/bundle/direct/dresources/app.go @@ -106,19 +106,18 @@ func (r *ResourceApp) DoRead(ctx context.Context, id string) (*AppRemote, error) return remote, nil } -// appRequestBody returns config.App with the deploy-only fields cleared. source_code_path -// and git_source became part of apps.App in SDK v0.175, but DABs applies them through the -// Deploy API (see manageLifecycle), so they must not ride along in create/update bodies. -// ForceSendFields is cloned and stripped of SourceCodePath because the SDK's JSON -// unmarshal (used when loading the plan) adds every present basic-type field to -// ForceSendFields, which would otherwise force "source_code_path": "" into the body. +// appRequestBody returns config.App for the Create/Update request. An empty source_code_path +// is never sent: the SDK's JSON unmarshal (used when loading the plan) adds every present +// basic-type field to ForceSendFields, which would otherwise force "source_code_path": "" +// into the body, and the API rejects that (see #6401, fixed in #6404). ForceSendFields is +// cloned so the plan entry is not modified. func appRequestBody(config *AppState) apps.App { app := config.App - app.SourceCodePath = "" - app.GitSource = nil - app.ForceSendFields = slices.DeleteFunc(slices.Clone(app.ForceSendFields), func(s string) bool { - return s == "SourceCodePath" - }) + if app.SourceCodePath == "" { + app.ForceSendFields = slices.DeleteFunc(slices.Clone(app.ForceSendFields), func(s string) bool { + return s == "SourceCodePath" + }) + } return app } @@ -127,7 +126,7 @@ func (r *ResourceApp) DoCreate(ctx context.Context, config *AppState) (string, * // For nil (omitted) or false, use no_compute=true (do not start compute). noCompute := config.Lifecycle == nil || config.Lifecycle.Started == nil || !*config.Lifecycle.Started request := apps.CreateAppRequest{ - App: config.App, + App: appRequestBody(config), NoCompute: noCompute, ForceSendFields: nil, } @@ -178,17 +177,24 @@ var UpdateMaskFields = []string{ "telemetry_export_destinations", } -var updateMask = strings.Join(UpdateMaskFields, ",") +// updateMaskFor returns the update mask for the request body. source_code_path is left out +// when the body omits it, so the update never asks the API to change a field it was not sent. +func updateMaskFor(app apps.App) string { + fields := slices.DeleteFunc(slices.Clone(UpdateMaskFields), func(s string) bool { + return s == "source_code_path" && app.SourceCodePath == "" + }) + return strings.Join(fields, ",") +} func (r *ResourceApp) DoUpdate(ctx context.Context, id string, config *AppState, entry *PlanEntry) (*AppRemote, error) { // source_code_path and git_source are sent as part of the App body (in the update // mask). Only config (command/env) is deploy-only and applied via manageLifecycle. if hasAppChanges(entry) { - app := config.App + app := appRequestBody(config) request := apps.AsyncUpdateAppRequest{ App: &app, AppName: id, - UpdateMask: updateMask, + UpdateMask: updateMaskFor(app), } updateWaiter, err := r.client.Apps.CreateUpdate(ctx, request) if err != nil { diff --git a/bundle/direct/dresources/app_test.go b/bundle/direct/dresources/app_test.go index a32dbdeb0ed..d7c6bc8cc74 100644 --- a/bundle/direct/dresources/app_test.go +++ b/bundle/direct/dresources/app_test.go @@ -173,14 +173,14 @@ func TestAppDoUpdate_UpdateMaskHasAllFields(t *testing.T) { } } -// TestAppRequestBody_StripsSourceCodePathFromForceSendFields verifies that -// appRequestBody removes SourceCodePath from ForceSendFields even when the plan -// JSON round-trip has forced it in — reproduces the v1.14.0 regression where -// "source_code_path": "" was sent in the UpdateApp body, causing a 400. -func TestAppRequestBody_StripsSourceCodePathFromForceSendFields(t *testing.T) { - config := &AppState{ - Name: "my-app", - SourceCodePath: "/Workspace/Users/me/app", +// TestAppRequestBody_StripsEmptySourceCodePathFromForceSendFields verifies that an empty +// SourceCodePath is removed from ForceSendFields even when the plan JSON round-trip has +// forced it in — reproduces the v1.14.0 regression (#6401) where "source_code_path": "" +// was sent in the UpdateApp body, causing a 400. +func TestAppRequestBody_StripsEmptySourceCodePathFromForceSendFields(t *testing.T) { + config := &AppState{} + config.App = apps.App{ + Name: "my-app", // Simulate ForceSendFields as populated by marshal.Unmarshal when the // plan entry is deserialized from JSON (ToStructVar calls json.Unmarshal, // which calls apps.App.UnmarshalJSON -> marshal.Unmarshal, which adds @@ -190,9 +190,7 @@ func TestAppRequestBody_StripsSourceCodePathFromForceSendFields(t *testing.T) { body := appRequestBody(config) - // SourceCodePath must be cleared and absent from ForceSendFields so that - // the SDK's marshal.Marshal omits it from the request body. - assert.Empty(t, body.SourceCodePath) + // Absent from ForceSendFields so that the SDK's marshal.Marshal omits it from the request body. assert.NotContains(t, body.ForceSendFields, "SourceCodePath") // Verify the field is absent from the marshaled JSON (the root cause of the 400). @@ -200,8 +198,30 @@ func TestAppRequestBody_StripsSourceCodePathFromForceSendFields(t *testing.T) { require.NoError(t, err) var m map[string]any require.NoError(t, json.Unmarshal(data, &m)) - assert.NotContains(t, m, "source_code_path", "source_code_path must not appear in the UpdateApp request body") + assert.NotContains(t, m, "source_code_path", "source_code_path must not appear in the request body when empty") // Other ForceSendFields entries must be preserved. assert.Contains(t, body.ForceSendFields, "Name") + // The plan entry itself must not be modified. + assert.Contains(t, config.ForceSendFields, "SourceCodePath") +} + +func TestAppRequestBody_SendsNonEmptySourceCodePath(t *testing.T) { + config := &AppState{} + config.App = apps.App{ + Name: "my-app", + SourceCodePath: "/Workspace/Users/me/app", + ForceSendFields: []string{"SourceCodePath"}, + } + + body := appRequestBody(config) + + assert.Equal(t, "/Workspace/Users/me/app", body.SourceCodePath) + assert.Contains(t, body.ForceSendFields, "SourceCodePath") +} + +func TestAppUpdateMaskOmitsEmptySourceCodePath(t *testing.T) { + assert.Contains(t, updateMaskFor(apps.App{SourceCodePath: "/Workspace/Users/me/app"}), "source_code_path") + assert.NotContains(t, updateMaskFor(apps.App{}), "source_code_path") + assert.Contains(t, updateMaskFor(apps.App{}), "git_source") } diff --git a/libs/testserver/apps.go b/libs/testserver/apps.go index abb92d77e91..a7ab2aab698 100644 --- a/libs/testserver/apps.go +++ b/libs/testserver/apps.go @@ -47,7 +47,8 @@ func (s *FakeWorkspace) AppsCreateUpdate(req Request, name string) Response { } } - // The real API rejects source_code_path in the UpdateApp body at any value. + // The real API rejects an empty source_code_path in the UpdateApp body (#6401: the CLI + // sent "source_code_path": "" and got a 400). A non-empty value is accepted. if updateReq.App != nil { var rawBody struct { App json.RawMessage `json:"app"` @@ -55,7 +56,7 @@ func (s *FakeWorkspace) AppsCreateUpdate(req Request, name string) Response { if err := json.Unmarshal(req.Body, &rawBody); err == nil { var appFields map[string]json.RawMessage if err := json.Unmarshal(rawBody.App, &appFields); err == nil { - if _, ok := appFields["source_code_path"]; ok { + if sourceCodePath, ok := appFields["source_code_path"]; ok && string(sourceCodePath) == `""` { return Response{ StatusCode: http.StatusBadRequest, Body: map[string]string{ From 521bf3067cf1c39af90b1f60e357455f68d411ad Mon Sep 17 00:00:00 2001 From: "andrew.nester" Date: Wed, 11 Nov 2026 13:12:08 +0000 Subject: [PATCH 5/7] Send source_code_path on app Create only; UpdateApp rejects it The production Integration Tests run for this PR rejected UpdateApp with 400 INVALID_PARAMETER_VALUE because the update mask contained source_code_path (lifecycle-started and update-source-code-path-cloud failed on every cloud). Apply the fallback from the PR description: - Keep source_code_path in the CreateApp body. On UpdateApp, clear it from the body and drop it from UpdateMaskFields; git_repository and git_source stay on both Create and Update. - Exclude source_code_path from hasAppChanges again, so a change to it alone no longer triggers an UpdateApp call that cannot carry it. The Deploy API in manageLifecycle still receives source_code_path. - Teach the fake server to reject source_code_path in the UpdateApp mask and in the body at any value, matching production, so the local suite catches a regression. - Rework the source-code-path-update acceptance test to assert both the no-request path for a source_code_path-only change and the UpdateApp body/mask without source_code_path on a description change; retitle the cloud test and regenerate affected outputs. Co-authored-by: Isaac --- .../apps/lifecycle-started/output.txt | 10 ++-- .../apps/source-code-path-update/output.txt | 20 +++++-- .../apps/source-code-path-update/script | 7 ++- .../update-source-code-path-cloud/output.txt | 14 +---- .../apps/update-source-code-path-cloud/script | 2 +- .../update-source-code-path-cloud/test.toml | 5 +- .../resources/apps/update/out.requests.json | 5 +- bundle/config/resources/apps.go | 13 +++-- bundle/direct/dresources/app.go | 55 +++++++++--------- bundle/direct/dresources/app_test.go | 57 +++++++++++++------ libs/testserver/apps.go | 18 +++++- 11 files changed, 124 insertions(+), 82 deletions(-) diff --git a/acceptance/bundle/resources/apps/lifecycle-started/output.txt b/acceptance/bundle/resources/apps/lifecycle-started/output.txt index ee3ff917206..a751de3c38b 100644 --- a/acceptance/bundle/resources/apps/lifecycle-started/output.txt +++ b/acceptance/bundle/resources/apps/lifecycle-started/output.txt @@ -89,10 +89,9 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "body": { "app": { "description": "MY_APP_DESCRIPTION_2", - "name": "[UNIQUE_NAME]", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" + "name": "[UNIQUE_NAME]" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } @@ -117,10 +116,9 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "body": { "app": { "description": "MY_APP_DESCRIPTION_3", - "name": "[UNIQUE_NAME]", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/lifecycle-started-[UNIQUE_NAME]/default/files/app" + "name": "[UNIQUE_NAME]" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } { diff --git a/acceptance/bundle/resources/apps/source-code-path-update/output.txt b/acceptance/bundle/resources/apps/source-code-path-update/output.txt index 7c197d0b908..a44e344e13f 100644 --- a/acceptance/bundle/resources/apps/source-code-path-update/output.txt +++ b/acceptance/bundle/resources/apps/source-code-path-update/output.txt @@ -28,7 +28,18 @@ update apps.myapp Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged -=== Redeploy: App Update sends the new source_code_path in the update mask +=== Redeploy: UpdateApp rejects source_code_path, so no app request is sent; the next Deploy applies it +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files... +Updated apps.myapp +Files: 1 uploaded, 0 deleted +Resources: 0 created, 1 changed, 0 deleted, 0 unchanged + +>>> print_requests.py //apps + +=== Change description: App Update omits source_code_path from the body and the update mask +>>> update_file.py databricks.yml my_app_description MY_APP_DESCRIPTION + >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files... Updated apps.myapp @@ -41,10 +52,9 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "path": "/api/2.0/apps/test-app-source-code-path-update/update", "body": { "app": { - "description": "my_app_description", - "name": "test-app-source-code-path-update", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/app-source-code-path-update/default/files/app2" + "description": "MY_APP_DESCRIPTION", + "name": "test-app-source-code-path-update" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } diff --git a/acceptance/bundle/resources/apps/source-code-path-update/script b/acceptance/bundle/resources/apps/source-code-path-update/script index 9766c0933b9..58260eb246d 100644 --- a/acceptance/bundle/resources/apps/source-code-path-update/script +++ b/acceptance/bundle/resources/apps/source-code-path-update/script @@ -6,6 +6,11 @@ title "Change source_code_path: plan detects an update" trace update_file.py databricks.yml "source_code_path: ./app" "source_code_path: ./app2" trace $CLI bundle plan -title "Redeploy: App Update sends the new source_code_path in the update mask" +title "Redeploy: UpdateApp rejects source_code_path, so no app request is sent; the next Deploy applies it" +trace $CLI bundle deploy +trace print_requests.py //apps + +title "Change description: App Update omits source_code_path from the body and the update mask" +trace update_file.py databricks.yml my_app_description MY_APP_DESCRIPTION trace $CLI bundle deploy trace print_requests.py //apps diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/output.txt b/acceptance/bundle/resources/apps/update-source-code-path-cloud/output.txt index ad758528ad4..1c5abd1ee9d 100644 --- a/acceptance/bundle/resources/apps/update-source-code-path-cloud/output.txt +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/output.txt @@ -20,7 +20,7 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged } } -=== Update an existing app with a new non-empty source_code_path +=== Change source_code_path on an existing app: no UpdateApp request is sent >>> update_file.py databricks.yml source_code_path: ./app source_code_path: ./app2 >>> errcode [CLI] bundle deploy @@ -30,18 +30,6 @@ Files: 1 uploaded, 0 deleted Resources: 0 created, 1 changed, 0 deleted, 0 unchanged >>> print_requests.py //apps -{ - "method": "POST", - "path": "/api/2.0/apps/[UNIQUE_NAME]/update", - "body": { - "app": { - "description": "my_app_description", - "name": "[UNIQUE_NAME]", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/update-source-code-path-cloud-[UNIQUE_NAME]/default/files/app2" - }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" - } -} >>> [CLI] bundle destroy --auto-approve The following resources will be deleted: diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/script b/acceptance/bundle/resources/apps/update-source-code-path-cloud/script index 8c50b7f92ef..6179a002e1d 100755 --- a/acceptance/bundle/resources/apps/update-source-code-path-cloud/script +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/script @@ -11,7 +11,7 @@ trace errcode $CLI bundle deploy trace print_requests.py //apps rm -f out.requests.txt -title "Update an existing app with a new non-empty source_code_path" +title "Change source_code_path on an existing app: no UpdateApp request is sent" trace update_file.py databricks.yml "source_code_path: ./app" "source_code_path: ./app2" trace errcode $CLI bundle deploy trace print_requests.py //apps diff --git a/acceptance/bundle/resources/apps/update-source-code-path-cloud/test.toml b/acceptance/bundle/resources/apps/update-source-code-path-cloud/test.toml index 18e2fffc5d0..34b9beb94c8 100644 --- a/acceptance/bundle/resources/apps/update-source-code-path-cloud/test.toml +++ b/acceptance/bundle/resources/apps/update-source-code-path-cloud/test.toml @@ -1,5 +1,6 @@ -# Runs against a real workspace to establish whether UpdateApp accepts a non-empty -# source_code_path. Locally the fake server enforces the rule from #6404; see libs/testserver/apps.go. +# Runs against a real workspace: production rejects source_code_path in the UpdateApp mask +# (400 INVALID_PARAMETER_VALUE), so changing it on an existing app must not call UpdateApp. +# Locally the fake server enforces the same rule; see libs/testserver/apps.go. Cloud = true RecordRequests = true diff --git a/acceptance/bundle/resources/apps/update/out.requests.json b/acceptance/bundle/resources/apps/update/out.requests.json index 3a5f6352d7f..71886304e06 100644 --- a/acceptance/bundle/resources/apps/update/out.requests.json +++ b/acceptance/bundle/resources/apps/update/out.requests.json @@ -16,10 +16,9 @@ "body": { "app": { "description": "MY_APP_DESCRIPTION", - "name": "myappname", - "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app" + "name": "myappname" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,source_code_path,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } { diff --git a/bundle/config/resources/apps.go b/bundle/config/resources/apps.go index a082ad20f2f..fcf2b9f3851 100644 --- a/bundle/config/resources/apps.go +++ b/bundle/config/resources/apps.go @@ -44,12 +44,13 @@ type App struct { // Lifecycle shadows BaseResource.Lifecycle to add support for lifecycle.started. Lifecycle *LifecycleWithStarted `json:"lifecycle,omitempty"` - // SourceCodePath and GitSource come from the embedded apps.App and are sent as part of - // the Create/Update App request so they are recorded on the app. source_code_path points - // at app source on local disk and is translated to its workspace path. The API accepts - // both on write but does not echo them on read (input_only), so drift is suppressed via - // ignore_remote_changes. They are also passed to the Deploy API, which requires a - // deployment source. Declaring them here too would duplicate their json tags and break diffing. + // SourceCodePath and GitSource come from the embedded apps.App and are sent in the Create + // App request so they are recorded on the app; git_source is also sent on Update, while + // UpdateApp rejects source_code_path. source_code_path points at app source on local disk + // and is translated to its workspace path. The API accepts both on write but does not echo + // them on read (input_only), so drift is suppressed via ignore_remote_changes. They are + // also passed to the Deploy API, which requires a deployment source. Declaring them here + // too would duplicate their json tags and break diffing. // Config represents inline app.yaml configuration for the app. // When specified, this configuration is written to an app.yaml file in the source code path during deployment. diff --git a/bundle/direct/dresources/app.go b/bundle/direct/dresources/app.go index 5955294d4ff..5cd4cb04846 100644 --- a/bundle/direct/dresources/app.go +++ b/bundle/direct/dresources/app.go @@ -99,20 +99,19 @@ func (r *ResourceApp) DoRead(ctx context.Context, id string) (*AppRemote, error) if app.ActiveDeployment != nil { // config (command/env) is not part of apps.App, so it is read back from the // active deployment for drift detection. source_code_path and git_source are - // sent on Create/Update and classified input_only, so their remote value is - // ignored (see resources.generated.yml) and does not need populating here. + // classified input_only, so their remote value is ignored (see + // apps.generated.yml) and does not need populating here. remote.Config = deploymentToAppConfig(app.ActiveDeployment) } return remote, nil } -// appRequestBody returns config.App for the Create/Update request. An empty source_code_path +// appRequestBody returns app for the Create/Update request body. An empty source_code_path // is never sent: the SDK's JSON unmarshal (used when loading the plan) adds every present // basic-type field to ForceSendFields, which would otherwise force "source_code_path": "" // into the body, and the API rejects that (see #6401, fixed in #6404). ForceSendFields is // cloned so the plan entry is not modified. -func appRequestBody(config *AppState) apps.App { - app := config.App +func appRequestBody(app apps.App) apps.App { if app.SourceCodePath == "" { app.ForceSendFields = slices.DeleteFunc(slices.Clone(app.ForceSendFields), func(s string) bool { return s == "SourceCodePath" @@ -121,12 +120,22 @@ func appRequestBody(config *AppState) apps.App { return app } +// appUpdateBody returns config.App for the Update request. UpdateApp rejects source_code_path +// (400 INVALID_PARAMETER_VALUE: invalid update mask), so it is sent on Create only and is not +// in UpdateMaskFields; a changed source_code_path reaches the app through the Deploy API +// (see manageLifecycle). git_source is accepted on Update and stays in the body. +func appUpdateBody(config *AppState) apps.App { + app := config.App + app.SourceCodePath = "" + return appRequestBody(app) +} + func (r *ResourceApp) DoCreate(ctx context.Context, config *AppState) (string, *AppRemote, error) { // Start app compute only when lifecycle.started=true is explicit. // For nil (omitted) or false, use no_compute=true (do not start compute). noCompute := config.Lifecycle == nil || config.Lifecycle.Started == nil || !*config.Lifecycle.Started request := apps.CreateAppRequest{ - App: appRequestBody(config), + App: appRequestBody(config.App), NoCompute: noCompute, ForceSendFields: nil, } @@ -162,6 +171,8 @@ func (r *ResourceApp) DoCreate(ctx context.Context, config *AppState) (string, * return app.Name, nil, nil } +// UpdateMaskFields lists the App fields UpdateApp may change. source_code_path is absent +// because the API rejects it in the update mask; see appUpdateBody. var UpdateMaskFields = []string{ "description", "budget_policy_id", @@ -173,28 +184,20 @@ var UpdateMaskFields = []string{ "compute_max_instances", "git_repository", "git_source", - "source_code_path", "telemetry_export_destinations", } -// updateMaskFor returns the update mask for the request body. source_code_path is left out -// when the body omits it, so the update never asks the API to change a field it was not sent. -func updateMaskFor(app apps.App) string { - fields := slices.DeleteFunc(slices.Clone(UpdateMaskFields), func(s string) bool { - return s == "source_code_path" && app.SourceCodePath == "" - }) - return strings.Join(fields, ",") -} +var updateMask = strings.Join(UpdateMaskFields, ",") func (r *ResourceApp) DoUpdate(ctx context.Context, id string, config *AppState, entry *PlanEntry) (*AppRemote, error) { - // source_code_path and git_source are sent as part of the App body (in the update - // mask). Only config (command/env) is deploy-only and applied via manageLifecycle. + // git_source is sent as part of the App body (in the update mask). source_code_path and + // config (command/env) are deploy-only on update and applied via manageLifecycle. if hasAppChanges(entry) { - app := appRequestBody(config) + app := appUpdateBody(config) request := apps.AsyncUpdateAppRequest{ App: &app, AppName: id, - UpdateMask: updateMaskFor(app), + UpdateMask: updateMask, } updateWaiter, err := r.client.Apps.CreateUpdate(ctx, request) if err != nil { @@ -235,9 +238,9 @@ func (r *ResourceApp) manageLifecycle(ctx context.Context, id string, config *Ap return err } } - // source_code_path and git_source are also sent on Create/Update (so they are - // recorded on the app and drift-detected), but the Deploy API requires a - // deployment source, so the deployment carries them too. + // source_code_path is recorded on the app at Create and git_source at Create/Update, + // but the Deploy API requires a deployment source, so the deployment carries them + // too. This is also the only way a changed source_code_path reaches the app. deployment := appdeploy.BuildDeployment(config.SourceCodePath, config.Config, config.GitSource) if err := appdeploy.Deploy(ctx, r.client, id, deployment); err != nil { return err @@ -258,11 +261,11 @@ func (r *ResourceApp) manageLifecycle(ctx context.Context, id string, config *Ap return nil } -// hasAppChanges reports whether the plan entry contains any Update changes -// to fields that belong to the App Update API. config (command/env) is deploy-only -// and applied via manageLifecycle; lifecycle drives compute start/stop. +// hasAppChanges reports whether the plan entry contains any Update changes to fields that +// belong to the App Update API. source_code_path and config (command/env) are deploy-only +// on update and applied via manageLifecycle; lifecycle drives compute start/stop. func hasAppChanges(entry *PlanEntry) bool { - return entry.Changes.HasChangeExcept("config", "lifecycle", "lifecycle.started") + return entry.Changes.HasChangeExcept("source_code_path", "config", "lifecycle", "lifecycle.started") } // OverrideChangeDesc skips drift on config (command/env) while the app has no active diff --git a/bundle/direct/dresources/app_test.go b/bundle/direct/dresources/app_test.go index d7c6bc8cc74..92423c03dd3 100644 --- a/bundle/direct/dresources/app_test.go +++ b/bundle/direct/dresources/app_test.go @@ -178,8 +178,7 @@ func TestAppDoUpdate_UpdateMaskHasAllFields(t *testing.T) { // forced it in — reproduces the v1.14.0 regression (#6401) where "source_code_path": "" // was sent in the UpdateApp body, causing a 400. func TestAppRequestBody_StripsEmptySourceCodePathFromForceSendFields(t *testing.T) { - config := &AppState{} - config.App = apps.App{ + app := apps.App{ Name: "my-app", // Simulate ForceSendFields as populated by marshal.Unmarshal when the // plan entry is deserialized from JSON (ToStructVar calls json.Unmarshal, @@ -188,40 +187,66 @@ func TestAppRequestBody_StripsEmptySourceCodePathFromForceSendFields(t *testing. ForceSendFields: []string{"Name", "SourceCodePath"}, } - body := appRequestBody(config) + body := appRequestBody(app) // Absent from ForceSendFields so that the SDK's marshal.Marshal omits it from the request body. assert.NotContains(t, body.ForceSendFields, "SourceCodePath") // Verify the field is absent from the marshaled JSON (the root cause of the 400). - data, err := json.Marshal(body) - require.NoError(t, err) - var m map[string]any - require.NoError(t, json.Unmarshal(data, &m)) - assert.NotContains(t, m, "source_code_path", "source_code_path must not appear in the request body when empty") + assert.NotContains(t, marshalFields(t, body), "source_code_path", "source_code_path must not appear in the request body when empty") // Other ForceSendFields entries must be preserved. assert.Contains(t, body.ForceSendFields, "Name") // The plan entry itself must not be modified. - assert.Contains(t, config.ForceSendFields, "SourceCodePath") + assert.Contains(t, app.ForceSendFields, "SourceCodePath") } func TestAppRequestBody_SendsNonEmptySourceCodePath(t *testing.T) { - config := &AppState{} - config.App = apps.App{ + app := apps.App{ Name: "my-app", SourceCodePath: "/Workspace/Users/me/app", ForceSendFields: []string{"SourceCodePath"}, } - body := appRequestBody(config) + body := appRequestBody(app) assert.Equal(t, "/Workspace/Users/me/app", body.SourceCodePath) assert.Contains(t, body.ForceSendFields, "SourceCodePath") } -func TestAppUpdateMaskOmitsEmptySourceCodePath(t *testing.T) { - assert.Contains(t, updateMaskFor(apps.App{SourceCodePath: "/Workspace/Users/me/app"}), "source_code_path") - assert.NotContains(t, updateMaskFor(apps.App{}), "source_code_path") - assert.Contains(t, updateMaskFor(apps.App{}), "git_source") +// TestAppUpdateBody_OmitsSourceCodePath verifies that the UpdateApp body never carries +// source_code_path, even when the plan entry has a value and ForceSendFields lists it, +// while git_source is kept. Production rejects source_code_path on UpdateApp. +func TestAppUpdateBody_OmitsSourceCodePath(t *testing.T) { + config := &AppState{} + config.App = apps.App{ + Name: "my-app", + SourceCodePath: "/Workspace/Users/me/app", + GitSource: &apps.GitSource{Branch: "main"}, + ForceSendFields: []string{"Name", "SourceCodePath"}, + } + + body := appUpdateBody(config) + + fields := marshalFields(t, body) + assert.NotContains(t, fields, "source_code_path") + assert.Contains(t, fields, "git_source") + assert.NotContains(t, body.ForceSendFields, "SourceCodePath") + // The plan entry itself must not be modified. + assert.Equal(t, "/Workspace/Users/me/app", config.SourceCodePath) + assert.Contains(t, config.ForceSendFields, "SourceCodePath") +} + +func TestAppUpdateMaskOmitsSourceCodePath(t *testing.T) { + assert.NotContains(t, UpdateMaskFields, "source_code_path") + assert.Contains(t, UpdateMaskFields, "git_source") +} + +// marshalFields returns the JSON field names the SDK marshaler emits for app. +func marshalFields(t *testing.T, app apps.App) map[string]any { + data, err := json.Marshal(app) + require.NoError(t, err) + var m map[string]any + require.NoError(t, json.Unmarshal(data, &m)) + return m } diff --git a/libs/testserver/apps.go b/libs/testserver/apps.go index a7ab2aab698..208c9a33e5a 100644 --- a/libs/testserver/apps.go +++ b/libs/testserver/apps.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "slices" "strconv" "strings" @@ -47,16 +48,27 @@ func (s *FakeWorkspace) AppsCreateUpdate(req Request, name string) Response { } } - // The real API rejects an empty source_code_path in the UpdateApp body (#6401: the CLI - // sent "source_code_path": "" and got a 400). A non-empty value is accepted. + // The real API rejects source_code_path on UpdateApp both in the update mask + // (production returns 400 INVALID_PARAMETER_VALUE "Invalid update mask", see + // https://github.com/databricks/cli/pull/6399) and in the body at any value (#6401: + // the CLI sent "source_code_path": "" and got a 400). if updateReq.App != nil { + if slices.Contains(strings.Split(updateReq.UpdateMask, ","), "source_code_path") { + return Response{ + StatusCode: http.StatusBadRequest, + Body: map[string]string{ + "error_code": "INVALID_PARAMETER_VALUE", + "message": "Invalid update mask: source_code_path cannot be updated.", + }, + } + } var rawBody struct { App json.RawMessage `json:"app"` } if err := json.Unmarshal(req.Body, &rawBody); err == nil { var appFields map[string]json.RawMessage if err := json.Unmarshal(rawBody.App, &appFields); err == nil { - if sourceCodePath, ok := appFields["source_code_path"]; ok && string(sourceCodePath) == `""` { + if _, ok := appFields["source_code_path"]; ok { return Response{ StatusCode: http.StatusBadRequest, Body: map[string]string{ From f9fa887cc71347da7b51be00a1f3cfa1668956ae Mon Sep 17 00:00:00 2001 From: "andrew.nester" Date: Wed, 11 Nov 2026 13:12:10 +0000 Subject: [PATCH 6/7] Reword changelog fragment for app source_code_path on Create only Co-authored-by: Isaac --- .nextchanges/bundles/app-source-code-path.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/bundles/app-source-code-path.md b/.nextchanges/bundles/app-source-code-path.md index 04e4a558351..92d30119638 100644 --- a/.nextchanges/bundles/app-source-code-path.md +++ b/.nextchanges/bundles/app-source-code-path.md @@ -1 +1 @@ -* For apps deployed with the direct engine, `source_code_path` and `git_source` are now also sent as part of the Create/Update App request (in addition to the app Deploy API), so they are recorded on the app and drift-detected. The Terraform engine is unchanged (its `databricks_app` resource cannot manage these input-only fields). ([#6399](https://github.com/databricks/cli/pull/6399)) +* Send `source_code_path` on the app Create request and `git_source` on the app Create and Update requests, so the app records its configured source before its first deployment. ([#6399](https://github.com/databricks/cli/pull/6399)) From c6b5e564f450936ca28d5a7ae861d4238386fcba Mon Sep 17 00:00:00 2001 From: "andrew.nester" Date: Wed, 11 Nov 2026 15:44:49 +0000 Subject: [PATCH 7/7] Fix merge of app_test.go and regenerate apps goldens The merge of main (#7461) into this branch kept main's header for the old TestAppRequestBody_StripsSourceCodePathFromForceSendFields on top of this branch's rewritten body, which no longer compiled (undefined: app). Restore this branch's TestAppRequestBody_StripsEmptySourceCodePathFromForceSendFields below main's TestAppUpdateMask_ComputeSizeFollowsBody. Regenerate the apps acceptance goldens so they reflect both parents: - update, lifecycle-started: the merge took main's copy, which lacked this branch's git_source in the update mask. - update-compute-size (new on main): add source_code_path to the Create body and git_source to the update mask (this branch). - source-code-path-update (new on this branch): drop compute_size from the update mask when the bundle does not declare it (main, #7461). Co-authored-by: Isaac --- .../resources/apps/lifecycle-started/output.txt | 4 ++-- .../apps/source-code-path-update/output.txt | 2 +- .../apps/update-compute-size/out.requests.json | 7 ++++--- .../resources/apps/update/out.requests.json | 2 +- bundle/direct/dresources/app_test.go | 15 +++++++-------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/acceptance/bundle/resources/apps/lifecycle-started/output.txt b/acceptance/bundle/resources/apps/lifecycle-started/output.txt index 1da00ef351b..8add3993e89 100644 --- a/acceptance/bundle/resources/apps/lifecycle-started/output.txt +++ b/acceptance/bundle/resources/apps/lifecycle-started/output.txt @@ -91,7 +91,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "description": "MY_APP_DESCRIPTION_2", "name": "[UNIQUE_NAME]" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } @@ -118,7 +118,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "description": "MY_APP_DESCRIPTION_3", "name": "[UNIQUE_NAME]" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } { diff --git a/acceptance/bundle/resources/apps/source-code-path-update/output.txt b/acceptance/bundle/resources/apps/source-code-path-update/output.txt index a44e344e13f..afaff25ce2e 100644 --- a/acceptance/bundle/resources/apps/source-code-path-update/output.txt +++ b/acceptance/bundle/resources/apps/source-code-path-update/output.txt @@ -55,6 +55,6 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "description": "MY_APP_DESCRIPTION", "name": "test-app-source-code-path-update" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } diff --git a/acceptance/bundle/resources/apps/update-compute-size/out.requests.json b/acceptance/bundle/resources/apps/update-compute-size/out.requests.json index c39f33c9920..86487cb3ebb 100644 --- a/acceptance/bundle/resources/apps/update-compute-size/out.requests.json +++ b/acceptance/bundle/resources/apps/update-compute-size/out.requests.json @@ -7,7 +7,8 @@ "body": { "compute_size": "LARGE", "description": "my_app_description", - "name": "myappname" + "name": "myappname", + "source_code_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files/app" } } { @@ -19,7 +20,7 @@ "description": "MY_APP_DESCRIPTION", "name": "myappname" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } { @@ -30,6 +31,6 @@ "description": "MY_APP_DESCRIPTION_2", "name": "myappname" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } diff --git a/acceptance/bundle/resources/apps/update/out.requests.json b/acceptance/bundle/resources/apps/update/out.requests.json index de91f238968..0d5eeecc7c2 100644 --- a/acceptance/bundle/resources/apps/update/out.requests.json +++ b/acceptance/bundle/resources/apps/update/out.requests.json @@ -18,7 +18,7 @@ "description": "MY_APP_DESCRIPTION", "name": "myappname" }, - "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations" + "update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,git_source,telemetry_export_destinations" } } { diff --git a/bundle/direct/dresources/app_test.go b/bundle/direct/dresources/app_test.go index 442a1309771..e83631d5d82 100644 --- a/bundle/direct/dresources/app_test.go +++ b/bundle/direct/dresources/app_test.go @@ -192,14 +192,13 @@ func TestAppUpdateMask_ComputeSizeFollowsBody(t *testing.T) { } } -// TestAppRequestBody_StripsSourceCodePathFromForceSendFields verifies that -// appRequestBody removes SourceCodePath from ForceSendFields even when the plan -// JSON round-trip has forced it in — reproduces the v1.14.0 regression where -// "source_code_path": "" was sent in the UpdateApp body, causing a 400. -func TestAppRequestBody_StripsSourceCodePathFromForceSendFields(t *testing.T) { - config := &AppState{ - Name: "my-app", - SourceCodePath: "/Workspace/Users/me/app", +// TestAppRequestBody_StripsEmptySourceCodePathFromForceSendFields verifies that an empty +// SourceCodePath is removed from ForceSendFields even when the plan JSON round-trip has +// forced it in — reproduces the v1.14.0 regression (#6401) where "source_code_path": "" +// was sent in the UpdateApp body, causing a 400. +func TestAppRequestBody_StripsEmptySourceCodePathFromForceSendFields(t *testing.T) { + app := apps.App{ + Name: "my-app", // Simulate ForceSendFields as populated by marshal.Unmarshal when the // plan entry is deserialized from JSON (ToStructVar calls json.Unmarshal, // which calls apps.App.UnmarshalJSON -> marshal.Unmarshal, which adds