From 43bffe7bdc32bf835d2548402f433cfa1d5683e2 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 2 Mar 2026 11:35:04 +0000 Subject: [PATCH] test(perf): cache plugin fixtures and streamline shell tests --- .../config.meta-timestamp-coercion.test.ts | 9 +--- src/plugins/loader.test.ts | 43 ++++++++++++++----- test/scripts/ios-team-id.test.ts | 33 +++++++------- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/config/config.meta-timestamp-coercion.test.ts b/src/config/config.meta-timestamp-coercion.test.ts index 2fc75d1972c..84bf18ddaa4 100644 --- a/src/config/config.meta-timestamp-coercion.test.ts +++ b/src/config/config.meta-timestamp-coercion.test.ts @@ -1,10 +1,5 @@ -import { beforeAll, describe, expect, it } from "vitest"; - -let validateConfigObject: typeof import("./config.js").validateConfigObject; - -beforeAll(async () => { - ({ validateConfigObject } = await import("./config.js")); -}); +import { describe, expect, it } from "vitest"; +import { validateConfigObject } from "./config.js"; describe("meta.lastTouchedAt numeric timestamp coercion", () => { it("accepts a numeric Unix timestamp and coerces it to an ISO string", () => { diff --git a/src/plugins/loader.test.ts b/src/plugins/loader.test.ts index 3c2c692184d..a40073ae279 100644 --- a/src/plugins/loader.test.ts +++ b/src/plugins/loader.test.ts @@ -1,4 +1,3 @@ -import { randomUUID } from "node:crypto"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; @@ -9,10 +8,12 @@ import { __testing, loadOpenClawPlugins } from "./loader.js"; type TempPlugin = { dir: string; file: string; id: string }; -const fixtureRoot = path.join(os.tmpdir(), `openclaw-plugin-${randomUUID()}`); +const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-")); let tempDirIndex = 0; const prevBundledDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR; const EMPTY_PLUGIN_SCHEMA = { type: "object", additionalProperties: false, properties: {} }; +let cachedBundledTelegramDir = ""; +let cachedBundledMemoryDir = ""; const BUNDLED_TELEGRAM_PLUGIN_BODY = `export default { id: "telegram", register(api) { api.registerChannel({ plugin: { @@ -70,6 +71,20 @@ function loadBundledMemoryPluginRegistry(options?: { pluginBody?: string; pluginFilename?: string; }) { + if (!options && cachedBundledMemoryDir) { + process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = cachedBundledMemoryDir; + return loadOpenClawPlugins({ + cache: false, + config: { + plugins: { + slots: { + memory: "memory-core", + }, + }, + }, + }); + } + const bundledDir = makeTempDir(); let pluginDir = bundledDir; let pluginFilename = options?.pluginFilename ?? "memory-core.js"; @@ -101,6 +116,9 @@ function loadBundledMemoryPluginRegistry(options?: { dir: pluginDir, filename: pluginFilename, }); + if (!options) { + cachedBundledMemoryDir = bundledDir; + } process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledDir; return loadOpenClawPlugins({ @@ -116,14 +134,16 @@ function loadBundledMemoryPluginRegistry(options?: { } function setupBundledTelegramPlugin() { - const bundledDir = makeTempDir(); - writePlugin({ - id: "telegram", - body: BUNDLED_TELEGRAM_PLUGIN_BODY, - dir: bundledDir, - filename: "telegram.js", - }); - process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledDir; + if (!cachedBundledTelegramDir) { + cachedBundledTelegramDir = makeTempDir(); + writePlugin({ + id: "telegram", + body: BUNDLED_TELEGRAM_PLUGIN_BODY, + dir: cachedBundledTelegramDir, + filename: "telegram.js", + }); + } + process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = cachedBundledTelegramDir; } function expectTelegramLoaded(registry: ReturnType) { @@ -209,6 +229,9 @@ afterAll(() => { fs.rmSync(fixtureRoot, { recursive: true, force: true }); } catch { // ignore cleanup failures + } finally { + cachedBundledTelegramDir = ""; + cachedBundledMemoryDir = ""; } }); diff --git a/test/scripts/ios-team-id.test.ts b/test/scripts/ios-team-id.test.ts index 7662e8f05a2..10bca536630 100644 --- a/test/scripts/ios-team-id.test.ts +++ b/test/scripts/ios-team-id.test.ts @@ -113,7 +113,7 @@ exit 1`, } it("resolves fallback and preferred team IDs from provisioning profiles", async () => { - const { homeDir } = await createHomeDir(); + const { homeDir, binDir } = await createHomeDir(); const profilesDir = path.join(homeDir, "Library", "MobileDevice", "Provisioning Profiles"); await mkdir(profilesDir, { recursive: true }); await writeFile(path.join(profilesDir, "one.mobileprovision"), "stub1"); @@ -126,6 +126,20 @@ exit 1`, const preferredResult = runScript(homeDir, { IOS_PREFERRED_TEAM_ID: "BBBBB22222" }); expect(preferredResult.ok).toBe(true); expect(preferredResult.stdout).toBe("BBBBB22222"); + + await writeExecutable( + path.join(binDir, "fake-python"), + `#!/usr/bin/env bash +printf 'AAAAA11111\\t0\\tAlpha Team\\r\\n' +printf 'BBBBB22222\\t0\\tBeta Team\\r\\n'`, + ); + + const crlfResult = runScript(homeDir, { + IOS_PYTHON_BIN: path.join(binDir, "fake-python"), + IOS_PREFERRED_TEAM_ID: "BBBBB22222", + }); + expect(crlfResult.ok).toBe(true); + expect(crlfResult.stdout).toBe("BBBBB22222"); }); it("prints actionable guidance when Xcode account exists but no Team ID is resolvable", async () => { @@ -151,21 +165,4 @@ exit 1`, expect(result.stderr).toContain("An Apple account is signed in to Xcode"); expect(result.stderr).toContain("IOS_DEVELOPMENT_TEAM"); }); - - it("matches preferred team IDs even when parser output uses CRLF line endings", async () => { - const { homeDir, binDir } = await createHomeDir(); - await writeExecutable( - path.join(binDir, "fake-python"), - `#!/usr/bin/env bash -printf 'AAAAA11111\\t0\\tAlpha Team\\r\\n' -printf 'BBBBB22222\\t0\\tBeta Team\\r\\n'`, - ); - - const result = runScript(homeDir, { - IOS_PYTHON_BIN: path.join(binDir, "fake-python"), - IOS_PREFERRED_TEAM_ID: "BBBBB22222", - }); - expect(result.ok).toBe(true); - expect(result.stdout).toBe("BBBBB22222"); - }); });