Skip to content

Commit 32cf74a

Browse files
kevinelliottclaude
andcommitted
Add dedicated bridge.test event type
Test Commands: - Changed bridge test from using conversation.started to bridge.test event - Created BridgeTestData struct with message and system_info fields - Simplified test command by removing unused variables Event Types: - Added EventBridgeTest constant to event type enum - Provides proper semantic separation of test events Test Coverage: - Added TestBridgeTestEvent to verify JSON serialization - All tests passing Note: Backend API needs to be updated to accept bridge.test event type in its schema. Current production backend will reject this event type until the schema is updated to include it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 799871a commit 32cf74a

File tree

3 files changed

+60
-27
lines changed

3 files changed

+60
-27
lines changed

cmd/bridge.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"bufio"
5-
"context"
65
"encoding/json"
76
"fmt"
87
"os"
@@ -303,35 +302,16 @@ func runBridgeTest() {
303302
fmt.Printf("Timeout: %dms\n", config.TimeoutMs)
304303
fmt.Println()
305304

306-
// Create a test event
307-
emitter := bridge.NewEmitter(config, version.GetShortVersion())
308-
testAgents := []bridge.AgentParticipant{
309-
{
310-
AgentType: "test",
311-
Name: "Test Agent",
312-
Model: "test-model",
313-
CLIVersion: "1.0.0",
314-
},
315-
}
316-
317-
// Create context with timeout
318-
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(config.TimeoutMs)*time.Millisecond)
319-
defer cancel()
320-
321305
// Send test event
322306
fmt.Println("Sending test event...")
323307
client := bridge.NewClient(config)
324308

325309
event := &bridge.Event{
326-
Type: bridge.EventConversationStarted,
310+
Type: bridge.EventBridgeTest,
327311
Timestamp: bridge.UTCTime{Time: time.Now()},
328-
Data: bridge.ConversationStartedData{
329-
ConversationID: emitter.GetConversationID(),
330-
Mode: "test",
331-
InitialPrompt: "Bridge connection test",
332-
MaxTurns: 0,
333-
Agents: testAgents,
334-
SystemInfo: bridge.CollectSystemInfo(version.GetShortVersion()),
312+
Data: bridge.BridgeTestData{
313+
Message: "Bridge connection test",
314+
SystemInfo: bridge.CollectSystemInfo(version.GetShortVersion()),
335315
},
336316
}
337317

@@ -341,10 +321,7 @@ func runBridgeTest() {
341321
os.Exit(1)
342322
}
343323

344-
_ = ctx // Use ctx to avoid unused variable warning
345-
346324
fmt.Println("✓ Connection successful!")
347-
fmt.Printf(" Conversation ID: %s\n", emitter.GetConversationID())
348325
}
349326

350327
func runBridgeDisable() {

internal/bridge/events.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const (
1717
EventConversationCompleted EventType = "conversation.completed"
1818
// EventConversationError is emitted when an error occurs during the conversation
1919
EventConversationError EventType = "conversation.error"
20+
// EventBridgeTest is emitted when testing the bridge connection
21+
EventBridgeTest EventType = "bridge.test"
2022
)
2123

2224
// UTCTime wraps time.Time to ensure JSON marshaling always uses UTC with Z suffix
@@ -97,3 +99,9 @@ type ConversationErrorData struct {
9799
ErrorType string `json:"error_type,omitempty"`
98100
AgentType string `json:"agent_type,omitempty"`
99101
}
102+
103+
// BridgeTestData contains data for bridge.test events
104+
type BridgeTestData struct {
105+
Message string `json:"message"`
106+
SystemInfo SystemInfo `json:"system_info"`
107+
}

internal/bridge/events_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,54 @@ func TestConversationErrorEvent(t *testing.T) {
235235
}
236236
}
237237

238+
func TestBridgeTestEvent(t *testing.T) {
239+
sysInfo := SystemInfo{
240+
AgentPipeVersion: "0.3.3",
241+
OS: "darwin",
242+
OSVersion: "macOS 14.1",
243+
GoVersion: "go1.24.0",
244+
Architecture: "arm64",
245+
}
246+
247+
event := &Event{
248+
Type: EventBridgeTest,
249+
Timestamp: UTCTime{time.Now()},
250+
Data: BridgeTestData{
251+
Message: "Bridge connection test",
252+
SystemInfo: sysInfo,
253+
},
254+
}
255+
256+
data, err := json.Marshal(event)
257+
if err != nil {
258+
t.Fatalf("Failed to marshal bridge.test event: %v", err)
259+
}
260+
261+
var parsed map[string]interface{}
262+
if err := json.Unmarshal(data, &parsed); err != nil {
263+
t.Fatalf("Failed to unmarshal JSON: %v", err)
264+
}
265+
266+
if parsed["type"] != string(EventBridgeTest) {
267+
t.Errorf("Expected type=%s, got %v", EventBridgeTest, parsed["type"])
268+
}
269+
270+
dataMap := parsed["data"].(map[string]interface{})
271+
if dataMap["message"] != "Bridge connection test" {
272+
t.Errorf("Expected message='Bridge connection test', got %v", dataMap["message"])
273+
}
274+
275+
// Verify system_info is present
276+
systemInfoMap, ok := dataMap["system_info"].(map[string]interface{})
277+
if !ok {
278+
t.Fatal("Expected system_info to be an object")
279+
}
280+
281+
if systemInfoMap["agentpipe_version"] != "0.3.3" {
282+
t.Errorf("Expected agentpipe_version=0.3.3, got %v", systemInfoMap["agentpipe_version"])
283+
}
284+
}
285+
238286
func TestTimestampFormat(t *testing.T) {
239287
// Test that timestamps are in ISO 8601 format with Z suffix
240288
event := &Event{

0 commit comments

Comments
 (0)