@@ -275,14 +275,20 @@ def test_n_same_limit_respected(self, tmp_path):
275275 assert "Buy entry 0" not in ctx
276276 assert "Buy entry 5" in ctx
277277
278- def test_n_cross_limit_respected (self , tmp_path ):
279- """Only the n_cross most recent cross-ticker entries are included."""
280- log = make_log (tmp_path )
281- for i , ticker in enumerate (["AAPL" , "MSFT" , "GOOG" , "META" ]):
282- _seed_completed (tmp_path , ticker , f"2026-01-{ i + 1 :02d} " , f"Buy { ticker } ." , "Correct." )
283- ctx = log .get_past_context ("NVDA" , n_cross = 3 )
284- assert "AAPL" not in ctx
285- assert "META" in ctx
278+ def test_point_in_time_guard (self , tmp_path ):
279+ """Entries on or after the trade_date are excluded to prevent lookahead."""
280+ log = make_log (tmp_path )
281+ _seed_completed (tmp_path , "NVDA" , "2026-01-05" , "Decision Jan 5." , "Lesson Jan 5." )
282+ _seed_completed (tmp_path , "NVDA" , "2026-01-15" , "Decision Jan 15." , "Lesson Jan 15." )
283+ _seed_completed (tmp_path , "AAPL" , "2026-01-10" , "Decision AAPL Jan 10." , "Lesson AAPL Jan 10." )
284+ _seed_completed (tmp_path , "AAPL" , "2026-01-20" , "Decision AAPL Jan 20." , "Lesson AAPL Jan 20." )
285+
286+ # Querying with trade_date="2026-01-12" should only see Jan 5 for NVDA and Jan 10 for AAPL
287+ ctx = log .get_past_context ("NVDA" , trade_date = "2026-01-12" )
288+ assert "Decision Jan 5" in ctx
289+ assert "Decision Jan 15" not in ctx
290+ assert "AAPL" in ctx
291+ assert "2026-01-20" not in ctx
286292
287293 # No-op when config is None
288294
0 commit comments