Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
import { EnvironmentId } from "@akeru/contracts";
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
// Pinned so the direction cases below read as fixed versions instead of
// arithmetic on whatever version this checkout happens to be at.
const branding = vi.hoisted(() => ({ APP_VERSION: "0.0.34" }));
vi.mock("./branding", () => branding);
import { APP_VERSION } from "./branding";
import {
appendVersionMismatchHint,
buildVersionMismatchDismissalKey,
dismissVersionMismatch,
isVersionMismatchDismissed,
resolveServerConfigVersionMismatch,
resolveServerSelfUpdateCapability,
resolveVersionMismatch,
serverUpdateGuidance,
} from "./versionSkew";
const MISMATCH_HINT =
"Version mismatch. Try syncing the client and server to the same Akeru Bot version.";
describe("versionSkew", () => {
beforeEach(() => {
branding.APP_VERSION = "0.0.34";
});
it("does not warn when versions match", () => {
expect(resolveVersionMismatch(APP_VERSION)).toBeNull();
});
it("returns a mismatch when the server is behind the client", () => {
expect(resolveVersionMismatch("0.0.33")).toEqual({
clientVersion: "0.0.34",
serverVersion: "0.0.33",
hint: MISMATCH_HINT,
});
});
it("does not warn when the server is ahead of the client", () => {
expect(resolveVersionMismatch("0.0.35")).toBeNull();
expect(resolveVersionMismatch("9.9.9")).toBeNull();
});
it("still warns when a nightly client outruns the server by a release", () => {
branding.APP_VERSION = "0.0.35-nightly.20260818.1124";
expect(resolveVersionMismatch("0.0.34")).toEqual({
clientVersion: "0.0.35-nightly.20260818.1124",
serverVersion: "0.0.34",
hint: MISMATCH_HINT,
});
});
it("falls back to string inequality when a version is not semver", () => {
expect(resolveVersionMismatch("dev")).toEqual({
clientVersion: "0.0.34",
serverVersion: "dev",
hint: MISMATCH_HINT,
});
branding.APP_VERSION = "dev";
expect(resolveVersionMismatch("dev")).toBeNull();
expect(resolveVersionMismatch("0.0.34")).toMatchObject({ serverVersion: "0.0.34" });
});
it("reads the server version from config descriptors", () => {
expect(
resolveServerConfigVersionMismatch({
environment: {
environmentId: EnvironmentId.make("environment-1"),
label: "Remote",
platform: {
os: "darwin",
arch: "arm64",
},
serverVersion: "0.0.33",
capabilities: {
repositoryIdentity: true,
},
},
}),
).toMatchObject({
serverVersion: "0.0.33",
});
});
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 the server is behind", () => {
const mismatch = resolveVersionMismatch("0.0.33");
expect(appendVersionMismatchHint("Socket closed.", mismatch)).toBe(
`Socket closed. Hint: ${MISMATCH_HINT}`,
);
});
it("reads desktop-managed update capabilities from config descriptors", () => {
expect(
resolveServerSelfUpdateCapability({
environment: {
environmentId: EnvironmentId.make("environment-desktop"),
label: "Desktop",
platform: { os: "darwin", arch: "arm64" },
serverVersion: "9.9.9",
capabilities: {
repositoryIdentity: true,
serverSelfUpdate: "desktop-managed",
},
},
}),
).toBe("desktop-managed");
expect(resolveServerSelfUpdateCapability(null)).toBeNull();
});
it("matches version-drift guidance to the advertised update path", () => {
expect(serverUpdateGuidance("respawn", "Remote server")).toBe(
"Update the Remote server so they stay in sync.",
);
expect(serverUpdateGuidance("desktop-managed", "Desktop server")).toBe(
"Update the desktop app that runs the Desktop server.",
);
expect(serverUpdateGuidance(null, "Local server")).toBe(
"Relaunch the Local server with the copied command to sync them.",
);
});
});