Daksh C Jain commited on
Commit
9419fa5
·
1 Parent(s): 7eac194

fix: SDET mocking + assembler diagnostics + report reading

Browse files
Files changed (2) hide show
  1. src/main.py +16 -0
  2. src/providers.py +12 -4
src/main.py CHANGED
@@ -226,14 +226,30 @@ def results_assembler_node(state: AgentState):
226
  print("[*] Agent: Assembler 📊 - Building Native GitLab UX...")
227
 
228
  an_data, fin_data, test_data, dev_data = {}, {}, {}, {}
 
229
  if os.path.exists("analyze_results.json"):
230
  with open("analyze_results.json") as f: an_data = json.load(f)
 
 
 
 
231
  if os.path.exists("finops_results.json"):
232
  with open("finops_results.json") as f: fin_data = json.load(f)
 
 
 
 
233
  if os.path.exists("devops_results.json"):
234
  with open("devops_results.json") as f: dev_data = json.load(f)
 
 
 
 
235
  if os.path.exists("test_results.json"):
236
  with open("test_results.json") as f: test_data = json.load(f)
 
 
 
237
 
238
  # 1. Update MR Description
239
  summary = an_data.get("summary", "Code analyzed successfully.")
 
226
  print("[*] Agent: Assembler 📊 - Building Native GitLab UX...")
227
 
228
  an_data, fin_data, test_data, dev_data = {}, {}, {}, {}
229
+
230
  if os.path.exists("analyze_results.json"):
231
  with open("analyze_results.json") as f: an_data = json.load(f)
232
+ print(" -> ✅ Loaded analyze_results.json")
233
+ else:
234
+ print(" -> ⚠️ analyze_results.json NOT FOUND - check artifact paths")
235
+
236
  if os.path.exists("finops_results.json"):
237
  with open("finops_results.json") as f: fin_data = json.load(f)
238
+ print(" -> ✅ Loaded finops_results.json")
239
+ else:
240
+ print(" -> ⚠️ finops_results.json NOT FOUND - check artifact paths")
241
+
242
  if os.path.exists("devops_results.json"):
243
  with open("devops_results.json") as f: dev_data = json.load(f)
244
+ print(" -> ✅ Loaded devops_results.json")
245
+ else:
246
+ print(" -> ⚠️ devops_results.json NOT FOUND - check artifact paths")
247
+
248
  if os.path.exists("test_results.json"):
249
  with open("test_results.json") as f: test_data = json.load(f)
250
+ print(" -> ✅ Loaded test_results.json")
251
+ else:
252
+ print(" -> ⚠️ test_results.json NOT FOUND - check artifact paths")
253
 
254
  # 1. Update MR Description
255
  summary = an_data.get("summary", "Code analyzed successfully.")
src/providers.py CHANGED
@@ -273,11 +273,19 @@ class GeminiBrain:
273
  Analyze the code diffs carefully. If the MR introduces a new feature or core business logic (specifically Python code), generate a complete suite of Unit Tests using `pytest`.
274
 
275
  REQUIREMENTS:
276
- 1. Write robust test cases handling edge cases and mocking dependencies.
277
- 2. IMPORTANT IMPORT RULE: Your generated tests will be saved and executed from the root of the repository. You MUST infer the correct Python import paths based on the exact file paths provided in the MR DATA diffs. For example, if the MR data shows a change in `gcp_storage_handler.py` at the root, use `import gcp_storage_handler`. If it shows `src/api.py`, use `from src.api import ...`.
278
- 3. PYTEST RULES: You MUST start every single test function name with `test_` (e.g. `def test_calculate_billing()`). You MUST `import pytest` at the top of the file.
 
 
 
 
 
 
 
 
279
  4. RETURN ONLY THE RAW RUNNABLE PYTHON TEST CODE. Absolutely no markdown formatting, no tick marks, no explanations. Strictly syntactically correct Python.
280
- 5. If the MR only contains configuration changes, documentation, lockfiles, or does not warrant tests, return exactly the string: "NO_TESTS_NEEDED".
281
  """
282
  response = self.model.generate_content(prompt)
283
  text = response.text.strip('`').strip()
 
273
  Analyze the code diffs carefully. If the MR introduces a new feature or core business logic (specifically Python code), generate a complete suite of Unit Tests using `pytest`.
274
 
275
  REQUIREMENTS:
276
+ 1. MOCKING IS MANDATORY: The test environment is isolated and does NOT have cloud SDKs (google-cloud-storage, boto3, etc.) or database drivers installed. You MUST mock ALL external dependencies using `unittest.mock.patch` or `unittest.mock.MagicMock`. Never import the real module directly if it touches any cloud SDK, database, or network. Instead, use `@patch('module_name.dependency')` decorators on your test functions.
277
+ 2. SAFE IMPORT PATTERN: At the top of the file, only import `pytest`, `unittest.mock`, and the specific functions/classes under test. Do NOT import the entire module if it has SDK-level imports at module scope that will crash. Instead, use `sys.modules` patching to stub the whole dependency before importing:
278
+ ```
279
+ import sys
280
+ from unittest.mock import MagicMock
281
+ sys.modules['google.cloud'] = MagicMock()
282
+ sys.modules['google.cloud.storage'] = MagicMock()
283
+ # Then safely import the module under test
284
+ from my_module import my_function
285
+ ```
286
+ 3. PYTEST RULES: You MUST start every single test function name with `test_`. You MUST `import pytest` at the top of the file.
287
  4. RETURN ONLY THE RAW RUNNABLE PYTHON TEST CODE. Absolutely no markdown formatting, no tick marks, no explanations. Strictly syntactically correct Python.
288
+ 5. If the MR only contains configuration changes, documentation, lockfiles, Dockerfiles, CI/CD YAML, or does not have Python business logic, return exactly the string: "NO_TESTS_NEEDED".
289
  """
290
  response = self.model.generate_content(prompt)
291
  text = response.text.strip('`').strip()