@@ -172,6 +172,7 @@ vi.mock("../../mentions/resolveImageMentions", () => ({
172172
173173import { resolveImageMentions } from "../../mentions/resolveImageMentions"
174174import { Terminal } from "../../../integrations/terminal/Terminal"
175+ import { TerminalRegistry } from "../../../integrations/terminal/TerminalRegistry"
175176
176177describe ( "webviewMessageHandler - requestLmStudioModels" , ( ) => {
177178 beforeEach ( ( ) => {
@@ -874,32 +875,78 @@ describe("webviewMessageHandler - mcpEnabled", () => {
874875describe ( "webviewMessageHandler - terminalProfile" , ( ) => {
875876 beforeEach ( ( ) => {
876877 vi . clearAllMocks ( )
878+ Terminal . setTerminalProfile ( undefined )
877879 } )
878880
879881 afterEach ( ( ) => {
882+ Terminal . setTerminalProfile ( undefined )
880883 vi . restoreAllMocks ( )
881884 } )
882885
883- it ( "bridges a saved terminalProfile from updateSettings into the process-wide terminal state " , async ( ) => {
884- const setTerminalProfileSpy = vi . spyOn ( Terminal , "setTerminalProfile " ) . mockImplementation ( ( ) => { } )
886+ it ( "normalizes and persists a saved terminalProfile, then closes stale idle terminals " , async ( ) => {
887+ const closeIdleTerminalsSpy = vi . spyOn ( TerminalRegistry , "closeIdleTerminals " ) . mockImplementation ( ( ) => { } )
885888
886889 await webviewMessageHandler ( mockClineProvider , {
887890 type : "updateSettings" ,
888- updatedSettings : { terminalProfile : "Git Bash" } ,
891+ updatedSettings : { terminalProfile : " Git Bash " } ,
889892 } )
890893
891- expect ( setTerminalProfileSpy ) . toHaveBeenCalledWith ( "Git Bash" )
894+ expect ( Terminal . getTerminalProfile ( ) ) . toBe ( "Git Bash" )
895+ expect ( mockClineProvider . contextProxy . setValue ) . toHaveBeenCalledWith ( "terminalProfile" , "Git Bash" )
896+ expect ( closeIdleTerminalsSpy ) . toHaveBeenCalledTimes ( 1 )
892897 } )
893898
894- it ( "clears the terminal profile when updateSettings sends undefined" , async ( ) => {
895- const setTerminalProfileSpy = vi . spyOn ( Terminal , "setTerminalProfile" ) . mockImplementation ( ( ) => { } )
899+ it ( "does not close idle terminals when hydration sends the unchanged profile" , async ( ) => {
900+ Terminal . setTerminalProfile ( "Git Bash" )
901+ const closeIdleTerminalsSpy = vi . spyOn ( TerminalRegistry , "closeIdleTerminals" ) . mockImplementation ( ( ) => { } )
896902
897903 await webviewMessageHandler ( mockClineProvider , {
898904 type : "updateSettings" ,
899- updatedSettings : { terminalProfile : undefined } ,
905+ updatedSettings : { terminalProfile : " Git Bash " } ,
900906 } )
901907
902- expect ( setTerminalProfileSpy ) . toHaveBeenCalledWith ( undefined )
908+ expect ( mockClineProvider . contextProxy . setValue ) . toHaveBeenCalledWith ( "terminalProfile" , "Git Bash" )
909+ expect ( closeIdleTerminalsSpy ) . not . toHaveBeenCalled ( )
910+ } )
911+
912+ it ( "clears the persisted profile when SettingsView sends the empty-string sentinel" , async ( ) => {
913+ Terminal . setTerminalProfile ( "Git Bash" )
914+ const closeIdleTerminalsSpy = vi . spyOn ( TerminalRegistry , "closeIdleTerminals" ) . mockImplementation ( ( ) => { } )
915+
916+ await webviewMessageHandler ( mockClineProvider , {
917+ type : "updateSettings" ,
918+ updatedSettings : { terminalProfile : "" } ,
919+ } )
920+
921+ expect ( Terminal . getTerminalProfile ( ) ) . toBeUndefined ( )
922+ expect ( mockClineProvider . contextProxy . setValue ) . toHaveBeenCalledWith ( "terminalProfile" , undefined )
923+ expect ( closeIdleTerminalsSpy ) . toHaveBeenCalledTimes ( 1 )
924+ } )
925+
926+ it ( "does not close idle terminals when the empty-string sentinel leaves the profile unset" , async ( ) => {
927+ const closeIdleTerminalsSpy = vi . spyOn ( TerminalRegistry , "closeIdleTerminals" ) . mockImplementation ( ( ) => { } )
928+
929+ await webviewMessageHandler ( mockClineProvider , {
930+ type : "updateSettings" ,
931+ updatedSettings : { terminalProfile : "" } ,
932+ } )
933+
934+ expect ( mockClineProvider . contextProxy . setValue ) . toHaveBeenCalledWith ( "terminalProfile" , undefined )
935+ expect ( closeIdleTerminalsSpy ) . not . toHaveBeenCalled ( )
936+ } )
937+
938+ it ( "treats non-string terminalProfile values as unset" , async ( ) => {
939+ Terminal . setTerminalProfile ( "Git Bash" )
940+ const closeIdleTerminalsSpy = vi . spyOn ( TerminalRegistry , "closeIdleTerminals" ) . mockImplementation ( ( ) => { } )
941+
942+ await webviewMessageHandler ( mockClineProvider , {
943+ type : "updateSettings" ,
944+ updatedSettings : { terminalProfile : 42 as any } ,
945+ } )
946+
947+ expect ( Terminal . getTerminalProfile ( ) ) . toBeUndefined ( )
948+ expect ( mockClineProvider . contextProxy . setValue ) . toHaveBeenCalledWith ( "terminalProfile" , undefined )
949+ expect ( closeIdleTerminalsSpy ) . toHaveBeenCalledTimes ( 1 )
903950 } )
904951} )
905952
0 commit comments