mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
revert: remove bundled channel fallback masking
This commit is contained in:
@@ -84,50 +84,4 @@ describe("loadBundledEntryExportSync", () => {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("falls back from src setup and secret specifiers to packaged public artifacts", () => {
|
||||
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-channel-entry-contract-"));
|
||||
tempDirs.push(tempRoot);
|
||||
|
||||
const pluginRoot = path.join(tempRoot, "dist", "extensions", "telegram");
|
||||
fs.mkdirSync(pluginRoot, { recursive: true });
|
||||
|
||||
const importerPath = path.join(pluginRoot, "setup-entry.js");
|
||||
const channelPluginApiPath = path.join(pluginRoot, "channel-plugin-api.js");
|
||||
const secretContractApiPath = path.join(pluginRoot, "secret-contract-api.js");
|
||||
fs.writeFileSync(importerPath, "export default {};\n", "utf8");
|
||||
fs.writeFileSync(
|
||||
channelPluginApiPath,
|
||||
"export const telegramSetupPlugin = { id: 'telegram-setup' };\n",
|
||||
"utf8",
|
||||
);
|
||||
fs.writeFileSync(
|
||||
secretContractApiPath,
|
||||
[
|
||||
"export const secretTargetRegistryEntries = ['botToken'];",
|
||||
"export function collectRuntimeConfigAssignments() { return undefined; }",
|
||||
].join("\n"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
expect(
|
||||
loadBundledEntryExportSync<{ id: string }>(pathToFileURL(importerPath).href, {
|
||||
specifier: "./src/channel.setup.js",
|
||||
exportName: "telegramSetupPlugin",
|
||||
}),
|
||||
).toEqual({ id: "telegram-setup" });
|
||||
|
||||
expect(
|
||||
loadBundledEntryExportSync<{
|
||||
secretTargetRegistryEntries: string[];
|
||||
collectRuntimeConfigAssignments: () => undefined;
|
||||
}>(pathToFileURL(importerPath).href, {
|
||||
specifier: "./src/secret-contract.js",
|
||||
exportName: "channelSecrets",
|
||||
}),
|
||||
).toMatchObject({
|
||||
secretTargetRegistryEntries: ["botToken"],
|
||||
collectRuntimeConfigAssignments: expect.any(Function),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -106,30 +106,6 @@ function addBundledEntryCandidates(
|
||||
}
|
||||
}
|
||||
|
||||
function resolveBundledEntryFallbackSpecifiers(specifier: string): string[] {
|
||||
const sourceRelativeSpecifier = specifier.replace(/^\.\/src\//u, "./");
|
||||
const fallbackSpecifiers: string[] = [];
|
||||
if (sourceRelativeSpecifier !== specifier) {
|
||||
fallbackSpecifiers.push(sourceRelativeSpecifier);
|
||||
}
|
||||
|
||||
switch (sourceRelativeSpecifier) {
|
||||
case "./channel.js":
|
||||
fallbackSpecifiers.push("./channel-plugin-api.js", "./api.js");
|
||||
break;
|
||||
case "./channel.setup.js":
|
||||
fallbackSpecifiers.push("./setup-plugin-api.js", "./channel-plugin-api.js", "./api.js");
|
||||
break;
|
||||
case "./secret-contract.js":
|
||||
fallbackSpecifiers.push("./secret-contract-api.js", "./contract-api.js", "./api.js");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return [...new Set(fallbackSpecifiers)];
|
||||
}
|
||||
|
||||
function resolveBundledEntryModuleCandidates(
|
||||
importMetaUrl: string,
|
||||
specifier: string,
|
||||
@@ -141,10 +117,11 @@ function resolveBundledEntryModuleCandidates(
|
||||
const primaryResolved = path.resolve(importerDir, specifier);
|
||||
addBundledEntryCandidates(candidates, primaryResolved, boundaryRoot);
|
||||
|
||||
for (const fallbackSpecifier of resolveBundledEntryFallbackSpecifiers(specifier)) {
|
||||
const sourceRelativeSpecifier = specifier.replace(/^\.\/src\//u, "./");
|
||||
if (sourceRelativeSpecifier !== specifier) {
|
||||
addBundledEntryCandidates(
|
||||
candidates,
|
||||
path.resolve(importerDir, fallbackSpecifier),
|
||||
path.resolve(importerDir, sourceRelativeSpecifier),
|
||||
boundaryRoot,
|
||||
);
|
||||
}
|
||||
@@ -175,33 +152,16 @@ function resolveBundledEntryModuleCandidates(
|
||||
path.resolve(sourcePluginRoot, specifier),
|
||||
sourcePluginRoot,
|
||||
);
|
||||
for (const fallbackSpecifier of resolveBundledEntryFallbackSpecifiers(specifier)) {
|
||||
if (sourceRelativeSpecifier !== specifier) {
|
||||
addBundledEntryCandidates(
|
||||
candidates,
|
||||
path.resolve(sourcePluginRoot, fallbackSpecifier),
|
||||
path.resolve(sourcePluginRoot, sourceRelativeSpecifier),
|
||||
sourcePluginRoot,
|
||||
);
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
function resolveBundledEntryCompatExport<T>(
|
||||
loaded: unknown,
|
||||
reference: BundledEntryModuleRef,
|
||||
): T | undefined {
|
||||
if (reference.exportName !== "channelSecrets" || !loaded || typeof loaded !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const record = loaded as Record<string, unknown>;
|
||||
if ("collectRuntimeConfigAssignments" in record && "secretTargetRegistryEntries" in record) {
|
||||
return {
|
||||
collectRuntimeConfigAssignments: record.collectRuntimeConfigAssignments,
|
||||
secretTargetRegistryEntries: record.secretTargetRegistryEntries,
|
||||
} as T;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function formatBundledEntryUnknownError(error: unknown): string {
|
||||
if (typeof error === "string") {
|
||||
return error;
|
||||
@@ -348,10 +308,6 @@ export function loadBundledEntryExportSync<T>(
|
||||
}
|
||||
const record = (resolved ?? loaded) as Record<string, unknown> | undefined;
|
||||
if (!record || !(reference.exportName in record)) {
|
||||
const compatResolved = resolveBundledEntryCompatExport<T>(record ?? loaded, reference);
|
||||
if (compatResolved !== undefined) {
|
||||
return compatResolved;
|
||||
}
|
||||
throw new Error(
|
||||
`missing export "${reference.exportName}" from bundled entry module ${reference.specifier}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user