@@ -94,8 +94,10 @@ def load_env_file(env_file: str) -> bool:
9494 value = value .strip ()
9595
9696 # 只设置 LLM 相关的环境变量
97- if key in ["OPENAI_API_KEY" , "TRPC_AGENT_API_KEY" , "OPENAI_BASE_URL" ,
98- "TRPC_AGENT_BASE_URL" , "MODEL_NAME" , "TRPC_AGENT_MODEL_NAME" ]:
97+ if key in [
98+ "OPENAI_API_KEY" , "TRPC_AGENT_API_KEY" , "OPENAI_BASE_URL" , "TRPC_AGENT_BASE_URL" ,
99+ "MODEL_NAME" , "TRPC_AGENT_MODEL_NAME"
100+ ]:
99101 os .environ [key ] = value
100102
101103 # 验证是否成功加载 API Key
@@ -160,8 +162,7 @@ def load_fixture_diff(fixture_name: str) -> str:
160162 return f .read ()
161163
162164
163- def evaluate_fixture (fixture_name : str , expected_data : Dict [str , Any ],
164- use_llm : bool = False ) -> Dict [str , Any ]:
165+ def evaluate_fixture (fixture_name : str , expected_data : Dict [str , Any ], use_llm : bool = False ) -> Dict [str , Any ]:
165166 """评估单个fixture
166167
167168 Args:
@@ -186,11 +187,12 @@ def evaluate_fixture(fixture_name: str, expected_data: Dict[str, Any],
186187 print ("[OK] 成功加载diff文件" )
187188
188189 # 运行审查管线
189- report = run_review (diff_text = diff_text ,
190- repo = "https://github.com/test/repo" ,
191- sandbox = "fake" ,
192- dry_run = not use_llm , # llm=True 时 dry_run=False
193- llm = use_llm ) # 传递 llm 参数
190+ report = run_review (
191+ diff_text = diff_text ,
192+ repo = "https://github.com/test/repo" ,
193+ sandbox = "fake" ,
194+ dry_run = not use_llm , # llm=True 时 dry_run=False
195+ llm = use_llm ) # 传递 llm 参数
194196 mode_str = "LLM 增强" if use_llm else "基础"
195197 print (f"[OK] 完成审查({ mode_str } 模式),发现 { len (report .findings )} 个findings" )
196198
@@ -211,7 +213,6 @@ def evaluate_fixture(fixture_name: str, expected_data: Dict[str, Any],
211213
212214 # 高置信度桶(findings + warnings):正常算 TP/FP
213215 high_confidence_findings = findings_findings + warnings_findings
214- high_confidence_rule_ids = set (finding .rule_id for finding in high_confidence_findings )
215216
216217 # 所有实际检测(用于召回率计算):包含三个桶
217218 all_actual_findings = high_confidence_findings + needs_review_findings
@@ -311,48 +312,27 @@ def evaluate_fixture(fixture_name: str, expected_data: Dict[str, Any],
311312
312313 # 构造结果
313314 result = {
314- "fixture_name" :
315- fixture_name ,
316- "description" :
317- expected_data .get ("description" , "" ),
318- "expected_rule_ids" :
319- list (expected_rule_ids ),
320- "actual_rule_ids" :
321- list (actual_rule_ids ),
322- "expected_instances" :
323- expected_instances ,
324- "actual_instances" :
325- all_instances ,
326- "high_confidence_instances" :
327- high_conf_instances ,
328- "needs_review_instances" :
329- needs_review_instances ,
330- "expected_count" :
331- expected_count ,
332- "actual_count" :
333- len (all_actual_findings ),
334- "high_confidence_count" :
335- len (high_confidence_findings ),
336- "needs_review_count" :
337- len (needs_review_findings ),
338- "tp" :
339- tp ,
340- "fp" :
341- fp ,
342- "fn" :
343- fn ,
344- "precision" :
345- precision_val ,
346- "recall" :
347- recall_val ,
348- "f1" :
349- f1_val ,
350- "redaction_rate" :
351- redaction_check ["redaction_rate" ],
352- "note" :
353- expected_data .get ("note" , "" ),
354- "success" :
355- True
315+ "fixture_name" : fixture_name ,
316+ "description" : expected_data .get ("description" , "" ),
317+ "expected_rule_ids" : list (expected_rule_ids ),
318+ "actual_rule_ids" : list (actual_rule_ids ),
319+ "expected_instances" : expected_instances ,
320+ "actual_instances" : all_instances ,
321+ "high_confidence_instances" : high_conf_instances ,
322+ "needs_review_instances" : needs_review_instances ,
323+ "expected_count" : expected_count ,
324+ "actual_count" : len (all_actual_findings ),
325+ "high_confidence_count" : len (high_confidence_findings ),
326+ "needs_review_count" : len (needs_review_findings ),
327+ "tp" : tp ,
328+ "fp" : fp ,
329+ "fn" : fn ,
330+ "precision" : precision_val ,
331+ "recall" : recall_val ,
332+ "f1" : f1_val ,
333+ "redaction_rate" : redaction_check ["redaction_rate" ],
334+ "note" : expected_data .get ("note" , "" ),
335+ "success" : True
356336 }
357337
358338 # 打印结果
@@ -599,10 +579,8 @@ def main():
599579 """主函数"""
600580 # 解析命令行参数
601581 parser = argparse .ArgumentParser (description = "代码审查Agent量化评测" )
602- parser .add_argument ("--llm" , action = "store_true" ,
603- help = "启用真实 LLM 模式(默认为 dry_run 模式)" )
604- parser .add_argument ("--env-file" , type = str , default = None ,
605- help = "指定 .env 文件路径(默认自动探测)" )
582+ parser .add_argument ("--llm" , action = "store_true" , help = "启用真实 LLM 模式(默认为 dry_run 模式)" )
583+ parser .add_argument ("--env-file" , type = str , default = None , help = "指定 .env 文件路径(默认自动探测)" )
606584
607585 args = parser .parse_args ()
608586
0 commit comments