from okx_codex_trader.models import Candle from scripts import report_candle_cache_freshness as module def candle(ts: int) -> Candle: return Candle(symbol="ETH-USDT-SWAP", ts=ts, open=1.0, high=1.0, low=1.0, close=1.0, volume=1.0) def test_freshness_rows_reports_local_remote_gap(tmp_path): path = tmp_path / "ETH-USDT-SWAP" path.mkdir() (path / "15m.csv").write_text("ts,open,high,low,close,volume\n1000,1,1,1,1,1\n901000,1,1,1,1,1\n", encoding="utf-8") class Client: def get_recent_candles(self, symbol: str, bar: str, limit: int) -> list[Candle]: assert symbol == "ETH-USDT-SWAP" assert bar == "15m" assert limit == 2 return [candle(1_801_000), candle(2_701_000)] rows = module.freshness_rows(client=Client(), cache_dir=tmp_path, symbols=("ETH-USDT-SWAP",), bars=("15m",)) assert rows == [ { "symbol": "ETH-USDT-SWAP", "bar": "15m", "local_rows": 2, "local_last_ts": 901000, "local_last_time": "1970-01-01T00:15:01Z", "remote_last_ts": 2701000, "remote_last_time": "1970-01-01T00:45:01Z", "lag_bars": 2, "lag_ms": 1800000, } ]