Skip to content

Commit a4c8b17

Browse files
committed
test(scripts): route Parallels lib helpers
1 parent d87f832 commit a4c8b17

3 files changed

Lines changed: 123 additions & 1 deletion

File tree

scripts/test-projects.test-support.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3098,10 +3098,14 @@ function resolveK8sManifestTargets(changedPath) {
30983098
function resolveParallelsToolingTestTargets(changedPath) {
30993099
if (
31003100
!/^scripts\/e2e\/parallels\/[^/]+\.ts$/u.test(changedPath) &&
3101-
!/^scripts\/e2e\/parallels-(?:linux|macos|npm-update|windows)-smoke\.sh$/u.test(changedPath)
3101+
!/^scripts\/e2e\/parallels-(?:linux|macos|npm-update|windows)-smoke\.sh$/u.test(changedPath) &&
3102+
!/^scripts\/e2e\/lib\/parallels-package\/build-info-commit\.mjs$/u.test(changedPath)
31023103
) {
31033104
return null;
31043105
}
3106+
if (/^scripts\/e2e\/lib\/parallels-package\/build-info-commit\.mjs$/u.test(changedPath)) {
3107+
return ["test/scripts/parallels-lib-helpers.test.ts"];
3108+
}
31053109
const targets = ["test/scripts/parallels-smoke-model.test.ts"];
31063110
if (
31073111
[
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { spawnSync } from "node:child_process";
2+
import { chmodSync, mkdirSync, writeFileSync } from "node:fs";
3+
import path from "node:path";
4+
import { afterEach, describe, expect, it } from "vitest";
5+
import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
6+
7+
const BUILD_INFO_COMMIT_SCRIPT = path.resolve(
8+
"scripts/e2e/lib/parallels-package/build-info-commit.mjs",
9+
);
10+
const tempDirs: string[] = [];
11+
12+
afterEach(() => {
13+
cleanupTempDirs(tempDirs);
14+
});
15+
16+
function shellQuote(value: string): string {
17+
return `'${value.replaceAll("'", "'\\''")}'`;
18+
}
19+
20+
function runBash(script: string, env: NodeJS.ProcessEnv = {}) {
21+
return spawnSync("/bin/bash", ["-c", script], {
22+
cwd: process.cwd(),
23+
encoding: "utf8",
24+
env: { ...process.env, ...env },
25+
});
26+
}
27+
28+
describe("Parallels lib helpers", () => {
29+
it("reads build-info commit metadata from the current package cwd", () => {
30+
const root = makeTempDir(tempDirs, "openclaw-parallels-build-info-");
31+
32+
const missingResult = spawnSync(process.execPath, [BUILD_INFO_COMMIT_SCRIPT], {
33+
cwd: root,
34+
encoding: "utf8",
35+
env: { ...process.env },
36+
});
37+
expect(missingResult.status).toBe(0);
38+
expect(missingResult.stdout).toBe("\n");
39+
40+
mkdirSync(path.join(root, "dist"));
41+
writeFileSync(
42+
path.join(root, "dist", "build-info.json"),
43+
`${JSON.stringify({ commit: "abc123" })}\n`,
44+
);
45+
const result = spawnSync(process.execPath, [BUILD_INFO_COMMIT_SCRIPT], {
46+
cwd: root,
47+
encoding: "utf8",
48+
env: { ...process.env },
49+
});
50+
51+
expect(result.status).toBe(0);
52+
expect(result.stdout).toBe("abc123\n");
53+
});
54+
55+
it("reclaims stale package shell locks and releases current locks", () => {
56+
const root = makeTempDir(tempDirs, "openclaw-parallels-package-lock-");
57+
const lockDir = path.join(root, "build.lock");
58+
const result = runBash(`
59+
set -euo pipefail
60+
source scripts/e2e/lib/parallels-package-common.sh
61+
lock_dir=${shellQuote(lockDir)}
62+
mkdir -p "$lock_dir"
63+
printf '%s\\n' 999999999 >"$lock_dir/pid"
64+
parallels_package_acquire_build_lock "$lock_dir"
65+
owner="$(cat "$lock_dir/pid")"
66+
parallels_package_release_build_lock "$lock_dir"
67+
printf 'owner=%s exists=%s\\n' "$owner" "$([[ -e "$lock_dir" ]] && echo yes || echo no)"
68+
`);
69+
70+
expect(result.status).toBe(0);
71+
expect(result.stderr).toContain("warn: Removing stale Parallels build lock");
72+
expect(result.stdout).toMatch(/^owner=\d+ exists=no\n$/u);
73+
expect(result.stdout).not.toContain("owner=999999999");
74+
});
75+
76+
it("resolves macOS desktop users through prlctl fallbacks", () => {
77+
const root = makeTempDir(tempDirs, "openclaw-parallels-macos-common-");
78+
const binDir = path.join(root, "bin");
79+
const macHome = `${"/"}Users/alice`;
80+
mkdirSync(binDir);
81+
const prlctlShim = path.join(binDir, "prlctl");
82+
writeFileSync(
83+
prlctlShim,
84+
`#!/usr/bin/env bash
85+
args="$*"
86+
if [[ "$args" == *"/usr/bin/stat -f %Su /dev/console"* ]]; then
87+
printf 'loginwindow\\r\\n'
88+
exit 0
89+
fi
90+
if [[ "$args" == *"/usr/bin/dscl . -list /Users NFSHomeDirectory"* ]]; then
91+
printf '_daemon /var/root\\r\\nShared %s\\r\\nalice %s\\r\\n' "${`${"/"}Users/Shared`}" "${macHome}"
92+
exit 0
93+
fi
94+
if [[ "$args" == *"-read ${macHome} NFSHomeDirectory"* ]]; then
95+
printf 'NFSHomeDirectory: %s\\r\\n' "${macHome}"
96+
exit 0
97+
fi
98+
exit 1
99+
`,
100+
);
101+
chmodSync(prlctlShim, 0o755);
102+
103+
const result = runBash(
104+
`
105+
set -euo pipefail
106+
source scripts/e2e/lib/parallels-macos-common.sh
107+
printf 'user=%s\\n' "$(parallels_macos_resolve_desktop_user macos-vm)"
108+
printf 'home=%s\\n' "$(parallels_macos_resolve_desktop_home macos-vm alice)"
109+
`,
110+
{ PATH: `${binDir}${path.delimiter}${process.env.PATH ?? ""}` },
111+
);
112+
113+
expect(result.status).toBe(0);
114+
expect(result.stdout).toBe(`user=alice\nhome=${macHome}\n`);
115+
});
116+
});

test/scripts/test-projects.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,6 +2281,7 @@ describe("scripts/test-projects changed-target routing", () => {
22812281
"scripts/e2e/parallels/update-job-timeout.ts",
22822282
"scripts/e2e/parallels/windows-smoke.ts",
22832283
"scripts/e2e/parallels-windows-smoke.sh",
2284+
"scripts/e2e/lib/parallels-package/build-info-commit.mjs",
22842285
]),
22852286
).toEqual([
22862287
{
@@ -2290,6 +2291,7 @@ describe("scripts/test-projects changed-target routing", () => {
22902291
"test/scripts/parallels-smoke-model.test.ts",
22912292
"test/scripts/parallels-npm-update-smoke.test.ts",
22922293
"test/scripts/parallels-update-job-timeout.test.ts",
2294+
"test/scripts/parallels-lib-helpers.test.ts",
22932295
],
22942296
watchMode: false,
22952297
},

0 commit comments

Comments
 (0)