

























@@ -21,19 +21,34 @@ printf '%s\n' '${escapedOutput}'
2121return { root, cliPath };
2222}
232324-function resolveVersionsFromInstaller(cliPaths: string[]): string[] {
24+function resolveInstallerVersionCases(params: {
25+cliPaths: string[];
26+stdinCliPath: string;
27+stdinCwd: string;
28+}): string[] {
2529const installerPath = path.join(process.cwd(), "scripts", "install.sh");
30+const installerSource = fs.readFileSync(installerPath, "utf-8");
2631const output = execFileSync(
2732"bash",
2833[
2934"-lc",
3035`source "${installerPath}" >/dev/null 2>&1
31-for openclaw_bin in "$@"; do
36+for openclaw_bin in "\${@:3}"; do
3237 OPENCLAW_BIN="$openclaw_bin"
3338 resolve_openclaw_version
34-done`,
39+done
40+(
41+ cd "$2"
42+ FAKE_OPENCLAW_BIN="\${@:1:1}" bash -s <<'OPENCLAW_STDIN_INSTALLER'
43+${installerSource}
44+OPENCLAW_BIN="$FAKE_OPENCLAW_BIN"
45+resolve_openclaw_version
46+OPENCLAW_STDIN_INSTALLER
47+)`,
3548"openclaw-version-test",
36- ...cliPaths,
49+params.stdinCliPath,
50+params.stdinCwd,
51+ ...params.cliPaths,
3752],
3853{
3954cwd: process.cwd(),
@@ -47,44 +62,17 @@ done`,
4762return output.trimEnd().split("\n");
4863}
496450-function resolveVersionFromInstallerViaStdin(cliPath: string, cwd: string): string {
51-const installerPath = path.join(process.cwd(), "scripts", "install.sh");
52-const installerSource = fs.readFileSync(installerPath, "utf-8");
53-const output = execFileSync("bash", [], {
54- cwd,
55-encoding: "utf-8",
56-input: `${installerSource}
57-OPENCLAW_BIN="$FAKE_OPENCLAW_BIN"
58-resolve_openclaw_version
59-`,
60-env: {
61- ...process.env,
62-FAKE_OPENCLAW_BIN: cliPath,
63-OPENCLAW_INSTALL_SH_NO_RUN: "1",
64-},
65-});
66-return output.trim();
67-}
68-6965describe("install.sh version resolution", () => {
7066afterEach(() => {
7167cleanupTempDirs(tempRoots);
7268});
736974-it.runIf(process.platform !== "win32")("parses decorated and raw CLI versions", () => {
75-const decorated = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
76-const raw = withFakeCli("OpenClaw dev's build");
77-78-expect(resolveVersionsFromInstaller([decorated.cliPath, raw.cliPath])).toEqual([
79-"2026.3.10",
80-"OpenClaw dev's build",
81-]);
82-});
83-8470it.runIf(process.platform !== "win32")(
85-"does not source version helpers from cwd when installer runs via stdin",
71+"parses CLI versions and keeps stdin helpers isolated from cwd",
8672() => {
87-const fixture = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
73+const decorated = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
74+const raw = withFakeCli("OpenClaw dev's build");
75+const stdinFixture = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
88768977const hostileCwd = makeTempDir(tempRoots, "openclaw-install-stdin-");
9078const hostileHelper = path.join(
@@ -104,7 +92,13 @@ extract_openclaw_semver() {
10492"utf-8",
10593);
10694107-expect(resolveVersionFromInstallerViaStdin(fixture.cliPath, hostileCwd)).toBe("2026.3.10");
95+expect(
96+resolveInstallerVersionCases({
97+cliPaths: [decorated.cliPath, raw.cliPath],
98+stdinCliPath: stdinFixture.cliPath,
99+stdinCwd: hostileCwd,
100+}),
101+).toEqual(["2026.3.10", "OpenClaw dev's build", "2026.3.10"]);
108102},
109103);
110104});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。