Skip to content

test(tools): comprehensive test suite for code_execute module (+45 tests) - #141

Open
manus-use wants to merge 1 commit into
mainfrom
test/code-execute-suite
Open

test(tools): comprehensive test suite for code_execute module (+45 tests)#141
manus-use wants to merge 1 commit into
mainfrom
test/code-execute-suite

Conversation

@manus-use

Copy link
Copy Markdown
Owner

Summary

Adds a comprehensive test suite for the code_execute tool module (src/manus_agent/tools/code_execute.py), which previously had zero test coverage.

What's Tested (45 tests)

CodeExecutor class

  • Initialization with default config (Config.from_file()) and explicit config
  • Sandbox lazy initialization (_get_sandbox): disabled returns None, enabled creates/starts DockerSandbox, reuses instance on subsequent calls

execute_python

  • Sandbox path: routes to sandbox.execute_code() with correct args
  • Local path: writes temp file, runs via subprocess.run, cleans up temp file
  • Custom timeout passthrough
  • Non-zero exit code handling

execute_bash

  • Sandbox path: routes to sandbox.execute_command()
  • Local path: uses subprocess.run with shell=True
  • Failure handling (non-zero exit codes)

cleanup

  • Stops running sandbox and resets state
  • No-op when no sandbox was created

get_executor (global singleton)

  • Creates and reuses a single instance
  • Config passthrough

code_execute (async function)

  • Language routing: python, bash, sh, shell
  • Case-insensitive language matching
  • Unsupported language returns error dict
  • Non-zero exit code sets error field
  • Zero exit code leaves error as None
  • asyncio.TimeoutError handling
  • Generic exception handling (RuntimeError, PermissionError, OSError)
  • Custom timeout passthrough

code_execute_sync (@tool decorator)

  • Wraps async function in a new event loop
  • Passes all arguments through

Integration tests (subprocess-mocked)

  • Full Python execution flow
  • Full bash execution flow
  • subprocess.TimeoutExpired surfaces as execution error
  • Syntax error handling

Edge cases

  • Empty code, multiline code, large output
  • Both stdout and stderr captured simultaneously

No Overlap with Existing PRs

Checked all 50 open PRs (#80#140) and 30 most recently merged PRs. Test suites exist for:

None test code_execute.py. This module is the core code execution engine (async CodeExecutor with sandbox/local paths, language dispatch, timeout handling, global singleton) and had zero coverage.

Test Results

1203 passed, 3 deselected, 3 warnings in 24.47s

Baseline: 1158 → New total: 1203 (+45 tests), 0 failures.

Technical Notes

  • All tests are 100% mocked — no real subprocess calls, no Docker dependency
  • Uses pytest-asyncio for async test methods
  • Global _executor singleton is reset between tests via autouse fixture
  • Mocks DockerSandbox at the import boundary to test sandbox path without Docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant