MCPcopy Create free account
hub / github.com/compozy/agh / TestUnixSocketClientAgentMeSendsIdentityHeaders

Function TestUnixSocketClientAgentMeSendsIdentityHeaders

internal/cli/client_test.go:32–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func TestUnixSocketClientAgentMeSendsIdentityHeaders(t *testing.T) {
33 t.Parallel()
34
35 t.Run("Should send identity headers", func(t *testing.T) {
36 t.Parallel()
37
38 client := &unixSocketClient{
39 socketPath: "/tmp/agh.sock",
40 httpClient: &http.Client{
41 Transport: roundTripperFunc(func(req *http.Request) (*http.Response, error) {
42 if req.Method != http.MethodGet || req.URL.Path != "/api/agent/me" {
43 t.Fatalf("request = %s %s, want GET /api/agent/me", req.Method, req.URL.Path)
44 }
45 if got := req.Header.Get(agentidentity.HeaderSessionID); got != "sess-1" {
46 t.Fatalf("%s = %q, want sess-1", agentidentity.HeaderSessionID, got)
47 }
48 if got := req.Header.Get(agentidentity.HeaderAgent); got != "coder" {
49 t.Fatalf("%s = %q, want coder", agentidentity.HeaderAgent, got)
50 }
51 if got := req.Header.Get(agentidentity.HeaderWorkspaceID); got != "ws-1" {
52 t.Fatalf("%s = %q, want ws-1", agentidentity.HeaderWorkspaceID, got)
53 }
54 return newHTTPResponse(
55 http.StatusOK,
56 `{"me":{"self":{"session_id":"sess-1","agent_name":"coder","provider":"test"},"workspace":{"id":"ws-1"},"session":{"id":"sess-1","agent_name":"coder","state":"active","created_at":"2026-04-03T12:00:00Z","updated_at":"2026-04-03T12:00:00Z"},"capabilities":[],"channels":[],"active_task_leases":[]}}`,
57 ), nil
58 }),
59 },
60 }
61
62 me, err := client.AgentMe(context.Background(), agentidentity.Credentials{
63 SessionID: "sess-1",
64 AgentName: "coder",
65 WorkspaceID: "ws-1",
66 })
67 if err != nil {
68 t.Fatalf("AgentMe() error = %v", err)
69 }
70 if me.Self.SessionID != "sess-1" || me.Self.AgentName != "coder" {
71 t.Fatalf("AgentMe() = %#v, want validated response", me.Self)
72 }
73 })
74}
75
76func TestUnixSocketClientAgentChannelMethodsSendIdentityHeaders(t *testing.T) {
77 t.Parallel()

Callers

nothing calls this directly

Calls 5

AgentMeMethod · 0.95
roundTripperFuncFuncType · 0.85
newHTTPResponseFunction · 0.70
RunMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected