Skip to content
Merged
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
62 changes: 0 additions & 62 deletions pkg/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"testing"
"time"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -539,67 +538,6 @@ func TestTrackServerStart(t *testing.T) {
assert.True(t, executed)
}

// TestBuildCommandInfo tests the BuildCommandInfo function with all commands
func TestBuildCommandInfo(t *testing.T) {
testCases := []struct {
name string
command string
args []string
expected CommandInfo
}{
{
name: "run command with config",
command: "run",
args: []string{"config.yaml", "--debug"},
expected: CommandInfo{
Action: "run",
Args: []string{"config.yaml"},
Flags: []string{},
},
},
{
name: "pull command with image",
command: "pull",
args: []string{"user/agent:latest"},
expected: CommandInfo{
Action: "pull",
Args: []string{"user/agent:latest"},
Flags: []string{},
},
},
{
name: "catalog command",
command: "catalog",
args: []string{},
expected: CommandInfo{
Action: "catalog",
Args: []string{},
Flags: []string{},
},
},
{
name: "version command",
command: "version",
args: []string{},
expected: CommandInfo{
Action: "version",
Args: []string{},
Flags: []string{},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmd := &cobra.Command{Use: tc.command}
result := BuildCommandInfo(cmd, tc.args, tc.command)

assert.Equal(t, tc.expected.Action, result.Action)
assert.Equal(t, tc.expected.Args, result.Args)
})
}
}

// TestGlobalTelemetryFunctions tests the global telemetry convenience functions
func TestGlobalTelemetryFunctions(t *testing.T) {
// Save original global state
Expand Down
52 changes: 0 additions & 52 deletions pkg/telemetry/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

"github.com/google/uuid"
"github.com/spf13/cobra"

"github.com/docker/cagent/pkg/paths"
)
Expand Down Expand Up @@ -100,54 +99,3 @@ type CommandInfo struct {
Args []string
Flags []string
}

// BuildCommandInfo extracts detailed command information for telemetry
func BuildCommandInfo(cmd *cobra.Command, args []string, baseName string) CommandInfo {
info := CommandInfo{
Action: baseName,
Args: []string{},
Flags: []string{},
}

// Only capture arguments for specific commands where they provide valuable context
shouldCaptureArgs := baseName == "run" || baseName == "pull" || baseName == "catalog"

if shouldCaptureArgs {
// Add subcommands from args (first non-flag arguments)
for _, arg := range args {
if !strings.HasPrefix(arg, "-") {
info.Args = append(info.Args, arg)
} else {
// Stop at first flag
break
}
}
}

// Add important flags that provide context
if cmd.Flags() != nil {
// Check for help flag
if help, _ := cmd.Flags().GetBool("help"); help {
info.Flags = append(info.Flags, "--help")
}

// Check for version flag (if it exists)
if cmd.Flags().Lookup("version") != nil {
if version, _ := cmd.Flags().GetBool("version"); version {
info.Flags = append(info.Flags, "--version")
}
}

// Check for other commonly used flags (more relevant for run/pull commands)
if shouldCaptureArgs {
flagsToCheck := []string{"config", "agent", "model", "output", "format", "yolo"}
for _, flagName := range flagsToCheck {
if flag := cmd.Flags().Lookup(flagName); flag != nil && flag.Changed {
info.Flags = append(info.Flags, "--"+flagName)
}
}
}
}

return info
}