mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 03:45:46 -06:00
fix(installer): clean temporary files on failure (#103725)
This commit is contained in:
committed by
Vincent Koc
parent
b2569f9180
commit
5bbf27edf1
@@ -881,6 +881,67 @@ describe("install-cli.sh", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("removes the Node staging directory when download fails", () => {
|
||||
const tmp = mkdtempSync(join(tmpdir(), "openclaw-install-cli-node-cleanup-"));
|
||||
const prefix = join(tmp, "prefix");
|
||||
const stagingDir = join(tmp, "node-staging");
|
||||
|
||||
try {
|
||||
const result = runInstallCliShell(
|
||||
[
|
||||
"set -euo pipefail",
|
||||
`cd ${JSON.stringify(process.cwd())}`,
|
||||
`source ${JSON.stringify(SCRIPT_PATH)}`,
|
||||
"os_detect() { printf 'linux\\n'; }",
|
||||
"arch_detect() { printf 'x64\\n'; }",
|
||||
"is_musl_linux() { return 1; }",
|
||||
"linked_node_is_usable() { return 1; }",
|
||||
"detect_downloader() { :; }",
|
||||
"require_bin() { :; }",
|
||||
`mktemp() { mkdir -p ${JSON.stringify(stagingDir)}; printf '%s\\n' ${JSON.stringify(stagingDir)}; }`,
|
||||
"download_file() { return 42; }",
|
||||
`PREFIX=${JSON.stringify(prefix)}`,
|
||||
"NODE_VERSION=22.22.0",
|
||||
"install_node",
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
expect(result.status).toBe(42);
|
||||
expect(() => lstatSync(stagingDir)).toThrow();
|
||||
} finally {
|
||||
rmSync(tmp, { force: true, recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("removes the workspace rewrite temp file when rewriting fails", () => {
|
||||
const tmp = mkdtempSync(join(tmpdir(), "openclaw-install-cli-workspace-cleanup-"));
|
||||
const repo = join(tmp, "repo");
|
||||
const workspaceFile = join(repo, "pnpm-workspace.yaml");
|
||||
const rewriteTemp = join(tmp, "workspace-rewrite");
|
||||
const workspace = 'packages:\n - "packages/*"\n\nallowBuilds:\n';
|
||||
mkdirSync(repo, { recursive: true });
|
||||
writeFileSync(workspaceFile, workspace);
|
||||
|
||||
try {
|
||||
const result = runInstallCliShell(
|
||||
[
|
||||
"set -euo pipefail",
|
||||
`cd ${JSON.stringify(process.cwd())}`,
|
||||
`source ${JSON.stringify(SCRIPT_PATH)}`,
|
||||
`mktemp() { : > ${JSON.stringify(rewriteTemp)}; printf '%s\\n' ${JSON.stringify(rewriteTemp)}; }`,
|
||||
"awk() { return 43; }",
|
||||
`ensure_pnpm_git_prepare_allowlist ${JSON.stringify(repo)}`,
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
expect(result.status).toBe(43);
|
||||
expect(() => lstatSync(rewriteTemp)).toThrow();
|
||||
expect(readFileSync(workspaceFile, "utf8")).toBe(workspace);
|
||||
} finally {
|
||||
rmSync(tmp, { force: true, recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("clears npm freshness filters for package installs", () => {
|
||||
expect(script).toContain('freshness_flag="--min-release-age=0"');
|
||||
expect(script).toContain('npm_config_has_raw_key "$(npm_bin)" "min-release-age"');
|
||||
|
||||
Reference in New Issue
Block a user