mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 19:50:42 +00:00
Merged via squash.
Prepared head SHA: 3d6ee85993
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
emitDiagnosticEvent,
|
|
resetDiagnosticEventsForTest,
|
|
} from "../../infra/diagnostic-events.js";
|
|
import {
|
|
resetDiagnosticStabilityRecorderForTest,
|
|
startDiagnosticStabilityRecorder,
|
|
stopDiagnosticStabilityRecorder,
|
|
} from "../../logging/diagnostic-stability.js";
|
|
import { diagnosticsHandlers } from "./diagnostics.js";
|
|
|
|
describe("diagnostics gateway methods", () => {
|
|
beforeEach(() => {
|
|
resetDiagnosticStabilityRecorderForTest();
|
|
resetDiagnosticEventsForTest();
|
|
startDiagnosticStabilityRecorder();
|
|
});
|
|
|
|
afterEach(() => {
|
|
stopDiagnosticStabilityRecorder();
|
|
resetDiagnosticStabilityRecorderForTest();
|
|
resetDiagnosticEventsForTest();
|
|
});
|
|
|
|
it("returns a filtered stability snapshot", async () => {
|
|
emitDiagnosticEvent({ type: "webhook.received", channel: "telegram" });
|
|
emitDiagnosticEvent({
|
|
type: "payload.large",
|
|
surface: "gateway.http.json",
|
|
action: "rejected",
|
|
bytes: 1024,
|
|
limitBytes: 512,
|
|
});
|
|
|
|
const respond = vi.fn();
|
|
await diagnosticsHandlers["diagnostics.stability"]({
|
|
req: { type: "req", id: "1", method: "diagnostics.stability", params: {} },
|
|
params: { type: "payload.large", limit: 10 },
|
|
client: null,
|
|
isWebchatConnect: () => false,
|
|
context: {} as never,
|
|
respond,
|
|
});
|
|
|
|
expect(respond).toHaveBeenCalledWith(
|
|
true,
|
|
expect.objectContaining({
|
|
count: 1,
|
|
events: [
|
|
expect.objectContaining({
|
|
type: "payload.large",
|
|
surface: "gateway.http.json",
|
|
action: "rejected",
|
|
}),
|
|
],
|
|
}),
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
it("rejects invalid stability params", async () => {
|
|
const respond = vi.fn();
|
|
await diagnosticsHandlers["diagnostics.stability"]({
|
|
req: { type: "req", id: "1", method: "diagnostics.stability", params: {} },
|
|
params: { limit: 0 },
|
|
client: null,
|
|
isWebchatConnect: () => false,
|
|
context: {} as never,
|
|
respond,
|
|
});
|
|
|
|
expect(respond).toHaveBeenCalledWith(
|
|
false,
|
|
undefined,
|
|
expect.objectContaining({
|
|
code: "INVALID_REQUEST",
|
|
message: "limit must be between 1 and 1000",
|
|
}),
|
|
);
|
|
});
|
|
});
|