|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { compareVersions, isAgentCompatible } from "@/utils/version"; |
| 3 | + |
| 4 | +describe("compareVersions", () => { |
| 5 | + it("returns 0 for equal versions", () => { |
| 6 | + expect(compareVersions("1.2.3", "1.2.3")).toBe(0); |
| 7 | + }); |
| 8 | + |
| 9 | + it("returns -1 when a < b", () => { |
| 10 | + expect(compareVersions("0.1.4", "0.1.5")).toBe(-1); |
| 11 | + expect(compareVersions("0.1.9", "0.2.0")).toBe(-1); |
| 12 | + expect(compareVersions("0.9.9", "1.0.0")).toBe(-1); |
| 13 | + }); |
| 14 | + |
| 15 | + it("returns 1 when a > b", () => { |
| 16 | + expect(compareVersions("0.1.5", "0.1.4")).toBe(1); |
| 17 | + expect(compareVersions("1.0.0", "0.9.9")).toBe(1); |
| 18 | + }); |
| 19 | + |
| 20 | + it("handles v prefix", () => { |
| 21 | + expect(compareVersions("v1.0.0", "1.0.0")).toBe(0); |
| 22 | + }); |
| 23 | + |
| 24 | + it("handles wildcard x as infinity", () => { |
| 25 | + expect(compareVersions("0.5.0", "0.x.x")).toBe(-1); |
| 26 | + expect(compareVersions("1.0.0", "0.x.x")).toBe(1); |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +describe("isAgentCompatible", () => { |
| 31 | + it("returns compatible for unknown version", () => { |
| 32 | + const result = isAgentCompatible("unknown"); |
| 33 | + expect(result.compatible).toBe(true); |
| 34 | + }); |
| 35 | + |
| 36 | + it("returns compatible for empty version", () => { |
| 37 | + const result = isAgentCompatible(""); |
| 38 | + expect(result.compatible).toBe(true); |
| 39 | + }); |
| 40 | + |
| 41 | + it("returns compatible for valid version", () => { |
| 42 | + const result = isAgentCompatible("0.1.5"); |
| 43 | + expect(result.compatible).toBe(true); |
| 44 | + }); |
| 45 | + |
| 46 | + it("returns incompatible for old version", () => { |
| 47 | + const result = isAgentCompatible("0.1.3"); |
| 48 | + expect(result.compatible).toBe(false); |
| 49 | + expect(result.message).toContain("too old"); |
| 50 | + }); |
| 51 | + |
| 52 | + it("returns compatible for minimum version", () => { |
| 53 | + const result = isAgentCompatible("0.1.4"); |
| 54 | + expect(result.compatible).toBe(true); |
| 55 | + }); |
| 56 | + |
| 57 | + it("returns incompatible for version beyond max", () => { |
| 58 | + const result = isAgentCompatible("1.0.0"); |
| 59 | + expect(result.compatible).toBe(false); |
| 60 | + expect(result.message).toContain("newer than supported"); |
| 61 | + }); |
| 62 | + |
| 63 | + it("flags dev versions as incompatible but dismissable", () => { |
| 64 | + const versions = ["dev", "0.1.5-dev", "0.0.1-alpha", "1.0.0-rc.1", "0.2.0-beta", "0.0.0-snapshot"]; |
| 65 | + for (const v of versions) { |
| 66 | + const result = isAgentCompatible(v); |
| 67 | + expect(result.compatible).toBe(false); |
| 68 | + expect(result.dev).toBe(true); |
| 69 | + expect(result.message).toContain("development build"); |
| 70 | + } |
| 71 | + }); |
| 72 | +}); |
0 commit comments