@@ -290,3 +290,103 @@ async def test_checker_fail_verdict():
290290 test_results = result .structuredContent .get ("test_results" , [])
291291 if test_results :
292292 assert test_results [0 ].get ("actual_verdict" ) == "FAIL"
293+
294+
295+ # ============== source_path 参数测试 ==============
296+
297+
298+ @pytest .mark .asyncio
299+ async def test_solution_build_source_path ():
300+ """测试 solution_build 使用 source_path 参数。"""
301+ from autocode_mcp .server import call_tool , register_all_tools
302+
303+ register_all_tools ()
304+
305+ import tempfile
306+
307+ with tempfile .TemporaryDirectory () as tmpdir :
308+ os .makedirs (os .path .join (tmpdir , "solutions" ))
309+ source_file = os .path .join (tmpdir , "solutions" , "sol.cpp" )
310+ with open (source_file , "w" , encoding = "utf-8" ) as f :
311+ f .write ('#include <iostream>\n int main() { std::cout << 42; return 0; }' )
312+
313+ result = await call_tool (
314+ "solution_build" ,
315+ {"problem_dir" : tmpdir , "solution_type" : "sol" , "source_path" : source_file },
316+ )
317+ assert result .isError is False
318+
319+
320+ @pytest .mark .asyncio
321+ async def test_solution_build_source_path_not_found ():
322+ """测试 source_path 文件不存在时报错。"""
323+ from autocode_mcp .server import call_tool , register_all_tools
324+
325+ register_all_tools ()
326+
327+ import tempfile
328+
329+ with tempfile .TemporaryDirectory () as tmpdir :
330+ result = await call_tool (
331+ "solution_build" ,
332+ {
333+ "problem_dir" : tmpdir ,
334+ "solution_type" : "sol" ,
335+ "source_path" : os .path .join (tmpdir , "nonexistent.cpp" ),
336+ },
337+ )
338+ assert result .isError is True
339+ assert "not found" in result .structuredContent .get ("error" , "" ).lower ()
340+
341+
342+ @pytest .mark .asyncio
343+ async def test_solution_build_neither_code_nor_source_path ():
344+ """测试既不提供 code 也不提供 source_path 时报错。"""
345+ from autocode_mcp .server import call_tool , register_all_tools
346+
347+ register_all_tools ()
348+
349+ import tempfile
350+
351+ with tempfile .TemporaryDirectory () as tmpdir :
352+ result = await call_tool (
353+ "solution_build" ,
354+ {"problem_dir" : tmpdir , "solution_type" : "sol" },
355+ )
356+ assert result .isError is True
357+ error = result .structuredContent .get ("error" , "" ).lower ()
358+ assert "either" in error or "must be provided" in error
359+
360+
361+ # ============== stress_test 错误诊断测试 ==============
362+
363+
364+ @pytest .mark .asyncio
365+ async def test_stress_test_generator_timeout_hint ():
366+ """测试 generator 超时时返回特定提示和数据字段。"""
367+ from autocode_mcp .server import call_tool , register_all_tools
368+
369+ register_all_tools ()
370+
371+ import tempfile
372+
373+ with tempfile .TemporaryDirectory () as tmpdir :
374+ os .makedirs (os .path .join (tmpdir , "files" ))
375+ os .makedirs (os .path .join (tmpdir , "solutions" ))
376+
377+ gen_code = '#include "testlib.h"\n int main(int argc, char* argv[]) { while(true); return 0; }'
378+ gen_result = await call_tool ("generator_build" , {"problem_dir" : tmpdir , "code" : gen_code })
379+ if gen_result .isError :
380+ pytest .skip ("Generator compilation failed (g++ not available)" )
381+
382+ simple_code = '#include <iostream>\n int main() { int x; std::cin >> x; std::cout << x; return 0; }'
383+ await call_tool ("solution_build" , {"problem_dir" : tmpdir , "solution_type" : "sol" , "code" : simple_code })
384+ await call_tool ("solution_build" , {"problem_dir" : tmpdir , "solution_type" : "brute" , "code" : simple_code })
385+
386+ result = await call_tool ("stress_test_run" , {"problem_dir" : tmpdir , "trials" : 1 , "timeout" : 2 })
387+ assert result .isError is True
388+ error_msg = result .structuredContent .get ("error" , "" ).lower ()
389+ assert "generator failed" in error_msg
390+ data = result .structuredContent .get ("data" , {})
391+ assert "seed" in data
392+ assert "cmd_args" in data
0 commit comments