test: allow bundled root fixtures under vitest

This commit is contained in:
Peter Steinberger
2026-04-28 20:14:50 +01:00
parent e61756f9e8
commit 9f37ff0c6c
2 changed files with 16 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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] : [];