llmcodegen/create-test.issue

36 lines
2.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 需求工单:完善单元测试
name: 完善单元测试
description: 当前项目的单元测试覆盖不足,需补充核心模块的测试用例,确保代码质量并便于后续迭代。
affected_files:
# 测试文件(可能需新建)
- tests/test_cli.py
- tests/test_core.py
- tests/test_checker.py
- tests/test_utils.py
- tests/test_models.py
# 核心代码文件(测试将覆盖它们,但本身无需修改)
- src/llm_codegen/cli.py
- src/llm_codegen/core.py
- src/llm_codegen/checker.py
- src/llm_codegen/utils.py
- src/llm_codegen/models.py
acceptance_criteria:
- 所有新增或修改的测试用例均通过 `pytest` 运行,无失败、错误或跳过。
- 测试覆盖率(语句覆盖率)不低于 85%,分支覆盖率不低于 70%,可通过 `pytest --cov=src/llm_codegen --cov-branch` 验证。
- 核心类 `CodeGenerator` 的以下方法被充分测试:
- `__init__`(不同参数组合)
- `_call_llm`(模拟 API 响应、超时、异常)
- `parse_readme`(正常文件、空文件、编码问题)
- `get_project_structure`(模拟 LLM 返回)
- `generate_file`(依赖文件存在/不存在)
- `execute_command`(正常执行、危险命令拦截、超时)
- `run`(完整流程的模拟)
- 并行检查模块 `checker.py` 的主要函数(如 `run_checks`、`apply_fixes`)需覆盖正常与错误场景。
- 工具函数 `is_dangerous_command` 应测试多个危险命令变体及安全命令。
- 命令行接口CLI需包含端到端测试验证 `init`、`enhance`、`fix` 子命令的基本流程(可使用 `CliRunner` 或 `subprocess` 模拟)。
- 测试应使用 `pytest` 的临时目录(`tmp_path`)和 `unittest.mock` 模拟外部依赖如文件系统、API 调用),避免污染实际环境。
- 为常用模拟操作(如模拟 OpenAI 客户端、模拟文件读写)编写可复用的 fixture。
- 测试代码遵循项目的编码规范(使用 black、isort 格式化,类型注解完整)。