From 9657ded2e11565f7fe62580471f9c5ab7fa43876 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 3 Mar 2026 00:42:30 +0000 Subject: [PATCH] test(perf): trim slack, hook, and plugin-validation test overhead --- src/config/config.plugin-validation.test.ts | 8 ++++++++ src/hooks/install.test.ts | 18 +++++++++++++----- src/slack/monitor.tool-result.test.ts | 19 ++++++++++--------- .../monitor/message-handler/prepare.test.ts | 13 +++++++------ 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/config/config.plugin-validation.test.ts b/src/config/config.plugin-validation.test.ts index 72b3b4680c8..488d4ab7eac 100644 --- a/src/config/config.plugin-validation.test.ts +++ b/src/config/config.plugin-validation.test.ts @@ -70,6 +70,14 @@ describe("config plugin validation", () => { process.env.OPENCLAW_STATE_DIR = path.join(suiteHome, ".openclaw"); process.env.OPENCLAW_PLUGIN_MANIFEST_CACHE_MS = "10000"; clearPluginManifestRegistryCache(); + // Warm the plugin manifest cache once so path-based validations can reuse + // parsed manifests across test cases. + validateInSuite({ + plugins: { + enabled: false, + load: { paths: [badPluginDir, bluebubblesPluginDir] }, + }, + }); }); afterAll(async () => { diff --git a/src/hooks/install.test.ts b/src/hooks/install.test.ts index 5930de2c2b7..1f4dd0a4f68 100644 --- a/src/hooks/install.test.ts +++ b/src/hooks/install.test.ts @@ -1,4 +1,4 @@ -import { randomUUID } from "node:crypto"; +import { createHash, randomUUID } from "node:crypto"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; @@ -13,7 +13,9 @@ import { import { isAddressInUseError } from "./gmail-watcher.js"; const fixtureRoot = path.join(os.tmpdir(), `openclaw-hook-install-${randomUUID()}`); +const sharedArchiveDir = path.join(fixtureRoot, "_archives"); let tempDirIndex = 0; +const sharedArchivePathByName = new Map(); const fixturesDir = path.resolve(process.cwd(), "test", "fixtures", "hooks-install"); const zipHooksBuffer = fs.readFileSync(path.join(fixturesDir, "zip-hooks.zip")); @@ -30,7 +32,7 @@ vi.mock("../process/exec.js", () => ({ function makeTempDir() { const dir = path.join(fixtureRoot, `case-${tempDirIndex++}`); - fs.mkdirSync(dir, { recursive: true }); + fs.mkdirSync(dir); return dir; } @@ -52,13 +54,19 @@ beforeEach(() => { beforeAll(() => { fs.mkdirSync(fixtureRoot, { recursive: true }); + fs.mkdirSync(sharedArchiveDir, { recursive: true }); }); function writeArchiveFixture(params: { fileName: string; contents: Buffer }) { const stateDir = makeTempDir(); - const workDir = makeTempDir(); - const archivePath = path.join(workDir, params.fileName); - fs.writeFileSync(archivePath, params.contents); + const archiveHash = createHash("sha256").update(params.contents).digest("hex").slice(0, 12); + const archiveKey = `${params.fileName}:${archiveHash}`; + let archivePath = sharedArchivePathByName.get(archiveKey); + if (!archivePath) { + archivePath = path.join(sharedArchiveDir, `${archiveHash}-${params.fileName}`); + fs.writeFileSync(archivePath, params.contents); + sharedArchivePathByName.set(archiveKey, archivePath); + } return { stateDir, archivePath, diff --git a/src/slack/monitor.tool-result.test.ts b/src/slack/monitor.tool-result.test.ts index cf81828ceac..210ce81a91b 100644 --- a/src/slack/monitor.tool-result.test.ts +++ b/src/slack/monitor.tool-result.test.ts @@ -37,16 +37,17 @@ describe("monitorSlackProvider tool results", () => { parent_user_id?: string; }; + const baseSlackMessageEvent = Object.freeze({ + type: "message", + user: "U1", + text: "hello", + ts: "123", + channel: "C1", + channel_type: "im", + }) as SlackMessageEvent; + function makeSlackMessageEvent(overrides: Partial = {}): SlackMessageEvent { - return { - type: "message", - user: "U1", - text: "hello", - ts: "123", - channel: "C1", - channel_type: "im", - ...overrides, - }; + return { ...baseSlackMessageEvent, ...overrides }; } function setDirectMessageReplyMode(replyToMode: "off" | "all" | "first") { diff --git a/src/slack/monitor/message-handler/prepare.test.ts b/src/slack/monitor/message-handler/prepare.test.ts index 64f59b2e2dd..d503e16c346 100644 --- a/src/slack/monitor/message-handler/prepare.test.ts +++ b/src/slack/monitor/message-handler/prepare.test.ts @@ -59,14 +59,14 @@ describe("slack prepareSlackMessage inbound contract", () => { userTokenSource: "none", config: {}, }; - const defaultMessageTemplate: SlackMessageEvent = { + const defaultMessageTemplate = Object.freeze({ channel: "D123", channel_type: "im", user: "U1", text: "hi", ts: "1.000", - } as SlackMessageEvent; - const threadAccount: ResolvedSlackAccount = { + }) as SlackMessageEvent; + const threadAccount = Object.freeze({ accountId: "default", enabled: true, botTokenSource: "config", @@ -77,14 +77,15 @@ describe("slack prepareSlackMessage inbound contract", () => { thread: { initialHistoryLimit: 20 }, }, replyToMode: "all", - }; + }) as ResolvedSlackAccount; + const defaultPrepareOpts = Object.freeze({ source: "message" }) as { source: "message" }; async function prepareWithDefaultCtx(message: SlackMessageEvent) { return prepareSlackMessage({ ctx: createDefaultSlackCtx(), account: defaultAccount, message, - opts: { source: "message" }, + opts: defaultPrepareOpts, }); } @@ -101,7 +102,7 @@ describe("slack prepareSlackMessage inbound contract", () => { ctx, account, message, - opts: { source: "message" }, + opts: defaultPrepareOpts, }); }