@@ -21,8 +21,24 @@ import { eagerClosureOf, eagerlyEvaluatedModules } from './eager-import-closure.
2121
2222const srcRoot = path . resolve ( import . meta. dirname , '..' ) ;
2323const LAZY_HTTP_MODULES = new Set ( [ 'node:http' , 'node:https' ] ) ;
24- /** Engines heavy enough that evaluating them on startup is a measurable regression. */
25- const LAZY_ENGINE_MODULES = new Set ( [ '@agent-device/maestro' ] ) ;
24+ /**
25+ * Engines heavy enough that evaluating them on startup is a measurable regression: the engine
26+ * package and every subpath of it except the replay backend's engine-free declaration.
27+ */
28+ function isLazyEngineModule ( specifier : string ) : boolean {
29+ return (
30+ specifier === '@agent-device/maestro' ||
31+ ( specifier . startsWith ( '@agent-device/maestro/' ) &&
32+ specifier !== '@agent-device/maestro/replay-backend-declaration' )
33+ ) ;
34+ }
35+
36+ test ( 'the lazy engine set covers the plugin subpath but not its engine-free declaration' , ( ) => {
37+ expect ( isLazyEngineModule ( '@agent-device/maestro' ) ) . toBe ( true ) ;
38+ expect ( isLazyEngineModule ( '@agent-device/maestro/replay-backend' ) ) . toBe ( true ) ;
39+ expect ( isLazyEngineModule ( '@agent-device/maestro/replay-backend-declaration' ) ) . toBe ( false ) ;
40+ expect ( isLazyEngineModule ( '@agent-device/maestroish' ) ) . toBe ( false ) ;
41+ } ) ;
2642
2743test . for ( [
2844 // --- static forms ---
@@ -104,7 +120,7 @@ test('the CLI startup import closure never evaluates the Maestro engine', () =>
104120 const offenders : string [ ] = [ ] ;
105121 for ( const file of eagerClosureOf ( path . join ( srcRoot , 'cli.ts' ) ) ) {
106122 for ( const specifier of eagerlyEvaluatedModules ( file , fs . readFileSync ( file , 'utf8' ) ) ) {
107- if ( LAZY_ENGINE_MODULES . has ( specifier ) ) {
123+ if ( isLazyEngineModule ( specifier ) ) {
108124 offenders . push ( `${ path . relative ( srcRoot , file ) } -> ${ specifier } ` ) ;
109125 }
110126 }
@@ -126,9 +142,7 @@ test('the replay command source closure keeps Maestro behind flow selection', ()
126142
127143 expect ( replayClosure ) . toContain ( sourceBundle ) ;
128144 for ( const file of replayClosure ) {
129- if (
130- eagerlyEvaluatedModules ( file , fs . readFileSync ( file , 'utf8' ) ) . includes ( '@agent-device/maestro' )
131- ) {
145+ if ( eagerlyEvaluatedModules ( file , fs . readFileSync ( file , 'utf8' ) ) . some ( isLazyEngineModule ) ) {
132146 offenders . push ( path . relative ( srcRoot , file ) ) ;
133147 }
134148 }
0 commit comments