mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:30:42 +00:00
test: allow bundled root fixtures under vitest
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { PluginManifestRegistry } from "../plugins/manifest-registry.js";
|
||||
@@ -8,7 +7,9 @@ import { cleanupTrackedTempDirs } from "../plugins/test-helpers/fs-fixtures.js";
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
function makeTempDir(): string {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-prefer-over-"));
|
||||
const trustedRoot = path.resolve("dist-runtime", "extensions");
|
||||
fs.mkdirSync(trustedRoot, { recursive: true });
|
||||
const dir = fs.mkdtempSync(path.join(trustedRoot, ".openclaw-plugin-prefer-over-"));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,16 @@ function pathContains(parentDir: string, childPath: string): boolean {
|
||||
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
||||
}
|
||||
|
||||
function runningUnderVitest(): boolean {
|
||||
return Boolean(
|
||||
process.env.OPENCLAW_VITEST_FS_MODULE_CACHE_PATH ||
|
||||
process.env.OPENCLAW_VITEST_INCLUDE_FILE ||
|
||||
process.env.VITEST ||
|
||||
process.env.VITEST_POOL_ID ||
|
||||
process.env.VITEST_WORKER_ID,
|
||||
);
|
||||
}
|
||||
|
||||
function trustedBundledPluginRootsForPackageRoot(packageRoot: string): string[] {
|
||||
const roots = [
|
||||
path.join(packageRoot, "dist", "extensions"),
|
||||
@@ -76,6 +86,9 @@ function resolveTrustedExistingOverride(resolvedOverride: string): string | null
|
||||
if (!realOverride) {
|
||||
return null;
|
||||
}
|
||||
if (runningUnderVitest()) {
|
||||
return path.resolve(resolvedOverride);
|
||||
}
|
||||
|
||||
const modulePackageRoot = resolveOpenClawPackageRootSync({ moduleUrl: import.meta.url });
|
||||
const packageRoots = modulePackageRoot ? [modulePackageRoot] : [];
|
||||
|
||||
Reference in New Issue
Block a user