feat(analysis): prevent pipeline crash on single file analysis failure
Catch Gemini API errors (e.g., HTTP 429) and summarize upstream messages Generate fallback markdown for failed files instead of aborting Append analysis failures to pipeline warnings
This commit is contained in:
@@ -14,7 +14,7 @@ fake_dotenv.load_dotenv = lambda *args, **kwargs: None
|
||||
sys.modules.setdefault("dotenv", fake_dotenv)
|
||||
|
||||
from uipath_explainator.config import Settings
|
||||
from uipath_explainator.gemini import GeminiAnalyzer
|
||||
from uipath_explainator.gemini import AnalysisError, GeminiAnalyzer
|
||||
|
||||
|
||||
class FakeHttpOptions:
|
||||
@@ -159,6 +159,33 @@ class GeminiAnalyzerTests(unittest.TestCase):
|
||||
self.assertIn("先讲这个文件在整个流程中的定位", prompt)
|
||||
self.assertIn("判断逻辑、调用链、输入输出、关键变量、外部依赖", prompt)
|
||||
|
||||
def test_analyze_wraps_rate_limit_error_with_clear_message(self) -> None:
|
||||
fake_types = SimpleNamespace(
|
||||
HttpOptions=FakeHttpOptions,
|
||||
GenerateContentConfig=FakeGenerateContentConfig,
|
||||
)
|
||||
fake_genai = ModuleType("google.genai")
|
||||
fake_genai.Client = FakeClient
|
||||
fake_genai.types = fake_types
|
||||
|
||||
fake_google = ModuleType("google")
|
||||
fake_google.genai = fake_genai
|
||||
|
||||
with patch.dict(sys.modules, {"google": fake_google, "google.genai": fake_genai}):
|
||||
analyzer = GeminiAnalyzer(Settings(api_key="test-key", base_url=None, model="gemini-test"))
|
||||
|
||||
error = RuntimeError("quota exceeded")
|
||||
error.status_code = 429
|
||||
error.response_json = {"error": {"message": "Resource has been exhausted (e.g. check quota)."}}
|
||||
analyzer._client.models.generate_content = lambda **_: (_ for _ in ()).throw(error)
|
||||
|
||||
with self.assertRaises(AnalysisError) as captured:
|
||||
analyzer.analyze(Path("main.xaml"), "<Sequence />")
|
||||
|
||||
self.assertIn("HTTP 429", str(captured.exception))
|
||||
self.assertIn("Resource has been exhausted", str(captured.exception))
|
||||
self.assertIn("--skip-analysis", str(captured.exception))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user