
























@@ -14,6 +14,7 @@ import {
1414resolveDirectNodeVitestArgs,
1515resolveExplicitTestFileNoPassArgs,
1616resolveImplicitVitestArgs,
17+resolveLinkedSourceBundledPluginsEnv,
1718resolveMissingVitestDependencyMessage,
1819resolveMissingExplicitTestFiles,
1920resolveRunVitestSpawnEnv,
@@ -30,6 +31,34 @@ import {
30313132const posixIt = process.platform === "win32" ? it.skip : it;
323334+function createRunVitestFs(params: { nodeModulesSymlink: boolean; bundledPlugin: boolean }) {
35+return {
36+existsSync: (filePath: string) => {
37+const normalized = filePath.replaceAll("\\", "/");
38+return (
39+normalized === "/repo/extensions" ||
40+(params.bundledPlugin &&
41+(normalized === "/repo/extensions/codex/package.json" ||
42+normalized === "/repo/extensions/codex/openclaw.plugin.json"))
43+);
44+},
45+lstatSync: (filePath: string) => {
46+if (filePath.replaceAll("\\", "/") !== "/repo/node_modules") {
47+throw new Error(`unexpected lstat path: ${filePath}`);
48+}
49+return {
50+isSymbolicLink: () => params.nodeModulesSymlink,
51+};
52+},
53+readdirSync: (filePath: string) => {
54+if (filePath.replaceAll("\\", "/") !== "/repo/extensions") {
55+throw new Error(`unexpected readdir path: ${filePath}`);
56+}
57+return params.bundledPlugin ? [{ name: "codex", isDirectory: () => true }] : [];
58+},
59+};
60+}
61+3362describe("scripts/run-vitest", () => {
3463it("adds --no-maglev to vitest child processes by default", () => {
3564expect(resolveVitestNodeArgs({ PATH: "/usr/bin" })).toEqual(["--no-maglev"]);
@@ -573,6 +602,45 @@ describe("scripts/run-vitest", () => {
573602});
574603});
575604605+it("points symlinked source worktree Vitest runs at local bundled plugins", () => {
606+expect(
607+resolveLinkedSourceBundledPluginsEnv(
608+{ PATH: "/usr/bin", PWD: "/repo" },
609+{
610+baseDir: "/repo",
611+fsImpl: createRunVitestFs({ nodeModulesSymlink: true, bundledPlugin: true }),
612+},
613+),
614+).toEqual({
615+OPENCLAW_BUNDLED_PLUGINS_DIR: nodePath.join("/repo", "extensions"),
616+OPENCLAW_TEST_TRUST_BUNDLED_PLUGINS_DIR: "1",
617+});
618+});
619+620+it("keeps explicit bundled plugin env ahead of symlinked worktree defaults", () => {
621+expect(
622+resolveLinkedSourceBundledPluginsEnv(
623+{ OPENCLAW_BUNDLED_PLUGINS_DIR: "/custom/extensions", PATH: "/usr/bin", PWD: "/repo" },
624+{
625+baseDir: "/repo",
626+fsImpl: createRunVitestFs({ nodeModulesSymlink: true, bundledPlugin: true }),
627+},
628+),
629+).toEqual({});
630+});
631+632+it("does not add bundled plugin env for normal dependency installs", () => {
633+expect(
634+resolveLinkedSourceBundledPluginsEnv(
635+{ PATH: "/usr/bin", PWD: "/repo" },
636+{
637+baseDir: "/repo",
638+fsImpl: createRunVitestFs({ nodeModulesSymlink: false, bundledPlugin: true }),
639+},
640+),
641+).toEqual({});
642+});
643+576644it("does not default explicit watch runs to the stall watchdog", () => {
577645expect(resolveRunVitestSpawnEnv({ PATH: "/usr/bin" }, ["--watch"])).toEqual({
578646PATH: "/usr/bin",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。