Skip to content

Commit 8577101

Browse files
committed
It works
1 parent 2cb056f commit 8577101

File tree

16 files changed

+728
-271
lines changed

16 files changed

+728
-271
lines changed

packages/cloud/src/CloudAPI.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,13 @@ export class CloudAPI {
142142
}
143143

144144
async getCloudAgents(): Promise<CloudAgent[]> {
145-
try {
146-
this.log("[CloudAPI] Fetching cloud agents")
145+
this.log("[CloudAPI] Fetching cloud agents")
147146

148-
const response = await this.request<{ agents: CloudAgent[] }>("/api/cloud_agents", {
149-
method: "GET",
150-
})
147+
const response = await this.request<{ success: boolean; data: CloudAgent[] }>("/api/cloud-agents", {
148+
method: "GET",
149+
})
151150

152-
this.log("[CloudAPI] Cloud agents response:", response)
153-
return response.agents || []
154-
} catch (error) {
155-
this.log("[CloudAPI] Failed to fetch cloud agents, returning mock data:", error)
156-
157-
// Return mock data when API fails as requested
158-
return [
159-
{ id: "1", name: "Code Assistant", type: "code" },
160-
{ id: "2", name: "Test Generator", type: "test" },
161-
{ id: "3", name: "Code Reviewer", type: "review" },
162-
{ id: "4", name: "Documentation Writer", type: "docs" },
163-
]
164-
}
151+
this.log("[CloudAPI] Cloud agents response:", response)
152+
return response.data || []
165153
}
166154
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { describe, it, expect, vi, beforeEach } from "vitest"
2+
import { CloudAPI } from "../CloudAPI.js"
3+
import { AuthenticationError } from "../errors.js"
4+
import type { AuthService } from "@roo-code/types"
5+
6+
// Mock fetch globally
7+
global.fetch = vi.fn()
8+
9+
describe("CloudAPI", () => {
10+
let mockAuthService: Partial<AuthService>
11+
let cloudAPI: CloudAPI
12+
13+
beforeEach(() => {
14+
// Mock only the methods we need for testing
15+
mockAuthService = {
16+
getSessionToken: vi.fn().mockReturnValue("test-token"),
17+
}
18+
19+
cloudAPI = new CloudAPI(mockAuthService as AuthService)
20+
vi.clearAllMocks()
21+
})
22+
23+
describe("getCloudAgents", () => {
24+
it("should return cloud agents on success", async () => {
25+
const mockAgents = [
26+
{ id: "1", name: "Agent 1", type: "code", icon: "code" },
27+
{ id: "2", name: "Agent 2", type: "chat", icon: "chat" },
28+
]
29+
30+
// Mock successful response
31+
;(global.fetch as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
32+
ok: true,
33+
json: async () => ({ success: true, data: mockAgents }),
34+
})
35+
36+
const agents = await cloudAPI.getCloudAgents()
37+
38+
expect(agents).toEqual(mockAgents)
39+
expect(global.fetch).toHaveBeenCalledWith(
40+
expect.stringContaining("/api/cloud-agents"),
41+
expect.objectContaining({
42+
method: "GET",
43+
headers: expect.objectContaining({
44+
Authorization: "Bearer test-token",
45+
}),
46+
}),
47+
)
48+
})
49+
50+
it("should throw AuthenticationError on 401 response", async () => {
51+
// Mock 401 response
52+
;(global.fetch as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
53+
ok: false,
54+
status: 401,
55+
statusText: "Unauthorized",
56+
json: async () => ({ error: "Authentication required" }),
57+
})
58+
59+
await expect(cloudAPI.getCloudAgents()).rejects.toThrow(AuthenticationError)
60+
})
61+
62+
it("should throw AuthenticationError when no session token", async () => {
63+
// Mock no session token
64+
mockAuthService.getSessionToken = vi.fn().mockReturnValue(null)
65+
66+
await expect(cloudAPI.getCloudAgents()).rejects.toThrow(AuthenticationError)
67+
})
68+
69+
it("should return empty array when data is missing", async () => {
70+
// Mock response with no data
71+
;(global.fetch as ReturnType<typeof vi.fn>).mockResolvedValueOnce({
72+
ok: true,
73+
json: async () => ({ success: true }),
74+
})
75+
76+
const agents = await cloudAPI.getCloudAgents()
77+
78+
expect(agents).toEqual([])
79+
})
80+
})
81+
})

packages/types/src/cloud.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,8 @@ export type LeaveResponse = {
730730
export interface CloudAgent {
731731
id: string
732732
name: string
733-
type: string // e.g., "code", "review", "test", "docs"
733+
type: string // e.g., "PR Reviewer", "Documentation Writer"
734+
icon?: string // e.g., "pr-reviewer", "documentation-writer"
734735
}
735736

736737
/**

src/core/webview/ClineProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,12 +1034,11 @@ export class ClineProvider
10341034
window.__vite_plugin_react_preamble_installed__ = true
10351035
</script>
10361036
`
1037-
10381037
const csp = [
10391038
"default-src 'none'",
10401039
`font-src ${webview.cspSource} data:`,
10411040
`style-src ${webview.cspSource} 'unsafe-inline' https://* http://${localServerUrl} http://0.0.0.0:${localPort}`,
1042-
`img-src ${webview.cspSource} https://storage.googleapis.com https://img.clerk.com data:`,
1041+
`img-src ${webview.cspSource} https://storage.googleapis.com https://img.clerk.com ${getRooCodeApiUrl()} data:`,
10431042
`media-src ${webview.cspSource}`,
10441043
`script-src 'unsafe-eval' ${webview.cspSource} https://* https://*.posthog.com http://${localServerUrl} http://0.0.0.0:${localPort} 'nonce-${nonce}'`,
10451044
`connect-src ${webview.cspSource} https://* https://*.posthog.com ws://${localServerUrl} ws://0.0.0.0:${localPort} http://${localServerUrl} http://0.0.0.0:${localPort}`,

0 commit comments

Comments
 (0)