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
3 changes: 3 additions & 0 deletions internal/cli/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func newChatCmd(cfg *globalConfig, deps deps) *cobra.Command {
if !deps.isTerminal() {
return clierr.Usage("chat needs a terminal; use send to send a single message")
}
if err := rejectEmptyIDs(cmd); err != nil {
return err
}

baseCtx := withServiceParams(cmd.Context(), cfg)
var client *a2aclient.Client
Expand Down
18 changes: 18 additions & 0 deletions internal/cli/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,24 @@ func TestChatWithoutATerminalIsAUsageError(t *testing.T) {
}
}

func TestChatWithAnEmptyIDIsAUsageError(t *testing.T) {
t.Parallel()
for _, flag := range []string{"--task-id", "--context-id"} {
t.Run(flag, func(t *testing.T) {
t.Parallel()
agent, url := startChatAgent(t)

_, _, err := runChat(t, url, true, "", flag, "", "one")
if ce := clierr.Classify(err); ce == nil || ce.Code != clierr.CodeUsage {
t.Fatalf("a2a chat %s \"\" error = %v, want a usage error", flag, err)
}
if got := len(agent.requests); got != 0 {
t.Fatalf("a2a chat %s \"\" sent %d messages, want 0", flag, got)
}
})
}
}

func TestChatResumesATask(t *testing.T) {
t.Parallel()
agent, url := startChatAgent(t, a2a.TaskStateInputRequired, a2a.TaskStateCompleted)
Expand Down
2 changes: 2 additions & 0 deletions internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ func TestUsageErrors(t *testing.T) {
{"--endpoint with two --transport", []string{"send", "-e", "http://x", "--transport", "rest", "--transport", "grpc", "hi"}},
{"empty --transport", []string{"send", "-a", "http://x", "--transport", "", "hi"}},
{"unknown --a2a-version", []string{"send", "-a", "http://x", "--a2a-version", "1", "hi"}},
{"empty send --task-id", []string{"send", "-a", "http://x", "--task-id", "", "hi"}},
{"empty send --context-id", []string{"send", "-a", "http://x", "--context-id", "", "hi"}},
{"unknown server --protocol", []string{"server", "--echo", "--port", "0", "--protocol", "bogus"}},
{"unknown server --serve-transport", []string{"server", "--echo", "--port", "0", "--serve-transport", "bogus"}},
{"missing server --card file", []string{"server", "--echo", "--port", "0", "--card", "/no/such/card.json"}},
Expand Down
14 changes: 14 additions & 0 deletions internal/cli/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func newSendCmd(cfg *globalConfig, poller pollerFunc) *cobra.Command {
a2a send -a https://agent.example.com --data-part '{"priority":"high"}' "Triage"`,
Args: cobra.ArbitraryArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if err := rejectEmptyIDs(cmd); err != nil {
return err
}
if flags.stream && flags.async {
return clierr.Usage("--stream is incompatible with --async")
}
Expand Down Expand Up @@ -235,6 +238,17 @@ func parseRequestPayload(ref string) (*a2a.SendMessageRequest, error) {
return req, nil
}

// rejectEmptyIDs fails on an empty --task-id or --context-id, which usually
// comes from an unset shell variable, instead of starting a new task.
func rejectEmptyIDs(cmd *cobra.Command) error {
for _, name := range []string{"task-id", "context-id"} {
if f := cmd.Flags().Lookup(name); f.Changed && f.Value.String() == "" {
return clierr.Usage(fmt.Sprintf("empty --%s value", name))
}
}
return nil
}

// ensureNoPayloadOverrides rejects flags and positional arguments that would
// conflict with a --request-payload, which already carries the whole request.
func ensureNoPayloadOverrides(cmd *cobra.Command, positional []string) error {
Expand Down
Loading