(t *testing.T)
| 156 | } |
| 157 | |
| 158 | func TestConversionAndStatusHelpers(t *testing.T) { |
| 159 | t.Parallel() |
| 160 | |
| 161 | usageValue := int64(10) |
| 162 | agentEvent := core.AgentEventPayloadFromEvent(acp.AgentEvent{ |
| 163 | Type: acp.EventTypePermission, |
| 164 | SessionID: "sess-1", |
| 165 | TurnID: "turn-1", |
| 166 | Timestamp: time.Date(2026, 4, 3, 12, 0, 0, 0, time.UTC), |
| 167 | Action: "fs/read_text_file", |
| 168 | Failure: &store.SessionFailure{ |
| 169 | Kind: store.FailurePermission, |
| 170 | Summary: "permission policy denied", |
| 171 | }, |
| 172 | Usage: &acp.TokenUsage{ |
| 173 | InputTokens: &usageValue, |
| 174 | Timestamp: time.Date(2026, 4, 3, 12, 0, 1, 0, time.UTC), |
| 175 | }, |
| 176 | Raw: []byte(`{"ok":true}`), |
| 177 | }) |
| 178 | if agentEvent.Type != acp.EventTypePermission || agentEvent.Usage == nil || agentEvent.Usage.InputTokens == nil { |
| 179 | t.Fatalf("agent event payload = %#v", agentEvent) |
| 180 | } |
| 181 | if agentEvent.Failure == nil || agentEvent.Failure.Kind != store.FailurePermission { |
| 182 | t.Fatalf("agent event failure = %#v", agentEvent.Failure) |
| 183 | } |
| 184 | if got := string(agentEvent.Raw); got != `{"ok":true}` { |
| 185 | t.Fatalf("agent event raw payload = %s, want valid JSON passthrough", got) |
| 186 | } |
| 187 | plainRawEvent := core.AgentEventPayloadFromEvent(acp.AgentEvent{Raw: []byte("plain-text")}) |
| 188 | if got := string(plainRawEvent.Raw); got != `"plain-text"` { |
| 189 | t.Fatalf("plain raw payload = %s, want quoted string", got) |
| 190 | } |
| 191 | if payload := core.PayloadJSON("plain-text"); string(payload) == "plain-text" { |
| 192 | t.Fatalf("PayloadJSON() = %s, want quoted JSON", string(payload)) |
| 193 | } |
| 194 | if status := core.StatusForWorkspaceError(workspacepkg.ErrWorkspacePathTaken); status != http.StatusConflict { |
| 195 | t.Fatalf("StatusForWorkspaceError() = %d, want %d", status, http.StatusConflict) |
| 196 | } |
| 197 | if status := core.StatusForMemoryError(errors.New("boom")); status != http.StatusInternalServerError { |
| 198 | t.Fatalf("StatusForMemoryError(default) = %d, want %d", status, http.StatusInternalServerError) |
| 199 | } |
| 200 | if status := core.StatusForMemoryError(nil); status != http.StatusOK { |
| 201 | t.Fatalf("StatusForMemoryError(nil) = %d, want %d", status, http.StatusOK) |
| 202 | } |
| 203 | if got := core.NewMemoryValidationError(nil); got != nil { |
| 204 | t.Fatalf("NewMemoryValidationError(nil) = %v, want nil", got) |
| 205 | } |
| 206 | |
| 207 | sessions := core.SessionPayloadsForWorkspace([]*session.Info{ |
| 208 | {ID: "sess-1", WorkspaceID: "ws_alpha"}, |
| 209 | {ID: "sess-2", WorkspaceID: "ws_beta"}, |
| 210 | {ID: "sess-3", WorkspaceID: "ws_alpha", Type: session.SessionTypeDream}, |
| 211 | { |
| 212 | ID: "sess-4", |
| 213 | WorkspaceID: "ws_alpha", |
| 214 | Type: session.SessionTypeSpawned, |
| 215 | Lineage: &store.SessionLineage{ |
nothing calls this directly
no test coverage detected