@@ -358,3 +358,73 @@ def broken(company):
358358 assert result ["dataAsOf" ]["earliestPeriod" ] == "2024"
359359 assert result ["dataAsOf" ]["blockLatestPeriods" ] == {"older" : "2024" , "newer" : "2025" }
360360 assert result ["dataAsOf" ]["mixedPeriods" ] is True
361+
362+
363+ def test_run_degrades_only_optional_aggregated_source_failures (monkeypatch ):
364+ """OS가 묶은 외부 source 실패는 한 calc 결손으로 남기되 로컬 오류는 숨기지 않는다."""
365+ from types import SimpleNamespace
366+
367+ import dartlab .analysis .financial as financial
368+ from dartlab .analysis .financial import Analysis
369+ from dartlab .analysis .financial ._registry import _AxisEntry , _CalcEntry
370+ from dartlab .core .offlineGuard import OfflineViolation
371+ from dartlab .gather .types import SourceAttemptsExhaustedError , SourceUnavailableError
372+
373+ optionalError = SourceAttemptsExhaustedError (
374+ "history" ,
375+ [
376+ ("naver" , ExceptionGroup ("connect" , [OfflineViolation ("blocked" )])),
377+ ("fmp" , SourceUnavailableError ("key missing" )),
378+ ],
379+ )
380+
381+ def stable (company ):
382+ return {"period" : "2025" }
383+
384+ def optional (company ):
385+ raise optionalError
386+
387+ module = SimpleNamespace (stable = stable , optional = optional )
388+ monkeypatch .setattr (financial .importlib , "import_module" , lambda name : module )
389+ entry = _AxisEntry (
390+ section = "테스트" ,
391+ partId = "test" ,
392+ description = "" ,
393+ example = "" ,
394+ calcs = (
395+ _CalcEntry ("stable" , "synthetic" , "stable" , "stable" ),
396+ _CalcEntry ("optional" , "synthetic" , "optional" , "optional" ),
397+ ),
398+ )
399+
400+ result = Analysis ()._run (SimpleNamespace (), entry )
401+
402+ assert result ["assessmentStatus" ] == "partial"
403+ assert result ["calculationErrors" ] == {"optional" : "SourceAttemptsExhaustedError" }
404+ assert result ["coverage" ]["usableBlockKeys" ] == ["stable" ]
405+
406+
407+ def test_run_does_not_hide_mixed_aggregated_source_failures (monkeypatch ):
408+ """fallback 집계 안의 로컬 데이터 오류는 정상 실패로 다시 올린다."""
409+ from types import SimpleNamespace
410+
411+ import dartlab .analysis .financial as financial
412+ from dartlab .analysis .financial import Analysis
413+ from dartlab .analysis .financial ._registry import _AxisEntry , _CalcEntry
414+ from dartlab .gather .types import SourceAttemptsExhaustedError
415+
416+ def broken (company ):
417+ raise SourceAttemptsExhaustedError ("history" , [("local" , ValueError ("invalid cached row" ))])
418+
419+ module = SimpleNamespace (broken = broken )
420+ monkeypatch .setattr (financial .importlib , "import_module" , lambda name : module )
421+ entry = _AxisEntry (
422+ section = "테스트" ,
423+ partId = "test" ,
424+ description = "" ,
425+ example = "" ,
426+ calcs = (_CalcEntry ("broken" , "synthetic" , "broken" , "broken" ),),
427+ )
428+
429+ with pytest .raises (SourceAttemptsExhaustedError ):
430+ Analysis ()._run (SimpleNamespace (), entry )
0 commit comments