Skip to content

Commit 4423656

Browse files
acceptance: prepare plan and template comparisons for UUID numbering (#7423)
## Changes Capture the immutable no-artifacts test's initial plan in a separate golden, preserving its assertions. Teach the Python replacement helper to honor `Distinct` so template comparisons can match numbered goldens. ## Why Saved-plan deployment reuses the planned snapshot UUID; direct deployment generates another. Separate plan output lets both variants share expectations. Template comparisons also need the same numbering behavior as the Go harness before #7021 removes the UUID opt-out. Stacked on #7020. UUID numbering remains off by default in this PR. ## Tests Both immutable variants, template tests, and helper selftests passed with numbering off. Python doctests cover repeated values, multiple distinct values, and already-normalized output. Formatting, checks, lint, and the full test suite passed with numbering always enabled on the completed stack; #7021 records the transient retry. _This PR was written by Codex._
1 parent 10d6a13 commit 4423656

4 files changed

Lines changed: 84 additions & 58 deletions

File tree

‎acceptance/bin/repls.py‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def read_entries():
2929

3030

3131
def read_repls():
32-
"""Return (pattern, replacement) pairs in the order they must be applied."""
32+
"""Return (pattern, replacement, distinct) tuples in application order."""
3333
entries = []
3434

3535
for item in read_entries():
@@ -38,35 +38,57 @@ def read_repls():
3838
literal = item.get("Literal")
3939

4040
if literal is None:
41-
# "Distinct" is not honoured here; unlike the harness, we do not number the matches.
42-
entries.append((order, item["Old"], new))
41+
entries.append((order, item["Old"], new, item["Distinct"]))
4342
continue
4443

4544
# Set() in libs/testdiff also registers the JSON-encoded form of the value, so that
4645
# values with quotes or backslashes are replaced inside JSON output as well.
4746
encoded = json.dumps(literal, ensure_ascii=False)[1:-1]
4847
if encoded != literal:
49-
entries.append((order, re.escape(encoded), new))
50-
entries.append((order, re.escape(literal), new))
48+
entries.append((order, re.escape(encoded), new, False))
49+
entries.append((order, re.escape(literal), new, False))
5150

5251
# Stable sort: replacements with the same order are applied in the order they were added.
5352
entries.sort(key=lambda entry: entry[0])
5453

55-
return [(old, new) for _, old, new in entries]
54+
return [(old, new, distinct) for _, old, new, distinct in entries]
5655

5756

5857
def compile_repls():
5958
"""Same as read_repls(), with patterns compiled. Invalid patterns are reported and skipped."""
6059
result = []
61-
for old, new in read_repls():
60+
for old, new, distinct in read_repls():
6261
try:
63-
result.append((re.compile(old), new))
62+
result.append((re.compile(old), new, distinct))
6463
except re.error as e:
6564
print(f"Regex error for pattern {old}: {e}", file=sys.stderr)
6665
return result
6766

6867

6968
def replace_all(patterns, s):
70-
for comp, new in patterns:
69+
r"""Apply replacements with the same per-output numbering as the Go harness.
70+
71+
>>> distinct = [(re.compile(r"item-\w+"), "[ITEM]", True)]
72+
>>> replace_all(distinct, "item-b item-a item-b")
73+
'[ITEM][0] [ITEM][1] [ITEM][0]'
74+
>>> replace_all(distinct, "item-a item-a")
75+
'[ITEM] [ITEM]'
76+
>>> replace_all(distinct, "no matches")
77+
'no matches'
78+
>>> replace_all(distinct, "[ITEM][0] [ITEM][1] [ITEM][0]")
79+
'[ITEM][0] [ITEM][1] [ITEM][0]'
80+
>>> replace_all([(re.compile(r"item-\w+"), "[ITEM]", False)], "item-a item-b")
81+
'[ITEM] [ITEM]'
82+
"""
83+
for comp, new, distinct in patterns:
84+
if distinct:
85+
seen = {}
86+
for match in comp.finditer(s):
87+
value = match.group(0)
88+
if value not in seen:
89+
seen[value] = len(seen)
90+
if len(seen) > 1:
91+
s = comp.sub(lambda match, new=new, seen=seen: match.expand(new) + f"[{seen[match.group(0)]}]", s)
92+
continue
7193
s = comp.sub(new, s)
7294
return s
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
>>> [CLI] bundle plan -o json
3+
4+
>>> jq .plan["resources.jobs.my_job"].new_state.value.tasks plan.json
5+
[
6+
{
7+
"notebook_task": {
8+
"base_parameters": {
9+
"path": "/Workspace/Users/[UUID]/.snapshots/[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]/snapshot/files/some_path"
10+
},
11+
"notebook_path": "/Workspace/Users/[UUID]/.snapshots/[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]/snapshot/files/src/notebook"
12+
},
13+
"task_key": "notebook_task"
14+
},
15+
{
16+
"environment_key": "env",
17+
"spark_python_task": {
18+
"python_file": "/Workspace/Users/[UUID]/.snapshots/[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]/snapshot/files/src/main.py"
19+
},
20+
"task_key": "spark_python_task"
21+
}
22+
]
23+
24+
>>> jq .plan["resources.internal_immutable_snapshots.immutable"] plan.json
25+
{
26+
"action": "create",
27+
"new_state": {
28+
"value": {
29+
"relative_path": "[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]",
30+
"full_path": "/Workspace/Users/[UUID]/.snapshots/[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]/snapshot",
31+
"bundle_id": "[SNAPSHOT_HASH]",
32+
"acl": [
33+
{
34+
"user_name": "[USERNAME]",
35+
"permission_level": "CAN_READ"
36+
}
37+
],
38+
"can_manage": [
39+
{
40+
"service_principal_name": "[USERNAME]"
41+
}
42+
],
43+
"zip_path": "[TEST_TMP_DIR]/.databricks/bundle/default/snapshots/[SNAPSHOT_HASH]-[UUID].zip"
44+
}
45+
}
46+
}

‎acceptance/bundle/deploy/immutable/no-artifacts/output.txt‎

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,6 @@ Workspace:
88

99
Validation OK!
1010

11-
>>> [CLI] bundle plan -o json
12-
13-
>>> jq .plan["resources.jobs.my_job"].new_state.value.tasks plan.json
14-
[
15-
{
16-
"notebook_task": {
17-
"base_parameters": {
18-
"path": "/Workspace/Users/[UUID]/.snapshots/[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]/snapshot/files/some_path"
19-
},
20-
"notebook_path": "/Workspace/Users/[UUID]/.snapshots/[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]/snapshot/files/src/notebook"
21-
},
22-
"task_key": "notebook_task"
23-
},
24-
{
25-
"environment_key": "env",
26-
"spark_python_task": {
27-
"python_file": "/Workspace/Users/[UUID]/.snapshots/[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]/snapshot/files/src/main.py"
28-
},
29-
"task_key": "spark_python_task"
30-
}
31-
]
32-
33-
>>> jq .plan["resources.internal_immutable_snapshots.immutable"] plan.json
34-
{
35-
"action": "create",
36-
"new_state": {
37-
"value": {
38-
"relative_path": "[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]",
39-
"full_path": "/Workspace/Users/[UUID]/.snapshots/[SNAPSHOT_HASH]/[SNAPSHOT_HASH]-[UUID]/snapshot",
40-
"bundle_id": "[SNAPSHOT_HASH]",
41-
"acl": [
42-
{
43-
"user_name": "[USERNAME]",
44-
"permission_level": "CAN_READ"
45-
}
46-
],
47-
"can_manage": [
48-
{
49-
"service_principal_name": "[USERNAME]"
50-
}
51-
],
52-
"zip_path": "[TEST_TMP_DIR]/.databricks/bundle/default/snapshots/[SNAPSHOT_HASH]-[UUID].zip"
53-
}
54-
}
55-
}
56-
5711
>>> [CLI] bundle deploy
5812
Created internal_immutable_snapshots.immutable
5913
Created jobs.my_job

‎acceptance/bundle/deploy/immutable/no-artifacts/script‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
envsubst < databricks.yml.tmpl > databricks.yml
22

33
trace $CLI bundle validate
4-
trace $CLI bundle plan -o json > plan.json
5-
trace jq '.plan["resources.jobs.my_job"].new_state.value.tasks' plan.json
6-
trace jq '.plan["resources.internal_immutable_snapshots.immutable"]' plan.json
4+
# A direct deploy generates a new snapshot UUID, while --plan reuses the planned
5+
# one. Keep the initial plan in its own golden so both variants agree per file.
6+
{
7+
trace $CLI bundle plan -o json > plan.json
8+
trace jq '.plan["resources.jobs.my_job"].new_state.value.tasks' plan.json
9+
trace jq '.plan["resources.internal_immutable_snapshots.immutable"]' plan.json
10+
} > out.plan.txt 2>&1
711

812
trace $CLI bundle deploy $(readplanarg plan.json)
913

0 commit comments

Comments
 (0)