@@ -189,7 +189,15 @@ def spy_exec(argv: list[str], *, timeout_ms: int, max_output_bytes: int, cwd: st
189189
190190@pytest .mark .parametrize (
191191 "case_name" ,
192- ["missing_receipt" , "non_quiescent" , "command_error" , "negative_savings" , "prefix_mismatch" ],
192+ [
193+ "missing_receipt" ,
194+ "non_quiescent" ,
195+ "command_error" ,
196+ "negative_savings" ,
197+ "zero_savings" ,
198+ "tokenizer_unavailable" ,
199+ "prefix_mismatch" ,
200+ ],
193201)
194202def test_codex_context_hook_semantic_unit_fails_closed_keep_raw (
195203 tmp_path : Path , monkeypatch : pytest .MonkeyPatch , case_name : str ,
@@ -271,6 +279,14 @@ def spy_exec(argv: list[str], *, timeout_ms: int, max_output_bytes: int, cwd: st
271279 obs_cmd ["command" ] = ["cat" , str (tmp_path / "missing-obs-file.txt" )]
272280 elif case_name == "negative_savings" :
273281 fold_spec ["baseline_text" ] = "short"
282+ elif case_name == "zero_savings" :
283+ fold_spec .update (
284+ baseline_tokens = 100 ,
285+ replacement_tokens = 100 ,
286+ tokenizer = {"name" : "fixture" , "encoding" : "o200k_base" },
287+ )
288+ elif case_name == "tokenizer_unavailable" :
289+ monkeypatch .setattr (hook_mod , "count_verifiable_tokens" , lambda * args , ** kwargs : None )
274290 elif case_name == "prefix_mismatch" :
275291 fold_spec ["prefix_digest" ] = "9" * 64
276292
@@ -285,6 +301,18 @@ def spy_exec(argv: list[str], *, timeout_ms: int, max_output_bytes: int, cwd: st
285301 assert "retained obligation" in res ["hookSpecificOutput" ]["additionalContext" ]
286302 if case_name in {"missing_receipt" , "non_quiescent" , "prefix_mismatch" }:
287303 assert obs_spawns == [], f"pre-check must prevent obs_next_cmd execution for { case_name } "
304+ if case_name == "tokenizer_unavailable" :
305+ assert fold_out ["fallback_reason" ] == "token_estimation_unavailable"
306+ assert fold_out ["baseline_tokens" ] is None
307+ assert fold_out ["replacement_tokens" ] is None
308+ assert fold_out ["net_savings_tokens" ] is None
309+ assert fold_out ["bytes_saved" ] == 0
310+ assert fold_out ["executed" ] is False
311+ assert obs_spawns == []
312+ if case_name == "zero_savings" :
313+ assert fold_out ["fallback_reason" ] == "negative_net_savings"
314+ assert fold_out ["baseline_tokens" ] == fold_out ["replacement_tokens" ] == 100
315+ assert fold_out ["net_savings_tokens" ] == 0
288316 saved_state = codex_context ._state (ctx_dir )
289317 assert "todo_fail_1" in saved_state ["semantic_unit_anchors" ]
290318 assert not saved_state .get ("semantic_unit_folds" )
0 commit comments