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

versionSkew.test.ts

110 lines3.5 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 resolveServerSelfUpdateCapability,
12 resolveVersionMismatch,
13 serverUpdateGuidance,
14} from "./versionSkew";
15​
16describe("versionSkew", () => {
17 it("does not warn when versions match", () => {
18 expect(resolveVersionMismatch(APP_VERSION)).toBeNull();
19 });
20​
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.",
26 });
27 });
28​
29 it("reads the server version from config descriptors", () => {
30 expect(
31 resolveServerConfigVersionMismatch({
32 environment: {
33 environmentId: EnvironmentId.make("environment-1"),
34 label: "Remote",
35 platform: {
36 os: "darwin",
37 arch: "arm64",
38 },
39 serverVersion: "9.9.9",
40 capabilities: {
41 repositoryIdentity: true,
42 },
43 },
44 }),
45 ).toMatchObject({
46 serverVersion: "9.9.9",
47 });
48 });
49​
50 it("keys dismissals by environment, client version, and server version", () => {
51 const environmentId = EnvironmentId.make("environment-dismissal");
52 const key = buildVersionMismatchDismissalKey(environmentId, {
53 clientVersion: APP_VERSION,
54 serverVersion: "9.9.9",
55 });
56​
57 expect(key).toBe(`${environmentId}:${APP_VERSION}:9.9.9`);
58 expect(isVersionMismatchDismissed(key)).toBe(false);
59​
60 dismissVersionMismatch(key);
61​
62 expect(isVersionMismatchDismissed(key)).toBe(true);
63 expect(
64 isVersionMismatchDismissed(
65 buildVersionMismatchDismissalKey(environmentId, {
66 clientVersion: APP_VERSION,
67 serverVersion: "9.9.10",
68 }),
69 ),
70 ).toBe(false);
71 });
72​
73 it("appends a hint to connection errors when versions differ", () => {
74 const mismatch = resolveVersionMismatch("9.9.9");
75​
76 expect(appendVersionMismatchHint("Socket closed.", mismatch)).toBe(
77 "Socket closed. Hint: Version mismatch. Try syncing the client and server to the same T3 Code version.",
78 );
79 });
80​
81 it("reads desktop-managed update capabilities from config descriptors", () => {
82 expect(
83 resolveServerSelfUpdateCapability({
84 environment: {
85 environmentId: EnvironmentId.make("environment-desktop"),
86 label: "Desktop",
87 platform: { os: "darwin", arch: "arm64" },
88 serverVersion: "9.9.9",
89 capabilities: {
90 repositoryIdentity: true,
91 serverSelfUpdate: "desktop-managed",
92 },
93 },
94 }),
95 ).toBe("desktop-managed");
96 expect(resolveServerSelfUpdateCapability(null)).toBeNull();
97 });
98​
99 it("matches version-drift guidance to the advertised update path", () => {
100 expect(serverUpdateGuidance("respawn", "Remote server")).toBe(
101 "Update the Remote server so they stay in sync.",
102 );
103 expect(serverUpdateGuidance("desktop-managed", "Desktop server")).toBe(
104 "The Desktop server is run by the T3 Code desktop app on its machine — update the desktop app there to sync them.",
105 );
106 expect(serverUpdateGuidance(null, "Local server")).toBe(
107 "Relaunch the Local server with the copied command to sync them.",
108 );
109 });
110});