mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
perf(test): trim bundled registry and facade tests
This commit is contained in:
@@ -274,10 +274,7 @@ describe("plugin-sdk facade runtime", () => {
|
||||
});
|
||||
|
||||
it("resolves a globally-installed plugin whose rootDir basename matches the dirName", () => {
|
||||
const emptyBundled = createTempDirSync("openclaw-facade-empty-bundled-");
|
||||
|
||||
const stateDir = createTempDirSync("openclaw-facade-state-");
|
||||
const lineDir = path.join(stateDir, "extensions", "line");
|
||||
const lineDir = createTempDirSync("openclaw-facade-global-line-");
|
||||
fs.mkdirSync(lineDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(lineDir, "runtime-api.js"),
|
||||
@@ -306,34 +303,26 @@ describe("plugin-sdk facade runtime", () => {
|
||||
"utf8",
|
||||
);
|
||||
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = emptyBundled;
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
|
||||
clearPluginDiscoveryCache();
|
||||
clearPluginManifestRegistryCache();
|
||||
resetFacadeRuntimeStateForTest();
|
||||
|
||||
setRuntimeConfigSnapshot({
|
||||
channels: {
|
||||
line: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
canLoadActivatedBundledPluginPublicSurface({
|
||||
__testing.resolveRegistryPluginModuleLocationFromRegistry({
|
||||
registry: [
|
||||
{
|
||||
id: "line",
|
||||
rootDir: lineDir,
|
||||
channels: ["line"],
|
||||
},
|
||||
],
|
||||
dirName: "line",
|
||||
artifactBasename: "runtime-api.js",
|
||||
}),
|
||||
).toBe(true);
|
||||
).toEqual({
|
||||
modulePath: path.join(lineDir, "runtime-api.js"),
|
||||
boundaryRoot: lineDir,
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves a globally-installed plugin with an encoded scoped rootDir basename", () => {
|
||||
const emptyBundled = createTempDirSync("openclaw-facade-empty-bundled-");
|
||||
|
||||
const stateDir = createTempDirSync("openclaw-facade-state-");
|
||||
const encodedDir = path.join(stateDir, "extensions", "@openclaw+line");
|
||||
const encodedDir = createTempDirSync("openclaw-facade-encoded-line-");
|
||||
fs.mkdirSync(encodedDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(encodedDir, "runtime-api.js"),
|
||||
@@ -362,27 +351,22 @@ describe("plugin-sdk facade runtime", () => {
|
||||
"utf8",
|
||||
);
|
||||
|
||||
process.env.OPENCLAW_BUNDLED_PLUGINS_DIR = emptyBundled;
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
|
||||
clearPluginDiscoveryCache();
|
||||
clearPluginManifestRegistryCache();
|
||||
resetFacadeRuntimeStateForTest();
|
||||
|
||||
setRuntimeConfigSnapshot({
|
||||
channels: {
|
||||
line: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
canLoadActivatedBundledPluginPublicSurface({
|
||||
__testing.resolveRegistryPluginModuleLocationFromRegistry({
|
||||
registry: [
|
||||
{
|
||||
id: "line",
|
||||
rootDir: encodedDir,
|
||||
channels: ["line"],
|
||||
},
|
||||
],
|
||||
dirName: "line",
|
||||
artifactBasename: "runtime-api.js",
|
||||
}),
|
||||
).toBe(true);
|
||||
).toEqual({
|
||||
modulePath: path.join(encodedDir, "runtime-api.js"),
|
||||
boundaryRoot: encodedDir,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps shared runtime-core facades available without plugin activation", () => {
|
||||
|
||||
@@ -115,12 +115,13 @@ function resolveSourceFirstPublicSurfacePath(params: {
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveRegistryPluginModuleLocation(params: {
|
||||
function resolveRegistryPluginModuleLocationFromRegistry(params: {
|
||||
registry: readonly Pick<PluginManifestRecord, "id" | "rootDir" | "channels">[];
|
||||
dirName: string;
|
||||
artifactBasename: string;
|
||||
}): { modulePath: string; boundaryRoot: string } | null {
|
||||
const registry = getFacadeManifestRegistry();
|
||||
const tiers: Array<(plugin: (typeof registry)[number]) => boolean> = [
|
||||
type RegistryRecord = (typeof params.registry)[number];
|
||||
const tiers: Array<(plugin: RegistryRecord) => boolean> = [
|
||||
(plugin) => plugin.id === params.dirName,
|
||||
(plugin) => path.basename(plugin.rootDir) === params.dirName,
|
||||
(plugin) => plugin.channels.includes(params.dirName),
|
||||
@@ -128,7 +129,7 @@ function resolveRegistryPluginModuleLocation(params: {
|
||||
const artifactBasename = params.artifactBasename.replace(/^\.\//u, "");
|
||||
const sourceBaseName = artifactBasename.replace(/\.js$/u, "");
|
||||
for (const matchFn of tiers) {
|
||||
for (const record of registry.filter(matchFn)) {
|
||||
for (const record of params.registry.filter(matchFn)) {
|
||||
const rootDir = path.resolve(record.rootDir);
|
||||
const builtCandidate = path.join(rootDir, artifactBasename);
|
||||
if (fs.existsSync(builtCandidate)) {
|
||||
@@ -145,6 +146,16 @@ function resolveRegistryPluginModuleLocation(params: {
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveRegistryPluginModuleLocation(params: {
|
||||
dirName: string;
|
||||
artifactBasename: string;
|
||||
}): { modulePath: string; boundaryRoot: string } | null {
|
||||
return resolveRegistryPluginModuleLocationFromRegistry({
|
||||
registry: getFacadeManifestRegistry(),
|
||||
...params,
|
||||
});
|
||||
}
|
||||
|
||||
function resolveFacadeModuleLocationUncached(params: {
|
||||
dirName: string;
|
||||
artifactBasename: string;
|
||||
@@ -729,6 +740,7 @@ export function resetFacadeRuntimeStateForTest(): void {
|
||||
export const __testing = {
|
||||
evaluateBundledPluginPublicSurfaceAccess,
|
||||
loadFacadeModuleAtLocationSync,
|
||||
resolveRegistryPluginModuleLocationFromRegistry,
|
||||
throwForBundledPluginPublicSurfaceAccess,
|
||||
resolveActivatedBundledPluginPublicSurfaceAccessOrThrow,
|
||||
resolveFacadeModuleLocation,
|
||||
|
||||
Reference in New Issue
Block a user