"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
test(loaders): pin the adjustment stamp on served FMP/Tiingo frames
Yufeng Hec85c3fa2fcd8
diff --git a/agent/tests/test_fmp_loader.py b/agent/tests/test_fmp_loader.pyindex 03de7dea6..5cf3be1a7 100644--- a/agent/tests/test_fmp_loader.py+++ b/agent/tests/test_fmp_loader.py@@ -162,6 +162,25 @@ class TestParseHistorical:# Nothing to adjust against: the whole series stays on the raw basis# rather than the response being discarded.assert list(df["close"]) == [100.0, 101.0]+ # The static source table stamps fmp split_dividend; an all-raw+ # response must override that on the frame so frame_caliber reports+ # the basis actually served.+ assert df.attrs["adjustment"] == "raw"++ def test_an_adjusted_response_stamps_the_adjusted_basis(self):+ bars = [+ {+ "date": "2024-01-03", "open": 100, "high": 102, "low": 99,+ "close": 100, "adjClose": 50, "volume": 1000,+ },+ ]++ df = _parse_historical(_body("AAPL", bars))++ assert df is not None+ # Both bases carry an explicit stamp; the provenance table must never+ # fall back to the static source default for a served frame.+ assert df.attrs["adjustment"] == "split_dividend"def test_a_bar_without_a_usable_date_is_dropped(self):"""A bar that cannot be placed in time is not a bar.diff --git a/agent/tests/test_loader_retry_helpers.py b/agent/tests/test_loader_retry_helpers.pyindex b78ca9277..3d1e5201f 100644--- a/agent/tests/test_loader_retry_helpers.py+++ b/agent/tests/test_loader_retry_helpers.py@@ -500,6 +500,35 @@ def test_loader_cache_real_duckdb_round_trip(tmp_path, monkeypatch, loader_cacheassert restored.attrs == frame.attrs+def test_loader_cache_round_trip_keeps_adjustment_override(tmp_path, monkeypatch, loader_cache_root):+ """A frame-level ``adjustment`` override must survive the cache.++ FMP/Tiingo stamp ``adjustment="raw"`` when a response carries no usable+ adjusted column; if the cache dropped that attr, a warm hit would come+ back unmarked and the provenance table would stamp the static+ ``split_dividend`` caliber onto prices that are actually raw.+ """+ pytest.importorskip("duckdb")+ monkeypatch.setenv(LOADER_CACHE_ENV, "1")+ frame = _cache_frame()+ frame.attrs.update(adjustment="raw")+ kwargs = {+ "source": "fmp",+ "symbol": "AAPL.US",+ "timeframe": "1D",+ "start_date": "2025-01-01",+ "end_date": "2025-01-03",+ "fields": None,+ }++ loader_cache_put(**kwargs, frame=frame)+ restored = loader_cache_get(**kwargs)++ assert restored is not None+ assert restored.attrs == frame.attrs+ assert restored.attrs["adjustment"] == "raw"++def test_yfinance_loader_serves_second_fetch_from_cache(tmp_path, monkeypatch, fake_duckdb, loader_cache_root):"""A batch loader (yfinance) must skip its bulk download on a full cache hit."""monkeypatch.setenv(LOADER_CACHE_ENV, "1")diff --git a/agent/tests/test_tiingo_loader.py b/agent/tests/test_tiingo_loader.pyindex ec21fd208..4f7fb1b8c 100644--- a/agent/tests/test_tiingo_loader.py+++ b/agent/tests/test_tiingo_loader.py@@ -176,6 +176,27 @@ def test_an_all_unusable_adjusted_response_stays_one_raw_basis() -> None:# (one basis) rather than being discarded or priced at zero.assert df is not Noneassert list(df["close"]) == [100.0, 101.0]+ # The static source table stamps tiingo split_dividend; an all-raw+ # response must override that on the frame so frame_caliber reports the+ # basis actually served.+ assert df.attrs["adjustment"] == "raw"+++def test_an_adjusted_response_stamps_the_adjusted_basis() -> None:+ rows = [+ {+ "date": "2024-01-02T00:00:00.000Z",+ "open": 100, "high": 101, "low": 99, "close": 100, "volume": 1000,+ "adjOpen": 50.0, "adjHigh": 50.5, "adjLow": 49.5, "adjClose": 50.0,+ },+ ]++ df = _rows_to_frame(rows)++ assert df is not None+ # Both bases carry an explicit stamp; the provenance table must never+ # fall back to the static source default for a served frame.+ assert df.attrs["adjustment"] == "split_dividend"def test_a_bar_that_cannot_be_emitted_does_not_set_the_adjusted_basis() -> None: