From 7e5e5bd6007079338f08baa7efa32c18f0c5abb0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 23 Mar 2026 01:04:57 +0000 Subject: [PATCH] refactor: remove dead ClassifyNotification method, fix reflection tests The private static ClassifyNotification method in OpenClawGatewayClient was never called from production code - only from tests via reflection. It simply forwarded to NotificationCategorizer.ClassifyByKeywords. - Remove the dead ClassifyNotification method from OpenClawGatewayClient - Update GatewayClientTestHelper to call NotificationCategorizer.ClassifyByKeywords directly instead of using brittle reflection to invoke a private method The reflection-based approach was fragile: any refactor of the private method would silently break the tests (as demonstrated when the method was removed). Calling the public API directly is clearer and more robust. 503 tests pass, 18 skipped. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/OpenClaw.Shared/OpenClawGatewayClient.cs | 5 ----- .../OpenClawGatewayClientTests.cs | 14 ++++---------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/OpenClaw.Shared/OpenClawGatewayClient.cs b/src/OpenClaw.Shared/OpenClawGatewayClient.cs index 0e21836..72ae996 100644 --- a/src/OpenClaw.Shared/OpenClawGatewayClient.cs +++ b/src/OpenClaw.Shared/OpenClawGatewayClient.cs @@ -1562,11 +1562,6 @@ private void EmitNotification(string text) NotificationReceived?.Invoke(this, notification); } - private static (string title, string type) ClassifyNotification(string text) - { - return NotificationCategorizer.ClassifyByKeywords(text); - } - // --- Utility --- private static ActivityKind ClassifyTool(string toolName) diff --git a/tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs b/tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs index 424182d..7bda800 100644 --- a/tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs +++ b/tests/OpenClaw.Shared.Tests/OpenClawGatewayClientTests.cs @@ -21,20 +21,14 @@ public GatewayClientTestHelper() public string ClassifyNotification(string text) { - var method = typeof(OpenClawGatewayClient).GetMethod("ClassifyNotification", - System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); - var result = method!.Invoke(null, new object[] { text }); - var tuple = ((string title, string type))result!; - return tuple.type; + var (_, type) = NotificationCategorizer.ClassifyByKeywords(text); + return type; } public string GetNotificationTitle(string text) { - var method = typeof(OpenClawGatewayClient).GetMethod("ClassifyNotification", - System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); - var result = method!.Invoke(null, new object[] { text }); - var tuple = ((string title, string type))result!; - return tuple.title; + var (title, _) = NotificationCategorizer.ClassifyByKeywords(text); + return title; } public ActivityKind ClassifyTool(string toolName)