fix(cli): restored binary update rollback
Rolled back binary updater replacements when post-install version verification fails instead of deleting the previous working binary first. Added a release workflow gate that downloads the published macOS arm64 asset and verifies codesign plus --version before npm publishing. Fixes #1240
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { resolveUpdateMethodForTest } from "../src/cli/update-cli";
|
||||
import { afterEach, describe, expect, it } from "bun:test";
|
||||
import * as fs from "node:fs/promises";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import { replaceBinaryForUpdate, resolveUpdateMethodForTest } from "../src/cli/update-cli";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
async function makeTempDir(): Promise<string> {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "omp-update-test-"));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(tempDirs.splice(0).map(dir => fs.rm(dir, { recursive: true, force: true })));
|
||||
});
|
||||
describe("update-cli install target detection", () => {
|
||||
it("uses bun update when prioritized omp is inside bun global bin", () => {
|
||||
const method = resolveUpdateMethodForTest("/Users/test/.bun/bin/omp", "/Users/test/.bun/bin");
|
||||
@@ -20,3 +34,49 @@ describe("update-cli install target detection", () => {
|
||||
expect(method).toBe("binary");
|
||||
});
|
||||
});
|
||||
|
||||
describe("update-cli binary replacement", () => {
|
||||
it("restores the previous binary when the replacement fails verification", async () => {
|
||||
const dir = await makeTempDir();
|
||||
const targetPath = path.join(dir, "omp");
|
||||
const tempPath = `${targetPath}.new`;
|
||||
const backupPath = `${targetPath}.bak`;
|
||||
await Bun.write(targetPath, "old binary");
|
||||
await Bun.write(tempPath, "broken binary");
|
||||
|
||||
await expect(
|
||||
replaceBinaryForUpdate({
|
||||
targetPath,
|
||||
tempPath,
|
||||
backupPath,
|
||||
expectedVersion: "15.1.8",
|
||||
verifyInstalledVersion: async () => ({ ok: false, path: targetPath }),
|
||||
}),
|
||||
).rejects.toThrow("restored previous omp binary");
|
||||
|
||||
expect(await Bun.file(targetPath).text()).toBe("old binary");
|
||||
expect(await Bun.file(tempPath).exists()).toBe(false);
|
||||
expect(await Bun.file(backupPath).exists()).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps the replacement only after it reports the expected version", async () => {
|
||||
const dir = await makeTempDir();
|
||||
const targetPath = path.join(dir, "omp");
|
||||
const tempPath = `${targetPath}.new`;
|
||||
const backupPath = `${targetPath}.bak`;
|
||||
await Bun.write(targetPath, "old binary");
|
||||
await Bun.write(tempPath, "new binary");
|
||||
|
||||
await replaceBinaryForUpdate({
|
||||
targetPath,
|
||||
tempPath,
|
||||
backupPath,
|
||||
expectedVersion: "15.1.8",
|
||||
verifyInstalledVersion: async () => ({ ok: true, actual: "15.1.8", path: targetPath }),
|
||||
});
|
||||
|
||||
expect(await Bun.file(targetPath).text()).toBe("new binary");
|
||||
expect(await Bun.file(tempPath).exists()).toBe(false);
|
||||
expect(await Bun.file(backupPath).exists()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user