Skip to content

Commit b273013

Browse files
SummerOneTwoclaude
andcommitted
feat: 实现 problem_generate_tests 后处理功能
新增功能: - 去重:基于 MD5 signature 去除重复测试数据 - Validator 过滤:自动检测 val.exe,过滤无效输入 - 平衡分布:按策略类型(tiny/random/extreme/tle)均衡采样 - 超额采样:生成候选数据后采样最终 test_count 个 新增参数: - enable_dedup: 启用去重(默认 True) - enable_validator_filter: 启用 Validator 过滤(默认 True) - enable_balance: 启用平衡分布(默认 True) - oversample_ratio: 超额采样比例(默认 1.5) 修复: - interactor_build 超时检测逻辑(命名 sleep task) - interactor_build 移除默认返回 AC 的兜底逻辑 - 中文 README 工具数量和参数 schema 更新 - README 占位链接替换 测试: - 新增 test_problem_generate_tests_dedup - 新增 test_problem_generate_tests_balance - 新增 test_problem_generate_tests_oversample - 测试数量从 142 增至 145 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4e90264 commit b273013

6 files changed

Lines changed: 392 additions & 64 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939
- **Generator 协议统一 (P1)**
4040
- `stress_test_run` 新增 `generator_args` 参数
4141
- 支持完整协议: `gen.exe <seed> <type> <n_min> <n_max> <t_min> <t_max>`
42-
- 默认保持简单协议: `gen.exe <seed>`
42+
- 默认使用完整协议(type=2 random)
4343

4444
- **Verdict 完善 (P1)**
4545
- `checker_build` 根据 testlib.h 返回码正确区分 AC/WA/PE/TLE
@@ -124,7 +124,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
124124

125125
### Features
126126

127-
- 完成 Interactor 完整验证逻辑,实现真实的交互测试
127+
- 添加 Interactor 基础验证逻辑,支持变异测试
128128
- 添加 compiler.py 单元测试(14 个测试用例)
129129
- 创建平台工具模块 `platform.py`,消除 `exe_ext` 判断的代码重复
130130
- 拆分 `StressTestRunTool.execute` 函数,提高代码可读性

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ uv tool install autocode-mcp
3939
### From Source
4040

4141
```bash
42-
git clone https://github.com/your-repo/autocode-mcp.git
42+
git clone https://github.com/SummerOneTwo/AutoCode.git
4343
cd autocode-mcp
4444
uv sync
4545
```
@@ -474,7 +474,7 @@ problems/your-problem/
474474
### Setup
475475

476476
```bash
477-
git clone https://github.com/your-repo/autocode-mcp.git
477+
git clone https://github.com/SummerOneTwo/AutoCode.git
478478
cd autocode-mcp
479479
uv sync
480480
```

README_CN.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
**基于论文《AutoCode: LLMs as Problem Setters for Competitive Programming》实现的竞赛编程出题辅助 MCP Server。**
99

10-
AutoCode MCP Server 提供 14 个原子工具,让 AI 助手能够创建、验证和测试竞赛编程题目。它负责编译、执行、压力测试和测试数据生成——让 AI 专注于题目设计和解法逻辑。
10+
AutoCode MCP Server 提供 15 个原子工具,让 AI 助手能够创建、验证和测试竞赛编程题目。它负责编译、执行、压力测试和测试数据生成——让 AI 专注于题目设计和解法逻辑。
1111

1212
[English Documentation](README.md)
1313

1414
## 特性
1515

1616
- **Validator-Generator-Checker 框架** — 基于论文实现输入正确性自动验证、多策略测试生成和输出验证
17-
- **14 个原子工具** — 文件操作、解法构建、压力测试、校验器/生成器/检查器构建等
17+
- **15 个原子工具** — 文件操作、解法构建、压力测试、校验器/生成器/检查器构建等
1818
- **testlib.h 支持** — 完整集成竞赛编程标准库,用于校验器、生成器和检查器
1919
- **多策略生成** — 四种生成策略:tiny(穷举)、random(随机)、extreme(边界情况)、tle(诱导超时)
2020
- **压力测试** — 自动比较最优解和暴力解,可配置测试轮数
@@ -39,7 +39,7 @@ uv tool install autocode-mcp
3939
### 从源码安装
4040

4141
```bash
42-
git clone https://github.com/your-repo/autocode-mcp.git
42+
git clone https://github.com/SummerOneTwo/AutoCode.git
4343
cd autocode-mcp
4444
uv sync
4545
```
@@ -189,11 +189,11 @@ stress_test_run(problem_dir="problems/ab", trials=100)
189189

190190
### 验证安装
191191

