@@ -29,6 +29,24 @@ const artifact = {
2929 tarballPath : "/gateway/bundle.tgz" ,
3030} ;
3131
32+ function nodeProof ( nodeId : string , bundlePrewarm ?: number ) : NodeWorkerSupervisorNodeProof {
33+ return {
34+ ...node ,
35+ nodeId,
36+ connId : `conn-${ nodeId } ` ,
37+ ...( bundlePrewarm === undefined
38+ ? { }
39+ : {
40+ workerRuns : {
41+ bundleHash : artifact . bundleHash ,
42+ openclawVersion : artifact . openclawVersion ,
43+ protocolFeatures : artifact . protocolFeatures ,
44+ bundlePrewarm,
45+ } ,
46+ } ) ,
47+ } ;
48+ }
49+
3250describe ( "Gateway node worker bundle installer" , ( ) => {
3351 it ( "binds install dispatch to the current node proof and exact receipt" , async ( ) => {
3452 const transfer = createNodeWorkerBundleTransferService ( {
@@ -96,4 +114,37 @@ describe("Gateway node worker bundle installer", () => {
96114
97115 await expect ( ensure ( { deviceId : node . nodeId } ) ) . rejects . toThrow ( "mismatched build receipt" ) ;
98116 } ) ;
117+
118+ it ( "negotiates prewarming independently across a mixed node fleet" , async ( ) => {
119+ const transfer = createNodeWorkerBundleTransferService ( {
120+ generateToken : ( ) => String . fromCharCode ( 65 + invoke . mock . calls . length ) . repeat ( 43 ) ,
121+ } ) ;
122+ const advertising = nodeProof ( "advertising" , 7 ) ;
123+ const legacy = nodeProof ( "legacy" ) ;
124+ const invoke = vi . fn < NodeWorkerSupervisorTransport [ "invoke" ] > ( async ( request ) => ( {
125+ ok : true ,
126+ payloadJSON : JSON . stringify ( ( request . params as { build : typeof artifact } ) . build ) ,
127+ } ) ) ;
128+ const transport : NodeWorkerSupervisorTransport = {
129+ listCurrentNodes : async ( ) => [ advertising , legacy ] ,
130+ isCurrent : ( ) => true ,
131+ invoke,
132+ } ;
133+ const ensure = createGatewayNodeWorkerBundleInstaller ( {
134+ gatewayNamespace : "gateway-test" ,
135+ getTransport : ( ) => transport ,
136+ prepareBundle : async ( ) => artifact ,
137+ transfer,
138+ } ) ;
139+
140+ await expect ( ensure ( { deviceId : advertising . nodeId } ) ) . resolves . toMatchObject ( {
141+ bundleHash : artifact . bundleHash ,
142+ } ) ;
143+ await expect ( ensure ( { deviceId : legacy . nodeId } ) ) . resolves . toMatchObject ( {
144+ bundleHash : artifact . bundleHash ,
145+ } ) ;
146+
147+ expect ( invoke . mock . calls [ 0 ] ?. [ 0 ] . params ) . toMatchObject ( { bundlePrewarm : 1 } ) ;
148+ expect ( invoke . mock . calls [ 1 ] ?. [ 0 ] . params ) . not . toHaveProperty ( "bundlePrewarm" ) ;
149+ } ) ;
99150} ) ;
0 commit comments