@@ -3,6 +3,7 @@ import fs from "node:fs";
33import path from "node:path" ;
44import { afterEach , describe , expect , it , vi } from "vitest" ;
55import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js" ;
6+ import * as processExec from "../process/exec.js" ;
67import { closeOpenClawStateDatabaseForTest } from "../state/openclaw-state-db.js" ;
78import type { WorkerConnectionEndpoint } from "../worker/worker-connection-endpoint.js" ;
89import { NodeWorkerContainerLifecycle } from "./node-worker-container-lifecycle.js" ;
@@ -33,6 +34,7 @@ const endpoint: WorkerConnectionEndpoint = {
3334const hostLabel = "openclaw.node-worker.host" ;
3435const gatewayLabel = "openclaw.node-worker.gateway" ;
3536const launchLabel = "openclaw.node-worker.launch" ;
37+ const DAEMON_TIMER_SCALE = 5 ;
3638
3739type FakeContainer = {
3840 id : string ;
@@ -151,6 +153,36 @@ function containerFixture(
151153 } ;
152154}
153155
156+ function delayDaemonRevalidation ( fixture : ReturnType < typeof containerFixture > , delayMs : number ) {
157+ fs . writeFileSync (
158+ path . join ( fixture . engineRoot , "info-delay-ms" ) ,
159+ String ( delayMs / DAEMON_TIMER_SCALE ) ,
160+ ) ;
161+ const requestedTimeouts : number [ ] = [ ] ;
162+ const runExec = processExec . runExec ;
163+ vi . spyOn ( processExec , "runExec" ) . mockImplementation ( ( command , args , options ) => {
164+ if (
165+ command === fixture . containerEngine . command &&
166+ args . length === 3 &&
167+ args [ 0 ] === "info" &&
168+ args [ 1 ] === "--format" &&
169+ args [ 2 ] === "{{.ID}}" &&
170+ typeof options === "object" &&
171+ typeof options . timeoutMs === "number"
172+ ) {
173+ // Scale both sides so the old five-second deadline still loses to the
174+ // six-second response. Execa, process signals, and other commands stay real.
175+ requestedTimeouts . push ( options . timeoutMs ) ;
176+ return runExec ( command , args , {
177+ ...options ,
178+ timeoutMs : options . timeoutMs / DAEMON_TIMER_SCALE ,
179+ } ) ;
180+ }
181+ return runExec ( command , args , options ) ;
182+ } ) ;
183+ return requestedTimeouts ;
184+ }
185+
154186async function waitForWorkerStarted ( workspaceDir : string ) : Promise < void > {
155187 await vi . waitFor (
156188 ( ) => expect ( fs . existsSync ( path . join ( workspaceDir , "worker-started" ) ) ) . toBe ( true ) ,
@@ -438,12 +470,12 @@ describe("node worker supervisor container isolation", () => {
438470 } ) ;
439471
440472 it (
441- "launches after a busy daemon takes six seconds to revalidate " ,
473+ "launches when daemon revalidation outlasts the discovery timeout " ,
442474 { timeout : 15_000 } ,
443475 async ( ) => {
444476 const fixture = containerFixture ( ) ;
445477 const input = testWorkerLaunchInput ( fixture . workspaceDir , "container-busy-daemon" ) ;
446- fs . writeFileSync ( path . join ( fixture . engineRoot , "info-delay-ms" ) , "6000" ) ;
478+ const requestedTimeouts = delayDaemonRevalidation ( fixture , 6_000 ) ;
447479
448480 try {
449481 expect ( await fixture . supervisor . launch ( input , endpoint ) ) . toMatchObject ( {
@@ -452,6 +484,7 @@ describe("node worker supervisor container isolation", () => {
452484 expect ( await waitForTerminal ( fixture . supervisor , input . launchId ) ) . toMatchObject ( {
453485 state : "completed" ,
454486 } ) ;
487+ expect ( requestedTimeouts ) . toEqual ( [ 30_000 ] ) ;
455488 } finally {
456489 await fixture . supervisor . close ( ) ;
457490 }
@@ -464,13 +497,16 @@ describe("node worker supervisor container isolation", () => {
464497 async ( ) => {
465498 const fixture = containerFixture ( ) ;
466499 const input = testWorkerLaunchInput ( fixture . workspaceDir , "container-unresponsive-daemon" ) ;
467- fs . writeFileSync ( path . join ( fixture . engineRoot , "info-delay-ms" ) , "35000" ) ;
500+ const requestedTimeouts = delayDaemonRevalidation ( fixture , 35_000 ) ;
468501
469502 try {
470503 const failed = await fixture . supervisor . launch ( input , endpoint ) ;
471504
472505 expect ( failed . state ) . toBe ( "failed" ) ;
473- expect ( failed . errorText ) . toMatch ( / C o m m a n d t i m e d o u t a f t e r \d + m i l l i s e c o n d s : / u) ;
506+ expect ( requestedTimeouts ) . toEqual ( [ 30_000 ] ) ;
507+ expect ( failed . errorText ) . toContain (
508+ `Command timed out after ${ 30_000 / DAEMON_TIMER_SCALE } milliseconds:` ,
509+ ) ;
474510 expect ( failed . errorText ) . toContain ( "docker info --format '{{.ID}}'" ) ;
475511 expect ( await fixture . supervisor . status ( input . launchId ) ) . toMatchObject ( {
476512 state : "failed" ,
0 commit comments