mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
98e3f729bc
* refactor(plugins): trim activation and contract exports * test(plugins): restore fixture cleanup * refactor(plugins): trim install and loader exports * test(plugins): fully reset loader caches * refactor(plugins): trim metadata and catalog exports * test(plugins): preserve catalog trust coverage * refactor(plugins): trim provider and plugin exports * refactor(plugins): trim runtime and tool exports * test(plugins): update dead-export consumers * test(plugins): remove empty dead-export suites * refactor(plugins): align exports with split registry * refactor(plugins): trim drifted loader exports * style(plugins): format test fixtures * refactor(scripts): use supported plugin APIs * refactor(plugins): finish dead export cleanup * chore(deadcode): refresh export baseline * test(cli): mock production memory state * chore(deadcode): sync latest export baseline * fix(tests): keep plugin fixtures inside core * chore(deadcode): refresh rebased export baseline * chore(deadcode): sync current ratchets * fix(plugins): retain reserved slot invariant * fix(plugins): preserve dead-export invariants * test(plugins): use neutral catalog query fixture * test(plugins): satisfy catalog lint * test(plugins): preserve integrity drift coverage * fix(ci): register skill experience live proof
171 lines
5.3 KiB
TypeScript
171 lines
5.3 KiB
TypeScript
/** Covers cloud-worker provider manifest ownership, uniqueness, and lookup ordering. */
|
|
import { describe, expect, it } from "vitest";
|
|
import { createPluginRecord } from "./loader-records.js";
|
|
import { createPluginRegistry } from "./registry.js";
|
|
import type { PluginRuntime } from "./runtime/types.js";
|
|
import type { WorkerProvider } from "./types.js";
|
|
import { resolveDurableWorkerProviderAutoEnabledReasons } from "./worker-provider-registry.js";
|
|
|
|
function createTestRegistry() {
|
|
return createPluginRegistry({
|
|
logger: {
|
|
info() {},
|
|
warn() {},
|
|
error() {},
|
|
debug() {},
|
|
},
|
|
runtime: {} as PluginRuntime,
|
|
activateGlobalSideEffects: false,
|
|
});
|
|
}
|
|
|
|
function createWorkerProvider(id: string): WorkerProvider {
|
|
return {
|
|
id,
|
|
provision: async () => {
|
|
throw new Error("not called");
|
|
},
|
|
inspect: async () => ({ status: "unknown" }),
|
|
destroy: async () => {},
|
|
};
|
|
}
|
|
|
|
function createOwner(id: string, workerProviders: string[] = []) {
|
|
return createPluginRecord({
|
|
id,
|
|
name: id,
|
|
source: `/tmp/${id}/index.js`,
|
|
origin: "global",
|
|
enabled: true,
|
|
contracts: { workerProviders },
|
|
configSchema: false,
|
|
});
|
|
}
|
|
|
|
describe("worker provider registry", () => {
|
|
it("rejects registrations missing manifest ownership", () => {
|
|
const pluginRegistry = createTestRegistry();
|
|
|
|
pluginRegistry.registerWorkerProvider(createOwner("owner"), createWorkerProvider("static-ssh"));
|
|
|
|
expect(pluginRegistry.registry.workerProviders.size).toBe(0);
|
|
expect(pluginRegistry.registry.diagnostics).toContainEqual(
|
|
expect.objectContaining({
|
|
level: "error",
|
|
pluginId: "owner",
|
|
message: "plugin must declare contracts.workerProviders for provider: static-ssh",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("rejects incomplete provider contracts", () => {
|
|
const pluginRegistry = createTestRegistry();
|
|
const provider = createWorkerProvider("static-ssh");
|
|
delete (provider as Partial<WorkerProvider>).inspect;
|
|
|
|
pluginRegistry.registerWorkerProvider(createOwner("owner", ["static-ssh"]), provider);
|
|
|
|
expect(pluginRegistry.registry.workerProviders.size).toBe(0);
|
|
expect(pluginRegistry.registry.diagnostics).toContainEqual(
|
|
expect.objectContaining({ message: "worker provider registration missing method: inspect" }),
|
|
);
|
|
});
|
|
|
|
it("rejects a non-function optional renew hook", () => {
|
|
const pluginRegistry = createTestRegistry();
|
|
const provider = {
|
|
...createWorkerProvider("static-ssh"),
|
|
renew: "later",
|
|
} as unknown as WorkerProvider;
|
|
|
|
pluginRegistry.registerWorkerProvider(createOwner("owner", ["static-ssh"]), provider);
|
|
|
|
expect(pluginRegistry.registry.workerProviders.size).toBe(0);
|
|
expect(pluginRegistry.registry.diagnostics).toContainEqual(
|
|
expect.objectContaining({
|
|
message: "worker provider registration renew must be a function",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("rejects a non-function optional SSH identity resolver", () => {
|
|
const pluginRegistry = createTestRegistry();
|
|
const provider = {
|
|
...createWorkerProvider("static-ssh"),
|
|
resolveSshIdentity: "later",
|
|
} as unknown as WorkerProvider;
|
|
|
|
pluginRegistry.registerWorkerProvider(createOwner("owner", ["static-ssh"]), provider);
|
|
|
|
expect(pluginRegistry.registry.workerProviders.size).toBe(0);
|
|
expect(pluginRegistry.registry.diagnostics).toContainEqual(
|
|
expect.objectContaining({
|
|
message: "worker provider registration resolveSshIdentity must be a function",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("rejects invalid provider ids", () => {
|
|
const pluginRegistry = createTestRegistry();
|
|
|
|
pluginRegistry.registerWorkerProvider(
|
|
createOwner("owner", ["__proto__"]),
|
|
createWorkerProvider("__proto__"),
|
|
);
|
|
|
|
expect(pluginRegistry.registry.workerProviders.size).toBe(0);
|
|
expect(pluginRegistry.registry.diagnostics).toContainEqual(
|
|
expect.objectContaining({
|
|
level: "error",
|
|
pluginId: "owner",
|
|
message: "worker provider registration missing valid id",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("rejects normalized duplicate provider ids", () => {
|
|
const pluginRegistry = createTestRegistry();
|
|
pluginRegistry.registerWorkerProvider(
|
|
createOwner("first", ["static-ssh"]),
|
|
createWorkerProvider("Static-SSH"),
|
|
);
|
|
|
|
pluginRegistry.registerWorkerProvider(
|
|
createOwner("second", ["static-ssh"]),
|
|
createWorkerProvider(" static-ssh "),
|
|
);
|
|
|
|
expect(pluginRegistry.registry.workerProviders.size).toBe(1);
|
|
expect(pluginRegistry.registry.diagnostics).toContainEqual(
|
|
expect.objectContaining({
|
|
level: "error",
|
|
pluginId: "second",
|
|
message: "worker provider already registered: static-ssh (first)",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("auto-enables only bundled owners needed by durable leases", () => {
|
|
const reasons = resolveDurableWorkerProviderAutoEnabledReasons(
|
|
{
|
|
plugins: [
|
|
{
|
|
id: "qa-lab",
|
|
origin: "bundled",
|
|
contracts: { workerProviders: ["other", "static-ssh"] },
|
|
},
|
|
{
|
|
id: "external-workers",
|
|
origin: "global",
|
|
contracts: { workerProviders: ["cloud-vendor"] },
|
|
},
|
|
],
|
|
diagnostics: [],
|
|
} as never,
|
|
[" STATIC-SSH ", "cloud-vendor"],
|
|
);
|
|
|
|
expect(reasons).toEqual({ "qa-lab": ["static-ssh durable worker lease"] });
|
|
});
|
|
});
|