Update unit tests to mock CallToolResult objects instead of plain dicts,
matching actual MCP tool behavior in production.
Changes:
- Add create_mcp_result() helper to create mock CallToolResult objects
- Update all mock handlers to return MCP result objects
- Update assertions to access result.structuredContent field
- Maintains test coverage while accurately reflecting production behavior
This ensures tests validate the actual code path used in production,
where MCP tools return CallToolResult objects with structuredContent
field containing the position dict.
Resolves issue where sell proceeds were not immediately available for
subsequent buy orders within the same trading session.
Problem:
- Both buy() and sell() independently queried database for starting position
- Multiple trades within same day all saw pre-trade cash balance
- Agents couldn't rebalance portfolios (sell + buy) in single session
Solution:
- ContextInjector maintains in-memory position state during trading session
- Position updates accumulate after each successful trade
- Position state injected into buy/sell via _current_position parameter
- Reset position state at start of each trading day
Changes:
- agent/context_injector.py: Add position tracking with reset_position()
- agent_tools/tool_trade.py: Accept _current_position in buy/sell functions
- agent/base_agent/base_agent.py: Reset position state daily
- tests: Add 13 comprehensive tests for position tracking
All new tests pass. Backward compatible, no schema changes required.