test: update health/status and legacy migration coverage
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { HealthSummary } from "./health.js";
|
||||
import { healthCommand } from "./health.js";
|
||||
import { formatHealthChannelLines, healthCommand } from "./health.js";
|
||||
|
||||
const runtime = {
|
||||
log: vi.fn(),
|
||||
@@ -20,14 +20,23 @@ describe("healthCommand", () => {
|
||||
});
|
||||
|
||||
it("outputs JSON from gateway", async () => {
|
||||
const agentSessions = {
|
||||
path: "/tmp/sessions.json",
|
||||
count: 1,
|
||||
recent: [{ key: "+1555", updatedAt: Date.now(), age: 0 }],
|
||||
};
|
||||
const snapshot: HealthSummary = {
|
||||
ok: true,
|
||||
ts: Date.now(),
|
||||
durationMs: 5,
|
||||
channels: {
|
||||
whatsapp: { linked: true, authAgeMs: 5000 },
|
||||
telegram: { configured: true, probe: { ok: true, elapsedMs: 1 } },
|
||||
discord: { configured: false },
|
||||
whatsapp: { accountId: "default", linked: true, authAgeMs: 5000 },
|
||||
telegram: {
|
||||
accountId: "default",
|
||||
configured: true,
|
||||
probe: { ok: true, elapsedMs: 1 },
|
||||
},
|
||||
discord: { accountId: "default", configured: false },
|
||||
},
|
||||
channelOrder: ["whatsapp", "telegram", "discord"],
|
||||
channelLabels: {
|
||||
@@ -36,11 +45,23 @@ describe("healthCommand", () => {
|
||||
discord: "Discord",
|
||||
},
|
||||
heartbeatSeconds: 60,
|
||||
sessions: {
|
||||
path: "/tmp/sessions.json",
|
||||
count: 1,
|
||||
recent: [{ key: "+1555", updatedAt: Date.now(), age: 0 }],
|
||||
},
|
||||
defaultAgentId: "main",
|
||||
agents: [
|
||||
{
|
||||
agentId: "main",
|
||||
isDefault: true,
|
||||
heartbeat: {
|
||||
enabled: true,
|
||||
every: "1m",
|
||||
everyMs: 60_000,
|
||||
prompt: "hi",
|
||||
target: "last",
|
||||
ackMaxChars: 160,
|
||||
},
|
||||
sessions: agentSessions,
|
||||
},
|
||||
],
|
||||
sessions: agentSessions,
|
||||
};
|
||||
callGatewayMock.mockResolvedValueOnce(snapshot);
|
||||
|
||||
@@ -60,9 +81,9 @@ describe("healthCommand", () => {
|
||||
ts: Date.now(),
|
||||
durationMs: 5,
|
||||
channels: {
|
||||
whatsapp: { linked: false, authAgeMs: null },
|
||||
telegram: { configured: false },
|
||||
discord: { configured: false },
|
||||
whatsapp: { accountId: "default", linked: false, authAgeMs: null },
|
||||
telegram: { accountId: "default", configured: false },
|
||||
discord: { accountId: "default", configured: false },
|
||||
},
|
||||
channelOrder: ["whatsapp", "telegram", "discord"],
|
||||
channelLabels: {
|
||||
@@ -71,6 +92,22 @@ describe("healthCommand", () => {
|
||||
discord: "Discord",
|
||||
},
|
||||
heartbeatSeconds: 60,
|
||||
defaultAgentId: "main",
|
||||
agents: [
|
||||
{
|
||||
agentId: "main",
|
||||
isDefault: true,
|
||||
heartbeat: {
|
||||
enabled: true,
|
||||
every: "1m",
|
||||
everyMs: 60_000,
|
||||
prompt: "hi",
|
||||
target: "last",
|
||||
ackMaxChars: 160,
|
||||
},
|
||||
sessions: { path: "/tmp/sessions.json", count: 0, recent: [] },
|
||||
},
|
||||
],
|
||||
sessions: { path: "/tmp/sessions.json", count: 0, recent: [] },
|
||||
} satisfies HealthSummary);
|
||||
|
||||
@@ -79,4 +116,61 @@ describe("healthCommand", () => {
|
||||
expect(runtime.exit).not.toHaveBeenCalled();
|
||||
expect(runtime.log).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("formats per-account probe timings", () => {
|
||||
const summary: HealthSummary = {
|
||||
ok: true,
|
||||
ts: Date.now(),
|
||||
durationMs: 5,
|
||||
channels: {
|
||||
telegram: {
|
||||
accountId: "main",
|
||||
configured: true,
|
||||
probe: { ok: true, elapsedMs: 196, bot: { username: "pinguini_ugi_bot" } },
|
||||
accounts: {
|
||||
main: {
|
||||
accountId: "main",
|
||||
configured: true,
|
||||
probe: { ok: true, elapsedMs: 196, bot: { username: "pinguini_ugi_bot" } },
|
||||
},
|
||||
flurry: {
|
||||
accountId: "flurry",
|
||||
configured: true,
|
||||
probe: { ok: true, elapsedMs: 190, bot: { username: "flurry_ugi_bot" } },
|
||||
},
|
||||
poe: {
|
||||
accountId: "poe",
|
||||
configured: true,
|
||||
probe: { ok: true, elapsedMs: 188, bot: { username: "poe_ugi_bot" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
channelOrder: ["telegram"],
|
||||
channelLabels: { telegram: "Telegram" },
|
||||
heartbeatSeconds: 60,
|
||||
defaultAgentId: "main",
|
||||
agents: [
|
||||
{
|
||||
agentId: "main",
|
||||
isDefault: true,
|
||||
heartbeat: {
|
||||
enabled: true,
|
||||
every: "1m",
|
||||
everyMs: 60_000,
|
||||
prompt: "hi",
|
||||
target: "last",
|
||||
ackMaxChars: 160,
|
||||
},
|
||||
sessions: { path: "/tmp/sessions.json", count: 0, recent: [] },
|
||||
},
|
||||
],
|
||||
sessions: { path: "/tmp/sessions.json", count: 0, recent: [] },
|
||||
};
|
||||
|
||||
const lines = formatHealthChannelLines(summary, { accountMode: "all" });
|
||||
expect(lines).toContain(
|
||||
"Telegram: ok (@pinguini_ugi_bot:main:196ms, @flurry_ugi_bot:flurry:190ms, @poe_ugi_bot:poe:188ms)",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user