fix(test): stabilize workspace package test imports

This commit is contained in:
Vincent Koc
2026-04-18 06:45:09 -07:00
parent 552c0f22a6
commit e5747629c3
2 changed files with 21 additions and 5 deletions

View File

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

View File

@@ -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",
});