diff --git a/shortcuts/whiteboard/whiteboard_query.go b/shortcuts/whiteboard/whiteboard_query.go index 6abcc9a5e..09bdbdc51 100644 --- a/shortcuts/whiteboard/whiteboard_query.go +++ b/shortcuts/whiteboard/whiteboard_query.go @@ -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{}) diff --git a/shortcuts/whiteboard/whiteboard_query_test.go b/shortcuts/whiteboard/whiteboard_query_test.go index 60eda5299..b00375a90 100644 --- a/shortcuts/whiteboard/whiteboard_query_test.go +++ b/shortcuts/whiteboard/whiteboard_query_test.go @@ -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", @@ -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 {