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/air/7646.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `air run` now lists a `code_source.root_path` outside a git repository relative to `root_path`, so running from a subdirectory of `root_path` no longer uploads an empty or partial snapshot. ([#7646](https://github.com/databricks/cli/pull/7646))
12 changes: 12 additions & 0 deletions acceptance/air/run/non-git-subdir.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
experiment_name: smoke-test
command: python main.py
compute:
accelerator_type: GPU_1xH100
num_accelerators: 1
code_source:
type: snapshot
snapshot:
root_path: ..
include_paths:
- main.py
- data
6 changes: 6 additions & 0 deletions acceptance/air/run/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ Tip: use the --debug flag to see more details and a trace of this error:

Exit code: 1

=== a non-git root_path selects the same files when run from its subdirectory

>>> [CLI] air run -f workload.yaml --dry-run
Dry run: code_source snapshot would include 2 file(s).
Dry run: configuration for "smoke-test" is valid; not submitting.

=== git.remote is rejected

>>> [CLI] air run -f git-remote.yaml --dry-run
Expand Down
10 changes: 10 additions & 0 deletions acceptance/air/run/script
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ echo 'print(1)' > .scratch/proj/main.py
errcode trace $CLI air run -f ignored-root.yaml --dry-run
rm -fr .git .gitignore .scratch

title "a non-git root_path selects the same files when run from its subdirectory"
# sub/main.py shadows main.py; a listing relative to the working directory would pick 1 file.
mkdir -p proj/sub proj/data
echo 'print(1)' > proj/main.py
echo 'print(2)' > proj/sub/main.py
echo 'a,b' > proj/data/x.csv
cp non-git-subdir.yaml proj/sub/workload.yaml
(cd proj/sub && trace $CLI air run -f workload.yaml --dry-run)
rm -fr proj

title "git.remote is rejected"
errcode trace $CLI air run -f git-remote.yaml --dry-run

Expand Down
4 changes: 3 additions & 1 deletion cmd/air/snapshot_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ func snapshotFiles(ctx context.Context, repoPath string, includePaths []string,
if output, err := cmd.CombinedOutput(); err != nil {
return nil, fmt.Errorf("failed to initialize temporary git metadata: %w: %s", err, strings.TrimSpace(string(output)))
}
args = []string{"--git-dir", gitDir, "--work-tree", repoPath, "ls-files", "-z", "--cached", "--others", "--exclude-standard"}
// Without -C, git resolves include_paths and prints file names relative to the
// CLI's working directory, not repoPath.
args = []string{"-C", repoPath, "--git-dir", gitDir, "--work-tree", repoPath, "ls-files", "-z", "--cached", "--others", "--exclude-standard"}
}

if len(includePaths) > 0 {
Expand Down
32 changes: 32 additions & 0 deletions cmd/air/snapshot_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,38 @@ func TestCreatePlainTarball_IncludePaths(t *testing.T) {
assert.NotContains(t, entries, dirName+"/a.txt")
}

func TestSnapshotFiles_NonGitRootFromSubdirectory(t *testing.T) {
// The CLI often runs from the workload's directory, inside root_path. sub/main.py
// shadows main.py, so a listing relative to the working directory picks the wrong
// files instead of failing.
tests := []struct {
name string
includePaths []string
want []string
}{
{name: "include_paths", includePaths: []string{"main.py", "data"}, want: []string{"data/x.csv", "main.py"}},
{name: "whole root", want: []string{"data/x.csv", "main.py", "sub/main.py"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
root := t.TempDir()
writeRepoFile(t, root, "main.py", "print('root')")
writeRepoFile(t, root, "sub/main.py", "print('sub')")
writeRepoFile(t, root, "data/x.csv", "a,b")
t.Chdir(filepath.Join(root, "sub"))

files, err := snapshotFiles(t.Context(), root, tt.includePaths, false)
require.NoError(t, err)
var got []string
for _, f := range files {
got = append(got, filepath.ToSlash(f.rel))
}
slices.Sort(got)
assert.Equal(t, tt.want, got)
})
}
}

func TestCreatePlainTarball_HonorsNestedGitignoreAndNegation(t *testing.T) {
repo := t.TempDir()
writeRepoFile(t, repo, ".gitignore", "*.log\n!keep.log\n/root-only.txt\n")
Expand Down
Loading