Skip to content

Commit 13252d5

Browse files
denikIsaac
andcommitted
acc: remove engine-specific logic from the acceptance harness
The terraform engine is gone, so no test varies DATABRICKS_BUNDLE_ENGINE anymore. - Drop the engine-aware subset grouping and 10x direct weighting; subset selection now hashes over all variants. - Drop the EnvMatrix.DATABRICKS_BUNDLE_ENGINE = [] validation, the terraform CHECKPOINT_DISABLE env, and the DBR runner's engine ENVFILTER. - Gate eventual-consistency injection on INJECT_STALE_ON_DIRECT alone. This makes postgres_synced_tables/recreate_capped exercise the capped wait it was written for (its golden previously showed a successful recreate). - read_state.py/print_state.py: drop the terraform-engine branch; print_state.py decides on DMS recording from the state file, not the engine env var. - Make engine-conditional test assertions unconditional, drop the dead permissions direct-vs-terraform comparison, and the terraform-only exclusions in empty_string_dropped/gen_empty_config.py (fixture and goldens regenerated). - Update testing rules that described the two-engine matrix. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 4e9d99e commit 13252d5

31 files changed

Lines changed: 89 additions & 407 deletions

File tree

‎.agents/rules/testing.md‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The whole `Cloud*` family lives inside an `if isRunningOnCloud` branch in `getSk
6666

6767
Exception: mass string replacement when the change is predictable and much cheaper than re-running the test suite.
6868

69-
**RULE: All `EnvMatrix` variants MUST produce identical output files.** Filenames containing `$DATABRICKS_BUNDLE_ENGINE` (e.g. `output.direct.txt`) are the only per-engine exception.
69+
**RULE: All `EnvMatrix` variants MUST produce identical output files.** The only exception is a test that sets `EnvVaryOutput`, whose files named after the variant value (e.g. `out.deploy.<value>.txt`) are per-variant.
7070

7171
**RULE: Do not run `-update` while a divergent variant exists.** It is destructive: it overwrites with the last variant and breaks the others. To debug: run a single variant you consider correct with `-update`, then debug the other variant to find why it diverges.
7272

@@ -95,13 +95,9 @@ acceptance/cmd/fs/cp/file-to-dir/
9595
output.txt
9696
```
9797

98-
**RULE: When output genuinely diverges between engines (terraform vs direct), split only the diverging file into per-engine variants.** Keep the rest of the output unified. Files named `output.$DATABRICKS_BUNDLE_ENGINE.txt` or `out.requests.$DATABRICKS_BUNDLE_ENGINE.json` are the allowed per-engine form.
99-
100-
If the only reason for divergence is a server-side default that one engine sets and the other doesn't, set the field explicitly in `databricks.yml` so both engines produce identical output. Don't paper over it with per-engine files.
101-
10298
**RULE: On Windows, Git Bash auto-converts a leading-`/` path argument (e.g. `/api/2.0/...`) into a Windows path, so `$CLI` sees the wrong path and the testserver 404s.** Set `Env.MSYS_NO_PATHCONV = "1"` in the test directory's `test.toml`. Quoting the argument in bash does NOT help — the conversion is done by the Windows binary's argument processing. Precedent: `acceptance/cmd/workspace/export-dir-*/test.toml`.
10399

104-
**RULE: `EnvMatrix.<VAR> = []` removes that variable from the inherited matrix** (see `ExpandEnvMatrix` in `acceptance/internal/config.go`). The root `test.toml` matrixes `DATABRICKS_BUNDLE_ENGINE = [terraform, direct]`, so a non-bundle test opts out of both engine runs with `EnvMatrix.DATABRICKS_BUNDLE_ENGINE = []`. The `out.test.toml` snapshot of inherited values is generated and committed by design.
100+
**RULE: `EnvMatrix.<VAR> = []` removes that variable from the inherited matrix** (see `ExpandEnvMatrix` in `acceptance/internal/config.go`). For example, `acceptance/bundle/test.toml` matrixes `DMS = ["", "true"]`, so a bundle test opts out of the DMS run with `EnvMatrix.DMS = []`. The `out.test.toml` snapshot of inherited values is generated and committed by design.
105101

106102
**RULE: Write every map-valued setting in dotted form at the top of `test.toml`, never under a table header.** This covers `Env`, `EnvMatrix`, `EnvMatrixExclude`, `EnvRepl`, `GOOS` and `CloudEnvs` — e.g. `Env.MSYS_NO_PATHCONV = "1"`, `GOOS.windows = false`. In TOML every key after a `[EnvMatrix]` header belongs to that table until the next header — a blank line does not end it. So a top-level key like `Ignore` placed below `[EnvMatrix]` is silently parsed as `EnvMatrix.Ignore` (a bogus matrix variable) instead of the real top-level field, and the test runs with the field unset. Dotted form keeps each key's table explicit and is immune to ordering.
107103

