Skip to content

Commit a647df5

Browse files
Use enforced file-backed history for the YAML opt-in
1 parent 1723931 commit a647df5

39 files changed

Lines changed: 894 additions & 247 deletions

File tree

‎acceptance/bin/print_state.py‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import posixpath
1515
import subprocess
16+
from pathlib import Path
1617

1718
from nostamp import scrub
1819

@@ -123,9 +124,23 @@ def get_deployment_id(target):
123124
def get_resources(target):
124125
"""Map every recorded resource key ("jobs.foo") to its {"id", "state"}.
125126
126-
Empty when the bundle has no deployment recorded yet. Cached because a lookup costs three
127-
round trips and a script asks for one resource at a time.
127+
File-history state is read locally. Legacy DMS state is read from the service,
128+
or is empty when no deployment has been recorded. Cached for repeated resource lookups.
128129
"""
130+
filename = get_state_file(target, False)
131+
if filename.endswith("resources.json") and os.path.exists(filename):
132+
data = json.loads(Path(filename).read_text())
133+
if "deployment_history_best_effort" in (data.get("features") or {}):
134+
# DMS can miss history updates. The file remains authoritative in this mode.
135+
return {
136+
key.removeprefix("resources."): {
137+
"id": entry.get("__id__"),
138+
"state": entry.get("state") or {},
139+
"depends_on": entry.get("depends_on") or [],
140+
}
141+
for key, entry in data.get("state", {}).items()
142+
}
143+
129144
deployment_id = get_deployment_id(target)
130145
if not deployment_id:
131146
return {}
@@ -174,10 +189,9 @@ def get_last_version_id(target):
174189

175190

