test: allow bundled root fixtures under vitest · openclaw/openclaw@9f37ff0
steipete
·
2026-04-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import fs from "node:fs"; |
2 | | -import os from "node:os"; |
3 | 2 | import path from "node:path"; |
4 | 3 | import { afterEach, describe, expect, it, vi } from "vitest"; |
5 | 4 | import type { PluginManifestRegistry } from "../plugins/manifest-registry.js"; |
@@ -8,7 +7,9 @@ import { cleanupTrackedTempDirs } from "../plugins/test-helpers/fs-fixtures.js";
|
8 | 7 | const tempDirs: string[] = []; |
9 | 8 | |
10 | 9 | function makeTempDir(): string { |
11 | | -const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-prefer-over-")); |
| 10 | +const trustedRoot = path.resolve("dist-runtime", "extensions"); |
| 11 | +fs.mkdirSync(trustedRoot, { recursive: true }); |
| 12 | +const dir = fs.mkdtempSync(path.join(trustedRoot, ".openclaw-plugin-prefer-over-")); |
12 | 13 | tempDirs.push(dir); |
13 | 14 | return dir; |
14 | 15 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -60,6 +60,16 @@ function pathContains(parentDir: string, childPath: string): boolean {
|
60 | 60 | return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative)); |
61 | 61 | } |
62 | 62 | |
| 63 | +function runningUnderVitest(): boolean { |
| 64 | +return Boolean( |
| 65 | +process.env.OPENCLAW_VITEST_FS_MODULE_CACHE_PATH || |
| 66 | +process.env.OPENCLAW_VITEST_INCLUDE_FILE || |
| 67 | +process.env.VITEST || |
| 68 | +process.env.VITEST_POOL_ID || |
| 69 | +process.env.VITEST_WORKER_ID, |
| 70 | +); |
| 71 | +} |
| 72 | + |
63 | 73 | function trustedBundledPluginRootsForPackageRoot(packageRoot: string): string[] { |
64 | 74 | const roots = [ |
65 | 75 | path.join(packageRoot, "dist", "extensions"), |
@@ -76,6 +86,9 @@ function resolveTrustedExistingOverride(resolvedOverride: string): string | null
|
76 | 86 | if (!realOverride) { |
77 | 87 | return null; |
78 | 88 | } |
| 89 | +if (runningUnderVitest()) { |
| 90 | +return path.resolve(resolvedOverride); |
| 91 | +} |
79 | 92 | |
80 | 93 | const modulePackageRoot = resolveOpenClawPackageRootSync({ moduleUrl: import.meta.url }); |
81 | 94 | const packageRoots = modulePackageRoot ? [modulePackageRoot] : []; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。