@@ -365,6 +365,23 @@ function expectGroupedShellCommand(remoteCommand: string, command: string): void
365365const remoteChangedGateEnvPrefix =
366366 "OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 CI=1" ;
367367const remoteChangedGateExport = `export ${ remoteChangedGateEnvPrefix } ;` ;
368+ const remoteChangedGateFetch =
369+ 'git fetch -q --depth=1 origin "$openclaw_changed_gate_base:refs/remotes/origin/main"' ;
370+
371+ function expectChangedGateGitBootstrap ( remoteCommand : string ) : void {
372+ expect ( remoteCommand ) . toContain ( "command -v git" ) ;
373+ expect ( remoteCommand ) . toContain (
374+ "openclaw_changed_gate_base=${OPENCLAW_CHANGED_GATE_BASE:-abc123}" ,
375+ ) ;
376+ expect ( remoteCommand ) . toContain (
377+ 'openclaw_changed_gate_remote_base="$(git rev-parse --verify refs/remotes/origin/main 2>/dev/null || true)"' ,
378+ ) ;
379+ expect ( remoteCommand ) . toContain (
380+ '[ "$openclaw_changed_gate_remote_base" != "$openclaw_changed_gate_base" ]' ,
381+ ) ;
382+ expect ( remoteCommand ) . toContain ( "git init -q" ) ;
383+ expect ( remoteCommand ) . toContain ( remoteChangedGateFetch ) ;
384+ }
368385
369386afterAll ( ( ) => {
370387 for ( const dir of tempDirs . splice ( 0 ) ) {
@@ -1985,7 +2002,7 @@ describe.concurrent("scripts/crabbox-wrapper", () => {
19852002 expect ( result . stderr ) . toContain ( "syncing from temporary full checkout" ) ;
19862003 expect ( result . stderr ) . toContain ( "overlaying local HEAD as worktree changes from origin/main" ) ;
19872004 expect ( parseFakeCrabboxOutput ( result ) . args . join ( " " ) ) . toContain (
1988- "if ! git status --short >/dev/null 2>&1; then rm -rf .git;" ,
2005+ 'openclaw_changed_gate_remote_base="$( git rev-parse --verify refs/remotes/origin/main 2 >/dev/null || true)"' ,
19892006 ) ;
19902007 expect ( parseFakeCrabboxOutput ( result ) . cwd ) . toContain ( "openclaw-crabbox-sync-" ) ;
19912008 } ) ;
@@ -2036,10 +2053,7 @@ describe.concurrent("scripts/crabbox-wrapper", () => {
20362053 const remoteCommand = normalizeShellLineEndings ( output . args . at ( - 1 ) ?? "" ) ;
20372054 expect ( result . status ) . toBe ( 0 ) ;
20382055 expect ( output . args ) . toContain ( "--shell" ) ;
2039- expect ( remoteCommand ) . toContain ( "git init -q" ) ;
2040- expect ( remoteCommand ) . toContain (
2041- "git fetch -q --depth=1 origin abc123:refs/remotes/origin/main" ,
2042- ) ;
2056+ expectChangedGateGitBootstrap ( remoteCommand ) ;
20432057 expect ( remoteCommand ) . toContain ( "git reset --mixed --quiet refs/remotes/origin/main" ) ;
20442058 expect ( remoteCommand ) . toContain ( "git add -A" ) ;
20452059 expect ( remoteCommand ) . toContain ( "git diff --cached --quiet" ) ;
@@ -2049,6 +2063,25 @@ describe.concurrent("scripts/crabbox-wrapper", () => {
20492063 ) ;
20502064 } ) ;
20512065
2066+ it ( "rebuilds stale remote Git metadata before sparse changed gates" , ( ) => {
2067+ const result = runWrapper (
2068+ "provider: hetzner, aws, local-container, blacksmith-testbox, or cloudflare\n" ,
2069+ [ "run" , "--provider" , "aws" , "--" , "corepack" , "pnpm" , "check:changed" ] ,
2070+ {
2071+ gitResponses : {
2072+ [ GIT_CONFIG_SPARSE_KEY ] : { stdout : "true\n" } ,
2073+ [ GIT_STATUS_PORCELAIN_KEY ] : { stdout : "" } ,
2074+ [ GIT_MERGE_BASE_MAIN_HEAD_KEY ] : { stdout : "abc123\n" } ,
2075+ } ,
2076+ } ,
2077+ ) ;
2078+
2079+ const output = parseFakeCrabboxOutput ( result ) ;
2080+ const remoteCommand = normalizeShellLineEndings ( output . args . at ( - 1 ) ?? "" ) ;
2081+ expect ( result . status ) . toBe ( 0 ) ;
2082+ expectChangedGateGitBootstrap ( remoteCommand ) ;
2083+ } ) ;
2084+
20522085 it ( "bootstraps Git metadata for non-sparse changed gates on remote raw syncs" , ( ) => {
20532086 const result = runWrapper (
20542087 "provider: hetzner, aws, local-container, blacksmith-testbox, or cloudflare\n" ,
@@ -2069,9 +2102,7 @@ describe.concurrent("scripts/crabbox-wrapper", () => {
20692102 expect ( output . cwd ) . toContain ( "openclaw-crabbox-sync-" ) ;
20702103 expect ( output . args ) . toContain ( "--shell" ) ;
20712104 expect ( remoteCommand ) . toContain ( "git init -q" ) ;
2072- expect ( remoteCommand ) . toContain (
2073- "git fetch -q --depth=1 origin abc123:refs/remotes/origin/main" ,
2074- ) ;
2105+ expect ( remoteCommand ) . toContain ( remoteChangedGateFetch ) ;
20752106 expect ( remoteCommand ) . toMatch (
20762107 / & & e n v O P E N C L A W _ C H E C K _ C H A N G E D _ R E M O T E _ C H I L D = 1 O P E N C L A W _ C H A N G E D _ L A N E S _ R A W _ S Y N C = 1 C I = 1 c o r e p a c k p n p m c h e c k : c h a n g e d $ / u,
20772108 ) ;
@@ -2106,9 +2137,7 @@ describe.concurrent("scripts/crabbox-wrapper", () => {
21062137 const remoteCommand = normalizeShellLineEndings ( output . args . at ( - 1 ) ?? "" ) ;
21072138 expect ( result . status ) . toBe ( 0 ) ;
21082139 expect ( output . args ) . toContain ( "--shell" ) ;
2109- expect ( remoteCommand ) . toContain (
2110- "git fetch -q --depth=1 origin abc123:refs/remotes/origin/main" ,
2111- ) ;
2140+ expect ( remoteCommand ) . toContain ( remoteChangedGateFetch ) ;
21122141 expect ( remoteCommand ) . toMatch (
21132142 / & & e n v O P E N C L A W _ C H E C K _ C H A N G E D _ R E M O T E _ C H I L D = 1 O P E N C L A W _ C H A N G E D _ L A N E S _ R A W _ S Y N C = 1 C I = 1 c o r e p a c k p n p m c h e c k : c h a n g e d $ / u,
21142143 ) ;
@@ -2131,9 +2160,7 @@ describe.concurrent("scripts/crabbox-wrapper", () => {
21312160 const remoteCommand = normalizeShellLineEndings ( output . args . at ( - 1 ) ?? "" ) ;
21322161 expect ( result . status ) . toBe ( 0 ) ;
21332162 expect ( output . args . filter ( ( arg ) => arg === "--shell" ) ) . toHaveLength ( 1 ) ;
2134- expect ( remoteCommand ) . toContain (
2135- "git fetch -q --depth=1 origin abc123:refs/remotes/origin/main" ,
2136- ) ;
2163+ expect ( remoteCommand ) . toContain ( remoteChangedGateFetch ) ;
21372164 expect ( remoteCommand ) . toContain ( "openclaw_crabbox_bootstrap_macos_js" ) ;
21382165 expectGroupedShellCommand (
21392166 remoteCommand ,
@@ -2247,9 +2274,7 @@ describe.concurrent("scripts/crabbox-wrapper", () => {
22472274 const remoteCommand = normalizeShellLineEndings ( output . args . at ( - 1 ) ?? "" ) ;
22482275 expect ( result . status ) . toBe ( 0 ) ;
22492276 expect ( remoteCommand ) . toContain ( "git init -q" ) ;
2250- expect ( remoteCommand ) . toContain (
2251- "git fetch -q --depth=1 origin abc123:refs/remotes/origin/main" ,
2252- ) ;
2277+ expect ( remoteCommand ) . toContain ( remoteChangedGateFetch ) ;
22532278 expect ( remoteCommand ) . toContain (
22542279 `&& export OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1; ${ shellScript } ` ,
22552280 ) ;
@@ -2358,9 +2383,7 @@ describe.concurrent("scripts/crabbox-wrapper", () => {
23582383 const remoteCommand = normalizeShellLineEndings ( output . args . at ( - 1 ) ?? "" ) ;
23592384 expect ( result . status ) . toBe ( 0 ) ;
23602385 expect ( remoteCommand ) . toContain ( "git init -q" ) ;
2361- expect ( remoteCommand ) . toContain (
2362- "git fetch -q --depth=1 origin abc123:refs/remotes/origin/main" ,
2363- ) ;
2386+ expect ( remoteCommand ) . toContain ( remoteChangedGateFetch ) ;
23642387 expect ( remoteCommand ) . toContain ( `&& ${ remoteChangedGateExport } ${ shellScript } ` ) ;
23652388 } ) ;
23662389
@@ -2714,9 +2737,7 @@ describe.concurrent("scripts/crabbox-wrapper", () => {
27142737 const remoteCommand = normalizeShellLineEndings ( output . args . at ( - 1 ) ?? "" ) ;
27152738 expect ( result . status ) . toBe ( 0 ) ;
27162739 expect ( output . args . filter ( ( arg ) => arg === "--shell" ) ) . toHaveLength ( 1 ) ;
2717- expect ( remoteCommand ) . toContain (
2718- "git fetch -q --depth=1 origin abc123:refs/remotes/origin/main" ,
2719- ) ;
2740+ expect ( remoteCommand ) . toContain ( remoteChangedGateFetch ) ;
27202741 expect ( remoteCommand ) . toMatch (
27212742 / & & e x p o r t O P E N C L A W _ C H E C K _ C H A N G E D _ R E M O T E _ C H I L D = 1 O P E N C L A W _ C H A N G E D _ L A N E S _ R A W _ S Y N C = 1 ; e n v C I = 1 p n p m c h e c k : c h a n g e d $ / u,
27222743 ) ;
0 commit comments