mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 11:03:31 +00:00
Plugins: clarify registerHttpHandler migration errors (#36794)
* Changelog: note plugin HTTP route migration diagnostics * Tests: cover registerHttpHandler migration diagnostics * Plugins: clarify registerHttpHandler migration errors * Tests: cover registerHttpHandler diagnostic edge cases * Plugins: tighten registerHttpHandler migration hint
This commit is contained in:
@@ -191,6 +191,15 @@ function createWarningLogger(warnings: string[]) {
|
||||
};
|
||||
}
|
||||
|
||||
function createErrorLogger(errors: string[]) {
|
||||
return {
|
||||
info: () => {},
|
||||
warn: () => {},
|
||||
error: (msg: string) => errors.push(msg),
|
||||
debug: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
function createEscapingEntryFixture(params: { id: string; sourceBody: string }) {
|
||||
const pluginDir = makeTempDir();
|
||||
const outsideDir = makeTempDir();
|
||||
@@ -574,6 +583,65 @@ describe("loadOpenClawPlugins", () => {
|
||||
expect(httpPlugin?.httpRoutes).toBe(1);
|
||||
});
|
||||
|
||||
it("rewrites removed registerHttpHandler failures into migration diagnostics", () => {
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
id: "http-handler-legacy",
|
||||
filename: "http-handler-legacy.cjs",
|
||||
body: `module.exports = { id: "http-handler-legacy", register(api) {
|
||||
api.registerHttpHandler({ path: "/legacy", handler: async () => true });
|
||||
} };`,
|
||||
});
|
||||
|
||||
const errors: string[] = [];
|
||||
const registry = loadRegistryFromSinglePlugin({
|
||||
plugin,
|
||||
pluginConfig: {
|
||||
allow: ["http-handler-legacy"],
|
||||
},
|
||||
options: {
|
||||
logger: createErrorLogger(errors),
|
||||
},
|
||||
});
|
||||
|
||||
const loaded = registry.plugins.find((entry) => entry.id === "http-handler-legacy");
|
||||
expect(loaded?.status).toBe("error");
|
||||
expect(loaded?.error).toContain("api.registerHttpHandler(...) was removed");
|
||||
expect(loaded?.error).toContain("api.registerHttpRoute(...)");
|
||||
expect(loaded?.error).toContain("registerPluginHttpRoute(...)");
|
||||
expect(
|
||||
registry.diagnostics.some((diag) =>
|
||||
String(diag.message).includes("api.registerHttpHandler(...) was removed"),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(errors.some((entry) => entry.includes("api.registerHttpHandler(...) was removed"))).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("does not rewrite unrelated registerHttpHandler helper failures", () => {
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
id: "http-handler-local-helper",
|
||||
filename: "http-handler-local-helper.cjs",
|
||||
body: `module.exports = { id: "http-handler-local-helper", register() {
|
||||
const registerHttpHandler = undefined;
|
||||
registerHttpHandler();
|
||||
} };`,
|
||||
});
|
||||
|
||||
const registry = loadRegistryFromSinglePlugin({
|
||||
plugin,
|
||||
pluginConfig: {
|
||||
allow: ["http-handler-local-helper"],
|
||||
},
|
||||
});
|
||||
|
||||
const loaded = registry.plugins.find((entry) => entry.id === "http-handler-local-helper");
|
||||
expect(loaded?.status).toBe("error");
|
||||
expect(loaded?.error).not.toContain("api.registerHttpHandler(...) was removed");
|
||||
});
|
||||
|
||||
it("rejects plugin http routes missing explicit auth", () => {
|
||||
useNoBundledPlugins();
|
||||
const plugin = writePlugin({
|
||||
|
||||
Reference in New Issue
Block a user