11# Agent Guidelines
22
3- ## 开发环境
3+ ## 安装
44
55``` bash
66git clone git@github.com:OpenWSGR/AutoWSGR.git
@@ -14,70 +14,65 @@ pre-commit install
1414``` bash
1515source .venv/bin/activate # Linux/macOS
1616# .venv\Scripts\activate # Windows
17- pytest
18- pre-commit run --all-files
1917```
2018
21- ## 代码风格
22-
23- - Python 版本:3.12+
24- - 格式化与 lint:** Ruff** (已覆盖 isort / black 功能),配置见 ` pyproject.toml `
25- - 目标行宽 100,单引号字符串
26- - 禁止相对导入(` ban-relative-imports = all ` )
27- - 英语拼写检查:** codespell** ,忽略词表见 ` docs/spelling_wordlist.txt `
28-
29- 提交前务必运行:
19+ ## pytest
3020
3121``` bash
32- pre-commit run --all-files
22+ pytest -n auto
3323```
3424
35- ## 测试
25+ 测试目录结构:
26+
27+ | 目录 | 说明 |
28+ | ------| ------|
29+ | ` tests/unit/ ` | pytest 自动运行的单元测试 |
30+ | ` tests/manual/ ` | 需真实设备的手动 e2e 测试 |
3631
37- - 单元测试:` pytest ` (测试目录 ` testing/ ` )
38- - 功能测试:运行 ` examples/ ` 目录中的脚本进行端到端验证
32+ ## pre-commit 检查
33+
34+ 提交前务必运行:
3935
4036``` bash
41- pytest
37+ pre-commit run --all-files
4238```
4339
44- ## 约定式提交(Conventional Commits)
40+ 包含 ** Ruff ** (格式化与 lint)和 ** ty ** (类型检查)。
4541
46- 提交信息格式:
42+ ## 类型检查
4743
48- ```
49- <type>(<scope>): <简短描述>
44+ 本项目使用 ** ty** (Astral 出品的 Python 类型检查器)进行静态类型检查。
5045
51- <正文>
52- ```
46+ - 优先通过正确的类型注解、返回值标注和类型窄化来消除类型错误。
47+ - ** 禁止** 在工作代码中使用 ` typing.cast ` 来掩盖类型问题;` cast ` 只允许在测试文件的 Mock 场景中使用。
48+ - 若类型检查器因容器型变(如 ` list ` 的 invariant)报错,优先考虑将函数参数改为 ` Sequence ` 、` Mapping ` 等协变抽象基类,而非使用 ` cast ` 。
49+ - 修复类型问题时尽量保持最小改动,避免不必要的重构。
5350
54- 常用类型:
51+ ### ` ty: ignore ` 注释规范
5552
56- - ` feat ` :新功能
57- - ` fix ` :修复
58- - ` build ` :构建系统或依赖变更
59- - ` docs ` :文档
60- - ` style ` :不影响代码逻辑的格式调整
61- - ` refactor ` :重构
62- - ` test ` :测试
53+ 当必须通过注释忽略类型错误时,** 必须使用 ty 原生格式** :
6354
64- 示例:
55+ ``` python
56+ # 正确
57+ c.r = 10 # ty: ignore[invalid-assignment]
58+ ctrl._device.shell.assert_called_once_with(' input tap 480 270' ) # ty: ignore[unresolved-attribute]
6559
66- ```
67- build: migrate from setuptools to hatchling
60+ # 错误 —— ty 无法识别 mypy 的 error code
61+ # type: ignore [ invalid -assignment ]
62+ # type: ignore [ misc ]
6863
69- - Replace setuptools with hatchling as build backend
70- - Remove obsolete MANIFEST.in
64+ # 错误 —— 裸 ignore 会被 ruff PGH003 拦截,且无法精确控制
65+ # type: ignore
66+ # type: ignore # noqa: PGH003
7167```
7268
73- ## 构建与打包
69+ > 项目已启用 ` unused-type-ignore-comment = "error" ` ,未使用的 ` # ty: ignore[...] ` 会导致 CI 失败。
7470
75- - Build backend:** hatchling**
76- - 包数据(图片、YAML、JAR 等)位于 ` autowsgr/data/ ` ,由 hatchling 自动包含,无需 ` MANIFEST.in `
71+ ## 单元测试要求
7772
78- ``` bash
79- uv build
80- ```
73+ 新增功能或修改核心逻辑时,必须在 ` tests/unit/ ` 下提供对应的 pytest 单元测试。测试文件应与被测源文件一一对应。
74+
75+ ## 约定式提交
8176
8277## 文档
8378
0 commit comments