TradingAgents/tests/unit
ahmet guzererler 728ae69eab
feat: PM brain upgrade — macro/micro agents & memory split (#123)
* feat: introduce flow_id with timestamp-based report versioning

Replace run_id with flow_id as the primary grouping concept (one flow =
one user analysis intent spanning scan + pipeline + portfolio). Reports
are now written as {timestamp}_{name}.json so load methods always return
the latest version by lexicographic sort, eliminating the latest.json
pointer pattern for new flows.

Key changes:
- report_paths.py: add generate_flow_id(), ts_now() (ms precision),
  flow_id kwarg on all path helpers; keep run_id / pointer helpers for
  backward compatibility
- ReportStore: dual-mode save/load — flow_id uses timestamped layout,
  run_id uses legacy runs/{id}/ layout with latest.json
- MongoReportStore: add flow_id field and index; run_id stays for compat
- DualReportStore: expose flow_id property
- store_factory: accept flow_id as primary param, run_id as alias
- runs.py / langgraph_engine.py: generate and thread flow_id through all
  trigger endpoints and run methods
- Tests: add flow_id coverage for all layers; 905 tests pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: PM brain upgrade — macro/micro summary agents, memory split, forensic dashboard

Replaces the PM's raw-JSON context (~6,800 tokens on deep_think) with a
MAP-REDUCE compression layer using two parallel mid_think summary agents,
achieving ~70% cost reduction at the PM tier.

Architecture:
- MacroMemory: new regime-level memory class (MongoDB/JSON, separate from
  per-ticker reflexion memory) with record_macro_state/build_macro_context
- ReflexionMemory: extended with collection_name param to isolate
  micro_reflexion from the pipeline reflexion collection (with distinct
  local JSON fallback path to prevent file collision)
- Macro_Summary_Agent (mid_think): compresses scan_summary into a 1-page
  regime brief with memory injection; sentinel guard prevents LLM call on
  empty/error scan data ("NO DATA AVAILABLE - ABORT MACRO")
- Micro_Summary_Agent (mid_think): compresses holding_reviews + candidates
  into a markdown table brief with per-ticker memory injection
- Portfolio graph: parallel fan-out (prioritize_candidates → macro_summary
  ‖ micro_summary → make_pm_decision) using _last_value reducers for safe
  concurrent state writes (ADR-005 pattern)
- PM refactor: Pydantic PMDecisionSchema enforces Forensic Execution
  Dashboard output (macro_regime, forensic_report, per-trade
  macro_alignment/memory_note/position_sizing_logic); with_structured_output
  as primary path, extract_json fallback for non-conforming providers
- PM sentinel handling: "NO DATA AVAILABLE" in macro_brief substituted
  with actionable conservative guidance before LLM sees it

62 new unit tests across 4 test files covering all new components.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: address code review — relaxed error guard, ticker_analyses, PM memory wiring

1. macro_summary_agent: relaxed error guard to only abort when scan_summary's
   sole key is "error" (partial failures with real data are now processed)
2. micro_summary_agent: now reads ticker_analyses from state and enriches
   the per-ticker table with trading graph analysis data
3. portfolio_graph: wires macro_memory and micro_memory to PM factory call
4. test_empty_state: updated test for new partial-failure behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 12:55:24 +01:00
..
agents Parallel pre-fetch for analyst agents to reduce LLM round-trips 2026-03-23 21:08:15 +00:00
__init__.py Add integration and unit tests for scanner routing, TTM analysis, vendor fail-fast, and yfinance data layer 2026-03-19 13:51:57 +01:00
conftest.py Add integration and unit tests for scanner routing, TTM analysis, vendor fail-fast, and yfinance data layer 2026-03-19 13:51:57 +01:00
test_alpha_vantage_exceptions.py fix(tests): complete PR #26 — enforce socket isolation in unit tier and add test suite reference doc (#30) 2026-03-19 17:41:25 +01:00
test_alpha_vantage_integration.py Add integration and unit tests for scanner routing, TTM analysis, vendor fail-fast, and yfinance data layer 2026-03-19 13:51:57 +01:00
test_alpha_vantage_scanner.py Add integration and unit tests for scanner routing, TTM analysis, vendor fail-fast, and yfinance data layer 2026-03-19 13:51:57 +01:00
test_api_usage.py Add API consumption estimation module and CLI command 2026-03-21 17:25:26 +00:00
test_cli_main_tools.py 🧪 Implement robust tool call parsing and unit tests 2026-03-21 14:56:12 +00:00
test_config_wiring.py merge: sync with upstream TauricResearch/TradingAgents v0.2.2 2026-03-23 12:17:25 +00:00
test_debate_rounds.py merge: sync with upstream TauricResearch/TradingAgents v0.2.2 2026-03-23 12:17:25 +00:00
test_e2e_api_integration.py Add integration and unit tests for scanner routing, TTM analysis, vendor fail-fast, and yfinance data layer 2026-03-19 13:51:57 +01:00
test_empty_state.py feat: PM brain upgrade — macro/micro agents & memory split (#123) 2026-03-26 12:55:24 +01:00
test_env_override.py fix(tests): complete PR #26 — enforce socket isolation in unit tier and add test suite reference doc (#30) 2026-03-19 17:41:25 +01:00
test_finnhub_integration.py Fix Finnhub API error handling and add coverage 2026-03-21 14:51:29 +00:00
test_finnhub_scanner_utils.py 🧪 Add unit tests for _safe_fmt in finnhub_scanner 2026-03-21 22:20:19 +00:00
test_incident_fixes.py fix: harden dataflows layer against silent failures and data corruption 2026-03-22 07:23:14 +01:00
test_industry_deep_dive.py test: add tests and parsing logic for text formats in _extract_top_sectors 2026-03-21 08:28:35 +00:00
test_json_utils.py Add integration and unit tests for scanner routing, TTM analysis, vendor fail-fast, and yfinance data layer 2026-03-19 13:51:57 +01:00
test_langgraph_engine_extraction.py Fix report saving, event storing, auto tickers, portfolio report loading, and state propagation 2026-03-23 18:33:11 +00:00
test_langgraph_engine_run_modes.py fix: address all PR#106 review findings (ADR 016) (#106) 2026-03-25 11:14:23 +01:00
test_macro_bridge.py feat: include portfolio holdings in auto mode pipeline analysis (#104) 2026-03-24 18:35:53 +01:00
test_macro_memory.py feat: PM brain upgrade — macro/micro agents & memory split (#123) 2026-03-26 12:55:24 +01:00
test_macro_regime.py Merge pull request #54 from aguzererler/test-macro-regime-fmt-pct-18208719821293052000 2026-03-21 17:36:20 +01:00
test_mongo_report_store.py fix: address all PR#106 review findings (ADR 016) (#106) 2026-03-25 11:14:23 +01:00
test_notebook_sync.py Fix security vulnerability in NotebookLM sync subprocess calls 2026-03-21 22:17:55 +00:00
test_observability_integration.py fix: address all PR#106 review findings (ADR 016) (#106) 2026-03-25 11:14:23 +01:00
test_peer_comparison.py Add integration and unit tests for scanner routing, TTM analysis, vendor fail-fast, and yfinance data layer 2026-03-19 13:51:57 +01:00
test_portfolio_tools.py feat: add portfolio risk metrics module and LangChain agent tools 2026-03-20 14:42:43 +00:00
test_pr106_review_fixes.py fix: address all PR#106 review findings (ADR 016) (#106) 2026-03-25 11:14:23 +01:00
test_pydantic_schema.py feat: PM brain upgrade — macro/micro agents & memory split (#123) 2026-03-26 12:55:24 +01:00
test_reflexion_memory.py fix: address all PR#106 review findings (ADR 016) (#106) 2026-03-25 11:14:23 +01:00
test_report_paths_run_id.py feat: load flow_id in FE to resume runs and fix max_tickers cap (#113) 2026-03-26 07:10:42 +01:00
test_report_store_run_id.py feat: load flow_id in FE to resume runs and fix max_tickers cap (#113) 2026-03-26 07:10:42 +01:00
test_scanner_fallback.py refactor(tests): consolidate live-API tests into integration/, move mocked tests to unit/ 2026-03-19 14:24:52 +01:00
test_scanner_graph.py feat(scanner): Finviz smart money scanner + Golden Overlap strategy 2026-03-24 16:03:17 +01:00
test_scanner_mocked.py feat(scanner): Finviz smart money scanner + Golden Overlap strategy 2026-03-24 16:03:17 +01:00
test_security_notebook_sync.py Fix security vulnerability in NotebookLM sync subprocess calls 2026-03-21 22:17:55 +00:00
test_stockstats_utils.py 🧪 Resolve PRs #56, #58, and #60 2026-03-21 16:51:49 +00:00
test_store_factory.py feat: load flow_id in FE to resume runs and fix max_tickers cap (#113) 2026-03-26 07:10:42 +01:00
test_summary_agents.py feat: PM brain upgrade — macro/micro agents & memory split (#123) 2026-03-26 12:55:24 +01:00
test_ttm_analysis.py Merge pull request #69 from aguzererler/copilot/review-financial-tools-implementation 2026-03-21 22:41:55 +01:00
test_vendor_failfast.py Add integration and unit tests for scanner routing, TTM analysis, vendor fail-fast, and yfinance data layer 2026-03-19 13:51:57 +01:00
test_yfinance_integration.py 🧪 Add tests for _extract_article_data in yfinance_news.py 2026-03-21 08:23:12 +00:00