mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 21:20:22 +00:00
fix: stabilize npm owner update test on Windows (#60153) (thanks @jayeshp19)
This commit is contained in:
@@ -137,52 +137,61 @@ describe("update global helpers", () => {
|
||||
});
|
||||
|
||||
it("prefers the owning npm prefix when PATH npm points at a different global root", async () => {
|
||||
const base = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-update-npm-prefix-"));
|
||||
const brewPrefix = path.join(base, "opt", "homebrew");
|
||||
const brewBin = path.join(brewPrefix, "bin");
|
||||
const brewRoot = path.join(brewPrefix, "lib", "node_modules");
|
||||
const pkgRoot = path.join(brewRoot, "openclaw");
|
||||
const pathNpmRoot = path.join(base, "nvm", "lib", "node_modules");
|
||||
const brewNpm = path.join(brewBin, process.platform === "win32" ? "npm.cmd" : "npm");
|
||||
await fs.mkdir(pkgRoot, { recursive: true });
|
||||
await fs.mkdir(brewBin, { recursive: true });
|
||||
await fs.writeFile(brewNpm, "", "utf8");
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("darwin");
|
||||
try {
|
||||
const base = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-update-npm-prefix-"));
|
||||
const brewPrefix = path.join(base, "opt", "homebrew");
|
||||
const brewBin = path.join(brewPrefix, "bin");
|
||||
const brewRoot = path.join(brewPrefix, "lib", "node_modules");
|
||||
const pkgRoot = path.join(brewRoot, "openclaw");
|
||||
const pathNpmRoot = path.join(base, "nvm", "lib", "node_modules");
|
||||
const brewNpm = path.join(brewBin, "npm");
|
||||
await fs.mkdir(pkgRoot, { recursive: true });
|
||||
await fs.mkdir(brewBin, { recursive: true });
|
||||
await fs.writeFile(brewNpm, "", "utf8");
|
||||
|
||||
const runCommand: CommandRunner = async (argv) => {
|
||||
if (argv[0] === "npm") {
|
||||
return { stdout: `${pathNpmRoot}\n`, stderr: "", code: 0 };
|
||||
}
|
||||
if (argv[0] === brewNpm) {
|
||||
return { stdout: `${brewRoot}\n`, stderr: "", code: 0 };
|
||||
}
|
||||
if (argv[0] === "pnpm") {
|
||||
return { stdout: "", stderr: "", code: 1 };
|
||||
}
|
||||
throw new Error(`unexpected command: ${argv.join(" ")}`);
|
||||
};
|
||||
const runCommand: CommandRunner = async (argv) => {
|
||||
if (argv[0] === "npm") {
|
||||
return { stdout: `${pathNpmRoot}\n`, stderr: "", code: 0 };
|
||||
}
|
||||
if (argv[0] === brewNpm) {
|
||||
return { stdout: `${brewRoot}\n`, stderr: "", code: 0 };
|
||||
}
|
||||
if (argv[0] === "pnpm") {
|
||||
return { stdout: "", stderr: "", code: 1 };
|
||||
}
|
||||
throw new Error(`unexpected command: ${argv.join(" ")}`);
|
||||
};
|
||||
|
||||
await expect(detectGlobalInstallManagerForRoot(runCommand, pkgRoot, 1000)).resolves.toBe("npm");
|
||||
await expect(resolveGlobalRoot("npm", runCommand, 1000, pkgRoot)).resolves.toBe(brewRoot);
|
||||
await expect(resolveGlobalPackageRoot("npm", runCommand, 1000, pkgRoot)).resolves.toBe(pkgRoot);
|
||||
expect(globalInstallArgs("npm", "openclaw@latest", pkgRoot)).toEqual([
|
||||
brewNpm,
|
||||
"i",
|
||||
"-g",
|
||||
"openclaw@latest",
|
||||
"--no-fund",
|
||||
"--no-audit",
|
||||
"--loglevel=error",
|
||||
]);
|
||||
expect(globalInstallFallbackArgs("npm", "openclaw@latest", pkgRoot)).toEqual([
|
||||
brewNpm,
|
||||
"i",
|
||||
"-g",
|
||||
"openclaw@latest",
|
||||
"--omit=optional",
|
||||
"--no-fund",
|
||||
"--no-audit",
|
||||
"--loglevel=error",
|
||||
]);
|
||||
await expect(detectGlobalInstallManagerForRoot(runCommand, pkgRoot, 1000)).resolves.toBe(
|
||||
"npm",
|
||||
);
|
||||
await expect(resolveGlobalRoot("npm", runCommand, 1000, pkgRoot)).resolves.toBe(brewRoot);
|
||||
await expect(resolveGlobalPackageRoot("npm", runCommand, 1000, pkgRoot)).resolves.toBe(
|
||||
pkgRoot,
|
||||
);
|
||||
expect(globalInstallArgs("npm", "openclaw@latest", pkgRoot)).toEqual([
|
||||
brewNpm,
|
||||
"i",
|
||||
"-g",
|
||||
"openclaw@latest",
|
||||
"--no-fund",
|
||||
"--no-audit",
|
||||
"--loglevel=error",
|
||||
]);
|
||||
expect(globalInstallFallbackArgs("npm", "openclaw@latest", pkgRoot)).toEqual([
|
||||
brewNpm,
|
||||
"i",
|
||||
"-g",
|
||||
"openclaw@latest",
|
||||
"--omit=optional",
|
||||
"--no-fund",
|
||||
"--no-audit",
|
||||
"--loglevel=error",
|
||||
]);
|
||||
} finally {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("does not infer npm ownership from path shape alone when the owning npm binary is absent", async () => {
|
||||
|
||||
Reference in New Issue
Block a user