

























@@ -0,0 +1,75 @@
1+import { spawnSync } from "node:child_process";
2+import { mkdirSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
3+import { tmpdir } from "node:os";
4+import path from "node:path";
5+import { afterEach, describe, expect, it } from "vitest";
6+7+const tempDirs: string[] = [];
8+const scriptPath = "scripts/codesign-mac-app.sh";
9+10+function makeTempDir(prefix: string): string {
11+const dir = mkdtempSync(path.join(tmpdir(), prefix));
12+tempDirs.push(dir);
13+return dir;
14+}
15+16+function entitlementTemps(dir: string): string[] {
17+return readdirSync(dir).filter((name) => name.startsWith("openclaw-entitlements"));
18+}
19+20+function runCodesign(args: string[], tempRoot: string) {
21+return spawnSync("bash", [scriptPath, ...args], {
22+cwd: process.cwd(),
23+encoding: "utf8",
24+env: {
25+ ...process.env,
26+TMPDIR: tempRoot,
27+},
28+});
29+}
30+31+afterEach(() => {
32+for (const dir of tempDirs.splice(0)) {
33+rmSync(dir, { recursive: true, force: true });
34+}
35+});
36+37+describe("codesign-mac-app temp file hygiene", () => {
38+it("does not allocate entitlement temp files for help output", () => {
39+const tempRoot = makeTempDir("openclaw-codesign-help-");
40+const result = runCodesign(["--help"], tempRoot);
41+42+expect(result.status).toBe(0);
43+expect(result.stdout).toContain("Usage: scripts/codesign-mac-app.sh");
44+expect(entitlementTemps(tempRoot)).toEqual([]);
45+});
46+47+it("does not allocate entitlement temp files before app validation", () => {
48+const tempRoot = makeTempDir("openclaw-codesign-missing-");
49+const missingApp = path.join(tempRoot, "Missing.app");
50+const result = runCodesign([missingApp], tempRoot);
51+52+expect(result.status).toBe(1);
53+expect(result.stderr).toContain("App bundle not found");
54+expect(entitlementTemps(tempRoot)).toEqual([]);
55+});
56+57+it("cleans entitlement temp files when signing fails", () => {
58+const tempRoot = makeTempDir("openclaw-codesign-fail-");
59+const app = path.join(tempRoot, "Fake.app");
60+mkdirSync(path.join(app, "Contents", "MacOS"), { recursive: true });
61+62+const result = spawnSync("bash", [scriptPath, app], {
63+cwd: process.cwd(),
64+encoding: "utf8",
65+env: {
66+ ...process.env,
67+ALLOW_ADHOC_SIGNING: "1",
68+TMPDIR: tempRoot,
69+},
70+});
71+72+expect(result.status).not.toBe(0);
73+expect(entitlementTemps(tempRoot)).toEqual([]);
74+});
75+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。