@@ -121,21 +121,21 @@ describe('Performance Optimizations', () => {
121
121
const generatedShellCode = shellcode ( )
122
122
123
123
// Fast path should return 0 immediately when conditions are met
124
- const fastPathSection = generatedShellCode . substring (
125
- generatedShellCode . indexOf ( 'If environment exists and has binaries, activate quickly' ) ,
126
- generatedShellCode . indexOf ( 'Skip setup if we\'ve had too many timeouts' ) ,
127
- )
124
+ // Look for the ultra-fast path activation logic
125
+ expect ( generatedShellCode ) . toContain ( 'Ultra-fast path activation completed' )
126
+ expect ( generatedShellCode ) . toContain ( 'return 0' )
128
127
129
- expect ( fastPathSection ) . toContain ( 'return 0' )
128
+ // Should have instant activation logic
129
+ expect ( generatedShellCode ) . toContain ( 'Instant activation - no external commands, no file operations' )
130
130
} )
131
131
132
132
it ( 'should include optimized binary existence check' , ( ) => {
133
133
const generatedShellCode = shellcode ( )
134
134
135
- // Should use glob expansion which is faster than ls
136
- expect ( generatedShellCode ) . toContain ( 'use glob expansion which is faster than ls ' )
137
- expect ( generatedShellCode ) . toContain ( '$(echo "$env_dir/bin"/*) ' )
138
- expect ( generatedShellCode ) . toContain ( '!= "$env_dir/bin/*" ' )
135
+ // Should have directory existence checks for fast path
136
+ expect ( generatedShellCode ) . toContain ( '-d "$env_dir/bin" ' )
137
+ expect ( generatedShellCode ) . toContain ( 'Ultra-fast path ' )
138
+ expect ( generatedShellCode ) . toContain ( 'ready=true ' )
139
139
} )
140
140
141
141
it ( 'should use optimized printf instead of slow commands in fast path' , ( ) => {
@@ -144,8 +144,8 @@ describe('Performance Optimizations', () => {
144
144
// Should use printf for activation messages
145
145
expect ( generatedShellCode ) . toContain ( 'printf "✅ Environment activated' )
146
146
147
- // Should have the basic fast path logic
148
- expect ( generatedShellCode ) . toContain ( 'If environment exists and has binaries, activate quickly ' )
147
+ // Should have fast path logic with return 0
148
+ expect ( generatedShellCode ) . toContain ( 'Ultra-fast path ' )
149
149
expect ( generatedShellCode ) . toContain ( 'return 0' )
150
150
} )
151
151
} )
@@ -218,19 +218,16 @@ describe('Performance Optimizations', () => {
218
218
it ( 'should minimize filesystem operations in fast path' , ( ) => {
219
219
const generatedShellCode = shellcode ( )
220
220
221
- // The fast path should have minimal filesystem calls
222
- const fastPathSection = generatedShellCode . substring (
223
- generatedShellCode . indexOf ( 'If environment exists and has binaries, activate quickly' ) ,
224
- generatedShellCode . indexOf ( 'Continue with setup' ) ,
225
- )
221
+ // Should have background operations to avoid blocking
222
+ expect ( generatedShellCode ) . toContain ( '>/dev/null 2>&1 &' )
223
+ expect ( generatedShellCode ) . toContain ( 'disown 2>/dev/null || true' )
226
224
227
- // Should not have expensive operations like find in fast path
228
- expect ( fastPathSection ) . not . toContain ( 'find ' )
229
- expect ( fastPathSection ) . not . toContain ( 'ls -A' )
225
+ // Should not have expensive operations in the main path
226
+ expect ( generatedShellCode ) . not . toContain ( 'find ' )
227
+ expect ( generatedShellCode ) . not . toContain ( 'ls -A' )
230
228
231
- // Should minimize directory scans
232
- const touchOperations = ( fastPathSection . match ( / t o u c h / g) || [ ] ) . length
233
- expect ( touchOperations ) . toBeLessThanOrEqual ( 2 ) // Cache file creation and timestamp sync
229
+ // Should have instant activation logic
230
+ expect ( generatedShellCode ) . toContain ( 'Instant activation - no external commands' )
234
231
} )
235
232
236
233
it ( 'should ensure cache variables are properly initialized' , ( ) => {
0 commit comments