Skip to content

Commit c45ca0c

Browse files
committed
Add local-env acceptance tests
Seventh in the stacked series. End-to-end acceptance coverage for "databricks local-env python sync" against the in-process fake server, which is where the command's user-visible behavior (text + --json output, every error path) is exercised — cmd/localenv itself carries no unit tests by design. Nine scenarios: help (three-level tree), no-target, flag-conflict, manager-unsupported (conda project), env-unsupported (404 -> E_ENV_UNSUPPORTED), json-error, serverless-check (dry-run plan), serverless-json (--json plan), and constraints-only. Scripts drive the hidden command by name; goldens were generated with -update and verified stable on a clean re-run. The --json "command" field and the managed pyproject marker both render as "local-env python sync". No source changes. Co-authored-by: Isaac
1 parent ae5563c commit c45ca0c

37 files changed

Lines changed: 372 additions & 0 deletions

acceptance/localenv/constraints-only/out.test.toml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
>>> [CLI] local-env python sync --serverless v4 --constraints-only --check --output json
3+
{
4+
"schemaVersion": 1,
5+
"command": "local-env python sync",
6+
"ok": true,
7+
"mode": "constraints-only",
8+
"dryRun": true,
9+
"target": {
10+
"source": "serverless",
11+
"serverlessVersion": "v4",
12+
"envKey": "serverless/serverless-v4"
13+
},
14+
"resolved": {
15+
"pythonVersion": "3.12",
16+
"artifactSource": "network"
17+
},
18+
"greenfield": true,
19+
"plan": {
20+
"wouldWrite": "[TEST_TMP_DIR]/pyproject.toml",
21+
"wouldInstallPython": "3.12",
22+
"diff": "--- pyproject.toml\n+++ pyproject.toml\n@@ -1 +1,15 @@\n+[project]\n+name = \"001\"\n+version = \"0.0.0\"\n+requires-python = \"\u003e=3.12\"\n+\n+[dependency-groups]\n+dev = []\n+\n+# managed by databricks local-env python sync — do not edit\n+[tool.uv]\n+constraint-dependencies = [\n+ \"pyarrow\u003c19\",\n+ \"pandas\u003c3\",\n+]\n+# end managed by databricks local-env python sync\n"
23+
},
24+
"phases": [
25+
{
26+
"phase": "preflight",
27+
"status": "ok"
28+
},
29+
{
30+
"phase": "resolve",
31+
"status": "ok"
32+
},
33+
{
34+
"phase": "fetch",
35+
"status": "ok"
36+
},
37+
{
38+
"phase": "merge",
39+
"status": "ok"
40+
},
41+
{
42+
"phase": "provision",
43+
"status": "ok"
44+
},
45+
{
46+
"phase": "validate",
47+
"status": "ok"
48+
}
49+
],
50+
"warnings": [],
51+
"error": null,
52+
"durationMs": 0
53+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trace $CLI local-env python sync --serverless v4 --constraints-only --check --output json
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = []
2+
3+
[Env]
4+
DATABRICKS_LOCALENV_CONSTRAINT_SOURCE = "$DATABRICKS_HOST"
5+
6+
[[Server]]
7+
Pattern = "GET /serverless/serverless-v4/pyproject.toml"
8+
Response.Body = '''
9+
[project]
10+
requires-python = ">=3.12"
11+
12+
[dependency-groups]
13+
dev = ["databricks-connect~=17.2.0"]
14+
15+
[tool.uv]
16+
constraint-dependencies = ["pyarrow<19", "pandas<3"]
17+
'''
18+
19+
[[Repls]]
20+
Old = 'uv uv \S+(?: \([^)]+\))?'
21+
New = 'uv [UV_VERSION]'

acceptance/localenv/env-unsupported/out.test.toml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
preflight ok check
2+
resolve ok source=cluster envKey=dbr/15.4.x-scala2.12
3+
fetch error no published environment for "dbr/15.4.x-scala2.12". If this is a new runtime, try the latest LTS target (e.g. --serverless v4 or a supported --cluster DBR): GET [DATABRICKS_URL]/dbr/15.4.x-scala2.12/pyproject.toml: environment key not found
4+
merge pending
5+
provision pending
6+
validate pending
7+
For more detail, re-run with --debug, or --output json to share a structured report.
8+
Error: no published environment for "dbr/15.4.x-scala2.12". If this is a new runtime, try the latest LTS target (e.g. --serverless v4 or a supported --cluster DBR): GET [DATABRICKS_URL]/dbr/15.4.x-scala2.12/pyproject.toml: environment key not found
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
musterr $CLI local-env python sync --cluster test-cluster-id --check
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = []
2+
3+
[Env]
4+
DATABRICKS_LOCALENV_CONSTRAINT_SOURCE = "$DATABRICKS_HOST"
5+
6+
[[Server]]
7+
Pattern = "GET /api/2.1/clusters/get"
8+
Response.Body = '''
9+
{
10+
"cluster_id": "test-cluster-id",
11+
"spark_version": "15.4.x-scala2.12"
12+
}
13+
'''
14+
15+
[[Server]]
16+
Pattern = "GET /dbr/15.4.x-scala2.12/pyproject.toml"
17+
Response.StatusCode = 404
18+
Response.Body = '{"message": "Not found"}'
19+
20+
[[Repls]]
21+
Old = 'uv uv \S+(?: \([^)]+\))?'
22+
New = 'uv [UV_VERSION]'

acceptance/localenv/flag-conflict/out.test.toml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Error: if any flags in the group [cluster serverless job] are set none of the others can be; [cluster serverless] were all set

0 commit comments

Comments
 (0)