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";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { validateConfigObject } from "./config.js";
|
||||||
let validateConfigObject: typeof import("./config.js").validateConfigObject;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
({ validateConfigObject } = await import("./config.js"));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("meta.lastTouchedAt numeric timestamp coercion", () => {
|
describe("meta.lastTouchedAt numeric timestamp coercion", () => {
|
||||||
it("accepts a numeric Unix timestamp and coerces it to an ISO string", () => {
|
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 fs from "node:fs";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
@@ -9,10 +8,12 @@ import { __testing, loadOpenClawPlugins } from "./loader.js";
|
|||||||
|
|
||||||
type TempPlugin = { dir: string; file: string; id: string };
|
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;
|
let tempDirIndex = 0;
|
||||||
const prevBundledDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
const prevBundledDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
|
||||||
const EMPTY_PLUGIN_SCHEMA = { type: "object", additionalProperties: false, properties: {} };
|
const EMPTY_PLUGIN_SCHEMA = { type: "object", additionalProperties: false, properties: {} };
|
||||||
|
let cachedBundledTelegramDir = "";
|
||||||
|
let cachedBundledMemoryDir = "";
|
||||||
const BUNDLED_TELEGRAM_PLUGIN_BODY = `export default { id: "telegram", register(api) {
|
const BUNDLED_TELEGRAM_PLUGIN_BODY = `export default { id: "telegram", register(api) {
|
||||||
api.registerChannel({
|
api.registerChannel({
|
||||||
plugin: {
|
plugin: {
|
||||||
@@ -70,6 +71,20 @@ function loadBundledMemoryPluginRegistry(options?: {
|
|||||||
pluginBody?: string;
|
pluginBody?: string;
|
||||||
pluginFilename?: 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();
|
const bundledDir = makeTempDir();
|
||||||
let pluginDir = bundledDir;
|
let pluginDir = bundledDir;
|
||||||
let pluginFilename = options?.pluginFilename ?? "memory-core.js";
|
let pluginFilename = options?.pluginFilename ?? "memory-core.js";
|
||||||
@@ -101,6 +116,9 @@ function loadBundledMemoryPluginRegistry(options?: {
|
|||||||
dir: pluginDir,
|
dir: pluginDir,
|
||||||
filename: pluginFilename,
|
filename: pluginFilename,
|
||||||
});
|
});
|
||||||
|
if (!options) {
|
||||||
|
cachedBundledMemoryDir = bundledDir;
|
||||||
|
}
|
||||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledDir;
|
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledDir;
|
||||||
|
|
||||||
return loadOpenClawPlugins({
|
return loadOpenClawPlugins({
|
||||||
@@ -116,14 +134,16 @@ function loadBundledMemoryPluginRegistry(options?: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupBundledTelegramPlugin() {
|
function setupBundledTelegramPlugin() {
|
||||||
const bundledDir = makeTempDir();
|
if (!cachedBundledTelegramDir) {
|
||||||
writePlugin({
|
cachedBundledTelegramDir = makeTempDir();
|
||||||
id: "telegram",
|
writePlugin({
|
||||||
body: BUNDLED_TELEGRAM_PLUGIN_BODY,
|
id: "telegram",
|
||||||
dir: bundledDir,
|
body: BUNDLED_TELEGRAM_PLUGIN_BODY,
|
||||||
filename: "telegram.js",
|
dir: cachedBundledTelegramDir,
|
||||||
});
|
filename: "telegram.js",
|
||||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = bundledDir;
|
});
|
||||||
|
}
|
||||||
|
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = cachedBundledTelegramDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectTelegramLoaded(registry: ReturnType<typeof loadOpenClawPlugins>) {
|
function expectTelegramLoaded(registry: ReturnType<typeof loadOpenClawPlugins>) {
|
||||||
@@ -209,6 +229,9 @@ afterAll(() => {
|
|||||||
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
||||||
} catch {
|
} catch {
|
||||||
// ignore cleanup failures
|
// ignore cleanup failures
|
||||||
|
} finally {
|
||||||
|
cachedBundledTelegramDir = "";
|
||||||
|
cachedBundledMemoryDir = "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ exit 1`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
it("resolves fallback and preferred team IDs from provisioning profiles", async () => {
|
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");
|
const profilesDir = path.join(homeDir, "Library", "MobileDevice", "Provisioning Profiles");
|
||||||
await mkdir(profilesDir, { recursive: true });
|
await mkdir(profilesDir, { recursive: true });
|
||||||
await writeFile(path.join(profilesDir, "one.mobileprovision"), "stub1");
|
await writeFile(path.join(profilesDir, "one.mobileprovision"), "stub1");
|
||||||
@@ -126,6 +126,20 @@ exit 1`,
|
|||||||
const preferredResult = runScript(homeDir, { IOS_PREFERRED_TEAM_ID: "BBBBB22222" });
|
const preferredResult = runScript(homeDir, { IOS_PREFERRED_TEAM_ID: "BBBBB22222" });
|
||||||
expect(preferredResult.ok).toBe(true);
|
expect(preferredResult.ok).toBe(true);
|
||||||
expect(preferredResult.stdout).toBe("BBBBB22222");
|
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 () => {
|
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("An Apple account is signed in to Xcode");
|
||||||
expect(result.stderr).toContain("IOS_DEVELOPMENT_TEAM");
|
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