mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test(perf): trim slack, hook, and plugin-validation test overhead
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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<string, string>();
|
||||
|
||||
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,
|
||||
|
||||
@@ -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> = {}): 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") {
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user