mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:31:23 +00:00
perf(test): fold gateway server utils into misc suite
This commit is contained in:
@@ -7,6 +7,7 @@ import type { RequestFrame } from "./protocol/index.js";
|
|||||||
import type { GatewayClient as GatewayMethodClient } from "./server-methods/types.js";
|
import type { GatewayClient as GatewayMethodClient } from "./server-methods/types.js";
|
||||||
import type { GatewayRequestContext, RespondFn } from "./server-methods/types.js";
|
import type { GatewayRequestContext, RespondFn } from "./server-methods/types.js";
|
||||||
import type { GatewayWsClient } from "./server/ws-types.js";
|
import type { GatewayWsClient } from "./server/ws-types.js";
|
||||||
|
import { defaultVoiceWakeTriggers } from "../infra/voicewake.js";
|
||||||
import { GatewayClient } from "./client.js";
|
import { GatewayClient } from "./client.js";
|
||||||
import { handleControlUiHttpRequest } from "./control-ui.js";
|
import { handleControlUiHttpRequest } from "./control-ui.js";
|
||||||
import {
|
import {
|
||||||
@@ -17,6 +18,7 @@ import { createGatewayBroadcaster } from "./server-broadcast.js";
|
|||||||
import { createChatRunRegistry } from "./server-chat.js";
|
import { createChatRunRegistry } from "./server-chat.js";
|
||||||
import { handleNodeInvokeResult } from "./server-methods/nodes.handlers.invoke-result.js";
|
import { handleNodeInvokeResult } from "./server-methods/nodes.handlers.invoke-result.js";
|
||||||
import { createNodeSubscriptionManager } from "./server-node-subscriptions.js";
|
import { createNodeSubscriptionManager } from "./server-node-subscriptions.js";
|
||||||
|
import { formatError, normalizeVoiceWakeTriggers } from "./server-utils.js";
|
||||||
|
|
||||||
const wsMockState = vi.hoisted(() => ({
|
const wsMockState = vi.hoisted(() => ({
|
||||||
last: null as { url: unknown; opts: unknown } | null,
|
last: null as { url: unknown; opts: unknown } | null,
|
||||||
@@ -281,3 +283,27 @@ describe("resolveNodeCommandAllowlist", () => {
|
|||||||
expect(allow.has("camera.clip")).toBe(false);
|
expect(allow.has("camera.clip")).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("normalizeVoiceWakeTriggers", () => {
|
||||||
|
test("returns defaults when input is empty", () => {
|
||||||
|
expect(normalizeVoiceWakeTriggers([])).toEqual(defaultVoiceWakeTriggers());
|
||||||
|
expect(normalizeVoiceWakeTriggers(null)).toEqual(defaultVoiceWakeTriggers());
|
||||||
|
});
|
||||||
|
|
||||||
|
test("trims and limits entries", () => {
|
||||||
|
const result = normalizeVoiceWakeTriggers([" hello ", "", "world"]);
|
||||||
|
expect(result).toEqual(["hello", "world"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("formatError", () => {
|
||||||
|
test("prefers message for Error", () => {
|
||||||
|
expect(formatError(new Error("boom"))).toBe("boom");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("handles status/code", () => {
|
||||||
|
expect(formatError({ status: 500, code: "EPIPE" })).toBe("status=500 code=EPIPE");
|
||||||
|
expect(formatError({ status: 404 })).toBe("status=404 code=unknown");
|
||||||
|
expect(formatError({ code: "ENOENT" })).toBe("status=unknown code=ENOENT");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import { describe, expect, test } from "vitest";
|
|
||||||
import { defaultVoiceWakeTriggers } from "../infra/voicewake.js";
|
|
||||||
import { formatError, normalizeVoiceWakeTriggers } from "./server-utils.js";
|
|
||||||
|
|
||||||
describe("normalizeVoiceWakeTriggers", () => {
|
|
||||||
test("returns defaults when input is empty", () => {
|
|
||||||
expect(normalizeVoiceWakeTriggers([])).toEqual(defaultVoiceWakeTriggers());
|
|
||||||
expect(normalizeVoiceWakeTriggers(null)).toEqual(defaultVoiceWakeTriggers());
|
|
||||||
});
|
|
||||||
|
|
||||||
test("trims and limits entries", () => {
|
|
||||||
const result = normalizeVoiceWakeTriggers([" hello ", "", "world"]);
|
|
||||||
expect(result).toEqual(["hello", "world"]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("formatError", () => {
|
|
||||||
test("prefers message for Error", () => {
|
|
||||||
expect(formatError(new Error("boom"))).toBe("boom");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("handles status/code", () => {
|
|
||||||
expect(formatError({ status: 500, code: "EPIPE" })).toBe("status=500 code=EPIPE");
|
|
||||||
expect(formatError({ status: 404 })).toBe("status=404 code=unknown");
|
|
||||||
expect(formatError({ code: "ENOENT" })).toBe("status=unknown code=ENOENT");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user