fix(onlines): agent 在线名单按节点归因键存储(第12条修复A)

reportTraffic 旧实现把所有 agent 的在线名单写死存入 "agent" 键,
而入站页按 originNodeGuid / node:{id} 归因键查找,永远查不到:
agent 入站行永不亮在线,且所有 agent 节点被并进同一键。
改为 InboundService.SetAgentOnlineClients:按节点的 effectiveNodeKey
(有唯一 GUID 用 GUID、否则 node:{id})存入;空名单仍走
ClearNodeOnlineClients 清整棵子树。同步修正 online_store_test 中
断言旧键的用例注释与键名;新增两例服务层测试(双 agent 节点键互不
合并、空上报清空)。
This commit is contained in:
Muse
2026-10-22 10:25:15 +00:00
parent ac39370879
commit ff1204ce2d
4 changed files with 125 additions and 10 deletions
+5 -3
View File
@@ -55,13 +55,15 @@ func TestOnlineStoreSetTreeUnionAndByGuid(t *testing.T) {
requireSet(t, "local", st.GetLocalOnlineClients(), "alice@example.com", "local@example.com")
}
// The agent controller reports onlines under the literal "agent" GUID key;
// Agent-node onlines arrive keyed by the node's attribution key (the
// synthNodeGuid form below for a GUID-less agent node — the controller used
// to file them under a literal "agent" key no inbound lookup ever matched);
// they must reach the union untouched.
func TestOnlineStoreAgentKeyTree(t *testing.T) {
st := &onlineStore{}
st.SetNodeOnlineTree(7, map[string][]string{"agent": {"agentuser@example.com"}})
st.SetNodeOnlineTree(7, map[string][]string{"node:7": {"agentuser@example.com"}})
requireSet(t, "union", st.GetOnlineClients(), "agentuser@example.com")
requireSet(t, "byGuid agent", st.GetMergedNodeTrees()["agent"], "agentuser@example.com")
requireSet(t, "byGuid node:7", st.GetMergedNodeTrees()["node:7"], "agentuser@example.com")
}
// Setting a tree replaces the node's previous contribution; an empty tree