Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 54 additions & 10 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ func requirePrerequisites(t *testing.T) bool {

// selectedTests, when non-empty, limits the run to those test directories.
// skipToolBuilds skips building the tools that the selected tests do not use
// (the databricks-bundles wheel, yamlfmt); it must stay false for a
// full run.
// (the databricks-bundles wheel, yamlfmt) and the agent CLI stand-ins. Tests
// under acceptance/cmd/aitools then stop at script.prepare, so it must stay
// false for a full run.
func testAccept(t *testing.T, inprocessMode bool, selectedTests []string, skipToolBuilds bool) int {
if testdiff.OverwriteMode && !hasRunFilter() {
Subset = true
Expand Down Expand Up @@ -297,24 +298,32 @@ func testAccept(t *testing.T, inprocessMode bool, selectedTests []string, skipTo

buildDir := getBuildDir(t, cwd, runtime.GOOS, runtime.GOARCH)

// Download old CLI versions in parallel, overlapping with the builds below.
// Download old CLI versions and build the agent CLI stand-ins in parallel, overlapping with the builds below.
var cli293Path, cli18Path, cli1161Path string
var oldCLIs errgroup.Group
var setup errgroup.Group
if !inprocessMode {
oldCLIs.Go(func() (err error) {
setup.Go(func() (err error) {
cli293Path, err = downloadCLI(buildDir, "0.293.0")
return err
})
oldCLIs.Go(func() (err error) {
setup.Go(func() (err error) {
cli18Path, err = downloadCLI(buildDir, "1.8.0")
return err
})
// CLI version that predates the hashed_fields feature. Used by acceptance/bundle/hashing
oldCLIs.Go(func() (err error) {
setup.Go(func() (err error) {
cli1161Path, err = downloadCLI(buildDir, "1.16.1")
return err
})
}
// The stand-ins for the agent CLIs go first on PATH in every test under acceptance/cmd/aitools (see script.prepare there).
var fakeAgentDir string
if !skipToolBuilds {
setup.Go(func() (err error) {
fakeAgentDir, err = buildFakeAgentCLIs(buildDir)
return err
})
}

vendoredPyPackages, err := filepath.Abs("../libs/vendored_py_packages")
require.NoError(t, err)
Expand Down Expand Up @@ -370,7 +379,7 @@ func testAccept(t *testing.T, inprocessMode bool, selectedTests []string, skipTo
version = resolveLatestVersion(t, buildDir)
}
// Wait for the old CLI downloads so the same version isn't downloaded concurrently.
require.NoError(t, oldCLIs.Wait())
require.NoError(t, setup.Wait())
execPath = DownloadCLI(t, buildDir, version)
// For a downloaded release the version string is already known.
cliVersion = version
Expand Down Expand Up @@ -402,9 +411,12 @@ func testAccept(t *testing.T, inprocessMode bool, selectedTests []string, skipTo
t.Setenv("SELECTION", selectionPath)
repls.SetPath(selectionPath, "[SELECTION]")

if !inprocessMode {
require.NoError(t, oldCLIs.Wait())
require.NoError(t, setup.Wait())
if !skipToolBuilds {
t.Setenv("FAKE_AGENT_DIR", fakeAgentDir)
}

if !inprocessMode {
t.Setenv("CLI_293", cli293Path)
repls.SetPath(cli293Path, "[CLI_293]")

Expand Down Expand Up @@ -1498,6 +1510,38 @@ func buildSelectionCmd(t *testing.T, buildDir string) string {
return execPath
}

// buildFakeAgentCLIs builds the stand-in for the claude, codex, gemini and copilot CLIs once, and copies it under each
// name, since a PATH lookup finds a binary by name. It returns the directory that holds them. It takes no *testing.T,
// so that it can run in the errgroup of the builds.
func buildFakeAgentCLIs(buildDir string) (string, error) {
dir := filepath.Join(buildDir, "agent-clis")
if err := os.MkdirAll(dir, 0o755); err != nil {
return "", err
}
built := filepath.Join(dir, "fakeagent"+exeSuffix)
args := []string{"go", "build", "-o", built}
if runtime.GOOS == "windows" {
// See BuildCLI: VCS stamping fails on Windows.
args = append(args, "-buildvcs=false")
}
// The package path goes last: go build reads anything after it as another package.
args = append(args, "./internal/fakeagent")
if out, err := exec.Command(args[0], args[1:]...).CombinedOutput(); err != nil {
return "", fmt.Errorf("building the agent CLI stand-in failed: %w\n%s", err, out)
}

data, err := os.ReadFile(built)
if err != nil {
return "", err
}
for _, name := range []string{"claude", "codex", "gemini", "copilot"} {
if err := os.WriteFile(filepath.Join(dir, name+exeSuffix), data, 0o755); err != nil {
return "", err
}
}
return dir, nil
}

// readGOFIPS140 returns the GOFIPS140 version the Taskfile pins for `task`
// builds; the release pipeline pins the same value independently in
// .goreleaser.yaml.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[logfood]
host = $DATABRICKS_HOST
token = test-token-logfood
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
Loading
Loading