From 3c0e5f0ea55736a4b96a365f5d7533733ea9bebb Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 10 Apr 2026 15:31:48 +0100 Subject: [PATCH] test: restore moved Vitest config paths --- src/infra/vitest-config.test.ts | 5 ++-- .../bundled-plugin-public-surface.ts | 27 ++++++++++++++++--- test/vitest/vitest.boundary.config.ts | 4 +-- test/vitest/vitest.config.ts | 3 ++- test/vitest/vitest.contracts.config.ts | 4 +-- test/vitest/vitest.e2e.config.ts | 7 ++++- test/vitest/vitest.live.config.ts | 7 ++++- test/vitest/vitest.project-shard-config.ts | 4 +-- test/vitest/vitest.scoped-config.ts | 11 +++++--- test/vitest/vitest.shared.config.ts | 8 ++++-- test/vitest/vitest.unit.config.ts | 14 +++++++--- 11 files changed, 71 insertions(+), 23 deletions(-) diff --git a/src/infra/vitest-config.test.ts b/src/infra/vitest-config.test.ts index 7f5704e35b7..294433ab83c 100644 --- a/src/infra/vitest-config.test.ts +++ b/src/infra/vitest-config.test.ts @@ -203,12 +203,13 @@ describe("base vitest config", () => { }); it("keeps the base setup file minimal", () => { - expect(baseConfig.test?.setupFiles).toEqual(["test/setup.ts"]); + expect(baseConfig.test?.setupFiles).toHaveLength(1); + expect(baseConfig.test?.setupFiles?.[0]).toMatch(/(?:^|\/)test\/setup\.ts$/u); }); it("keeps the base runner non-isolated by default", () => { expect(baseConfig.test?.isolate).toBe(false); - expect(baseConfig.test?.runner).toBe("./test/non-isolated-runner.ts"); + expect(baseConfig.test?.runner).toMatch(/(?:^|\/)test\/non-isolated-runner\.ts$/u); }); }); diff --git a/src/test-utils/bundled-plugin-public-surface.ts b/src/test-utils/bundled-plugin-public-surface.ts index e7ce1ed68a2..848d11db541 100644 --- a/src/test-utils/bundled-plugin-public-surface.ts +++ b/src/test-utils/bundled-plugin-public-surface.ts @@ -1,3 +1,4 @@ +import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { loadBundledPluginPublicSurfaceModuleSync } from "../plugin-sdk/facade-loader.js"; @@ -74,16 +75,34 @@ export function resolveBundledPluginPublicModulePath(params: { ); } +function resolveVitestSourceModulePath(targetPath: string): string { + if (!targetPath.endsWith(".js")) { + return targetPath; + } + const sourcePath = `${targetPath.slice(0, -".js".length)}.ts`; + return pathExists(sourcePath) ? sourcePath : targetPath; +} + +function pathExists(filePath: string): boolean { + try { + return Boolean(filePath) && path.isAbsolute(filePath) && fs.statSync(filePath).isFile(); + } catch { + return false; + } +} + export function resolveRelativeBundledPluginPublicModuleId(params: { fromModuleUrl: string; pluginId: string; artifactBasename: string; }): string { const fromFilePath = fileURLToPath(params.fromModuleUrl); - const targetPath = resolveBundledPluginPublicModulePath({ - pluginId: params.pluginId, - artifactBasename: params.artifactBasename, - }); + const targetPath = resolveVitestSourceModulePath( + resolveBundledPluginPublicModulePath({ + pluginId: params.pluginId, + artifactBasename: params.artifactBasename, + }), + ); const relativePath = path .relative(path.dirname(fromFilePath), targetPath) .replaceAll(path.sep, "/"); diff --git a/test/vitest/vitest.boundary.config.ts b/test/vitest/vitest.boundary.config.ts index f6333428d32..6f5fc8f087c 100644 --- a/test/vitest/vitest.boundary.config.ts +++ b/test/vitest/vitest.boundary.config.ts @@ -1,7 +1,7 @@ import { defineProject } from "vitest/config"; import { loadPatternListFromEnv, narrowIncludePatternsForCli } from "./vitest.pattern-file.ts"; import { resolveVitestIsolation } from "./vitest.scoped-config.ts"; -import { sharedVitestConfig } from "./vitest.shared.config.ts"; +import { nonIsolatedRunnerPath, sharedVitestConfig } from "./vitest.shared.config.ts"; import { boundaryTestFiles } from "./vitest.unit-paths.mjs"; export function loadBoundaryIncludePatternsFromEnv( @@ -22,7 +22,7 @@ export function createBoundaryVitestConfig( ...sharedVitestConfig.test, name: "boundary", isolate, - ...(isolate ? { runner: undefined } : { runner: "./test/non-isolated-runner.ts" }), + ...(isolate ? { runner: undefined } : { runner: nonIsolatedRunnerPath }), include: loadBoundaryIncludePatternsFromEnv(env) ?? cliIncludePatterns ?? boundaryTestFiles, ...(cliIncludePatterns !== null ? { passWithNoTests: true } : {}), // Boundary workers still need the shared isolated HOME/bootstrap. Only diff --git a/test/vitest/vitest.config.ts b/test/vitest/vitest.config.ts index 5795b67cc03..f3ec799ded9 100644 --- a/test/vitest/vitest.config.ts +++ b/test/vitest/vitest.config.ts @@ -3,6 +3,7 @@ import { resolveDefaultVitestPool, resolveLocalVitestMaxWorkers, resolveLocalVitestScheduling, + nonIsolatedRunnerPath, sharedVitestConfig, } from "./vitest.shared.config.ts"; @@ -68,7 +69,7 @@ export default defineConfig({ ...sharedVitestConfig, test: { ...sharedVitestConfig.test, - runner: "./test/non-isolated-runner.ts", + runner: nonIsolatedRunnerPath, projects: [...rootVitestProjects], }, }); diff --git a/test/vitest/vitest.contracts.config.ts b/test/vitest/vitest.contracts.config.ts index a48cca398bc..a9d0f5bf80c 100644 --- a/test/vitest/vitest.contracts.config.ts +++ b/test/vitest/vitest.contracts.config.ts @@ -1,5 +1,5 @@ import { defineConfig } from "vitest/config"; -import { sharedVitestConfig } from "./vitest.shared.config.ts"; +import { nonIsolatedRunnerPath, sharedVitestConfig } from "./vitest.shared.config.ts"; const base = sharedVitestConfig as Record; const baseTest = sharedVitestConfig.test ?? {}; @@ -10,7 +10,7 @@ export function createContractsVitestConfig() { test: { ...baseTest, isolate: false, - runner: "./test/non-isolated-runner.ts", + runner: nonIsolatedRunnerPath, setupFiles: baseTest.setupFiles ?? [], include: [ "src/channels/plugins/contracts/**/*.test.ts", diff --git a/test/vitest/vitest.e2e.config.ts b/test/vitest/vitest.e2e.config.ts index 5d52d76d35a..aedba717a20 100644 --- a/test/vitest/vitest.e2e.config.ts +++ b/test/vitest/vitest.e2e.config.ts @@ -2,6 +2,7 @@ import os from "node:os"; import { defineConfig } from "vitest/config"; import { BUNDLED_PLUGIN_E2E_TEST_GLOB } from "./vitest.bundled-plugin-paths.ts"; import baseConfig from "./vitest.config.ts"; +import { resolveRepoRootPath } from "./vitest.shared.config.ts"; const base = baseConfig as unknown as Record; const isCI = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true"; @@ -31,7 +32,11 @@ export default defineConfig({ ...baseTest, maxWorkers: e2eWorkers, silent: !verboseE2E, - setupFiles: [...new Set([...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"])], + setupFiles: [ + ...new Set( + [...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"].map(resolveRepoRootPath), + ), + ], include: [ "test/**/*.e2e.test.ts", "src/**/*.e2e.test.ts", diff --git a/test/vitest/vitest.live.config.ts b/test/vitest/vitest.live.config.ts index ec6c807a129..cef7c95c4a2 100644 --- a/test/vitest/vitest.live.config.ts +++ b/test/vitest/vitest.live.config.ts @@ -1,6 +1,7 @@ import { defineConfig } from "vitest/config"; import { BUNDLED_PLUGIN_LIVE_TEST_GLOB } from "./vitest.bundled-plugin-paths.ts"; import baseConfig from "./vitest.config.ts"; +import { resolveRepoRootPath } from "./vitest.shared.config.ts"; const base = baseConfig as unknown as Record; const baseTestWithProjects = @@ -20,7 +21,11 @@ export default defineConfig({ // Vitest's buffered per-test console capture. disableConsoleIntercept: true, maxWorkers: 1, - setupFiles: [...new Set([...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"])], + setupFiles: [ + ...new Set( + [...(baseTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"].map(resolveRepoRootPath), + ), + ], include: ["src/**/*.live.test.ts", "test/**/*.live.test.ts", BUNDLED_PLUGIN_LIVE_TEST_GLOB], exclude, }, diff --git a/test/vitest/vitest.project-shard-config.ts b/test/vitest/vitest.project-shard-config.ts index 852be84d101..386a4ebbd11 100644 --- a/test/vitest/vitest.project-shard-config.ts +++ b/test/vitest/vitest.project-shard-config.ts @@ -1,5 +1,5 @@ import { defineConfig } from "vitest/config"; -import { sharedVitestConfig } from "./vitest.shared.config.ts"; +import { nonIsolatedRunnerPath, sharedVitestConfig } from "./vitest.shared.config.ts"; export function createProjectShardVitestConfig(projects: readonly string[]) { const maxWorkers = sharedVitestConfig.test.maxWorkers; @@ -10,7 +10,7 @@ export function createProjectShardVitestConfig(projects: readonly string[]) { ...sharedVitestConfig, test: { ...sharedVitestConfig.test, - runner: "./test/non-isolated-runner.ts", + runner: nonIsolatedRunnerPath, projects: [...projects], }, }); diff --git a/test/vitest/vitest.scoped-config.ts b/test/vitest/vitest.scoped-config.ts index 7fcf2e683e1..85c7c7afdbd 100644 --- a/test/vitest/vitest.scoped-config.ts +++ b/test/vitest/vitest.scoped-config.ts @@ -1,7 +1,12 @@ import path from "node:path"; import { defineConfig } from "vitest/config"; import { loadPatternListFromEnv, narrowIncludePatternsForCli } from "./vitest.pattern-file.ts"; -import { repoRoot, sharedVitestConfig } from "./vitest.shared.config.ts"; +import { + nonIsolatedRunnerPath, + repoRoot, + resolveRepoRootPath, + sharedVitestConfig, +} from "./vitest.shared.config.ts"; import { unitFastTestFiles } from "./vitest.unit-fast-paths.mjs"; function normalizePathPattern(value: string): string { @@ -160,9 +165,9 @@ export function createScopedVitestConfig( ...(options?.setupFiles ?? []), ...(options?.includeOpenClawRuntimeSetup === false ? [] : ["test/setup-openclaw-runtime.ts"]), ]), - ]; + ].map(resolveRepoRootPath); const useNonIsolatedRunner = options?.useNonIsolatedRunner ?? !isolate; - const runner = useNonIsolatedRunner ? "./test/non-isolated-runner.ts" : undefined; + const runner = useNonIsolatedRunner ? nonIsolatedRunnerPath : undefined; const scopedGroupOrder = resolveScopedProjectGroupOrder(options?.name, scopedDir, include); return defineConfig({ diff --git a/test/vitest/vitest.shared.config.ts b/test/vitest/vitest.shared.config.ts index 2de77e36bca..ecbcdda5a20 100644 --- a/test/vitest/vitest.shared.config.ts +++ b/test/vitest/vitest.shared.config.ts @@ -160,6 +160,10 @@ export function resolveDefaultVitestPool( } export const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); +export const nonIsolatedRunnerPath = path.join(repoRoot, "test", "non-isolated-runner.ts"); +export function resolveRepoRootPath(value: string): string { + return path.isAbsolute(value) ? value : path.join(repoRoot, value); +} const isCI = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true"; const isWindows = process.platform === "win32"; const defaultPool = resolveDefaultVitestPool(); @@ -208,7 +212,7 @@ export const sharedVitestConfig = { unstubGlobals: true, isolate: false, pool: defaultPool, - runner: "./test/non-isolated-runner.ts", + runner: nonIsolatedRunnerPath, maxWorkers: isCI ? ciWorkers : localScheduling.maxWorkers, fileParallelism: isCI ? true : localScheduling.fileParallelism, forceRerunTriggers: [ @@ -315,7 +319,7 @@ export const sharedVitestConfig = { "ui/src/ui/app-gateway.sessions.node.test.ts", "ui/src/ui/chat/slash-command-executor.node.test.ts", ], - setupFiles: ["test/setup.ts"], + setupFiles: [resolveRepoRootPath("test/setup.ts")], exclude: [ "dist/**", "test/fixtures/**", diff --git a/test/vitest/vitest.unit.config.ts b/test/vitest/vitest.unit.config.ts index 3d8dff36ce0..f6436d567e4 100644 --- a/test/vitest/vitest.unit.config.ts +++ b/test/vitest/vitest.unit.config.ts @@ -1,7 +1,11 @@ import { defineProject } from "vitest/config"; import { loadPatternListFromEnv, narrowIncludePatternsForCli } from "./vitest.pattern-file.ts"; import { resolveVitestIsolation } from "./vitest.scoped-config.ts"; -import { sharedVitestConfig } from "./vitest.shared.config.ts"; +import { + nonIsolatedRunnerPath, + resolveRepoRootPath, + sharedVitestConfig, +} from "./vitest.shared.config.ts"; import { unitFastTestFiles } from "./vitest.unit-fast-paths.mjs"; import { isBundledPluginDependentUnitTestFile, @@ -51,9 +55,13 @@ export function createUnitVitestConfigWithOptions( ...sharedTest, name: options.name ?? "unit", isolate, - ...(isolate ? { runner: undefined } : { runner: "./test/non-isolated-runner.ts" }), + ...(isolate ? { runner: undefined } : { runner: nonIsolatedRunnerPath }), setupFiles: [ - ...new Set([...(sharedTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"]), + ...new Set( + [...(sharedTest.setupFiles ?? []), "test/setup-openclaw-runtime.ts"].map( + resolveRepoRootPath, + ), + ), ], include: loadIncludePatternsFromEnv(env) ?? cliIncludePatterns ?? defaultIncludePatterns, exclude: [