Files
horus-3d/tests/unit/heartbeatGatewayClient.test.ts
T
Luke The Dev 4fa4f13558 First Release of Claw3D (#11)
Co-authored-by: iamlukethedev <iamlukethedev@users.noreply.github.com>
2026-03-19 23:14:04 -05:00

82 lines
2.3 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import {
listHeartbeatsForAgent,
triggerHeartbeatNow,
} from "@/lib/gateway/agentConfig";
import type { GatewayClient } from "@/lib/gateway/GatewayClient";
describe("heartbeat gateway client", () => {
it("returns_empty_list_when_agent_has_no_heartbeat", async () => {
const client = {
call: vi
.fn()
.mockResolvedValueOnce({ config: { agents: { list: [{ id: "agent-1" }] } } })
.mockResolvedValueOnce({
heartbeat: { agents: [{ agentId: "agent-1", enabled: false, every: "disabled" }] },
}),
} as unknown as GatewayClient;
const result = await listHeartbeatsForAgent(client, "agent-1");
expect(result.heartbeats).toEqual([]);
expect(client.call).toHaveBeenCalledTimes(2);
expect(client.call).toHaveBeenNthCalledWith(1, "config.get", {});
expect(client.call).toHaveBeenNthCalledWith(2, "status", {});
});
it("returns_override_heartbeat_for_agent", async () => {
const client = {
call: vi
.fn()
.mockResolvedValueOnce({
config: {
agents: {
defaults: { heartbeat: { every: "30m", target: "last", includeReasoning: false } },
list: [
{
id: "agent-1",
heartbeat: { every: "15m", target: "none", includeReasoning: true },
},
],
},
},
})
.mockResolvedValueOnce({
heartbeat: { agents: [{ agentId: "agent-1", enabled: true, every: "15m" }] },
}),
} as unknown as GatewayClient;
const result = await listHeartbeatsForAgent(client, "agent-1");
expect(result.heartbeats).toEqual([
{
id: "agent-1",
agentId: "agent-1",
source: "override",
enabled: true,
heartbeat: {
every: "15m",
target: "none",
includeReasoning: true,
ackMaxChars: 300,
activeHours: null,
},
},
]);
});
it("triggers_wake_now_for_heartbeat", async () => {
const client = {
call: vi.fn(async () => ({ ok: true })),
} as unknown as GatewayClient;
await triggerHeartbeatNow(client, "agent-1");
expect(client.call).toHaveBeenCalledWith("wake", {
mode: "now",
text: "Claw3D heartbeat trigger (agent-1).",
});
});
});