@@ -250,7 +250,7 @@ describe("ClineProvider - API Handler Rebuild Guard", () => {
250250 } )
251251
252252 describe ( "upsertProviderProfile" , ( ) => {
253- test ( "does NOT rebuild API handler when provider and model unchanged, but task.apiConfiguration is synced " , async ( ) => {
253+ test ( "rebuilds API handler when provider/ model unchanged but profile settings changed (explicit save) " , async ( ) => {
254254 // Create a task with the current config
255255 const mockTask = new Task ( {
256256 ...defaultTaskOptions ,
@@ -285,10 +285,15 @@ describe("ClineProvider - API Handler Rebuild Guard", () => {
285285 true ,
286286 )
287287
288- // Verify buildApiHandler was NOT called since provider/model unchanged
289- expect ( buildApiHandlerMock ) . not . toHaveBeenCalled ( )
290- // Verify the task's api property was NOT reassigned (still same reference)
291- expect ( mockTask . api ) . toBe ( originalApi )
288+ // Verify buildApiHandler WAS called because we force rebuild on explicit save/switch
289+ expect ( buildApiHandlerMock ) . toHaveBeenCalledWith (
290+ expect . objectContaining ( {
291+ apiProvider : "openrouter" ,
292+ openRouterModelId : "openai/gpt-4" ,
293+ } ) ,
294+ )
295+ // Verify the task's api property was reassigned (new client)
296+ expect ( mockTask . api ) . not . toBe ( originalApi )
292297 // Verify task.apiConfiguration was synchronized with non-model fields
293298 expect ( ( mockTask as any ) . apiConfiguration . openRouterModelId ) . toBe ( "openai/gpt-4" )
294299 expect ( ( mockTask as any ) . apiConfiguration . rateLimitSeconds ) . toBe ( 5 )
@@ -390,7 +395,7 @@ describe("ClineProvider - API Handler Rebuild Guard", () => {
390395 } )
391396
392397 describe ( "activateProviderProfile" , ( ) => {
393- test ( "does NOT rebuild API handler when provider and model unchanged, but task.apiConfiguration is synced " , async ( ) => {
398+ test ( "rebuilds API handler when provider/ model unchanged but settings differ (explicit profile switch) " , async ( ) => {
394399 const mockTask = new Task ( {
395400 ...defaultTaskOptions ,
396401 apiConfiguration : {
@@ -423,10 +428,15 @@ describe("ClineProvider - API Handler Rebuild Guard", () => {
423428
424429 await provider . activateProviderProfile ( { name : "test-config" } )
425430
426- // Verify buildApiHandler was NOT called
427- expect ( buildApiHandlerMock ) . not . toHaveBeenCalled ( )
428- // Verify the API reference wasn't changed
429- expect ( mockTask . api ) . toBe ( originalApi )
431+ // Verify buildApiHandler WAS called due to forced rebuild on explicit switch
432+ expect ( buildApiHandlerMock ) . toHaveBeenCalledWith (
433+ expect . objectContaining ( {
434+ apiProvider : "openrouter" ,
435+ openRouterModelId : "openai/gpt-4" ,
436+ } ) ,
437+ )
438+ // Verify the API reference changed
439+ expect ( mockTask . api ) . not . toBe ( originalApi )
430440 // Verify task.apiConfiguration was synchronized
431441 expect ( ( mockTask as any ) . apiConfiguration . openRouterModelId ) . toBe ( "openai/gpt-4" )
432442 expect ( ( mockTask as any ) . apiConfiguration . modelTemperature ) . toBe ( 0.9 )
0 commit comments