Skip to content

Commit 71b210c

Browse files
committed
Simplify and fix tests
1 parent 4ce37c2 commit 71b210c

File tree

13 files changed

+54
-58
lines changed

13 files changed

+54
-58
lines changed

packages/cloud/src/__mocks__/vscode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const Uri = {
1313
parse: vi.fn((uri: string) => ({ toString: () => uri })),
1414
}
1515

16+
export const commands = {
17+
executeCommand: vi.fn().mockResolvedValue(undefined),
18+
}
19+
1620
export interface ExtensionContext {
1721
secrets: {
1822
get: (key: string) => Promise<string | undefined>

packages/cloud/src/bridge/BaseChannel.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { Socket } from "socket.io-client"
22
import * as vscode from "vscode"
33

4-
import { ExtensionMetadata } from "@roo-code/types"
4+
import { StaticAppProperties } from "@roo-code/types"
55

66
export interface BaseChannelOptions {
77
instanceId: string
8-
extensionMetadata: ExtensionMetadata
8+
appProperties: StaticAppProperties
99
}
1010

1111
/**
@@ -19,11 +19,11 @@ export interface BaseChannelOptions {
1919
export abstract class BaseChannel<TCommand = unknown, TEventName extends string = string, TEventData = unknown> {
2020
protected socket: Socket | null = null
2121
protected readonly instanceId: string
22-
protected readonly extensionMetadata: ExtensionMetadata
22+
protected readonly appProperties: StaticAppProperties
2323

2424
constructor(options: BaseChannelOptions) {
2525
this.instanceId = options.instanceId
26-
this.extensionMetadata = options.extensionMetadata
26+
this.appProperties = options.appProperties
2727
}
2828

2929
/**
@@ -99,10 +99,10 @@ export abstract class BaseChannel<TCommand = unknown, TEventName extends string
9999
* handleCommandImplementation method.
100100
*/
101101
public async handleCommand(command: TCommand): Promise<void> {
102-
// Common functionality: focus the sidebar
103-
await vscode.commands.executeCommand(`${this.extensionMetadata.name}.SidebarProvider.focus`)
102+
// Common functionality: focus the sidebar.
103+
await vscode.commands.executeCommand(`${this.appProperties.appName}.SidebarProvider.focus`)
104104

105-
// Delegate to subclass-specific implementation
105+
// Delegate to subclass-specific implementation.
106106
await this.handleCommandImplementation(command)
107107
}
108108

packages/cloud/src/bridge/BridgeOrchestrator.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import crypto from "crypto"
2+
import os from "os"
23

34
import {
45
type TaskProviderLike,
56
type TaskLike,
67
type CloudUserInfo,
78
type ExtensionBridgeCommand,
89
type TaskBridgeCommand,
9-
type ExtensionMetadata,
10+
type StaticAppProperties,
1011
ConnectionState,
1112
ExtensionSocketEvents,
1213
TaskSocketEvents,
@@ -22,7 +23,6 @@ export interface BridgeOrchestratorOptions {
2223
token: string
2324
provider: TaskProviderLike
2425
sessionId?: string
25-
extensionMetadata: ExtensionMetadata
2626
}
2727

2828
/**
@@ -41,7 +41,7 @@ export class BridgeOrchestrator {
4141
private readonly token: string
4242
private readonly provider: TaskProviderLike
4343
private readonly instanceId: string
44-
private readonly extensionMetadata: ExtensionMetadata
44+
private readonly appProperties: StaticAppProperties
4545

4646
// Components
4747
private socketTransport: SocketTransport
@@ -152,7 +152,7 @@ export class BridgeOrchestrator {
152152
this.token = options.token
153153
this.provider = options.provider
154154
this.instanceId = options.sessionId || crypto.randomUUID()
155-
this.extensionMetadata = options.extensionMetadata
155+
this.appProperties = { ...options.provider.appProperties, hostname: os.hostname() }
156156

157157
this.socketTransport = new SocketTransport({
158158
url: this.socketBridgeUrl,
@@ -175,12 +175,15 @@ export class BridgeOrchestrator {
175175

176176
this.extensionChannel = new ExtensionChannel({
177177
instanceId: this.instanceId,
178+
appProperties: this.appProperties,
178179
userId: this.userId,
179180
provider: this.provider,
180-
extensionMetadata: this.extensionMetadata,
181181
})
182182

183-
this.taskChannel = new TaskChannel({ instanceId: this.instanceId, extensionMetadata: this.extensionMetadata })
183+
this.taskChannel = new TaskChannel({
184+
instanceId: this.instanceId,
185+
appProperties: this.appProperties,
186+
})
184187
}
185188

186189
private setupSocketListeners() {

packages/cloud/src/bridge/ExtensionChannel.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class ExtensionChannel extends BaseChannel<
3737
private eventListeners: Map<RooCodeEventName, (...args: unknown[]) => void> = new Map()
3838

3939
constructor(options: ExtensionChannelOptions) {
40-
super({ instanceId: options.instanceId, extensionMetadata: options.extensionMetadata })
40+
super({ instanceId: options.instanceId, appProperties: options.appProperties })
4141

4242
this.userId = options.userId
4343
this.provider = options.provider
@@ -49,10 +49,7 @@ export class ExtensionChannel extends BaseChannel<
4949
appProperties: this.provider.appProperties,
5050
gitProperties: this.provider.gitProperties,
5151
lastHeartbeat: Date.now(),
52-
task: {
53-
taskId: "",
54-
taskStatus: TaskStatus.None,
55-
},
52+
task: { taskId: "", taskStatus: TaskStatus.None },
5653
taskHistory: [],
5754
}
5855

@@ -224,8 +221,6 @@ export class ExtensionChannel extends BaseChannel<
224221

225222
this.extensionInstance = {
226223
...this.extensionInstance,
227-
appProperties: this.extensionInstance.appProperties ?? this.provider.appProperties,
228-
gitProperties: this.extensionInstance.gitProperties ?? this.provider.gitProperties,
229224
lastHeartbeat: Date.now(),
230225
task: task
231226
? {

packages/cloud/src/bridge/__tests__/ExtensionChannel.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Socket } from "socket.io-client"
55
import {
66
type TaskProviderLike,
77
type TaskProviderEvents,
8+
type StaticAppProperties,
89
RooCodeEventName,
910
ExtensionBridgeEventName,
1011
ExtensionSocketEvents,
@@ -18,12 +19,14 @@ describe("ExtensionChannel", () => {
1819
let extensionChannel: ExtensionChannel
1920
const instanceId = "test-instance-123"
2021
const userId = "test-user-456"
21-
const extensionMetadata = {
22-
name: "roo-code",
23-
publisher: "Roocode",
24-
version: "1.0.0",
25-
outputChannel: "Roo Code",
26-
sha: undefined,
22+
23+
const appProperties: StaticAppProperties = {
24+
appName: "roo-code",
25+
appVersion: "1.0.0",
26+
vscodeVersion: "1.0.0",
27+
platform: "darwin",
28+
editorName: "Roo Code",
29+
hostname: "test-host",
2730
}
2831

2932
// Track registered event listeners
@@ -89,7 +92,7 @@ describe("ExtensionChannel", () => {
8992
// Create extension channel instance
9093
extensionChannel = new ExtensionChannel({
9194
instanceId,
92-
extensionMetadata,
95+
appProperties,
9396
userId,
9497
provider: mockProvider,
9598
})
@@ -169,7 +172,7 @@ describe("ExtensionChannel", () => {
169172
// Create a second channel with the same provider
170173
const secondChannel = new ExtensionChannel({
171174
instanceId: "instance-2",
172-
extensionMetadata,
175+
appProperties,
173176
userId,
174177
provider: mockProvider,
175178
})

packages/cloud/src/bridge/__tests__/TaskChannel.test.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Socket } from "socket.io-client"
66
import {
77
type TaskLike,
88
type ClineMessage,
9+
type StaticAppProperties,
910
RooCodeEventName,
1011
TaskBridgeEventName,
1112
TaskBridgeCommandName,
@@ -21,12 +22,14 @@ describe("TaskChannel", () => {
2122
let mockTask: TaskLike
2223
const instanceId = "test-instance-123"
2324
const taskId = "test-task-456"
24-
const extensionMetadata = {
25-
name: "roo-code",
26-
publisher: "Roocode",
27-
version: "1.0.0",
28-
outputChannel: "Roo Code",
29-
sha: undefined,
25+
26+
const appProperties: StaticAppProperties = {
27+
appName: "roo-code",
28+
appVersion: "1.0.0",
29+
vscodeVersion: "1.0.0",
30+
platform: "darwin",
31+
editorName: "Roo Code",
32+
hostname: "test-host",
3033
}
3134

3235
beforeEach(() => {
@@ -84,7 +87,7 @@ describe("TaskChannel", () => {
8487
// Create task channel instance
8588
taskChannel = new TaskChannel({
8689
instanceId,
87-
extensionMetadata,
90+
appProperties,
8891
})
8992
})
9093

@@ -330,7 +333,7 @@ describe("TaskChannel", () => {
330333
channel.subscribedTasks.set(taskId, mockTask)
331334
})
332335

333-
it("should handle Message command", () => {
336+
it("should handle Message command", async () => {
334337
const command = {
335338
type: TaskBridgeCommandName.Message,
336339
taskId,
@@ -341,7 +344,7 @@ describe("TaskChannel", () => {
341344
},
342345
}
343346

344-
taskChannel.handleCommand(command)
347+
await taskChannel.handleCommand(command)
345348

346349
expect(mockTask.submitUserMessage).toHaveBeenCalledWith(
347350
command.payload.text,
@@ -351,7 +354,7 @@ describe("TaskChannel", () => {
351354
)
352355
})
353356

354-
it("should handle ApproveAsk command", () => {
357+
it("should handle ApproveAsk command", async () => {
355358
const command = {
356359
type: TaskBridgeCommandName.ApproveAsk,
357360
taskId,
@@ -361,12 +364,12 @@ describe("TaskChannel", () => {
361364
},
362365
}
363366

364-
taskChannel.handleCommand(command)
367+
await taskChannel.handleCommand(command)
365368

366369
expect(mockTask.approveAsk).toHaveBeenCalledWith(command.payload)
367370
})
368371

369-
it("should handle DenyAsk command", () => {
372+
it("should handle DenyAsk command", async () => {
370373
const command = {
371374
type: TaskBridgeCommandName.DenyAsk,
372375
taskId,
@@ -376,12 +379,12 @@ describe("TaskChannel", () => {
376379
},
377380
}
378381

379-
taskChannel.handleCommand(command)
382+
await taskChannel.handleCommand(command)
380383

381384
expect(mockTask.denyAsk).toHaveBeenCalledWith(command.payload)
382385
})
383386

384-
it("should log error for unknown task", () => {
387+
it("should log error for unknown task", async () => {
385388
const errorSpy = vi.spyOn(console, "error")
386389

387390
const command = {
@@ -393,7 +396,7 @@ describe("TaskChannel", () => {
393396
},
394397
}
395398

396-
taskChannel.handleCommand(command)
399+
await taskChannel.handleCommand(command)
397400

398401
expect(errorSpy).toHaveBeenCalledWith(`[TaskChannel] Unable to find task unknown-task`)
399402

packages/types/npm/package.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@roo-code/types",
3-
"version": "1.70.0",
3+
"version": "1.71.0",
44
"description": "TypeScript type definitions for Roo Code.",
55
"publishConfig": {
66
"access": "public",

packages/types/src/extension.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/types/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export * from "./cloud.js"
33
export * from "./codebase-index.js"
44
export * from "./events.js"
55
export * from "./experiment.js"
6-
export * from "./extension.js"
76
export * from "./followup.js"
87
export * from "./global-settings.js"
98
export * from "./history.js"

packages/types/src/telemetry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const staticAppPropertiesSchema = z.object({
7878
vscodeVersion: z.string(),
7979
platform: z.string(),
8080
editorName: z.string(),
81+
hostname: z.string().optional(),
8182
})
8283

8384
export type StaticAppProperties = z.infer<typeof staticAppPropertiesSchema>

0 commit comments

Comments
 (0)