feat: expand node agent routing and media artifacts

This commit is contained in:
lpf
2026-03-09 01:21:19 +08:00
parent c0fe977bce
commit 2d5a384342
14 changed files with 1291 additions and 81 deletions

76
pkg/nodes/manager_test.go Normal file
View File

@@ -0,0 +1,76 @@
package nodes
import (
"testing"
"time"
)
func TestPickRequestPrefersMatchingRemoteAgent(t *testing.T) {
t.Parallel()
manager := NewManager()
now := time.Now().UTC()
manager.Upsert(NodeInfo{
ID: "node-main-only",
Online: true,
LastSeenAt: now,
Capabilities: Capabilities{
Model: true,
},
Agents: []AgentInfo{{ID: "main"}},
})
manager.Upsert(NodeInfo{
ID: "node-coder",
Online: true,
LastSeenAt: now,
Capabilities: Capabilities{
Model: true,
},
Agents: []AgentInfo{{ID: "main"}, {ID: "coder"}},
})
picked, ok := manager.PickRequest(Request{
Action: "agent_task",
Args: map[string]interface{}{"remote_agent_id": "coder"},
}, "auto")
if !ok {
t.Fatalf("expected node pick")
}
if picked.ID != "node-coder" {
t.Fatalf("expected node-coder, got %+v", picked)
}
}
func TestPickRequestPrefersRealtimeCapableNodeForScreenActions(t *testing.T) {
t.Parallel()
manager := NewManager()
now := time.Now().UTC()
manager.Upsert(NodeInfo{
ID: "relay-only",
Online: true,
LastSeenAt: now.Add(-2 * time.Minute),
Capabilities: Capabilities{
Screen: true,
},
Actions: []string{"screen_snapshot"},
})
manager.Upsert(NodeInfo{
ID: "p2p-ready",
Online: true,
LastSeenAt: now,
Capabilities: Capabilities{
Screen: true,
},
Actions: []string{"screen_snapshot"},
})
manager.RegisterWireSender("p2p-ready", &captureWireSender{})
picked, ok := manager.PickRequest(Request{Action: "screen_snapshot"}, "auto")
if !ok {
t.Fatalf("expected node pick")
}
if picked.ID != "p2p-ready" {
t.Fatalf("expected p2p-ready, got %+v", picked)
}
}