Skip to content

Commit 7ef85bf

Browse files
committed
fix(crabbox): refresh stale changed-gate git metadata
1 parent 361320c commit 7ef85bf

2 files changed

Lines changed: 49 additions & 25 deletions

File tree

‎scripts/crabbox-wrapper.mjs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,11 +1501,14 @@ function mergeBaseForChangedGate() {
15011501
function remoteGitBootstrapForChangedGate(changedGateBase) {
15021502
const quotedBase = shellQuote(changedGateBase);
15031503
return [
1504-
"if ! git status --short >/dev/null 2>&1; then",
1504+
"openclaw_changed_gate_base=${OPENCLAW_CHANGED_GATE_BASE:-" + quotedBase + "};",
1505+
'if ! command -v git >/dev/null 2>&1; then echo "git is required for OpenClaw remote changed-gate sync" >&2; exit 2; fi;',
1506+
'openclaw_changed_gate_remote_base="$(git rev-parse --verify refs/remotes/origin/main 2>/dev/null || true)";',
1507+
'if ! git status --short >/dev/null 2>&1 || [ "$openclaw_changed_gate_remote_base" != "$openclaw_changed_gate_base" ]; then',
15051508
"rm -rf .git;",
15061509
"git init -q;",
15071510
"git remote add origin https://github.com/openclaw/openclaw.git 2>/dev/null || git remote set-url origin https://github.com/openclaw/openclaw.git;",
1508-
`git fetch -q --depth=1 origin ${quotedBase}:refs/remotes/origin/main;`,
1511+
'git fetch -q --depth=1 origin "$openclaw_changed_gate_base:refs/remotes/origin/main";',
15091512
"git reset --mixed --quiet refs/remotes/origin/main;",
15101513
"git add -A;",
15111514
"if ! git diff --cached --quiet; then git -c user.name=OpenClaw -c [email protected] commit -q --no-gpg-sign -m remote-changed-gate-tree; fi;",

‎test/scripts/crabbox-wrapper.test.ts‎

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,23 @@ function expectGroupedShellCommand(remoteCommand: string, command: string): void
365365
const remoteChangedGateEnvPrefix =
366366
"OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 CI=1";
367367
const 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

369386
afterAll(() => {
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
/&& env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 CI=1 corepack pnpm check:changed$/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
/&& env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 CI=1 corepack pnpm check:changed$/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
/&& export OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1; env CI=1 pnpm check:changed$/u,
27222743
);

0 commit comments

Comments
 (0)