Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

versionSkew.test.ts

78 lines2.3 KB

1import { EnvironmentId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { APP_VERSION } from "./branding";
5import {
6 appendVersionMismatchHint,
7 buildVersionMismatchDismissalKey,
8 dismissVersionMismatch,
9 isVersionMismatchDismissed,
10 resolveServerConfigVersionMismatch,
11 resolveVersionMismatch,
12} from "./versionSkew";
13​
14describe("versionSkew", () => {
15 it("does not warn when versions match", () => {
16 expect(resolveVersionMismatch(APP_VERSION)).toBeNull();
17 });
18​
19 it("returns a mismatch when the server version differs from the client", () => {
20 expect(resolveVersionMismatch("9.9.9")).toEqual({
21 clientVersion: APP_VERSION,
22 serverVersion: "9.9.9",
23 hint: "Version mismatch. Try syncing the client and server to the same T3 Code version.",
24 });
25 });
26​
27 it("reads the server version from config descriptors", () => {
28 expect(
29 resolveServerConfigVersionMismatch({
30 environment: {
31 environmentId: EnvironmentId.make("environment-1"),
32 label: "Remote",
33 platform: {
34 os: "darwin",
35 arch: "arm64",
36 },
37 serverVersion: "9.9.9",
38 capabilities: {
39 repositoryIdentity: true,
40 },
41 },
42 }),
43 ).toMatchObject({
44 serverVersion: "9.9.9",
45 });
46 });
47​
48 it("keys dismissals by environment, client version, and server version", () => {
49 const environmentId = EnvironmentId.make("environment-dismissal");
50 const key = buildVersionMismatchDismissalKey(environmentId, {
51 clientVersion: APP_VERSION,
52 serverVersion: "9.9.9",
53 });
54​
55 expect(key).toBe(`${environmentId}:${APP_VERSION}:9.9.9`);
56 expect(isVersionMismatchDismissed(key)).toBe(false);
57​
58 dismissVersionMismatch(key);
59​
60 expect(isVersionMismatchDismissed(key)).toBe(true);
61 expect(
62 isVersionMismatchDismissed(
63 buildVersionMismatchDismissalKey(environmentId, {
64 clientVersion: APP_VERSION,
65 serverVersion: "9.9.10",
66 }),
67 ),
68 ).toBe(false);
69 });
70​
71 it("appends a hint to connection errors when versions differ", () => {
72 const mismatch = resolveVersionMismatch("9.9.9");
73​
74 expect(appendVersionMismatchHint("Socket closed.", mismatch)).toBe(
75 "Socket closed. Hint: Version mismatch. Try syncing the client and server to the same T3 Code version.",
76 );
77 });
78});