(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestMeCommandJSONReturnsValidatedIdentity(t *testing.T) { |
| 17 | t.Parallel() |
| 18 | |
| 19 | t.Run("Should return validated identity as JSON", func(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | |
| 22 | client := &stubClient{} |
| 23 | deps := newAgentCommandTestDeps(t, client) |
| 24 | client.agentMeFn = func(_ context.Context, credentials agentidentity.Credentials) (AgentMeRecord, error) { |
| 25 | assertAgentCredentials(t, credentials) |
| 26 | return AgentMeRecord{ |
| 27 | Self: contract.AgentIdentityPayload{ |
| 28 | SessionID: "sess-agent", |
| 29 | AgentName: "coder", |
| 30 | Provider: "test-provider", |
| 31 | Model: "test-model", |
| 32 | }, |
| 33 | Workspace: contract.AgentWorkspacePayload{ |
| 34 | ID: "ws-1", |
| 35 | RootDir: "/workspace/project", |
| 36 | }, |
| 37 | Session: contract.AgentSessionPayload{ |
| 38 | ID: "sess-agent", |
| 39 | State: session.StateActive, |
| 40 | Channel: "builders", |
| 41 | CreatedAt: fixedTestNow, |
| 42 | UpdatedAt: fixedTestNow, |
| 43 | }, |
| 44 | }, nil |
| 45 | } |
| 46 | |
| 47 | stdout, _, err := executeRootCommand(t, deps, "me", "-o", "json") |
| 48 | if err != nil { |
| 49 | t.Fatalf("agh me error = %v", err) |
| 50 | } |
| 51 | |
| 52 | var got AgentMeRecord |
| 53 | if err := json.Unmarshal([]byte(stdout), &got); err != nil { |
| 54 | t.Fatalf("json.Unmarshal(agh me) error = %v", err) |
| 55 | } |
| 56 | if got.Self.SessionID != "sess-agent" || got.Self.AgentName != "coder" || got.Workspace.ID != "ws-1" { |
| 57 | t.Fatalf("agh me payload = %#v, want caller session/workspace identity", got) |
| 58 | } |
| 59 | }) |
| 60 | } |
| 61 | |
| 62 | func TestMeContextCommandJSONKeepsStableSectionOrder(t *testing.T) { |
| 63 | t.Parallel() |
nothing calls this directly
no test coverage detected