File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,14 @@ import { getRecentLimit } from './recent.js'
4848
4949global . __kitActionsMap = new Map < string , Action | Shortcut > ( )
5050
51+ // Raw console references captured early to avoid recursion when IPC send fails
52+ const __rawConsole = {
53+ log : global . console . log . bind ( global . console ) ,
54+ warn : global . console . warn . bind ( global . console ) ,
55+ error : global . console . error . bind ( global . console )
56+ }
57+ let __sendDiagCount = 0
58+
5159export async function initTrace ( ) {
5260 if ( process . env . KIT_TRACE || ( process . env . KIT_TRACE_DATA && ! global ?. trace ?. enabled ) ) {
5361 let timestamp = Date . now ( )
@@ -285,9 +293,31 @@ global.send = (channel: Channel, value?: any) => {
285293 args : payload
286294 } )
287295
296+ // Emit limited diagnostics in test runs on Windows to trace IPC behavior
297+ if ( process . env . KIT_TEST && process . platform === 'win32' && __sendDiagCount < 5 ) {
298+ __rawConsole . warn (
299+ `[send-diag] about to process.send channel=${ channel } pid=${ payload . pid } connected=${ ( process as any ) . connected } `
300+ )
301+ __sendDiagCount ++
302+ }
303+
288304 process . send ( payload )
289305 } catch ( e ) {
290- global . warn ( e )
306+ // Avoid recursive warn -> send loop in app context during tests
307+ if ( process . env . KIT_TEST && process . platform === 'win32' ) {
308+ try {
309+ const err : any = e
310+ __rawConsole . warn (
311+ `[send-diag] process.send threw for channel=${ channel } : ${ err ?. message || err } `
312+ )
313+ if ( err ?. stack ) __rawConsole . warn ( err . stack . split ( '\n' ) . slice ( 0 , 6 ) . join ( '\n' ) )
314+ __rawConsole . warn (
315+ `[send-diag] process.connected=${ ( process as any ) . connected } hasSend=${ typeof ( process as any ) . send === 'function' } `
316+ )
317+ } catch { }
318+ } else {
319+ global . warn ( e )
320+ }
291321 }
292322 } else {
293323 // console.log(from, ...args)
You can’t perform that action at this time.
0 commit comments