@@ -17,12 +17,13 @@ describe("Clipboard Memory Leak", () => {
1717 if ( typeof Bun . gc === "function" ) Bun . gc ( true )
1818
1919 const baselineRSS = process . memoryUsage . rss ( )
20- const iterations = 10000
20+ // Windows PowerShell is slow - use fewer iterations there
21+ const iterations = isWindows ? 100 : 10000
2122
2223 console . log ( `\nRunning ${ iterations } clipboard operations on ${ platform ( ) } ...` )
2324
2425 for ( let i = 0 ; i < iterations ; i ++ ) {
25- await Clipboard . copy ( `Memory test ${ i } - ${ "x" . repeat ( 500 ) } ` )
26+ await Clipboard . copy ( `Memory test ${ i } ` )
2627 }
2728
2829 if ( typeof Bun . gc === "function" ) Bun . gc ( true )
@@ -40,41 +41,44 @@ describe("Clipboard Memory Leak", () => {
4041 console . log ( ` Per Operation: ${ growthPerOpKB . toFixed ( 2 ) } KB` )
4142
4243 // macOS: ~9KB per op is normal baseline overhead
43- // Windows with leak: significantly higher (50KB+ per op due to process accumulation)
44- // Threshold: 25KB per operation indicates a leak
44+ // Windows with leak: significantly higher due to process accumulation
4545 expect ( growthPerOpKB ) . toBeLessThan ( 25 )
46- } )
47-
48- test . skipIf ( ! isWindows ) ( "PowerShell processes should not accumulate" , async ( ) => {
49- const { Clipboard } = await import ( "../../src/cli/cmd/tui/util/clipboard" )
50- const { execSync } = await import ( "child_process" )
51-
52- const countPowershellProcesses = ( ) => {
53- try {
54- const output = execSync ( 'tasklist /FI "IMAGENAME eq powershell.exe" /NH' , { encoding : "utf8" } )
55- return output . split ( "\n" ) . filter ( ( line ) => line . includes ( "powershell" ) ) . length
56- } catch {
57- return 0
46+ } , 600000 ) // 10 minute timeout
47+
48+ test . skipIf ( ! isWindows ) (
49+ "PowerShell processes should not accumulate" ,
50+ async ( ) => {
51+ const { Clipboard } = await import ( "../../src/cli/cmd/tui/util/clipboard" )
52+ const { execSync } = await import ( "child_process" )
53+
54+ const countPowershellProcesses = ( ) => {
55+ try {
56+ const output = execSync ( 'tasklist /FI "IMAGENAME eq powershell.exe" /NH' , { encoding : "utf8" } )
57+ return output . split ( "\n" ) . filter ( ( line ) => line . includes ( "powershell" ) ) . length
58+ } catch {
59+ return 0
60+ }
5861 }
59- }
6062
61- const baselineProcesses = countPowershellProcesses ( )
62- console . log ( `\nBaseline PowerShell processes: ${ baselineProcesses } ` )
63+ const baselineProcesses = countPowershellProcesses ( )
64+ console . log ( `\nBaseline PowerShell processes: ${ baselineProcesses } ` )
6365
64- const iterations = 10000
65- for ( let i = 0 ; i < iterations ; i ++ ) {
66- await Clipboard . copy ( `Process test ${ i } - ${ Date . now ( ) } ` )
67- }
66+ const iterations = 50
67+ for ( let i = 0 ; i < iterations ; i ++ ) {
68+ await Clipboard . copy ( `Process test ${ i } ` )
69+ }
6870
69- await new Promise ( ( r ) => setTimeout ( r , 500 ) )
71+ await new Promise ( ( r ) => setTimeout ( r , 2000 ) )
7072
71- const afterProcesses = countPowershellProcesses ( )
72- const growth = afterProcesses - baselineProcesses
73+ const afterProcesses = countPowershellProcesses ( )
74+ const growth = afterProcesses - baselineProcesses
7375
74- console . log ( `After ${ iterations } copies: ${ afterProcesses } processes` )
75- console . log ( `Process growth: ${ growth } ` )
76+ console . log ( `After ${ iterations } copies: ${ afterProcesses } processes` )
77+ console . log ( `Process growth: ${ growth } ` )
7678
77- // If leak exists, hundreds/thousands of zombie processes will accumulate
78- expect ( growth ) . toBeLessThan ( 10 )
79- } )
79+ // If leak exists, processes will accumulate
80+ expect ( growth ) . toBeLessThan ( 10 )
81+ } ,
82+ 600000 ,
83+ ) // 10 minute timeout
8084} )
0 commit comments