Files
t3code/apps/web/src/versionSkew.test.ts
2026-06-03 16:16:53 -07:00

79 lines
2.3 KiB
TypeScript

import { EnvironmentId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import { APP_VERSION } from "./branding";
import {
appendVersionMismatchHint,
buildVersionMismatchDismissalKey,
dismissVersionMismatch,
isVersionMismatchDismissed,
resolveServerConfigVersionMismatch,
resolveVersionMismatch,
} from "./versionSkew";
describe("versionSkew", () => {
it("does not warn when versions match", () => {
expect(resolveVersionMismatch(APP_VERSION)).toBeNull();
});
it("returns a mismatch when the server version differs from the client", () => {
expect(resolveVersionMismatch("9.9.9")).toEqual({
clientVersion: APP_VERSION,
serverVersion: "9.9.9",
hint: "Version mismatch. Try syncing the client and server to the same T3 Code version.",
});
});
it("reads the server version from config descriptors", () => {
expect(
resolveServerConfigVersionMismatch({
environment: {
environmentId: EnvironmentId.make("environment-1"),
label: "Remote",
platform: {
os: "darwin",
arch: "arm64",
},
serverVersion: "9.9.9",
capabilities: {
repositoryIdentity: true,
},
},
}),
).toMatchObject({
serverVersion: "9.9.9",
});
});
it("keys dismissals by environment, client version, and server version", () => {
const environmentId = EnvironmentId.make("environment-dismissal");
const key = buildVersionMismatchDismissalKey(environmentId, {
clientVersion: APP_VERSION,
serverVersion: "9.9.9",
});
expect(key).toBe(`${environmentId}:${APP_VERSION}:9.9.9`);
expect(isVersionMismatchDismissed(key)).toBe(false);
dismissVersionMismatch(key);
expect(isVersionMismatchDismissed(key)).toBe(true);
expect(
isVersionMismatchDismissed(
buildVersionMismatchDismissalKey(environmentId, {
clientVersion: APP_VERSION,
serverVersion: "9.9.10",
}),
),
).toBe(false);
});
it("appends a hint to connection errors when versions differ", () => {
const mismatch = resolveVersionMismatch("9.9.9");
expect(appendVersionMismatchHint("Socket closed.", mismatch)).toBe(
"Socket closed. Hint: Version mismatch. Try syncing the client and server to the same T3 Code version.",
);
});
});