192-
配置完成后,重启 MCP 客户端并检查工具是否可用。你应该能看到 14 个以 `autocode_` 为前缀的工具。
192+
配置完成后,重启 MCP 客户端并检查工具是否可用。你应该能看到 15 个以 `autocode_` 为前缀的工具。
193193

194194
## 工具参考
195195

196-
AutoCode 提供 14 个原子工具,分为 7 组。所有工具返回统一格式:
196+
AutoCode 提供 15 个原子工具,分为 7 组。所有工具返回统一格式:
197197

198198
```json
199199
{
@@ -241,7 +241,7 @@ AutoCode 提供 14 个原子工具,分为 7 组。所有工具返回统一格
241241

242242
| 工具 | 描述 | 关键参数 |
243243
|------|------|----------|
244-
| `interactor_build` | 构建交互题的交互器 | `problem_dir`, `code`, `test_scenarios` |
244+
| `interactor_build` | 构建交互题的交互器 | `problem_dir`, `code`, `reference_solution_path`, `mutant_solutions` |
245245

246246
### 压力测试
247247

@@ -253,9 +253,9 @@ AutoCode 提供 14 个原子工具,分为 7 组。所有工具返回统一格
253253

254254
| 工具 | 描述 | 关键参数 |
255255
|------|------|----------|
256-
| `problem_create` | 初始化题目目录 | `problem_dir`, `title`, `time_limit`, `memory_limit` |
256+
| `problem_create` | 初始化题目目录 | `problem_dir`, `problem_name` |
257257
| `problem_generate_tests` | 生成最终测试数据 | `problem_dir`, `test_count` |
258-
| `problem_pack_polygon` | 打包为 Polygon 格式 | `problem_dir`, `output_dir` |
258+
| `problem_pack_polygon` | 打包为 Polygon 格式 | `problem_dir`, `time_limit`, `memory_limit` |
259259

260260
## 工作流教程:A+B 问题
261261

@@ -266,9 +266,7 @@ AutoCode 提供 14 个原子工具,分为 7 组。所有工具返回统一格
266266
```python
267267
problem_create(
268268
problem_dir="problems/ab",
269-
title="A + B",
270-
time_limit=1000,
271-
memory_limit=256
269+
problem_name="A + B"
272270
)
273271
```
274272

@@ -393,7 +391,8 @@ problem_generate_tests(
393391
```python
394392
problem_pack_polygon(
395393
problem_dir="problems/ab",
396-
output_dir="polygon/ab"
394+
time_limit=1,
395+
memory_limit=256
397396
)
398397
```
399398

@@ -475,7 +474,7 @@ problems/your-problem/
475474
### 环境搭建
476475

477476
```bash
478-
git clone https://github.com/your-repo/autocode-mcp.git
477+
git clone https://github.com/SummerOneTwo/AutoCode.git
479478
cd autocode-mcp
480479
uv sync
481480
```

src/autocode_mcp/tools/interactor.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,19 @@ async def _run_interactor_test(
214214
# 这里简化处理:让解法和交互器都运行,等待完成
215215

216216
try:
217+
# 创建通信任务和超时任务(命名以便识别)
218+
comm_task = asyncio.create_task(self._communicate(interactor, solution))
219+
sleep_task = asyncio.create_task(asyncio.sleep(timeout))
220+
sleep_task.set_name("sleep")
221+
217222
# 等待任一进程完成
218223
done, pending = await asyncio.wait(
219-
[
220-
asyncio.create_task(self._communicate(interactor, solution)),
221-
asyncio.create_task(asyncio.sleep(timeout)),
222-
],
224+
[comm_task, sleep_task],
223225
return_when=asyncio.FIRST_COMPLETED,
224226
)
225227

226-
# 检查是否超时 - asyncio.wait 返回 set,需要遍历
227-
timed_out = False
228-
comm_task = None
229-
for task in done:
230-
if task.get_name() == "sleep":
231-
timed_out = True
232-
else:
233-
comm_task = task
228+
# 检查是否超时
229+
timed_out = sleep_task in done
234230

235231
if timed_out:
236232
interactor.kill()
@@ -264,8 +260,9 @@ async def _run_interactor_test(
264260
except Exception as e:
265261
return {"verdict": "RE", "reason": str(e)}
266262

267-
# 默认返回 AC(简化处理)
268-
return {"verdict": "AC", "reason": "Test passed"}
263+
# 如果走到这里,说明通信任务没有返回有效结果
264+
# 这通常表示进程异常终止或通信失败
265+
return {"verdict": "RE", "reason": "Interactor test failed to complete"}
269266

270267
async def _communicate(
271268
self,

0 commit comments

Comments
 (0)