version-compare.test.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { describe, expect, it } from "vitest";
  2. import { comparePluginUpdate, comparePluginVersions } from "../src/plugins/version-compare.js";
  3. describe("comparePluginVersions", () => {
  4. it("reports update-available when latest is strictly greater", () => {
  5. expect(comparePluginVersions({ installed: "1.0.0", latest: "1.1.0" })).toBe("update-available");
  6. });
  7. it("reports none when equal", () => {
  8. expect(comparePluginVersions({ installed: "2.3.4", latest: "2.3.4" })).toBe("none");
  9. });
  10. it("reports none when latest is older", () => {
  11. expect(comparePluginVersions({ installed: "2.0.0", latest: "1.0.0" })).toBe("none");
  12. });
  13. it("reports version-changed for non-semver differing versions", () => {
  14. expect(comparePluginVersions({ installed: "abc", latest: "def" })).toBe("version-changed");
  15. });
  16. it("reports none for non-semver equal versions", () => {
  17. expect(comparePluginVersions({ installed: "abc", latest: "abc" })).toBe("none");
  18. });
  19. it("reports none when either version is missing", () => {
  20. expect(comparePluginVersions({ installed: undefined, latest: "1.0.0" })).toBe("none");
  21. expect(comparePluginVersions({ installed: "1.0.0", latest: undefined })).toBe("none");
  22. });
  23. });
  24. describe("comparePluginUpdate", () => {
  25. // Version axis: only when the manifest (latest) advertises a semver version.
  26. it("uses the version axis when the manifest entry has a version", () => {
  27. expect(
  28. comparePluginUpdate({
  29. installedVersion: "1.0.0",
  30. installedSha: undefined,
  31. latestVersion: "1.2.0",
  32. latestSha: undefined,
  33. }),
  34. ).toBe("update-available");
  35. expect(
  36. comparePluginUpdate({
  37. installedVersion: "2.0.0",
  38. installedSha: undefined,
  39. latestVersion: "2.0.0",
  40. latestSha: undefined,
  41. }),
  42. ).toBe("none");
  43. });
  44. // Sha axis: the common Claude-official case — manifest entry pins a commit sha, no version.
  45. it("uses the sha axis when the manifest entry pins a sha and has no version", () => {
  46. expect(
  47. comparePluginUpdate({
  48. installedVersion: "0.0.0",
  49. installedSha: "295ab93b7d765912ee1a0dc7f1abb0ecaf73f138",
  50. latestVersion: undefined,
  51. latestSha: "896224c4aa11deadbeefcafef00dba5eed1234567",
  52. }),
  53. ).toBe("update-available");
  54. expect(
  55. comparePluginUpdate({
  56. installedVersion: "6.0.3",
  57. installedSha: "295ab93b7d765912ee1a0dc7f1abb0ecaf73f138",
  58. latestVersion: undefined,
  59. latestSha: "295ab93b7d765912ee1a0dc7f1abb0ecaf73f138",
  60. }),
  61. ).toBe("none");
  62. });
  63. // Manifest pins a sha but the installed record has none to compare → surface as changed.
  64. it("reports version-changed when the manifest pins a sha but the installed record has none", () => {
  65. expect(
  66. comparePluginUpdate({
  67. installedVersion: "0.0.0",
  68. installedSha: undefined,
  69. latestVersion: undefined,
  70. latestSha: "896224c4aa11deadbeefcafef00dba5eed1234567",
  71. }),
  72. ).toBe("version-changed");
  73. });
  74. // Prefer the version axis (ordered) when the manifest entry carries both version and sha.
  75. it("prefers the version axis when the manifest entry has both version and sha", () => {
  76. expect(
  77. comparePluginUpdate({
  78. installedVersion: "2.0.6",
  79. installedSha: "oldsha",
  80. latestVersion: "2.0.6",
  81. latestSha: "newsha",
  82. }),
  83. ).toBe("none");
  84. });
  85. // Local-path plugins (no version, no sha on either side) are Phase 2 → no false positives.
  86. it("reports none when neither side has a comparable pin (local path)", () => {
  87. expect(
  88. comparePluginUpdate({
  89. installedVersion: "0.0.0",
  90. installedSha: undefined,
  91. latestVersion: undefined,
  92. latestSha: undefined,
  93. }),
  94. ).toBe("none");
  95. });
  96. });