@@ -2,11 +2,14 @@ package aircmd
22
33import (
44 "fmt"
5+ "net/http"
6+ "net/http/httptest"
57 "os"
68 "path/filepath"
79 "strings"
810 "testing"
911
12+ "github.com/databricks/cli/libs/cmdctx"
1013 "github.com/stretchr/testify/assert"
1114 "github.com/stretchr/testify/require"
1215)
@@ -756,6 +759,82 @@ func TestWriteConfigFieldHelp(t *testing.T) {
756759 require .Error (t , writeConfigFieldHelp (& strings.Builder {}, "config.nope" ))
757760}
758761
762+ func TestRunCommandHelpComputeOptions (t * testing.T ) {
763+ builtInOptions := ` GPU_1xA10 - 1 accelerator per node
764+ GPU_1xH100 - 1 accelerator per node
765+ GPU_8xH100 - 8 accelerators per node
766+ GPU_8xB300 - 8 accelerators per node`
767+ tests := []struct {
768+ name string
769+ statusCode int
770+ response string
771+ wantOptions string
772+ wantWarning bool
773+ }{
774+ {
775+ name : "workspace subset" ,
776+ response : `{"compute_options":[{"hardware_accelerator":"GPU_8xH100","per_node_accelerator_count":4,"launch_stage":"PUBLIC_PREVIEW"},{"hardware_accelerator":"GPU_UNKNOWN"},{"hardware_accelerator":"GPU_1xA10"}]}` ,
777+ wantOptions : " GPU_8xH100 - 4 accelerators per node [Public Preview]\n GPU_1xA10 - 1 accelerator per node" ,
778+ },
779+ {
780+ name : "empty response falls back" ,
781+ response : `{}` ,
782+ wantOptions : builtInOptions ,
783+ wantWarning : true ,
784+ },
785+ {
786+ name : "disabled endpoint falls back" ,
787+ statusCode : http .StatusBadRequest ,
788+ response : `{"error_code":"FEATURE_DISABLED","message":"ListComputeOptions is not yet enabled."}` ,
789+ wantOptions : builtInOptions ,
790+ },
791+ {
792+ name : "missing endpoint falls back" ,
793+ statusCode : http .StatusNotFound ,
794+ response : `{"error_code":"ENDPOINT_NOT_FOUND","message":"Not found."}` ,
795+ wantOptions : builtInOptions ,
796+ },
797+ {
798+ name : "unexpected API error warns and falls back" ,
799+ statusCode : http .StatusInternalServerError ,
800+ response : `{"error_code":"INTERNAL_ERROR","message":"Internal error."}` ,
801+ wantOptions : builtInOptions ,
802+ wantWarning : true ,
803+ },
804+ }
805+
806+ for _ , tt := range tests {
807+ t .Run (tt .name , func (t * testing.T ) {
808+ srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
809+ if tt .statusCode != 0 {
810+ w .WriteHeader (tt .statusCode )
811+ }
812+ _ , _ = w .Write ([]byte (tt .response ))
813+ }))
814+ t .Cleanup (srv .Close )
815+
816+ var out , errOut strings.Builder
817+ cmd := newRunCommand ()
818+ cmd .SetContext (cmdctx .SetWorkspaceClient (t .Context (), newTestWorkspaceClient (t , srv .URL )))
819+ cmd .SetOut (& out )
820+ cmd .SetErr (& errOut )
821+ cmd .SetArgs ([]string {"-h" , "config.compute" })
822+ require .NoError (t , cmd .Execute ())
823+
824+ options , found := strings .CutPrefix (out .String (), "config.compute\n Which accelerators to run on and how many.\n \n Supported accelerator types:\n " )
825+ require .True (t , found )
826+ options , _ , found = strings .Cut (options , "\n \n Fields:" )
827+ require .True (t , found )
828+ assert .Equal (t , tt .wantOptions , options )
829+ if tt .wantWarning {
830+ assert .Contains (t , errOut .String (), "showing the built-in list" )
831+ } else {
832+ assert .Empty (t , errOut .String ())
833+ }
834+ })
835+ }
836+ }
837+
759838// Guards against adding a schema field without a help: tag.
760839func TestConfigFieldsAllDocumented (t * testing.T ) {
761840 root , err := resolveConfigField ("config" )
0 commit comments