@@ -175,6 +175,9 @@ def test_complete_reader_delivery_allows_delta_without_diagnostics_or_ack(tmp_pa
175175 context .codex_context_hook (str (tmp_path ), {** event , "hook_event_name" : name ,
176176 "tool_response" : "ordinary tool output" })
177177 assert context ._state (tmp_path ) == state
178+ context .codex_context_hook (str (tmp_path ), {** event , "hook_event_name" : "PostToolUse" ,
179+ "tool_response" : {"isError" : True , "content" : [{"type" : "text" , "text" : "Unrelated tool failed." }]}})
180+ assert context ._state (tmp_path ) == state
178181 _ , second = project (tmp_path , "two" , payload = payload )
179182 assert second ["mode" ] == "delta" and second ["continuity_basis" ] == "captured_file"
180183 assert not (tmp_path / "traces" ).exists ()
@@ -443,7 +446,8 @@ def test_known_incomplete_delivery_cannot_establish_baseline(tmp_path, monkeypat
443446
444447
445448@pytest .mark .parametrize ("mode" , ["full" , "delta" ])
446- @pytest .mark .parametrize ("damage" , ["changed_bytes" , "missing_file" , "changed_file" , "symlink" ])
449+ @pytest .mark .parametrize ("damage" , ["changed_bytes" , "missing_file" , "changed_file" , "symlink" ,
450+ "failed_mcp" , "failed_mcp_nested" ])
447451def test_hook_cli_rejects_changed_page_bytes_and_recovers_original (tmp_path , monkeypatch , mode , damage ):
448452 event = setup (tmp_path , monkeypatch )
449453 payload = {"ok" : True , "plan_summary" : {"requirements" : "Preserve every obligation. " * 1000 }}
@@ -469,7 +473,7 @@ def test_hook_cli_rejects_changed_page_bytes_and_recovers_original(tmp_path, mon
469473 assert json .loads ("" .join (page ["content" ] for page in changed ))
470474 elif damage == "changed_file" :
471475 source .write_bytes (source_raw + b" " ) # valid JSON, different pinned digest
472- else :
476+ elif damage in { "missing_file" , "symlink" } :
473477 source .unlink ()
474478 if damage == "symlink" :
475479 alias_target = tmp_path / "same-bytes.json"
@@ -481,18 +485,21 @@ def test_hook_cli_rejects_changed_page_bytes_and_recovers_original(tmp_path, mon
481485 "--format" , "json" , "quota" , "context-hook" , "--context-delivery" , "on" , "--codex-app" ,
482486 "--codex-context-dir" , str (tmp_path )]
483487
484- def hook (values ):
485- response = {"content" : [{"type" : "text" , "text" : json .dumps (page )} for page in values ]}
488+ def hook (values , * , failed = False , nested = False ):
489+ response = {"isError" : failed ,
490+ "content" : [{"type" : "text" , "text" : json .dumps (page )} for page in values ]}
491+ if nested :
492+ response = {"exit_code" : 0 , "output" : json .dumps (response )}
486493 result = subprocess .run (cmd , input = json .dumps ({** event , "hook_event_name" : "PostToolUse" ,
487494 "tool_use_id" : "capture-read" , "tool_response" : response }), capture_output = True , text = True ,
488495 cwd = tmp_path , env = {** os .environ , "PYTHONPATH" : str (repo )}, timeout = 20 )
489496 assert result .returncode == 0 , result .stderr
490497 assert json .loads (result .stdout ) == {}
491498
492- hook (changed )
499+ hook (changed , failed = damage . startswith ( "failed_mcp" ), nested = damage == "failed_mcp_nested" )
493500 assert "candidate" not in context ._state (tmp_path )
494501 assert context ._state (tmp_path )["recovery" ] == recovery
495- if damage != "changed_bytes" :
502+ if damage in { "missing_file" , "changed_file" , "symlink" } :
496503 source .unlink (missing_ok = True )
497504 source .write_bytes (source_raw )
498505 source .chmod (0o600 )
0 commit comments