mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test(perf): cache plugin fixtures and streamline shell tests
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -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<typeof loadOpenClawPlugins>) {
|
||||
@@ -209,6 +229,9 @@ afterAll(() => {
|
||||
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
||||
} catch {
|
||||
// ignore cleanup failures
|
||||
} finally {
|
||||
cachedBundledTelegramDir = "";
|
||||
cachedBundledMemoryDir = "";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user