2323from autocode_mcp .utils .platform import get_exe_extension
2424
2525
26+ def write_verified_workflow_state (problem_dir : str ) -> None :
27+ workflow_dir = os .path .join (problem_dir , ".autocode-workflow" )
28+ os .makedirs (workflow_dir , exist_ok = True )
29+ with open (os .path .join (workflow_dir , "state.json" ), "w" , encoding = "utf-8" ) as f :
30+ json .dump (
31+ {
32+ "tests_verified" : True ,
33+ "verify_signals" : {
34+ "limit_semantics" : {"executed" : True , "passed" : True },
35+ "wrong_solution_kill" : {"executed" : True , "passed" : True },
36+ "validator_check" : {"executed" : True , "passed" : True },
37+ },
38+ },
39+ f ,
40+ )
41+
42+
2643@pytest .mark .asyncio
2744async def test_problem_create ():
2845 """测试题目目录创建。"""
@@ -87,6 +104,7 @@ async def test_problem_pack_polygon():
87104 f .write ("1\n " )
88105 with open (os .path .join (problem_dir , "tests" , "01.ans" ), "w" , encoding = "utf-8" ) as f :
89106 f .write ("1\n " )
107+ write_verified_workflow_state (problem_dir )
90108
91109 # 打包
92110 result = await pack_tool .execute (problem_dir = problem_dir )
@@ -113,6 +131,7 @@ async def test_problem_pack_polygon_creates_xml():
113131 f .write ("1\n " )
114132 with open (os .path .join (problem_dir , "tests" , "01.ans" ), "w" , encoding = "utf-8" ) as f :
115133 f .write ("1\n " )
134+ write_verified_workflow_state (problem_dir )
116135
117136 result = await tool .execute (
118137 problem_dir = problem_dir ,
@@ -926,6 +945,7 @@ async def test_problem_pack_polygon_dynamic_test_count():
926945 f .write (f"answer { i } \n " )
927946 with open (os .path .join (problem_dir , "sol.cpp" ), "w" , encoding = "utf-8" ) as f :
928947 f .write ("// sol\n " )
948+ write_verified_workflow_state (problem_dir )
929949
930950 await pack_tool .execute (problem_dir = problem_dir )
931951
@@ -955,6 +975,7 @@ async def test_problem_pack_polygon_sanitizes_answer_ext_from_manifest():
955975 json .dump ({"answer_ext" : ".bad<ext>" }, f )
956976 with open (os .path .join (problem_dir , "sol.cpp" ), "w" , encoding = "utf-8" ) as f :
957977 f .write ("// sol\n " )
978+ write_verified_workflow_state (problem_dir )
958979
959980 result = await pack_tool .execute (problem_dir = problem_dir )
960981 assert result .success
@@ -1011,6 +1032,27 @@ async def test_problem_pack_polygon_fails_when_workflow_state_unverified():
10111032 assert "run problem_verify_tests first" in result .error
10121033
10131034
1035+ @pytest .mark .asyncio
1036+ async def test_problem_pack_polygon_fails_when_workflow_state_missing ():
1037+ tool = ProblemPackPolygonTool ()
1038+ with tempfile .TemporaryDirectory () as tmpdir :
1039+ problem_dir = os .path .join (tmpdir , "pack_state_missing" )
1040+ os .makedirs (os .path .join (problem_dir , "tests" ), exist_ok = True )
1041+ os .makedirs (os .path .join (problem_dir , "statements" ), exist_ok = True )
1042+ os .makedirs (os .path .join (problem_dir , "solutions" ), exist_ok = True )
1043+ with open (os .path .join (problem_dir , "tests" , "01.in" ), "w" , encoding = "utf-8" ) as f :
1044+ f .write ("1\n " )
1045+ with open (os .path .join (problem_dir , "tests" , "01.ans" ), "w" , encoding = "utf-8" ) as f :
1046+ f .write ("1\n " )
1047+ with open (os .path .join (problem_dir , "statements" , "README.md" ), "w" , encoding = "utf-8" ) as f :
1048+ f .write ("# T\n " )
1049+ with open (os .path .join (problem_dir , "solutions" , "sol.cpp" ), "w" , encoding = "utf-8" ) as f :
1050+ f .write ("// sol\n " )
1051+ result = await tool .execute (problem_dir = problem_dir )
1052+ assert not result .success
1053+ assert "workflow state missing" in result .error
1054+
1055+
10141056@pytest .mark .asyncio
10151057async def test_problem_pack_polygon_respects_require_tests_verified_override ():
10161058 tool = ProblemPackPolygonTool ()
@@ -1029,7 +1071,18 @@ async def test_problem_pack_polygon_respects_require_tests_verified_override():
10291071 with open (os .path .join (problem_dir , "solutions" , "sol.cpp" ), "w" , encoding = "utf-8" ) as f :
10301072 f .write ("// sol\n " )
10311073 with open (os .path .join (problem_dir , "autocode.json" ), "w" , encoding = "utf-8" ) as f :
1032- json .dump ({"problem_name" : "t" , "quality_gates" : {"require_tests_verified" : False }}, f )
1074+ json .dump (
1075+ {
1076+ "problem_name" : "t" ,
1077+ "quality_gates" : {
1078+ "require_tests_verified" : False ,
1079+ "require_limit_semantics" : False ,
1080+ "require_wrong_solution_kill" : False ,
1081+ "require_validator_check" : False ,
1082+ },
1083+ },
1084+ f ,
1085+ )
10331086 with open (
10341087 os .path .join (problem_dir , ".autocode-workflow" , "state.json" ),
10351088 "w" ,
@@ -1040,6 +1093,30 @@ async def test_problem_pack_polygon_respects_require_tests_verified_override():
10401093 assert result .success
10411094
10421095
1096+ @pytest .mark .asyncio
1097+ async def test_problem_pack_polygon_fails_when_required_verify_signal_missing ():
1098+ tool = ProblemPackPolygonTool ()
1099+ with tempfile .TemporaryDirectory () as tmpdir :
1100+ problem_dir = os .path .join (tmpdir , "pack_signal_missing" )
1101+ os .makedirs (os .path .join (problem_dir , "tests" ), exist_ok = True )
1102+ os .makedirs (os .path .join (problem_dir , "statements" ), exist_ok = True )
1103+ os .makedirs (os .path .join (problem_dir , "solutions" ), exist_ok = True )
1104+ os .makedirs (os .path .join (problem_dir , ".autocode-workflow" ), exist_ok = True )
1105+ with open (os .path .join (problem_dir , "tests" , "01.in" ), "w" , encoding = "utf-8" ) as f :
1106+ f .write ("1\n " )
1107+ with open (os .path .join (problem_dir , "tests" , "01.ans" ), "w" , encoding = "utf-8" ) as f :
1108+ f .write ("1\n " )
1109+ with open (os .path .join (problem_dir , "statements" , "README.md" ), "w" , encoding = "utf-8" ) as f :
1110+ f .write ("# T\n " )
1111+ with open (os .path .join (problem_dir , "solutions" , "sol.cpp" ), "w" , encoding = "utf-8" ) as f :
1112+ f .write ("// sol\n " )
1113+ with open (os .path .join (problem_dir , ".autocode-workflow" , "state.json" ), "w" , encoding = "utf-8" ) as f :
1114+ json .dump ({"tests_verified" : True , "verify_signals" : {}}, f )
1115+ result = await tool .execute (problem_dir = problem_dir )
1116+ assert not result .success
1117+ assert "verification signal" in result .error
1118+
1119+
10431120@pytest .mark .asyncio
10441121async def test_problem_pack_polygon_enforces_min_limit_case_ratio ():
10451122 tool = ProblemPackPolygonTool ()
@@ -1070,6 +1147,7 @@ async def test_problem_pack_polygon_enforces_min_limit_case_ratio():
10701147 f .write ("# T\n " )
10711148 with open (os .path .join (problem_dir , "solutions" , "sol.cpp" ), "w" , encoding = "utf-8" ) as f :
10721149 f .write ("// sol\n " )
1150+ write_verified_workflow_state (problem_dir )
10731151 with open (
10741152 os .path .join (problem_dir , "autocode.json" ),
10751153 "w" ,
0 commit comments