Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.
This repository was archived by the owner on May 18, 2026. It is now read-only.

test: add boundary condition and nil-input tests for command builder and MCP handlers #106

@jongio

Description

@jongio

Summary

The buildCommand() function in cli/src/internal/executor/command_builder.go and several MCP handler functions lack tests for nil struct inputs, zero-value configurations, and boundary conditions. While callers currently validate inputs before calling these functions, the absence of defensive tests means refactoring could introduce nil-pointer panics.

Impact

  • Nil pointer dereferences would crash the CLI or MCP server without a clear error message
  • Boundary conditions (extremely long paths, special characters in shell names) are untested
  • As the codebase grows, new callers may not replicate existing validation patterns

Specific Gaps

command_builder.go - buildCommand():

  • No test for nil Config struct
  • No test for empty shell name combined with failed OS detection
  • No test for shell path containing spaces or special characters
  • No test for extremely long script paths

mcp.go - handler functions:

  • handleExecScript: no test for nil CallToolRequest or nil Arguments
  • handleExecInline: no test for nil Arguments map
  • handleGetEnvironment: no test with completely empty environment

executor.go - prepareEnvironment():

  • No test for environment variable with = in the value (e.g., KEY=val=ue)
  • No test for environment variable with empty key
  • No test for duplicate environment variable keys

Recommendation

  1. Add a TestBuildCommandBoundaryConditions table-driven test covering:

    • Nil/zero-value Config
    • Shell name with spaces
    • Very long script path (>260 chars on Windows)
    • Shell set to nonexistent binary
  2. Add nil-input guards to MCP handler tests:

    • Nil request object
    • Request with nil Arguments map
    • Arguments with unexpected types (number where string expected)
  3. Add environment edge case tests:

    • Values containing = characters
    • Empty string keys or values
    • Duplicate keys with different values

Metadata

Metadata

Assignees

No one assigned

    Labels

    automatedCreated by automationtest-healthTest suite health findings

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions