Skip to content

Commit cbc0e6a

Browse files
SummerOneTwoclaude
andcommitted
fix: 修复产品化缺口和文档问题
- 修复 README 中目录名错误 (autocode-mcp → AutoCode) - 添加 CI 打包产物 smoke test,验证 wheel 安装后 console script 正常工作 - 增强安全边界说明,明确 file_read/file_save 的访问控制行为 - 添加测试分层文档 (tests/README.md),明确 L1-L4 测试职责 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7661e52 commit cbc0e6a

6 files changed

Lines changed: 382 additions & 15 deletions

File tree

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,35 @@ jobs:
6666
enable-cache: true
6767
- run: uv sync --all-extras
6868
- run: uv run pytest tests/ -v -m "integration"
69+
70+
# 打包产物 smoke test - 验证 wheel 安装后 console script 正常工作
71+
test-packaging:
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@v4
75+
- uses: actions/setup-python@v5
76+
with:
77+
python-version: "3.10"
78+
- uses: astral-sh/setup-uv@v4
79+
with:
80+
enable-cache: true
81+
- name: Build wheel
82+
run: |
83+
uv sync --all-extras
84+
uv build
85+
- name: Install from wheel
86+
run: |
87+
# 创建临时虚拟环境进行安装测试
88+
python -m venv /tmp/test-venv
89+
source /tmp/test-venv/bin/activate
90+
pip install dist/autocode_mcp-*.whl
91+
- name: Run packaging smoke tests
92+
run: |
93+
source /tmp/test-venv/bin/activate
94+
pytest tests/test_packaging_smoke.py -v -m "packaging"
95+
- name: Verify console script
96+
run: |
97+
source /tmp/test-venv/bin/activate
98+
autocode-mcp --help || true # --help 可能返回非 0,但命令应该存在
99+
# 验证 MCP 握手
100+
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | timeout 5 autocode-mcp | head -1

README.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ uv tool install autocode-mcp
4040

4141
```bash
4242
git clone https://github.com/SummerOneTwo/AutoCode.git
43-
cd autocode-mcp
43+
cd AutoCode
4444
uv sync
4545
```
4646

