mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 12:30:44 +00:00
* fix(discord): surface stalled transport health * fix(discord): surface stalled transport health * fix(discord): surface stalled transport health --------- Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import AjvPkg from "ajv";
|
|
import { describe, expect, it } from "vitest";
|
|
import { ChannelsStatusResultSchema, WebLoginWaitParamsSchema } from "./schema/channels.js";
|
|
|
|
const Ajv = AjvPkg as unknown as new (opts?: object) => import("ajv").default;
|
|
|
|
describe("WebLoginWaitParamsSchema", () => {
|
|
const validate = new Ajv().compile(WebLoginWaitParamsSchema);
|
|
|
|
it("bounds caller-provided QR data URLs", () => {
|
|
expect(
|
|
validate({
|
|
currentQrDataUrl: "data:image/png;base64,qr",
|
|
}),
|
|
).toBe(true);
|
|
|
|
expect(
|
|
validate({
|
|
currentQrDataUrl: "x".repeat(16_385),
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
validate({
|
|
currentQrDataUrl: "https://example.com/qr.png",
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("ChannelsStatusResultSchema", () => {
|
|
const validate = new Ajv().compile(ChannelsStatusResultSchema);
|
|
|
|
it("accepts gateway event-loop diagnostics emitted by channels.status", () => {
|
|
expect(
|
|
validate({
|
|
ts: Date.now(),
|
|
channelOrder: ["discord"],
|
|
channelLabels: { discord: "Discord" },
|
|
channels: { discord: { configured: true } },
|
|
channelAccounts: {
|
|
discord: [
|
|
{
|
|
accountId: "default",
|
|
enabled: true,
|
|
configured: true,
|
|
running: true,
|
|
connected: false,
|
|
healthState: "stale-socket",
|
|
},
|
|
],
|
|
},
|
|
channelDefaultAccountId: { discord: "default" },
|
|
eventLoop: {
|
|
degraded: true,
|
|
reasons: ["event_loop_delay", "cpu"],
|
|
intervalMs: 62_000,
|
|
delayP99Ms: 1_250.5,
|
|
delayMaxMs: 62_000,
|
|
utilization: 0.98,
|
|
cpuCoreRatio: 1.2,
|
|
},
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
});
|