From 4be63695847a4e608d6bdd2b351988d9d192f763 Mon Sep 17 00:00:00 2001 From: Connor Moss Date: Wed, 18 Nov 2026 16:52:33 -0500 Subject: [PATCH] fix: reject an empty --task-id or --context-id --- internal/cli/chat.go | 3 +++ internal/cli/chat_test.go | 18 ++++++++++++++++++ internal/cli/cli_test.go | 2 ++ internal/cli/send.go | 14 ++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/internal/cli/chat.go b/internal/cli/chat.go index c433c80..510778a 100644 --- a/internal/cli/chat.go +++ b/internal/cli/chat.go @@ -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 diff --git a/internal/cli/chat_test.go b/internal/cli/chat_test.go index 823c900..78d36be 100644 --- a/internal/cli/chat_test.go +++ b/internal/cli/chat_test.go @@ -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) diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index ad0de29..8bd60ac 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -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"}}, diff --git a/internal/cli/send.go b/internal/cli/send.go index 87b8001..11c57ef 100644 --- a/internal/cli/send.go +++ b/internal/cli/send.go @@ -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") } @@ -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 {