fix: 存根任务三个根本问题修复

1. gap_detector: TypeError/takes no arguments也识别为stub_returns_none
   (之前只匹配assert None==和NoneType,漏掉了TypeError模式)
2. generator: 逐函数patch全失败时fallback到whole_file路径
   (之前返回None导致patches=0)
3. generator: codegen路径文件已存在时走whole_file覆盖
   (之前生成pipeline_1.py,测试跑的还是原文件)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Val-sss
2026-05-07 14:20:18 +08:00
parent 106b1d2af1
commit e4a65e5117
2 changed files with 17 additions and 10 deletions

View File

@@ -134,6 +134,13 @@ class GapDetector:
none_calls = len(re.findall(r'where None = \w+\(', output))
if none_calls >= 2:
return True
# 扩展模式TypeError: XxxClass() takes no argumentspass的__init__被调用
if 'TypeError' in output and 'takes no arguments' in output:
return True
# 扩展模式多个TypeError存根类被实例化/调用)
type_errors = len(re.findall(r'TypeError:', output))
if type_errors >= 3:
return True
return False
def _all_passed(self, output: str) -> bool:

View File

@@ -297,8 +297,9 @@ class GeneratorExpert:
explanation_parts.append(f"{fpath}:{func_name}")
if not patches:
logger.warning("Generator: no patches produced")
return None
# Fallback: 逐函数patch全失败时尝试whole_file路径
logger.warning("Generator: no patches produced, trying whole_file fallback")
return self._run_whole_file(ctx, files)
result = {
"patches": patches,
@@ -570,15 +571,14 @@ class GeneratorExpert:
import os
full_path = os.path.join(ctx.project_root, target_file)
# 防止覆盖已有文件:如果文件已存在,加数字后缀
# 如果文件已存在走whole_file覆盖不生成_1.py
if os.path.exists(full_path):
base, ext = os.path.splitext(target_file)
for i in range(1, 100):
candidate = f"{base}_{i}{ext}"
if not os.path.exists(os.path.join(ctx.project_root, candidate)):
target_file = candidate
full_path = os.path.join(ctx.project_root, candidate)
break
result = {
"patches": [{"file": target_file, "content": code, "write_mode": "whole_file"}],
"explanation": f"已覆盖:{target_file}",
}
ctx.generator_output = result
return result
result = {
"patches": [{"file": target_file, "original": "", "modified": code}],