惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
博客园 - 聂微东
S
SegmentFault 最新的问题
量子位
宝玉的分享
宝玉的分享
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(feishu): await HTTP server shutdown during monitor cl...
openclaw-clo · 2026-06-14 · via Recent Commits to openclaw:main
11

// Feishu tests cover monitor.cleanup plugin behavior.

2+

import type { Server } from "node:http";

23

import { afterAll, afterEach, describe, expect, it, vi } from "vitest";

3-

import { botNames, botOpenIds, stopFeishuMonitorState, wsClients } from "./monitor.state.js";

4+

import {

5+

botNames,

6+

botOpenIds,

7+

FEISHU_HTTP_SERVER_CLOSE_TIMEOUT_MS,

8+

httpServers,

9+

setFeishuBotIdentityState,

10+

stopFeishuMonitorState,

11+

wsClients,

12+

} from "./monitor.state.js";

413

import type { ResolvedFeishuAccount } from "./types.js";

514615

const createFeishuWSClientMock = vi.hoisted(() => vi.fn());

@@ -38,6 +47,34 @@ function createWsClient(): MockWsClient {

3847

};

3948

}

404950+

function createHttpServerMock(): {

51+

server: Server;

52+

close: ReturnType<typeof vi.fn>;

53+

closeAllConnections: ReturnType<typeof vi.fn>;

54+

finishClose: (error?: Error) => void;

55+

} {

56+

let closeCallback: ((err?: Error) => void) | undefined;

57+

const server = {} as Server;

58+

const close = vi.fn((callback?: (err?: Error) => void) => {

59+

closeCallback = callback;

60+

return server;

61+

});

62+

const closeAllConnections = vi.fn();

63+

server.close = close as unknown as Server["close"];

64+

server.closeAllConnections = closeAllConnections;

65+

return {

66+

server,

67+

close,

68+

closeAllConnections,

69+

finishClose: (error?: Error) => {

70+

if (!closeCallback) {

71+

throw new Error("expected HTTP server close callback");

72+

}

73+

closeCallback(error);

74+

},

75+

};

76+

}

77+4178

function firstRuntimeError(runtime: { error: ReturnType<typeof vi.fn> }): string {

4279

return String(runtime.error.mock.calls[0]?.[0] ?? "");

4380

}

@@ -50,9 +87,9 @@ function firstWsCallbacks(): { onError?: (err: Error) => void } {

5087

return callbacks as { onError?: (err: Error) => void };

5188

}

528953-

