Skip to content

Commit cbe19ed

Browse files
authored
fix(scripts): materialize PR worktrees before gates (#115120)
* fix(scripts): materialize PR worktrees before gates * test(agents): stabilize failed local service fixture * test(ui): isolate config route location
1 parent 9ae79ee commit cbe19ed

4 files changed

Lines changed: 80 additions & 1 deletion

File tree

‎scripts/pr-lib/worktree.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ EOF
2929
return 1
3030
}
3131

32+
ensure_full_pr_worktree_checkout() {
33+
local sparse_checkout
34+
sparse_checkout=$(git config --bool core.sparseCheckout 2>/dev/null || true)
35+
if [ "$sparse_checkout" = "true" ]; then
36+
# Prepare gates build the whole repository. Inherited sparse settings can
37+
# omit tracked transitive inputs and turn healthy PRs into false failures.
38+
git sparse-checkout disable
39+
fi
40+
}
41+
3242
enter_worktree() {
3343
local pr="$1"
3444
local reset_to_main="${2:-false}"
@@ -81,6 +91,7 @@ enter_worktree() {
8191
return 1
8292
fi
8393

94+
ensure_full_pr_worktree_checkout
8495
git fetch origin main
8596
if [ "$reset_to_main" = "true" ]; then
8697
git checkout -B "temp/pr-$pr" origin/main

‎src/agents/provider-local-service.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,9 @@ describe("provider local service", () => {
820820
const tempDir = tempDirs.make("openclaw-local-service-failed-unref-");
821821
const servicePidPath = path.join(tempDir, "service.pid");
822822
const moduleUrl = new URL("./provider-local-service.ts", import.meta.url).href;
823+
// The assertion targets diagnostic-pipe cleanup after failed readiness.
824+
// Give the nested Node child enough startup time under loaded CI.
825+
const failedServiceReadyTimeoutMs = 5_000;
823826
const serviceScript = [
824827
`const fs=require("node:fs");`,
825828
`fs.writeFileSync(${JSON.stringify(servicePidPath)},String(process.pid));`,
@@ -837,7 +840,7 @@ describe("provider local service", () => {
837840
` service: {`,
838841
` command: process.execPath,`,
839842
` args: ["-e", ${JSON.stringify(serviceScript)}],`,
840-
` readyTimeoutMs: 100,`,
843+
` readyTimeoutMs: ${failedServiceReadyTimeoutMs},`,
841844
` },`,
842845
` });`,
843846
`} catch {}`,

‎test/scripts/pr-operation-lock.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ function createRepo(nestedName?: string) {
9696
return dir;
9797
}
9898

99+
function addTrackedUiConfig(repoDir: string) {
100+
const configDir = join(repoDir, "ui", "config");
101+
mkdirSync(configDir, { recursive: true });
102+
writeFileSync(join(configDir, "control-ui-chunking.ts"), "export const chunking = true;\n");
103+
execFileSync("git", ["add", "ui/config/control-ui-chunking.ts"], { cwd: repoDir });
104+
execFileSync("git", ["commit", "-qm", "add ui config"], { cwd: repoDir });
105+
}
106+
107+
function setSparseCheckout(repoDir: string) {
108+
execFileSync("git", ["sparse-checkout", "init", "--no-cone"], { cwd: repoDir });
109+
execFileSync("git", ["sparse-checkout", "set", "--no-cone", "--stdin"], {
110+
cwd: repoDir,
111+
input: "/*\n!/*/\n/base.txt\n",
112+
});
113+
}
114+
99115
function bashSource(repoDir: string, supervised = false) {
100116
return [
101117
"set -euo pipefail",
@@ -2193,6 +2209,54 @@ describePosix("scripts/pr per-PR operation lock", () => {
21932209
).toBe("temp/pr-43");
21942210
});
21952211

2212+
it("materializes a new PR worktree inherited from a sparse checkout", () => {
2213+
const repoDir = createRepo();
2214+
addTrackedUiConfig(repoDir);
2215+
execFileSync("git", ["remote", "add", "origin", repoDir], { cwd: repoDir });
2216+
setSparseCheckout(repoDir);
2217+
const worktreeDir = join(repoDir, ".worktrees", "pr-44");
2218+
2219+
const result = runLockShell(repoDir, [
2220+
"ensure_gh_api_auth() { return 0; }",
2221+
"enter_worktree 44",
2222+
]);
2223+
2224+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
2225+
expect(existsSync(join(worktreeDir, "ui", "config", "control-ui-chunking.ts"))).toBe(true);
2226+
expect(
2227+
execFileSync("git", ["config", "--bool", "core.sparseCheckout"], {
2228+
cwd: worktreeDir,
2229+
encoding: "utf8",
2230+
}).trim(),
2231+
).toBe("false");
2232+
});
2233+
2234+
it("materializes an existing sparse PR worktree before reuse", () => {
2235+
const repoDir = createRepo();
2236+
addTrackedUiConfig(repoDir);
2237+
execFileSync("git", ["remote", "add", "origin", repoDir], { cwd: repoDir });
2238+
const worktreeDir = join(repoDir, ".worktrees", "pr-45");
2239+
execFileSync("git", ["worktree", "add", "-q", "-b", "temp/pr-45", worktreeDir], {
2240+
cwd: repoDir,
2241+
});
2242+
setSparseCheckout(worktreeDir);
2243+
expect(existsSync(join(worktreeDir, "ui", "config", "control-ui-chunking.ts"))).toBe(false);
2244+
2245+
const result = runLockShell(repoDir, [
2246+
"ensure_gh_api_auth() { return 0; }",
2247+
"enter_worktree 45",
2248+
]);
2249+
2250+
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
2251+
expect(existsSync(join(worktreeDir, "ui", "config", "control-ui-chunking.ts"))).toBe(true);
2252+
expect(
2253+
execFileSync("git", ["config", "--bool", "core.sparseCheckout"], {
2254+
cwd: worktreeDir,
2255+
encoding: "utf8",
2256+
}).trim(),
2257+
).toBe("false");
2258+
});
2259+
21962260
it("refuses a symlink alias to another registered worktree", () => {
21972261
const repoDir = createRepo();
21982262
const worktreesDir = join(repoDir, ".worktrees");

‎ui/src/pages/config/config-page.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function deferred<T>() {
2929
let localStorageMock: Storage;
3030

3131
beforeEach(() => {
32+
window.history.replaceState({}, "", "/");
3233
vi.spyOn(realtimeTalk, "switchActiveRealtimeTalkCameras").mockImplementation(
3334
switchActiveRealtimeTalkCameras,
3435
);

0 commit comments

Comments
 (0)