

























@@ -3310,6 +3310,66 @@ module.exports = { id: "throws-after-import", register() {} };`,
33103310clearInternalHooks();
33113311});
331233123313+it("injects plugin config into internal hook event context", async () => {
3314+useNoBundledPlugins();
3315+const plugin = writePlugin({
3316+id: "hook-config-context",
3317+filename: "hook-config-context.cjs",
3318+body: `module.exports = {
3319+ id: "hook-config-context",
3320+ register(api) {
3321+ api.registerHook(
3322+ "gateway:startup",
3323+ (event) => {
3324+ event.messages.push(event.context.pluginConfig?.marker);
3325+ },
3326+ { name: "hook-config-context" },
3327+ );
3328+ },
3329+ };`,
3330+});
3331+fs.writeFileSync(
3332+path.join(plugin.dir, "openclaw.plugin.json"),
3333+JSON.stringify(
3334+{
3335+id: "hook-config-context",
3336+configSchema: { type: "object" },
3337+},
3338+null,
3339+2,
3340+),
3341+"utf-8",
3342+);
3343+3344+clearInternalHooks();
3345+3346+loadOpenClawPlugins({
3347+cache: false,
3348+workspaceDir: plugin.dir,
3349+config: {
3350+plugins: {
3351+load: { paths: [plugin.file] },
3352+allow: ["hook-config-context"],
3353+entries: {
3354+"hook-config-context": {
3355+config: {
3356+marker: "plugin-config-visible",
3357+},
3358+},
3359+},
3360+},
3361+},
3362+onlyPluginIds: ["hook-config-context"],
3363+});
3364+3365+const event = createInternalHookEvent("gateway", "startup", "gateway:startup");
3366+await triggerInternalHook(event);
3367+expect(event.messages).toEqual(["plugin-config-visible"]);
3368+expect(event.context).toEqual({});
3369+3370+clearInternalHooks();
3371+});
3372+33133373it("rolls back global side effects when registration fails", async () => {
33143374useNoBundledPlugins();
33153375const plugin = writePlugin({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。