Skip to content

Commit b1c07c3

Browse files
committed
feat: 发布 v0.2.0,完成 Interactor 验证逻辑与代码质量提升
- 完成 Interactor 完整验证逻辑,实现真实的交互测试 - 添加 compiler.py 单元测试(14 个测试用例) - 创建平台工具模块 platform.py,消除 exe_ext 判断的代码重复 - 拆分 StressTestRunTool.execute 函数,提高代码可读性 - 测试代码覆盖从约 50-60% 提升至 80%+ - 消除 10 处 exe_ext 重复代码 - 通过工具函数封装提高可维护性 - 将平台相关逻辑集中到 platform.py 模块 - 重构过长函数,拆分为更小的辅助方法 - 更新类型注解和导入声明 - 添加 TROUBLESHOOTING.md 故障排除指南
1 parent fb478f1 commit b1c07c3

File tree

13 files changed

+839
-54
lines changed

13 files changed

+839
-54
lines changed

CHANGELOG.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.0] - 2026-03-31
9+
10+
### Features
11+
12+
- 完成 Interactor 完整验证逻辑,实现真实的交互测试
13+
- 添加 compiler.py 单元测试(14 个测试用例)
14+
- 创建平台工具模块 `platform.py`,消除 `exe_ext` 判断的代码重复
15+
- 拆分 `StressTestRunTool.execute` 函数,提高代码可读性
16+
17+
### Improvements
18+
19+
- 测试代码覆盖从约 50-60% 提升至 80%+
20+
- 消除 10 处 `exe_ext` 重复代码
21+
- 通过工具函数封装提高可维护性
22+
23+
### Code Quality
24+
25+
- 将平台相关逻辑集中到 `platform.py` 模块
26+
- 重构过长函数,拆分为更小的辅助方法
27+
- 更新类型注解和导入声明
28+
29+
### Breaking Changes
30+
31+
-
32+
833
## [0.1.0] - 2025-03-30
934

1035
### Features
@@ -31,6 +56,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3156

3257
### Notes & Caveats
3358

34-
- Interactor 工具的交互测试逻辑尚未完全实现(有 TODO 标记)
3559
- Windows 平台不支持内存限制(ulimit)
36-
- 需要 g++ 编译器支持 C++2C 标准
60+
- 需要 g++ 编译器支持 C++2c 标准

