fix(test): reduce startup-heavy hotspot retention (#52381)

This commit is contained in:
Vincent Koc
2026-03-22 12:28:55 -07:00
committed by GitHub
parent 26d400bea6
commit dbd26e49f1
12 changed files with 380 additions and 212 deletions

View File

@@ -7,9 +7,14 @@ const registerFeishuWikiToolsMock = vi.hoisted(() => vi.fn());
const registerFeishuDriveToolsMock = vi.hoisted(() => vi.fn());
const registerFeishuPermToolsMock = vi.hoisted(() => vi.fn());
const registerFeishuBitableToolsMock = vi.hoisted(() => vi.fn());
const feishuPluginMock = vi.hoisted(() => ({ id: "feishu-test-plugin" }));
const setFeishuRuntimeMock = vi.hoisted(() => vi.fn());
const registerFeishuSubagentHooksMock = vi.hoisted(() => vi.fn());
vi.mock("./src/channel.js", () => ({
feishuPlugin: feishuPluginMock,
}));
vi.mock("./src/docx.js", () => ({
registerFeishuDocTools: registerFeishuDocToolsMock,
}));
@@ -58,6 +63,7 @@ describe("feishu plugin register", () => {
expect(setFeishuRuntimeMock).toHaveBeenCalledWith(api.runtime);
expect(registerChannel).toHaveBeenCalledTimes(1);
expect(registerChannel).toHaveBeenCalledWith({ plugin: feishuPluginMock });
expect(registerFeishuSubagentHooksMock).toHaveBeenCalledWith(api);
expect(registerFeishuDocToolsMock).toHaveBeenCalledWith(api);
expect(registerFeishuChatToolsMock).toHaveBeenCalledWith(api);

View File

@@ -3,7 +3,7 @@ import type { Server } from "node:http";
import { createConnection, type AddressInfo } from "node:net";
import express from "express";
import { describe, expect, it } from "vitest";
import { applyMSTeamsWebhookTimeouts } from "./monitor.js";
import { applyMSTeamsWebhookTimeouts } from "./webhook-timeouts.js";
async function closeServer(server: Server): Promise<void> {
await new Promise<void>((resolve) => {

View File

@@ -1,4 +1,3 @@
import type { Server } from "node:http";
import type { Request, Response } from "express";
import {
DEFAULT_WEBHOOK_MAX_BODY_BYTES,
@@ -21,6 +20,10 @@ import {
import { getMSTeamsRuntime } from "./runtime.js";
import { createMSTeamsAdapter, loadMSTeamsSdkWithAuth } from "./sdk.js";
import { resolveMSTeamsCredentials } from "./token.js";
import {
applyMSTeamsWebhookTimeouts,
type ApplyMSTeamsWebhookTimeoutsOpts,
} from "./webhook-timeouts.js";
export type MonitorMSTeamsOpts = {
cfg: OpenClawConfig;
@@ -36,32 +39,6 @@ export type MonitorMSTeamsResult = {
};
const MSTEAMS_WEBHOOK_MAX_BODY_BYTES = DEFAULT_WEBHOOK_MAX_BODY_BYTES;
const MSTEAMS_WEBHOOK_INACTIVITY_TIMEOUT_MS = 30_000;
const MSTEAMS_WEBHOOK_REQUEST_TIMEOUT_MS = 30_000;
const MSTEAMS_WEBHOOK_HEADERS_TIMEOUT_MS = 15_000;
export type ApplyMSTeamsWebhookTimeoutsOpts = {
inactivityTimeoutMs?: number;
requestTimeoutMs?: number;
headersTimeoutMs?: number;
};
export function applyMSTeamsWebhookTimeouts(
httpServer: Server,
opts?: ApplyMSTeamsWebhookTimeoutsOpts,
): void {
const inactivityTimeoutMs = opts?.inactivityTimeoutMs ?? MSTEAMS_WEBHOOK_INACTIVITY_TIMEOUT_MS;
const requestTimeoutMs = opts?.requestTimeoutMs ?? MSTEAMS_WEBHOOK_REQUEST_TIMEOUT_MS;
const headersTimeoutMs = Math.min(
opts?.headersTimeoutMs ?? MSTEAMS_WEBHOOK_HEADERS_TIMEOUT_MS,
requestTimeoutMs,
);
httpServer.setTimeout(inactivityTimeoutMs);
httpServer.requestTimeout = requestTimeoutMs;
httpServer.headersTimeout = headersTimeoutMs;
}
export async function monitorMSTeamsProvider(
opts: MonitorMSTeamsOpts,
): Promise<MonitorMSTeamsResult> {

View File

@@ -0,0 +1,27 @@
import type { Server } from "node:http";
const MSTEAMS_WEBHOOK_INACTIVITY_TIMEOUT_MS = 30_000;
const MSTEAMS_WEBHOOK_REQUEST_TIMEOUT_MS = 30_000;
const MSTEAMS_WEBHOOK_HEADERS_TIMEOUT_MS = 15_000;
export type ApplyMSTeamsWebhookTimeoutsOpts = {
inactivityTimeoutMs?: number;
requestTimeoutMs?: number;
headersTimeoutMs?: number;
};
export function applyMSTeamsWebhookTimeouts(
httpServer: Server,
opts?: ApplyMSTeamsWebhookTimeoutsOpts,
): void {
const inactivityTimeoutMs = opts?.inactivityTimeoutMs ?? MSTEAMS_WEBHOOK_INACTIVITY_TIMEOUT_MS;
const requestTimeoutMs = opts?.requestTimeoutMs ?? MSTEAMS_WEBHOOK_REQUEST_TIMEOUT_MS;
const headersTimeoutMs = Math.min(
opts?.headersTimeoutMs ?? MSTEAMS_WEBHOOK_HEADERS_TIMEOUT_MS,
requestTimeoutMs,
);
httpServer.setTimeout(inactivityTimeoutMs);
httpServer.requestTimeout = requestTimeoutMs;
httpServer.headersTimeout = headersTimeoutMs;
}