fix(test): restore bundled loader coverage

This commit is contained in:
Peter Steinberger
2026-04-06 18:14:37 +01:00
parent 96b39e01b4
commit 348cd6b17a
15 changed files with 207 additions and 58 deletions

View File

@@ -1,4 +1,5 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import { resolveOpenClawPackageRootSync } from "../../infra/openclaw-root.js";
import { createSubsystemLogger } from "../../logging/subsystem.js";
import type {
@@ -23,10 +24,13 @@ type GeneratedBundledChannelEntry = {
const log = createSubsystemLogger("channels");
const OPENCLAW_PACKAGE_ROOT =
resolveOpenClawPackageRootSync({
cwd: process.cwd(),
moduleUrl: import.meta.url,
argv1: process.argv[1],
}) ?? process.cwd();
cwd: process.cwd(),
moduleUrl: import.meta.url.startsWith("file:") ? import.meta.url : undefined,
}) ??
(import.meta.url.startsWith("file:")
? path.resolve(fileURLToPath(new URL("../../..", import.meta.url)))
: process.cwd());
function resolveChannelPluginModuleEntry(
moduleExport: unknown,
@@ -94,15 +98,35 @@ function resolveBundledChannelBoundaryRoot(params: {
return path.resolve(OPENCLAW_PACKAGE_ROOT, "extensions", params.metadata.dirName);
}
function resolveGeneratedBundledChannelModulePath(params: {
metadata: BundledChannelPluginMetadata;
entry: BundledChannelPluginMetadata["source"] | BundledChannelPluginMetadata["setupSource"];
}): string | null {
if (!params.entry) {
return null;
}
const candidateRoots = [
path.resolve(OPENCLAW_PACKAGE_ROOT, "dist", "extensions", params.metadata.dirName),
path.resolve(OPENCLAW_PACKAGE_ROOT, "extensions", params.metadata.dirName),
];
for (const rootDir of candidateRoots) {
const resolved = resolveBundledChannelGeneratedPath(
rootDir,
params.entry,
params.metadata.dirName,
);
if (resolved) {
return resolved;
}
}
return null;
}
function loadGeneratedBundledChannelModule(params: {
metadata: BundledChannelPluginMetadata;
entry: BundledChannelPluginMetadata["source"] | BundledChannelPluginMetadata["setupSource"];
}): unknown {
const modulePath = resolveBundledChannelGeneratedPath(
OPENCLAW_PACKAGE_ROOT,
params.entry,
params.metadata.dirName,
);
const modulePath = resolveGeneratedBundledChannelModulePath(params);
if (!modulePath) {
throw new Error(`missing generated module for bundled channel ${params.metadata.manifest.id}`);
}