Skip to content

Commit a603b3f

Browse files
committed
test(ci): derive PR fixtures from the trusted helper closure
1 parent a62c140 commit a603b3f

3 files changed

Lines changed: 23 additions & 89 deletions

File tree

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

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { expectDefined } from "@openclaw/normalization-core";
2828
import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
2929
import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
3030
import { validReview, writeReviewArtifacts } from "./pr-review-artifact-fixture.js";
31+
import { copyPrWrapperFixture } from "./pr-wrapper-fixture.js";
3132

3233
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
3334
const freshMainTemplateDirs = useAutoCleanupTempDirTracker(afterAll);
@@ -230,45 +231,7 @@ function writeEscapedPipeHolderLauncher(repoDir: string, pidFile: string) {
230231
}
231232

232233
function installPrCliFixture(repoDir: string, env?: NodeJS.ProcessEnv) {
233-
const files = [
234-
"scripts/pr",
235-
"scripts/watch-pr-ci.mjs",
236-
"scripts/watch-pr-ci.mts",
237-
"scripts/verify-pr-hosted-gates.mjs",
238-
"scripts/verify-pr-hosted-gates.mts",
239-
"scripts/lib/plain-gh.sh",
240-
"scripts/lib/plain-gh.mjs",
241-
"scripts/lib/direct-run.mjs",
242-
"scripts/lib/record-shared.mjs",
243-
"scripts/lib/tsx-cli-shim.mjs",
244-
"scripts/lib/local-check-runtime.mts",
245-
"scripts/tsx.mjs",
246-
"scripts/pr-lib/worktree.sh",
247-
"scripts/pr-lib/operation-lock.sh",
248-
"scripts/pr-lib/process-group-runner.mjs",
249-
"scripts/pr-lib/common.sh",
250-
"scripts/pr-lib/changelog.sh",
251-
"scripts/pr-lib/gates.sh",
252-
"scripts/pr-lib/ci-dispatch.mjs",
253-
"scripts/pr-lib/crabbox-gate-contract.mjs",
254-
"scripts/pr-lib/crabbox-gate-plan.mts",
255-
"scripts/pr-lib/crabbox-merge-bypass.mjs",
256-
"scripts/pr-lib/crabbox-merge-bypass.sh",
257-
"scripts/pr-lib/push.sh",
258-
"scripts/pr-lib/review.sh",
259-
"scripts/pr-lib/review-artifacts.mjs",
260-
"scripts/pr-lib/prepare-core.sh",
261-
"scripts/pr-lib/merge.sh",
262-
"scripts/pr-lib/merge-outcome.sh",
263-
"scripts/crabbox-untrusted-bootstrap.sh",
264-
"scripts/pr-crabbox-gate-publisher.mjs",
265-
".github/workflows/pr-crabbox-gate-publisher.yml",
266-
];
267-
for (const file of files) {
268-
const target = join(repoDir, file);
269-
mkdirSync(dirname(target), { recursive: true });
270-
cpSync(join(repoRoot, file), target);
271-
}
234+
copyPrWrapperFixture(repoDir);
272235
const cli = join(repoDir, "scripts/pr");
273236
chmodSync(cli, 0o755);
274237
const binDir = join(repoDir, "isolated-bin");
@@ -334,7 +297,7 @@ function createFreshMainTemplate() {
334297
join(repoDir, ".git/info/exclude"),
335298
"/.local/\n/.worktrees/\n/isolated-bin/\n/fixture-state/\n",
336299
);
337-
git("add", "scripts", ".github");
300+
git("add", "scripts", ".github", "packages");
338301
git("commit", "-qm", "test: unmodified public PR wrapper fixture");
339302
const cachedMain = git("rev-parse", "HEAD");
340303
const canonicalTree = git("rev-parse", "HEAD^{tree}");
@@ -1811,7 +1774,7 @@ describePosix("scripts/pr per-PR operation lock", () => {
18111774
"validate_review_artifact_data() { :; }\n" +
18121775
"merge_verify() { MERGE_USE_CRABBOX_ADMIN_BYPASS=false; mark_pr_operation_side_effects_started; }\n",
18131776
);
1814-
git("add", "scripts", ".github");
1777+
git("add", "scripts", ".github", "packages");
18151778
git("commit", "-qm", "test: native cleanup fixture");
18161779
const preparedHead = git("rev-parse", "HEAD");
18171780
const origin = tempDirs.make("openclaw-pr-cleanup-origin-");

‎test/scripts/pr-wrapper-fixture.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { cpSync, mkdirSync, readFileSync } from "node:fs";
2+
import { dirname, join } from "node:path";
3+
4+
export function copyPrWrapperFixture(repoDir: string): void {
5+
const sourceRoot = process.cwd();
6+
const source = readFileSync(join(sourceRoot, "scripts/pr"), "utf8");
7+
const components = /^pr_wrapper_components=\(\n([\s\S]*?)^\)/m.exec(source)?.[1];
8+
if (!components?.trim()) {
9+
throw new Error("scripts/pr has no wrapper component declaration");
10+
}
11+
// The executable trust owner supplies the closure; fixture copies must not drift.
12+
for (const component of components.trim().split(/\s+/)) {
13+
const target = join(repoDir, component);
14+
mkdirSync(dirname(target), { recursive: true });
15+
cpSync(join(sourceRoot, component), target, { recursive: true });
16+
}
17+
}

‎test/scripts/pr-wrappers.test.ts‎

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import { tmpdir } from "node:os";
1616
import { delimiter, join } from "node:path";
1717
import { describe, expect, it } from "vitest";
18+
import { copyPrWrapperFixture } from "./pr-wrapper-fixture.js";
1819

1920
function readScript(path: string): string {
2021
return readFileSync(path, "utf8");
@@ -71,54 +72,7 @@ function makeMismatchedWrapperRepo(dispatchBody = 'echo "canonical wrapper execu
7172
git(root, ["init", "-b", "main", canonicalPath]);
7273
const canonical = realpathSync(canonicalPath);
7374
const origin = realpathSync(originPath);
74-
mkdirSync(join(canonical, ".github", "workflows"), { recursive: true });
75-
mkdirSync(join(canonical, "scripts", "lib"), { recursive: true });
76-
cpSync("scripts/pr-lib", join(canonical, "scripts", "pr-lib"), { recursive: true });
77-
writeFileSync(join(canonical, "scripts", "pr"), readScript("scripts/pr"));
78-
cpSync(
79-
".github/workflows/pr-crabbox-gate-publisher.yml",
80-
join(canonical, ".github", "workflows", "pr-crabbox-gate-publisher.yml"),
81-
);
82-
cpSync(
83-
"scripts/crabbox-untrusted-bootstrap.sh",
84-
join(canonical, "scripts", "crabbox-untrusted-bootstrap.sh"),
85-
);
86-
cpSync(
87-
"scripts/pr-crabbox-gate-publisher.mjs",
88-
join(canonical, "scripts", "pr-crabbox-gate-publisher.mjs"),
89-
);
90-
cpSync("scripts/watch-pr-ci.mjs", join(canonical, "scripts", "watch-pr-ci.mjs"));
91-
cpSync("scripts/watch-pr-ci.mts", join(canonical, "scripts", "watch-pr-ci.mts"));
92-
cpSync(
93-
"scripts/verify-pr-hosted-gates.mjs",
94-
join(canonical, "scripts", "verify-pr-hosted-gates.mjs"),
95-
);
96-
cpSync(
97-
"scripts/verify-pr-hosted-gates.mts",
98-
join(canonical, "scripts", "verify-pr-hosted-gates.mts"),
99-
);
100-
cpSync("scripts/lib/plain-gh.mjs", join(canonical, "scripts", "lib", "plain-gh.mjs"));
101-
cpSync("scripts/lib/direct-run.mjs", join(canonical, "scripts", "lib", "direct-run.mjs"));
102-
for (const file of ["record-shared.mjs", "arg-utils.mts", "arg-utils.runtime.mjs"]) {
103-
cpSync(`scripts/lib/${file}`, join(canonical, "scripts", "lib", file));
104-
}
105-
for (const extension of ["mjs", "mts"]) {
106-
const file = `check-changelog-attributions.${extension}`;
107-
cpSync(`scripts/${file}`, join(canonical, "scripts", file));
108-
}
109-
cpSync("scripts/lib/tsx-cli-shim.mjs", join(canonical, "scripts", "lib", "tsx-cli-shim.mjs"));
110-
cpSync(
111-
"scripts/lib/local-check-runtime.mts",
112-
join(canonical, "scripts", "lib", "local-check-runtime.mts"),
113-
);
114-
cpSync("scripts/tsx.mjs", join(canonical, "scripts", "tsx.mjs"));
115-
const normalizationRoot = join(canonical, "packages", "normalization-core");
116-
mkdirSync(join(normalizationRoot, "src"), { recursive: true });
117-
cpSync("packages/normalization-core/package.json", join(normalizationRoot, "package.json"));
118-
cpSync(
119-
"packages/normalization-core/src/record-coerce.ts",
120-
join(normalizationRoot, "src", "record-coerce.ts"),
121-
);
75+
copyPrWrapperFixture(canonical);
12276
writeFileSync(
12377
join(canonical, "scripts", "lib", "plain-gh.sh"),
12478
"resolve_plain_gh_bin() { printf '/usr/bin/true\\n'; }\ngh_plain() { :; }\n",

0 commit comments

Comments
 (0)