fix(cli): align stream error handling after output-mode merge
Follow up on #1740/#1741 by typing terminal SSE errors in the SDK, classifying them as server.error in the CLI/MCP, marking Projector done on error frames, attaching session_id to MCP stream failures, and migrating the e2e chat step to the bounded JSON envelope.
This commit is contained in:
@@ -218,7 +218,7 @@ func runChatNDJSON(ctx context.Context, opts *Options, sessionID string, svc Cha
|
||||
if cmdutil.IsCancelled(ctx, err) {
|
||||
return cmdutil.Wrapf(cmdutil.CodeOperationCancelled, err, "chat cancelled")
|
||||
}
|
||||
return cmdutil.WrapHTTP(err, "knowledge qa stream")
|
||||
return cmdutil.WrapStream(err, "knowledge qa stream")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -265,7 +265,7 @@ func runChatText(ctx context.Context, opts *Options, sessionID string, autoCreat
|
||||
}
|
||||
// Pre-stream HTTP / transport failure: route through the canonical
|
||||
// classifier so 401 / 404 / 5xx still surface their specific codes.
|
||||
return cmdutil.WrapHTTP(streamErr, "knowledge qa stream")
|
||||
return cmdutil.WrapStream(streamErr, "knowledge qa stream")
|
||||
}
|
||||
|
||||
// SDK returned nil but we never saw a Done event - server closed the
|
||||
@@ -304,7 +304,7 @@ func runChatJSON(ctx context.Context, opts *Options, fopts *cmdutil.FormatOption
|
||||
if cmdutil.IsCancelled(ctx, err) {
|
||||
return chatStreamError(cmdutil.Wrapf(cmdutil.CodeOperationCancelled, err, "chat cancelled"), sessionID, projector.AssistantMessageID())
|
||||
}
|
||||
return chatStreamError(cmdutil.WrapHTTP(err, "knowledge qa stream"), sessionID, projector.AssistantMessageID())
|
||||
return chatStreamError(cmdutil.WrapStream(err, "knowledge qa stream"), sessionID, projector.AssistantMessageID())
|
||||
}
|
||||
if !projector.Done() {
|
||||
return chatStreamError(
|
||||
|
||||
@@ -318,6 +318,29 @@ func TestChat_SDKError_MidStream_AbortsAsSSE(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChat_TerminalSSEError_ClassifiesAsServerError(t *testing.T) {
|
||||
_, _ = iostreams.SetForTest(t)
|
||||
svc := &fakeChatService{
|
||||
streamEvents: []*sdk.StreamResponse{
|
||||
{ResponseType: sdk.ResponseTypeAnswer, Content: "partial"},
|
||||
{ResponseType: sdk.ResponseTypeError, Content: "boom", Done: true},
|
||||
},
|
||||
streamErr: sdk.NewSSEStreamError("boom"),
|
||||
}
|
||||
opts := &Options{Query: "q", KBID: "kb"}
|
||||
err := runChat(context.Background(), opts, textOpts(), svc)
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
var typed *cmdutil.Error
|
||||
if !errors.As(err, &typed) {
|
||||
t.Fatalf("expected *cmdutil.Error, got %T", err)
|
||||
}
|
||||
if typed.Code != cmdutil.CodeServerError {
|
||||
t.Errorf("code: got %q want %q", typed.Code, cmdutil.CodeServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChat_ContextCancelled(t *testing.T) {
|
||||
_, _ = iostreams.SetForTest(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -190,7 +190,7 @@ func runAskNDJSON(ctx context.Context, opts *AskOptions, sessionID string, svc A
|
||||
if cmdutil.IsCancelled(ctx, err) {
|
||||
return cmdutil.Wrapf(cmdutil.CodeOperationCancelled, err, "session ask cancelled")
|
||||
}
|
||||
return cmdutil.WrapHTTP(err, "agent-chat stream")
|
||||
return cmdutil.WrapStream(err, "agent-chat stream")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func runAskText(ctx context.Context, opts *AskOptions, sessionID string, autoCre
|
||||
if projector.Seen() && !projector.Done() {
|
||||
return cmdutil.Wrapf(cmdutil.CodeSSEStreamAborted, streamErr, "stream aborted before completion")
|
||||
}
|
||||
return cmdutil.WrapHTTP(streamErr, "agent-chat stream")
|
||||
return cmdutil.WrapStream(streamErr, "agent-chat stream")
|
||||
}
|
||||
|
||||
// Server closed cleanly but never sent a complete event — treat as aborted
|
||||
@@ -260,7 +260,7 @@ func runAskJSON(ctx context.Context, opts *AskOptions, fopts *cmdutil.FormatOpti
|
||||
if cmdutil.IsCancelled(ctx, err) {
|
||||
return askStreamError(cmdutil.Wrapf(cmdutil.CodeOperationCancelled, err, "session ask cancelled"), sessionID)
|
||||
}
|
||||
return askStreamError(cmdutil.WrapHTTP(err, "agent-chat stream"), sessionID)
|
||||
return askStreamError(cmdutil.WrapStream(err, "agent-chat stream"), sessionID)
|
||||
}
|
||||
if !projector.Done() {
|
||||
return askStreamError(
|
||||
|
||||
Reference in New Issue
Block a user