88import tempfile
99import types
1010import unittest
11- from contextlib import redirect_stderr
11+ from contextlib import redirect_stderr , redirect_stdout
1212from io import StringIO
1313from pathlib import Path
1414from unittest .mock import patch
@@ -159,11 +159,14 @@ def test_main_rejects_invalid_depth(self):
159159 def test_head_uses_incremental (self ):
160160 ri , rf = _Rec (), _Rec ()
161161 self ._install (run_full = rf , run_incremental = ri )
162- engine_adapter .run_head ("/repo" , "/out" , "r" , "rid" , 1 , "base" , "head" , "head" )
162+ buf = StringIO ()
163+ with redirect_stdout (buf ):
164+ engine_adapter .run_head ("/repo" , "/out" , "r" , "rid" , 1 , "base" , "head" , "head" )
163165 self .assertEqual (len (ri .calls ), 1 )
164166 self .assertEqual (len (rf .calls ), 0 ) # no fallback
165167 self .assertEqual (ri .calls [0 ]["base_ref" ], "base" )
166168 self .assertEqual (ri .calls [0 ]["target_ref" ], "head" )
169+ self .assertIn ("head_analysis_mode=incremental" , buf .getvalue ())
167170
168171 def test_head_falls_back_to_full_on_cache_miss (self ):
169172 analysis , IncMiss , _ = self ._install () # install once so the exception class identity matches
@@ -174,11 +177,14 @@ def test_head_falls_back_to_full_on_cache_miss(self):
174177 (Path (out ) / "stale.json" ).write_text ("{}" ) # must be wiped before the full run
175178 (Path (out ) / "health" ).mkdir ()
176179 (Path (out ) / "health" / "stale.json" ).write_text ("{}" )
177- engine_adapter .run_head ("/repo" , out , "r" , "rid" , 3 , "base" , "head" , "head" )
180+ buf = StringIO ()
181+ with redirect_stdout (buf ):
182+ engine_adapter .run_head ("/repo" , out , "r" , "rid" , 3 , "base" , "head" , "head" )
178183 self .assertEqual (len (rf .calls ), 1 ) # fell back to full
179184 self .assertEqual (rf .calls [0 ]["depth_level" ], 3 )
180185 self .assertFalse ((Path (out ) / "stale.json" ).exists ()) # head dir wiped before full
181186 self .assertFalse ((Path (out ) / "health" ).exists ()) # nested stale artifacts wiped too
187+ self .assertIn ("head_analysis_mode=full" , buf .getvalue ())
182188
183189 def test_head_falls_back_to_full_on_baseline_unavailable (self ):
184190 analysis , _ , BaseUnavail = self ._install () # the other warm-start failure must also fall back
0 commit comments