From e5747629c337c3c933401332c22dd6e9e914375f Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 18 Apr 2026 06:45:09 -0700 Subject: [PATCH] fix(test): stabilize workspace package test imports --- .../bundled-plugin-public-surface.ts | 21 +++++++++++++++++-- test/helpers/plugins/tts-contract-suites.ts | 5 ++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/test-utils/bundled-plugin-public-surface.ts b/src/test-utils/bundled-plugin-public-surface.ts index 1e27415fe40..471a6dcf194 100644 --- a/src/test-utils/bundled-plugin-public-surface.ts +++ b/src/test-utils/bundled-plugin-public-surface.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; import path from "node:path"; -import { fileURLToPath } from "node:url"; +import { fileURLToPath, pathToFileURL } from "node:url"; import { loadBundledPluginPublicSurfaceModuleSync } from "../plugin-sdk/facade-loader.js"; import { resolveBundledPluginsDir } from "../plugins/bundled-dir.js"; import { @@ -218,5 +218,22 @@ export function resolveRelativeWorkspacePackagePublicModuleId(params: { const relativePath = path .relative(path.dirname(fromFilePath), targetPath) .replaceAll(path.sep, "/"); - return relativePath.startsWith(".") ? relativePath : `./${relativePath}`; + const normalizedRelativePath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`; + if (path.resolve(path.dirname(fromFilePath), normalizedRelativePath) !== targetPath) { + return pathToFileURL(targetPath).href; + } + return normalizedRelativePath; +} + +export function resolveWorkspacePackagePublicModuleUrl(params: { + packageName: string; + artifactBasename: string; +}): string { + const targetPath = resolveVitestSourceModulePath( + path.resolve( + resolveWorkspacePackageDir(params.packageName), + normalizeBundledPluginArtifactSubpath(params.artifactBasename), + ), + ); + return pathToFileURL(targetPath).href; } diff --git a/test/helpers/plugins/tts-contract-suites.ts b/test/helpers/plugins/tts-contract-suites.ts index fec4d1d1dd6..d409bdcbb9b 100644 --- a/test/helpers/plugins/tts-contract-suites.ts +++ b/test/helpers/plugins/tts-contract-suites.ts @@ -4,15 +4,14 @@ import type { OpenClawConfig } from "../../../src/config/config.js"; import { createEmptyPluginRegistry } from "../../../src/plugins/registry-empty.js"; import { setActivePluginRegistry } from "../../../src/plugins/runtime.js"; import type { SpeechProviderPlugin } from "../../../src/plugins/types.js"; -import { resolveRelativeWorkspacePackagePublicModuleId } from "../../../src/test-utils/bundled-plugin-public-surface.js"; +import { resolveWorkspacePackagePublicModuleUrl } from "../../../src/test-utils/bundled-plugin-public-surface.js"; import { withEnv } from "../../../src/test-utils/env.js"; import type { ResolvedTtsConfig } from "../../../src/tts/tts-types.js"; type TtsRuntimeModule = typeof import("../../../src/tts/tts.js"); type TtsCoreModule = typeof import("../../../src/tts/tts-core.js"); -const speechCoreRuntimeApiModuleId = resolveRelativeWorkspacePackagePublicModuleId({ - fromModuleUrl: import.meta.url, +const speechCoreRuntimeApiModuleId = resolveWorkspacePackagePublicModuleUrl({ packageName: "@openclaw/speech-core", artifactBasename: "runtime-api.js", });