mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 04:50:23 +00:00
perf(secrets): drop bundled channel manifest fallback
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { basename } from "node:path";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { loadPluginManifestRegistryMock } = vi.hoisted(() => ({
|
||||
@@ -47,4 +48,25 @@ describe("channel contract api explicit fast path", () => {
|
||||
expect(api?.collectUnsupportedSecretRefConfigCandidates).toBeTypeOf("function");
|
||||
expect(loadPluginManifestRegistryMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps bundled channel ids aligned with their plugin directories", async () => {
|
||||
const { loadPluginManifestRegistry } = await vi.importActual<
|
||||
typeof import("../plugins/manifest-registry.js")
|
||||
>("../plugins/manifest-registry.js");
|
||||
|
||||
const mismatches = loadPluginManifestRegistry({})
|
||||
.plugins.filter((record) => record.origin === "bundled")
|
||||
.filter((record) => typeof record.rootDir === "string" && record.rootDir.trim().length > 0)
|
||||
.flatMap((record) =>
|
||||
record.channels
|
||||
.filter((channelId) => channelId !== basename(record.rootDir))
|
||||
.map((channelId) => ({
|
||||
id: record.id,
|
||||
channelId,
|
||||
dirName: basename(record.rootDir),
|
||||
})),
|
||||
);
|
||||
|
||||
expect(mismatches).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import path from "node:path";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { loadPluginManifestRegistry } from "../plugins/manifest-registry.js";
|
||||
import { loadBundledPluginPublicArtifactModuleSync } from "../plugins/public-surface-loader.js";
|
||||
import type { ResolverContext, SecretDefaults } from "./runtime-shared.js";
|
||||
import type { SecretTargetRegistryEntry } from "./target-registry-types.js";
|
||||
@@ -24,73 +21,31 @@ type BundledChannelContractApi = {
|
||||
) => UnsupportedSecretRefConfigCandidate[];
|
||||
};
|
||||
|
||||
let bundledChannelDirNameByChannelId: Map<string, string> | null = null;
|
||||
|
||||
function getBundledChannelDirName(channelId: string): string | undefined {
|
||||
if (!bundledChannelDirNameByChannelId) {
|
||||
bundledChannelDirNameByChannelId = new Map(
|
||||
loadPluginManifestRegistry({})
|
||||
.plugins.filter((entry) => entry.origin === "bundled")
|
||||
.filter((entry) => typeof entry.rootDir === "string" && entry.rootDir.trim().length > 0)
|
||||
.flatMap((entry) =>
|
||||
entry.channels.map(
|
||||
(candidateChannelId) =>
|
||||
[
|
||||
candidateChannelId,
|
||||
entry.rootDir ? path.basename(entry.rootDir) : entry.id,
|
||||
] as const,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return bundledChannelDirNameByChannelId.get(channelId);
|
||||
}
|
||||
|
||||
function loadBundledChannelPublicArtifact(
|
||||
channelId: string,
|
||||
artifactBasenames: readonly string[],
|
||||
): BundledChannelContractApi | undefined {
|
||||
const triedDirNames = new Set<string>();
|
||||
const tryDirName = (dirName: string | undefined): BundledChannelContractApi | undefined => {
|
||||
if (typeof dirName !== "string" || dirName.trim().length === 0 || triedDirNames.has(dirName)) {
|
||||
return undefined;
|
||||
}
|
||||
triedDirNames.add(dirName);
|
||||
|
||||
for (const artifactBasename of artifactBasenames) {
|
||||
try {
|
||||
return loadBundledPluginPublicArtifactModuleSync<BundledChannelContractApi>({
|
||||
dirName,
|
||||
artifactBasename,
|
||||
});
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
error.message.startsWith("Unable to resolve bundled plugin public surface ")
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (process.env.OPENCLAW_DEBUG_CHANNEL_CONTRACT_API === "1") {
|
||||
const detail = formatErrorMessage(error);
|
||||
process.stderr.write(
|
||||
`[channel-contract-api] failed to load ${channelId} via ${dirName}/${artifactBasename}: ${detail}\n`,
|
||||
);
|
||||
}
|
||||
for (const artifactBasename of artifactBasenames) {
|
||||
try {
|
||||
return loadBundledPluginPublicArtifactModuleSync<BundledChannelContractApi>({
|
||||
dirName: channelId,
|
||||
artifactBasename,
|
||||
});
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
error.message.startsWith("Unable to resolve bundled plugin public surface ")
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (process.env.OPENCLAW_DEBUG_CHANNEL_CONTRACT_API === "1") {
|
||||
const detail = error instanceof Error ? error.message : String(error);
|
||||
process.stderr.write(
|
||||
`[channel-contract-api] failed to load ${channelId}/${artifactBasename}: ${detail}\n`,
|
||||
);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const direct = tryDirName(channelId);
|
||||
if (direct) {
|
||||
return direct;
|
||||
}
|
||||
|
||||
const fallback = tryDirName(getBundledChannelDirName(channelId));
|
||||
if (fallback) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user