@@ -57,7 +57,9 @@ if (args[0] === "--version") {
5757 fs.appendFileSync(path.join(state, "enabled"), args[2] + "\\n");
5858} else {
5959 process.title = "openclaw-connect";
60- fs.writeFileSync(path.join(state, "launch.json"), JSON.stringify({ build: ${ JSON . stringify ( build ) } , args, cli: process.argv[1], token: process.env.CRABBOX_WORKER_BOOTSTRAP_TOKEN, setupCode: process.env.CRABBOX_WORKER_SETUP_CODE, environment: { DISPLAY: process.env.DISPLAY, DBUS_SESSION_BUS_ADDRESS: process.env.DBUS_SESSION_BUS_ADDRESS, XDG_RUNTIME_DIR: process.env.XDG_RUNTIME_DIR }, enabledPlugins: fs.readFileSync(path.join(state, "enabled"), "utf8").trim().split("\\n") }));
60+ fs.writeFileSync(path.join(state, "launch.json.tmp"), JSON.stringify({ build: ${ JSON . stringify ( build ) } , args, cli: process.argv[1], token: process.env.CRABBOX_WORKER_BOOTSTRAP_TOKEN, setupCode: process.env.CRABBOX_WORKER_SETUP_CODE, environment: { DISPLAY: process.env.DISPLAY, DBUS_SESSION_BUS_ADDRESS: process.env.DBUS_SESSION_BUS_ADDRESS, XDG_RUNTIME_DIR: process.env.XDG_RUNTIME_DIR }, enabledPlugins: fs.readFileSync(path.join(state, "enabled"), "utf8").trim().split("\\n") }));
61+ // Existence signals readiness only after the child publishes complete JSON.
62+ fs.renameSync(path.join(state, "launch.json.tmp"), path.join(state, "launch.json"));
6163 setInterval(() => {}, 60000);
6264}
6365` ,
@@ -88,7 +90,10 @@ function testHome() {
8890 return { home, stateDir, stop } ;
8991}
9092
91- async function serveArtifact ( archive : Buffer , options : { tls ?: boolean ; redirect ?: boolean } = { } ) {
93+ async function serveArtifact (
94+ archive : Buffer ,
95+ options : { tls ?: boolean ; redirect ?: boolean ; truncate ?: boolean } = { } ,
96+ ) {
9297 let tls : { cert : Buffer ; key : Buffer } | undefined ;
9398 if ( options . tls ) {
9499 const directory = tempDirs . make ( "crabbox-bootstrap-tls-" ) ;
@@ -124,6 +129,10 @@ async function serveArtifact(archive: Buffer, options: { tls?: boolean; redirect
124129 return ;
125130 }
126131 response . writeHead ( 200 , { "content-length" : archive . length } ) ;
132+ if ( options . truncate ) {
133+ response . write ( archive . subarray ( 0 , 1 ) , ( ) => response . destroy ( ) ) ;
134+ return ;
135+ }
127136 response . end ( archive ) ;
128137 } ;
129138 const server = tls ? https . createServer ( tls , handle ) : http . createServer ( handle ) ;
@@ -315,28 +324,33 @@ describe.skipIf(process.platform === "win32")("source node bootstrap", () => {
315324 30_000 ,
316325 ) ;
317326
318- it . each ( [ "digest" , "length" , "redirect" ] as const ) (
327+ it . each ( [
328+ [ "digest" , "integrity verification" ] ,
329+ [ "length" , "length does not match" ] ,
330+ [ "redirect" , "HTTP 302" ] ,
331+ [ "truncated" , "bootstrap download failed (ECONNRESET): aborted" ] ,
332+ ] as const ) (
319333 "rejects a bad archive %s before installing or starting a node" ,
320- async ( failure ) => {
334+ async ( failure , diagnosis ) => {
321335 const { home, stateDir } = testHome ( ) ;
322336 const archive = await packageFixture ( "first" ) ;
323- const { nodeBootstrap } = await serveArtifact ( archive , { redirect : failure === "redirect" } ) ;
337+ const { nodeBootstrap, authorizations } = await serveArtifact ( archive , {
338+ redirect : failure === "redirect" ,
339+ truncate : failure === "truncated" ,
340+ } ) ;
324341 const result = await enroll ( home , {
325342 ...nodeBootstrap ,
326343 ...( failure === "digest" ? { sha256 : "f" . repeat ( 64 ) } : { } ) ,
327344 ...( failure === "length" ? { bytes : archive . length + 1 } : { } ) ,
328345 } ) ;
329346 expect ( result . code ) . toBe ( 1 ) ;
330- expect ( result . output ) . toContain (
331- failure === "digest"
332- ? "integrity verification"
333- : failure === "length"
334- ? "length does not match"
335- : "HTTP 302" ,
336- ) ;
347+ expect ( result . output ) . toContain ( diagnosis ) ;
337348 expect ( result . output ) . not . toContain ( nodeBootstrap . token ) ;
349+ expect ( result . output ) . not . toContain ( setupCode ) ;
350+ expect ( authorizations ) . toEqual ( [ `Bearer ${ nodeBootstrap . token } ` ] ) ;
338351 expect ( fs . existsSync ( path . join ( stateDir , "node.pid" ) ) ) . toBe ( false ) ;
339352 expect ( fs . readdirSync ( stateDir ) ) . toEqual ( [ ] ) ;
353+ expect ( fs . readdirSync ( path . join ( home , ".openclaw-worker" , "node-runtimes" ) ) ) . toEqual ( [ ] ) ;
340354 } ,
341355 ) ;
342356
0 commit comments