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
5 changes: 1 addition & 4 deletions shortcuts/whiteboard/whiteboard_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ func fetchWhiteboardNodes(runtime *common.RuntimeContext, wbToken string) (*wbNo
return nil, err
}
var nodes wbNodesResp
rawNodes, ok := data["nodes"]
if !ok {
return nil, wbInvalidResponse("get whiteboard nodes failed: missing data.nodes")
}
rawNodes, _ := data["nodes"]
if rawNodes != nil {
var ok bool
nodes.Data.Nodes, ok = rawNodes.([]interface{})
Expand Down
31 changes: 26 additions & 5 deletions shortcuts/whiteboard/whiteboard_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,6 @@ func TestFetchWhiteboardNodes_InvalidResponseTypedError(t *testing.T) {
token string
data map[string]interface{}
}{
{
name: "missing nodes",
token: "test-token-missing-nodes",
data: map[string]interface{}{},
},
{
name: "nodes not array",
token: "test-token-bad-nodes",
Expand Down Expand Up @@ -880,6 +875,32 @@ func TestFetchWhiteboardNodes_InvalidResponseTypedError(t *testing.T) {
}
}

// TestFetchWhiteboardNodes_MissingNodesIsEmpty verifies that a response with
// missing nodes field is treated as an empty whiteboard (success), not an error.
// This matches the behavior introduced in commit 4b39b037.
func TestFetchWhiteboardNodes_MissingNodesIsEmpty(t *testing.T) {
factory, stdout, reg := newExecuteFactory(t)

reg.Register(&httpmock.Stub{
Method: "GET",
URL: "/open-apis/board/v1/whiteboards/test-token-missing-nodes/nodes",
Body: map[string]interface{}{
"code": 0,
"msg": "success",
"data": map[string]interface{}{},
},
})

args := []string{"+query", "--whiteboard-token", "test-token-missing-nodes", "--output_as", "raw"}
if err := runShortcut(t, WhiteboardQuery, args, factory, stdout); err != nil {
t.Fatalf("expected success for missing nodes (empty whiteboard), got err=%v", err)
}

if !strings.Contains(stdout.String(), "whiteboard is empty") {
t.Fatalf("stdout missing empty whiteboard message: %s", stdout.String())
}
}

func assertInvalidResponse(t *testing.T, err error) {
t.Helper()
if err == nil {
Expand Down
Loading