Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit 05a601e

Browse files
authored
Introduce testing/resetStroage endpoint and add a related action to JB (#8144)
There are some functionalities that use the local storage. We want to be able to test them. One of them is auto-edit enrolment that uses storage to mark a user as enrolled. Thanks to this change, a user will be able to reset the storage from the client and retry the features. ## Test plan 1. cmd + shift + A 2. Search for: "Cody: Reset Cody Storage" 3. Execute <!-- Required. See https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles. -->
1 parent 3ec15bf commit 05a601e

6 files changed

Lines changed: 31 additions & 0 deletions

File tree

agent/bindings/kotlin/lib/src/main/kotlin/com/sourcegraph/cody/agent/protocol_generated/CodyAgentServer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,6 @@ interface CodyAgentServer {
186186
fun secrets_didChange(params: Secrets_DidChangeParams)
187187
@JsonNotification("window/didChangeFocus")
188188
fun window_didChangeFocus(params: Window_DidChangeFocusParams)
189+
@JsonNotification("testing/resetStorage")
190+
fun testing_resetStorage(params: Null?)
189191
}

agent/src/agent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,10 @@ export class Agent extends MessageHandler implements ExtensionClient {
14171417
this.secretsDidChange.fire({ key })
14181418
})
14191419

1420+
this.registerNotification('testing/resetStorage', () => {
1421+
localStorage.resetStorage()
1422+
})
1423+
14201424
this.registerAuthenticatedRequest('featureFlags/getFeatureFlag', async ({ flagName }) => {
14211425
return featureFlagProvider.evaluateFeatureFlagEphemerally(
14221426
FeatureFlag[flagName as keyof typeof FeatureFlag]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.sourcegraph.cody
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent
4+
import com.sourcegraph.cody.agent.CodyAgentService
5+
import com.sourcegraph.common.ui.DumbAwareEDTAction
6+
7+
class ResetStorage : DumbAwareEDTAction() {
8+
override fun actionPerformed(e: AnActionEvent) {
9+
CodyAgentService.withAgent(e.project!!) { agent -> agent.server.testing_resetStorage(null) }
10+
}
11+
}

jetbrains/src/main/resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@
200200
<override-text place="GoToAction" text="Cody: Export All Chats As JSON"/>
201201
</action>
202202

203+
<action id="cody.resetStorage"
204+
class="com.sourcegraph.cody.ResetStorage"
205+
text="Reset Cody Storage"
206+
description="Reset Cody Storage">
207+
<override-text place="GoToAction" text="Cody: Reset Cody Storage"/>
208+
</action>
209+
203210
<action id="cody.openChat"
204211
class="com.sourcegraph.cody.chat.OpenChatAction"
205212
text="Open Chat"

vscode/src/jsonrpc/agent-protocol.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ export type ClientNotifications = {
378378
'secrets/didChange': [{ key: string }]
379379

380380
'window/didChangeFocus': [{ focused: boolean }]
381+
382+
'testing/resetStorage': [null]
381383
}
382384

383385
// ================

vscode/src/services/LocalStorageProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ class LocalStorage implements LocalStorageForModelPreferences {
241241
await this.set(this.AUTO_EDITS_BETA_ENROLLED, true)
242242
}
243243

244+
public async resetStorage(): Promise<void> {
245+
for (const key of this.storage.keys()) {
246+
await this.storage.update(key, undefined)
247+
}
248+
}
244249
public async setGitHubRepoAccessibility(data: GitHubDotComRepoMetaData[]): Promise<void> {
245250
await this.set(this.GIT_REPO_ACCESSIBILITY_KEY, data)
246251
}

0 commit comments

Comments
 (0)