灵隙(synapse) v1.0.0 版本

This commit is contained in:
lychang
2026-06-29 00:48:45 +08:00
parent 6d1234efff
commit db716f94ac
6 changed files with 334 additions and 107 deletions

View File

@@ -191,7 +191,7 @@ func TestHandleHeartbeat(t *testing.T) {
ID: types.GenerateMessageID(),
Version: "1.0.0",
Type: string(types.P2PHeartbeat),
Sender: types.AgentEndpoint{AgentID: "agent-002"},
Sender: types.AgentEndpoint{AgentID: "agent-002", Endpoint: "http://localhost:8081"},
Payload: json.RawMessage("{}"),
Timestamp: types.NowTimestamp(),
}
@@ -217,7 +217,7 @@ func TestHandleAck(t *testing.T) {
ID: types.GenerateMessageID(),
Version: "1.0.0",
Type: string(types.P2PAck),
Sender: types.AgentEndpoint{AgentID: "agent-002"},
Sender: types.AgentEndpoint{AgentID: "agent-002", Endpoint: "http://localhost:8081"},
ReplyTo: "msg-001",
Payload: json.RawMessage("{}"),
Timestamp: types.NowTimestamp(),
@@ -295,6 +295,10 @@ func TestGetTaskStatus(t *testing.T) {
}
proto := NewP2PProtocol(ep, nil)
proto.SetTaskHandler(&mockTaskHandler{
canHandle: true,
result: "test result",
})
// 查询不存在的任务
status, ok := proto.GetTaskStatus("nonexistent")
@@ -327,9 +331,9 @@ func TestGetTaskStatus(t *testing.T) {
if !ok {
t.Error("Task should be found")
}
// 状态应该是 pending 或 confirmed
if status != types.P2PStatusPending && status != types.P2PStatusConfirmed {
t.Errorf("Status should be pending or confirmed: got %s", status)
// 状态应该是 pending 或 executing(异步执行可能已经开始)
if status != types.P2PStatusPending && status != types.P2PStatusExecuting && status != types.P2PStatusCompleted {
t.Errorf("Status should be pending/executing/completed: got %s", status)
}
}
@@ -340,6 +344,10 @@ func TestListTasks(t *testing.T) {
}
proto := NewP2PProtocol(ep, nil)
proto.SetTaskHandler(&mockTaskHandler{
canHandle: true,
result: "test result",
})
// 初始应该为空
tasks := proto.ListTasks()
@@ -487,8 +495,14 @@ func TestHandleUnknownMessageType(t *testing.T) {
Timestamp: types.NowTimestamp(),
}
_, err := proto.HandleMessage(context.Background(), msg)
if err == nil {
t.Error("Unknown message type should return error")
resp, err := proto.HandleMessage(context.Background(), msg)
if err != nil {
t.Errorf("Unknown message type should return NACK response, not error: %v", err)
}
if resp == nil {
t.Error("Unknown message type should return NACK response")
}
if resp.Type != string(types.P2PNack) {
t.Errorf("Expected NACK response, got: %s", resp.Type)
}
}