Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
// Copyright 2026 Ix Infrastructure Inc.
import { describe, expect, it } from "vitest";
import { join } from "node:path";
import { homedir } from "node:os";
import {
CLIENT_EXPECTED_SCHEMA_VERSION,
checkBackendSchema,
isNonStandardBackend,
type BackendContainer,
} from "../backend-status.js";
import type { IxClient } from "../../client/api.js";
import { isNewer } from "../commands/upgrade.js";
// `endpoint` matters now: checkBackendSchema records through the shared health
// fetch, and the recorder is gated on the endpoint being local. A remote one
// keeps these unit tests from touching any stamp file at all.
function fakeClient(health: () => Promise<any>): IxClient {
return { endpoint: "http://schema-spec.invalid:8090", health } as unknown as IxClient;
}
function container(overrides: Partial<BackendContainer>): BackendContainer {
return {
containerId: "abc123",
imageRef: "ghcr.io/ix-infrastructure/ix-memory-layer:latest",
imageId: "sha256:deadbeef",
repoDigests: [],
composeProject: "ix",
composeConfigFiles: null,
...overrides,
};
}
describe("checkBackendSchema", () => {
it("matches when the backend reports the expected version", async () => {
const s = await checkBackendSchema(fakeClient(async () => ({ status: "ok", schema_version: CLIENT_EXPECTED_SCHEMA_VERSION })), null, isNewer);
expect(s).toEqual({ reachable: true, serverVersion: CLIENT_EXPECTED_SCHEMA_VERSION, expected: CLIENT_EXPECTED_SCHEMA_VERSION, matches: true });
});
it("flags a mismatch when the persisted graph predates the engine", async () => {
const s = await checkBackendSchema(fakeClient(async () => ({ status: "ok", schema_version: CLIENT_EXPECTED_SCHEMA_VERSION - 1 })), null, isNewer);
expect(s.matches).toBe(false);
expect(s.serverVersion).toBe(CLIENT_EXPECTED_SCHEMA_VERSION - 1);
});
it("does not flag when the backend reports no schema version (can't prove stale)", async () => {
const s = await checkBackendSchema(fakeClient(async () => ({ status: "ok" })), null, isNewer);
expect(s.matches).toBe(true);
expect(s.serverVersion).toBeNull();
});
it("reports unreachable (and does not flag) when health throws", async () => {
const s = await checkBackendSchema(
fakeClient(async () => { throw new Error("ECONNREFUSED"); }),
null,
isNewer,
);
expect(s).toEqual({ reachable: false, serverVersion: null, expected: CLIENT_EXPECTED_SCHEMA_VERSION, matches: true });
});
});
describe("isNonStandardBackend", () => {
const standard = join(homedir(), ".ix", "backend", "docker-compose.yml");
it("treats a compose project under ~/.ix/backend as standard", () => {
expect(isNonStandardBackend(container({ composeConfigFiles: standard }))).toBe(false);
});
it("flags a compose project outside ~/.ix/backend", () => {
expect(isNonStandardBackend(container({ composeConfigFiles: "/work/ix-memory-layer/docker-compose.yml" }))).toBe(true);
});
it("does not flag when no compose config files are known", () => {
expect(isNonStandardBackend(container({ composeConfigFiles: null }))).toBe(false);
});
});