From 6855cbc3dfa9486eecc3b465771b2607c473cdc8 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 17 Jun 2026 10:45:04 +0800 Subject: [PATCH] refactor(plugins): hide cleanup timeout internals --- .../contracts/run-context-lifecycle.contract.test.ts | 3 ++- src/plugins/host-hook-cleanup-timeout.test.ts | 7 +++---- src/plugins/host-hook-cleanup-timeout.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/contracts/run-context-lifecycle.contract.test.ts b/src/plugins/contracts/run-context-lifecycle.contract.test.ts index 7f412f74e630..c761a350e9af 100644 --- a/src/plugins/contracts/run-context-lifecycle.contract.test.ts +++ b/src/plugins/contracts/run-context-lifecycle.contract.test.ts @@ -10,7 +10,6 @@ import { loadSessionStore, updateSessionStore } from "../../config/sessions.js"; import { withTempConfig } from "../../gateway/test-temp-config.js"; import { emitAgentEvent, resetAgentEventsForTest } from "../../infra/agent-events.js"; import { resolvePreferredOpenClawTmpDir } from "../../infra/tmp-openclaw-dir.js"; -import { PLUGIN_HOST_CLEANUP_TIMEOUT_MS } from "../host-hook-cleanup-timeout.js"; import { runPluginHostCleanup } from "../host-hook-cleanup.js"; import { clearPluginHostRuntimeState, @@ -26,6 +25,8 @@ import { setActivePluginRegistry } from "../runtime.js"; import { createPluginRecord } from "../status.test-helpers.js"; import type { OpenClawPluginApi } from "../types.js"; +const PLUGIN_HOST_CLEANUP_TIMEOUT_MS = 5_000; + async function waitForPluginEventHandlers(): Promise { await new Promise((resolve) => { setImmediate(resolve); diff --git a/src/plugins/host-hook-cleanup-timeout.test.ts b/src/plugins/host-hook-cleanup-timeout.test.ts index 0caed54e6ab8..bf4862c77dd1 100644 --- a/src/plugins/host-hook-cleanup-timeout.test.ts +++ b/src/plugins/host-hook-cleanup-timeout.test.ts @@ -1,9 +1,8 @@ /** Verifies host hook cleanup timeout behavior and cancellation reporting. */ import { afterEach, describe, expect, it, vi } from "vitest"; -import { - PLUGIN_HOST_CLEANUP_TIMEOUT_MS, - withPluginHostCleanupTimeout, -} from "./host-hook-cleanup-timeout.js"; +import { withPluginHostCleanupTimeout } from "./host-hook-cleanup-timeout.js"; + +const PLUGIN_HOST_CLEANUP_TIMEOUT_MS = 5_000; function requireSetTimeoutCall(callIndex: number): unknown[] { const call = vi.mocked(globalThis.setTimeout).mock.calls[callIndex]; diff --git a/src/plugins/host-hook-cleanup-timeout.ts b/src/plugins/host-hook-cleanup-timeout.ts index 1c98a808890b..f16083f9b381 100644 --- a/src/plugins/host-hook-cleanup-timeout.ts +++ b/src/plugins/host-hook-cleanup-timeout.ts @@ -1,8 +1,8 @@ /** Max time allowed for plugin host cleanup hooks before failing shutdown. */ -export const PLUGIN_HOST_CLEANUP_TIMEOUT_MS = 5_000; +const PLUGIN_HOST_CLEANUP_TIMEOUT_MS = 5_000; /** Error raised when a plugin host cleanup hook exceeds the shutdown timeout. */ -export class PluginHostCleanupTimeoutError extends Error { +class PluginHostCleanupTimeoutError extends Error { constructor(hookId: string) { super(`plugin host cleanup timed out: ${hookId}`); this.name = "PluginHostCleanupTimeoutError";