Skip to content

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

Merged
shanselman merged 1 commit intomasterfrom
repo-assist/improve-node-capabilities-2026-04-09-408966fccb27f239
Apr 10, 2026
Merged

[Repo Assist] improve: add GetStringArrayArg helper and expand test coverage#161
shanselman merged 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

Adds the GetStringArrayArg helper for node capabilities, simplifies
system.which to use it, preserves the existing trim semantics for bin
names, and expands Shared test coverage for both the helper and
WindowsNodeClient behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@shanselman shanselman force-pushed the repo-assist/improve-node-capabilities-2026-04-09-408966fccb27f239 branch from 2440c68 to 05cdd46 Compare April 10, 2026 00:43
@shanselman shanselman marked this pull request as ready for review April 10, 2026 00:43
@shanselman shanselman merged commit 87e5cd8 into master Apr 10, 2026
1 check passed
@shanselman shanselman deleted the repo-assist/improve-node-capabilities-2026-04-09-408966fccb27f239 branch April 10, 2026 00:43
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.

1 participant