Files
oh-my-pi/packages/coding-agent/test/update-cli.test.ts
T
roboomp a6279e0730 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
2026-05-21 00:09:43 +00:00

83 lines
2.8 KiB
TypeScript

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");
expect(method).toBe("bun");
});
it("uses binary update when prioritized omp is outside bun global bin", () => {
const method = resolveUpdateMethodForTest("/Users/test/.local/bin/omp", "/Users/test/.bun/bin");
expect(method).toBe("binary");
});
it("uses binary update when bun global bin cannot be resolved", () => {
const method = resolveUpdateMethodForTest("/Users/test/.local/bin/omp", undefined);
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);
});
});