@@ -395,6 +395,100 @@ describe("worker tunnel manager", () => {
395395 await handle . stop ( ) ;
396396 } ) ;
397397
398+ it ( "does not downgrade an operational HEAD probe failure to plain sync" , async ( ) => {
399+ const remoteWorkspaceDir = "/home/worker/.openclaw-worker/workspaces/env/session/3" ;
400+ const localPath = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-worker-head-probe-" ) ) ;
401+ await fs . mkdir ( path . join ( localPath , ".git" ) ) ;
402+ const fake = fakeRunner ( ( argv , options ) => {
403+ if ( argv . includes ( "--show-toplevel" ) ) {
404+ return success ( `${ localPath } \n` ) ;
405+ }
406+ if ( argv . includes ( "--verify" ) ) {
407+ return {
408+ ...success ( "" , "HEAD probe timed out" ) ,
409+ code : null ,
410+ killed : true ,
411+ termination : "timeout" ,
412+ } ;
413+ }
414+ if (
415+ typeof options . input === "string" &&
416+ options . input . includes ( "unsafe worker workspace directory" )
417+ ) {
418+ return success ( `${ remoteWorkspaceDir } \n` ) ;
419+ }
420+ return undefined ;
421+ } ) ;
422+ const manager = createWorkerTunnelManager ( { runner : fake . runner } ) ;
423+ const starting = manager . start ( {
424+ environmentId : "worker:head-probe-failure" ,
425+ ownerEpoch : 3 ,
426+ ssh : SSH ,
427+ gateway : { host : "127.0.0.1" , port : 18789 } ,
428+ resolveIdentity,
429+ } ) ;
430+ await waitForStarts ( fake . starts , 1 ) ;
431+ fake . starts [ 0 ] ?. process . becomeReady ( ) ;
432+ const handle = await starting ;
433+
434+ try {
435+ await expect (
436+ handle . syncWorkspace ( { localPath, sessionId : "session:three" , generation : 3 } ) ,
437+ ) . rejects . toThrow ( "Worker workspace sync failed: HEAD probe timed out" ) ;
438+ expect ( fake . runs . some ( ( entry ) => entry . argv [ 0 ] === "rsync" ) ) . toBe ( false ) ;
439+ } finally {
440+ await handle . stop ( ) ;
441+ await fs . rm ( localPath , { recursive : true , force : true } ) ;
442+ }
443+ } ) ;
444+
445+ it ( "does not downgrade an operational repository-root probe failure to plain sync" , async ( ) => {
446+ const remoteWorkspaceDir = "/home/worker/.openclaw-worker/workspaces/env/session/4" ;
447+ const localPath = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-worker-root-probe-" ) ) ;
448+ await fs . mkdir ( path . join ( localPath , ".git" ) ) ;
449+ const fake = fakeRunner ( ( argv , options ) => {
450+ if ( argv . includes ( "--show-toplevel" ) ) {
451+ return {
452+ ...success ( "" , "root probe timed out" ) ,
453+ code : null ,
454+ killed : true ,
455+ termination : "timeout" ,
456+ } ;
457+ }
458+ if ( argv . includes ( "--verify" ) ) {
459+ return success ( "0123456789abcdef0123456789abcdef01234567\n" ) ;
460+ }
461+ if (
462+ typeof options . input === "string" &&
463+ options . input . includes ( "unsafe worker workspace directory" )
464+ ) {
465+ return success ( `${ remoteWorkspaceDir } \n` ) ;
466+ }
467+ return undefined ;
468+ } ) ;
469+ const manager = createWorkerTunnelManager ( { runner : fake . runner } ) ;
470+ const starting = manager . start ( {
471+ environmentId : "worker:root-probe-failure" ,
472+ ownerEpoch : 4 ,
473+ ssh : SSH ,
474+ gateway : { host : "127.0.0.1" , port : 18789 } ,
475+ resolveIdentity,
476+ } ) ;
477+ await waitForStarts ( fake . starts , 1 ) ;
478+ fake . starts [ 0 ] ?. process . becomeReady ( ) ;
479+ const handle = await starting ;
480+
481+ try {
482+ await expect (
483+ handle . syncWorkspace ( { localPath, sessionId : "session:four" , generation : 4 } ) ,
484+ ) . rejects . toThrow ( "Worker workspace sync failed: root probe timed out" ) ;
485+ expect ( fake . runs . some ( ( entry ) => entry . argv [ 0 ] === "rsync" ) ) . toBe ( false ) ;
486+ } finally {
487+ await handle . stop ( ) ;
488+ await fs . rm ( localPath , { recursive : true , force : true } ) ;
489+ }
490+ } ) ;
491+
398492 it ( "materializes a large dirty git workspace as a credential-free commit-capable clone" , async ( ) => {
399493 const root = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-worker-git-sync-" ) ) ;
400494 const localPath = path . join ( root , "local" ) ;
@@ -607,6 +701,9 @@ describe("worker tunnel manager", () => {
607701 fs . writeFile ( path . join ( plainPath , "hello.txt" ) , "plain\n" ) ,
608702 fs . writeFile ( path . join ( plainPath , "nested/.git/config" ) , "private metadata\n" ) ,
609703 ] ) ;
704+ // Result staging stores refs in an unborn repository for a plain workspace.
705+ // A later dispatch must keep using plain-mode sync until the user creates HEAD.
706+ await git ( plainPath , "init" ) ;
610707 await fs . mkdir ( path . join ( plainPath , "__pycache__" ) ) ;
611708 await Promise . all ( [
612709 fs . writeFile ( path . join ( plainPath , "__pycache__/fizzbuzz.pyc" ) , "derived\n" ) ,
0 commit comments