@@ -34,8 +34,11 @@ function expectDangerousTextStep(command: string): void {
3434 ) . toBeDefined ( ) ;
3535}
3636
37- function expectWorktreeExplainBlocked ( command : ( mainWorktree : string ) => string , reason : string ) {
38- withLinkedWorktreeFixture ( ( fixture ) => {
37+ async function expectWorktreeExplainBlocked (
38+ command : ( mainWorktree : string ) => string ,
39+ reason : string ,
40+ ) {
41+ await withLinkedWorktreeFixture ( ( fixture ) => {
3942 withEnv ( { SAFETY_NET_WORKTREE : '1' } , ( ) => {
4043 const result = explainCommand ( command ( toShellPath ( fixture . mainWorktree ) ) , {
4144 cwd : fixture . linkedWorktree ,
@@ -394,22 +397,14 @@ describe('explainCommand shell wrapper edge cases', () => {
394397
395398describe ( 'explainCommand max recursion depth' , ( ) => {
396399 test ( 'deeply nested command hits max recursion' , ( ) => {
397- const deepNested =
398- 'bash -c "bash -c \\"bash -c \\\\\\"bash -c \\\\\\\\\\\\\\"bash -c \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"echo deep\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\"\\\\\\"\\"" ' ;
399- const steps = getTraceSteps ( explainCommand ( deepNested ) ) ;
400- expect (
401- steps . filter ( ( s ) => s . type === 'recurse' ) . length +
402- ( recursionLimitErrorStep ( deepNested ) ? 1 : 0 ) ,
403- ) . toBeGreaterThan ( 0 ) ;
400+ const deepNested = nestedBashCommand ( 'echo deep' , 10 ) ;
401+ expect ( recursionLimitErrorStep ( deepNested ) ) . toBeTruthy ( ) ;
404402 } ) ;
405403
406404 test ( 'hits exact max recursion depth of 5' , ( ) => {
407405 const level5 =
408406 'bash -c "bash -c \\"bash -c \\\\\\"bash -c \\\\\\\\\\\\\\"bash -c \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"echo hi\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\"\\\\\\"\\"" ' ;
409- const steps = getTraceSteps ( explainCommand ( level5 ) ) ;
410- expect (
411- steps . filter ( ( s ) => s . type === 'recurse' ) . length >= 3 || recursionLimitErrorStep ( level5 ) ,
412- ) . toBeTruthy ( ) ;
407+ expect ( recursionLimitErrorStep ( level5 ) ) . toBeFalsy ( ) ;
413408 } ) ;
414409
415410 test ( 'hits max recursion depth with 10 nested bash -c calls' , ( ) => {
@@ -581,54 +576,57 @@ describe('explainCommand fallback scan with find', () => {
581576} ) ;
582577
583578describe ( 'explainCommand worktree parity' , ( ) => {
584- test ( 'uses wrapper cwd when explaining worktree relaxation' , ( ) => {
585- expectWorktreeExplainBlocked ( ( main ) => `env -C ${ main } git reset --hard` , 'git reset --hard' ) ;
579+ test ( 'uses wrapper cwd when explaining worktree relaxation' , async ( ) => {
580+ await expectWorktreeExplainBlocked (
581+ ( main ) => `env -C ${ main } git reset --hard` ,
582+ 'git reset --hard' ,
583+ ) ;
586584 } ) ;
587585
588- test ( 'carries exported git context overrides into later segments' , ( ) => {
589- expectWorktreeExplainBlocked (
586+ test ( 'carries exported git context overrides into later segments' , async ( ) => {
587+ await expectWorktreeExplainBlocked (
590588 ( main ) => `export GIT_WORK_TREE=${ main } ; git reset --hard` ,
591589 'git reset --hard' ,
592590 ) ;
593591 } ) ;
594592
595- test ( 'passes wrapper cwd into recursive explain analysis' , ( ) => {
596- expectWorktreeExplainBlocked (
593+ test ( 'passes wrapper cwd into recursive explain analysis' , async ( ) => {
594+ await expectWorktreeExplainBlocked (
597595 ( main ) => `env -C ${ main } sh -c "git reset --hard"` ,
598596 'git reset --hard' ,
599597 ) ;
600598 } ) ;
601599
602- test ( 'passes stripped env into recursive explain analysis' , ( ) => {
603- expectWorktreeExplainBlocked (
600+ test ( 'passes stripped env into recursive explain analysis' , async ( ) => {
601+ await expectWorktreeExplainBlocked (
604602 ( main ) => `GIT_WORK_TREE=${ main } sh -c "git reset --hard"` ,
605603 'git reset --hard' ,
606604 ) ;
607605 } ) ;
608606
609- test ( 'carries nested exported git context overrides across inner segments' , ( ) => {
610- expectWorktreeExplainBlocked (
607+ test ( 'carries nested exported git context overrides across inner segments' , async ( ) => {
608+ await expectWorktreeExplainBlocked (
611609 ( main ) => `sh -c "export GIT_WORK_TREE=${ main } ; git reset --hard"` ,
612610 'git reset --hard' ,
613611 ) ;
614612 } ) ;
615613
616- test ( 'includes keyword-export git context overrides in current segment' , ( ) => {
617- expectWorktreeExplainBlocked (
614+ test ( 'includes keyword-export git context overrides in current segment' , async ( ) => {
615+ await expectWorktreeExplainBlocked (
618616 ( main ) => `set -k; git restore file.txt GIT_WORK_TREE=${ main } ` ,
619617 'git restore' ,
620618 ) ;
621619 } ) ;
622620
623- test ( 'includes nested keyword-export git context overrides in current segment' , ( ) => {
624- expectWorktreeExplainBlocked (
621+ test ( 'includes nested keyword-export git context overrides in current segment' , async ( ) => {
622+ await expectWorktreeExplainBlocked (
625623 ( main ) => `sh -c "set -k; git restore file.txt GIT_WORK_TREE=${ main } "` ,
626624 'git restore' ,
627625 ) ;
628626 } ) ;
629627
630- test ( 'honors parallel nested overrides when explaining remote commands' , ( ) => {
631- withLinkedWorktreeFixture ( ( fixture ) => {
628+ test ( 'honors parallel nested overrides when explaining remote commands' , async ( ) => {
629+ await withLinkedWorktreeFixture ( ( fixture ) => {
632630 withEnv ( { SAFETY_NET_WORKTREE : '1' } , ( ) => {
633631 const result = explainCommand ( 'parallel -S host sh -c "git reset --hard" ::: x' , {
634632 cwd : fixture . linkedWorktree ,
@@ -640,8 +638,8 @@ describe('explainCommand worktree parity', () => {
640638 } ) ;
641639 } ) ;
642640
643- test ( 'does not report worktree relaxation for fallback embedded git' , ( ) => {
644- withLinkedWorktreeFixture ( ( fixture ) => {
641+ test ( 'does not report worktree relaxation for fallback embedded git' , async ( ) => {
642+ await withLinkedWorktreeFixture ( ( fixture ) => {
645643 withEnv ( { SAFETY_NET_WORKTREE : '1' } , ( ) => {
646644 const result = explainCommand ( 'ssh host git clean -f' , { cwd : fixture . linkedWorktree } ) ;
647645 const worktreeStep = result . trace . segments
0 commit comments