afterEach(() => {

90+

afterEach(async () => {

5491

vi.useRealTimers();

55-

stopFeishuMonitorState();

92+

await stopFeishuMonitorState();

5693

vi.clearAllMocks();

5794

});

5895

@@ -339,7 +376,7 @@ describe("feishu websocket cleanup", () => {

339376

expect(errorMessage).not.toContain("secret_token");

340377

});

341378342-

it("closes targeted websocket clients during stop cleanup", () => {

379+

it("closes targeted websocket clients during stop cleanup", async () => {

343380

const alphaClient = createWsClient();

344381

const betaClient = createWsClient();

345382

@@ -350,7 +387,7 @@ describe("feishu websocket cleanup", () => {

350387

botNames.set("alpha", "Alpha");

351388

botNames.set("beta", "Beta");

352389353-

stopFeishuMonitorState("alpha");

390+

await stopFeishuMonitorState("alpha");

354391355392

expect(alphaClient.close).toHaveBeenCalledTimes(1);

356393

expect(betaClient.close).not.toHaveBeenCalled();

@@ -362,7 +399,7 @@ describe("feishu websocket cleanup", () => {

362399

expect(botNames.has("beta")).toBe(true);

363400

});

364401365-

it("closes all websocket clients during global stop cleanup", () => {

402+

it("closes all websocket clients during global stop cleanup", async () => {

366403

const alphaClient = createWsClient();

367404

const betaClient = createWsClient();

368405

@@ -373,12 +410,136 @@ describe("feishu websocket cleanup", () => {

373410

botNames.set("alpha", "Alpha");

374411

botNames.set("beta", "Beta");

375412376-

stopFeishuMonitorState();

413+

await stopFeishuMonitorState();

377414378415

expect(alphaClient.close).toHaveBeenCalledTimes(1);

379416

expect(betaClient.close).toHaveBeenCalledTimes(1);

380417

expect(wsClients.size).toBe(0);

381418

expect(botOpenIds.size).toBe(0);

382419

expect(botNames.size).toBe(0);

383420

});

421+422+

it("keeps targeted HTTP server state until close completes", async () => {

423+

const { server, close, closeAllConnections, finishClose } = createHttpServerMock();

424+425+

httpServers.set("alpha", server);

426+

botOpenIds.set("alpha", "ou_alpha");

427+

botNames.set("alpha", "Alpha");

428+429+

const stopPromise = stopFeishuMonitorState("alpha");

430+

await Promise.resolve();

431+432+

expect(close).toHaveBeenCalledTimes(1);

433+

expect(httpServers.get("alpha")).toBe(server);

434+

expect(botOpenIds.get("alpha")).toBe("ou_alpha");

435+

expect(botNames.get("alpha")).toBe("Alpha");

436+437+

finishClose();

438+

await stopPromise;

439+440+

expect(closeAllConnections).not.toHaveBeenCalled();

441+

expect(httpServers.has("alpha")).toBe(false);

442+

expect(botOpenIds.has("alpha")).toBe(false);

443+

expect(botNames.has("alpha")).toBe(false);

444+

});

445+446+

it("preserves replacement HTTP state after delayed targeted cleanup", async () => {

447+

const oldServer = createHttpServerMock();

448+

const replacementServer = createHttpServerMock();

449+450+

httpServers.set("alpha", oldServer.server);

451+

setFeishuBotIdentityState("alpha", { botOpenId: "ou_old", botName: "Old" });

452+453+

const stopPromise = stopFeishuMonitorState("alpha");

454+

await Promise.resolve();

455+456+

setFeishuBotIdentityState("alpha", { botOpenId: "ou_new", botName: "New" });

457+

httpServers.set("alpha", replacementServer.server);

458+459+

oldServer.finishClose();

460+

await stopPromise;

461+462+

expect(httpServers.get("alpha")).toBe(replacementServer.server);

463+

expect(botOpenIds.get("alpha")).toBe("ou_new");

464+

expect(botNames.get("alpha")).toBe("New");

465+466+

const cleanupPromise = stopFeishuMonitorState("alpha");

467+

await Promise.resolve();

468+

replacementServer.finishClose();

469+

await cleanupPromise;

470+

});

471+472+

it("preserves replacement identity written before the replacement HTTP server is tracked", async () => {

473+

const oldServer = createHttpServerMock();

474+475+

httpServers.set("alpha", oldServer.server);

476+

setFeishuBotIdentityState("alpha", { botOpenId: "ou_old", botName: "Old" });

477+478+

const stopPromise = stopFeishuMonitorState("alpha");

479+

await Promise.resolve();

480+481+

setFeishuBotIdentityState("alpha", { botOpenId: "ou_new", botName: "New" });

482+483+

oldServer.finishClose();

484+

await stopPromise;

485+486+

expect(httpServers.has("alpha")).toBe(false);

487+

expect(botOpenIds.get("alpha")).toBe("ou_new");

488+

expect(botNames.get("alpha")).toBe("New");

489+490+

await stopFeishuMonitorState("alpha");

491+

});

492+493+

it("forces targeted HTTP server cleanup after the close timeout", async () => {

494+

vi.useFakeTimers();

495+

const { server, close, closeAllConnections } = createHttpServerMock();

496+497+

httpServers.set("alpha", server);

498+

botOpenIds.set("alpha", "ou_alpha");

499+

botNames.set("alpha", "Alpha");

500+501+

const stopPromise = stopFeishuMonitorState("alpha");

502+

await Promise.resolve();

503+504+

expect(close).toHaveBeenCalledTimes(1);

505+

expect(httpServers.get("alpha")).toBe(server);

506+507+

await vi.advanceTimersByTimeAsync(FEISHU_HTTP_SERVER_CLOSE_TIMEOUT_MS - 1);

508+

expect(closeAllConnections).not.toHaveBeenCalled();

509+

expect(httpServers.get("alpha")).toBe(server);

510+511+

await vi.advanceTimersByTimeAsync(1);

512+

await stopPromise;

513+514+

expect(closeAllConnections).toHaveBeenCalledTimes(1);

515+

expect(httpServers.has("alpha")).toBe(false);

516+

expect(botOpenIds.has("alpha")).toBe(false);

517+

expect(botNames.has("alpha")).toBe(false);

518+

});

519+520+

it("preserves replacement HTTP state after delayed global cleanup", async () => {

521+

const oldServer = createHttpServerMock();

522+

const replacementServer = createHttpServerMock();

523+524+

httpServers.set("alpha", oldServer.server);

525+

setFeishuBotIdentityState("alpha", { botOpenId: "ou_old", botName: "Old" });

526+527+

const stopPromise = stopFeishuMonitorState();

528+

await Promise.resolve();

529+530+

setFeishuBotIdentityState("alpha", { botOpenId: "ou_new", botName: "New" });

531+

httpServers.set("alpha", replacementServer.server);

532+533+

oldServer.finishClose();

534+

await stopPromise;

535+536+

expect(httpServers.get("alpha")).toBe(replacementServer.server);

537+

expect(botOpenIds.get("alpha")).toBe("ou_new");

538+

expect(botNames.get("alpha")).toBe("New");

539+540+

const cleanupPromise = stopFeishuMonitorState("alpha");

541+

await Promise.resolve();

542+

replacementServer.finishClose();

543+

await cleanupPromise;

544+

});

384545

});