(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestUnixSocketClientNetworkMethods(t *testing.T) { |
| 16 | t.Parallel() |
| 17 | |
| 18 | t.Run("Should call network routes through the unix socket client", func(t *testing.T) { |
| 19 | t.Parallel() |
| 20 | |
| 21 | directID := "direct_99401d24bee62651d189e5a561785466" |
| 22 | client := &unixSocketClient{ |
| 23 | socketPath: "/tmp/agh.sock", |
| 24 | httpClient: &http.Client{ |
| 25 | Transport: roundTripperFunc(func(req *http.Request) (*http.Response, error) { |
| 26 | switch { |
| 27 | case req.Method == http.MethodGet && req.URL.Path == "/api/network/status": |
| 28 | return newHTTPResponse( |
| 29 | http.StatusOK, |
| 30 | `{"network":{"enabled":true,"status":"running","listener_host":"127.0.0.1","listener_port":4222,"local_peers":1,"remote_peers":2,"channels":1,"queued_messages":3,"queued_sessions":1,"delivery_workers":1,"messages_sent":4,"messages_received":5,"messages_rejected":1,"messages_delivered":3,"workflow_tagged_events":2,"handoff_tagged_events":1,"kind_metrics":[{"kind":"say","sent":4,"received":5,"rejected":1,"delivered":3}]}}`, |
| 31 | ), nil |
| 32 | case req.Method == http.MethodGet && req.URL.Path == "/api/workspaces/ws-alpha/network/peers": |
| 33 | if got := req.URL.Query().Get("channel"); got != "builders" { |
| 34 | t.Fatalf("network peers channel query = %q, want builders", got) |
| 35 | } |
| 36 | return newHTTPResponse( |
| 37 | http.StatusOK, |
| 38 | `{"peers":[{"peer_id":"reviewer.sess-a","session_id":"sess-a","channel":"builders","local":true,"presence_state":"local","peer_card":{"peer_id":"reviewer.sess-a","display_name":"Reviewer","profiles_supported":["v0"],"capabilities":[{"id":"send","summary":"Send direct messages"}],"artifacts_supported":["text"],"trust_modes_supported":["untrusted"]}}]}`, |
| 39 | ), nil |
| 40 | case req.Method == http.MethodGet && req.URL.Path == "/api/workspaces/ws-alpha/network/channels": |
| 41 | return newHTTPResponse( |
| 42 | http.StatusOK, |
| 43 | `{"channels":[{"channel":"builders","peer_count":2}]}`, |
| 44 | ), nil |
| 45 | case req.Method == http.MethodPost && req.URL.Path == "/api/workspaces/ws-alpha/network/channels": |
| 46 | body, err := io.ReadAll(req.Body) |
| 47 | if err != nil { |
| 48 | t.Fatalf("io.ReadAll(network channels create body) error = %v", err) |
| 49 | } |
| 50 | if strings.Contains(string(body), `"workspace_id"`) || |
| 51 | !strings.Contains(string(body), `"channel":"launch_ops"`) || |
| 52 | !strings.Contains(string(body), `"purpose":"Coordinate launch work"`) || |
| 53 | !strings.Contains(string(body), `"agent_names":["site_copywriter","growth_marketer"]`) { |
| 54 | t.Fatalf("network channels create body = %s, want route-scoped create payload", body) |
| 55 | } |
| 56 | return newHTTPResponse( |
| 57 | http.StatusCreated, |
| 58 | `{"channel":{"channel":"launch_ops","workspace_id":"ws-alpha","purpose":"Coordinate launch work","created_by":"site_copywriter","peer_count":2,"session_count":2}}`, |
| 59 | ), nil |
| 60 | case req.Method == http.MethodGet && req.URL.Path == "/api/workspaces/ws-alpha/network/channels/builders/threads": |
| 61 | if got := req.URL.Query().Get("limit"); got != "2" { |
| 62 | t.Fatalf("network threads limit query = %q, want 2", got) |
| 63 | } |
| 64 | if got := req.URL.Query().Get("after"); got != "thread_0" { |
| 65 | t.Fatalf("network threads after query = %q, want thread_0", got) |
| 66 | } |
| 67 | return newHTTPResponse( |
| 68 | http.StatusOK, |
| 69 | `{"threads":[{"channel":"builders","thread_id":"thread_launch","root_message_id":"msg-root","opened_by_peer_id":"coder.sess-a","message_count":2,"participant_count":2,"open_work_count":1,"last_message_preview":"ready"}]}`, |
| 70 | ), nil |
| 71 | case req.Method == http.MethodGet && req.URL.Path == "/api/workspaces/ws-alpha/network/channels/builders/threads/thread_launch": |
| 72 | return newHTTPResponse( |
nothing calls this directly
no test coverage detected