mtkit 1.16.1__tar.gz
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.
- mtkit-1.16.1/MANIFEST.in +2 -0
- mtkit-1.16.1/PKG-INFO +150 -0
- mtkit-1.16.1/README.md +123 -0
- mtkit-1.16.1/mtkit/__init__.py +36 -0
- mtkit-1.16.1/mtkit/__main__.py +6 -0
- mtkit-1.16.1/mtkit/asset.py +101 -0
- mtkit-1.16.1/mtkit/audit.py +220 -0
- mtkit-1.16.1/mtkit/builder.py +100 -0
- mtkit-1.16.1/mtkit/cli.py +885 -0
- mtkit-1.16.1/mtkit/conf.py +63 -0
- mtkit-1.16.1/mtkit/coverage.py +175 -0
- mtkit-1.16.1/mtkit/db.py +676 -0
- mtkit-1.16.1/mtkit/evolve.py +142 -0
- mtkit-1.16.1/mtkit/extract/__init__.py +17 -0
- mtkit-1.16.1/mtkit/extract/code_facts.py +631 -0
- mtkit-1.16.1/mtkit/extract/docx_loader.py +115 -0
- mtkit-1.16.1/mtkit/extract/xmind_loader.py +125 -0
- mtkit-1.16.1/mtkit/generate/__init__.py +10 -0
- mtkit-1.16.1/mtkit/generate/llm.py +360 -0
- mtkit-1.16.1/mtkit/generate/prompts.py +178 -0
- mtkit-1.16.1/mtkit/generate/skeleton.py +59 -0
- mtkit-1.16.1/mtkit/normalize.py +480 -0
- mtkit-1.16.1/mtkit/parsers.py +318 -0
- mtkit-1.16.1/mtkit/review.py +274 -0
- mtkit-1.16.1/mtkit/selfheal.py +110 -0
- mtkit-1.16.1/mtkit/tb.py +191 -0
- mtkit-1.16.1/mtkit/track.py +309 -0
- mtkit-1.16.1/mtkit/validator.py +174 -0
- mtkit-1.16.1/mtkit/writer.py +137 -0
- mtkit-1.16.1/mtkit.egg-info/PKG-INFO +150 -0
- mtkit-1.16.1/mtkit.egg-info/SOURCES.txt +36 -0
- mtkit-1.16.1/mtkit.egg-info/dependency_links.txt +1 -0
- mtkit-1.16.1/mtkit.egg-info/entry_points.txt +2 -0
- mtkit-1.16.1/mtkit.egg-info/requires.txt +10 -0
- mtkit-1.16.1/mtkit.egg-info/top_level.txt +1 -0
- mtkit-1.16.1/pyproject.toml +42 -0
- mtkit-1.16.1/setup.cfg +16 -0
mtkit-1.16.1/MANIFEST.in
ADDED
mtkit-1.16.1/PKG-INFO
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mtkit
|
|
3
|
+
Version: 1.16.1
|
|
4
|
+
Summary: AI 全站测试工程师:计划先行生成标准 XMind 测试用例(质量门禁把关),用例资产体检修复,交互式测试咨询与问题定位指导,使用即训练、越用越成熟
|
|
5
|
+
Author: mtkit
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: testing,xmind,test-case,ai,qoder
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Topic :: Software Development :: Testing
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Provides-Extra: docx
|
|
21
|
+
Requires-Dist: python-docx; extra == "docx"
|
|
22
|
+
Provides-Extra: mysql
|
|
23
|
+
Requires-Dist: pymysql; extra == "mysql"
|
|
24
|
+
Provides-Extra: all
|
|
25
|
+
Requires-Dist: python-docx; extra == "all"
|
|
26
|
+
Requires-Dist: pymysql; extra == "all"
|
|
27
|
+
|
|
28
|
+
# mtkit — AI 全站测试工程师
|
|
29
|
+
|
|
30
|
+
计划先行生成标准 XMind 测试用例(质量门禁把关),体检修复用例资产,交互式测试咨询与问题定位指导;使用即训练,越用越成熟。
|
|
31
|
+
|
|
32
|
+
## 流水线
|
|
33
|
+
|
|
34
|
+
```mermaid
|
|
35
|
+
flowchart LR
|
|
36
|
+
IN[输入: 方案.docx + 样例.xmind + 后端仓库 + 自定义文档] --> READ[读取与文档体检]
|
|
37
|
+
READ --> FACTS[代码事实扫描<br/>九语言接口/SQL]
|
|
38
|
+
FACTS --> PLAN[测试用例输出计划<br/>设计方法 + 构建者建议]
|
|
39
|
+
PLAN --> AUTH{授权}
|
|
40
|
+
AUTH -->|确认| CONTRACT[契约 JSON]
|
|
41
|
+
CONTRACT --> GATE[质量门禁<br/>review + AI 审查]
|
|
42
|
+
GATE --> RENDER[渲染 XMind]
|
|
43
|
+
RENDER --> CHECK[校验 + 漏测对比]
|
|
44
|
+
CHECK --> OUT[交付: XMind + 缺陷点汇总 + 工作痕迹]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 快速上手(零依赖)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# 1. 生成 XMind(纯标准库,无需任何安装)
|
|
51
|
+
cd d:\mtkit
|
|
52
|
+
mtkit gen -i examples/sample.json -o 用例.xmind
|
|
53
|
+
|
|
54
|
+
# 2. 校验与统计
|
|
55
|
+
mtkit validate -i 用例.xmind
|
|
56
|
+
mtkit info -i 用例.xmind
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
可选依赖(用到才装):`.docx` 解析 `pip install python-docx`;数据库直连 `pip install pymysql`。
|
|
60
|
+
|
|
61
|
+
## 一键安装(含 Qoder 插件注册与可选依赖)
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 方式一(推荐,新机器零门槛):PyPI 安装 CLI
|
|
65
|
+
pip install mtkit
|
|
66
|
+
|
|
67
|
+
# 方式二:仓库根目录执行(含可选依赖自动安装)
|
|
68
|
+
python install.py # 或双击 install.bat
|
|
69
|
+
|
|
70
|
+
# 方式三:输入 git 地址自动拉取安装
|
|
71
|
+
python install.py --git <git 地址> [--dir 目标目录]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
安装完成后**重启 Qoder**,对话框输入 `/` 应列出 mtkit-gen-xmind,或直接自然语言触发。
|
|
75
|
+
|
|
76
|
+
> Qoder 插件注册:`skills/`、`commands/` 不在 PyPI 包中,pip 安装后执行
|
|
77
|
+
> `mtkit install --git <git 地址>`(或先设置环境变量 `MTKIT_INSTALL_GIT`)拉取完整仓库并注册插件。
|
|
78
|
+
|
|
79
|
+
## 命令
|
|
80
|
+
|
|
81
|
+
| 命令 | 作用 | 示例 |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| `gen` | 契约/数据 → .xmind | `mtkit gen -i 契约.json -o 用例.xmind` |
|
|
84
|
+
| `gather` | 方案+样例+代码 → 生成上下文 | `mtkit gather -i 方案.docx --hist 样例.xmind -r 后端 -o ctx.json` |
|
|
85
|
+
| `facts` | 九语言代码事实扫描 | `mtkit facts -r 后端 -o facts.json` |
|
|
86
|
+
| `review` | 契约质量门禁 | `mtkit review -i 契约.json -f facts.json` |
|
|
87
|
+
| `audit` | 用例资产体检(检索不合适用例) | `mtkit audit -i 旧用例.xmind -f facts.json` |
|
|
88
|
+
| `db` | 数据库只读接入(check/schema/verify) | `mtkit db verify -c db.json -i 契约.json` |
|
|
89
|
+
| `validate` / `info` | 校验 / 统计 .xmind | `mtkit validate -i 用例.xmind` |
|
|
90
|
+
| `diff` | 漏测对比 | `mtkit diff -i 用例.xmind -f facts.json -d 方案.docx` |
|
|
91
|
+
| `contract` / `tree` | 用例 ↔ 契约互转 / 还原树 | `mtkit contract -i 用例.xmind -o 契约.json` |
|
|
92
|
+
| `track` | 测试管理:执行记录/报告/趋势 | `mtkit track record --case 用例 --result pass` |
|
|
93
|
+
| `bug` | 缺陷库:登记/清单/关闭/统计 | `mtkit bug add --title 缺陷 --severity P1` |
|
|
94
|
+
| `evolve` | 自进化:备份/恢复/清单/清理 | `mtkit evolve backup 文件` |
|
|
95
|
+
| `asset` | 用例资产老化检测(治理) | `mtkit asset --dir 输出目录 --days 30` |
|
|
96
|
+
|
|
97
|
+
契约格式(唯一输入约定):
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{"chapters":[{"t":"章节","cases":[{"t":"tc-P0-功能测试:用例名",
|
|
101
|
+
"pc":["前置"],"steps":["步骤"],"expects":["预期"],"sql":["SELECT ..."]}]}]}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 数据库接入(可选,严格只读)
|
|
105
|
+
|
|
106
|
+
`db.json` 四种数据源(`type` 字段):
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{"type":"cli","connect":{"cmd":"mysql -h{host} -u{user} -p{pass} {db} -N -e \"{sql}\"","host":"10.0.0.1","user":"ro","pass":"${DB_PASS}","db":"bill_db"}}
|
|
110
|
+
{"type":"driver","driver":"pymysql","host":"10.0.0.1","user":"ro","password":"${DB_PASS}","db":"bill_db"}
|
|
111
|
+
{"type":"http","url":"https://gw.example.com/query","token":"${DB_TOKEN}"}
|
|
112
|
+
{"type":"file","path":"schema.json"}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
仅允许 SELECT/EXPLAIN/DESC/SHOW;写操作一律拒绝。密码用 `${ENV_VAR}` 环境变量。
|
|
116
|
+
|
|
117
|
+
## Qoder 集成(2 步)
|
|
118
|
+
|
|
119
|
+
1. Qoder 插件管理 → 本地插件 → 选择 `d:\mtkit`
|
|
120
|
+
2. 对话输入:
|
|
121
|
+
- 生成用例:"用 mtkit 生成 XMind 测试用例:方案 xxx.docx,样例 xxx.xmind,后端仓库 xxx"
|
|
122
|
+
- 测试咨询:"这个功能怎么测?" / "线上报错了帮我看看" / "是不是 bug?"
|
|
123
|
+
|
|
124
|
+
## 技能时序
|
|
125
|
+
|
|
126
|
+
```mermaid
|
|
127
|
+
sequenceDiagram
|
|
128
|
+
participant U as 使用者
|
|
129
|
+
participant A as AI(测试构建者)
|
|
130
|
+
U->>A: 输入三件套 + 可选文档/db
|
|
131
|
+
A->>U: 文档体检(缺陷点+建议,逐条确认)
|
|
132
|
+
A->>A: gather + facts + 经验库加载
|
|
133
|
+
A->>U: 测试用例输出计划(设计方法+构建者建议)
|
|
134
|
+
U->>A: 授权(可增删调整)
|
|
135
|
+
A->>A: 生成契约 → 质量门禁 → 修正循环
|
|
136
|
+
A->>U: 用例调整建议(逐条确认)
|
|
137
|
+
A->>A: 渲染 XMind → 校验 → 漏测对比
|
|
138
|
+
A->>U: 交付(XMind/缺陷点汇总/工作痕迹)+ 训练沉淀
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## 迭代更新(editable 安装,无需重装)
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
pip install --force-reinstall --no-deps -e d:\mtkit # 仅在需要时
|
|
145
|
+
python -m unittest # 自检
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
- 插件侧:仓库文件更新即生效,仅 plugin.json 版本变化需重启 Qoder
|
|
149
|
+
- **自我迭代**:AI 使用中发现改进点会写入 `.mtkit-work/improvements.json`;在 `.mtkit.json` 开启 `auto_improve` 并授权后,AI 可自行优化并自验(详见 skills 文档)
|
|
150
|
+
- 详细说明:见 [CHANGELOG.md](CHANGELOG.md)、[skills/mtkit-gen-xmind/](skills/mtkit-gen-xmind/)(技能与规范)
|
mtkit-1.16.1/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# mtkit — AI 全站测试工程师
|
|
2
|
+
|
|
3
|
+
计划先行生成标准 XMind 测试用例(质量门禁把关),体检修复用例资产,交互式测试咨询与问题定位指导;使用即训练,越用越成熟。
|
|
4
|
+
|
|
5
|
+
## 流水线
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
flowchart LR
|
|
9
|
+
IN[输入: 方案.docx + 样例.xmind + 后端仓库 + 自定义文档] --> READ[读取与文档体检]
|
|
10
|
+
READ --> FACTS[代码事实扫描<br/>九语言接口/SQL]
|
|
11
|
+
FACTS --> PLAN[测试用例输出计划<br/>设计方法 + 构建者建议]
|
|
12
|
+
PLAN --> AUTH{授权}
|
|
13
|
+
AUTH -->|确认| CONTRACT[契约 JSON]
|
|
14
|
+
CONTRACT --> GATE[质量门禁<br/>review + AI 审查]
|
|
15
|
+
GATE --> RENDER[渲染 XMind]
|
|
16
|
+
RENDER --> CHECK[校验 + 漏测对比]
|
|
17
|
+
CHECK --> OUT[交付: XMind + 缺陷点汇总 + 工作痕迹]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 快速上手(零依赖)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# 1. 生成 XMind(纯标准库,无需任何安装)
|
|
24
|
+
cd d:\mtkit
|
|
25
|
+
mtkit gen -i examples/sample.json -o 用例.xmind
|
|
26
|
+
|
|
27
|
+
# 2. 校验与统计
|
|
28
|
+
mtkit validate -i 用例.xmind
|
|
29
|
+
mtkit info -i 用例.xmind
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
可选依赖(用到才装):`.docx` 解析 `pip install python-docx`;数据库直连 `pip install pymysql`。
|
|
33
|
+
|
|
34
|
+
## 一键安装(含 Qoder 插件注册与可选依赖)
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 方式一(推荐,新机器零门槛):PyPI 安装 CLI
|
|
38
|
+
pip install mtkit
|
|
39
|
+
|
|
40
|
+
# 方式二:仓库根目录执行(含可选依赖自动安装)
|
|
41
|
+
python install.py # 或双击 install.bat
|
|
42
|
+
|
|
43
|
+
# 方式三:输入 git 地址自动拉取安装
|
|
44
|
+
python install.py --git <git 地址> [--dir 目标目录]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
安装完成后**重启 Qoder**,对话框输入 `/` 应列出 mtkit-gen-xmind,或直接自然语言触发。
|
|
48
|
+
|
|
49
|
+
> Qoder 插件注册:`skills/`、`commands/` 不在 PyPI 包中,pip 安装后执行
|
|
50
|
+
> `mtkit install --git <git 地址>`(或先设置环境变量 `MTKIT_INSTALL_GIT`)拉取完整仓库并注册插件。
|
|
51
|
+
|
|
52
|
+
## 命令
|
|
53
|
+
|
|
54
|
+
| 命令 | 作用 | 示例 |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `gen` | 契约/数据 → .xmind | `mtkit gen -i 契约.json -o 用例.xmind` |
|
|
57
|
+
| `gather` | 方案+样例+代码 → 生成上下文 | `mtkit gather -i 方案.docx --hist 样例.xmind -r 后端 -o ctx.json` |
|
|
58
|
+
| `facts` | 九语言代码事实扫描 | `mtkit facts -r 后端 -o facts.json` |
|
|
59
|
+
| `review` | 契约质量门禁 | `mtkit review -i 契约.json -f facts.json` |
|
|
60
|
+
| `audit` | 用例资产体检(检索不合适用例) | `mtkit audit -i 旧用例.xmind -f facts.json` |
|
|
61
|
+
| `db` | 数据库只读接入(check/schema/verify) | `mtkit db verify -c db.json -i 契约.json` |
|
|
62
|
+
| `validate` / `info` | 校验 / 统计 .xmind | `mtkit validate -i 用例.xmind` |
|
|
63
|
+
| `diff` | 漏测对比 | `mtkit diff -i 用例.xmind -f facts.json -d 方案.docx` |
|
|
64
|
+
| `contract` / `tree` | 用例 ↔ 契约互转 / 还原树 | `mtkit contract -i 用例.xmind -o 契约.json` |
|
|
65
|
+
| `track` | 测试管理:执行记录/报告/趋势 | `mtkit track record --case 用例 --result pass` |
|
|
66
|
+
| `bug` | 缺陷库:登记/清单/关闭/统计 | `mtkit bug add --title 缺陷 --severity P1` |
|
|
67
|
+
| `evolve` | 自进化:备份/恢复/清单/清理 | `mtkit evolve backup 文件` |
|
|
68
|
+
| `asset` | 用例资产老化检测(治理) | `mtkit asset --dir 输出目录 --days 30` |
|
|
69
|
+
|
|
70
|
+
契约格式(唯一输入约定):
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{"chapters":[{"t":"章节","cases":[{"t":"tc-P0-功能测试:用例名",
|
|
74
|
+
"pc":["前置"],"steps":["步骤"],"expects":["预期"],"sql":["SELECT ..."]}]}]}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 数据库接入(可选,严格只读)
|
|
78
|
+
|
|
79
|
+
`db.json` 四种数据源(`type` 字段):
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{"type":"cli","connect":{"cmd":"mysql -h{host} -u{user} -p{pass} {db} -N -e \"{sql}\"","host":"10.0.0.1","user":"ro","pass":"${DB_PASS}","db":"bill_db"}}
|
|
83
|
+
{"type":"driver","driver":"pymysql","host":"10.0.0.1","user":"ro","password":"${DB_PASS}","db":"bill_db"}
|
|
84
|
+
{"type":"http","url":"https://gw.example.com/query","token":"${DB_TOKEN}"}
|
|
85
|
+
{"type":"file","path":"schema.json"}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
仅允许 SELECT/EXPLAIN/DESC/SHOW;写操作一律拒绝。密码用 `${ENV_VAR}` 环境变量。
|
|
89
|
+
|
|
90
|
+
## Qoder 集成(2 步)
|
|
91
|
+
|
|
92
|
+
1. Qoder 插件管理 → 本地插件 → 选择 `d:\mtkit`
|
|
93
|
+
2. 对话输入:
|
|
94
|
+
- 生成用例:"用 mtkit 生成 XMind 测试用例:方案 xxx.docx,样例 xxx.xmind,后端仓库 xxx"
|
|
95
|
+
- 测试咨询:"这个功能怎么测?" / "线上报错了帮我看看" / "是不是 bug?"
|
|
96
|
+
|
|
97
|
+
## 技能时序
|
|
98
|
+
|
|
99
|
+
```mermaid
|
|
100
|
+
sequenceDiagram
|
|
101
|
+
participant U as 使用者
|
|
102
|
+
participant A as AI(测试构建者)
|
|
103
|
+
U->>A: 输入三件套 + 可选文档/db
|
|
104
|
+
A->>U: 文档体检(缺陷点+建议,逐条确认)
|
|
105
|
+
A->>A: gather + facts + 经验库加载
|
|
106
|
+
A->>U: 测试用例输出计划(设计方法+构建者建议)
|
|
107
|
+
U->>A: 授权(可增删调整)
|
|
108
|
+
A->>A: 生成契约 → 质量门禁 → 修正循环
|
|
109
|
+
A->>U: 用例调整建议(逐条确认)
|
|
110
|
+
A->>A: 渲染 XMind → 校验 → 漏测对比
|
|
111
|
+
A->>U: 交付(XMind/缺陷点汇总/工作痕迹)+ 训练沉淀
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 迭代更新(editable 安装,无需重装)
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install --force-reinstall --no-deps -e d:\mtkit # 仅在需要时
|
|
118
|
+
python -m unittest # 自检
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
- 插件侧:仓库文件更新即生效,仅 plugin.json 版本变化需重启 Qoder
|
|
122
|
+
- **自我迭代**:AI 使用中发现改进点会写入 `.mtkit-work/improvements.json`;在 `.mtkit.json` 开启 `auto_improve` 并授权后,AI 可自行优化并自验(详见 skills 文档)
|
|
123
|
+
- 详细说明:见 [CHANGELOG.md](CHANGELOG.md)、[skills/mtkit-gen-xmind/](skills/mtkit-gen-xmind/)(技能与规范)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
mtkit - AI 全站测试工程师
|
|
4
|
+
|
|
5
|
+
生成模式:计划先行(含测试设计方法)→ 授权 → 契约 → 质量门禁 → 标准 XMind 用例;
|
|
6
|
+
指导模式:测试答疑/问题定位/缺陷研判/需求澄清/回归建议,交互式指导。
|
|
7
|
+
使用即训练、授权后可自我迭代。
|
|
8
|
+
|
|
9
|
+
约定:
|
|
10
|
+
- 节点为 dict: {"t": 标题, "c": [子节点...]},子节点可省略;也兼容 (标题, [子节点]) 元组树与字符串叶子
|
|
11
|
+
- 用例节点标题以 "tc-" 开头,描述风格两种:
|
|
12
|
+
zen 风格(pc: / 步骤: / 预期: 平铺行)与 history 风格(操作步骤/预期结果 多级节点)
|
|
13
|
+
- 输出为 XMind Zen 格式(标准 zip,含 content.json / metadata.json / manifest.json)
|
|
14
|
+
|
|
15
|
+
用法:
|
|
16
|
+
mtkit gen -i cases.json -o out.xmind
|
|
17
|
+
mtkit gen-doc -i 方案.docx --hist 历史.xmind -o out.xmind # 骨架(无 LLM)
|
|
18
|
+
mtkit gen-doc -i 方案.docx --llm http --endpoint ... -o out.xmind # LLM 生成
|
|
19
|
+
mtkit facts -r 代码仓库 -o facts.json
|
|
20
|
+
mtkit diff -i out.xmind -f facts.json -d 方案.docx
|
|
21
|
+
mtkit validate -i out.xmind
|
|
22
|
+
mtkit info -i out.xmind
|
|
23
|
+
mtkit db check -c db.json # 数据库接入(严格只读)
|
|
24
|
+
mtkit db schema -c db.json -o schema.json
|
|
25
|
+
mtkit db verify -c db.json -i 契约.json
|
|
26
|
+
mtkit review -i 契约.json -f facts.json # 契约质量门禁
|
|
27
|
+
mtkit audit -i 用例.xmind # 用例资产体检
|
|
28
|
+
"""
|
|
29
|
+
__version__ = "1.16.1"
|
|
30
|
+
|
|
31
|
+
from .builder import build_sheet
|
|
32
|
+
from .validator import check_tree
|
|
33
|
+
from .writer import write_xmind, read_xmind
|
|
34
|
+
from . import tb
|
|
35
|
+
|
|
36
|
+
__all__ = ["build_sheet", "check_tree", "write_xmind", "read_xmind", "tb", "__version__"]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Case asset metadata: sidecar written at render time, supports asset stale detection.
|
|
4
|
+
|
|
5
|
+
Metadata file: <xmind path>.meta.json (does not touch the xmind structure)
|
|
6
|
+
{
|
|
7
|
+
"asset": "xxx.xmind",
|
|
8
|
+
"generated_at": "2026-11-25T10:00:00",
|
|
9
|
+
"tool_version": "1.15.7",
|
|
10
|
+
"facts_hash": "md5 first 12 chars (optional)",
|
|
11
|
+
"case_count": 120,
|
|
12
|
+
"audited_at": "last audit time (optional)"
|
|
13
|
+
}
|
|
14
|
+
"""
|
|
15
|
+
import hashlib
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
from datetime import datetime
|
|
19
|
+
|
|
20
|
+
META_SUFFIX = ".meta.json"
|
|
21
|
+
STALE_DEFAULT_DAYS = 30
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def write_meta(asset_path, case_count=0, facts_hash="", tool_version="", audited=False):
|
|
25
|
+
"""Write/update asset metadata sidecar (create if missing), return metadata path."""
|
|
26
|
+
meta_path = asset_path + META_SUFFIX
|
|
27
|
+
meta = read_meta(asset_path) or {}
|
|
28
|
+
meta.setdefault("asset", os.path.basename(asset_path))
|
|
29
|
+
meta["case_count"] = case_count
|
|
30
|
+
if facts_hash:
|
|
31
|
+
meta["facts_hash"] = facts_hash
|
|
32
|
+
if tool_version:
|
|
33
|
+
meta["tool_version"] = tool_version
|
|
34
|
+
meta["generated_at"] = meta.get("generated_at") or datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
|
|
35
|
+
if audited:
|
|
36
|
+
meta["audited_at"] = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
|
|
37
|
+
with open(meta_path, "w", encoding="utf-8") as fp:
|
|
38
|
+
json.dump(meta, fp, ensure_ascii=False, indent=2)
|
|
39
|
+
return meta_path
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def read_meta(asset_path):
|
|
43
|
+
"""Read asset metadata (return None when missing)."""
|
|
44
|
+
meta_path = asset_path + META_SUFFIX
|
|
45
|
+
if not os.path.isfile(meta_path):
|
|
46
|
+
return None
|
|
47
|
+
with open(meta_path, "r", encoding="utf-8-sig") as fp:
|
|
48
|
+
return json.load(fp)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def facts_digest(facts):
|
|
52
|
+
"""facts summary hash (md5 first 12 chars), marks the code-facts version of the asset."""
|
|
53
|
+
payload = json.dumps(facts or {}, ensure_ascii=False, sort_keys=True, default=str)
|
|
54
|
+
return hashlib.md5(payload.encode("utf-8")).hexdigest()[:12]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def asset_age_days(asset_path, now=None):
|
|
58
|
+
"""Asset age in days: prefer metadata audited_at/generated_at, else file mtime."""
|
|
59
|
+
meta = read_meta(asset_path)
|
|
60
|
+
stamp = None
|
|
61
|
+
last = None
|
|
62
|
+
if meta:
|
|
63
|
+
stamp = meta.get("audited_at") or meta.get("generated_at")
|
|
64
|
+
if stamp:
|
|
65
|
+
try:
|
|
66
|
+
last = datetime.strptime(stamp[:19], "%Y-%m-%dT%H:%M:%S")
|
|
67
|
+
except ValueError:
|
|
68
|
+
last = None
|
|
69
|
+
if last is None and os.path.isfile(asset_path):
|
|
70
|
+
last = datetime.fromtimestamp(os.path.getmtime(asset_path))
|
|
71
|
+
if last is None:
|
|
72
|
+
return 0
|
|
73
|
+
now = now or datetime.now()
|
|
74
|
+
days = (now - last).days
|
|
75
|
+
return days if days > 0 else 0
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def stale_assets(directory, stale_days=STALE_DEFAULT_DAYS, now=None):
|
|
79
|
+
"""Scan .xmind assets under a directory, return those unaudited for more than stale_days.
|
|
80
|
+
|
|
81
|
+
Discovery is dual-source: .xmind files plus orphan .meta.json sidecars.
|
|
82
|
+
|
|
83
|
+
:return: [{"asset": path, "age_days": n, "meta": metadata or None}]
|
|
84
|
+
"""
|
|
85
|
+
results = []
|
|
86
|
+
if not os.path.isdir(directory):
|
|
87
|
+
return results
|
|
88
|
+
assets = set()
|
|
89
|
+
for root, dirs, files in os.walk(directory):
|
|
90
|
+
for name in files:
|
|
91
|
+
if name.endswith(".xmind"):
|
|
92
|
+
assets.add(os.path.join(root, name))
|
|
93
|
+
elif name.endswith(META_SUFFIX):
|
|
94
|
+
# orphan sidecar without the .xmind file itself
|
|
95
|
+
asset = os.path.join(root, name[: -len(META_SUFFIX)])
|
|
96
|
+
assets.add(asset)
|
|
97
|
+
for asset in sorted(assets):
|
|
98
|
+
age = asset_age_days(asset, now=now)
|
|
99
|
+
if age > stale_days:
|
|
100
|
+
results.append({"asset": asset, "age_days": age, "meta": read_meta(asset)})
|
|
101
|
+
return results
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Case asset audit: rule-level checks on an existing case tree (read from .xmind), finding unsuitable cases.
|
|
4
|
+
|
|
5
|
+
check items:
|
|
6
|
+
1. structure issues: reuse validator.check_tree (case nodes missing pc/steps/expects, non-compliant titles)
|
|
7
|
+
2. SQL readonly & executability: 「SQL核对」 nodes in the tree checked one by one (write ops rejected; missing tables/columns fail)
|
|
8
|
+
3. coverage gaps: reuse coverage.compare_interfaces/compare_features (interfaces/features vs case tree)
|
|
9
|
+
4. granularity outliers: cases with >8 steps or >200-char expect text flagged as 「粒度存疑」
|
|
10
|
+
|
|
11
|
+
product: issue list + coverage matrix + granularity stats; caller exits 1 when issues exist.
|
|
12
|
+
"""
|
|
13
|
+
import re
|
|
14
|
+
|
|
15
|
+
from .builder import CASE_TITLE_PATTERN
|
|
16
|
+
from .coverage import compare_features, compare_interfaces
|
|
17
|
+
from .db import check_readonly
|
|
18
|
+
from .normalize import SQL_TITLE_PATTERN, detect_style
|
|
19
|
+
from .validator import check_tree
|
|
20
|
+
|
|
21
|
+
MAX_STEPS = 8
|
|
22
|
+
MAX_EXPECT_LEN = 200
|
|
23
|
+
|
|
24
|
+
# circled numbers inside zen style step lines
|
|
25
|
+
_CIRCLE_STEP_PATTERN = re.compile(r"[①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮]")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def extract_sqls_from_tree(tree):
|
|
29
|
+
"""Walk the case tree, collect (case_title, sql_text).
|
|
30
|
+
|
|
31
|
+
- zen style: node title 「SQL核对: SELECT ...」, take the text after the colon
|
|
32
|
+
- history style: child node text of the 「SQL核对」 node
|
|
33
|
+
"""
|
|
34
|
+
results = []
|
|
35
|
+
|
|
36
|
+
def walk(nodes, case_title=""):
|
|
37
|
+
for node in nodes:
|
|
38
|
+
title = node.get("t") or ""
|
|
39
|
+
if CASE_TITLE_PATTERN.match(title):
|
|
40
|
+
case_title = title
|
|
41
|
+
if SQL_TITLE_PATTERN.search(title):
|
|
42
|
+
text = re.sub(r"^\s*SQL核对[::]?\s*", "", title, flags=re.IGNORECASE).strip()
|
|
43
|
+
if not text:
|
|
44
|
+
for child in node.get("c") or []:
|
|
45
|
+
text = (child.get("t") or "").strip()
|
|
46
|
+
if text:
|
|
47
|
+
break
|
|
48
|
+
if text:
|
|
49
|
+
results.append((case_title, text))
|
|
50
|
+
walk(node.get("c") or [], case_title)
|
|
51
|
+
|
|
52
|
+
walk(tree)
|
|
53
|
+
return results
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _count_steps(case_node):
|
|
57
|
+
"""Count steps in a case node subtree (zen circled numbers / history child count)."""
|
|
58
|
+
def walk(nodes, steps):
|
|
59
|
+
for node in nodes:
|
|
60
|
+
title = node.get("t") or ""
|
|
61
|
+
if title.startswith("步骤:") or title.startswith("操作步骤"):
|
|
62
|
+
circles = _CIRCLE_STEP_PATTERN.findall(title)
|
|
63
|
+
if circles:
|
|
64
|
+
steps[0] = max(steps[0], len(circles))
|
|
65
|
+
else:
|
|
66
|
+
children = node.get("c") or []
|
|
67
|
+
steps[0] = max(steps[0], len(children))
|
|
68
|
+
walk(node.get("c") or [], steps)
|
|
69
|
+
|
|
70
|
+
steps = [0]
|
|
71
|
+
walk(case_node.get("c") or [], steps)
|
|
72
|
+
return steps[0]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _expect_length(case_node):
|
|
76
|
+
"""Total expect text length of a case node subtree (zen line length / history subtree join)."""
|
|
77
|
+
def walk(nodes, length):
|
|
78
|
+
for node in nodes:
|
|
79
|
+
title = node.get("t") or ""
|
|
80
|
+
if title.startswith("预期:") or title.startswith("预期结果"):
|
|
81
|
+
length[0] = max(length[0], len(title))
|
|
82
|
+
walk(node.get("c") or [], length)
|
|
83
|
+
else:
|
|
84
|
+
walk(node.get("c") or [], length)
|
|
85
|
+
|
|
86
|
+
length = [0]
|
|
87
|
+
walk(case_node.get("c") or [], length)
|
|
88
|
+
return length[0]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def grain_stats(tree):
|
|
92
|
+
"""Case granularity stats: per-case steps/expect length, flag outlier cases."""
|
|
93
|
+
cases = []
|
|
94
|
+
outliers = []
|
|
95
|
+
|
|
96
|
+
def walk(nodes):
|
|
97
|
+
for node in nodes:
|
|
98
|
+
title = node.get("t") or ""
|
|
99
|
+
if CASE_TITLE_PATTERN.match(title):
|
|
100
|
+
steps = _count_steps(node)
|
|
101
|
+
expect_len = _expect_length(node)
|
|
102
|
+
cases.append({"case": title, "steps": steps, "expect_len": expect_len})
|
|
103
|
+
if steps > MAX_STEPS:
|
|
104
|
+
outliers.append({"case": title,
|
|
105
|
+
"message": "步骤数 %d 超过 %d,粒度存疑" % (steps, MAX_STEPS)})
|
|
106
|
+
if expect_len > MAX_EXPECT_LEN:
|
|
107
|
+
outliers.append({"case": title,
|
|
108
|
+
"message": "预期文本 %d 字超过 %d,粒度存疑" % (expect_len, MAX_EXPECT_LEN)})
|
|
109
|
+
walk(node.get("c") or [])
|
|
110
|
+
|
|
111
|
+
walk(tree)
|
|
112
|
+
return {"cases": cases, "outliers": outliers,
|
|
113
|
+
"max_steps": MAX_STEPS, "max_expect_len": MAX_EXPECT_LEN}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def audit_xmind(tree, facts=None, provider=None, style=None):
|
|
117
|
+
"""Audit main entry.
|
|
118
|
+
|
|
119
|
+
:param tree: case tree (read_tree output)
|
|
120
|
+
:param facts: facts.json output (optional)
|
|
121
|
+
:param provider: database provider (optional, SQL executability check)
|
|
122
|
+
:param style: zen/history (auto detect by default)
|
|
123
|
+
:return: {issues: [{case, rule, message}], coverage: {...}, stats: {...}}
|
|
124
|
+
"""
|
|
125
|
+
style = style or detect_style(tree)
|
|
126
|
+
facts = facts or {}
|
|
127
|
+
issues = []
|
|
128
|
+
|
|
129
|
+
# 1. structure
|
|
130
|
+
for message in check_tree(tree, style=style):
|
|
131
|
+
issues.append({"case": "", "rule": "结构", "message": message})
|
|
132
|
+
|
|
133
|
+
# 2. SQL readonly & executability
|
|
134
|
+
for case_title, sql in extract_sqls_from_tree(tree):
|
|
135
|
+
ok, reason = check_readonly(sql)
|
|
136
|
+
if not ok:
|
|
137
|
+
issues.append({"case": case_title, "rule": "SQL只读", "message": reason})
|
|
138
|
+
continue
|
|
139
|
+
if provider is not None:
|
|
140
|
+
try:
|
|
141
|
+
provider.explain(sql)
|
|
142
|
+
except Exception as exc:
|
|
143
|
+
issues.append({"case": case_title, "rule": "SQL可执行", "message": str(exc)})
|
|
144
|
+
|
|
145
|
+
# 3. coverage gaps
|
|
146
|
+
coverage = {
|
|
147
|
+
"interfaces": compare_interfaces(facts, tree) if facts.get("interfaces") else {"covered": [], "missing": []},
|
|
148
|
+
"features": compare_features(facts, tree) if facts.get("features") else {"covered": [], "missing": []},
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
# 4. granularity outliers
|
|
152
|
+
stats = grain_stats(tree)
|
|
153
|
+
for outlier in stats["outliers"]:
|
|
154
|
+
issues.append({"case": outlier["case"], "rule": "粒度", "message": outlier["message"]})
|
|
155
|
+
|
|
156
|
+
return {"issues": issues, "coverage": coverage, "stats": stats}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def render_audit_report(result):
|
|
160
|
+
"""Audit report markdown."""
|
|
161
|
+
issues = result["issues"]
|
|
162
|
+
coverage = result["coverage"]
|
|
163
|
+
stats = result["stats"]
|
|
164
|
+
lines = ["用例资产体检报告", ""]
|
|
165
|
+
lines.append("| 检查项 | 结果 |")
|
|
166
|
+
lines.append("|---|---|")
|
|
167
|
+
lines.append("| 用例总数 | %d |" % len(stats["cases"]))
|
|
168
|
+
lines.append("| 问题总数 | %d |" % len(issues))
|
|
169
|
+
lines.append("| 接口覆盖 | %d/%d |" % (
|
|
170
|
+
len(coverage["interfaces"]["covered"]),
|
|
171
|
+
len(coverage["interfaces"]["covered"]) + len(coverage["interfaces"]["missing"])))
|
|
172
|
+
lines.append("| 功能点覆盖 | %d/%d |" % (
|
|
173
|
+
len(coverage["features"]["covered"]),
|
|
174
|
+
len(coverage["features"]["covered"]) + len(coverage["features"]["missing"])))
|
|
175
|
+
lines.append("")
|
|
176
|
+
if issues:
|
|
177
|
+
lines.append("## 问题清单")
|
|
178
|
+
lines.append("")
|
|
179
|
+
by_rule = {}
|
|
180
|
+
for issue in issues:
|
|
181
|
+
by_rule.setdefault(issue["rule"], []).append(issue)
|
|
182
|
+
for rule in ("结构", "SQL只读", "SQL可执行", "粒度"):
|
|
183
|
+
for issue in by_rule.pop(rule, []):
|
|
184
|
+
lines.append("- [%s] %s | %s" % (issue["rule"], issue["case"], issue["message"]))
|
|
185
|
+
for rule, items in by_rule.items():
|
|
186
|
+
for issue in items:
|
|
187
|
+
lines.append("- [%s] %s | %s" % (issue["rule"], issue["case"], issue["message"]))
|
|
188
|
+
lines.append("")
|
|
189
|
+
else:
|
|
190
|
+
lines.append("## 问题清单")
|
|
191
|
+
lines.append("")
|
|
192
|
+
lines.append("无问题")
|
|
193
|
+
lines.append("")
|
|
194
|
+
lines.append("## 覆盖矩阵")
|
|
195
|
+
lines.append("")
|
|
196
|
+
for key, label in (("interfaces", "接口"), ("features", "功能点")):
|
|
197
|
+
missing = coverage[key]["missing"]
|
|
198
|
+
covered = coverage[key]["covered"]
|
|
199
|
+
if covered:
|
|
200
|
+
lines.append("%s已覆盖:" % label)
|
|
201
|
+
for item in covered:
|
|
202
|
+
lines.append("- %s" % (item[0] if isinstance(item, (list, tuple)) else item))
|
|
203
|
+
lines.append("")
|
|
204
|
+
if missing:
|
|
205
|
+
lines.append("%s未覆盖:" % label)
|
|
206
|
+
for item in missing:
|
|
207
|
+
lines.append("- %s" % item)
|
|
208
|
+
lines.append("")
|
|
209
|
+
if not covered and not missing:
|
|
210
|
+
lines.append("%s:无对比数据" % label)
|
|
211
|
+
lines.append("")
|
|
212
|
+
lines.append("## 粒度统计")
|
|
213
|
+
lines.append("")
|
|
214
|
+
lines.append("| 用例 | 步骤数 | 预期长度 |")
|
|
215
|
+
lines.append("|---|---|---|")
|
|
216
|
+
for item in stats["cases"]:
|
|
217
|
+
lines.append("| %s | %s | %s |" % (item["case"], item["steps"] or "-", item["expect_len"] or "-"))
|
|
218
|
+
lines.append("")
|
|
219
|
+
lines.append("阈值:步骤 >%d 或预期 >%d 字标记粒度存疑" % (stats["max_steps"], stats["max_expect_len"]))
|
|
220
|
+
return "\n".join(lines)
|