Skip to content

Commit 3e7c38f

Browse files
denikIsaac
andauthored
acc: cover environments setup-local on cloud, drop the integration equivalents (#8117)
## Changes - Delete `integration/cmd/environments` (3 tests for `databricks environments setup-local --serverless-version`). All three are PORTED to the new `acceptance/localenv/published-serverless` (`Cloud = true`): - Locally and on cloud: a v5 `--dry-run` plans and fetches with nothing written, and an unpublished v9999 `--dry-run` fails in the fetch phase with `E_ENV_UNSUPPORTED` (asserted with `musterr`), with nothing written. Locally the test server serves the artifacts. On cloud the script unsets the constraint-source override, so the CLI fetches the real published repo (`artifactSource: network`). - On cloud only: a real `uv sync` of serverless v5 (the deleted `TestSetupLocalServerlessProvision`). The JSON result (`ok`, `dryRun: false`, command, mode, compute, artifact source, Python and databricks-connect versions present, all six phases `ok`), the exact project files (`.venv`, `pyproject.toml`, `uv.lock`) and the venv interpreter at the OS layout are diffed against the committed `provision.expected.txt`. A mismatch prints the diff and fails the test, so `output.txt` is identical locally and on cloud. - The provision step unsets the runner's `UV_OFFLINE`/`UV_FIND_LINKS`, because the vendored wheels don't include databricks-connect. It gives `uv python install` a private dir, like the deleted test did. ## Why `integration/` is deprecated ([integration/README.md](https://github.com/databricks/cli/blob/main/integration/README.md), `.agents/rules/testing.md`). Earlier batches: #6113, #6140, #6223, #6316, #7251. Dashboard: [integration/cmd/environments.TestSetupLocalServerlessProvision](http://go/cli/dashboard/test/integration/cmd/environments.TestSetupLocalServerlessProvision), [error/1082](http://go/cli/dashboard/error/1082) (`Received unexpected error: AlreadyPrinted`, 16 failures across aws/azure/gcp in the week to 2026-11-26). ## Coverage proof Method: each integration test's `-coverpkg` profile was recorded on AWS. The tests don't branch on the cloud and make no workspace calls with `--serverless-version`. Each profile was compared block by block with per-test acceptance coverage from a full local run plus AWS runs of the two new tests. | integration test | verdict | product blocks (command-specific) | covered | acceptance tests | |---|---|---|---|---| | TestSetupLocalServerlessProvision | PORTED | 722 | all but 3 harness-only | localenv/published-serverless (cloud provision step) | | TestSetupLocalDryRunWritesNothing | PORTED | 618 | all but 3 harness-only | localenv/published-serverless | | TestSetupLocalUnpublishedVersion | PORTED | 453 | all but 3 harness-only | localenv/published-serverless | Real-gap blocks are the same for all three, and only the in-process test harness reaches them: - `cmd/root/tree.go:54.38,54.55` and `tree.go:57.38,57.55` (`Tree.SetOut`/`SetErr`): only `internal/testcli` calls them. - `cmd/root/auth.go:222.3,223.1` (nil host-metadata resolver factory): only `main.go` registers the factory, so this branch runs only in test binaries. <details><summary>Assertion map</summary> | integration test:line | fact | acceptance check | where | |---|---|---|---| | Provision:53 | real provision exits 0 | provision step: `diff` against provision.expected.txt passes | cloud | | Provision:62-65 | ok, dryRun=false, command, mode=default | provision.expected.txt: JSON projection | cloud | | Provision:67-69 | compute source serverless, envKey serverless/serverless-v5 | provision.expected.txt: `compute` | cloud | | Provision:71-74 | pythonVersion and dbconnectVersion non-empty strings | provision.expected.txt: `hasPythonVersion`, `hasDBConnectVersion` | cloud | | Provision:78 | every phase ok | provision.expected.txt: six `<phase>: ok` lines | cloud | | Provision:83-85 | venv interpreter (OS layout), pyproject.toml, uv.lock | provision.expected.txt: `files: .venv pyproject.toml uv.lock`, `<file>: regular file` | cloud | | DryRun:96-106 | v5 --dry-run exits 0, ok, dryRun=true | published-serverless: first section | local + cloud | | DryRun:110-111 | project dir empty | published-serverless: `files in project: 0` | local + cloud | | Unpublished:124-130 | v9999 --dry-run exits non-zero | published-serverless: `musterr` | local + cloud | | Unpublished:134-137 | ok=false, E_ENV_UNSUPPORTED, failurePhase fetch | published-serverless: second projection | local + cloud | | Unpublished:143-144 | project dir empty | published-serverless: second `files in project: 0` | local + cloud | </details> ## Tests - `published-serverless` passes locally and on AWS (`testme-aws`, empty uv cache). Earlier heads of this PR ran the same dry-run and provision checks in two directories, and those passed in the PR's cloud CI on aws, azure and gcp, linux and windows (real fetch, real interpreter download, real `uv sync`). The `cloud:` line in the last commit reruns the merged test on every cloud. - Mutation checks: making `--dry-run` write `pyproject.toml` (libs/localenv/pipeline.go, Check branch) fails the test locally (`files in project: 1`). Changing one line of `provision.expected.txt` fails the cloud run. - Runtime: the integration tests took about 48s on AWS (provision 47s, others about 1s each). The new test takes 15-45s on cloud (most of it the provision, depending on the uv cache and OS) and under 1s locally. ## Gaps and risks - The real provision is checked only on cloud; locally the non-dry-run pipeline is covered by the sibling fake-uv tests (`provision-conflict`, `provision-conflict-sync`, `workspace-member`). A fake-uv local provision here would need `GOOS.windows = false`, which would drop the Windows cloud run. - The JSON is checked through jq projections, not a typed decode, so a wrong type in an unprojected field (e.g. `durationMs`) would go unnoticed, as in the sibling localenv tests. - The local AWS run took the installed-Python fallback (downloads disabled on the dev box). CI downloads the interpreter, as the deleted test did. The output doesn't print which path was taken. - Selection: `integration/` ran on every cloud run. Acceptance cloud PR runs pick only changed or named tests, while main and nightly runs run all of them. So a later `libs/localenv` change runs the provision test on its PR only if it is named. - Both tests still depend on the published repo (v5 present, v9999 absent) and on a package index, as the deleted tests did. - Risk: low. This PR was created by the integration-deprecation loop. 🤖 AI agent (opus5.5, isaac_claude) This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 8569867 commit 3e7c38f

6 files changed

Lines changed: 163 additions & 154 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cloud = true
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
=== Published version: the plan resolves and fetches, and nothing is written
3+
4+
>>> [CLI] environments setup-local --serverless-version 5 --dry-run --output json
5+
{
6+
"ok": true,
7+
"dryRun": true,
8+
"command": "environments setup-local",
9+
"compute": {
10+
"source": "serverless",
11+
"envKey": "serverless/serverless-v5"
12+
},
13+
"artifactSource": "network",
14+
"hasPythonVersion": true,
15+
"phases": [
16+
"preflight: ok",
17+
"resolve: ok",
18+
"fetch: ok",
19+
"merge: ok",
20+
"provision: ok",
21+
"validate: ok"
22+
]
23+
}
24+
files in project: 0
25+
26+
=== Unpublished version: fetch fails with E_ENV_UNSUPPORTED, and nothing is written
27+
28+
>>> [CLI] environments setup-local --serverless-version 9999 --dry-run --output json
29+
{
30+
"ok": false,
31+
"dryRun": true,
32+
"code": "E_ENV_UNSUPPORTED",
33+
"failurePhase": "fetch"
34+
}
35+
files in project: 0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"ok": true,
3+
"dryRun": false,
4+
"command": "environments setup-local",
5+
"mode": "default",
6+
"compute": {
7+
"source": "serverless",
8+
"envKey": "serverless/serverless-v5"
9+
},
10+
"artifactSource": "network",
11+
"hasPythonVersion": true,
12+
"hasDBConnectVersion": true,
13+
"phases": [
14+
"preflight: ok",
15+
"resolve: ok",
16+
"fetch: ok",
17+
"merge: ok",
18+
"provision: ok",
19+
"validate: ok"
20+
]
21+
}
22+
files: .venv pyproject.toml uv.lock
23+
venv python: regular file
24+
pyproject.toml: regular file
25+
uv.lock: regular file
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Locally the test server stands in for the published artifacts; on cloud the
2+
# CLI fetches the real ones.
3+
if [ -z "${CLOUD_ENV:-}" ]; then
4+
export DATABRICKS_LOCALENV_CONSTRAINT_SOURCE_URL_TEST_OVERRIDE="$DATABRICKS_HOST"
5+
else
6+
unset DATABRICKS_LOCALENV_CONSTRAINT_SOURCE_URL_TEST_OVERRIDE
7+
fi
8+
9+
# Run in an empty project dir so "writes nothing" is a plain file count. The JSON
10+
# goes to LOG files outside it: resolved versions follow the published repo.
11+
mkdir project
12+
cd project
13+
14+
title "Published version: the plan resolves and fetches, and nothing is written"
15+
trace $CLI environments setup-local --serverless-version 5 --dry-run --output json > ../LOG.v5.json
16+
jq '{ok, dryRun, command, compute: {source: .compute.source, envKey: .compute.envKey}, artifactSource: .resolved.artifactSource, hasPythonVersion: (.resolved.pythonVersion | type == "string" and length > 0), phases: [.phases[] | "\(.phase): \(.status)"]}' ../LOG.v5.json
17+
echo "files in project: $(ls -A | wc -l | tr -d ' ')"
18+
19+
title "Unpublished version: fetch fails with E_ENV_UNSUPPORTED, and nothing is written"
20+
musterr trace $CLI environments setup-local --serverless-version 9999 --dry-run --output json > ../LOG.v9999.json
21+
jq '{ok, dryRun, code: .error.code, failurePhase: .error.failurePhase}' ../LOG.v9999.json
22+
echo "files in project: $(ls -A | wc -l | tr -d ' ')"
23+
cd ..
24+
25+
# The real provision needs the published artifacts and a package index, so it
26+
# runs on cloud only. Its result is diffed against provision.expected.txt: a
27+
# mismatch prints the diff and fails the script. Locally the dry runs above and
28+
# the sibling tests with a fake uv cover the pipeline.
29+
if [ -n "${CLOUD_ENV:-}" ]; then
30+
# The runner points every uv at the vendored wheels offline, which lack
31+
# databricks-connect (a warm uv cache would hide that).
32+
unset UV_OFFLINE UV_FIND_LINKS
33+
34+
# `uv python install` rewrites the minor-version links of every managed Python
35+
# in its install dir (junctions on Windows), which breaks concurrent uv users
36+
# of a shared dir, so give it a private one. Git Bash's $PWD is /c/..., which
37+
# the native uv does not read, so use pwd -W there, as sethome does.
38+
venv_python=.venv/bin/python
39+
case "$OSTYPE" in
40+
msys*|cygwin*|win32)
41+
root="$(pwd -W)"
42+
venv_python=.venv/Scripts/python.exe
43+
;;
44+
*) root="$PWD" ;;
45+
esac
46+
export UV_PYTHON_INSTALL_DIR="$root/uv-python/installs"
47+
export UV_PYTHON_BIN_DIR="$root/uv-python/bin"
48+
export UV_PYTHON_INSTALL_REGISTRY=0
49+
50+
mkdir provision
51+
cd provision
52+
# Traced into the LOG file: a trace line in output.txt would be cloud-only.
53+
trace $CLI environments setup-local --serverless-version 5 --output json > ../LOG.provision.json 2> ../LOG.provision.stderr
54+
{
55+
jq '{ok, dryRun, command, mode, compute: {source: .compute.source, envKey: .compute.envKey}, artifactSource: .resolved.artifactSource, hasPythonVersion: (.resolved.pythonVersion | type == "string" and length > 0), hasDBConnectVersion: (.resolved.dbconnectVersion | type == "string" and length > 0), phases: [.phases[] | "\(.phase): \(.status)"]}' ../LOG.provision.json
56+
echo "files:" $(ls -A | sort)
57+
for f in "$venv_python" pyproject.toml uv.lock; do
58+
if [ -f "$f" ]; then
59+
echo "${f/#$venv_python/venv python}: regular file"
60+
fi
61+
done
62+
} > ../LOG.provision.txt
63+
cd ..
64+
# Native jq on Windows may end lines with CRLF.
65+
diff --strip-trailing-cr provision.expected.txt LOG.provision.txt
66+
fi
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# setup-local against the published databricks/environments artifacts. Locally
2+
# the test server stands in for them (stubs below) and the script plans only;
3+
# on cloud the CLI fetches the real artifacts, so the run pins that v5 is
4+
# published in a shape setup-local can plan from and provision, and that an
5+
# unpublished version maps to E_ENV_UNSUPPORTED.
6+
Cloud = true
7+
8+
# The real provision (cloud only) writes a venv, a lockfile and uv's private
9+
# Python installs; their contents follow the published repo and the package
10+
# index, so the script checks them itself.
11+
Ignore = ["provision", "uv-python"]
12+
13+
# The published v5 artifact, trimmed to the fields setup-local reads.
14+
[[Server]]
15+
Pattern = "GET /serverless/serverless-v5/pyproject.toml"
16+
Response.Body = '''
17+
[project]
18+
name = "constraint-env-serverless-v5"
19+
version = "0.1.0"
20+
requires-python = "==3.12.*"
21+
22+
[dependency-groups]
23+
dev = [
24+
"databricks-connect~=18.2.0",
25+
]
26+
27+
[tool.uv]
28+
constraint-dependencies = [
29+
"pandas~=2.2.3",
30+
]
31+
'''
32+
33+
[[Server]]
34+
Pattern = "GET /serverless/serverless-v9999/pyproject.toml"
35+
Response.StatusCode = 404
36+
Response.Body = '404: Not Found'

‎integration/cmd/environments/setup_local_test.go‎

Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
 (0)