murashit_codex-panel/tests/panel/diagnostics.test.ts

89 lines
3.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
capabilityProbeError,
capabilityProbeOk,
createAppServerDiagnostics,
upsertMcpServerDiagnostic,
} from "../../src/app-server/compatibility";
import { connectionDiagnosticLines, connectionDiagnosticRows, diagnosticAlertLevel } from "../../src/panel/diagnostics";
describe("connection diagnostics", () => {
it("formats base rows, capability probes, and MCP issues for /doctor", () => {
let diagnostics = createAppServerDiagnostics();
diagnostics.probes["model/list"] = capabilityProbeOk("model/list", "12 models", 1);
diagnostics.probes["skills/list"] = capabilityProbeError("skills/list", new Error("unknown method skills/list"), 2);
diagnostics = upsertMcpServerDiagnostic(diagnostics, {
name: "github",
startupStatus: "failed",
authStatus: null,
toolCount: null,
message: "missing token",
});
diagnostics = upsertMcpServerDiagnostic(diagnostics, {
name: "docs",
startupStatus: "ready",
authStatus: "notLoggedIn",
toolCount: 2,
message: null,
});
const rows = connectionDiagnosticRows({
connected: true,
configuredCommand: "/opt/homebrew/bin/codex",
initializeResponse: {
userAgent: "codex-cli/0.130.0",
codexHome: "/Users/showhey/.codex",
platformFamily: "unix",
platformOs: "macos",
},
activeThreadCliVersion: "0.130.0",
diagnostics,
});
expect(rows.map((row) => `${row.label}: ${row.value}`)).toEqual(
expect.arrayContaining([
"connection: connected",
"capability model/list: ok (12 models)",
"capability skills/list: unsupported - unknown method skills/list",
"mcp docs: ready - auth notLoggedIn",
"mcp github: failed - missing token",
]),
);
expect(rows.find((row) => row.label === "capability skills/list")?.level).toBe("warning");
expect(rows.find((row) => row.label === "mcp github")?.level).toBe("error");
expect(connectionDiagnosticLines(rows)[0]).toBe("Connection diagnostics");
});
it("derives a top-level diagnostic alert without treating unknown or unsupported probes as warnings", () => {
expect(diagnosticAlertLevel(createAppServerDiagnostics())).toBe("normal");
const unsupported = createAppServerDiagnostics();
unsupported.probes["skills/list"] = capabilityProbeError("skills/list", new Error("unknown method skills/list"), 1);
expect(diagnosticAlertLevel(unsupported)).toBe("normal");
const failed = createAppServerDiagnostics();
failed.probes["model/list"] = capabilityProbeError("model/list", new Error("network down"), 1);
expect(diagnosticAlertLevel(failed)).toBe("error");
});
it("derives MCP diagnostic alerts with error priority", () => {
let authIssue = upsertMcpServerDiagnostic(createAppServerDiagnostics(), {
name: "docs",
startupStatus: "ready",
authStatus: "notLoggedIn",
toolCount: 0,
message: null,
});
expect(diagnosticAlertLevel(authIssue)).toBe("warning");
authIssue = upsertMcpServerDiagnostic(authIssue, {
name: "github",
startupStatus: "failed",
authStatus: null,
toolCount: null,
message: "missing token",
});
expect(diagnosticAlertLevel(authIssue)).toBe("error");
});
});