@@ -145,6 +145,20 @@ vi.mock('../agents/subagent-tool-wrapper.js', () => ({
145145 SubagentToolWrapper : vi . fn ( ) ,
146146} ) ) ;
147147
148+ const mockCoreEvents = vi . hoisted ( ( ) => ( {
149+ emitFeedback : vi . fn ( ) ,
150+ } ) ) ;
151+
152+ const mockSetGlobalProxy = vi . hoisted ( ( ) => vi . fn ( ) ) ;
153+
154+ vi . mock ( '../utils/events.js' , ( ) => ( {
155+ coreEvents : mockCoreEvents ,
156+ } ) ) ;
157+
158+ vi . mock ( '../utils/fetch.js' , ( ) => ( {
159+ setGlobalProxy : mockSetGlobalProxy ,
160+ } ) ) ;
161+
148162import { BaseLlmClient } from '../core/baseLlmClient.js' ;
149163import { tokenLimit } from '../core/tokenLimits.js' ;
150164import { uiTelemetryService } from '../telemetry/index.js' ;
@@ -912,6 +926,63 @@ describe('Server Config (config.ts)', () => {
912926 expect ( config . getTruncateToolOutputThreshold ( ) ) . toBe ( 50000 ) ;
913927 } ) ;
914928 } ) ;
929+
930+ describe ( 'Proxy Configuration Error Handling' , ( ) => {
931+ beforeEach ( ( ) => {
932+ vi . clearAllMocks ( ) ;
933+ } ) ;
934+
935+ it ( 'should call setGlobalProxy when proxy is configured' , ( ) => {
936+ const paramsWithProxy : ConfigParameters = {
937+ ...baseParams ,
938+ proxy : 'http://proxy.example.com:8080' ,
939+ } ;
940+ new Config ( paramsWithProxy ) ;
941+
942+ expect ( mockSetGlobalProxy ) . toHaveBeenCalledWith (
943+ 'http://proxy.example.com:8080' ,
944+ ) ;
945+ } ) ;
946+
947+ it ( 'should not call setGlobalProxy when proxy is not configured' , ( ) => {
948+ new Config ( baseParams ) ;
949+
950+ expect ( mockSetGlobalProxy ) . not . toHaveBeenCalled ( ) ;
951+ } ) ;
952+
953+ it ( 'should emit error feedback when setGlobalProxy throws an error' , ( ) => {
954+ const proxyError = new Error ( 'Invalid proxy URL' ) ;
955+ mockSetGlobalProxy . mockImplementation ( ( ) => {
956+ throw proxyError ;
957+ } ) ;
958+
959+ const paramsWithProxy : ConfigParameters = {
960+ ...baseParams ,
961+ proxy : 'invalid-proxy' ,
962+ } ;
963+ new Config ( paramsWithProxy ) ;
964+
965+ expect ( mockCoreEvents . emitFeedback ) . toHaveBeenCalledWith (
966+ 'error' ,
967+ 'Invalid proxy configuration detected. Check debug drawer for more details (F12)' ,
968+ proxyError ,
969+ ) ;
970+ } ) ;
971+
972+ it ( 'should not emit error feedback when setGlobalProxy succeeds' , ( ) => {
973+ mockSetGlobalProxy . mockImplementation ( ( ) => {
974+ // Success - no error thrown
975+ } ) ;
976+
977+ const paramsWithProxy : ConfigParameters = {
978+ ...baseParams ,
979+ proxy : 'http://proxy.example.com:8080' ,
980+ } ;
981+ new Config ( paramsWithProxy ) ;
982+
983+ expect ( mockCoreEvents . emitFeedback ) . not . toHaveBeenCalled ( ) ;
984+ } ) ;
985+ } ) ;
915986} ) ;
916987
917988describe ( 'setApprovalMode with folder trust' , ( ) => {
0 commit comments