TROUBLESHOOTING.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# 故障排查指南
2+
3+
本文档提供 AutoCode MCP Server 的常见问题和解决方案。
4+
5+
## 编译问题
6+
7+
### C++ 编译器未找到
8+
9+
**错误信息:**
10+
```
11+
Compiler not found: g++
12+
Compilation failed with error
13+
```
14+
15+
**解决方案:**
16+
17+
1. Windows 平台:
18+
- 安装 [MinGW-w64](https://www.mingw-w64.org/)
19+
- 或安装 [MSYS2](https://www.msys2.org/)
20+
- 确保 `g++` 在 PATH 中
21+
22+
2. Linux/macOS:
23+
- 安装 `g++``sudo apt install g++``brew install gcc`
24+
25+
3. 验证安装:
26+
```bash
27+
g++ --version
28+
```
29+
30+
### C++2c 标准不支持
31+
32+
**错误信息:**
33+
```
34+
error: 'c++2c' is not a valid standard
35+
```
36+
37+
**解决方案:**
38+
39+
1. 升级到 GCC 14+:
40+
```bash
41+
gcc --version # 需要 14.0 或更高
42+
```
43+
44+
2. 或降级到 C++20:
45+
- 修改 `compiler.py` 中的 `std` 参数默认值
46+
47+
### 编译超时
48+
49+
**错误信息:**
50+
```
51+
Compilation timeout after 30s
52+
```
53+
54+
**解决方案:**
55+
56+
1. 检查代码复杂度,可能有模板递归展开
57+
2. 增加 `compile_cpp()``timeout` 参数
58+
3. 检查是否有头文件循环依赖
59+
60+
## 执行问题
61+
62+
### 二进制文件未找到
63+
64+
**错误信息:**
65+
```
66+
Binary not found: /path/to/binary
67+
```
68+
69+
**解决方案:**
70+
71+
1. 确保已运行 `*_build` 工具
72+
2. 检查文件扩展名:
73+
- Windows:需要 `.exe`
74+
- Linux/macOS:无扩展名
75+
3. 验证编译是否成功(检查 `compile_result.success`
76+
77+
### 执行超时 (TLE)
78+
79+
**错误信息:**
80+
```
81+
Execution timeout after 30s
82+
```
83+
84+
**解决方案:**
85+
86+
1. 增加超时时间
87+
2. 优化算法复杂度
88+
3. 检查是否有死循环或低效代码
89+
90+
### 内存限制错误(仅 Linux)
91+
92+
**错误信息:**
93+
```
94+
Binary not found or prlimit unavailable
95+
```
96+
97+
**解决方案:**
98+
99+
1. 安装 `prlimit`
100+
```bash
101+
sudo apt install util-linux
102+
```
103+
2. Windows 平台内存限制不支持,仅依赖超时控制
104+
105+
## 测试问题
106+
107+
### stress_test 失败
108+
109+
**可能原因:**
110+
111+
1. **Generator 失败**:检查 `gen.cpp` 生成逻辑
112+
2. **sol 失败**:检查 `sol.cpp` 代码正确性
113+
3. **brute 失败**:检查 `brute.cpp` 代码正确性
114+
4. **Validator 失败**:检查 `val.cpp` 验证逻辑
115+
116+
**调试步骤:**
117+
118+
1. 运行单轮测试(设置 `trials=1`
119+
2. 检查失败的输入数据
120+
3. 比较 `sol``brute` 的输出差异
121+
122+
### Validator 验证不一致
123+
124+
**症状:**
125+
- 预期 `expected_valid=True`,但实际返回非零退出码
126+
- 或相反情况
127+
128+
**解决方案:**
129+
130+
1. 检查 Validator 使用 `quitf(_ok, ...)``quitf(_wa, ...)`
131+
2. 确保退出码正确:
132+
- `_ok` → exit 0
133+
- `_wa` 或其他 → exit 非 0
134+
135+
## 平台特定问题
136+
137+
### Windows 路径问题
138+
139+
**症状:**
140+
```
141+
OSError: [WinError 32] The process cannot access the file
142+
```
143+
144+
**解决方案:**
145+
146+
1. 确保路径使用正斜杠 `/` 或双反斜杠 `\\`
147+
2. 避免使用保留名称(如 `con`, `prn`, `aux`
148+
3. 检查文件是否被其他进程占用
149+
150+
### Windows 文件权限问题
151+
152+
**错误信息:**
153+
```
154+
PermissionError: [Errno 13] Permission denied
155+
```
156+
157+
**解决方案:**
158+
159+
1. 关闭可能占用文件的程序
160+
2. 以管理员身份运行
161+
3. 检查文件是否设置为只读
162+
163+
## 性能优化
164+
165+
### 测试生成缓慢
166+
167+
**优化建议:**
168+
169+
1. 使用 `test_count` 参数限制测试数量
170+
2. 调整 `max_attempts` 系数(默认 `test_count * 10`
171+
3. 优化 `gen.cpp` 生成算法复杂度
172+
173+
### 对拍测试缓慢
174+
175+
**优化建议:**
176+
177+
1. 减小 `n_max` 参数(默认 100)
178+
2. 减少 `trials` 轮数
179+
3. 优化 `brute.cpp` 暴力解法复杂度
180+
181+
## MCP Server 问题
182+
183+
### 无法连接 Server
184+
185+
**检查清单:**
186+
187+
1. 确认 `autocode-mcp` 命令可执行
188+
2. 检查 MCP 客户端配置
189+
3. 验证 Python 虚拟环境已激活
190+
191+
### 工具调用失败
192+
193+
**调试步骤:**
194+
195+
1. 查看 Server 日志的完整错误信息
196+
2. 验证 `input_schema` 参数是否正确
197+
3. 检查 `problem_dir` 路径是否存在且有写权限
198+
199+
## 获取帮助
200+
201+
如果遇到未在本文档中列出的问题:
202+
203+
1. 查看测试用例:`tests/` 目录
204+
2. 检查工具文档:`src/autocode_mcp/tools/` 源代码注释
205+
3. 运行测试验证环境:`pytest tests/ -v`
206+
4. 提交 Issue:[GitHub Issues](https://github.com/your-repo/issues)

src/autocode_mcp/tools/checker.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
基于论文 Algorithm 3: BUILDCHECKER 实现。
55
"""
66
import os
7-
import sys
87

98
from ..utils.compiler import compile_cpp, run_binary_with_args
9+
from ..utils.platform import get_exe_extension
1010
from .base import Tool, ToolResult
1111

1212

@@ -89,8 +89,7 @@ async def execute(
8989
return ToolResult.fail(f"Failed to save code: {str(e)}")
9090

9191
# 编译
92-
exe_ext = ".exe" if sys.platform == "win32" else ""
93-
binary_path = os.path.join(problem_dir, f"checker{exe_ext}")
92+
binary_path = os.path.join(problem_dir, f"checker{get_exe_extension()}")
9493

9594
compile_result = await compile_cpp(source_path, binary_path, compiler=compiler)
9695

src/autocode_mcp/tools/generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"""
66
import hashlib
77
import os
8-
import sys
98

109
from ..utils.compiler import compile_cpp, run_binary, run_binary_with_args
10+
from ..utils.platform import get_exe_extension
1111
from .base import Tool, ToolResult
1212

1313

@@ -65,7 +65,7 @@ async def execute(
6565
except Exception as e:
6666
return ToolResult.fail(f"Failed to save code: {str(e)}")
6767

68-
exe_ext = ".exe" if sys.platform == "win32" else ""
68+
exe_ext = get_exe_extension()
6969
binary_path = os.path.join(problem_dir, f"gen{exe_ext}")
7070

7171
compile_result = await compile_cpp(source_path, binary_path, compiler=compiler)
@@ -154,7 +154,7 @@ async def execute(
154154
t_max: int = 1,
155155
) -> ToolResult:
156156
"""执行数据生成。"""
157-
exe_ext = ".exe" if sys.platform == "win32" else ""
157+
exe_ext = get_exe_extension()
158158

159159
# 检查 generator
160160
gen_exe = os.path.join(problem_dir, f"gen{exe_ext}")

0 commit comments

Comments
 (0)