TradingAgents/tests
voidborne-d 1e2164ec78 fix: add JSON file persistence to FinancialSituationMemory
FinancialSituationMemory stored all learned lessons in RAM-only Python
lists with no persistence layer.  Every process restart or new
TradingAgentsGraph() instance wiped all memory, making
reflect_and_remember() useless in practice — especially in server/API
deployments where a new graph is created per request.

Changes:

1. memory.py — add optional JSON file persistence:
   - New config key `memory_persist_dir`: when set to a directory path,
     each memory instance writes `<dir>/<name>.json` on every mutation
     (add_situations / clear) and loads it on construction.
   - When unset or None (the default), behaviour is identical to before
     (RAM-only) — fully backward compatible.
   - Atomic-ish writes via .tmp → rename to avoid corruption on crash.
   - Graceful handling of corrupt / missing / partial JSON files.
   - Tilde expansion (`~/...`) and automatic parent directory creation.

2. default_config.py — add `memory_persist_dir: None` to DEFAULT_CONFIG.

3. main.py — enable persistence in the example and improve
   reflect_and_remember documentation comment.

4. tests/test_memory_persistence.py — 21 regression tests covering:
   - RAM-only backward compatibility (5 tests)
   - Persistence round-trip, incremental add, clear, BM25 rebuild,
     JSON schema, Unicode (7 tests)
   - Edge cases: corrupt JSON, missing keys, mismatched lengths,
     nested directory creation, tilde expansion (5 tests)
   - Multiple instances sharing same directory (1 test)
   - Default config key existence (2 tests)
   - Source audit: TradingAgentsGraph passes config to all 5 memories (1 test)

Closes #563
2026-04-17 19:06:59 +00:00
..
test_google_api_key.py refactor: simplify api_key mapping and consolidate tests 2026-03-24 14:52:51 +01:00
test_memory_persistence.py fix: add JSON file persistence to FinancialSituationMemory 2026-04-17 19:06:59 +00:00
test_model_validation.py sync model validation with cli catalog 2026-03-25 21:23:02 +08:00
test_ticker_symbol_handling.py fix: preserve exchange-qualified tickers across agent prompts 2026-03-21 21:10:13 +08:00