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
This commit is contained in:
Vincent Koc
2026-07-28 23:38:17 +08:00
committed by GitHub
parent 9ae79eed2d
commit cbe19ed3be
4 changed files with 80 additions and 1 deletions
+64
View File
@@ -96,6 +96,22 @@ function createRepo(nestedName?: string) {
return dir;
}
function addTrackedUiConfig(repoDir: string) {
const configDir = join(repoDir, "ui", "config");
mkdirSync(configDir, { recursive: true });
writeFileSync(join(configDir, "control-ui-chunking.ts"), "export const chunking = true;\n");
execFileSync("git", ["add", "ui/config/control-ui-chunking.ts"], { cwd: repoDir });
execFileSync("git", ["commit", "-qm", "add ui config"], { cwd: repoDir });
}
function setSparseCheckout(repoDir: string) {
execFileSync("git", ["sparse-checkout", "init", "--no-cone"], { cwd: repoDir });
execFileSync("git", ["sparse-checkout", "set", "--no-cone", "--stdin"], {
cwd: repoDir,
input: "/*\n!/*/\n/base.txt\n",
});
}
function bashSource(repoDir: string, supervised = false) {
return [
"set -euo pipefail",
@@ -2193,6 +2209,54 @@ describePosix("scripts/pr per-PR operation lock", () => {
).toBe("temp/pr-43");
});
it("materializes a new PR worktree inherited from a sparse checkout", () => {
const repoDir = createRepo();
addTrackedUiConfig(repoDir);
execFileSync("git", ["remote", "add", "origin", repoDir], { cwd: repoDir });
setSparseCheckout(repoDir);
const worktreeDir = join(repoDir, ".worktrees", "pr-44");
const result = runLockShell(repoDir, [
"ensure_gh_api_auth() { return 0; }",
"enter_worktree 44",
]);
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
expect(existsSync(join(worktreeDir, "ui", "config", "control-ui-chunking.ts"))).toBe(true);
expect(
execFileSync("git", ["config", "--bool", "core.sparseCheckout"], {
cwd: worktreeDir,
encoding: "utf8",
}).trim(),
).toBe("false");
});
it("materializes an existing sparse PR worktree before reuse", () => {
const repoDir = createRepo();
addTrackedUiConfig(repoDir);
execFileSync("git", ["remote", "add", "origin", repoDir], { cwd: repoDir });
const worktreeDir = join(repoDir, ".worktrees", "pr-45");
execFileSync("git", ["worktree", "add", "-q", "-b", "temp/pr-45", worktreeDir], {
cwd: repoDir,
});
setSparseCheckout(worktreeDir);
expect(existsSync(join(worktreeDir, "ui", "config", "control-ui-chunking.ts"))).toBe(false);
const result = runLockShell(repoDir, [
"ensure_gh_api_auth() { return 0; }",
"enter_worktree 45",
]);
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
expect(existsSync(join(worktreeDir, "ui", "config", "control-ui-chunking.ts"))).toBe(true);
expect(
execFileSync("git", ["config", "--bool", "core.sparseCheckout"], {
cwd: worktreeDir,
encoding: "utf8",
}).trim(),
).toBe("false");
});
it("refuses a symlink alias to another registered worktree", () => {
const repoDir = createRepo();
const worktreesDir = join(repoDir, ".worktrees");