fix: parsing empty whiteboard (#1391)

Change-Id: I10082f89c36ed77e77e1d016be263e0f7369b7b3
This commit is contained in:
syh-cpdsss
2026-06-11 11:27:38 +08:00
committed by GitHub
parent 6d8dc402ac
commit 483043c88b
2 changed files with 27 additions and 9 deletions

View File

@@ -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{})

View File

@@ -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 {