| ... | ... | @@ -1,5 +1,10 @@ |
| 1 | 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { beforeEach, describe, expect, it, vi } from "vite-plus/test"; |
| 3 | |
| 4 | // Pinned so the direction cases below read as fixed versions instead of |
| 5 | // arithmetic on whatever version this checkout happens to be at. |
| 6 | const branding = vi.hoisted(() => ({ APP_VERSION: "0.0.34" })); |
| 7 | vi.mock("./branding", () => branding); |
| 3 | 8 | |
| 4 | 9 | import { APP_VERSION } from "./branding"; |
| 5 | 10 | import { |
| ... | ... | @@ -13,19 +18,64 @@ import { |
| 13 | 18 | serverUpdateGuidance, |
| 14 | 19 | } from "./versionSkew"; |
| 15 | 20 | |
| 21 | const MISMATCH_HINT = |
| 22 | "Version mismatch. Try syncing the client and server to the same T3 Code version."; |
| 23 | |
| 16 | 24 | describe("versionSkew", () => { |
| 25 | beforeEach(() => { |
| 26 | branding.APP_VERSION = "0.0.34"; |
| 27 | }); |
| 28 | |
| 17 | 29 | it("does not warn when versions match", () => { |
| 18 | 30 | expect(resolveVersionMismatch(APP_VERSION)).toBeNull(); |
| 19 | 31 | }); |
| 20 | 32 | |
| 21 | | it("returns a mismatch when the server version differs from the client", () => { |
| 22 | | expect(resolveVersionMismatch("9.9.9")).toEqual({ |
| 23 | | clientVersion: APP_VERSION, |
| 24 | | serverVersion: "9.9.9", |
| 25 | | hint: "Version mismatch. Try syncing the client and server to the same T3 Code version.", |
| 33 | it("returns a mismatch when the server is behind the client", () => { |
| 34 | expect(resolveVersionMismatch("0.0.33")).toEqual({ |
| 35 | clientVersion: "0.0.34", |
| 36 | serverVersion: "0.0.33", |
| 37 | hint: MISMATCH_HINT, |
| 26 | 38 | }); |
| 27 | 39 | }); |
| 28 | 40 | |
| 41 | it("does not warn when the server is ahead of the client", () => { |
| 42 | expect(resolveVersionMismatch("0.0.35")).toBeNull(); |
| 43 | expect(resolveVersionMismatch("9.9.9")).toBeNull(); |
| 44 | }); |
| 45 | |
| 46 | it("does not warn when a nightly and a stable build share a core version", () => { |
| 47 | expect(resolveVersionMismatch("0.0.34-nightly.20260818.1124")).toBeNull(); |
| 48 | |
| 49 | branding.APP_VERSION = "0.0.34-nightly.20260818.1124"; |
| 50 | expect(resolveVersionMismatch("0.0.34")).toBeNull(); |
| 51 | }); |
| 52 | |
| 53 | it("treats a nightly server built past the client as ahead, not skew", () => { |
| 54 | expect(resolveVersionMismatch("0.0.35-nightly.20260818.1124")).toBeNull(); |
| 55 | }); |
| 56 | |
| 57 | it("still warns when a nightly client outruns the server by a release", () => { |
| 58 | branding.APP_VERSION = "0.0.35-nightly.20260818.1124"; |
| 59 | |
| 60 | expect(resolveVersionMismatch("0.0.34")).toEqual({ |
| 61 | clientVersion: "0.0.35-nightly.20260818.1124", |
| 62 | serverVersion: "0.0.34", |
| 63 | hint: MISMATCH_HINT, |
| 64 | }); |
| 65 | }); |
| 66 | |
| 67 | it("falls back to string inequality when a version is not semver", () => { |
| 68 | expect(resolveVersionMismatch("dev")).toEqual({ |
| 69 | clientVersion: "0.0.34", |
| 70 | serverVersion: "dev", |
| 71 | hint: MISMATCH_HINT, |
| 72 | }); |
| 73 | |
| 74 | branding.APP_VERSION = "dev"; |
| 75 | expect(resolveVersionMismatch("dev")).toBeNull(); |
| 76 | expect(resolveVersionMismatch("0.0.34")).toMatchObject({ serverVersion: "0.0.34" }); |
| 77 | }); |
| 78 | |
| 29 | 79 | it("reads the server version from config descriptors", () => { |
| 30 | 80 | expect( |
| 31 | 81 | resolveServerConfigVersionMismatch({ |
| ... | ... | @@ -36,14 +86,14 @@ describe("versionSkew", () => { |
| 36 | 86 | os: "darwin", |
| 37 | 87 | arch: "arm64", |
| 38 | 88 | }, |
| 39 | | serverVersion: "9.9.9", |
| 89 | serverVersion: "0.0.33", |
| 40 | 90 | capabilities: { |
| 41 | 91 | repositoryIdentity: true, |
| 42 | 92 | }, |
| 43 | 93 | }, |
| 44 | 94 | }), |
| 45 | 95 | ).toMatchObject({ |
| 46 | | serverVersion: "9.9.9", |
| 96 | serverVersion: "0.0.33", |
| 47 | 97 | }); |
| 48 | 98 | }); |
| 49 | 99 | |
| ... | ... | @@ -70,11 +120,11 @@ describe("versionSkew", () => { |
| 70 | 120 | ).toBe(false); |
| 71 | 121 | }); |
| 72 | 122 | |
| 73 | | it("appends a hint to connection errors when versions differ", () => { |
| 74 | | const mismatch = resolveVersionMismatch("9.9.9"); |
| 123 | it("appends a hint to connection errors when the server is behind", () => { |
| 124 | const mismatch = resolveVersionMismatch("0.0.33"); |
| 75 | 125 | |
| 76 | 126 | expect(appendVersionMismatchHint("Socket closed.", mismatch)).toBe( |
| 77 | | "Socket closed. Hint: Version mismatch. Try syncing the client and server to the same T3 Code version.", |
| 127 | `Socket closed. Hint: ${MISMATCH_HINT}`, |
| 78 | 128 | ); |
| 79 | 129 | }); |
| 80 | 130 | |