From 32e425758d7288249c1cf60a1e9f52e754f6d8f9 Mon Sep 17 00:00:00 2001 From: Caroline Chen <324939130+caroline-db@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:54:50 +0000 Subject: [PATCH 1/4] air: validate list filters --- .nextchanges/air/list-filter-validation.md | 1 + acceptance/air/help/output.txt | 5 +++- cmd/air/list.go | 5 +++- cmd/air/list_filter.go | 34 +++++++++++++++++++--- cmd/air/list_filter_test.go | 32 +++++++++++++++++++- 5 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 .nextchanges/air/list-filter-validation.md diff --git a/.nextchanges/air/list-filter-validation.md b/.nextchanges/air/list-filter-validation.md new file mode 100644 index 00000000000..ee639e94b6c --- /dev/null +++ b/.nextchanges/air/list-filter-validation.md @@ -0,0 +1 @@ +* Support full accelerator types in `air list` filters and reject invalid filter values. diff --git a/acceptance/air/help/output.txt b/acceptance/air/help/output.txt index 29ab1a40dbe..6d8ea68da11 100644 --- a/acceptance/air/help/output.txt +++ b/acceptance/air/help/output.txt @@ -52,7 +52,8 @@ List active runs for the current user. Filters: Use --filter KEY=VALUE per condition. A run must match every condition. - accelerator_type Accelerator type, such as A10 or H100. + accelerator_type Accelerator family or exact full type. Examples: A10, H100, + GPU_1xA10, GPU_8xH100. experiment Case-insensitive glob matched against the experiment name. num_accelerators Total GPU count. user Run creator identifier. @@ -63,6 +64,8 @@ Usage: Examples: databricks air list --filter accelerator_type=H100 + databricks air list --filter accelerator_type=GPU_8xH100 + databricks air list --all-status \ --filter 'experiment=qwen*' \ --filter num_accelerators=8 \ diff --git a/cmd/air/list.go b/cmd/air/list.go index 61cfe3d9b3b..ff260b68cef 100644 --- a/cmd/air/list.go +++ b/cmd/air/list.go @@ -96,12 +96,15 @@ func newListCommand() *cobra.Command { Filters: Use --filter KEY=VALUE per condition. A run must match every condition. - accelerator_type Accelerator type, such as A10 or H100. + accelerator_type Accelerator family or exact full type. Examples: A10, H100, + GPU_1xA10, GPU_8xH100. experiment Case-insensitive glob matched against the experiment name. num_accelerators Total GPU count. user Run creator identifier.`, Example: ` databricks air list --filter accelerator_type=H100 + databricks air list --filter accelerator_type=GPU_8xH100 + databricks air list --all-status \ --filter 'experiment=qwen*' \ --filter num_accelerators=8 \ diff --git a/cmd/air/list_filter.go b/cmd/air/list_filter.go index bd2bf8dff6e..435c6b63b81 100644 --- a/cmd/air/list_filter.go +++ b/cmd/air/list_filter.go @@ -26,8 +26,8 @@ type listFilters struct { User string // Experiment is a case-insensitive glob Experiment string - // AcceleratorType is a case-insensitive substring matched against the - // display GPU name (e.g. "H100"). + // AcceleratorType is a case-insensitive exact match against either the full + // accelerator type or its display family (e.g. "GPU_8xH100" or "H100"). AcceleratorType string // NumAccelerators is an exact match against the GPU count. NumAccelerators *int @@ -40,12 +40,21 @@ func parseListFilters(raw []string) (listFilters, error) { if !ok || key == "" { return listFilters{}, fmt.Errorf("invalid --filter %q: expected KEY=VALUE", item) } + if strings.TrimSpace(value) == "" { + return listFilters{}, fmt.Errorf("invalid --filter %s: value cannot be empty", key) + } switch key { case "user": f.User = value case "experiment": + if _, err := path.Match(value, ""); err != nil { + return listFilters{}, fmt.Errorf("invalid --filter experiment=%q: invalid glob pattern: %w", value, err) + } f.Experiment = value case "accelerator_type": + if !validAcceleratorFilter(value) { + return listFilters{}, fmt.Errorf("invalid --filter accelerator_type=%q: %s", value, validAcceleratorFilterHint()) + } f.AcceleratorType = value case "num_accelerators": n, err := strconv.Atoi(value) @@ -60,6 +69,22 @@ func parseListFilters(raw []string) (listFilters, error) { return f, nil } +// validAcceleratorFilter reports whether value is a full accelerator type or +// a short family name. Full types select one topology; short names match every +// topology in that family (for example, H100 matches both 1x and 8x H100). +func validAcceleratorFilter(value string) bool { + for _, gpuType := range gpuTypes { + if strings.EqualFold(value, string(gpuType)) || strings.EqualFold(value, gpuDisplayName(string(gpuType))) { + return true + } + } + return false +} + +func validAcceleratorFilterHint() string { + return "use a family name (A10, H100, B300, RTX6000) or a full type; " + validGPUTypesHint() +} + // filterFields are the task-filter inputs, cached alongside the row so a cache // hit can be re-filtered without re-fetching the run. type filterFields struct { @@ -95,8 +120,9 @@ func (f listFilters) matchesFields(fields filterFields) bool { } if f.AcceleratorType != "" { - display := strings.ToLower(gpuDisplayName(fields.GPUType)) - if !strings.Contains(display, strings.ToLower(f.AcceleratorType)) { + matchesFullType := strings.EqualFold(fields.GPUType, f.AcceleratorType) + matchesFamily := strings.EqualFold(gpuDisplayName(fields.GPUType), f.AcceleratorType) + if !matchesFullType && !matchesFamily { return false } } diff --git a/cmd/air/list_filter_test.go b/cmd/air/list_filter_test.go index 381f5e3a62d..a98976ab4b7 100644 --- a/cmd/air/list_filter_test.go +++ b/cmd/air/list_filter_test.go @@ -46,6 +46,34 @@ func TestParseListFilters(t *testing.T) { require.Error(t, err) assert.Contains(t, err.Error(), "positive integer") }) + + for _, filter := range []string{"user=", "experiment=", "accelerator_type=", "num_accelerators="} { + t.Run("empty "+filter, func(t *testing.T) { + _, err := parseListFilters([]string{filter}) + require.Error(t, err) + assert.Contains(t, err.Error(), "value cannot be empty") + }) + } + + t.Run("malformed experiment glob", func(t *testing.T) { + _, err := parseListFilters([]string{"experiment=["}) + require.Error(t, err) + assert.Contains(t, err.Error(), "invalid glob pattern") + }) + + t.Run("unsupported accelerator type", func(t *testing.T) { + _, err := parseListFilters([]string{"accelerator_type=GPU_1xV100"}) + require.Error(t, err) + assert.Contains(t, err.Error(), "use a family name") + }) + + for _, acceleratorType := range []string{"GPU_1xA10", "GPU_1xH100", "GPU_8xH100"} { + t.Run("full accelerator type "+acceleratorType, func(t *testing.T) { + f, err := parseListFilters([]string{"accelerator_type=" + acceleratorType}) + require.NoError(t, err) + assert.Equal(t, acceleratorType, f.AcceleratorType) + }) + } } func TestListFiltersMatches(t *testing.T) { @@ -61,7 +89,9 @@ func TestListFiltersMatches(t *testing.T) { {"experiment suffix glob", listFilters{Experiment: "*-eval"}, true}, {"experiment case-insensitive", listFilters{Experiment: "QWEN*"}, true}, {"experiment no match", listFilters{Experiment: "llama*"}, false}, - {"accelerator type substring", listFilters{AcceleratorType: "h100"}, true}, + {"accelerator family", listFilters{AcceleratorType: "h100"}, true}, + {"accelerator full type", listFilters{AcceleratorType: "gpu_8xh100"}, true}, + {"accelerator full type other topology", listFilters{AcceleratorType: "GPU_1xH100"}, false}, {"accelerator type no match", listFilters{AcceleratorType: "a10"}, false}, {"num accelerators match", listFilters{NumAccelerators: new(8)}, true}, {"num accelerators no match", listFilters{NumAccelerators: new(4)}, false}, From 558f3aa8c66f5935181f69b1e259248d252e813d Mon Sep 17 00:00:00 2001 From: Caroline Chen <324939130+caroline-db@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:55:44 +0000 Subject: [PATCH 2/4] air: link changelog entry --- .nextchanges/air/list-filter-validation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/air/list-filter-validation.md b/.nextchanges/air/list-filter-validation.md index ee639e94b6c..a2a28cac621 100644 --- a/.nextchanges/air/list-filter-validation.md +++ b/.nextchanges/air/list-filter-validation.md @@ -1 +1 @@ -* Support full accelerator types in `air list` filters and reject invalid filter values. +* Support full accelerator types in `air list` filters and reject invalid filter values. ([#7515](https://github.com/databricks/cli/pull/7515)) From 038b845ce188650ce5b2bb839fdf0666a6ed184d Mon Sep 17 00:00:00 2001 From: Caroline Chen <324939130+caroline-db@users.noreply.github.com> Date: Thu, 12 Nov 2026 20:03:40 +0000 Subject: [PATCH 3/4] air: use workspace accelerator options for list filters --- .nextchanges/air/list-filter-validation.md | 2 +- acceptance/air/help/output.txt | 4 +- cmd/air/list.go | 13 ++- cmd/air/list_filter.go | 104 +++++++++++++++++---- cmd/air/list_filter_test.go | 68 +++++++++++--- cmd/air/list_test.go | 22 +++++ 6 files changed, 178 insertions(+), 35 deletions(-) diff --git a/.nextchanges/air/list-filter-validation.md b/.nextchanges/air/list-filter-validation.md index a2a28cac621..06f683bbdc6 100644 --- a/.nextchanges/air/list-filter-validation.md +++ b/.nextchanges/air/list-filter-validation.md @@ -1 +1 @@ -* Support full accelerator types in `air list` filters and reject invalid filter values. ([#7515](https://github.com/databricks/cli/pull/7515)) +* Support workspace accelerator families, display names, and full types in `air list` filters, and reject invalid filter values. ([#7515](https://github.com/databricks/cli/pull/7515)) diff --git a/acceptance/air/help/output.txt b/acceptance/air/help/output.txt index 6d8ea68da11..e51552e6938 100644 --- a/acceptance/air/help/output.txt +++ b/acceptance/air/help/output.txt @@ -52,8 +52,8 @@ List active runs for the current user. Filters: Use --filter KEY=VALUE per condition. A run must match every condition. - accelerator_type Accelerator family or exact full type. Examples: A10, H100, - GPU_1xA10, GPU_8xH100. + accelerator_type Accelerator family, display name, or full type. Examples: + A10, H100, 1xA10, 8xH100, GPU_1xA10, GPU_8xH100. experiment Case-insensitive glob matched against the experiment name. num_accelerators Total GPU count. user Run creator identifier. diff --git a/cmd/air/list.go b/cmd/air/list.go index ff260b68cef..10f6cd25f14 100644 --- a/cmd/air/list.go +++ b/cmd/air/list.go @@ -96,8 +96,8 @@ func newListCommand() *cobra.Command { Filters: Use --filter KEY=VALUE per condition. A run must match every condition. - accelerator_type Accelerator family or exact full type. Examples: A10, H100, - GPU_1xA10, GPU_8xH100. + accelerator_type Accelerator family, display name, or full type. Examples: + A10, H100, 1xA10, 8xH100, GPU_1xA10, GPU_8xH100. experiment Case-insensitive glob matched against the experiment name. num_accelerators Total GPU count. user Run creator identifier.`, @@ -130,6 +130,15 @@ Filters: if err != nil { return err } + if f.AcceleratorType != "" { + options, err := listWorkspaceComputeOptions(ctx, w) + if err != nil { + return fmt.Errorf("failed to validate --filter accelerator_type=%q: %w", f.AcceleratorType, err) + } + if err := resolveAcceleratorFilter(&f, options); err != nil { + return err + } + } // An explicit user= filter wins; otherwise default to the current user // unless --all-users is set. runs/list has no creator param, so the diff --git a/cmd/air/list_filter.go b/cmd/air/list_filter.go index 435c6b63b81..a86b1218cbb 100644 --- a/cmd/air/list_filter.go +++ b/cmd/air/list_filter.go @@ -3,6 +3,7 @@ package aircmd import ( "fmt" "path" + "slices" "strconv" "strings" @@ -26,9 +27,14 @@ type listFilters struct { User string // Experiment is a case-insensitive glob Experiment string - // AcceleratorType is a case-insensitive exact match against either the full - // accelerator type or its display family (e.g. "GPU_8xH100" or "H100"). + // AcceleratorType is the user-provided family, display name, or full type. AcceleratorType string + // AcceleratorTypes are the workspace accelerator types resolved from + // AcceleratorType. A run matches when its type is in this list. + AcceleratorTypes []string + // AcceleratorCount is set when AcceleratorType uses the list table's display + // format (for example, "8x H100"). It is the run's total accelerator count. + AcceleratorCount *int // NumAccelerators is an exact match against the GPU count. NumAccelerators *int } @@ -52,9 +58,6 @@ func parseListFilters(raw []string) (listFilters, error) { } f.Experiment = value case "accelerator_type": - if !validAcceleratorFilter(value) { - return listFilters{}, fmt.Errorf("invalid --filter accelerator_type=%q: %s", value, validAcceleratorFilterHint()) - } f.AcceleratorType = value case "num_accelerators": n, err := strconv.Atoi(value) @@ -69,20 +72,84 @@ func parseListFilters(raw []string) (listFilters, error) { return f, nil } -// validAcceleratorFilter reports whether value is a full accelerator type or -// a short family name. Full types select one topology; short names match every -// topology in that family (for example, H100 matches both 1x and 8x H100). -func validAcceleratorFilter(value string) bool { - for _, gpuType := range gpuTypes { - if strings.EqualFold(value, string(gpuType)) || strings.EqualFold(value, gpuDisplayName(string(gpuType))) { - return true +// resolveAcceleratorFilter resolves a family, display name, or full type to the +// canonical accelerator types currently available in the workspace. +func resolveAcceleratorFilter(f *listFilters, options []computeOption) error { + if f.AcceleratorType == "" { + return nil + } + + // A full type selects one topology exactly. + for _, option := range options { + if strings.EqualFold(f.AcceleratorType, option.HardwareAccelerator) { + f.AcceleratorTypes = append(f.AcceleratorTypes, option.HardwareAccelerator) + return nil + } + } + + // A copied table value selects a family plus the displayed total count. + family := f.AcceleratorType + if count, displayFamily, ok := parseAcceleratorDisplay(f.AcceleratorType); ok { + f.AcceleratorCount = &count + family = displayFamily + } + for _, option := range options { + if strings.EqualFold(family, acceleratorFamily(option.HardwareAccelerator)) { + f.AcceleratorTypes = append(f.AcceleratorTypes, option.HardwareAccelerator) } } - return false + if len(f.AcceleratorTypes) == 0 { + return fmt.Errorf("invalid --filter accelerator_type=%q: %s", f.AcceleratorType, validAcceleratorFilterHint(options)) + } + return nil } -func validAcceleratorFilterHint() string { - return "use a family name (A10, H100, B300, RTX6000) or a full type; " + validGPUTypesHint() +// acceleratorFamily extracts the hardware family from a canonical type, so a +// future type such as GPU_4xA100 works without a client-side type list. +func acceleratorFamily(acceleratorType string) string { + prefix, family, ok := strings.Cut(strings.TrimPrefix(acceleratorType, "GPU_"), "x") + if ok { + if _, err := strconv.Atoi(prefix); err == nil && family != "" { + return family + } + } + return acceleratorType +} + +func parseAcceleratorDisplay(value string) (int, string, bool) { + compact := strings.ReplaceAll(strings.TrimSpace(value), " ", "") + countText, family, ok := strings.Cut(compact, "x") + if !ok || family == "" { + return 0, "", false + } + count, err := strconv.Atoi(countText) + if err != nil || count <= 0 { + return 0, "", false + } + return count, family, true +} + +func validAcceleratorFilterHint(options []computeOption) string { + var families, displays, fullTypes []string + for _, option := range options { + family := acceleratorFamily(option.HardwareAccelerator) + if !slices.ContainsFunc(families, func(v string) bool { return strings.EqualFold(v, family) }) { + families = append(families, family) + } + if option.DisplayName != "" && !slices.ContainsFunc(displays, func(v string) bool { return strings.EqualFold(v, option.DisplayName) }) { + displays = append(displays, option.DisplayName) + } + fullTypes = append(fullTypes, option.HardwareAccelerator) + } + if len(fullTypes) == 0 { + return "no accelerator types are available in this workspace" + } + parts := []string{"families (" + strings.Join(families, ", ") + ")"} + if len(displays) > 0 { + parts = append(parts, "display names ("+strings.Join(displays, ", ")+")") + } + parts = append(parts, "full types ("+strings.Join(fullTypes, ", ")+")") + return "valid values for this workspace include " + strings.Join(parts, ", ") } // filterFields are the task-filter inputs, cached alongside the row so a cache @@ -120,9 +187,10 @@ func (f listFilters) matchesFields(fields filterFields) bool { } if f.AcceleratorType != "" { - matchesFullType := strings.EqualFold(fields.GPUType, f.AcceleratorType) - matchesFamily := strings.EqualFold(gpuDisplayName(fields.GPUType), f.AcceleratorType) - if !matchesFullType && !matchesFamily { + if !slices.ContainsFunc(f.AcceleratorTypes, func(v string) bool { return strings.EqualFold(v, fields.GPUType) }) { + return false + } + if f.AcceleratorCount != nil && fields.GPUCount != *f.AcceleratorCount { return false } } diff --git a/cmd/air/list_filter_test.go b/cmd/air/list_filter_test.go index a98976ab4b7..9a4072df7a7 100644 --- a/cmd/air/list_filter_test.go +++ b/cmd/air/list_filter_test.go @@ -61,14 +61,8 @@ func TestParseListFilters(t *testing.T) { assert.Contains(t, err.Error(), "invalid glob pattern") }) - t.Run("unsupported accelerator type", func(t *testing.T) { - _, err := parseListFilters([]string{"accelerator_type=GPU_1xV100"}) - require.Error(t, err) - assert.Contains(t, err.Error(), "use a family name") - }) - - for _, acceleratorType := range []string{"GPU_1xA10", "GPU_1xH100", "GPU_8xH100"} { - t.Run("full accelerator type "+acceleratorType, func(t *testing.T) { + for _, acceleratorType := range []string{"1xA10", "8xH100", "GPU_1xA10", "GPU_1xH100", "GPU_8xH100"} { + t.Run("accelerator type "+acceleratorType, func(t *testing.T) { f, err := parseListFilters([]string{"accelerator_type=" + acceleratorType}) require.NoError(t, err) assert.Equal(t, acceleratorType, f.AcceleratorType) @@ -76,6 +70,54 @@ func TestParseListFilters(t *testing.T) { } } +func TestResolveAcceleratorFilter(t *testing.T) { + options := []computeOption{ + {HardwareAccelerator: "GPU_1xA10", DisplayName: "1x A10"}, + {HardwareAccelerator: "GPU_1xH100", DisplayName: "1x H100"}, + {HardwareAccelerator: "GPU_8xH100", DisplayName: "8x H100"}, + {HardwareAccelerator: "GPU_4xA100", DisplayName: "4x A100"}, + } + + cases := []struct { + name string + value string + wantTypes []string + wantCount *int + }{ + {"family", "H100", []string{"GPU_1xH100", "GPU_8xH100"}, nil}, + {"display name", "8x H100", []string{"GPU_1xH100", "GPU_8xH100"}, new(8)}, + {"compact display name", "8xH100", []string{"GPU_1xH100", "GPU_8xH100"}, new(8)}, + {"full type", "GPU_1xA10", []string{"GPU_1xA10"}, nil}, + {"future family", "A100", []string{"GPU_4xA100"}, nil}, + {"future full type", "GPU_4xA100", []string{"GPU_4xA100"}, nil}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + f := listFilters{AcceleratorType: tc.value} + require.NoError(t, resolveAcceleratorFilter(&f, options)) + assert.Equal(t, tc.wantTypes, f.AcceleratorTypes) + assert.Equal(t, tc.wantCount, f.AcceleratorCount) + }) + } + + t.Run("unsupported", func(t *testing.T) { + f := listFilters{AcceleratorType: "GPU_1xV100"} + err := resolveAcceleratorFilter(&f, options) + require.Error(t, err) + assert.Contains(t, err.Error(), "valid values for this workspace") + assert.Contains(t, err.Error(), "A10, H100, A100") + assert.Contains(t, err.Error(), "1x A10, 1x H100, 8x H100, 4x A100") + assert.Contains(t, err.Error(), "GPU_4xA100") + }) + + t.Run("no available types", func(t *testing.T) { + f := listFilters{AcceleratorType: "H100"} + err := resolveAcceleratorFilter(&f, nil) + require.Error(t, err) + assert.Contains(t, err.Error(), "no accelerator types are available") + }) +} + func TestListFiltersMatches(t *testing.T) { run := airRun(1, "me@example.com", "GPU_8xH100", 8, "/Users/me@example.com/qwen-eval") @@ -89,10 +131,12 @@ func TestListFiltersMatches(t *testing.T) { {"experiment suffix glob", listFilters{Experiment: "*-eval"}, true}, {"experiment case-insensitive", listFilters{Experiment: "QWEN*"}, true}, {"experiment no match", listFilters{Experiment: "llama*"}, false}, - {"accelerator family", listFilters{AcceleratorType: "h100"}, true}, - {"accelerator full type", listFilters{AcceleratorType: "gpu_8xh100"}, true}, - {"accelerator full type other topology", listFilters{AcceleratorType: "GPU_1xH100"}, false}, - {"accelerator type no match", listFilters{AcceleratorType: "a10"}, false}, + {"accelerator family", listFilters{AcceleratorType: "h100", AcceleratorTypes: []string{"GPU_1xH100", "GPU_8xH100"}}, true}, + {"accelerator display name", listFilters{AcceleratorType: "8x H100", AcceleratorTypes: []string{"GPU_1xH100", "GPU_8xH100"}, AcceleratorCount: new(8)}, true}, + {"accelerator display count no match", listFilters{AcceleratorType: "1x H100", AcceleratorTypes: []string{"GPU_1xH100", "GPU_8xH100"}, AcceleratorCount: new(1)}, false}, + {"accelerator full type", listFilters{AcceleratorType: "gpu_8xh100", AcceleratorTypes: []string{"GPU_8xH100"}}, true}, + {"accelerator full type other topology", listFilters{AcceleratorType: "GPU_1xH100", AcceleratorTypes: []string{"GPU_1xH100"}}, false}, + {"accelerator type no match", listFilters{AcceleratorType: "a10", AcceleratorTypes: []string{"GPU_1xA10"}}, false}, {"num accelerators match", listFilters{NumAccelerators: new(8)}, true}, {"num accelerators no match", listFilters{NumAccelerators: new(4)}, false}, } diff --git a/cmd/air/list_test.go b/cmd/air/list_test.go index a7700d162f0..99ded671fc6 100644 --- a/cmd/air/list_test.go +++ b/cmd/air/list_test.go @@ -252,3 +252,25 @@ func TestListInvalidFilter(t *testing.T) { require.Error(t, err) assert.Contains(t, err.Error(), "unsupported --filter key") } + +func TestListInvalidAcceleratorFilter(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/.well-known/databricks-config" { + _, _ = w.Write([]byte(`{}`)) + return + } + assert.Equal(t, computeOptionsPath, r.URL.Path) + _, _ = w.Write([]byte(`{"compute_options":[{"hardware_accelerator":"GPU_8xH100","display_name":"8x H100"}]}`)) + })) + t.Cleanup(srv.Close) + + ctx := cmdctx.SetWorkspaceClient(cmdio.MockDiscard(t.Context()), newTestWorkspaceClient(t, srv.URL)) + cmd := newListCommand() + cmd.SetContext(ctx) + require.NoError(t, cmd.Flags().Set("filter", "accelerator_type=GPU_1xV100")) + + err := cmd.RunE(cmd, nil) + require.Error(t, err) + assert.Contains(t, err.Error(), "valid values for this workspace") + assert.Contains(t, err.Error(), "GPU_8xH100") +} From b2b3c8012f8151e9132032a4797b52635a139b3e Mon Sep 17 00:00:00 2001 From: Caroline Chen <324939130+caroline-db@users.noreply.github.com> Date: Thu, 12 Nov 2026 22:23:14 +0000 Subject: [PATCH 4/4] air: preserve accelerator filter compatibility --- .nextchanges/air/list-filter-validation.md | 2 +- acceptance/air/help/output.txt | 5 +- cmd/air/list.go | 53 +++++++--- cmd/air/list_filter.go | 116 +++++++++++---------- cmd/air/list_filter_test.go | 93 ++++++++++------- cmd/air/list_test.go | 66 +++++++++++- 6 files changed, 222 insertions(+), 113 deletions(-) diff --git a/.nextchanges/air/list-filter-validation.md b/.nextchanges/air/list-filter-validation.md index 06f683bbdc6..4606ee66255 100644 --- a/.nextchanges/air/list-filter-validation.md +++ b/.nextchanges/air/list-filter-validation.md @@ -1 +1 @@ -* Support workspace accelerator families, display names, and full types in `air list` filters, and reject invalid filter values. ([#7515](https://github.com/databricks/cli/pull/7515)) +* Support full workspace accelerator types in `air list` filters while preserving family matching, and reject invalid filter values. ([#7515](https://github.com/databricks/cli/pull/7515)) diff --git a/acceptance/air/help/output.txt b/acceptance/air/help/output.txt index e51552e6938..f52e589f702 100644 --- a/acceptance/air/help/output.txt +++ b/acceptance/air/help/output.txt @@ -52,8 +52,9 @@ List active runs for the current user. Filters: Use --filter KEY=VALUE per condition. A run must match every condition. - accelerator_type Accelerator family, display name, or full type. Examples: - A10, H100, 1xA10, 8xH100, GPU_1xA10, GPU_8xH100. + accelerator_type Accelerator family or full YAML type. Examples: + A10, H100, GPU_1xA10, GPU_8xH100. + Workspace types: databricks air run -h config.compute.accelerator_type experiment Case-insensitive glob matched against the experiment name. num_accelerators Total GPU count. user Run creator identifier. diff --git a/cmd/air/list.go b/cmd/air/list.go index 10f6cd25f14..835292ed1ff 100644 --- a/cmd/air/list.go +++ b/cmd/air/list.go @@ -96,8 +96,9 @@ func newListCommand() *cobra.Command { Filters: Use --filter KEY=VALUE per condition. A run must match every condition. - accelerator_type Accelerator family, display name, or full type. Examples: - A10, H100, 1xA10, 8xH100, GPU_1xA10, GPU_8xH100. + accelerator_type Accelerator family or full YAML type. Examples: + A10, H100, GPU_1xA10, GPU_8xH100. + Workspace types: databricks air run -h config.compute.accelerator_type experiment Case-insensitive glob matched against the experiment name. num_accelerators Total GPU count. user Run creator identifier.`, @@ -131,13 +132,7 @@ Filters: return err } if f.AcceleratorType != "" { - options, err := listWorkspaceComputeOptions(ctx, w) - if err != nil { - return fmt.Errorf("failed to validate --filter accelerator_type=%q: %w", f.AcceleratorType, err) - } - if err := resolveAcceleratorFilter(&f, options); err != nil { - return err - } + configureAcceleratorFilter(&f) } // An explicit user= filter wins; otherwise default to the current user @@ -173,6 +168,11 @@ Filters: limit: limit, workspaceID: workspaceID, }) + if f.AcceleratorType != "" { + fetcher.validateEmpty = func() error { + return validateEmptyAcceleratorFilter(ctx, w, f.AcceleratorType) + } + } // JSON prints the newest `limit` runs once. Text renders the table: // navigable in a terminal (paging in older runs on demand), printed once @@ -191,6 +191,15 @@ Filters: return cmd } +func validateEmptyAcceleratorFilter(ctx context.Context, w *databricks.WorkspaceClient, value string) error { + options, err := listWorkspaceComputeOptions(ctx, w) + if err != nil { + log.Debugf(ctx, "air list: could not validate accelerator filter against workspace compute options: %v", err) + return fmt.Errorf("no runs matched --filter accelerator_type=%q\nRetry or run 'databricks air run -h config.compute.accelerator_type' to check available types", value) + } + return validateAcceleratorFilter(value, options) +} + // listStrategy is a source of matching runs, pulled in batches. Two implement it: // jobsScanStrategy pages runs/list; indexStrategy hydrates the AiTrainingService // index. The fetcher wraps whichever is chosen. @@ -207,13 +216,16 @@ type listStrategy interface { // the interactive table's lazy paging. It wraps a listStrategy and adds the // shared tail: MLflow enrichment (text only) and row projection. type runFetcher struct { - ctx context.Context - w *databricks.WorkspaceClient - fetchMLflow bool - strategy listStrategy - workspaceID int64 - - exhausted bool + ctx context.Context + w *databricks.WorkspaceClient + fetchMLflow bool + strategy listStrategy + workspaceID int64 + validateEmpty func() error + + exhausted bool + matchedAny bool + validatedEmpty bool } func newRunFetcher(ctx context.Context, w *databricks.WorkspaceClient, q listQuery) *runFetcher { @@ -253,6 +265,15 @@ func (f *runFetcher) next(want int) ([]listRow, error) { return nil, err } f.exhausted = f.strategy.done() + if len(entries) > 0 { + f.matchedAny = true + } + if len(entries) == 0 && f.exhausted && !f.matchedAny && f.validateEmpty != nil && !f.validatedEmpty { + f.validatedEmpty = true + if err := f.validateEmpty(); err != nil { + return nil, err + } + } // MLflow links appear only in the text table, so the per-run get-output // lookups are skipped for JSON output (which omits the column anyway). diff --git a/cmd/air/list_filter.go b/cmd/air/list_filter.go index a86b1218cbb..9b5df111098 100644 --- a/cmd/air/list_filter.go +++ b/cmd/air/list_filter.go @@ -27,14 +27,14 @@ type listFilters struct { User string // Experiment is a case-insensitive glob Experiment string - // AcceleratorType is the user-provided family, display name, or full type. + // AcceleratorType is the user-provided family or full type. AcceleratorType string - // AcceleratorTypes are the workspace accelerator types resolved from - // AcceleratorType. A run matches when its type is in this list. - AcceleratorTypes []string - // AcceleratorCount is set when AcceleratorType uses the list table's display - // format (for example, "8x H100"). It is the run's total accelerator count. - AcceleratorCount *int + // ResolvedAcceleratorType is the canonical-looking user input used for an + // exact full-type match against runs. + ResolvedAcceleratorType string + // AcceleratorFamilyMatch preserves the legacy case-insensitive substring + // match against the display GPU family. + AcceleratorFamilyMatch bool // NumAccelerators is an exact match against the GPU count. NumAccelerators *int } @@ -46,8 +46,12 @@ func parseListFilters(raw []string) (listFilters, error) { if !ok || key == "" { return listFilters{}, fmt.Errorf("invalid --filter %q: expected KEY=VALUE", item) } - if strings.TrimSpace(value) == "" { - return listFilters{}, fmt.Errorf("invalid --filter %s: value cannot be empty", key) + if !slices.Contains(supportedFilterKeys, key) { + return listFilters{}, fmt.Errorf("unsupported --filter key %q: supported keys are %s", key, strings.Join(supportedFilterKeys, ", ")) + } + value = strings.TrimSpace(value) + if value == "" { + return listFilters{}, fmt.Errorf("invalid --filter %s=%q: value cannot be empty", key, value) } switch key { case "user": @@ -65,49 +69,48 @@ func parseListFilters(raw []string) (listFilters, error) { return listFilters{}, fmt.Errorf("invalid --filter num_accelerators=%q: must be a positive integer", value) } f.NumAccelerators = &n - default: - return listFilters{}, fmt.Errorf("unsupported --filter key %q: supported keys are %s", key, strings.Join(supportedFilterKeys, ", ")) } } return f, nil } -// resolveAcceleratorFilter resolves a family, display name, or full type to the -// canonical accelerator types currently available in the workspace. -func resolveAcceleratorFilter(f *listFilters, options []computeOption) error { - if f.AcceleratorType == "" { - return nil +// configureAcceleratorFilter selects exact full-type matching for YAML-style +// values and preserves legacy family substring matching for everything else. +func configureAcceleratorFilter(f *listFilters) { + if strings.HasPrefix(strings.ToUpper(f.AcceleratorType), "GPU_") { + f.ResolvedAcceleratorType = f.AcceleratorType + return } + f.AcceleratorFamilyMatch = true +} - // A full type selects one topology exactly. +// validateAcceleratorFilter checks a filter that produced no runs against the +// accelerator types currently available in the workspace. +func validateAcceleratorFilter(value string, options []computeOption) error { for _, option := range options { - if strings.EqualFold(f.AcceleratorType, option.HardwareAccelerator) { - f.AcceleratorTypes = append(f.AcceleratorTypes, option.HardwareAccelerator) + if strings.EqualFold(value, option.HardwareAccelerator) { return nil } } - // A copied table value selects a family plus the displayed total count. - family := f.AcceleratorType - if count, displayFamily, ok := parseAcceleratorDisplay(f.AcceleratorType); ok { - f.AcceleratorCount = &count - family = displayFamily - } - for _, option := range options { - if strings.EqualFold(family, acceleratorFamily(option.HardwareAccelerator)) { - f.AcceleratorTypes = append(f.AcceleratorTypes, option.HardwareAccelerator) + if !strings.HasPrefix(strings.ToUpper(value), "GPU_") { + for _, option := range options { + family := acceleratorFamily(option.HardwareAccelerator) + if strings.Contains(strings.ToLower(family), strings.ToLower(value)) { + return nil + } } } - if len(f.AcceleratorTypes) == 0 { - return fmt.Errorf("invalid --filter accelerator_type=%q: %s", f.AcceleratorType, validAcceleratorFilterHint(options)) + if fullType := suggestedAcceleratorType(value, options); fullType != "" { + return fmt.Errorf("invalid --filter accelerator_type=%q: use %q", value, fullType) } - return nil + return fmt.Errorf("invalid --filter accelerator_type=%q: %s", value, validAcceleratorFilterHint(options)) } -// acceleratorFamily extracts the hardware family from a canonical type, so a -// future type such as GPU_4xA100 works without a client-side type list. +// acceleratorFamily extracts the hardware family from a canonical type without +// a client-side type list. func acceleratorFamily(acceleratorType string) string { - prefix, family, ok := strings.Cut(strings.TrimPrefix(acceleratorType, "GPU_"), "x") + prefix, family, ok := strings.Cut(acceleratorShorthand(acceleratorType), "x") if ok { if _, err := strconv.Atoi(prefix); err == nil && family != "" { return family @@ -116,38 +119,41 @@ func acceleratorFamily(acceleratorType string) string { return acceleratorType } -func parseAcceleratorDisplay(value string) (int, string, bool) { - compact := strings.ReplaceAll(strings.TrimSpace(value), " ", "") - countText, family, ok := strings.Cut(compact, "x") - if !ok || family == "" { - return 0, "", false +func acceleratorShorthand(acceleratorType string) string { + return strings.TrimPrefix(acceleratorType, "GPU_") +} + +func acceleratorRunFamily(acceleratorType string) string { + family := acceleratorFamily(acceleratorType) + if family != acceleratorType { + return family } - count, err := strconv.Atoi(countText) - if err != nil || count <= 0 { - return 0, "", false + return gpuDisplayName(acceleratorType) +} + +func suggestedAcceleratorType(value string, options []computeOption) string { + compact := strings.Join(strings.Fields(value), "") + for _, option := range options { + if strings.EqualFold(compact, acceleratorShorthand(option.HardwareAccelerator)) { + return option.HardwareAccelerator + } } - return count, family, true + return "" } func validAcceleratorFilterHint(options []computeOption) string { - var families, displays, fullTypes []string + var families, fullTypes []string for _, option := range options { family := acceleratorFamily(option.HardwareAccelerator) if !slices.ContainsFunc(families, func(v string) bool { return strings.EqualFold(v, family) }) { families = append(families, family) } - if option.DisplayName != "" && !slices.ContainsFunc(displays, func(v string) bool { return strings.EqualFold(v, option.DisplayName) }) { - displays = append(displays, option.DisplayName) - } fullTypes = append(fullTypes, option.HardwareAccelerator) } if len(fullTypes) == 0 { return "no accelerator types are available in this workspace" } parts := []string{"families (" + strings.Join(families, ", ") + ")"} - if len(displays) > 0 { - parts = append(parts, "display names ("+strings.Join(displays, ", ")+")") - } parts = append(parts, "full types ("+strings.Join(fullTypes, ", ")+")") return "valid values for this workspace include " + strings.Join(parts, ", ") } @@ -187,10 +193,12 @@ func (f listFilters) matchesFields(fields filterFields) bool { } if f.AcceleratorType != "" { - if !slices.ContainsFunc(f.AcceleratorTypes, func(v string) bool { return strings.EqualFold(v, fields.GPUType) }) { - return false - } - if f.AcceleratorCount != nil && fields.GPUCount != *f.AcceleratorCount { + if f.AcceleratorFamilyMatch { + family := strings.ToLower(acceleratorRunFamily(fields.GPUType)) + if !strings.Contains(family, strings.ToLower(f.AcceleratorType)) { + return false + } + } else if !strings.EqualFold(f.ResolvedAcceleratorType, fields.GPUType) { return false } } diff --git a/cmd/air/list_filter_test.go b/cmd/air/list_filter_test.go index 9a4072df7a7..6369b48b685 100644 --- a/cmd/air/list_filter_test.go +++ b/cmd/air/list_filter_test.go @@ -1,6 +1,8 @@ package aircmd import ( + "fmt" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -29,6 +31,12 @@ func TestParseListFilters(t *testing.T) { assert.Contains(t, err.Error(), "unsupported --filter key") }) + t.Run("unknown key with empty value", func(t *testing.T) { + _, err := parseListFilters([]string{"acclerator_type="}) + require.Error(t, err) + assert.Contains(t, err.Error(), "unsupported --filter key") + }) + t.Run("malformed pair", func(t *testing.T) { _, err := parseListFilters([]string{"experiment"}) require.Error(t, err) @@ -50,11 +58,20 @@ func TestParseListFilters(t *testing.T) { for _, filter := range []string{"user=", "experiment=", "accelerator_type=", "num_accelerators="} { t.Run("empty "+filter, func(t *testing.T) { _, err := parseListFilters([]string{filter}) - require.Error(t, err) - assert.Contains(t, err.Error(), "value cannot be empty") + key, _, _ := strings.Cut(filter, "=") + require.EqualError(t, err, fmt.Sprintf("invalid --filter %s=%q: value cannot be empty", key, "")) }) } + t.Run("trim values", func(t *testing.T) { + f, err := parseListFilters([]string{"user= me@example.com ", "experiment= qwen* ", "num_accelerators= 8 "}) + require.NoError(t, err) + assert.Equal(t, "me@example.com", f.User) + assert.Equal(t, "qwen*", f.Experiment) + require.NotNil(t, f.NumAccelerators) + assert.Equal(t, 8, *f.NumAccelerators) + }) + t.Run("malformed experiment glob", func(t *testing.T) { _, err := parseListFilters([]string{"experiment=["}) require.Error(t, err) @@ -70,54 +87,56 @@ func TestParseListFilters(t *testing.T) { } } -func TestResolveAcceleratorFilter(t *testing.T) { +func TestValidateAcceleratorFilter(t *testing.T) { options := []computeOption{ {HardwareAccelerator: "GPU_1xA10", DisplayName: "1x A10"}, {HardwareAccelerator: "GPU_1xH100", DisplayName: "1x H100"}, {HardwareAccelerator: "GPU_8xH100", DisplayName: "8x H100"}, - {HardwareAccelerator: "GPU_4xA100", DisplayName: "4x A100"}, + {HardwareAccelerator: "GPU_8xB300", DisplayName: "8x B300"}, } - cases := []struct { - name string - value string - wantTypes []string - wantCount *int - }{ - {"family", "H100", []string{"GPU_1xH100", "GPU_8xH100"}, nil}, - {"display name", "8x H100", []string{"GPU_1xH100", "GPU_8xH100"}, new(8)}, - {"compact display name", "8xH100", []string{"GPU_1xH100", "GPU_8xH100"}, new(8)}, - {"full type", "GPU_1xA10", []string{"GPU_1xA10"}, nil}, - {"future family", "A100", []string{"GPU_4xA100"}, nil}, - {"future full type", "GPU_4xA100", []string{"GPU_4xA100"}, nil}, + for _, value := range []string{"H100", "GPU_1xA10", "B300"} { + t.Run("valid "+value, func(t *testing.T) { + require.NoError(t, validateAcceleratorFilter(value, options)) + }) } - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - f := listFilters{AcceleratorType: tc.value} - require.NoError(t, resolveAcceleratorFilter(&f, options)) - assert.Equal(t, tc.wantTypes, f.AcceleratorTypes) - assert.Equal(t, tc.wantCount, f.AcceleratorCount) + + for value, fullType := range map[string]string{ + "1xA10": "GPU_1xA10", + "1x A10": "GPU_1xA10", + "1xH100": "GPU_1xH100", + "1x H100": "GPU_1xH100", + "8xH100": "GPU_8xH100", + "8x H100": "GPU_8xH100", + "8x B300": "GPU_8xB300", + } { + t.Run("suggest full type for "+value, func(t *testing.T) { + err := validateAcceleratorFilter(value, options) + require.EqualError(t, err, fmt.Sprintf("invalid --filter accelerator_type=%q: use %q", value, fullType)) }) } t.Run("unsupported", func(t *testing.T) { - f := listFilters{AcceleratorType: "GPU_1xV100"} - err := resolveAcceleratorFilter(&f, options) + err := validateAcceleratorFilter("GPU_1xV100", options) require.Error(t, err) assert.Contains(t, err.Error(), "valid values for this workspace") - assert.Contains(t, err.Error(), "A10, H100, A100") - assert.Contains(t, err.Error(), "1x A10, 1x H100, 8x H100, 4x A100") - assert.Contains(t, err.Error(), "GPU_4xA100") + assert.Contains(t, err.Error(), "A10, H100, B300") + assert.Contains(t, err.Error(), "GPU_8xB300") }) t.Run("no available types", func(t *testing.T) { - f := listFilters{AcceleratorType: "H100"} - err := resolveAcceleratorFilter(&f, nil) + err := validateAcceleratorFilter("H100", nil) require.Error(t, err) assert.Contains(t, err.Error(), "no accelerator types are available") }) } +func TestLegacyAcceleratorSubstring(t *testing.T) { + f := listFilters{AcceleratorType: "H1"} + configureAcceleratorFilter(&f) + assert.True(t, f.matchesFields(filterFields{GPUType: "h100_80gb"})) +} + func TestListFiltersMatches(t *testing.T) { run := airRun(1, "me@example.com", "GPU_8xH100", 8, "/Users/me@example.com/qwen-eval") @@ -131,12 +150,10 @@ func TestListFiltersMatches(t *testing.T) { {"experiment suffix glob", listFilters{Experiment: "*-eval"}, true}, {"experiment case-insensitive", listFilters{Experiment: "QWEN*"}, true}, {"experiment no match", listFilters{Experiment: "llama*"}, false}, - {"accelerator family", listFilters{AcceleratorType: "h100", AcceleratorTypes: []string{"GPU_1xH100", "GPU_8xH100"}}, true}, - {"accelerator display name", listFilters{AcceleratorType: "8x H100", AcceleratorTypes: []string{"GPU_1xH100", "GPU_8xH100"}, AcceleratorCount: new(8)}, true}, - {"accelerator display count no match", listFilters{AcceleratorType: "1x H100", AcceleratorTypes: []string{"GPU_1xH100", "GPU_8xH100"}, AcceleratorCount: new(1)}, false}, - {"accelerator full type", listFilters{AcceleratorType: "gpu_8xh100", AcceleratorTypes: []string{"GPU_8xH100"}}, true}, - {"accelerator full type other topology", listFilters{AcceleratorType: "GPU_1xH100", AcceleratorTypes: []string{"GPU_1xH100"}}, false}, - {"accelerator type no match", listFilters{AcceleratorType: "a10", AcceleratorTypes: []string{"GPU_1xA10"}}, false}, + {"accelerator family", listFilters{AcceleratorType: "h100", AcceleratorFamilyMatch: true}, true}, + {"accelerator full type", listFilters{AcceleratorType: "gpu_8xh100", ResolvedAcceleratorType: "GPU_8xH100"}, true}, + {"accelerator full type other topology", listFilters{AcceleratorType: "GPU_1xH100", ResolvedAcceleratorType: "GPU_1xH100"}, false}, + {"accelerator type no match", listFilters{AcceleratorType: "GPU_1xA10", ResolvedAcceleratorType: "GPU_1xA10"}, false}, {"num accelerators match", listFilters{NumAccelerators: new(8)}, true}, {"num accelerators no match", listFilters{NumAccelerators: new(4)}, false}, } @@ -145,4 +162,10 @@ func TestListFiltersMatches(t *testing.T) { assert.Equal(t, c.want, c.f.matches(&run)) }) } + + t.Run("canonical type uses derived family", func(t *testing.T) { + fields := filterFields{GPUType: "GPU_8xB300"} + assert.True(t, (listFilters{AcceleratorType: "B300", AcceleratorFamilyMatch: true}).matchesFields(fields)) + assert.False(t, (listFilters{AcceleratorType: "8xB300", AcceleratorFamilyMatch: true}).matchesFields(fields)) + }) } diff --git a/cmd/air/list_test.go b/cmd/air/list_test.go index 99ded671fc6..0928769393d 100644 --- a/cmd/air/list_test.go +++ b/cmd/air/list_test.go @@ -9,6 +9,7 @@ import ( "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/flags" "github.com/databricks/databricks-sdk-go/experimental/mocks" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/stretchr/testify/assert" @@ -137,6 +138,10 @@ func TestRunFetcherResumesAcrossCalls(t *testing.T) { } srv := runsServer(t, runsListBody(t, "", runs...)) f := newRunFetcher(t.Context(), newTestWorkspaceClient(t, srv.URL), listQuery{activeOnly: true}) + f.validateEmpty = func() error { + t.Fatal("validation should not run after an earlier page matched") + return nil + } first, err := f.next(2) require.NoError(t, err) @@ -254,23 +259,74 @@ func TestListInvalidFilter(t *testing.T) { } func TestListInvalidAcceleratorFilter(t *testing.T) { + jobsCalled := false srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/.well-known/databricks-config" { + switch r.URL.Path { + case "/.well-known/databricks-config": + _, _ = w.Write([]byte(`{}`)) + case "/api/2.2/jobs/runs/list": + jobsCalled = true + _, _ = w.Write([]byte(runsListBody(t, ""))) + case computeOptionsPath: + _, _ = w.Write([]byte(`{"compute_options":[{"hardware_accelerator":"GPU_8xH100","display_name":"8x H100"}]}`)) + default: _, _ = w.Write([]byte(`{}`)) - return } - assert.Equal(t, computeOptionsPath, r.URL.Path) - _, _ = w.Write([]byte(`{"compute_options":[{"hardware_accelerator":"GPU_8xH100","display_name":"8x H100"}]}`)) })) t.Cleanup(srv.Close) ctx := cmdctx.SetWorkspaceClient(cmdio.MockDiscard(t.Context()), newTestWorkspaceClient(t, srv.URL)) - cmd := newListCommand() + cmd := withOutput(newListCommand(), flags.OutputText) cmd.SetContext(ctx) + require.NoError(t, cmd.Flags().Set("all-users", "true")) require.NoError(t, cmd.Flags().Set("filter", "accelerator_type=GPU_1xV100")) err := cmd.RunE(cmd, nil) require.Error(t, err) assert.Contains(t, err.Error(), "valid values for this workspace") assert.Contains(t, err.Error(), "GPU_8xH100") + assert.True(t, jobsCalled) +} + +func TestListValidatesAcceleratorOnlyAfterNoMatches(t *testing.T) { + for _, tc := range []struct { + name string + runs string + wantErr bool + }{ + {"matching run", runsListBody(t, "", airBaseRun(1, "me@example.com", "GPU_1xA10", 1, "exp")), false}, + {"no matching run", runsListBody(t, ""), true}, + } { + t.Run(tc.name, func(t *testing.T) { + computeOptionsCalled := false + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case computeOptionsPath: + computeOptionsCalled = true + http.Error(w, "unavailable", http.StatusNotFound) + case "/api/2.2/jobs/runs/list": + _, _ = w.Write([]byte(tc.runs)) + default: + _, _ = w.Write([]byte(`{}`)) + } + })) + t.Cleanup(srv.Close) + + ctx := cmdctx.SetWorkspaceClient(cmdio.MockDiscard(t.Context()), newTestWorkspaceClient(t, srv.URL)) + cmd := withOutput(newListCommand(), flags.OutputJSON) + cmd.SetContext(ctx) + require.NoError(t, cmd.Flags().Set("all-users", "true")) + require.NoError(t, cmd.Flags().Set("filter", "accelerator_type=A10")) + + err := cmd.RunE(cmd, nil) + if tc.wantErr { + require.Error(t, err) + assert.Equal(t, "no runs matched --filter accelerator_type=\"A10\"\nRetry or run 'databricks air run -h config.compute.accelerator_type' to check available types", err.Error()) + assert.True(t, computeOptionsCalled) + } else { + require.NoError(t, err) + assert.False(t, computeOptionsCalled) + } + }) + } }