Skip to content

fix(tests): MCP stdio harness subprocess PYTHONPATH + startup diagnostics (#227) - #228

Merged
tcconnally merged 1 commit into
mainfrom
fix/227-mcp-stdio-test-harness
Aug 11, 2026
Merged

fix(tests): MCP stdio harness subprocess PYTHONPATH + startup diagnostics (#227)#228
tcconnally merged 1 commit into
mainfrom
fix/227-mcp-stdio-test-harness

Conversation

@tcconnally

Copy link
Copy Markdown
Contributor

Closes #227.

Root cause

tests/test_mcp.py::_spawn_server() runs the child from a tmp cwd outside
the checkout (cwd=tmp_path.parent), so python -m ledger_agent.mcp_server
could not import ledger_agent unless the package happened to be
pip-installed into that interpreter. The child exited before initialization
and _exchange() surfaced the misleading KeyError: 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)
  • with PYTHONPATH=<repo root> prepended → clean start (exit 0 on EOF)

Fix

  • _spawn_server(): prepend the repository root to the child's PYTHONPATH.
  • _exchange(): blank stdout now raises an AssertionError containing the
    child 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
  • Full suite: 697 passed / 0 failed / 0 skipped

…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.
@tcconnally
tcconnally merged commit 8cc4353 into main Aug 11, 2026
11 checks passed
@tcconnally
tcconnally deleted the fix/227-mcp-stdio-test-harness branch August 11, 2026 17:54
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.

Fix MCP stdio test subprocess import path and startup diagnostics

1 participant