File size: 4,959 Bytes
4c76b0d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | // Plugin shape contract tests cover manifest, API, and runtime export shapes.
import {
createPluginRegistryFixture,
registerVirtualTestPlugin,
} from "openclaw/plugin-sdk/plugin-test-contracts";
import { describe, expect, it } from "vitest";
import { buildPluginShapeSummary } from "../inspect-shape.js";
describe("plugin shape compatibility matrix", () => {
it("keeps hook-only, plain capability, and hybrid capability shapes explicit", () => {
const { config, registry } = createPluginRegistryFixture({
plugins: {
entries: {
"hook-only": {
hooks: {
allowConversationAccess: true,
},
},
},
},
});
registerVirtualTestPlugin({
registry,
config,
id: "hook-only",
name: "Hook Only",
register(api) {
api.on("before_prompt_build", () => ({ prependContext: "hook-only" }));
},
});
registerVirtualTestPlugin({
registry,
config,
id: "plain-provider",
name: "Plain Provider",
register(api) {
api.registerProvider({
id: "plain-provider",
label: "Plain Provider",
auth: [],
});
},
});
registerVirtualTestPlugin({
registry,
config,
id: "hybrid-company",
name: "Hybrid Company",
register(api) {
api.registerProvider({
id: "hybrid-company",
label: "Hybrid Company",
auth: [],
});
api.registerWebSearchProvider({
id: "hybrid-search",
label: "Hybrid Search",
hint: "Search the web",
envVars: ["HYBRID_SEARCH_KEY"],
placeholder: "hsk_...",
signupUrl: "https://example.com/signup",
credentialPath: "tools.web.search.hybrid-search.apiKey",
getCredentialValue: () => "hsk-test",
setCredentialValue(searchConfigTarget, value) {
searchConfigTarget.apiKey = value;
},
createTool: () => ({
description: "Hybrid search",
parameters: {},
execute: async () => ({}),
}),
});
},
});
registerVirtualTestPlugin({
registry,
config,
id: "channel-demo",
name: "Channel Demo",
register(api) {
api.registerChannel({
plugin: {
id: "channel-demo",
meta: {
id: "channel-demo",
label: "Channel Demo",
selectionLabel: "Channel Demo",
docsPath: "/channels/channel-demo",
blurb: "channel demo",
},
capabilities: { chatTypes: ["direct"] },
config: {
listAccountIds: () => [],
resolveAccount: () => ({ accountId: "default" }),
},
outbound: { deliveryMode: "direct" },
},
});
},
});
registerVirtualTestPlugin({
registry,
config,
id: "session-catalog-demo",
name: "Session Catalog Demo",
register(api) {
api.registerSessionCatalog({
id: "session-catalog-demo",
label: "Session Catalog Demo",
list: async () => [],
read: async ({ hostId, threadId }) => ({ hostId, threadId, items: [] }),
});
},
});
registerVirtualTestPlugin({
registry,
config,
id: "document-extract-test",
name: "Document Extract Test",
contracts: { documentExtractors: ["pdf"] },
register() {},
});
const report = {
workspaceDir: "/virtual-workspace",
...registry.registry,
};
const inspect = report.plugins.map((plugin) =>
Object.assign({ plugin }, buildPluginShapeSummary({ plugin, report })),
);
expect(
inspect.map((entry) => ({
id: entry.plugin.id,
shape: entry.shape,
capabilityMode: entry.capabilityMode,
})),
).toEqual([
{
id: "hook-only",
shape: "hook-only",
capabilityMode: "none",
},
{
id: "plain-provider",
shape: "plain-capability",
capabilityMode: "plain",
},
{
id: "hybrid-company",
shape: "hybrid-capability",
capabilityMode: "hybrid",
},
{
id: "channel-demo",
shape: "plain-capability",
capabilityMode: "plain",
},
{
id: "session-catalog-demo",
shape: "plain-capability",
capabilityMode: "plain",
},
{
id: "document-extract-test",
shape: "plain-capability",
capabilityMode: "plain",
},
]);
expect(inspect.map((entry) => entry.capabilities.map((capability) => capability.kind))).toEqual(
[
[],
["text-inference"],
["text-inference", "web-search"],
["channel"],
["session-catalog"],
["document-extractors"],
],
);
});
});
|