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
69 changes: 69 additions & 0 deletions cmd/artifact/cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2026 DataRobot, Inc. and its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package artifact

import (
"testing"

"github.com/datarobot/cli/internal/cli"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// findChild returns the named direct subcommand, or nil.
func findChild(cmd *cobra.Command, name string) *cobra.Command {
for _, sub := range cmd.Commands() {
if sub.Name() == name {
return sub
}
}

return nil
}

// TestCmd_WorkloadGateHidesDoctor pins the gate-off behavior: without
// DATAROBOT_CLI_FEATURE_WORKLOAD the whole artifact tree (doctor included) is
// filtered out at registration time; with it, doctor is discoverable under
// `artifact code`.
func TestCmd_WorkloadGateHidesDoctor(t *testing.T) {
t.Setenv("DATAROBOT_CLI_FEATURE_WORKLOAD", "")

gatedRoot := &cli.CommandAdder{Command: &cobra.Command{Use: "root"}}
gatedRoot.AddCommand(Cmd())

assert.Nil(t, findChild(gatedRoot.Command, "artifact"),
"gate off: the artifact tree (and doctor with it) is not registered")

t.Setenv("DATAROBOT_CLI_FEATURE_WORKLOAD", "true")

openRoot := &cli.CommandAdder{Command: &cobra.Command{Use: "root"}}
openRoot.AddCommand(Cmd())

artifactCmd := findChild(openRoot.Command, "artifact")

require.NotNil(t, artifactCmd, "gate on: artifact registered")

codeCmd := findChild(artifactCmd, "code")

require.NotNil(t, codeCmd, "gate on: artifact code registered")

doctorCmd := findChild(codeCmd, "doctor")

require.NotNil(t, doctorCmd, "gate on: doctor inherits the artifact tree's gate")

assert.Empty(t, doctorCmd.Annotations["feature-gate"],
"doctor needs no gate of its own; the parent carries it")
}
4 changes: 4 additions & 0 deletions cmd/artifact/code/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package code
import (
"github.com/datarobot/cli/cmd/artifact/code/checkout"
"github.com/datarobot/cli/cmd/artifact/code/codesync"
doctorcmd "github.com/datarobot/cli/cmd/artifact/code/doctor"
initcmd "github.com/datarobot/cli/cmd/artifact/code/init"
"github.com/datarobot/cli/cmd/artifact/code/versions"
"github.com/spf13/cobra"
Expand All @@ -42,6 +43,8 @@ Subcommands:
versions List catalog versions for the linked artifact.
checkout Download a prior version into
'.datarobot/workload/.checkouts/' for read-only inspection.
doctor Diagnose the sync state of a project directory (read-only) and
suggest remedies for anything broken.

Artifacts must already exist before running 'init'. Create them via
'dr artifact create' or in the DataRobot UI — these commands
Expand All @@ -58,6 +61,7 @@ Example:
cmd.AddCommand(codesync.Cmd())
cmd.AddCommand(versions.Cmd())
cmd.AddCommand(checkout.Cmd())
cmd.AddCommand(doctorcmd.Cmd())

return cmd
}
33 changes: 33 additions & 0 deletions cmd/artifact/code/cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2026 DataRobot, Inc. and its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package code

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCmd_RegistersDoctor(t *testing.T) {
c := Cmd()

names := make([]string, 0, len(c.Commands()))

for _, sub := range c.Commands() {
names = append(names, sub.Name())
}

assert.Contains(t, names, "doctor", "doctor is registered alongside init/sync/versions/checkout")
}
Loading
Loading