Skip to content

Commit 42bd37f

Browse files
committed
Only load marketplace data when in experiment
1 parent 8f5a474 commit 42bd37f

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,15 @@ export class ClineProvider
13461346
const allowedCommands = vscode.workspace.getConfiguration(Package.name).get<string[]>("allowedCommands") || []
13471347
const cwd = this.cwd
13481348

1349-
const marketplaceItems = (await this.marketplaceManager.getCurrentItems()) || []
1350-
const marketplaceInstalledMetadata = await this.marketplaceManager.getInstallationMetadata()
1349+
// Only fetch marketplace data if the feature is enabled
1350+
const currentExperiments = await this.getState().then((state) => state.experiments)
1351+
let marketplaceItems: any[] = []
1352+
let marketplaceInstalledMetadata: any = { project: {}, global: {} }
1353+
1354+
if (currentExperiments.marketplace) {
1355+
marketplaceItems = (await this.marketplaceManager.getCurrentItems()) || []
1356+
marketplaceInstalledMetadata = await this.marketplaceManager.getInstallationMetadata()
1357+
}
13511358

13521359
// Check if there's a system prompt override for the current mode
13531360
const currentMode = mode ?? defaultModeSlug

src/core/webview/webviewMessageHandler.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,13 @@ export const webviewMessageHandler = async (
14761476
break
14771477
}
14781478
case "filterMarketplaceItems": {
1479+
// Check if marketplace is enabled before making API calls
1480+
const { experiments } = await provider.getState()
1481+
if (!experiments.marketplace) {
1482+
console.log("Marketplace: Feature disabled, skipping API call")
1483+
break
1484+
}
1485+
14791486
if (marketplaceManager && message.filters) {
14801487
try {
14811488
await marketplaceManager.updateWithFilteredItems({
@@ -1493,6 +1500,13 @@ export const webviewMessageHandler = async (
14931500
}
14941501

14951502
case "installMarketplaceItem": {
1503+
// Check if marketplace is enabled before installing
1504+
const { experiments } = await provider.getState()
1505+
if (!experiments.marketplace) {
1506+
console.log("Marketplace: Feature disabled, skipping installation")
1507+
break
1508+
}
1509+
14961510
if (marketplaceManager && message.mpItem && message.mpInstallOptions) {
14971511
try {
14981512
const configFilePath = await marketplaceManager.installMarketplaceItem(
@@ -1522,6 +1536,13 @@ export const webviewMessageHandler = async (
15221536
}
15231537

15241538
case "removeInstalledMarketplaceItem": {
1539+
// Check if marketplace is enabled before removing
1540+
const { experiments } = await provider.getState()
1541+
if (!experiments.marketplace) {
1542+
console.log("Marketplace: Feature disabled, skipping removal")
1543+
break
1544+
}
1545+
15251546
if (marketplaceManager && message.mpItem && message.mpInstallOptions) {
15261547
try {
15271548
await marketplaceManager.removeInstalledMarketplaceItem(message.mpItem, message.mpInstallOptions)
@@ -1534,6 +1555,13 @@ export const webviewMessageHandler = async (
15341555
}
15351556

15361557
case "installMarketplaceItemWithParameters": {
1558+
// Check if marketplace is enabled before installing with parameters
1559+
const { experiments } = await provider.getState()
1560+
if (!experiments.marketplace) {
1561+
console.log("Marketplace: Feature disabled, skipping installation with parameters")
1562+
break
1563+
}
1564+
15371565
if (marketplaceManager && message.payload && "item" in message.payload && "parameters" in message.payload) {
15381566
try {
15391567
const configFilePath = await marketplaceManager.installMarketplaceItem(message.payload.item, {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { webviewMessageHandler } from "../../../core/webview/webviewMessageHandler"
2+
import { MarketplaceManager } from "../MarketplaceManager"
3+
4+
// Mock the provider and marketplace manager
5+
const mockProvider = {
6+
getState: jest.fn(),
7+
postStateToWebview: jest.fn(),
8+
} as any
9+
10+
const mockMarketplaceManager = {
11+
updateWithFilteredItems: jest.fn(),
12+
} as any
13+
14+
describe("Marketplace Setting Check", () => {
15+
beforeEach(() => {
16+
jest.clearAllMocks()
17+
})
18+
19+
it("should skip API calls when marketplace is disabled", async () => {
20+
// Mock experiments with marketplace disabled
21+
mockProvider.getState.mockResolvedValue({
22+
experiments: { marketplace: false },
23+
})
24+
25+
const message = {
26+
type: "filterMarketplaceItems" as const,
27+
filters: { type: "mcp", search: "", tags: [] },
28+
}
29+
30+
await webviewMessageHandler(mockProvider, message, mockMarketplaceManager)
31+
32+
// Should not call marketplace manager methods
33+
expect(mockMarketplaceManager.updateWithFilteredItems).not.toHaveBeenCalled()
34+
expect(mockProvider.postStateToWebview).not.toHaveBeenCalled()
35+
})
36+
37+
it("should allow API calls when marketplace is enabled", async () => {
38+
// Mock experiments with marketplace enabled
39+
mockProvider.getState.mockResolvedValue({
40+
experiments: { marketplace: true },
41+
})
42+
43+
const message = {
44+
type: "filterMarketplaceItems" as const,
45+
filters: { type: "mcp", search: "", tags: [] },
46+
}
47+
48+
await webviewMessageHandler(mockProvider, message, mockMarketplaceManager)
49+
50+
// Should call marketplace manager methods
51+
expect(mockMarketplaceManager.updateWithFilteredItems).toHaveBeenCalledWith({
52+
type: "mcp",
53+
search: "",
54+
tags: [],
55+
})
56+
expect(mockProvider.postStateToWebview).toHaveBeenCalled()
57+
})
58+
59+
it("should skip installation when marketplace is disabled", async () => {
60+
// Mock experiments with marketplace disabled
61+
mockProvider.getState.mockResolvedValue({
62+
experiments: { marketplace: false },
63+
})
64+
65+
const mockInstallMarketplaceItem = jest.fn()
66+
const mockMarketplaceManagerWithInstall = {
67+
installMarketplaceItem: mockInstallMarketplaceItem,
68+
}
69+
70+
const message = {
71+
type: "installMarketplaceItem" as const,
72+
mpItem: {
73+
id: "test-item",
74+
name: "Test Item",
75+
type: "mcp" as const,
76+
description: "Test description",
77+
content: "test content",
78+
},
79+
mpInstallOptions: { target: "project" as const },
80+
}
81+
82+
await webviewMessageHandler(mockProvider, message, mockMarketplaceManagerWithInstall as any)
83+
84+
// Should not call install method
85+
expect(mockInstallMarketplaceItem).not.toHaveBeenCalled()
86+
})
87+
})

0 commit comments

Comments
 (0)