@@ -110,15 +106,15 @@ If the only reason for divergence is a server-side default that one engine sets
110106
GOOD:
111107

112108
```toml
113-
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"]
109+
EnvMatrix.READPLAN = ["", "1"]
114110
Ignore = ["databricks.yml"]
115111
```
116112

117113
BAD:
118114

119115
```toml
120116
[EnvMatrix]
121-
DATABRICKS_BUNDLE_ENGINE = ["direct"]
117+
READPLAN = ["", "1"]
122118

123119
Ignore = ["databricks.yml"] # parsed as EnvMatrix.Ignore, not top-level Ignore
124120
```
@@ -132,7 +128,7 @@ Ignore = ["databricks.yml"] # parsed as EnvMatrix.Ignore, not top-level Ignore
132128
- Source files: `test.toml`, `script`, `script.prepare`, `databricks.yml`, etc.
133129
- Tests are configured via `test.toml`. Config schema and explanation is in `acceptance/internal/config.go`. Certain options are also dumped to `out.test.toml` so that inherited values are visible on PRs.
134130
- Run a single test: `go test ./acceptance -run TestAccept/bundle/<path>/<to>/<folder>`
135-
- Run a specific variant by appending `EnvMatrix` values to the test name: `go test ./acceptance -run 'TestAccept/.../DATABRICKS_BUNDLE_ENGINE=direct'`. When there are multiple `EnvMatrix` variables, they appear in alphabetical order.
131+
- Run a specific variant by appending `EnvMatrix` values to the test name: `go test ./acceptance -run 'TestAccept/.../DMS=true'`. When there are multiple `EnvMatrix` variables, they appear in alphabetical order.
136132
- Useful flags: `-v` for verbose output, `-tail` to follow test output (requires `-v`), `-logrequests` to log all HTTP requests/responses (requires `-v`).
137133
- Run tests on cloud: `deco env run -i -n aws-prod-ucws -- <go test command>` (requires `deco` tool and access to test env). This is an *additional* pass over the same test directories, restricted to those with `Cloud = true` set; it does not replace the local run.
138134
- `script.prepare` files from parent directories are concatenated into the test script. Use them for shared bash helpers.
@@ -183,7 +179,7 @@ Available on `PATH` during test execution (from `acceptance/bin/`):
183179
- `update_file.py FILENAME OLD NEW`: replace all occurrences of OLD with NEW in FILENAME. Errors if OLD is not found. Cannot be used on `output.txt`.
184180
- `find.py REGEX [--expect N]`: find files matching regex in current directory. `--expect N` asserts an exact count.
185181
- `diff.py DIR1 DIR2` or `diff.py FILE1 FILE2`: recursive diff with test replacements applied.
186-
- `print_state.py [-t TARGET] [--backup]`: print deployment state (terraform or direct).
182+
- `print_state.py [-t TARGET] [--backup]`: print deployment state (`resources.json`, or a terraform state left by an older CLI).
187183
- `edit_resource.py TYPE ID < script.py`: fetch resource by ID, execute Python on it (resource in `r`), then update it. TYPE is `jobs` or `pipelines`.
188184
- `gron.py`: flatten JSON into greppable discrete assignments (simpler than `jq` for searching JSON).
189185
- `jq` is also available for JSON processing.

‎acceptance/acceptance_test.go‎

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func TestInprocessMode(t *testing.T) {
186186
// selftest/server too, which meant a second setup after StartDefaultServer had
187187
// pointed HOME at an empty temp dir, so building yamlfmt there re-downloaded the
188188
// entire module cache: 44s on Linux CI, 140s on Windows. Tool builds are skipped
189-
// for the same reason - selftest/basic uses neither terraform, the wheel, nor yamlfmt.
189+
// for the same reason - selftest/basic uses neither the wheel nor yamlfmt.
190190
require.Equal(t, 1, testAccept(t, true, []string{"selftest/basic"}, true))
191191
}
192192

@@ -204,29 +204,8 @@ func setReplsForTestEnvVars(t *testing.T, repls *testdiff.ReplacementsContext) {
204204
}
205205
}
206206

