[test] Add tests for server.registerSysTools#1523
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test] Add tests for server.registerSysTools#1523github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
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>
This was referenced Mar 1, 2026
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.
Test Coverage Improvement:
registerSysToolsFunction Analyzed
internal/server(*UnifiedServer).registerSysToolsinternal/server/unified.go:442sysInitHandlerandsysListHandler), each with multiple branches for argument parsing, session management, and backend delegationWhy This Function?
registerSysToolswas selected as the most complex, under-tested function in the codebase. It contains two substantial closure-based handlers that together implement thesys___initandsys___list_serversMCP 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 whenEnableDIFC=trueTestRegisterSysTools_NotRegisteredWhenDIFCDisabled— tools absent when DIFC is off (default)TestSysInitHandler_HappyPathWithToken— session created and token stored correctlyTestSysInitHandler_HappyPathWithoutToken— success with empty/absent tokenTestSysInitHandler_EmptyTokenArg— explicit empty string token handledTestSysInitHandler_InvalidJSONArgs— malformed JSON returns error resultTestSysInitHandler_DefaultSessionWhenNoContextSession— falls back to "default" keyTestSysInitHandler_ReplacesExistingSession— re-init overwrites previous session tokenTestSysListHandler_HappyPath— success with pre-initialized sessionTestSysListHandler_SessionAutoCreated— success whenrequireSessionauto-createsTestSysListHandler_DefaultContextSession— success with no explicit session in contextTestRegisterSysTools_Idempotent— calling registerSysTools twice does not errorCoverage Report
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
The following domains were blocked by the firewall during workflow execution:
go.yaml.ingolang.orggopkg.ininvalidhostthatdoesnotexist12345.comproxy.golang.org