import { describe, it, expect } from "vitest"; import { compareVersions } from "./ops"; /** * The farm strip flags machines running an older worker than the newest one * out there, which is only as reliable as this comparison: a plain string * compare ranks "1.10.0" below "1.9.0" and would quietly stop reporting drift * on the day the minor version reaches double digits. */ describe("compareVersions", () => { it("orders by numeric component, not lexically", () => { expect(compareVersions("1.10.0", "1.9.0")).toBeGreaterThan(0); expect(compareVersions("1.9.0", "1.10.0")).toBeLessThan(0); }); it("ignores the build stamp publish.ps1 appends", () => { // The exe reports "1.6.1+fe420b9"; two machines on the same release built // from different commits are not drifting. expect(compareVersions("1.6.1+fe420b9", "1.6.1")).toBe(0); expect(compareVersions("1.6.1+fe420b9", "1.6.0+2a88880")).toBeGreaterThan(0); }); it("treats a missing component as zero", () => { expect(compareVersions("1.6", "1.6.0")).toBe(0); expect(compareVersions("1.6", "1.6.1")).toBeLessThan(0); }); it("is transitive enough to pick a maximum", () => { const versions = ["1.5.2", "1.6.1", "1.6.0", "1.10.0"]; const latest = versions.reduce((a, b) => (compareVersions(a, b) >= 0 ? a : b)); expect(latest).toBe("1.10.0"); }); });