Skip to content

[test] Add tests for server.registerSysTools#1523

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
test/register-sys-tools-coverage-6a78ec4f2c806be1
Draft

[test] Add tests for server.registerSysTools#1523
github-actions[bot] wants to merge 1 commit intomainfrom
test/register-sys-tools-coverage-6a78ec4f2c806be1

Conversation

@github-actions
Copy link
Contributor

Test Coverage Improvement: registerSysTools

Function Analyzed

  • Package: internal/server
  • Function: (*UnifiedServer).registerSysTools
  • File: internal/server/unified.go:442
  • Previous Coverage: 12.8%
  • New Coverage: 80.9%
  • Improvement: +68.1 percentage points
  • Complexity: High — two handler closures (sysInitHandler and sysListHandler), each with multiple branches for argument parsing, session management, and backend delegation

Why This Function?

registerSysTools was selected as the most complex, under-tested function in the codebase. It contains two substantial closure-based handlers that together implement the sys___init and sys___list_servers MCP tools. These closures were almost entirely untested, even though they are the primary code path through which DIFC-enabled sessions are created and server lists are returned to clients.

Tests Added

New file: internal/server/register_sys_tools_test.go (11 test functions)

  • TestRegisterSysTools_ToolsAreRegistered — both tools registered when EnableDIFC=true
  • TestRegisterSysTools_NotRegisteredWhenDIFCDisabled — tools absent when DIFC is off (default)
  • TestSysInitHandler_HappyPathWithToken — session created and token stored correctly
  • TestSysInitHandler_HappyPathWithoutToken — success with empty/absent token
  • TestSysInitHandler_EmptyTokenArg — explicit empty string token handled
  • TestSysInitHandler_InvalidJSONArgs — malformed JSON returns error result
  • TestSysInitHandler_DefaultSessionWhenNoContextSession — falls back to "default" key
  • TestSysInitHandler_ReplacesExistingSession — re-init overwrites previous session token
  • TestSysListHandler_HappyPath — success with pre-initialized session
  • TestSysListHandler_SessionAutoCreated — success when requireSession auto-creates
  • TestSysListHandler_DefaultContextSession — success with no explicit session in context
  • TestRegisterSysTools_Idempotent — calling registerSysTools twice does not error

Coverage Report

Before: 12.8% (internal/server/unified.go:442: registerSysTools)
After:  80.9%
Improvement: +68.1pp
```

### Test Execution

All 11 new tests pass:

```
--- PASS: TestRegisterSysTools_ToolsAreRegistered (0.00s)
--- PASS: TestRegisterSysTools_NotRegisteredWhenDIFCDisabled (0.00s)
--- PASS: TestSysInitHandler_HappyPathWithToken (0.00s)
--- PASS: TestSysInitHandler_HappyPathWithoutToken (0.00s)
--- PASS: TestSysInitHandler_EmptyTokenArg (0.00s)
--- PASS: TestSysInitHandler_InvalidJSONArgs (0.00s)
--- PASS: TestSysInitHandler_DefaultSessionWhenNoContextSession (0.00s)
--- PASS: TestSysInitHandler_ReplacesExistingSession (0.00s)
--- PASS: TestSysListHandler_HappyPath (0.00s)
--- PASS: TestSysListHandler_SessionAutoCreated (0.00s)
--- PASS: TestSysListHandler_DefaultContextSession (0.00s)
--- PASS: TestRegisterSysTools_Idempotent (0.00s)
PASS
ok  	github.com/github/gh-aw-mcpg/internal/server

Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

Generated by Test Coverage Improver

Warning

⚠️ Firewall blocked 5 domains

The following domains were blocked by the firewall during workflow execution:

  • go.yaml.in
  • golang.org
  • gopkg.in
  • invalidhostthatdoesnotexist12345.com
  • proxy.golang.org

Adds 11 comprehensive tests for the registerSysTools function in
internal/server/unified.go, which was previously at 12.8% coverage.

Tests cover:
- Tool registration when DIFC is enabled vs disabled
- sysInitHandler happy path with and without token
- sysInitHandler with empty token argument
- sysInitHandler with invalid JSON arguments (error path)
- sysInitHandler fallback to 'default' session when no session in context
- sysInitHandler replacing an existing session on re-init
- sysListHandler happy path with pre-initialized session
- sysListHandler with auto-created session (requireSession behaviour)
- sysListHandler with default context session
- Idempotent tool re-registration via registerSysTools

Coverage improvement: 12.8% → 80.9% (+68.1pp)

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