176191
def print_recorded_state(filename, target):
177-
"""Print the state file with its resources filled in from the deployment metadata service.
192+
"""Normalize history state for comparisons with ordinary file-backed deployments.
178193
179-
While recording, the file itself carries only the header - the service holds the resources - so
180-
printing it raw would show an empty state and differ from the same test's non-recording run.
194+
get_resources uses the file for best-effort history and the service for legacy DMS state.
181195
"""
182196
data = json.loads(open(filename).read())
183197
# Recording stamps each resource payload with the deployment and version; drop it here so the
@@ -186,11 +200,18 @@ def print_recorded_state(filename, target):
186200

187201
# The file's serial is a copy of the DMS version to ensure outdated resource state is not read.
188202
# Rebuild in header order with the authoritative serial from the deployment.
189-
last_version_id = get_last_version_id(target)
190-
serial = int(last_version_id) if last_version_id else 0
203+
if "deployment_history_best_effort" in (data.get("features") or {}):
204+
serial = data.get("serial", 0)
205+
else:
206+
last_version_id = get_last_version_id(target)
207+
serial = int(last_version_id) if last_version_id else 0
191208

192209
# Recording itself is not what these tests assert, so drop the feature that marks it.
193-
features = {k: v for k, v in (data.get("features") or {}).items() if k != "deployment_history"}
210+
features = {
211+
k: v
212+
for k, v in (data.get("features") or {}).items()
213+
if k not in {"deployment_history", "deployment_history_best_effort"}
214+
}
194215

195216
rebuilt = {}
196217
for key in ("state_version", "cli_version", "lineage"):
@@ -213,7 +234,7 @@ def main():
213234
"--no-dms",
214235
action="store_true",
215236
help="Print resources.json as-is without fetching state from DMS. "
216-
"Use in bundle/dms tests to assert the tombstone content of the file.",
237+
"Use in bundle/dms tests to assert the file state and its feature markers.",
217238
)
218239
args = parser.parse_args()
219240

‎acceptance/bundle/dms/bind-unbind-unsupported/databricks.yml.tmpl‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
bundle:
22
name: dms-bind-unbind-$UNIQUE_NAME
3-
experimental:
4-
deployment_history: true
5-
63
resources:
74
jobs:
85
foo:

‎acceptance/bundle/dms/declined-deploy/output.txt‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
6767
"lineage": "[UUID]",
6868
"serial": 1,
6969
"features": {
70-
"deployment_history": {}
70+
"deployment_history_best_effort": {}
7171
}
7272
}
7373

@@ -79,18 +79,10 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
7979
"method": "GET",
8080
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]"
8181
}
82-
{
83-
"method": "GET",
84-
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/resources"
85-
}
8682
{
8783
"method": "GET",
8884
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]"
8985
}
90-
{
91-
"method": "GET",
92-
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/resources"
93-
}
9486

9587
>>> print_state.py --no-dms
9688
{
@@ -99,9 +91,17 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
9991
"lineage": "[UUID]",
10092
"serial": 1,
10193
"features": {
102-
"deployment_history": {}
94+
"deployment_history_best_effort": {}
10395
},
104-
"state": {}
96+
"state": {
97+
"resources.schemas.foo": {
98+
"__id__": "main.dms_declined_deploy_schema_[UNIQUE_NAME]",
99+
"state": {
100+
"catalog_name": "main",
101+
"name": "dms_declined_deploy_schema_[UNIQUE_NAME]"
102+
}
103+
}
104+
}
105105
}
106106

107107
=== A destructive change without --auto-approve is declined: this console cannot prompt
@@ -124,10 +124,6 @@ Files: 2 uploaded, 0 deleted
124124
"method": "GET",
125125
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]"
126126
}
127-
{
128-
"method": "GET",
129-
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/resources"
130-
}
131127

132128
=== The recorded resources are unchanged by the decline: the schema is still at version 1
133129
>>> MSYS_NO_PATHCONV=1 [CLI] bundle-deployments list-resources deployments/[DEPLOYMENT_ID] -o json
@@ -163,10 +159,6 @@ false
163159
"method": "GET",
164160
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]"
165161
}
166-
{
167-
"method": "GET",
168-
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/resources"
169-
}
170162
{
171163
"method": "POST",
172164
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions",

‎acceptance/bundle/dms/depends-on/output.txt‎

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
>>> [CLI] bundle plan -o json
44
{
55
"plan_version": [PLAN_VERSION],
6-
"cli_version": "[CLI_VERSION]",
7-
"features": {
8-
"deployment_history": {}
9-
}
6+
"cli_version": "[CLI_VERSION]"
107
}
118

129
>>> [CLI] bundle plan
@@ -61,7 +58,7 @@ Resources: 2 created, 0 changed, 0 deleted, 0 unchanged
6158
"lineage": "[UUID]",
6259
"serial": 1,
6360
"features": {
64-
"deployment_history": {}
61+
"deployment_history_best_effort": {}
6562
}
6663
}
6764

@@ -91,9 +88,53 @@ Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged
9188
"lineage": "[UUID]",
9289
"serial": 1,
9390
"features": {
94-
"deployment_history": {}
91+
"deployment_history_best_effort": {}
9592
},
96-
"state": {}
93+
"state": {
94+
"resources.jobs.child": {
95+
"__id__": "[CHILD_ID]",
96+
"state": {
97+
"deployment": {
98+
"deployment_id": "[DEPLOYMENT_ID]",
99+
"kind": "BUNDLE",
100+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/dms-depends-on-[UNIQUE_NAME]/default/state/metadata.json",
101+
"version_id": "1"
102+
},
103+
"description": "depends on [PARENT_ID]",
104+
"edit_mode": "UI_LOCKED",
105+
"format": "MULTI_TASK",
106+
"max_concurrent_runs": 1,
107+
"name": "child",
108+
"queue": {
109+
"enabled": true
110+
}
111+
},
112+
"depends_on": [
113+
{
114+
"node": "resources.jobs.parent",
115+
"label": "${resources.jobs.parent.id}"
116+
}
117+
]
118+
},
119+
"resources.jobs.parent": {
120+
"__id__": "[PARENT_ID]",
121+
"state": {
122+
"deployment": {
123+
"deployment_id": "[DEPLOYMENT_ID]",
124+
"kind": "BUNDLE",
125+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/dms-depends-on-[UNIQUE_NAME]/default/state/metadata.json",
126+
"version_id": "1"
127+
},
128+
"edit_mode": "UI_LOCKED",
129+
"format": "MULTI_TASK",
130+
"max_concurrent_runs": 1,
131+
"name": "parent",
132+
"queue": {
133+
"enabled": true
134+
}
135+
}
136+
}
137+
}
97138
}
98139

99140
>>> [CLI] bundle destroy --auto-approve

‎acceptance/bundle/dms/deployment-metadata-change/output.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
6767
"lineage": "[UUID]",
6868
"serial": 1,
6969
"features": {
70-
"deployment_history": {}
70+
"deployment_history_best_effort": {}
7171
}
7272
}
7373

@@ -128,7 +128,7 @@ A common practice is to use a username or principal name in this path, i.e. use
128128
"lineage": "[UUID]",
129129
"serial": 1,
130130
"features": {
131-
"deployment_history": {}
131+
"deployment_history_best_effort": {}
132132
}
133133
}
134134

‎acceptance/bundle/dms/empty-grants/output.txt‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
138138
"lineage": "[UUID]",
139139
"serial": 2,
140140
"features": {
141-
"deployment_history": {}
141+
"deployment_history_best_effort": {}
142142
}
143143
}
144144

@@ -163,9 +163,17 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
163163
"lineage": "[UUID]",
164164
"serial": 2,
165165
"features": {
166-
"deployment_history": {}
166+
"deployment_history_best_effort": {}
167167
},
168-
"state": {}
168+
"state": {
169+
"resources.schemas.foo": {
170+
"__id__": "main.dms_empty_grants_[UNIQUE_NAME]",
171+
"state": {
172+
"catalog_name": "main",
173+
"name": "dms_empty_grants_[UNIQUE_NAME]"
174+
}
175+
}
176+
}
169177
}
170178

171179
>>> [CLI] bundle destroy --auto-approve

‎acceptance/bundle/dms/failed-delete/output.txt‎

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged
6767
"lineage": "[UUID]",
6868
"serial": 1,
6969
"features": {
70-
"deployment_history": {}
70+
"deployment_history_best_effort": {}
7171
}
7272
}
7373

@@ -92,9 +92,28 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged
9292
"lineage": "[UUID]",
9393
"serial": 1,
9494
"features": {
95-
"deployment_history": {}
95+
"deployment_history_best_effort": {}
9696
},
97-
"state": {}
97+
"state": {
98+
"resources.jobs.stuck": {
99+
"__id__": "[STUCK_ID]",
100+
"state": {
101+
"deployment": {
102+
"deployment_id": "[DEPLOYMENT_ID]",
103+
"kind": "BUNDLE",
104+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/dms-failed-delete-[UNIQUE_NAME]/default/state/metadata.json",
105+
"version_id": "1"
106+
},
107+
"edit_mode": "UI_LOCKED",
108+
"format": "MULTI_TASK",
109+
"max_concurrent_runs": 1,
110+
"name": "stuck",
111+
"queue": {
112+
"enabled": true
113+
}
114+
}
115+
}
116+
}
98117
}
99118

100119
=== A resource that fails to delete is recorded as a failed operation carrying the error, so the history says why rather than showing the resource gone
@@ -176,22 +195,41 @@ API message: Fault injected by test.
176195
}
177196
]
178197

179-
=== The local state file records failed version 2
198+
=== The local state file keeps the resource and its serial after the failed delete
180199
>>> print_state.py --no-dms
181200
{
182201
"state_version": 3,
183202
"cli_version": "[CLI_VERSION]",
184203
"lineage": "[UUID]",
185-
"serial": 2,
204+
"serial": 1,
186205
"features": {
187-
"deployment_history": {}
206+
"deployment_history_best_effort": {}
188207
},
189-
"state": {}
208+
"state": {
209+
"resources.jobs.stuck": {
210+
"__id__": "[STUCK_ID]",
211+
"state": {
212+
"deployment": {
213+
"deployment_id": "[DEPLOYMENT_ID]",
214+
"kind": "BUNDLE",
215+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/dms-failed-delete-[UNIQUE_NAME]/default/state/metadata.json",
216+
"version_id": "1"
217+
},
218+
"edit_mode": "UI_LOCKED",
219+
"format": "MULTI_TASK",
220+
"max_concurrent_runs": 1,
221+
"name": "stuck",
222+
"queue": {
223+
"enabled": true
224+
}
225+
}
226+
}
227+
}
190228
}
191229

192230
=== The remote checkpoint stays at serial 1 while DMS advances to version 2
193231
>>> MSYS_NO_PATHCONV=1 [CLI] workspace export /Workspace/Users/[USERNAME]/.bundle/dms-failed-delete-[UNIQUE_NAME]/default/state/resources.json --format RAW
194232
{"serial":1}
195233

196-
>>> print_state.py
197-
{"serial":2}
234+
>>> MSYS_NO_PATHCONV=1 [CLI] bundle-deployments get-deployment deployments/[DEPLOYMENT_ID] -o json
235+
{"last_version_id":"2"}

‎acceptance/bundle/dms/failed-delete/script‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ trace MSYS_NO_PATHCONV=1 $CLI bundle-deployments list-resources "deployments/${d
2929
title "The failed operation records the error message"
3030
trace MSYS_NO_PATHCONV=1 $CLI bundle-deployments list-operations "deployments/${deployment_id}/versions/2" -o json | jq -S 'map({resource_key, action_type, status, error_message})'
3131

32-
title "The local state file records failed version 2"
32+
title "The local state file keeps the resource and its serial after the failed delete"
3333
trace print_state.py --no-dms
3434

3535
title "The remote checkpoint stays at serial 1 while DMS advances to version 2"
3636
trace MSYS_NO_PATHCONV=1 $CLI workspace export "/Workspace/Users/${CURRENT_USER_NAME}/.bundle/dms-failed-delete-${UNIQUE_NAME}/default/state/resources.json" --format RAW | jq -c '{serial}'
37-
trace print_state.py | jq -c '{serial}'
37+
trace MSYS_NO_PATHCONV=1 $CLI bundle-deployments get-deployment "deployments/${deployment_id}" -o json | jq -c '{last_version_id}'
3838

3939
# Drain any accumulated requests (plan, state reads) so the harness has nothing to diff.
4040
rm -f "$OUT_REQUESTS"

0 commit comments

Comments
 (0)