@wwkit/harness 1.0.32 → 1.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +128 -128
- package/agents/scrum.md +186 -180
- package/agents/sprint.md +121 -118
- package/bin/index.js +226 -226
- package/commands/fix.md +87 -87
- package/commands/git-sync.md +217 -217
- package/commands/net-port.md +364 -364
- package/commands/pytest.md +10 -10
- package/commands/resume.md +104 -104
- package/commands/tl.md +11 -11
- package/package.json +3 -3
- package/plugin.js +19 -19
- package/readme/development.md +39 -39
- package/readme/publish.md +41 -41
- package/readme/testing.md +44 -44
- package/scripts/postinstall.js +58 -58
- package/skills/better-skill/SKILL.md +124 -124
- package/skills/blame-skill/SKILL.md +201 -201
- package/skills/extract/SKILL.md +119 -119
- package/skills/extract/references/build-xpath.js +30 -30
- package/skills/extract/references/clean-html.js +90 -90
- package/skills/extract/references/detail.md +54 -54
- package/skills/extract/references/detail.schema.json5 +48 -48
- package/skills/extract/references/extract-detail.js +71 -71
- package/skills/extract/references/extract-regex.js +81 -81
- package/skills/extract/references/extract-sample.js +48 -48
- package/skills/extract/references/list-rule-gen.md +109 -109
- package/skills/extract/references/list.md +134 -134
- package/skills/extract/references/list.schema.json5 +33 -33
- package/skills/extract/references/navi.md +44 -44
- package/skills/extract/references/navi.schema.json5 +23 -23
- package/skills/extract/references/text.md +40 -40
- package/skills/extract/references/text.schema.json5 +21 -21
- package/skills/extract/references/to-text.js +20 -20
- package/skills/extract/references/validate-schema.js +39 -39
- package/skills/jstest/SKILL.md +561 -561
- package/skills/jstest/references/case-create.md +327 -327
- package/skills/jstest/references/case-fix.md +273 -273
- package/skills/jstest/references/config.md +148 -148
- package/skills/jstest/references/coverage-analyze.md +247 -247
- package/skills/jstest/references/env-ensure.md +210 -210
- package/skills/jstest/references/execute.md +168 -168
- package/skills/jstest/references/sample.md +166 -166
- package/skills/jstest/references/scoring-rules.md +75 -75
- package/skills/jstest/references/src/jstest-sample/Calculator.js +80 -80
- package/skills/jstest/references/src/jstest-sample/ConfigManager.js +72 -72
- package/skills/jstest/references/src/jstest-sample/FileProcessor.js +57 -57
- package/skills/jstest/references/src/jstest-sample/OrderService.js +98 -98
- package/skills/jstest/references/src/jstest-sample/TokenGenerator.js +60 -60
- package/skills/jstest/references/src/jstest-sample/UserService.js +56 -56
- package/skills/jstest/references/src/jstest-sample/index.js +6 -6
- package/skills/jstest/references/suitability-check.md +232 -232
- package/skills/jstest/references/test-standards.md +288 -288
- package/skills/lint/SKILL.md +440 -440
- package/skills/lint/references/ai-fix.md +137 -137
- package/skills/lint/references/config-setup.md +102 -102
- package/skills/lint/references/config.md +65 -65
- package/skills/lint/references/detect-language.js +65 -65
- package/skills/lint/references/env-ensure.md +88 -88
- package/skills/lint/references/language-detect.md +75 -75
- package/skills/lint/references/languages/js.md +110 -110
- package/skills/lint/references/languages/py.md +89 -89
- package/skills/lint/references/rules-analyze.md +125 -125
- package/skills/lint/references/suitability-check.md +81 -81
- package/skills/lint/references/tool-fix.md +90 -90
- package/skills/new-skill/SKILL.md +227 -227
- package/skills/new-skill/references/template.md +53 -53
- package/skills/new-skill/references/workflow-patterns.md +104 -104
- package/skills/pytest/SKILL.md +555 -555
- package/skills/pytest/references/case-create.md +324 -324
- package/skills/pytest/references/case-fix.md +271 -271
- package/skills/pytest/references/config.md +145 -145
- package/skills/pytest/references/coverage-analyze.md +223 -223
- package/skills/pytest/references/env-ensure.md +195 -195
- package/skills/pytest/references/execute.md +152 -152
- package/skills/pytest/references/sample.md +159 -159
- package/skills/pytest/references/scoring-rules.md +57 -57
- package/skills/pytest/references/src/pytest-sample/Calculator.py +67 -67
- package/skills/pytest/references/src/pytest-sample/ConfigManager.py +68 -68
- package/skills/pytest/references/src/pytest-sample/FileProcessor.py +53 -53
- package/skills/pytest/references/src/pytest-sample/OrderService.py +82 -82
- package/skills/pytest/references/src/pytest-sample/TokenGenerator.py +50 -50
- package/skills/pytest/references/src/pytest-sample/UserService.py +45 -45
- package/skills/pytest/references/suitability-check.md +220 -220
- package/skills/pytest/references/test-standards.md +244 -244
- package/skills/query/SKILL.md +71 -71
- package/skills/read-docs/SKILL.md +134 -134
- package/skills/read-docs/references/opencode/agents/cases.md +206 -206
- package/skills/read-docs/references/opencode/agents/design-pattern.md +47 -47
- package/skills/read-docs/references/opencode/agents/detail.md +191 -191
- package/skills/read-docs/references/opencode/agents/examples.md +100 -100
- package/skills/read-docs/references/opencode/agents/index.md +309 -309
- package/skills/read-docs/references/opencode/agents/parallel-dispatch.md +149 -149
- package/skills/read-docs/references/opencode/agents/subagent-internals.md +217 -217
- package/skills/read-docs/references/opencode/agents/workflow.md +161 -161
- package/skills/read-docs/references/opencode/cli/commands/acp.md +31 -31
- package/skills/read-docs/references/opencode/cli/commands/agent.md +16 -16
- package/skills/read-docs/references/opencode/cli/commands/attach.md +20 -20
- package/skills/read-docs/references/opencode/cli/commands/mcp.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/others.md +48 -48
- package/skills/read-docs/references/opencode/cli/commands/plugin.md +12 -12
- package/skills/read-docs/references/opencode/cli/commands/provider.md +43 -43
- package/skills/read-docs/references/opencode/cli/commands/run.md +81 -81
- package/skills/read-docs/references/opencode/cli/commands/serve.md +84 -84
- package/skills/read-docs/references/opencode/cli/commands/session.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/web.md +14 -14
- package/skills/read-docs/references/opencode/cli/env.md +38 -38
- package/skills/read-docs/references/opencode/cli/index.md +18 -18
- package/skills/read-docs/references/opencode/cli/tui.md +35 -35
- package/skills/read-docs/references/opencode/commands/examples.md +42 -42
- package/skills/read-docs/references/opencode/commands/index.md +185 -185
- package/skills/read-docs/references/opencode/config/provider.md +151 -151
- package/skills/read-docs/references/opencode/formatter/index.md +70 -70
- package/skills/read-docs/references/opencode/guide/config.md +419 -419
- package/skills/read-docs/references/opencode/guide/formatters.md +70 -70
- package/skills/read-docs/references/opencode/guide/index.md +37 -37
- package/skills/read-docs/references/opencode/guide/providers.md +31 -31
- package/skills/read-docs/references/opencode/guide/rules.md +63 -63
- package/skills/read-docs/references/opencode/plugins/examples.md +75 -75
- package/skills/read-docs/references/opencode/plugins/index.md +188 -188
- package/skills/read-docs/references/opencode/reference/index.md +118 -118
- package/skills/read-docs/references/opencode/rule/index.md +77 -77
- package/skills/read-docs/references/opencode/skills/detail.md +113 -113
- package/skills/read-docs/references/opencode/skills/examples.md +141 -141
- package/skills/read-docs/references/opencode/skills/index.md +126 -126
- package/skills/read-docs/references/opencode/skills/workflow.md +146 -146
- package/skills/read-docs/references/opencode/tests/agent.md +9 -9
- package/skills/read-docs/references/opencode/tests/config.md +59 -59
- package/skills/read-docs/references/opencode/tests/file.md +11 -11
- package/skills/read-docs/references/opencode/tests/serve.md +17 -17
- package/skills/read-docs/references/opencode/tests/session.md +30 -30
- package/skills/read-docs/references/opencode/tests/web.md +16 -16
- package/skills/read-docs/references/opencode/tools/arguments.md +305 -305
- package/skills/read-docs/references/opencode/tools/context.md +17 -17
- package/skills/read-docs/references/opencode/tools/custom.md +110 -110
- package/skills/read-docs/references/opencode/tools/detail.md +104 -104
- package/skills/read-docs/references/opencode/tools/examples.md +71 -71
- package/skills/read-docs/references/opencode/tools/index.md +56 -56
- package/skills/read-docs/references/opencode/tools/lsp.md +25 -25
- package/skills/read-docs/references/opencode/tools/mcp.md +132 -132
- package/skills/read-docs/references/opencode/train/README.md +134 -134
- package/skills/read-docs/references/opencode/train/agent-basic.md +771 -771
- package/skills/read-docs/references/opencode/train/command-basic.md +667 -667
- package/skills/read-docs/references/opencode/train/config-basic.md +508 -508
- package/skills/read-docs/references/opencode/train/index.md +163 -163
- package/skills/read-docs/references/opencode/train/practice.md +872 -872
- package/skills/read-docs/references/opencode/train/skill-basic.md +607 -607
- package/skills/read-docs/references/opencode/tui/commands/config.md +31 -31
- package/skills/read-docs/references/opencode/tui/commands/editor.md +46 -46
- package/skills/read-docs/references/opencode/tui/commands/index.md +124 -124
- package/skills/read-docs/references/opencode/tui/commands/init.md +4 -4
- package/skills/read-docs/references/opencode/tui/index.md +26 -26
- package/skills/read-docs/references/superpowers/bootstrap.md +107 -107
- package/skills/read-docs/references/superpowers/comparison.md +77 -77
- package/skills/read-docs/references/superpowers/context.md +71 -71
- package/skills/read-docs/references/superpowers/index.md +58 -58
- package/skills/read-docs/references/superpowers/parallel.md +49 -49
- package/skills/read-docs/references/superpowers/sdd.md +183 -183
- package/skills/read-docs/references/superpowers/skills.md +68 -68
- package/skills/read-docs/references/superpowers/workflow.md +83 -83
- package/skills/revise/SKILL.md +121 -121
- package/skills/revise/references/article.md +36 -36
- package/skills/revise/references/article.schema.json5 +40 -40
- package/skills/revise/references/gallery.md +34 -34
- package/skills/revise/references/gallery.schema.json5 +40 -40
- package/skills/revise/references/question.md +32 -32
- package/skills/revise/references/question.schema.json5 +31 -31
- package/skills/revise/references/status.md +31 -31
- package/skills/revise/references/status.schema.json5 +27 -27
- package/skills/revise/references/validate-schema.js +39 -39
- package/src/config.js +29 -29
- package/src/config.json5 +19 -19
|
@@ -1,244 +1,244 @@
|
|
|
1
|
-
# 测试用例创建规范
|
|
2
|
-
|
|
3
|
-
> 本规范适用于 Python pytest 测试框架,包含通用规范、Python 特定规范、以及单元/集成测试专属规范。
|
|
4
|
-
|
|
5
|
-
## 一、通用规范
|
|
6
|
-
|
|
7
|
-
### AAA 模式(Arrange-Act-Assert)
|
|
8
|
-
|
|
9
|
-
每个测试方法分为三段:
|
|
10
|
-
|
|
11
|
-
```python
|
|
12
|
-
def test_create_with_valid_data(self):
|
|
13
|
-
# Arrange — 准备
|
|
14
|
-
service = MyService()
|
|
15
|
-
data = {"name": "test", "age": 18}
|
|
16
|
-
|
|
17
|
-
# Act — 执行
|
|
18
|
-
result = service.create(data)
|
|
19
|
-
|
|
20
|
-
# Assert — 断言
|
|
21
|
-
assert result.id is not None
|
|
22
|
-
assert result.name == "test"
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### FIRST 原则
|
|
26
|
-
|
|
27
|
-
| 原则 | 说明 |
|
|
28
|
-
|------|------|
|
|
29
|
-
| Fast | 快速执行(单元测试秒级,集成测试分钟级) |
|
|
30
|
-
| Isolated | 测试间相互独立,不依赖执行顺序 |
|
|
31
|
-
| Repeatable | 可重复运行,结果稳定 |
|
|
32
|
-
| Self-Validating | 自动断言,无需人工判断 |
|
|
33
|
-
| Timely | 与开发同步编写 |
|
|
34
|
-
|
|
35
|
-
### 命名规范
|
|
36
|
-
|
|
37
|
-
| 元素 | 规则 | 示例 |
|
|
38
|
-
|------|------|------|
|
|
39
|
-
| 文件名 | `test_{ModuleName}.py` | `test_MyService.py` |
|
|
40
|
-
| 类名 | `test_{ModuleName}`(与文件名一致) | `test_MyService` |
|
|
41
|
-
| 方法名 | `test_{action}_{expected}` | `test_create_raises_on_empty_input` |
|
|
42
|
-
|
|
43
|
-
方法命名要素:
|
|
44
|
-
- **action**:被测方法名或核心行为(create, send, parse)
|
|
45
|
-
- **expected**:输入条件或预期结果(with_valid_data, raises_on_timeout)
|
|
46
|
-
|
|
47
|
-
### 一个方法一个行为
|
|
48
|
-
|
|
49
|
-
每个测试方法只验证一个行为,不混合多个断言逻辑。
|
|
50
|
-
|
|
51
|
-
## 二、Python/pytest 特定规范
|
|
52
|
-
|
|
53
|
-
### 类格式
|
|
54
|
-
|
|
55
|
-
遵循 AGENTS.md 规则:
|
|
56
|
-
- 2 空格缩进
|
|
57
|
-
- 类风格(非函数式)
|
|
58
|
-
- 文件名与类名一致
|
|
59
|
-
- 一个文件内只定义一个类
|
|
60
|
-
|
|
61
|
-
```python
|
|
62
|
-
import pytest
|
|
63
|
-
|
|
64
|
-
class test_MyService:
|
|
65
|
-
|
|
66
|
-
def test_create_with_valid_data(self):
|
|
67
|
-
# Arrange
|
|
68
|
-
service = MyService()
|
|
69
|
-
# Act
|
|
70
|
-
result = service.create({"name": "test"})
|
|
71
|
-
# Assert
|
|
72
|
-
assert result.id is not None
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### fixture 使用
|
|
76
|
-
|
|
77
|
-
```python
|
|
78
|
-
import pytest
|
|
79
|
-
|
|
80
|
-
class test_MyService:
|
|
81
|
-
|
|
82
|
-
@pytest.fixture
|
|
83
|
-
def service(self):
|
|
84
|
-
return MyService()
|
|
85
|
-
|
|
86
|
-
@pytest.fixture
|
|
87
|
-
def valid_data(self):
|
|
88
|
-
return {"name": "test", "age": 18}
|
|
89
|
-
|
|
90
|
-
def test_create_with_valid_data(self, service, valid_data):
|
|
91
|
-
result = service.create(valid_data)
|
|
92
|
-
assert result.id is not None
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Mock/Stub 使用
|
|
96
|
-
|
|
97
|
-
```python
|
|
98
|
-
from unittest.mock import Mock, patch
|
|
99
|
-
|
|
100
|
-
class test_MyService:
|
|
101
|
-
|
|
102
|
-
@patch('mypackage.MyService.fetch_remote')
|
|
103
|
-
def test_process_returns_data_from_remote(self, mock_fetch):
|
|
104
|
-
# Stub — 预设返回值
|
|
105
|
-
mock_fetch.return_value = {"key": "value"}
|
|
106
|
-
|
|
107
|
-
service = MyService()
|
|
108
|
-
result = service.process()
|
|
109
|
-
|
|
110
|
-
# Mock — 验证调用行为
|
|
111
|
-
mock_fetch.assert_called_once()
|
|
112
|
-
assert result["key"] == "value"
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### 参数化测试
|
|
116
|
-
|
|
117
|
-
```python
|
|
118
|
-
class test_MyValidator:
|
|
119
|
-
|
|
120
|
-
@pytest.mark.parametrize("input,expected", [
|
|
121
|
-
(18, True),
|
|
122
|
-
(30, True),
|
|
123
|
-
(60, True),
|
|
124
|
-
(17, False),
|
|
125
|
-
(61, False),
|
|
126
|
-
(-1, False),
|
|
127
|
-
])
|
|
128
|
-
def test_validate_age(self, input, expected):
|
|
129
|
-
assert MyValidator.validate_age(input) == expected
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### 异常断言
|
|
133
|
-
|
|
134
|
-
```python
|
|
135
|
-
class test_MyService:
|
|
136
|
-
|
|
137
|
-
def test_create_raises_on_empty_name(self):
|
|
138
|
-
service = MyService()
|
|
139
|
-
with pytest.raises(ValueError, match="name不能为空"):
|
|
140
|
-
service.create({"name": ""})
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### pytest marker
|
|
144
|
-
|
|
145
|
-
```python
|
|
146
|
-
@pytest.mark.unit
|
|
147
|
-
class test_MyService:
|
|
148
|
-
# 单元测试
|
|
149
|
-
|
|
150
|
-
@pytest.mark.integration
|
|
151
|
-
class test_LoginFlow:
|
|
152
|
-
# 集成测试
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## 三、单元测试专属规范(unit)
|
|
156
|
-
|
|
157
|
-
### Mock 策略:full — 全部 Mock 外部依赖
|
|
158
|
-
|
|
159
|
-
| 依赖类型 | 处理策略 | 示例 |
|
|
160
|
-
|---------|---------|------|
|
|
161
|
-
| HTTP 请求 | Mock:patch 请求方法,预设返回值 | `@patch('requests.get')` |
|
|
162
|
-
| 数据库操作 | Fake:内存数据库 或 patch 连接层 | `@patch('db.connect')` |
|
|
163
|
-
| 文件系统 | Fake:使用 `tmp_path` fixture | `def test_read(self, tmp_path)` |
|
|
164
|
-
| 时间依赖 | Mock:patch datetime.now | `@patch('datetime.now')` |
|
|
165
|
-
| 随机值 | Mock:patch random 或设 seed | `random.seed(42)` |
|
|
166
|
-
| 外部服务 | Mock:patch 发送方法 | `@patch('email.send')` |
|
|
167
|
-
| 环境变量 | Stub:monkeypatch.setenv | `monkeypatch.setenv('KEY', 'val')` |
|
|
168
|
-
|
|
169
|
-
### 用例覆盖要求
|
|
170
|
-
|
|
171
|
-
| 源码特征 | 必须创建的用例 |
|
|
172
|
-
|---------|---------------|
|
|
173
|
-
| 每个公开函数 | 至少 1 个正向用例 |
|
|
174
|
-
| 含 if/elif 分支 | 边界值用例(每个分支至少 1 个) |
|
|
175
|
-
| 含 raise/try-except | 异常路径用例(pytest.raises) |
|
|
176
|
-
| 多输入场景 | 参数化用例(@pytest.mark.parametrize) |
|
|
177
|
-
| 有返回值 | 断言返回值类型和内容 |
|
|
178
|
-
|
|
179
|
-
### 禁止事项
|
|
180
|
-
|
|
181
|
-
- 禁止真实网络调用
|
|
182
|
-
- 禁止操作真实文件系统
|
|
183
|
-
- 禁止依赖真实时间
|
|
184
|
-
- 禁止依赖随机值
|
|
185
|
-
- 禁止测试间依赖(共享状态)
|
|
186
|
-
- 禁止硬编码路径
|
|
187
|
-
|
|
188
|
-
## 四、集成测试专属规范(integration)
|
|
189
|
-
|
|
190
|
-
### Mock 策略:minimal — 最少 Mock,优先真实调用
|
|
191
|
-
|
|
192
|
-
| 依赖类型 | 处理策略 |
|
|
193
|
-
|---------|---------|
|
|
194
|
-
| 内部模块 | 真实调用,不 Mock |
|
|
195
|
-
| 数据库 | 真实连接(测试库)或 Fake 内存数据库 |
|
|
196
|
-
| 文件系统 | 真实文件操作(使用 tmp_path 清理) |
|
|
197
|
-
| 外部 API | 仅 Mock 不可控的生产 API,测试环境 API 真实调用 |
|
|
198
|
-
| 时间/随机 | 可接受真实值,或 seed 固定 |
|
|
199
|
-
|
|
200
|
-
### 用例组织
|
|
201
|
-
|
|
202
|
-
- 按 **业务场景** 组织用例,不按函数
|
|
203
|
-
- 每个场景覆盖完整流程:输入 → 处理 → 输出
|
|
204
|
-
- 验证端到端数据流完整性
|
|
205
|
-
|
|
206
|
-
```python
|
|
207
|
-
@pytest.mark.integration
|
|
208
|
-
class test_OrderFlow:
|
|
209
|
-
|
|
210
|
-
def test_create_order_and_send_notification(self, tmp_path):
|
|
211
|
-
# 场景:创建订单并发送通知
|
|
212
|
-
# Arrange
|
|
213
|
-
db = Database(test_url)
|
|
214
|
-
service = OrderService(db=db)
|
|
215
|
-
|
|
216
|
-
# Act
|
|
217
|
-
order = service.create_order(user_id=1, item="book")
|
|
218
|
-
notification = service.send_notification(order.id)
|
|
219
|
-
|
|
220
|
-
# Assert — 验证完整数据流
|
|
221
|
-
assert order.id is not None
|
|
222
|
-
assert order.status == "created"
|
|
223
|
-
assert notification.order_id == order.id
|
|
224
|
-
assert notification.sent is True
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### fixture 使用
|
|
228
|
-
|
|
229
|
-
- 使用 `scope="class"` 的 fixture 共享 setup
|
|
230
|
-
- teardown 负责清理测试数据
|
|
231
|
-
- 数据准备放在 fixture 中,不硬编码在测试方法内
|
|
232
|
-
|
|
233
|
-
## 五、稳定性保障规则
|
|
234
|
-
|
|
235
|
-
| 规则 | 说明 |
|
|
236
|
-
|------|------|
|
|
237
|
-
| 禁止真实网络 | 单元测试所有 HTTP 必须 Mock |
|
|
238
|
-
| 禁止真实文件 | 文件操作使用 tmp_path fixture |
|
|
239
|
-
| 禁止真实时间 | 时间依赖必须 patch |
|
|
240
|
-
| 禁止真实随机 | 随机值必须 patch 或 seed |
|
|
241
|
-
| 禁止真实外部服务 | 邮件/消息队列等必须 Mock(单元测试) |
|
|
242
|
-
| 禁止测试间依赖 | 每个测试独立,不依赖执行顺序 |
|
|
243
|
-
| 禁止硬编码路径 | 使用 fixture 或相对路径 |
|
|
244
|
-
| fixture 作用域 | class 级用 scope="class",函数级用默认 |
|
|
1
|
+
# 测试用例创建规范
|
|
2
|
+
|
|
3
|
+
> 本规范适用于 Python pytest 测试框架,包含通用规范、Python 特定规范、以及单元/集成测试专属规范。
|
|
4
|
+
|
|
5
|
+
## 一、通用规范
|
|
6
|
+
|
|
7
|
+
### AAA 模式(Arrange-Act-Assert)
|
|
8
|
+
|
|
9
|
+
每个测试方法分为三段:
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
def test_create_with_valid_data(self):
|
|
13
|
+
# Arrange — 准备
|
|
14
|
+
service = MyService()
|
|
15
|
+
data = {"name": "test", "age": 18}
|
|
16
|
+
|
|
17
|
+
# Act — 执行
|
|
18
|
+
result = service.create(data)
|
|
19
|
+
|
|
20
|
+
# Assert — 断言
|
|
21
|
+
assert result.id is not None
|
|
22
|
+
assert result.name == "test"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### FIRST 原则
|
|
26
|
+
|
|
27
|
+
| 原则 | 说明 |
|
|
28
|
+
|------|------|
|
|
29
|
+
| Fast | 快速执行(单元测试秒级,集成测试分钟级) |
|
|
30
|
+
| Isolated | 测试间相互独立,不依赖执行顺序 |
|
|
31
|
+
| Repeatable | 可重复运行,结果稳定 |
|
|
32
|
+
| Self-Validating | 自动断言,无需人工判断 |
|
|
33
|
+
| Timely | 与开发同步编写 |
|
|
34
|
+
|
|
35
|
+
### 命名规范
|
|
36
|
+
|
|
37
|
+
| 元素 | 规则 | 示例 |
|
|
38
|
+
|------|------|------|
|
|
39
|
+
| 文件名 | `test_{ModuleName}.py` | `test_MyService.py` |
|
|
40
|
+
| 类名 | `test_{ModuleName}`(与文件名一致) | `test_MyService` |
|
|
41
|
+
| 方法名 | `test_{action}_{expected}` | `test_create_raises_on_empty_input` |
|
|
42
|
+
|
|
43
|
+
方法命名要素:
|
|
44
|
+
- **action**:被测方法名或核心行为(create, send, parse)
|
|
45
|
+
- **expected**:输入条件或预期结果(with_valid_data, raises_on_timeout)
|
|
46
|
+
|
|
47
|
+
### 一个方法一个行为
|
|
48
|
+
|
|
49
|
+
每个测试方法只验证一个行为,不混合多个断言逻辑。
|
|
50
|
+
|
|
51
|
+
## 二、Python/pytest 特定规范
|
|
52
|
+
|
|
53
|
+
### 类格式
|
|
54
|
+
|
|
55
|
+
遵循 AGENTS.md 规则:
|
|
56
|
+
- 2 空格缩进
|
|
57
|
+
- 类风格(非函数式)
|
|
58
|
+
- 文件名与类名一致
|
|
59
|
+
- 一个文件内只定义一个类
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import pytest
|
|
63
|
+
|
|
64
|
+
class test_MyService:
|
|
65
|
+
|
|
66
|
+
def test_create_with_valid_data(self):
|
|
67
|
+
# Arrange
|
|
68
|
+
service = MyService()
|
|
69
|
+
# Act
|
|
70
|
+
result = service.create({"name": "test"})
|
|
71
|
+
# Assert
|
|
72
|
+
assert result.id is not None
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### fixture 使用
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import pytest
|
|
79
|
+
|
|
80
|
+
class test_MyService:
|
|
81
|
+
|
|
82
|
+
@pytest.fixture
|
|
83
|
+
def service(self):
|
|
84
|
+
return MyService()
|
|
85
|
+
|
|
86
|
+
@pytest.fixture
|
|
87
|
+
def valid_data(self):
|
|
88
|
+
return {"name": "test", "age": 18}
|
|
89
|
+
|
|
90
|
+
def test_create_with_valid_data(self, service, valid_data):
|
|
91
|
+
result = service.create(valid_data)
|
|
92
|
+
assert result.id is not None
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Mock/Stub 使用
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from unittest.mock import Mock, patch
|
|
99
|
+
|
|
100
|
+
class test_MyService:
|
|
101
|
+
|
|
102
|
+
@patch('mypackage.MyService.fetch_remote')
|
|
103
|
+
def test_process_returns_data_from_remote(self, mock_fetch):
|
|
104
|
+
# Stub — 预设返回值
|
|
105
|
+
mock_fetch.return_value = {"key": "value"}
|
|
106
|
+
|
|
107
|
+
service = MyService()
|
|
108
|
+
result = service.process()
|
|
109
|
+
|
|
110
|
+
# Mock — 验证调用行为
|
|
111
|
+
mock_fetch.assert_called_once()
|
|
112
|
+
assert result["key"] == "value"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 参数化测试
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
class test_MyValidator:
|
|
119
|
+
|
|
120
|
+
@pytest.mark.parametrize("input,expected", [
|
|
121
|
+
(18, True),
|
|
122
|
+
(30, True),
|
|
123
|
+
(60, True),
|
|
124
|
+
(17, False),
|
|
125
|
+
(61, False),
|
|
126
|
+
(-1, False),
|
|
127
|
+
])
|
|
128
|
+
def test_validate_age(self, input, expected):
|
|
129
|
+
assert MyValidator.validate_age(input) == expected
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 异常断言
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
class test_MyService:
|
|
136
|
+
|
|
137
|
+
def test_create_raises_on_empty_name(self):
|
|
138
|
+
service = MyService()
|
|
139
|
+
with pytest.raises(ValueError, match="name不能为空"):
|
|
140
|
+
service.create({"name": ""})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### pytest marker
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
@pytest.mark.unit
|
|
147
|
+
class test_MyService:
|
|
148
|
+
# 单元测试
|
|
149
|
+
|
|
150
|
+
@pytest.mark.integration
|
|
151
|
+
class test_LoginFlow:
|
|
152
|
+
# 集成测试
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 三、单元测试专属规范(unit)
|
|
156
|
+
|
|
157
|
+
### Mock 策略:full — 全部 Mock 外部依赖
|
|
158
|
+
|
|
159
|
+
| 依赖类型 | 处理策略 | 示例 |
|
|
160
|
+
|---------|---------|------|
|
|
161
|
+
| HTTP 请求 | Mock:patch 请求方法,预设返回值 | `@patch('requests.get')` |
|
|
162
|
+
| 数据库操作 | Fake:内存数据库 或 patch 连接层 | `@patch('db.connect')` |
|
|
163
|
+
| 文件系统 | Fake:使用 `tmp_path` fixture | `def test_read(self, tmp_path)` |
|
|
164
|
+
| 时间依赖 | Mock:patch datetime.now | `@patch('datetime.now')` |
|
|
165
|
+
| 随机值 | Mock:patch random 或设 seed | `random.seed(42)` |
|
|
166
|
+
| 外部服务 | Mock:patch 发送方法 | `@patch('email.send')` |
|
|
167
|
+
| 环境变量 | Stub:monkeypatch.setenv | `monkeypatch.setenv('KEY', 'val')` |
|
|
168
|
+
|
|
169
|
+
### 用例覆盖要求
|
|
170
|
+
|
|
171
|
+
| 源码特征 | 必须创建的用例 |
|
|
172
|
+
|---------|---------------|
|
|
173
|
+
| 每个公开函数 | 至少 1 个正向用例 |
|
|
174
|
+
| 含 if/elif 分支 | 边界值用例(每个分支至少 1 个) |
|
|
175
|
+
| 含 raise/try-except | 异常路径用例(pytest.raises) |
|
|
176
|
+
| 多输入场景 | 参数化用例(@pytest.mark.parametrize) |
|
|
177
|
+
| 有返回值 | 断言返回值类型和内容 |
|
|
178
|
+
|
|
179
|
+
### 禁止事项
|
|
180
|
+
|
|
181
|
+
- 禁止真实网络调用
|
|
182
|
+
- 禁止操作真实文件系统
|
|
183
|
+
- 禁止依赖真实时间
|
|
184
|
+
- 禁止依赖随机值
|
|
185
|
+
- 禁止测试间依赖(共享状态)
|
|
186
|
+
- 禁止硬编码路径
|
|
187
|
+
|
|
188
|
+
## 四、集成测试专属规范(integration)
|
|
189
|
+
|
|
190
|
+
### Mock 策略:minimal — 最少 Mock,优先真实调用
|
|
191
|
+
|
|
192
|
+
| 依赖类型 | 处理策略 |
|
|
193
|
+
|---------|---------|
|
|
194
|
+
| 内部模块 | 真实调用,不 Mock |
|
|
195
|
+
| 数据库 | 真实连接(测试库)或 Fake 内存数据库 |
|
|
196
|
+
| 文件系统 | 真实文件操作(使用 tmp_path 清理) |
|
|
197
|
+
| 外部 API | 仅 Mock 不可控的生产 API,测试环境 API 真实调用 |
|
|
198
|
+
| 时间/随机 | 可接受真实值,或 seed 固定 |
|
|
199
|
+
|
|
200
|
+
### 用例组织
|
|
201
|
+
|
|
202
|
+
- 按 **业务场景** 组织用例,不按函数
|
|
203
|
+
- 每个场景覆盖完整流程:输入 → 处理 → 输出
|
|
204
|
+
- 验证端到端数据流完整性
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
@pytest.mark.integration
|
|
208
|
+
class test_OrderFlow:
|
|
209
|
+
|
|
210
|
+
def test_create_order_and_send_notification(self, tmp_path):
|
|
211
|
+
# 场景:创建订单并发送通知
|
|
212
|
+
# Arrange
|
|
213
|
+
db = Database(test_url)
|
|
214
|
+
service = OrderService(db=db)
|
|
215
|
+
|
|
216
|
+
# Act
|
|
217
|
+
order = service.create_order(user_id=1, item="book")
|
|
218
|
+
notification = service.send_notification(order.id)
|
|
219
|
+
|
|
220
|
+
# Assert — 验证完整数据流
|
|
221
|
+
assert order.id is not None
|
|
222
|
+
assert order.status == "created"
|
|
223
|
+
assert notification.order_id == order.id
|
|
224
|
+
assert notification.sent is True
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### fixture 使用
|
|
228
|
+
|
|
229
|
+
- 使用 `scope="class"` 的 fixture 共享 setup
|
|
230
|
+
- teardown 负责清理测试数据
|
|
231
|
+
- 数据准备放在 fixture 中,不硬编码在测试方法内
|
|
232
|
+
|
|
233
|
+
## 五、稳定性保障规则
|
|
234
|
+
|
|
235
|
+
| 规则 | 说明 |
|
|
236
|
+
|------|------|
|
|
237
|
+
| 禁止真实网络 | 单元测试所有 HTTP 必须 Mock |
|
|
238
|
+
| 禁止真实文件 | 文件操作使用 tmp_path fixture |
|
|
239
|
+
| 禁止真实时间 | 时间依赖必须 patch |
|
|
240
|
+
| 禁止真实随机 | 随机值必须 patch 或 seed |
|
|
241
|
+
| 禁止真实外部服务 | 邮件/消息队列等必须 Mock(单元测试) |
|
|
242
|
+
| 禁止测试间依赖 | 每个测试独立,不依赖执行顺序 |
|
|
243
|
+
| 禁止硬编码路径 | 使用 fixture 或相对路径 |
|
|
244
|
+
| fixture 作用域 | class 级用 scope="class",函数级用默认 |
|
package/skills/query/SKILL.md
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: query
|
|
3
|
-
description: |
|
|
4
|
-
自包含内容生成 skill(固定 Sprint 范式):每次调用 = 一个固定 Sprint(Planning→Execution→Review),todowrite 落 3 项带 DoD 的 Sprint Backlog 并逐项验证,按输出语义交付生成内容。
|
|
5
|
-
prompt 为任务要求(含输出格式说明),source 为可选素材,language 控制输出语言(默认中文)。调用方直接传原始任务消息即可,无需预处理;禁止 WebFetch/网络请求。
|
|
6
|
-
license: MIT
|
|
7
|
-
metadata:
|
|
8
|
-
workflow: sequential
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# query 技能(固定 Sprint 冲刺)
|
|
12
|
-
|
|
13
|
-
## 执行范式
|
|
14
|
-
|
|
15
|
-
每次调用 = 一个固定 Sprint,三个事件:
|
|
16
|
-
|
|
17
|
-
1. **Sprint Planning**:解析入参 → 定义 Sprint Goal → todowrite 落固定 3 项 Sprint Backlog(每项带 DoD)
|
|
18
|
-
2. **Sprint Execution**:逐项执行,每项 = 执行 → 验证 DoD → todowrite 勾单 Done
|
|
19
|
-
3. **Sprint Review**:对照 Sprint Goal 验证 Increment(生成内容)及输出语义
|
|
20
|
-
|
|
21
|
-
**Sprint Goal** = `按 {{prompt}} 生成内容(语言 {{language}}),并按输出语义交付`。
|
|
22
|
-
|
|
23
|
-
## 输入参数
|
|
24
|
-
|
|
25
|
-
入参为调用方传入的**原始任务消息**,可为 JSON 对象、key=value 或自然语言等任意形态,agent 依据字段语义自主提取。字段清单(字段/类型/必填/默认值):
|
|
26
|
-
|
|
27
|
-
| 字段 | 类型 | 必填 | 说明 |
|
|
28
|
-
|---|---|---|---|
|
|
29
|
-
| `prompt` | string | ✅ | 任务要求,包含输出格式说明 |
|
|
30
|
-
| `source` | string | ❌ | 原始素材:普通文本或本地文件路径 |
|
|
31
|
-
| `language` | string | ❌ | 输出内容语言,默认 中文 |
|
|
32
|
-
| `output` | string | ❌ | 输出文件路径(提供则写文件,否则 stdout) |
|
|
33
|
-
|
|
34
|
-
本技能仅使用上表四个字段,忽略所有其他字段(如 `url`)。
|
|
35
|
-
|
|
36
|
-
## 固定 Sprint Backlog(todowrite 落单,覆盖历史 todos)
|
|
37
|
-
|
|
38
|
-
1. 解析入参 | DoD: 四字段已提取(或 prompt 缺失时 stderr 报错结束)
|
|
39
|
-
2. 内容生成 | DoD: 按 prompt 生成内容,语言 language(默认中文),source 已按需读取为素材
|
|
40
|
-
3. 输出 | DoD: 按输出语义交付(文件路径或 stdout)
|
|
41
|
-
|
|
42
|
-
## Sprint Execution
|
|
43
|
-
|
|
44
|
-
按固定 3 项逐项执行(勾单机制见执行范式)。
|
|
45
|
-
|
|
46
|
-
### Item 1:解析入参
|
|
47
|
-
|
|
48
|
-
从原始任务消息中自主提取 `prompt`/`source`/`language`/`output` 四个字段。`prompt` 为空、null 或仅含空白 → 将错误信息输出到 stderr 并结束,**禁止**继续执行。
|
|
49
|
-
|
|
50
|
-
### Item 2:内容生成
|
|
51
|
-
|
|
52
|
-
`source` 为文件路径时用 `read` 读取其内容作为素材。按 `prompt` 要求生成内容,输出语言使用 `language`(缺省按参数表默认值)。
|
|
53
|
-
|
|
54
|
-
### Item 3:输出
|
|
55
|
-
|
|
56
|
-
- 提供 `output` → 用 `write` 将生成内容写入该文件(**禁止创建其他文件**),stdout 输出文件路径
|
|
57
|
-
- 未提供 `output` → 将生成内容直接输出到 stdout,**不写任何文件**
|
|
58
|
-
|
|
59
|
-
结果为空或生成失败 → stderr 报错并结束,**不写任何文件**。
|
|
60
|
-
|
|
61
|
-
## Sprint Review
|
|
62
|
-
|
|
63
|
-
本 skill 每次调用 = 无状态独立 Sprint,无跨轮次状态,故不进行 Retrospective。所有 Backlog Items 完成后:
|
|
64
|
-
|
|
65
|
-
- **对照 Sprint Goal 验证**:生成内容是否符合 `{{prompt}}` 要求、语言 `{{language}}`?输出语义是否正确(写文件输出路径 / stdout 输出内容)?
|
|
66
|
-
- **展示 Increment**:输出文件路径或 stdout 的生成内容。
|
|
67
|
-
|
|
68
|
-
## 约束
|
|
69
|
-
|
|
70
|
-
- 只处理已声明字段(prompt/source/language/output),忽略所有其他传入参数(如 `url`),**禁止**以任何形式使用它们。
|
|
71
|
-
- **禁止使用 WebFetch 或任何网络请求、禁止访问外部网络**;`source` 仅为素材透传,绝不自行获取内容。
|
|
1
|
+
---
|
|
2
|
+
name: query
|
|
3
|
+
description: |
|
|
4
|
+
自包含内容生成 skill(固定 Sprint 范式):每次调用 = 一个固定 Sprint(Planning→Execution→Review),todowrite 落 3 项带 DoD 的 Sprint Backlog 并逐项验证,按输出语义交付生成内容。
|
|
5
|
+
prompt 为任务要求(含输出格式说明),source 为可选素材,language 控制输出语言(默认中文)。调用方直接传原始任务消息即可,无需预处理;禁止 WebFetch/网络请求。
|
|
6
|
+
license: MIT
|
|
7
|
+
metadata:
|
|
8
|
+
workflow: sequential
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# query 技能(固定 Sprint 冲刺)
|
|
12
|
+
|
|
13
|
+
## 执行范式
|
|
14
|
+
|
|
15
|
+
每次调用 = 一个固定 Sprint,三个事件:
|
|
16
|
+
|
|
17
|
+
1. **Sprint Planning**:解析入参 → 定义 Sprint Goal → todowrite 落固定 3 项 Sprint Backlog(每项带 DoD)
|
|
18
|
+
2. **Sprint Execution**:逐项执行,每项 = 执行 → 验证 DoD → todowrite 勾单 Done
|
|
19
|
+
3. **Sprint Review**:对照 Sprint Goal 验证 Increment(生成内容)及输出语义
|
|
20
|
+
|
|
21
|
+
**Sprint Goal** = `按 {{prompt}} 生成内容(语言 {{language}}),并按输出语义交付`。
|
|
22
|
+
|
|
23
|
+
## 输入参数
|
|
24
|
+
|
|
25
|
+
入参为调用方传入的**原始任务消息**,可为 JSON 对象、key=value 或自然语言等任意形态,agent 依据字段语义自主提取。字段清单(字段/类型/必填/默认值):
|
|
26
|
+
|
|
27
|
+
| 字段 | 类型 | 必填 | 说明 |
|
|
28
|
+
|---|---|---|---|
|
|
29
|
+
| `prompt` | string | ✅ | 任务要求,包含输出格式说明 |
|
|
30
|
+
| `source` | string | ❌ | 原始素材:普通文本或本地文件路径 |
|
|
31
|
+
| `language` | string | ❌ | 输出内容语言,默认 中文 |
|
|
32
|
+
| `output` | string | ❌ | 输出文件路径(提供则写文件,否则 stdout) |
|
|
33
|
+
|
|
34
|
+
本技能仅使用上表四个字段,忽略所有其他字段(如 `url`)。
|
|
35
|
+
|
|
36
|
+
## 固定 Sprint Backlog(todowrite 落单,覆盖历史 todos)
|
|
37
|
+
|
|
38
|
+
1. 解析入参 | DoD: 四字段已提取(或 prompt 缺失时 stderr 报错结束)
|
|
39
|
+
2. 内容生成 | DoD: 按 prompt 生成内容,语言 language(默认中文),source 已按需读取为素材
|
|
40
|
+
3. 输出 | DoD: 按输出语义交付(文件路径或 stdout)
|
|
41
|
+
|
|
42
|
+
## Sprint Execution
|
|
43
|
+
|
|
44
|
+
按固定 3 项逐项执行(勾单机制见执行范式)。
|
|
45
|
+
|
|
46
|
+
### Item 1:解析入参
|
|
47
|
+
|
|
48
|
+
从原始任务消息中自主提取 `prompt`/`source`/`language`/`output` 四个字段。`prompt` 为空、null 或仅含空白 → 将错误信息输出到 stderr 并结束,**禁止**继续执行。
|
|
49
|
+
|
|
50
|
+
### Item 2:内容生成
|
|
51
|
+
|
|
52
|
+
`source` 为文件路径时用 `read` 读取其内容作为素材。按 `prompt` 要求生成内容,输出语言使用 `language`(缺省按参数表默认值)。
|
|
53
|
+
|
|
54
|
+
### Item 3:输出
|
|
55
|
+
|
|
56
|
+
- 提供 `output` → 用 `write` 将生成内容写入该文件(**禁止创建其他文件**),stdout 输出文件路径
|
|
57
|
+
- 未提供 `output` → 将生成内容直接输出到 stdout,**不写任何文件**
|
|
58
|
+
|
|
59
|
+
结果为空或生成失败 → stderr 报错并结束,**不写任何文件**。
|
|
60
|
+
|
|
61
|
+
## Sprint Review
|
|
62
|
+
|
|
63
|
+
本 skill 每次调用 = 无状态独立 Sprint,无跨轮次状态,故不进行 Retrospective。所有 Backlog Items 完成后:
|
|
64
|
+
|
|
65
|
+
- **对照 Sprint Goal 验证**:生成内容是否符合 `{{prompt}}` 要求、语言 `{{language}}`?输出语义是否正确(写文件输出路径 / stdout 输出内容)?
|
|
66
|
+
- **展示 Increment**:输出文件路径或 stdout 的生成内容。
|
|
67
|
+
|
|
68
|
+
## 约束
|
|
69
|
+
|
|
70
|
+
- 只处理已声明字段(prompt/source/language/output),忽略所有其他传入参数(如 `url`),**禁止**以任何形式使用它们。
|
|
71
|
+
- **禁止使用 WebFetch 或任何网络请求、禁止访问外部网络**;`source` 仅为素材透传,绝不自行获取内容。
|
|
72
72
|
- 写文件一律用 `write` 工具;读文件用 `read` 工具。
|