-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
171 lines (153 loc) · 5.23 KB
/
Copy pathintegration_test.go
File metadata and controls
171 lines (153 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package mycelium_test
import (
"net/http/httptest"
"testing"
"github.com/closer/mycelium/internal/broker"
"github.com/closer/mycelium/internal/client"
"github.com/closer/mycelium/internal/types"
)
func TestIntegration_FullWorkflow(t *testing.T) {
// 1. Start broker with httptest.NewServer
b := broker.New()
srv := httptest.NewServer(b.Handler())
defer srv.Close()
// 2. Create 2 clients: c1 (frontend, repo A) and c2 (backend, repo B)
c1 := client.New(srv.URL)
c2 := client.New(srv.URL)
// 3. Germinate both
id1, err := c1.Germinate(1001, "/workspace/frontend", "repo-a", "frontend Claude instance")
if err != nil {
t.Fatalf("c1 germinate: %v", err)
}
id2, err := c2.Germinate(1002, "/workspace/backend", "repo-b", "backend Claude instance")
if err != nil {
t.Fatalf("c2 germinate: %v", err)
}
// 4. Discover machine scope — should find each other
peers, err := c1.Discover(id1, "machine")
if err != nil {
t.Fatalf("c1 discover machine: %v", err)
}
if len(peers) != 1 {
t.Fatalf("c1 discover machine: want 1 peer, got %d", len(peers))
}
if peers[0].ID != id2 {
t.Errorf("c1 discover machine: expected c2 peer_id %s, got %s", id2, peers[0].ID)
}
// 5. Discover repo scope — should NOT find each other (different repos)
repoPeers, err := c1.Discover(id1, "repo")
if err != nil {
t.Fatalf("c1 discover repo: %v", err)
}
if len(repoPeers) != 0 {
t.Fatalf("c1 discover repo: want 0 peers (different repos), got %d", len(repoPeers))
}
// 6. Signal c1→c2 "API schema ready", sense c2, verify message
_, err = c1.Signal(id1, id2, "API schema ready")
if err != nil {
t.Fatalf("c1 signal: %v", err)
}
msgs, err := c2.Sense(id2)
if err != nil {
t.Fatalf("c2 sense after signal: %v", err)
}
if len(msgs) != 1 {
t.Fatalf("c2 sense: want 1 message, got %d", len(msgs))
}
if msgs[0].Body != "API schema ready" {
t.Errorf("c2 sense: want body %q, got %q", "API schema ready", msgs[0].Body)
}
if msgs[0].From != id1 {
t.Errorf("c2 sense: want from %s, got %s", id1, msgs[0].From)
}
// 7. c2 subscribes to "deploy" topic
if err := c2.Attach(id2, "deploy"); err != nil {
t.Fatalf("c2 attach: %v", err)
}
// 8. c1 sporulates "deploying v1.0" on "deploy" topic, machine scope
if err := c1.Sporulate(id1, "deploying v1.0", "deploy", "machine"); err != nil {
t.Fatalf("c1 sporulate: %v", err)
}
// 9. c2 senses, verify topic message received
topicMsgs, err := c2.Sense(id2)
if err != nil {
t.Fatalf("c2 sense after sporulate: %v", err)
}
if len(topicMsgs) != 1 {
t.Fatalf("c2 sense topic: want 1 message, got %d", len(topicMsgs))
}
if topicMsgs[0].Body != "deploying v1.0" {
t.Errorf("c2 sense topic: want body %q, got %q", "deploying v1.0", topicMsgs[0].Body)
}
if topicMsgs[0].Topic != "deploy" {
t.Errorf("c2 sense topic: want topic %q, got %q", "deploy", topicMsgs[0].Topic)
}
// 10. c1 nurtures c2 "implement /users endpoint" with context "REST API, return JSON"
taskID, err := c1.Nurture(id1, id2, "implement /users endpoint", "REST API, return JSON")
if err != nil {
t.Fatalf("c1 nurture: %v", err)
}
if taskID == "" {
t.Fatal("c1 nurture: got empty task_id")
}
// 11. c2 surveys, verify received task
survey2, err := c2.Survey(id2)
if err != nil {
t.Fatalf("c2 survey: %v", err)
}
if len(survey2.Received) != 1 {
t.Fatalf("c2 survey received: want 1, got %d", len(survey2.Received))
}
task := survey2.Received[0]
if task.ID != taskID {
t.Errorf("c2 survey: want task_id %s, got %s", taskID, task.ID)
}
if task.Description != "implement /users endpoint" {
t.Errorf("c2 survey: want description %q, got %q", "implement /users endpoint", task.Description)
}
if task.Status != types.TaskStatusPending {
t.Errorf("c2 survey: want status pending, got %s", task.Status)
}
// 12. c2 fruits the task as completed "endpoint implemented with tests"
if err := c2.Fruit(taskID, types.TaskStatusCompleted, "endpoint implemented with tests"); err != nil {
t.Fatalf("c2 fruit: %v", err)
}
// 13. c1 senses, verify notification message
notifMsgs, err := c1.Sense(id1)
if err != nil {
t.Fatalf("c1 sense after fruit: %v", err)
}
if len(notifMsgs) != 1 {
t.Fatalf("c1 sense notification: want 1 message, got %d", len(notifMsgs))
}
if notifMsgs[0].From != id2 {
t.Errorf("c1 sense notification: want from %s, got %s", id2, notifMsgs[0].From)
}
// 14. c1 surveys, verify task status is completed
survey1, err := c1.Survey(id1)
if err != nil {
t.Fatalf("c1 survey: %v", err)
}
if len(survey1.Delegated) != 1 {
t.Fatalf("c1 survey delegated: want 1, got %d", len(survey1.Delegated))
}
completedTask := survey1.Delegated[0]
if completedTask.Status != types.TaskStatusCompleted {
t.Errorf("c1 survey: want status completed, got %s", completedTask.Status)
}
if completedTask.Result != "endpoint implemented with tests" {
t.Errorf("c1 survey: want result %q, got %q", "endpoint implemented with tests", completedTask.Result)
}
// 15. c1 withers
if err := c1.Wither(id1); err != nil {
t.Fatalf("c1 wither: %v", err)
}
// 16. c2 discovers machine scope, verify 0 peers
peersAfter, err := c2.Discover(id2, "machine")
if err != nil {
t.Fatalf("c2 discover after wither: %v", err)
}
if len(peersAfter) != 0 {
t.Fatalf("c2 discover after wither: want 0 peers, got %d", len(peersAfter))
}
}