fix(tests): MCP stdio harness subprocess PYTHONPATH + startup diagnostics (#227) - #228
Merged
Merged
Conversation
…ONPATH (#227) _spawn_server() ran the child from a tmp cwd outside the checkout, so `python -m ledger_agent.mcp_server` died with ModuleNotFoundError when the package was not pip-installed into that interpreter; the failure surfaced as a misleading KeyError: 1 from _exchange(). Prepend the repo root to PYTHONPATH for the child, and turn blank-stdout EOF into an AssertionError carrying the child return code and stderr. Verified: 8/8 MCP tests; full suite 697 passed / 0 failed / 0 skipped.
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.
Closes #227.
Root cause
tests/test_mcp.py::_spawn_server()runs the child from a tmp cwd outsidethe checkout (
cwd=tmp_path.parent), sopython -m ledger_agent.mcp_servercould not import
ledger_agentunless the package happened to bepip-installed into that interpreter. The child exited before initialization
and
_exchange()surfaced the misleadingKeyError: 1.Reproduced locally with a bare interpreter:
cd /tmp && python3 -m ledger_agent.mcp_server --db /tmp/x.db→ModuleNotFoundError: No module named 'ledger_agent'(exit 1)PYTHONPATH=<repo root>prepended → clean start (exit 0 on EOF)Fix
_spawn_server(): prepend the repository root to the child'sPYTHONPATH._exchange(): blank stdout now raises anAssertionErrorcontaining thechild return code and stderr (plus a distinct message if the child is
still running) instead of returning a partial response dict.
Validation
python3 -m pytest tests/test_mcp.py -q: 8 passed