Skip to content

[Repo Assist] improve: add GetStringArrayArg helper and expand test coverage#161

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-node-capabilities-2026-04-09-408966fccb27f239
Draft

[Repo Assist] improve: add GetStringArrayArg helper and expand test coverage#161
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-node-capabilities-2026-04-09-408966fccb27f239

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 9, 2026

🤖 This is an automated pull request from Repo Assist.

Summary

This PR covers two improvements:

Task 5 – Coding Improvement: Adds a GetStringArrayArg protected helper to NodeCapabilityBase and uses it to simplify SystemCapability.HandleWhich.

Task 9 – Testing Improvements: Adds 8 new unit tests for WindowsNodeClient and 6 new tests for the new GetStringArrayArg helper (14 net-new tests).

Changes

NodeCapabilityBase.GetStringArrayArg (new helper)

NodeCapabilityBase already has GetStringArg, GetIntArg, and GetBoolArg helpers. This PR adds the natural companion:

protected string[] GetStringArrayArg(JsonElement args, string name)
  • Returns Array.Empty(string)() when the property is absent, the args element is default, or the property is not a JSON array.
  • Filters out null and whitespace-only strings from the array.
  • Handles mixed-type arrays safely (skips non-string elements).

SystemCapability.HandleWhich simplified

Replaces 22 lines of manual JSON array parsing (with verbose System.Text.Json.JsonValueKind.* references) with a single call to GetStringArrayArg:

// Before: 22 lines of manual parsing
var bins = new List(string)();
if (request.Args.ValueKind != System.Text.Json.JsonValueKind.Undefined && ...)
{ ... }

// After: 1 line
var bins = GetStringArrayArg(request.Args, "bins");

Behaviour is identical; the helper uses string[] instead of List(string) so bins.Length replaces bins.Count in the guard.

New Tests

NodeCapabilitiesTests – 6 new tests for GetStringArrayArg:

  • Returns values from a valid array
  • Returns empty when property is missing
  • Returns empty when property is not an array (wrong type)
  • Filters out whitespace-only elements
  • Returns empty for default JsonElement
  • Ignores non-string elements in mixed arrays

WindowsNodeClientTests – 8 new tests:

  • SetPermission_UpdatesRegistrationPermissions – verifies permissions dictionary is populated correctly
  • SetPermission_OverwritesPreviousValue – verifies overwrite semantics
  • DisconnectAsync_RaisesDisconnectedStatus – verifies StatusChanged fires Disconnected
  • ProcessMessageAsync_InvalidJson_DoesNotThrow – resilience to malformed input
  • ProcessMessageAsync_NoTypeField_DoesNotThrow – resilience to missing type field
  • ProcessMessageAsync_UnknownMessageType_DoesNotThrow – resilience to unknown message types
  • GatewayUrl_ReturnsDisplayUrl – property returns normalized URL
  • NodeId_IsNullBeforeConnectionNodeId is null before a handshake completes

Trade-offs

  • Using string[] instead of List(string) means callers use .Length instead of .Count. This is consistent with other helpers and avoids unnecessary list allocation.
  • No behaviour changes to existing code — only the internal implementation of HandleWhich changed.

Test Status

Suite Result
OpenClaw.Shared.Tests ✅ 573 passed, 20 skipped (was 559)
OpenClaw.Tray.Tests ✅ 122 passed

Build: ./build.ps1 requires Windows — run was on Linux CI (expected ❌ This project requires Windows message — infrastructure-only limitation).

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@cbb46ab386962aa371045839fc9998ee4e97ca64

- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants