@@ -50,7 +50,7 @@ vi.mock("../fs", () => ({
5050} ) )
5151
5252vi . mock ( "../../core/config/ProviderSettingsManager" , async ( importOriginal ) => {
53- const originalModule = await importOriginal ( )
53+ const originalModule = await importOriginal < typeof import ( "../../core/config/ProviderSettingsManager" ) > ( )
5454 return {
5555 __esModule : true ,
5656 // We need to mock the class constructor and its methods,
@@ -76,25 +76,30 @@ vi.mock("../../core/config/CustomModesManager")
7676import { autoImportSettings } from "../autoImportSettings"
7777import * as vscode from "vscode"
7878import fsPromises from "fs/promises"
79+ import type { Mock } from "vitest"
7980import { fileExistsAtPath } from "../fs"
8081import { providerIdentifiers , retiredProviderIdentifiers } from "@roo-code/types/provider-identifiers"
82+ import { ProviderSettingsManager } from "../../core/config/ProviderSettingsManager"
83+ import { ContextProxy } from "../../core/config/ContextProxy"
84+ import { CustomModesManager } from "../../core/config/CustomModesManager"
85+ import { makeWorkspaceConfiguration } from "../../test-utils/vscode"
86+
87+ type MockedManager < T > = ReturnType < typeof vi . mocked < T > >
8188
8289describe ( "autoImportSettings" , ( ) => {
83- let mockProviderSettingsManager : any
84- let mockContextProxy : any
85- let mockCustomModesManager : any
86- let mockOutputChannel : any
90+ let mockProviderSettingsManager : MockedManager < ProviderSettingsManager >
91+ let mockContextProxy : MockedManager < ContextProxy >
92+ let mockCustomModesManager : MockedManager < CustomModesManager >
93+ let mockOutputChannel : vscode . OutputChannel
8794
8895 beforeEach ( ( ) => {
8996 // Reset all mocks
9097 vi . clearAllMocks ( )
9198
92- // Mock output channel
93- mockOutputChannel = {
94- appendLine : vi . fn ( ) ,
95- }
99+ // Double provides only appendLine, the sole OutputChannel member the SUT calls.
100+ mockOutputChannel = { appendLine : vi . fn ( ) } as unknown as vscode . OutputChannel
96101
97- // Mock provider settings manager
102+ // Double provides export/import/listConfig, the members importSettingsFromPath calls.
98103 mockProviderSettingsManager = {
99104 export : vi . fn ( ) . mockResolvedValue ( {
100105 apiConfigs : { } ,
@@ -103,19 +108,19 @@ describe("autoImportSettings", () => {
103108 } ) ,
104109 import : vi . fn ( ) . mockResolvedValue ( { success : true } ) ,
105110 listConfig : vi . fn ( ) . mockResolvedValue ( [ ] ) ,
106- }
111+ } as unknown as MockedManager < ProviderSettingsManager >
107112
108- // Mock context proxy
113+ // Double provides the ContextProxy members used by auto-import.
109114 mockContextProxy = {
110115 setValues : vi . fn ( ) . mockResolvedValue ( undefined ) ,
111116 setValue : vi . fn ( ) . mockResolvedValue ( undefined ) ,
112117 setProviderSettings : vi . fn ( ) . mockResolvedValue ( undefined ) ,
113- }
118+ } as unknown as MockedManager < ContextProxy >
114119
115- // Mock custom modes manager
120+ // Double provides only updateCustomMode, the CustomModesManager member auto-import calls.
116121 mockCustomModesManager = {
117122 updateCustomMode : vi . fn ( ) . mockResolvedValue ( undefined ) ,
118- }
123+ } as unknown as MockedManager < CustomModesManager >
119124
120125 // Reset fs mock
121126 vi . mocked ( fsPromises . readFile ) . mockReset ( )
@@ -130,9 +135,9 @@ describe("autoImportSettings", () => {
130135 } )
131136
132137 it ( "should skip auto-import when no settings path is specified" , async ( ) => {
133- vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( {
134- get : vi . fn ( ) . mockReturnValue ( "" ) ,
135- } as any )
138+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue (
139+ makeWorkspaceConfiguration ( { autoImportSettingsPath : "" } ) ,
140+ )
136141
137142 await autoImportSettings ( mockOutputChannel , {
138143 providerSettingsManager : mockProviderSettingsManager ,
@@ -148,9 +153,9 @@ describe("autoImportSettings", () => {
148153
149154 it ( "should skip auto-import when settings file does not exist" , async ( ) => {
150155 const settingsPath = "~/Documents/roo-config.json"
151- vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( {
152- get : vi . fn ( ) . mockReturnValue ( settingsPath ) ,
153- } as any )
156+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue (
157+ makeWorkspaceConfiguration ( { autoImportSettingsPath : settingsPath } ) ,
158+ )
154159
155160 // Mock fileExistsAtPath to return false
156161 vi . mocked ( fileExistsAtPath ) . mockResolvedValue ( false )
@@ -172,9 +177,9 @@ describe("autoImportSettings", () => {
172177
173178 it ( "should successfully import settings when file exists and is valid" , async ( ) => {
174179 const settingsPath = "/absolute/path/to/config.json"
175- vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( {
176- get : vi . fn ( ) . mockReturnValue ( settingsPath ) ,
177- } as any )
180+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue (
181+ makeWorkspaceConfiguration ( { autoImportSettingsPath : settingsPath } ) ,
182+ )
178183
179184 // Mock fileExistsAtPath to return true
180185 vi . mocked ( fileExistsAtPath ) . mockResolvedValue ( true )
@@ -195,7 +200,7 @@ describe("autoImportSettings", () => {
195200 } ,
196201 }
197202
198- vi . mocked ( fsPromises . readFile ) . mockResolvedValue ( JSON . stringify ( mockSettings ) as any )
203+ ; ( fsPromises . readFile as Mock ) . mockResolvedValue ( JSON . stringify ( mockSettings ) )
199204
200205 await autoImportSettings ( mockOutputChannel , {
201206 providerSettingsManager : mockProviderSettingsManager ,
@@ -216,9 +221,9 @@ describe("autoImportSettings", () => {
216221
217222 it ( "should log import warnings while still succeeding" , async ( ) => {
218223 const settingsPath = "/absolute/path/to/config.json"
219- vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( {
220- get : vi . fn ( ) . mockReturnValue ( settingsPath ) ,
221- } as any )
224+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue (
225+ makeWorkspaceConfiguration ( { autoImportSettingsPath : settingsPath } ) ,
226+ )
222227
223228 vi . mocked ( fileExistsAtPath ) . mockResolvedValue ( true )
224229
@@ -238,7 +243,7 @@ describe("autoImportSettings", () => {
238243 } ,
239244 }
240245
241- vi . mocked ( fsPromises . readFile ) . mockResolvedValue ( JSON . stringify ( mockSettings ) as any )
246+ ; ( fsPromises . readFile as Mock ) . mockResolvedValue ( JSON . stringify ( mockSettings ) )
242247
243248 await autoImportSettings ( mockOutputChannel , {
244249 providerSettingsManager : mockProviderSettingsManager ,
@@ -264,15 +269,15 @@ describe("autoImportSettings", () => {
264269
265270 it ( "should handle invalid JSON gracefully" , async ( ) => {
266271 const settingsPath = "~/config.json"
267- vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( {
268- get : vi . fn ( ) . mockReturnValue ( settingsPath ) ,
269- } as any )
272+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue (
273+ makeWorkspaceConfiguration ( { autoImportSettingsPath : settingsPath } ) ,
274+ )
270275
271276 // Mock fileExistsAtPath to return true
272277 vi . mocked ( fileExistsAtPath ) . mockResolvedValue ( true )
273278
274279 // Mock fs.readFile to return invalid JSON
275- vi . mocked ( fsPromises . readFile ) . mockResolvedValue ( "invalid json" as any )
280+ ; ( fsPromises . readFile as Mock ) . mockResolvedValue ( "invalid json" )
276281
277282 await autoImportSettings ( mockOutputChannel , {
278283 providerSettingsManager : mockProviderSettingsManager ,
@@ -291,9 +296,9 @@ describe("autoImportSettings", () => {
291296
292297 it ( "should resolve home directory paths correctly" , async ( ) => {
293298 const settingsPath = "~/Documents/config.json"
294- vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( {
295- get : vi . fn ( ) . mockReturnValue ( settingsPath ) ,
296- } as any )
299+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue (
300+ makeWorkspaceConfiguration ( { autoImportSettingsPath : settingsPath } ) ,
301+ )
297302
298303 // Mock fileExistsAtPath to return false (so we can check the resolved path)
299304 vi . mocked ( fileExistsAtPath ) . mockResolvedValue ( false )
@@ -311,9 +316,9 @@ describe("autoImportSettings", () => {
311316
312317 it ( "should handle relative paths by resolving them to home directory" , async ( ) => {
313318 const settingsPath = "Documents/config.json"
314- vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( {
315- get : vi . fn ( ) . mockReturnValue ( settingsPath ) ,
316- } as any )
319+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue (
320+ makeWorkspaceConfiguration ( { autoImportSettingsPath : settingsPath } ) ,
321+ )
317322
318323 // Mock fileExistsAtPath to return false (so we can check the resolved path)
319324 vi . mocked ( fileExistsAtPath ) . mockResolvedValue ( false )
@@ -331,9 +336,9 @@ describe("autoImportSettings", () => {
331336
332337 it ( "should handle file system errors gracefully" , async ( ) => {
333338 const settingsPath = "~/config.json"
334- vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue ( {
335- get : vi . fn ( ) . mockReturnValue ( settingsPath ) ,
336- } as any )
339+ vi . mocked ( vscode . workspace . getConfiguration ) . mockReturnValue (
340+ makeWorkspaceConfiguration ( { autoImportSettingsPath : settingsPath } ) ,
341+ )
337342
338343 // Mock fileExistsAtPath to throw an error
339344 vi . mocked ( fileExistsAtPath ) . mockRejectedValue ( new Error ( "File system error" ) )
0 commit comments