Skip to content

Commit 439fc58

Browse files
authored
Merge pull request #427 from RooVetGit/settings_page_cleanup
Clean up the settings page
2 parents 55852c4 + 993ebaf commit 439fc58

File tree

6 files changed

+417
-425
lines changed

6 files changed

+417
-425
lines changed

src/core/config/ConfigManager.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class ConfigManager {
6464
/**
6565
* List all available configs with metadata
6666
*/
67-
async ListConfig(): Promise<ApiConfigMeta[]> {
67+
async listConfig(): Promise<ApiConfigMeta[]> {
6868
try {
6969
const config = await this.readConfig()
7070
return Object.entries(config.apiConfigs).map(([name, apiConfig]) => ({
@@ -80,7 +80,7 @@ export class ConfigManager {
8080
/**
8181
* Save a config with the given name
8282
*/
83-
async SaveConfig(name: string, config: ApiConfiguration): Promise<void> {
83+
async saveConfig(name: string, config: ApiConfiguration): Promise<void> {
8484
try {
8585
const currentConfig = await this.readConfig()
8686
const existingConfig = currentConfig.apiConfigs[name]
@@ -97,7 +97,7 @@ export class ConfigManager {
9797
/**
9898
* Load a config by name
9999
*/
100-
async LoadConfig(name: string): Promise<ApiConfiguration> {
100+
async loadConfig(name: string): Promise<ApiConfiguration> {
101101
try {
102102
const config = await this.readConfig()
103103
const apiConfig = config.apiConfigs[name]
@@ -118,7 +118,7 @@ export class ConfigManager {
118118
/**
119119
* Delete a config by name
120120
*/
121-
async DeleteConfig(name: string): Promise<void> {
121+
async deleteConfig(name: string): Promise<void> {
122122
try {
123123
const currentConfig = await this.readConfig()
124124
if (!currentConfig.apiConfigs[name]) {
@@ -140,7 +140,7 @@ export class ConfigManager {
140140
/**
141141
* Set the current active API configuration
142142
*/
143-
async SetCurrentConfig(name: string): Promise<void> {
143+
async setCurrentConfig(name: string): Promise<void> {
144144
try {
145145
const currentConfig = await this.readConfig()
146146
if (!currentConfig.apiConfigs[name]) {
@@ -157,7 +157,7 @@ export class ConfigManager {
157157
/**
158158
* Check if a config exists by name
159159
*/
160-
async HasConfig(name: string): Promise<boolean> {
160+
async hasConfig(name: string): Promise<boolean> {
161161
try {
162162
const config = await this.readConfig()
163163
return name in config.apiConfigs
@@ -169,7 +169,7 @@ export class ConfigManager {
169169
/**
170170
* Set the API config for a specific mode
171171
*/
172-
async SetModeConfig(mode: Mode, configId: string): Promise<void> {
172+
async setModeConfig(mode: Mode, configId: string): Promise<void> {
173173
try {
174174
const currentConfig = await this.readConfig()
175175
if (!currentConfig.modeApiConfigs) {
@@ -185,7 +185,7 @@ export class ConfigManager {
185185
/**
186186
* Get the API config ID for a specific mode
187187
*/
188-
async GetModeConfigId(mode: Mode): Promise<string | undefined> {
188+
async getModeConfigId(mode: Mode): Promise<string | undefined> {
189189
try {
190190
const config = await this.readConfig()
191191
return config.modeApiConfigs?.[mode]
@@ -194,10 +194,23 @@ export class ConfigManager {
194194
}
195195
}
196196

197+
/**
198+
* Get the key used for storing config in secrets
199+
*/
200+
private getConfigKey(): string {
201+
return `${this.SCOPE_PREFIX}api_config`
202+
}
203+
204+
/**
205+
* Reset all configuration by deleting the stored config from secrets
206+
*/
207+
public async resetAllConfigs(): Promise<void> {
208+
await this.context.secrets.delete(this.getConfigKey())
209+
}
210+
197211
private async readConfig(): Promise<ApiConfigData> {
198212
try {
199-
const configKey = `${this.SCOPE_PREFIX}api_config`
200-
const content = await this.context.secrets.get(configKey)
213+
const content = await this.context.secrets.get(this.getConfigKey())
201214

202215
if (!content) {
203216
return this.defaultConfig
@@ -211,9 +224,8 @@ export class ConfigManager {
211224

212225
private async writeConfig(config: ApiConfigData): Promise<void> {
213226
try {
214-
const configKey = `${this.SCOPE_PREFIX}api_config`
215227
const content = JSON.stringify(config, null, 2)
216-
await this.context.secrets.store(configKey, content)
228+
await this.context.secrets.store(this.getConfigKey(), content)
217229
} catch (error) {
218230
throw new Error(`Failed to write config to secrets: ${error}`)
219231
}

src/core/config/__tests__/ConfigManager.test.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe("ConfigManager", () => {
106106

107107
mockSecrets.get.mockResolvedValue(JSON.stringify(existingConfig))
108108

109-
const configs = await configManager.ListConfig()
109+
const configs = await configManager.listConfig()
110110
expect(configs).toEqual([
111111
{ name: "default", id: "default", apiProvider: undefined },
112112
{ name: "test", id: "test-id", apiProvider: "anthropic" },
@@ -126,14 +126,14 @@ describe("ConfigManager", () => {
126126

127127
mockSecrets.get.mockResolvedValue(JSON.stringify(emptyConfig))
128128

129-
const configs = await configManager.ListConfig()
129+
const configs = await configManager.listConfig()
130130
expect(configs).toEqual([])
131131
})
132132

133133
it("should throw error if reading from secrets fails", async () => {
134134
mockSecrets.get.mockRejectedValue(new Error("Read failed"))
135135

136-
await expect(configManager.ListConfig()).rejects.toThrow(
136+
await expect(configManager.listConfig()).rejects.toThrow(
137137
"Failed to list configs: Error: Failed to read config from secrets: Error: Read failed",
138138
)
139139
})
@@ -160,7 +160,7 @@ describe("ConfigManager", () => {
160160
apiKey: "test-key",
161161
}
162162

163-
await configManager.SaveConfig("test", newConfig)
163+
await configManager.saveConfig("test", newConfig)
164164

165165
// Get the actual stored config to check the generated ID
166166
const storedConfig = JSON.parse(mockSecrets.store.mock.calls[0][1])
@@ -207,7 +207,7 @@ describe("ConfigManager", () => {
207207
apiKey: "new-key",
208208
}
209209

210-
await configManager.SaveConfig("test", updatedConfig)
210+
await configManager.saveConfig("test", updatedConfig)
211211

212212
const expectedConfig = {
213213
currentApiConfigName: "default",
@@ -235,7 +235,7 @@ describe("ConfigManager", () => {
235235
)
236236
mockSecrets.store.mockRejectedValueOnce(new Error("Storage failed"))
237237

238-
await expect(configManager.SaveConfig("test", {})).rejects.toThrow(
238+
await expect(configManager.saveConfig("test", {})).rejects.toThrow(
239239
"Failed to save config: Error: Failed to write config to secrets: Error: Storage failed",
240240
)
241241
})
@@ -258,7 +258,7 @@ describe("ConfigManager", () => {
258258

259259
mockSecrets.get.mockResolvedValue(JSON.stringify(existingConfig))
260260

261-
await configManager.DeleteConfig("test")
261+
await configManager.deleteConfig("test")
262262

263263
// Get the stored config to check the ID
264264
const storedConfig = JSON.parse(mockSecrets.store.mock.calls[0][1])
@@ -275,7 +275,7 @@ describe("ConfigManager", () => {
275275
}),
276276
)
277277

278-
await expect(configManager.DeleteConfig("nonexistent")).rejects.toThrow("Config 'nonexistent' not found")
278+
await expect(configManager.deleteConfig("nonexistent")).rejects.toThrow("Config 'nonexistent' not found")
279279
})
280280

281281
it("should throw error when trying to delete last remaining config", async () => {
@@ -290,7 +290,7 @@ describe("ConfigManager", () => {
290290
}),
291291
)
292292

293-
await expect(configManager.DeleteConfig("default")).rejects.toThrow(
293+
await expect(configManager.deleteConfig("default")).rejects.toThrow(
294294
"Cannot delete the last remaining configuration.",
295295
)
296296
})
@@ -311,7 +311,7 @@ describe("ConfigManager", () => {
311311

312312
mockSecrets.get.mockResolvedValue(JSON.stringify(existingConfig))
313313

314-
const config = await configManager.LoadConfig("test")
314+
const config = await configManager.loadConfig("test")
315315

316316
expect(config).toEqual({
317317
apiProvider: "anthropic",
@@ -342,7 +342,7 @@ describe("ConfigManager", () => {
342342
}),
343343
)
344344

345-
await expect(configManager.LoadConfig("nonexistent")).rejects.toThrow("Config 'nonexistent' not found")
345+
await expect(configManager.loadConfig("nonexistent")).rejects.toThrow("Config 'nonexistent' not found")
346346
})
347347

348348
it("should throw error if secrets storage fails", async () => {
@@ -361,7 +361,7 @@ describe("ConfigManager", () => {
361361
)
362362
mockSecrets.store.mockRejectedValueOnce(new Error("Storage failed"))
363363

364-
await expect(configManager.LoadConfig("test")).rejects.toThrow(
364+
await expect(configManager.loadConfig("test")).rejects.toThrow(
365365
"Failed to load config: Error: Failed to write config to secrets: Error: Storage failed",
366366
)
367367
})
@@ -384,7 +384,7 @@ describe("ConfigManager", () => {
384384

385385
mockSecrets.get.mockResolvedValue(JSON.stringify(existingConfig))
386386

387-
await configManager.SetCurrentConfig("test")
387+
await configManager.setCurrentConfig("test")
388388

389389
// Get the stored config to check the structure
390390
const storedConfig = JSON.parse(mockSecrets.store.mock.calls[0][1])
@@ -404,7 +404,7 @@ describe("ConfigManager", () => {
404404
}),
405405
)
406406

407-
await expect(configManager.SetCurrentConfig("nonexistent")).rejects.toThrow(
407+
await expect(configManager.setCurrentConfig("nonexistent")).rejects.toThrow(
408408
"Config 'nonexistent' not found",
409409
)
410410
})
@@ -420,12 +420,34 @@ describe("ConfigManager", () => {
420420
)
421421
mockSecrets.store.mockRejectedValueOnce(new Error("Storage failed"))
422422

423-
await expect(configManager.SetCurrentConfig("test")).rejects.toThrow(
423+
await expect(configManager.setCurrentConfig("test")).rejects.toThrow(
424424
"Failed to set current config: Error: Failed to write config to secrets: Error: Storage failed",
425425
)
426426
})
427427
})
428428

429+
describe("ResetAllConfigs", () => {
430+
it("should delete all stored configs", async () => {
431+
// Setup initial config
432+
mockSecrets.get.mockResolvedValue(
433+
JSON.stringify({
434+
currentApiConfigName: "test",
435+
apiConfigs: {
436+
test: {
437+
apiProvider: "anthropic",
438+
id: "test-id",
439+
},
440+
},
441+
}),
442+
)
443+
444+
await configManager.resetAllConfigs()
445+
446+
// Should have called delete with the correct config key
447+
expect(mockSecrets.delete).toHaveBeenCalledWith("roo_cline_config_api_config")
448+
})
449+
})
450+
429451
describe("HasConfig", () => {
430452
it("should return true for existing config", async () => {
431453
const existingConfig: ApiConfigData = {
@@ -443,7 +465,7 @@ describe("ConfigManager", () => {
443465

444466
mockSecrets.get.mockResolvedValue(JSON.stringify(existingConfig))
445467

446-
const hasConfig = await configManager.HasConfig("test")
468+
const hasConfig = await configManager.hasConfig("test")
447469
expect(hasConfig).toBe(true)
448470
})
449471

@@ -455,14 +477,14 @@ describe("ConfigManager", () => {
455477
}),
456478
)
457479

458-
const hasConfig = await configManager.HasConfig("nonexistent")
480+
const hasConfig = await configManager.hasConfig("nonexistent")
459481
expect(hasConfig).toBe(false)
460482
})
461483

462484
it("should throw error if secrets storage fails", async () => {
463485
mockSecrets.get.mockRejectedValue(new Error("Storage failed"))
464486

465-
await expect(configManager.HasConfig("test")).rejects.toThrow(
487+
await expect(configManager.hasConfig("test")).rejects.toThrow(
466488
"Failed to check config existence: Error: Failed to read config from secrets: Error: Storage failed",
467489
)
468490
})

0 commit comments

Comments
 (0)