@@ -454,12 +454,39 @@ problem_pack_polygon(
454454

455455
⚠️ **Important: This tool is designed for local trusted environments only**
456456

457-
- **File Operations**: `file_read` and `file_save` can read/write arbitrary paths (use `problem_dir` parameter to limit scope)
458-
- **Code Execution**: Compiles and executes AI-generated C++ code with only time/memory limits, no sandbox isolation
459-
- **Use Cases**: Local development, competitive programming problem creation, AI-assisted coding in trusted environments
460-
- **Not Suitable For**: Multi-tenant environments, untrusted code execution, production-grade code execution platforms
457+
#### File Operations
461458

462-
For stronger isolation, run inside a container or virtual machine.
459+
- **With `problem_dir` parameter**: `file_read` and `file_save` restrict access to paths within the specified directory
460+
- **Without `problem_dir` parameter**: These tools can read/write **any arbitrary path** on the filesystem
461+
- **Recommendation**: Always specify `problem_dir` when calling file operations to limit scope
462+
463+
#### Code Execution
464+
465+
- Compiles and executes AI-generated C++ code with only time/memory limits
466+
- No sandbox isolation (uses `prlimit` on Linux for memory limits only)
467+
- **Risk**: Malformed or malicious code could potentially affect the system
468+
469+
#### Use Cases
470+
471+
**Suitable For**:
472+
- Local development machines
473+
- Competitive programming problem creation
474+
- AI-assisted coding in trusted environments
475+
- Personal workstations with regular backups
476+
477+
**Not Suitable For**:
478+
- Multi-tenant environments
479+
- Untrusted code execution
480+
- Production-grade code execution platforms
481+
- Shared servers without isolation
482+
483+
#### Mitigation Strategies
484+
485+
For stronger isolation, consider:
486+
- Running inside a Docker container
487+
- Using a virtual machine
488+
- Restricting filesystem permissions at the OS level
489+
- Running as a non-privileged user
463490

464491
### Generation Strategies
465492

@@ -498,7 +525,7 @@ problems/your-problem/
498525

499526
```bash
500527
git clone https://github.com/SummerOneTwo/AutoCode.git
501-
cd autocode-mcp
528+
cd AutoCode
502529
uv sync
503530
```
504531

README_CN.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ uv tool install autocode-mcp
4040

4141
```bash
4242
git clone https://github.com/SummerOneTwo/AutoCode.git
43-
cd autocode-mcp
43+
cd AutoCode
4444
uv sync
4545
```
4646

@@ -454,12 +454,39 @@ problem_pack_polygon(
454454

455455
⚠️ **重要提示:本工具仅适用于本地可信环境**
456456

457-
- **文件操作**`file_read``file_save` 可读写任意路径(需显式指定 `problem_dir` 参数限制范围)
458-
- **代码执行**:编译并执行 AI 生成的 C++ 代码,仅提供时间/内存限制,无沙箱隔离
459-
- **适用场景**:本地开发、竞赛编程出题、可信环境下的 AI 辅助编程
460-
- **不适用场景**:多租户环境、不可信代码执行、生产级代码运行平台
457+
#### 文件操作
461458

462-
如需更强的安全隔离,建议在容器或虚拟机中运行。
459+
- **指定 `problem_dir` 参数时**`file_read``file_save` 限制在指定目录内访问
460+
- **不指定 `problem_dir` 参数时**:这些工具可以读写**任意路径**的文件
461+
- **建议**:调用文件操作时始终指定 `problem_dir` 以限制访问范围
462+
463+
#### 代码执行
464+
465+
- 编译并执行 AI 生成的 C++ 代码,仅提供时间/内存限制
466+
- 无沙箱隔离(Linux 上仅通过 `prlimit` 限制内存)
467+
- **风险**:畸形或恶意代码可能影响系统
468+
469+
#### 适用场景
470+
471+
**适用于**
472+
- 本地开发机器
473+
- 竞赛编程出题
474+
- 可信环境下的 AI 辅助编程
475+
- 有定期备份的个人工作站
476+
477+
**不适用于**
478+
- 多租户环境
479+
- 不可信代码执行
480+
- 生产级代码运行平台
481+
- 无隔离的共享服务器
482+
483+
#### 安全加固建议
484+
485+
如需更强的安全隔离,建议:
486+
- 在 Docker 容器中运行
487+
- 使用虚拟机
488+
- 在操作系统层面限制文件系统权限
489+
- 以非特权用户身份运行
463490

464491
### 生成策略
465492

@@ -498,7 +525,7 @@ problems/your-problem/
498525

499526
```bash
500527
git clone https://github.com/SummerOneTwo/AutoCode.git
501-
cd autocode-mcp
528+
cd AutoCode
502529
uv sync
503530
```
504531

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ artifacts = ["src/autocode_mcp/templates"]
3535
[tool.pytest.ini_options]
3636
asyncio_mode = "auto"
3737
testpaths = ["tests"]
38-
markers = ["integration: marks tests as integration tests (deselect with '-m \"not integration\"')"]
38+
markers = [
39+
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
40+
"packaging: marks tests as packaging smoke tests (run after uv build)",
41+
]
3942

4043
[tool.ruff]
4144
line-length = 100

tests/README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# 测试分层说明
2+
3+
本项目采用分层测试策略,确保从单元到端到端的全面覆盖。
4+
5+
## 测试层级
6+
7+
```
8+
┌─────────────────────────────────────────────────────────────┐
9+
│ L4: 打包产物测试 │
10+
│ test_packaging_smoke.py │
11+
│ 验证 wheel 安装后 console script 正常工作 │
12+
│ 运行时机:uv build 后,在独立虚拟环境中 │
13+
├─────────────────────────────────────────────────────────────┤
14+
│ L3: 端到端 MCP 测试 │
15+
│ test_e2e_mcp.py │
16+
│ 通过 stdio 启动真实 MCP Server 进程,验证协议兼容性 │
17+
│ 运行时机:CI 常规测试(源码环境) │
18+
├─────────────────────────────────────────────────────────────┤
19+
│ L2: 集成测试 │
20+
│ test_server.py, test_compiler.py, test_*.py │
21+
│ 测试模块间交互、工具链集成 │
22+
│ 运行时机:CI 常规测试 │
23+
├─────────────────────────────────────────────────────────────┤
24+
│ L1: 单元测试 │
25+
│ test_prompts.py, test_resources.py, test_cache.py │
26+
│ 测试独立函数和类的行为 │
27+
│ 运行时机:CI 常规测试 │
28+
└─────────────────────────────────────────────────────────────┘
29+
```
30+
31+
## 测试文件职责
32+
33+
### L1: 单元测试
34+
35+
| 文件 | 职责 |
36+
|------|------|
37+
| `test_prompts.py` | 测试 prompt 模板生成 |
38+
| `test_resources.py` | 测试资源访问 |
39+
| `test_cache.py` | 测试编译缓存 |
40+
| `test_mixins.py` | 测试工具 mixin 行为 |
41+
| `test_resource_limit.py` | 测试资源限制工具 |
42+
| `test_win_job.py` | 测试 Windows Job Object |
43+
44+
### L2: 集成测试
45+
46+
| 文件 | 职责 |
47+
|------|------|
48+
| `test_server.py` | 测试 MCP Server 工具注册和调用 |
49+
| `test_compiler.py` | 测试 C++ 编译器集成 |
50+
| `test_packaging.py` | 测试打包配置、模板访问、MCP 类型 |
51+
52+
### L3: 端到端 MCP 测试
53+
54+
| 文件 | 职责 |
55+
|------|------|
56+
| `test_e2e_mcp.py` | 真实 MCP 协议握手和工具调用 |
57+
58+
### L4: 打包产物测试
59+
60+
| 文件 | 职责 |
61+
|------|------|
62+
| `test_packaging_smoke.py` | 验证 wheel 安装后 console script |
63+
64+
## CI 测试流程
65+
66+
```yaml
67+
# 1. 单元测试 + 集成测试(多 Python 版本)
68+
test-unit:
69+
- uv run pytest tests/ -v -m "not integration"
70+
71+
# 2. 集成测试(标记为 integration)
72+
test-integration:
73+
- uv run pytest tests/ -v -m "integration"
74+
75+
# 3. 打包产物测试(uv build 后)
76+
test-packaging:
77+
- uv build
78+
- pip install dist/*.whl
79+
- pytest tests/test_packaging_smoke.py -v -m "packaging"
80+
```
81+
82+
## 测试标记
83+
84+
| 标记 | 用途 | 示例 |
85+
|------|------|------|
86+
| `@pytest.mark.integration` | 集成测试 | 需要 g++ 或外部依赖 |
87+
| `@pytest.mark.packaging` | 打包测试 | 需要从 wheel 安装 |
88+
89+
## 运行测试
90+
91+
```bash
92+
# 运行所有单元测试和集成测试
93+
uv run pytest tests/ -v
94+
95+
# 只运行单元测试
96+
uv run pytest tests/ -v -m "not integration"
97+
98+
# 只运行集成测试
99+
uv run pytest tests/ -v -m "integration"
100+
101+
# 运行端到端 MCP 测试
102+
uv run pytest tests/test_e2e_mcp.py -v
103+
104+
# 运行打包产物测试(需要先安装 wheel)
105+
pytest tests/test_packaging_smoke.py -v -m "packaging"
106+
```
107+
108+
## 测试覆盖目标
109+
110+
- **L1 单元测试**: 覆盖核心逻辑,快速反馈
111+
- **L2 集成测试**: 覆盖模块交互,验证工具链
112+
- **L3 端到端测试**: 覆盖 MCP 协议兼容性
113+
- **L4 打包测试**: 覆盖发布产物可用性

0 commit comments

Comments
 (0)