207-
// helperScriptUsesEngineCache caches whether a _script helper in a given directory
208-
// (or any of its ancestors) references $DATABRICKS_BUNDLE_ENGINE.
209-
// Since _script helpers are shared across many tests, caching avoids redundant reads.
210-
var helperScriptUsesEngineCache sync.Map
211-
212-
// anyHelperScriptUsesEngine returns true if any _script helper in dir or its ancestors
213-
// contains $DATABRICKS_BUNDLE_ENGINE.
214-
func anyHelperScriptUsesEngine(dir string) bool {
215-
if dir == "" || dir == "." {
216-
return false
217-
}
218-
if v, ok := helperScriptUsesEngineCache.Load(dir); ok {
219-
return v.(bool)
220-
}
221-
content, err := os.ReadFile(filepath.Join(dir, "_script"))
222-
result := (err == nil && strings.Contains(string(content), "$DATABRICKS_BUNDLE_ENGINE")) ||
223-
anyHelperScriptUsesEngine(filepath.Dir(dir))
224-
helperScriptUsesEngineCache.Store(dir, result)
225-
return result
226-
}
227-
228207
// hasRunFilter returns true if the -run flag contains '=', indicating a specific
229-
// EnvMatrix variant was requested (e.g. DATABRICKS_BUNDLE_ENGINE=direct).
208+
// EnvMatrix variant was requested (e.g. DMS=true).
230209
func hasRunFilter() bool {
231210
f := flag.Lookup("test.run")
232211
return f != nil && strings.Contains(f.Value.String(), "=")
@@ -263,7 +242,7 @@ func requirePrerequisites(t *testing.T) bool {
263242

264243
// selectedTests, when non-empty, limits the run to those test directories.
265244
// skipToolBuilds skips building the tools that the selected tests do not use
266-
// (terraform, the databricks-bundles wheel, yamlfmt); it must stay false for a
245+
// (the databricks-bundles wheel, yamlfmt); it must stay false for a
267246
// full run.
268247
func testAccept(t *testing.T, inprocessMode bool, selectedTests []string, skipToolBuilds bool) int {
269248
if testdiff.OverwriteMode && !hasRunFilter() {
@@ -629,10 +608,7 @@ func testAccept(t *testing.T, inprocessMode bool, selectedTests []string, skipTo
629608

630609
expanded := internal.ExpandEnvMatrix(config.EnvMatrix, config.EnvMatrixExclude, extraVars)
631610
if Subset {
632-
scriptContent, _ := os.ReadFile(filepath.Join(dir, EntryPointScript))
633-
scriptUsesEngine := strings.Contains(string(scriptContent), "$DATABRICKS_BUNDLE_ENGINE") ||
634-
anyHelperScriptUsesEngine(dir)
635-
expanded = internal.SubsetExpanded(expanded, dir, scriptUsesEngine)
611+
expanded = internal.SubsetExpanded(expanded, dir)
636612
}
637613

638614
// If the matrix expands to a single empty envset, run the test directly
@@ -1048,10 +1024,6 @@ func runTest(t *testing.T,
10481024
// (kill_after.py, callserver.py, …) would route their requests through
10491025
// the blocking proxy. NO_PROXY exempts them.
10501026
cmd.Env = append(cmd.Env, "NO_PROXY=127.0.0.1,localhost")
1051-
// Terraform phones home to checkpoint-api.hashicorp.com on every run to
1052-
// check for updates. Disable it so these CONNECT requests don't reach the
1053-
// blocking proxy and fail every terraform-engine test.
1054-
cmd.Env = append(cmd.Env, "CHECKPOINT_DISABLE=1")
10551027
}
10561028
// Run from outputDir so the entry-point script isn't a bundle source; the script
10571029
// cd's into tmpDir (the bundle dir) as its first line.
@@ -1997,8 +1969,8 @@ func loadScriptReplacements(t *testing.T, repls *testdiff.ReplacementsContext, r
19971969

19981970
type pathFilter struct {
19991971
// contains substrings from the variants other than current.
2000-
// E.g. if EnvVaryOutput is DATABRICKS_BUNDLE_ENGINE and current test running DATABRICKS_BUNDLE_ENGINE="terraform" then
2001-
// notSelected contains ".direct." meaning if filename contains that (e.g. out.deploy.direct.txt) then we ignore it here.
1972+
// E.g. if EnvVaryOutput is MODE = ["a", "b"] and current test running MODE="a" then
1973+
// notSelected contains ".b." meaning if filename contains that (e.g. out.deploy.b.txt) then we ignore it here.
20021974
notSelected []string
20031975
}
20041976

‎acceptance/bin/print_state.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,9 @@ def main():
220220
for filename in get_state_files(args.target, args.backup):
221221
if not os.path.exists(filename):
222222
continue
223-
# Recording only applies to the direct engine, so a terraform run prints the file as-is.
223+
# Recording only applies to direct-engine state, so a terraform state file prints as-is.
224224
recording = os.environ.get("DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY") == "true"
225-
terraform = os.environ.get("DATABRICKS_BUNDLE_ENGINE") == "terraform"
226-
if recording and not terraform and not args.no_dms:
225+
if recording and filename.endswith("resources.json") and not args.no_dms:
227226
print_recorded_state(filename, args.target)
228227
else:
229228
print_file(filename)

‎acceptance/bin/read_state.py‎

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
"""
3-
Print selected attributes from terraform state.
3+
Print selected attributes from the bundle state.
44
55
Usage: <group> <name> [attr...]
66
"""
@@ -13,34 +13,6 @@
1313
from print_state import get_resources
1414

1515

16-
def print_resource_terraform(group, name, *attrs):
17-
resource_type = "databricks_" + group[:-1]
18-
filename = ".databricks/bundle/default/terraform/terraform.tfstate"
19-
# A missing state file (e.g. after destroy removes it) means the resource's
20-
# state is not there, same as a missing entry within the file.
21-
if not os.path.exists(filename):
22-
print(f"State not found for {group}.{name} in {filename}")
23-
return
24-
raw = open(filename).read()
25-
data = json.loads(raw)
26-
found = 0
27-
for r in data["resources"]:
28-
r_type = r["type"]
29-
r_name = r["name"]
30-
if r_type != resource_type:
31-
continue
32-
if r_name != name:
33-
continue
34-
for inst in r["instances"]:
35-
attribute_values = inst.get("attributes")
36-
if attribute_values:
37-
values = [f"{x}={attribute_values.get(x)!r}" for x in attrs]
38-
print(group, name, " ".join(values))
39-
found += 1
40-
if not found:
41-
print(f"State not found for {group}.{name} in {filename}")
42-
43-
4416
def print_resource_direct(group, name, *attrs):
4517
filename = ".databricks/bundle/default/resources.json"
4618
# A missing state file (e.g. after destroy removes it) means the resource's
@@ -79,7 +51,5 @@ def print_resource_recorded(group, name, *attrs):
7951

8052
if os.environ.get("DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY") == "true":
8153
print_resource_recorded(*sys.argv[1:])
82-
elif os.environ.get("DATABRICKS_BUNDLE_ENGINE") == "terraform":
83-
print_resource_terraform(*sys.argv[1:])
8454
else:
8555
print_resource_direct(*sys.argv[1:])

‎acceptance/bundle/deployment/bind/job/stale-state/script‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
if [ "$DATABRICKS_BUNDLE_ENGINE" = "direct" ]; then
2-
state_file=".databricks/bundle/default/resources.json"
3-
else
4-
state_file=".databricks/bundle/default/terraform/terraform.tfstate"
5-
fi
1+
state_file=".databricks/bundle/default/resources.json"
62

73
title "Step 1: Deploy with job_1 only"
84
trace $CLI bundle deploy

‎acceptance/bundle/deployment/bind/job/stale-state/test.toml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ Ignore = [
44
"databricks_v2.yml",
55
"stale_state.json",
66
]
7-
8-
Env.DATABRICKS_BUNDLE_ENGINE = "direct"

‎acceptance/bundle/empty_string_dropped/databricks.yml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ resources:
2525
kms_key: ''
2626
region: ''
2727
cluster_name: ''
28+
driver_instance_pool_id: ''
29+
driver_node_type_id: ''
30+
instance_pool_id: ''
2831
node_type_id: ''
2932
num_workers: 1
3033
policy_id: ''
@@ -45,7 +48,9 @@ resources:
4548
description: ''
4649
git_source:
4750
git_branch: main
51+
git_commit: ''
4852
git_provider: gitHub
53+
git_tag: ''
4954
git_url: https://example.com/repo
5055
job_clusters:
5156
- job_cluster_key: main
@@ -63,11 +68,15 @@ resources:
6368
kms_key: ''
6469
region: ''
6570
cluster_name: ''
71+
driver_instance_pool_id: ''
72+
driver_node_type_id: ''
73+
instance_pool_id: ''
6674
node_type_id: ''
6775
num_workers: 1
6876
policy_id: ''
6977
single_user_name: ''
7078
spark_version: 13.3.x-scala2.12
79+
serverless_compute_id: ''
7180
max_concurrent_runs: 1
7281
name: ''
7382
parent_path: ''
@@ -79,6 +88,8 @@ resources:
7988
pipelines:
8089
my_pipeline:
8190
budget_policy_id: ''
91+
catalog: ''
92+
channel: ''
8293
clusters:
8394
- aws_attributes:
8495
availability: SPOT
@@ -90,14 +101,18 @@ resources:
90101
label: default
91102
node_type_id: ''
92103
policy_id: ''
104+
edition: ''
93105
libraries:
94106
- file:
95107
path: pipeline.py
96108
jar: ''
97109
whl: ''
98110
name: ''
99111
root_path: ''
112+
schema: ''
100113
serverless_compute_id: ''
114+
storage: ''
115+
target: ''
101116
usage_policy_id: ''
102117
registered_models:
103118
my_registered_model:
@@ -121,6 +136,7 @@ resources:
121136
my_warehouse:
122137
auto_stop_mins: 10
123138
cluster_size: 2X-Small
139+
creator_name: ''
124140
instance_profile_arn: ''
125141
max_num_clusters: 1
126142
min_num_clusters: 1

‎acceptance/bundle/empty_string_dropped/gen_empty_config.py‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
settable string LEAF (including nested ones) that the base doesn't already set
88
to "". Coverage is therefore scoped to the blocks present in base.yml, which is
99
how we avoid mutually-exclusive blocks (aws vs gcp attributes, git_source vs
10-
none) that would make terraform abort.
10+
none).
1111
1212
A field is settable/eligible when out.fields.txt types it as `string` (this
1313
skips enums, which are named types) with flag ALL or INPUT, and it is not
14-
output_only (<resource_type>.generated.yml), a bundle-framework field, or a
15-
known terraform-erroring field.
14+
output_only (<resource_type>.generated.yml) or a bundle-framework field.
1615
1716
Run from the repo root; writes databricks.yml in the test directory:
1817
acceptance/bundle/empty_string_dropped/gen_empty_config.py
@@ -32,23 +31,6 @@
3231
# Bundle-framework fields present on every resource; not real API inputs.
3332
FRAMEWORK_FIELDS = {"id", "url", "modified_status"}
3433

35-
# Leaf field names that make terraform error at plan time (ConflictsWith, enum
36-
# validation on string-typed fields, computed attributes), so no request is
37-
# recorded. Applied per resource type. Matched by leaf name at any depth.
38-
TERRAFORM_ERRORS = {
39-
"clusters": {"instance_pool_id", "driver_instance_pool_id", "driver_node_type_id"},
40-
"jobs": {
41-
"instance_pool_id",
42-
"driver_instance_pool_id",
43-
"driver_node_type_id",
44-
# git_source: branch/commit/tag are mutually exclusive; base sets branch.
45-
"git_commit",
46-
"git_tag",
47-
},
48-
"pipelines": {"channel", "edition", "catalog", "storage", "schema", "target"},
49-
"sql_warehouses": {"creator_name"},
50-
}
51-
5234

5335
def string_leaf_parents():
5436
"""Map resource type -> {parent_schema_path: {leaf field names}}.
@@ -115,7 +97,7 @@ def main():
11597
base = yaml.safe_load(BASE.read_text())
11698

11799
for rtype, entries in sorted(base.get("resources", {}).items()):
118-
excluded = output_only.get(rtype, set()) | FRAMEWORK_FIELDS | TERRAFORM_ERRORS.get(rtype, set())
100+
excluded = output_only.get(rtype, set()) | FRAMEWORK_FIELDS
119101
for cfg in entries.values():
120102
fill(cfg, "", parents.get(rtype, {}), excluded)
121103

acceptance/bundle/empty_string_dropped/out.requests.direct.json renamed to acceptance/bundle/empty_string_dropped/out.requests.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"method": "POST",
3636
"path": "/api/2.0/pipelines",
3737
"body": {
38-
"channel": "CURRENT",
3938
"clusters": [
4039
{
4140
"aws_attributes": {
@@ -48,7 +47,6 @@
4847
"kind": "BUNDLE",
4948
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/direct/state/metadata.json"
5049
},
51-
"edition": "ADVANCED",
5250
"libraries": [
5351
{
5452
"file": {

‎acceptance/bundle/empty_string_dropped/out.validate.json‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
},
7676
"pipelines": {
7777
"my_pipeline": {
78-
"channel": "CURRENT",
7978
"clusters": [
8079
{
8180
"aws_attributes": {
@@ -88,7 +87,6 @@
8887
"kind": "BUNDLE",
8988
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/direct/state/metadata.json"
9089
},
91-
"edition": "ADVANCED",
9290
"libraries": [
9391
{
9492
"file": {

0 commit comments

Comments
 (0)