




















@@ -25,6 +25,7 @@ import { withEnv } from "../test-utils/env.js";
2525import { resolveBundledRuntimeDependencyInstallRootPlan } from "./bundled-runtime-deps.js";
2626import { clearPluginCommands } from "./command-registry-state.js";
2727import { getPluginCommandSpecs } from "./command-specs.js";
28+import { listCompactionProviderIds } from "./compaction-provider.js";
2829import {
2930getGlobalHookRunner,
3031getGlobalPluginRegistry,
@@ -72,6 +73,7 @@ import {
7273getMemoryRuntime,
7374listActiveMemoryPublicArtifacts,
7475listMemoryCorpusSupplements,
76+listMemoryPromptSupplements,
7577registerMemoryCorpusSupplement,
7678registerMemoryFlushPlanResolver,
7779registerMemoryPromptSupplement,
@@ -3386,6 +3388,44 @@ module.exports = { id: "throws-after-import", register() {} };`,
33863388expect(listAgentHarnessIds()).toEqual([]);
33873389});
338833903391+it("rejects malformed plugin agent harness registrations", () => {
3392+useNoBundledPlugins();
3393+const plugin = writePlugin({
3394+id: "bad-harness",
3395+filename: "bad-harness.cjs",
3396+body: `module.exports = {
3397+ id: "bad-harness",
3398+ register(api) {
3399+ api.registerAgentHarness({
3400+ id: "broken",
3401+ label: "Broken",
3402+ });
3403+ },
3404+ };`,
3405+});
3406+3407+const registry = loadOpenClawPlugins({
3408+cache: false,
3409+workspaceDir: plugin.dir,
3410+config: {
3411+plugins: {
3412+load: { paths: [plugin.file] },
3413+allow: ["bad-harness"],
3414+},
3415+},
3416+onlyPluginIds: ["bad-harness"],
3417+});
3418+3419+expect(listAgentHarnessIds()).toEqual([]);
3420+expect(registry.diagnostics).toContainEqual(
3421+expect.objectContaining({
3422+level: "error",
3423+pluginId: "bad-harness",
3424+message: 'agent harness "broken" registration missing required runtime methods',
3425+}),
3426+);
3427+});
3428+33893429it("does not register internal hooks globally during non-activating loads", () => {
33903430useNoBundledPlugins();
33913431const plugin = writePlugin({
@@ -5120,6 +5160,21 @@ module.exports = { id: "throws-after-import", register() {} };`,
51205160).toBe("Demo Duplicate");
51215161},
51225162},
5163+{
5164+label: "rejects malformed plugin context engine registration",
5165+pluginId: "context-engine-malformed",
5166+body: `module.exports = { id: "context-engine-malformed", register(api) {
5167+ api.registerContextEngine({ id: "broken-context" });
5168+} };`,
5169+assert: (registry: ReturnType<typeof loadOpenClawPlugins>) => {
5170+expectRegistryErrorDiagnostic({
5171+ registry,
5172+pluginId: "context-engine-malformed",
5173+message: "context engine registration missing id",
5174+});
5175+expect(listContextEngineIds()).not.toContain("broken-context");
5176+},
5177+},
51235178{
51245179label: "rejects plugin context engine ids reserved by core",
51255180pluginId: "context-engine-core-collision",
@@ -5134,6 +5189,36 @@ module.exports = { id: "throws-after-import", register() {} };`,
51345189});
51355190},
51365191},
5192+{
5193+label: "rejects malformed compaction provider registration",
5194+pluginId: "compaction-provider-malformed",
5195+body: `module.exports = { id: "compaction-provider-malformed", register(api) {
5196+ api.registerCompactionProvider({ id: "broken-compaction", label: "Broken" });
5197+} };`,
5198+assert: (registry: ReturnType<typeof loadOpenClawPlugins>) => {
5199+expectRegistryErrorDiagnostic({
5200+ registry,
5201+pluginId: "compaction-provider-malformed",
5202+message: 'compaction provider "broken-compaction" registration missing summarize',
5203+});
5204+expect(listCompactionProviderIds()).not.toContain("broken-compaction");
5205+},
5206+},
5207+{
5208+label: "rejects malformed memory prompt supplement registration",
5209+pluginId: "memory-prompt-supplement-malformed",
5210+body: `module.exports = { id: "memory-prompt-supplement-malformed", register(api) {
5211+ api.registerMemoryPromptSupplement({ id: "broken-memory-prompt" });
5212+} };`,
5213+assert: (registry: ReturnType<typeof loadOpenClawPlugins>) => {
5214+expectRegistryErrorDiagnostic({
5215+ registry,
5216+pluginId: "memory-prompt-supplement-malformed",
5217+message: "memory prompt supplement registration missing builder",
5218+});
5219+expect(listMemoryPromptSupplements()).toEqual([]);
5220+},
5221+},
51375222{
51385223label: "requires plugin CLI registrars to declare explicit command roots",
51395224pluginId: "cli-missing-metadata",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。