|
1 | 1 | // PR wrapper tests cover maintainer helper command delegation. |
2 | 2 | import { spawnSync } from "node:child_process"; |
3 | | -import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 3 | +import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
4 | 4 | import { tmpdir } from "node:os"; |
5 | 5 | import { join } from "node:path"; |
6 | 6 | import { describe, expect, it } from "vitest"; |
@@ -66,6 +66,60 @@ describe("scripts/pr wrappers", () => { |
66 | 66 | expect(script).toContain('exec "$base" review-init "$@"'); |
67 | 67 | }); |
68 | 68 |
|
| 69 | + it("refuses to substitute a different canonical wrapper implementation", () => { |
| 70 | + const dir = mkdtempSync(join(tmpdir(), "openclaw-pr-wrapper-revision-")); |
| 71 | + const repo = join(dir, "repo"); |
| 72 | + const linked = join(dir, "linked"); |
| 73 | + mkdirSync(join(repo, "scripts", "lib"), { recursive: true }); |
| 74 | + mkdirSync(join(repo, "scripts", "pr-lib"), { recursive: true }); |
| 75 | + writeFileSync(join(repo, "scripts", "pr"), readScript("scripts/pr")); |
| 76 | + writeFileSync(join(repo, "scripts", "lib", "plain-gh.sh"), "# canonical\n"); |
| 77 | + writeFileSync(join(repo, "scripts", "pr-lib", "merge.sh"), "# canonical\n"); |
| 78 | + chmodSync(join(repo, "scripts", "pr"), 0o755); |
| 79 | + |
| 80 | + const git = (cwd: string, args: string[]) => |
| 81 | + spawnSync("git", args, { cwd, encoding: "utf8", stdio: "pipe" }); |
| 82 | + expect(git(repo, ["init", "-b", "main"]).status).toBe(0); |
| 83 | + expect(git(repo, ["config", "user.name", "OpenClaw Test"]).status).toBe(0); |
| 84 | + expect(git(repo, ["config", "user.email", "[email protected]"]).status).toBe(0); |
| 85 | + expect(git(repo, ["add", "scripts"]).status).toBe(0); |
| 86 | + expect(git(repo, ["commit", "-m", "test: canonical wrapper"]).status).toBe(0); |
| 87 | + expect(git(repo, ["worktree", "add", "-b", "feature", linked]).status).toBe(0); |
| 88 | + |
| 89 | + writeFileSync(join(linked, "scripts", "pr-lib", "merge.sh"), "# dirty linked\n"); |
| 90 | + const dirtyLinkedResult = spawnSync(join(linked, "scripts", "pr"), ["ls"], { |
| 91 | + cwd: linked, |
| 92 | + encoding: "utf8", |
| 93 | + }); |
| 94 | + expect(dirtyLinkedResult.status).toBe(1); |
| 95 | + expect(dirtyLinkedResult.stderr).toContain("scripts/pr wrapper files have uncommitted changes"); |
| 96 | + expect(git(linked, ["restore", "scripts/pr-lib/merge.sh"]).status).toBe(0); |
| 97 | + |
| 98 | + writeFileSync(join(repo, "scripts", "pr-lib", "merge.sh"), "# dirty canonical\n"); |
| 99 | + const dirtyResult = spawnSync(join(linked, "scripts", "pr"), ["ls"], { |
| 100 | + cwd: linked, |
| 101 | + encoding: "utf8", |
| 102 | + }); |
| 103 | + expect(dirtyResult.status).toBe(1); |
| 104 | + expect(dirtyResult.stderr).toContain("scripts/pr wrapper files have uncommitted changes"); |
| 105 | + expect(git(repo, ["restore", "scripts/pr-lib/merge.sh"]).status).toBe(0); |
| 106 | + |
| 107 | + writeFileSync(join(linked, "scripts", "pr-lib", "merge.sh"), "# linked\n"); |
| 108 | + expect(git(linked, ["add", "scripts/pr-lib/merge.sh"]).status).toBe(0); |
| 109 | + expect(git(linked, ["commit", "-m", "test: linked wrapper"]).status).toBe(0); |
| 110 | + |
| 111 | + const result = spawnSync(join(linked, "scripts", "pr"), ["ls"], { |
| 112 | + cwd: linked, |
| 113 | + encoding: "utf8", |
| 114 | + }); |
| 115 | + rmSync(dir, { recursive: true, force: true }); |
| 116 | + |
| 117 | + expect(result.status).toBe(1); |
| 118 | + expect(result.stderr).toContain( |
| 119 | + "scripts/pr implementation differs between this worktree and the canonical checkout.", |
| 120 | + ); |
| 121 | + }); |
| 122 | + |
69 | 123 | it("verifies local GitHub auth through GraphQL when REST quota is unavailable", () => { |
70 | 124 | const dir = mkdtempSync(join(tmpdir(), "openclaw-pr-auth-")); |
71 | 125 | const gh = join(dir, "gh"); |
|
0 commit comments