-
Notifications
You must be signed in to change notification settings - Fork 207
integration: add e2e tests for environments setup-local #6155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rugpanov
wants to merge
3
commits into
main
Choose a base branch
from
dbconnect/setup-local-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+147
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| package environments_test | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "runtime" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/integration/internal/acc" | ||
| "github.com/databricks/cli/internal/testcli" | ||
| "github.com/databricks/cli/libs/localenv" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // The serverless target needs no running compute: --serverless-version is used | ||
| // verbatim, so these tests resolve against the real Jobs/Clusters-free path and | ||
| // fetch from the public databricks/environments repo. v5 is a published LTS | ||
| // target (see the repo's python/serverless/ tree). | ||
| const testServerlessVersion = "5" | ||
|
|
||
| // TestSetupLocalServerlessProvision drives the full non-dry-run pipeline against | ||
| // the real published constraints: resolve -> fetch -> uv sync -> validate. It | ||
| // asserts a real .venv is created and the --output json contract carries the | ||
| // resolved versions. This is the one integration test that exercises a real uv | ||
| // provision end to end; the acceptance suite covers everything else via --dry-run. | ||
| func TestSetupLocalServerlessProvision(t *testing.T) { | ||
| ctx, _ := acc.WorkspaceTest(t) | ||
|
|
||
| // setup-local operates on the current working directory; run in a fresh | ||
| // greenfield project (no pre-existing pyproject.toml). | ||
| dir := t.TempDir() | ||
| t.Chdir(dir) | ||
|
|
||
| // Skip rather than let the pipeline install uv: EnvAutoInstallUv would run the | ||
| // remote installer and mutate ~/.local/bin on a developer machine. CI installs | ||
| // uv, so this only skips where the side effect would be unwanted. | ||
| if _, err := exec.LookPath("uv"); err != nil { | ||
| t.Skipf("uv not found on PATH (%v)", err) | ||
| } | ||
|
|
||
| stdout, _ := testcli.RequireSuccessfulRun(t, ctx, | ||
| "environments", "setup-local", | ||
| "--serverless-version", testServerlessVersion, | ||
| "--output", "json", | ||
| ) | ||
|
|
||
| var res localenv.Result | ||
| require.NoError(t, json.Unmarshal(stdout.Bytes(), &res)) | ||
|
|
||
| assert.True(t, res.OK, "expected ok=true, got result: %s", stdout.String()) | ||
| assert.False(t, res.DryRun) | ||
| assert.Equal(t, "environments setup-local", res.Command) | ||
| assert.Equal(t, "default", res.Mode) | ||
|
|
||
| require.NotNil(t, res.Compute) | ||
| assert.Equal(t, "serverless", res.Compute.Source) | ||
| assert.Equal(t, "serverless/serverless-v"+testServerlessVersion, res.Compute.EnvKey) | ||
|
|
||
| require.NotNil(t, res.Resolved) | ||
| assert.NotEmpty(t, res.Resolved.PythonVersion, "resolved python version should be reported") | ||
| // The default mode installs databricks-connect, so the resolved pin is present. | ||
| assert.NotEmpty(t, res.Resolved.DBConnectVersion) | ||
|
|
||
| // Every phase must have reached ok, including the real provision and validate. | ||
| for _, ph := range res.Phases { | ||
| assert.Equalf(t, localenv.StatusOK, ph.Status, "phase %s not ok", ph.Phase) | ||
| } | ||
|
|
||
| // A real interpreter and lockfile were written into the project. testcli runs | ||
| // in-process, so runtime.GOOS is the runner's OS and picks the right layout. | ||
| assert.FileExists(t, venvPython(dir)) | ||
| assert.FileExists(t, filepath.Join(dir, "pyproject.toml")) | ||
| assert.FileExists(t, filepath.Join(dir, "uv.lock")) | ||
| } | ||
|
|
||
| // TestSetupLocalDryRunWritesNothing verifies the --dry-run contract against the | ||
| // real repo: the plan resolves and fetches, reports ok, but writes no files. | ||
| func TestSetupLocalDryRunWritesNothing(t *testing.T) { | ||
| ctx, _ := acc.WorkspaceTest(t) | ||
|
|
||
| dir := t.TempDir() | ||
| t.Chdir(dir) | ||
|
|
||
| stdout, _ := testcli.RequireSuccessfulRun(t, ctx, | ||
| "environments", "setup-local", | ||
| "--serverless-version", testServerlessVersion, | ||
| "--dry-run", | ||
| "--output", "json", | ||
| ) | ||
|
|
||
| var res localenv.Result | ||
| require.NoError(t, json.Unmarshal(stdout.Bytes(), &res)) | ||
| assert.True(t, res.OK) | ||
| assert.True(t, res.DryRun) | ||
|
|
||
| // --dry-run must not touch disk. | ||
| entries, err := os.ReadDir(dir) | ||
| require.NoError(t, err) | ||
| assert.Empty(t, entries, "dry-run wrote files: %v", entries) | ||
| } | ||
|
|
||
| // TestSetupLocalUnpublishedVersion verifies the fetch-phase error contract: an | ||
| // unpublished serverless version resolves fine but has no artifact, so the run | ||
| // fails with E_ENV_UNSUPPORTED and a non-zero exit (surfaced as a run error). | ||
| func TestSetupLocalUnpublishedVersion(t *testing.T) { | ||
| ctx, _ := acc.WorkspaceTest(t) | ||
|
|
||
| dir := t.TempDir() | ||
| t.Chdir(dir) | ||
|
|
||
| // A version far above anything published; resolution succeeds, fetch 404s. | ||
| stdout, _, runErr := testcli.RequireErrorRun(t, ctx, | ||
| "environments", "setup-local", | ||
| "--serverless-version", "9999", | ||
| "--dry-run", | ||
| "--output", "json", | ||
| ) | ||
| require.Error(t, runErr) | ||
|
|
||
| var res localenv.Result | ||
| require.NoError(t, json.Unmarshal(stdout.Bytes(), &res)) | ||
| assert.False(t, res.OK) | ||
| require.NotNil(t, res.Error) | ||
| assert.Equal(t, localenv.ErrEnvUnsupported, res.Error.Code) | ||
| assert.Equal(t, localenv.PhaseFetch, res.Error.FailurePhase) | ||
|
|
||
| // Even a failed fetch must not have written anything on a dry run: preflight | ||
| // skips ensureWritable and cache writes are suppressed, so the project dir | ||
| // must still be empty. | ||
| entries, err := os.ReadDir(dir) | ||
| require.NoError(t, err) | ||
| assert.Empty(t, entries, "dry-run wrote files: %v", entries) | ||
| } | ||
|
|
||
| // venvPython returns the path to the created virtualenv's interpreter, accounting | ||
| // for the Windows (Scripts/python.exe) vs Unix (bin/python) layout. | ||
| func venvPython(dir string) string { | ||
| if runtime.GOOS == "windows" { | ||
| return filepath.Join(dir, ".venv", "Scripts", "python.exe") | ||
| } | ||
| return filepath.Join(dir, ".venv", "bin", "python") | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not this file, but related: OWNERS routes this file to
team:platformrather thanteam:ide./integration/→team:platform(.github/OWNERS:65) andfindOwnersis last-match-wins (.github/scripts/owners.js:97-106), so this file — squarely localenv territory — won't route to the team that owns/libs/localenv/,/cmd/environments/, and/acceptance/localenv/(added in #6187).Worth adding, and it must go below line 65 to win:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 9d9c0ac — added
/integration/cmd/environments/ team:idebelow the/integration/rule so it wins under last-match-wins. Verified withfindOwners: this file now resolves torugpanov rclarey anton-107 misha-db, whileintegration/cmd/jobs/still resolves toteam:platform.