@@ -198,6 +198,42 @@ def test_trace_inputs_are_automatically_frozen_and_clustered(tmp_path):
198198 with pytest .raises (artifacts .ArtifactError ): objectives .rows (st , 'kb-intake.draft' )
199199
200200
201+ def test_full_kb_replay_larger_than_old_limit_round_trips (tmp_path ):
202+ from infermatrix_copilot .trace_store import TraceStore
203+ st = Settings (_env_file = None , improve_ledger_dir = str (tmp_path / 'ledger' ))
204+ store = TraceStore (tmp_path / 'trace' )
205+ payload = {'repo' : 'demo' , 'files' : {'repos/demo/a.md' : 'knowledge' },
206+ 'external_texts' : {'adapters/demo/reference.md' : '文' * 5_400_000 }}
207+ assert len (json .dumps (payload , ensure_ascii = False ).encode ()) > 16_000_000
208+ objectives .capture (store , 'kb-intake.draft' , 'demo#1' , payload )
209+ assert objectives .collect (st , store , 'kb-intake.draft' ) == 1
210+ row = objectives .rows (st , 'kb-intake.draft' )[0 ]
211+ assert row ['payload' ] == payload
212+
213+
214+ def test_oversized_replay_is_explicit_and_ineligible (tmp_path , monkeypatch ):
215+ from infermatrix_copilot .trace_store import TraceStore
216+ st = Settings (_env_file = None , improve_ledger_dir = str (tmp_path / 'ledger' ))
217+ store = TraceStore (tmp_path / 'trace' )
218+ monkeypatch .setattr (objectives , 'REPLAY_INPUT_MAX_BYTES' , 80 )
219+ payload = {'files' : {'other.md' : '文' * 30 }}
220+ size = len (json .dumps (payload , ensure_ascii = False ).encode ())
221+ assert len (json .dumps (payload , ensure_ascii = False )) < 80 < size
222+ with pytest .raises (objectives .ReplayCaptureLimit ) as exc :
223+ objectives .capture (store , 'kb-intake.draft' , 'demo#1' , payload )
224+ assert (exc .value .size_bytes , exc .value .limit_bytes ) == (size , 80 )
225+ record , = store .query (workflow = 'kb-intake.draft' )
226+ assert record ['inputs' ] == {}
227+ assert record ['result' ] == {'type' : 'replay_capture_deferred' , 'reason' : 'size_limit' ,
228+ 'input_bytes' : size , 'limit_bytes' : 80 ,
229+ 'input_sha' : artifacts .digest (json .dumps (payload , ensure_ascii = False ).encode ())}
230+ assert objectives .collect (st , store , 'kb-intake.draft' ) == 0
231+ assert objectives .rows (st , 'kb-intake.draft' ) == []
232+ with pytest .raises (artifacts .ArtifactError , match = 'evaluator material' ) as exc :
233+ objectives .capture (store , 'kb-intake.draft' , 'demo#2' , {'labels' : []})
234+ assert not isinstance (exc .value , objectives .ReplayCaptureLimit )
235+
236+
201237def test_empty_kb_is_not_rewarded_as_an_error ():
202238 row = {'payload' : {'files' : {}, 'repo_dir' : 'repos/demo' , 'release' : 'v1' , 'today' : '2026-10-04' }}
203239 assert objectives .score ('kb-intake' , row , {'operations' : [], 'rejected' : False }) == 1
0 commit comments