[Repo Assist] improve: add GetStringArrayArg helper and expand test coverage#161
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Draft
Conversation
- Add GetStringArrayArg protected helper to NodeCapabilityBase that extracts a string array from JsonElement args, filtering out null and whitespace-only strings; returns Array.Empty when absent or wrong type. - Simplify SystemCapability.HandleWhich to use GetStringArrayArg instead of 22 lines of manual JSON array parsing with fully-qualified System.Text.Json.JsonValueKind references. - Add 6 GetStringArrayArg tests to NodeCapabilitiesTests covering: present array, missing property, non-array type, whitespace filtering, default JsonElement, and mixed element types. - Add 8 new WindowsNodeClient tests covering: SetPermission (set/ overwrite), DisconnectAsync raises Disconnected status, ProcessMessageAsync edge cases (invalid JSON, no type field, unknown type), GatewayUrl, NodeId null before connection. Test results: 573 passed, 20 skipped (Shared.Tests); 122 passed (Tray.Tests). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist.
Summary
This PR covers two improvements:
Task 5 – Coding Improvement: Adds a
GetStringArrayArgprotected helper toNodeCapabilityBaseand uses it to simplifySystemCapability.HandleWhich.Task 9 – Testing Improvements: Adds 8 new unit tests for
WindowsNodeClientand 6 new tests for the newGetStringArrayArghelper (14 net-new tests).Changes
NodeCapabilityBase.GetStringArrayArg(new helper)NodeCapabilityBasealready hasGetStringArg,GetIntArg, andGetBoolArghelpers. This PR adds the natural companion:Array.Empty(string)()when the property is absent, the args element is default, or the property is not a JSON array.nulland whitespace-only strings from the array.SystemCapability.HandleWhichsimplifiedReplaces 22 lines of manual JSON array parsing (with verbose
System.Text.Json.JsonValueKind.*references) with a single call toGetStringArrayArg:Behaviour is identical; the helper uses
string[]instead ofList(string)sobins.Lengthreplacesbins.Countin the guard.New Tests
NodeCapabilitiesTests– 6 new tests forGetStringArrayArg:JsonElementWindowsNodeClientTests– 8 new tests:SetPermission_UpdatesRegistrationPermissions– verifies permissions dictionary is populated correctlySetPermission_OverwritesPreviousValue– verifies overwrite semanticsDisconnectAsync_RaisesDisconnectedStatus– verifiesStatusChangedfiresDisconnectedProcessMessageAsync_InvalidJson_DoesNotThrow– resilience to malformed inputProcessMessageAsync_NoTypeField_DoesNotThrow– resilience to missingtypefieldProcessMessageAsync_UnknownMessageType_DoesNotThrow– resilience to unknown message typesGatewayUrl_ReturnsDisplayUrl– property returns normalized URLNodeId_IsNullBeforeConnection–NodeIdis null before a handshake completesTrade-offs
string[]instead ofList(string)means callers use.Lengthinstead of.Count. This is consistent with other helpers and avoids unnecessary list allocation.HandleWhichchanged.Test Status
OpenClaw.Shared.TestsOpenClaw.Tray.TestsBuild:
./build.ps1requires Windows — run was on Linux CI (expected❌ This project requires Windowsmessage — infrastructure-only limitation).