























1+// Doctor Install Switch Wrapper tests cover the generated wrapper script contract.
2+import { spawnSync } from "node:child_process";
3+import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4+import path from "node:path";
5+import { afterEach, describe, expect, it } from "vitest";
6+import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
7+8+const SCRIPT_PATH = "scripts/e2e/lib/doctor-install-switch/write-wrapper.mjs";
9+const tempDirs: string[] = [];
10+11+afterEach(() => {
12+cleanupTempDirs(tempDirs);
13+});
14+15+function runWriter(args: string[]) {
16+return spawnSync(process.execPath, [SCRIPT_PATH, ...args], {
17+encoding: "utf8",
18+env: { ...process.env },
19+});
20+}
21+22+describe("doctor install switch wrapper writer", () => {
23+it("writes an executable wrapper that preserves quoted paths and arguments", () => {
24+const root = makeTempDir(tempDirs, "openclaw-doctor-wrapper-");
25+const npmDir = path.join(root, "bin with ' quote");
26+mkdirSync(npmDir);
27+28+const fakeNpm = path.join(npmDir, "npm mock");
29+const forwardedArgsPath = path.join(root, "forwarded args.json");
30+writeFileSync(
31+fakeNpm,
32+`#!/usr/bin/env node
33+const fs = require("node:fs");
34+fs.writeFileSync(${JSON.stringify(forwardedArgsPath)}, JSON.stringify(process.argv.slice(2)));
35+`,
36+{ encoding: "utf8", mode: 0o755 },
37+);
38+chmodSync(fakeNpm, 0o755);
39+40+const wrapperPath = path.join(root, "openclaw wrapper");
41+const wrapperLogPath = path.join(root, "wrapper log with ' quote.txt");
42+const writeResult = runWriter([wrapperPath, fakeNpm, wrapperLogPath]);
43+44+expect(writeResult.status).toBe(0);
45+expect(writeResult.stderr).toBe("");
46+47+const args = ["gateway", "install", "--flag=value with spaces", "it's quoted"];
48+const wrapperResult = spawnSync(wrapperPath, args, {
49+encoding: "utf8",
50+env: { ...process.env },
51+});
52+53+expect(wrapperResult.status).toBe(0);
54+expect(wrapperResult.stderr).toBe("");
55+expect(readFileSync(wrapperLogPath, "utf8")).toBe(`${args.join("\n")}\n`);
56+expect(JSON.parse(readFileSync(forwardedArgsPath, "utf8"))).toEqual(args);
57+});
58+59+it("rejects missing required arguments before writing a wrapper", () => {
60+const result = runWriter([]);
61+62+expect(result.status).toBe(1);
63+expect(result.stderr).toContain("usage: write-wrapper.mjs <wrapper-path> <npm-bin> [log-path]");
64+});
65+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。