Skip to content

[Repo Assist] improve: SearchValues in GatewayUrlHelper + 10 SystemCapability tests#209

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-searchvalues-gatewayurlhelper-2026-04-24-191b04b3e623049b
Draft

[Repo Assist] improve: SearchValues in GatewayUrlHelper + 10 SystemCapability tests#209
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-searchvalues-gatewayurlhelper-2026-04-24-191b04b3e623049b

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist.

Two targeted improvements across Task 5 (Coding) and Task 9 (Testing).


Task 5 — Coding: SearchValues<char> in GatewayUrlHelper

GatewayUrlHelper.s_authorityTerminators was a char[] passed to string.IndexOfAny(char[], int). This is now a SearchValues<char> used with a span-based IndexOfAny, consistent with the pattern already established in ShellQuoting.cs.

Before:

private static readonly char[] s_authorityTerminators = { '/', '?', '#' };
// ...
var authorityEnd = url.IndexOfAny(s_authorityTerminators, authorityStart);
if (authorityEnd < 0) authorityEnd = url.Length;

After:

private static readonly SearchValues<char> s_authorityTerminators =
    SearchValues.Create("/?#");
// ...
int relativeEnd = url.AsSpan(authorityStart).IndexOfAny(s_authorityTerminators);
var authorityEnd = relativeEnd < 0 ? url.Length : authorityStart + relativeEnd;

SearchValues<char> builds an optimized SIMD lookup structure at startup (SSE2/AVX2 on x64), giving faster character scanning than the legacy overload. The logic is unchanged — same three terminator characters, same semantics.


Task 9 — Testing: SystemCapability coverage for untested command paths

Three command handlers had zero test coverage: system.run.prepare, system.execApprovals.get, and system.execApprovals.set. The env-sanitization guard in system.run was also untested. Added 10 new tests:

New test What it verifies
RunPrepare_ReturnsCommandText_ForArray cmdText field populated from argv array
RunPrepare_ReturnsCommandText_ForString cmdText uses rawCommand when provided
RunPrepare_ReturnsPlan_WithArgvAndCwd plan object carries argv, cwd, agentId
RunPrepare_ReturnsError_WhenMissingCommand Missing command → "Missing command" error
ExecApprovalsGet_WhenNoPolicyConfigured_ReturnsDisabled enabled: false with no policy set
ExecApprovalsGet_WhenPolicySet_ReturnsRules enabled: true + rules array when policy wired
ExecApprovalsSet_WhenNoPolicyConfigured_ReturnsError "No exec policy configured" error
ExecApprovalsSet_UpdatesRules updated: true, ruleCount: 1 after set
Run_BlockedEnvVar_ReturnsError PATH env override → blocked error response
Run_AllowedEnvVar_Passes Custom env var passes through to command runner

Test Status

  • dotnet test OpenClaw.Shared.Tests670 passed, 20 skipped (↑10 from 660)
  • dotnet test OpenClaw.Tray.Tests122 passed (unchanged)

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

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

…lity coverage

Task 5 (Coding Improvements):
- GatewayUrlHelper.s_authorityTerminators: char[] → SearchValues<char>
  matching the SIMD-optimized pattern already used in ShellQuoting.cs
- Span-based IndexOfAny avoids the start-offset overload

Task 9 (Testing Improvements):
- Add 10 new SystemCapability tests covering previously-untested paths:
  - system.run.prepare: array command, string command, plan structure, missing-command error
  - system.execApprovals.get: no-policy (disabled), with-policy (enabled + rules)
  - system.execApprovals.set: no-policy error, updates rules + ruleCount
  - system.run: blocked env var (PATH) → error; allowed env var passes through

All 660 Shared tests pass (↑10), 122 Tray tests pass.

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