Skip to content
Open
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
1 change: 1 addition & 0 deletions .nextchanges/cli/apps-run-local-absolute-entry-point.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fix `apps run-local --entry-point` failing with absolute paths to the app spec file. ([#6918](https://github.com/databricks/cli/pull/6918))
6 changes: 5 additions & 1 deletion libs/apps/runlocal/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ func (a *AppSpec) GetFileName() string {
func ReadAppSpecFile(config *Config) (*AppSpec, error) {
spec := &AppSpec{config: config}
for _, file := range config.AppSpecFiles {
// An absolute entry point is used verbatim; relative names resolve under AppPath.
if !filepath.IsAbs(file) {
file = filepath.Join(config.AppPath, file)
}
// Read the yaml file
yamlFile, err := os.ReadFile(filepath.Join(config.AppPath, file))
yamlFile, err := os.ReadFile(file)
if errors.Is(err, fs.ErrNotExist) {
continue
}
Expand Down
32 changes: 32 additions & 0 deletions libs/apps/runlocal/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,44 @@ package runlocal

import (
"context"
"os"
"path/filepath"
"testing"

"github.com/databricks/cli/libs/env"
"github.com/stretchr/testify/require"
)

func TestReadAppSpecFile(t *testing.T) {
appDir := t.TempDir()
specDir := t.TempDir()

specYAML := "command:\n - python\n - app.py\n"
require.NoError(t, os.WriteFile(filepath.Join(appDir, "app.yml"), []byte(specYAML), 0o644))
// Absolute spec lives outside the app dir so the test proves the
// path is used verbatim instead of joined with AppPath.
absSpec := filepath.Join(specDir, "custom.yml")
require.NoError(t, os.WriteFile(absSpec, []byte(specYAML), 0o644))

t.Run("relative path", func(t *testing.T) {
spec, err := ReadAppSpecFile(&Config{AppPath: appDir, AppSpecFiles: []string{"app.yml"}})
require.NoError(t, err)
require.Equal(t, []string{"python", "app.py"}, spec.Command)
})

t.Run("absolute path", func(t *testing.T) {
spec, err := ReadAppSpecFile(&Config{AppPath: appDir, AppSpecFiles: []string{absSpec}})
require.NoError(t, err)
require.Equal(t, []string{"python", "app.py"}, spec.Command)
})

t.Run("missing file returns empty spec", func(t *testing.T) {
spec, err := ReadAppSpecFile(&Config{AppPath: appDir, AppSpecFiles: []string{"does-not-exist.yml"}})
require.NoError(t, err)
require.Empty(t, spec.Command)
})
}

func TestAppSpecLoadEnvVars(t *testing.T) {
tempDir := t.TempDir()
config := &Config{
Expand Down