Skip to content

Commit ca9ef4a

Browse files
authored
Merge pull request #265 from vicsanity623/vicsanity623-patch-1
Update reviewer_mixins.py
2 parents 9443e1f + e5743ea commit ca9ef4a

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

src/pyob/reviewer_mixins.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ def _fix_runtime_errors(
244244
self, logs: str, entry_file: str, context_of_change: str = ""
245245
):
246246
"""Detects crashes. Handles missing packages automatically, otherwise asks AI."""
247+
248+
# --- 0. SANITIZE TARGET ---
249+
# Prevent the bot from hallucinating log headers as filenames
250+
if entry_file == "Validation Suite" or "Validation Suite" in entry_file:
251+
# Fallback to searching for a real file in the logs or use the project main
252+
found_file = getattr(self, "_find_entry_file")()
253+
entry_file = found_file if found_file else "main.js"
254+
247255
package_match = re.search(r"ModuleNotFoundError: No module named '(.*?)'", logs)
248256
if not package_match:
249257
package_match = re.search(r"ImportError: No module named '(.*?)'", logs)
@@ -312,20 +320,44 @@ def _fix_runtime_errors(
312320
except subprocess.CalledProcessError as e:
313321
logger.error(f"Failed to install {pkg} automatically: {e}")
314322

323+
# --- 1. SMART FILE IDENTIFICATION ---
324+
# Look for Python tracebacks first
315325
tb_files = re.findall(r'File "([^"]+)"', logs)
326+
327+
# NEW: Look for JavaScript/HTML filenames if Python search fails
328+
if not tb_files:
329+
tb_files = re.findall(r"([\w\-/]+\.(?:js|html|css))", logs)
330+
316331
target_file = entry_file
317332
for f in reversed(tb_files):
318-
abs_f = os.path.abspath(f)
333+
# Block the "Validation Suite" hallucination here too
334+
if "Validation Suite" in f:
335+
continue
336+
337+
abs_f = (
338+
os.path.abspath(f)
339+
if os.path.isabs(f)
340+
else os.path.join(self.target_dir, f)
341+
)
342+
319343
if (
320344
abs_f.startswith(self.target_dir)
321-
and not any(ign in abs_f for ign in IGNORE_DIRS)
345+
and not any(ign in abs_f for ign in getattr(self, "IGNORE_DIRS", []))
322346
and os.path.exists(abs_f)
323347
):
324348
target_file = abs_f
325349
break
350+
351+
# Ensure we have a valid path before proceeding
352+
if not os.path.exists(target_file):
353+
target_file = entry_file
354+
326355
rel_path = os.path.relpath(target_file, self.target_dir)
327-
with open(target_file, "r", encoding="utf-8") as f_obj:
356+
357+
# --- 2. LOAD CODE AND PROMPT ---
358+
with open(target_file, "r", encoding="utf-8", errors="ignore") as f_obj:
328359
code = f_obj.read()
360+
329361
if context_of_change:
330362
logger.info(
331363
f"Applying CONTEXT-AWARE fix for runtime crash in `{rel_path}`..."
@@ -340,8 +372,8 @@ def _fix_runtime_errors(
340372
else:
341373
logger.info(f"Applying standard fix for runtime crash in `{rel_path}`...")
342374
memory_section = (
343-
f"### Project Memory / Context:\n{self.memory}\n\n"
344-
if self.memory
375+
f"### Project Memory / Context:\n{getattr(self, 'memory', '')}\n\n"
376+
if getattr(self, "memory", None)
345377
else ""
346378
)
347379
prompt = getattr(self, "load_prompt")(
@@ -351,17 +383,21 @@ def _fix_runtime_errors(
351383
rel_path=rel_path,
352384
code=code,
353385
)
386+
387+
# --- 3. EXECUTE REPAIR ---
354388
new_code, explanation, _ = getattr(self, "get_valid_edit")(
355389
prompt, code, require_edit=True, target_filepath=target_file
356390
)
391+
357392
if new_code != code:
358393
with open(target_file, "w", encoding="utf-8") as f_out:
359394
f_out.write(new_code)
360395
logger.info(f"AI Auto-patched runtime crash in `{rel_path}`")
361396
self.session_context.append(
362397
f"Auto-fixed runtime crash in `{rel_path}`: {explanation}"
363398
)
364-
self.run_linter_fix_loop()
399+
if hasattr(self, "run_linter_fix_loop"):
400+
self.run_linter_fix_loop()
365401

366402
def check_downstream_breakages(self, target_path: str, rel_path: str) -> bool:
367403
logger.info(

0 commit comments

Comments
 (0)