mtkit 1.16.1__py3-none-any.whl

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/parsers.py ADDED
@@ -0,0 +1,318 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Input parsing module: supports three case data sources, unified into (root_title, tree)
4
+
5
+ 1. JSON file: {"root": "root title", "tree": [{t=..., c=[...]}, ...]} or a bare array
6
+ 2. Python module: the file defines a data variable (default TREE) and optional ROOT root title
7
+ 3. Markdown table: 3/4/5 column adapt (no/case/[precondition/scenario/steps]/expect), headings before the table become chapters
8
+ """
9
+ import importlib.util
10
+ import json
11
+ import os
12
+ import re
13
+ import sys
14
+
15
+ DEFAULT_MODULE_VAR = "TREE"
16
+ DEFAULT_ROOT_TITLE = "测试用例"
17
+
18
+ # markdown table header -> column role (case-insensitive fuzzy match)
19
+ _HEADER_ROLES = {
20
+ "编号": "no",
21
+ "用例": "name",
22
+ "用例名": "name",
23
+ "用例名称": "name",
24
+ "前置": "pc",
25
+ "前置条件": "pc",
26
+ "场景": "scene",
27
+ "步骤": "steps",
28
+ "预期": "expect",
29
+ "预期结果": "expect",
30
+ "sql核对": "sql",
31
+ "实际": "actual",
32
+ }
33
+
34
+ # circled numbers: 1-20 as ①-⑳, beyond that use parens
35
+ _CIRCLED = "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳"
36
+
37
+ # leading segment number: 1. / 1、 / 1) etc
38
+ _NUMBER_PATTERN = re.compile(r"^\s*(\d+)\s*[.、))]\s*")
39
+
40
+
41
+ def circle_number(number):
42
+ """Convert a number into a circled number (1-20 as ①-⑳, beyond that as (n))"""
43
+ if 1 <= number <= len(_CIRCLED):
44
+ return _CIRCLED[number - 1]
45
+ return "(%d)" % number
46
+
47
+
48
+ def circle_text(text, sep=";"):
49
+ """把文本中的段首编号转为圆圈编号。
50
+
51
+ 输入如 "1. aaa;2. bbb\n3. ccc",输出 "①aaa;②bbb;③ccc";
52
+ 句号+编号边界(如 "aaa。2. bbb")也切分,但保留原句号不额外插 sep;
53
+ 无编号的整段文本自动补 ① 前缀。
54
+
55
+ :param text: 原始文本
56
+ :param sep: 段间连接符
57
+ :return: 转换后的文本
58
+ """
59
+ if not text or not text.strip():
60
+ return text
61
+ # tokenize: explicit separators (;;newline) -> sep; period/。 + numbered boundary -> keep original text
62
+ tokens = []
63
+ buffer = ""
64
+ index = 0
65
+ length = len(text)
66
+ while index < length:
67
+ ch = text[index]
68
+ if ch in ";;" or ch == "\n":
69
+ if buffer.strip():
70
+ tokens.append(("text", buffer.strip()))
71
+ tokens.append(("sep", sep))
72
+ buffer = ""
73
+ index += 1
74
+ continue
75
+ # period (。/.) followed by a number boundary: e.g. aaa。2. bbb
76
+ boundary = re.match(r"[。.]\s*(?=\d+\s*[.、])", text[index:])
77
+ if boundary:
78
+ if buffer.strip():
79
+ tokens.append(("text", buffer.strip()))
80
+ tokens.append(("sep", boundary.group(0)))
81
+ buffer = ""
82
+ index += len(boundary.group(0))
83
+ continue
84
+ buffer += ch
85
+ index += 1
86
+ if buffer.strip():
87
+ tokens.append(("text", buffer.strip()))
88
+ # numbers -> circled
89
+ circled = []
90
+ for kind, value in tokens:
91
+ if kind == "sep":
92
+ circled.append(("sep", value))
93
+ continue
94
+ match = _NUMBER_PATTERN.match(value)
95
+ if match:
96
+ number = int(match.group(1))
97
+ circled.append(("text", circle_number(number) + value[match.end():]))
98
+ else:
99
+ circled.append(("text", value))
100
+ # single uncircled segment auto-prefixes ① (judged on original text to avoid double prefix)
101
+ original_texts = [v for k, v in tokens if k == "text"]
102
+ if len(original_texts) == 1 and not _NUMBER_PATTERN.match(original_texts[0]):
103
+ circled[0] = ("text", "①" + circled[0][1])
104
+ return "".join(value for _, value in circled)
105
+
106
+
107
+ def _priority_from_no(no):
108
+ """Parse priority P0/P1/P2 from the number column, default P1"""
109
+ if no:
110
+ for level in ("P0", "P1", "P2"):
111
+ if level in no.upper():
112
+ return level
113
+ return "P1"
114
+
115
+
116
+ def parse_json_file(path):
117
+ """解析 JSON 用例文件。
118
+
119
+ 支持三种结构:
120
+ {"root": "根标题", "tree": [...]} 或直接 [{t=..., c=[...]}, ...]
121
+ {"chapters": [...]} # LLM/Agent 输出契约格式(自动转换为用例树)
122
+
123
+ :return: (root_title, tree)
124
+ """
125
+ with open(path, encoding="utf-8") as fp:
126
+ data = json.load(fp)
127
+ return _parse_json_data(data)
128
+
129
+
130
+ def parse_json_text(text):
131
+ """解析 JSON 文本(stdin 输入用),规则与 parse_json_file 一致。
132
+
133
+ :param text: JSON 文本
134
+ :return: (root_title, tree)
135
+ """
136
+ return _parse_json_data(json.loads(text))
137
+
138
+
139
+ def _parse_json_data(data):
140
+ """Parse JSON data (shared by file/stdin)."""
141
+ if isinstance(data, dict) and "chapters" in data:
142
+ # LLM/agent output contract format -> zen style case tree
143
+ from .generate.llm import contract_to_tree
144
+
145
+ tree = contract_to_tree(data)
146
+ return data.get("root") or DEFAULT_ROOT_TITLE, tree
147
+ if isinstance(data, dict):
148
+ tree = data.get("tree") or []
149
+ root_title = data.get("root") or DEFAULT_ROOT_TITLE
150
+ elif isinstance(data, list):
151
+ tree = data
152
+ root_title = DEFAULT_ROOT_TITLE
153
+ else:
154
+ raise ValueError("JSON 结构不支持: 应为对象或数组")
155
+ return root_title, tree
156
+
157
+
158
+ def parse_python_file(path, module_var=DEFAULT_MODULE_VAR):
159
+ """加载 Python 模块并取用例树变量。
160
+
161
+ 模块中可定义:
162
+ TREE = [{t=..., c=[...]}, ...] # 用例树(必选)
163
+ ROOT = "根标题" # 根节点标题(可选)
164
+
165
+ :param path: .py 文件路径
166
+ :param module_var: 用例树变量名,默认 TREE
167
+ :return: (root_title, tree)
168
+ """
169
+ module_name = "mtkit_input_%s" % os.path.splitext(os.path.basename(path))[0]
170
+ # add the input file dir to sys.path for relative imports inside the module (e.g. from data_part1 import TREE)
171
+ module_dir = os.path.dirname(os.path.abspath(path))
172
+ if module_dir not in sys.path:
173
+ sys.path.insert(0, module_dir)
174
+ spec = importlib.util.spec_from_file_location(module_name, path)
175
+ module = importlib.util.module_from_spec(spec)
176
+ spec.loader.exec_module(module)
177
+ tree = getattr(module, module_var, None)
178
+ if tree is None:
179
+ raise ValueError("模块中未找到用例树变量 %s: %s" % (module_var, path))
180
+ root_title = getattr(module, "ROOT", None) or DEFAULT_ROOT_TITLE
181
+ return root_title, tree
182
+
183
+
184
+ def parse_markdown(path, root_title=None, case_type="功能测试"):
185
+ """解析 Markdown 用例表格。
186
+
187
+ 规则:
188
+ - 表格块(连续 | 行)前的最近一个 # 标题作为该表格的章节;
189
+ 全文第一个 # 标题作为根标题(可用 root_title 覆盖)
190
+ - 表头按列名识别:编号/用例/(前置|场景|步骤)/预期,3 列时场景列不存在
191
+ - 4 列(编号/用例/场景/预期)时,场景并入步骤
192
+ - 用例标题格式: tc-P{级别}-{类型}:{用例名}
193
+
194
+ :param path: .md 文件路径
195
+ :param root_title: 根节点标题,缺省取文件第一个 # 标题或默认值
196
+ :param case_type: 用例类型(如 功能测试/接口测试)
197
+ :return: (root_title, tree)
198
+ """
199
+ with open(path, encoding="utf-8") as fp:
200
+ lines = fp.read().splitlines()
201
+
202
+ detected_root = None
203
+ sections = [] # [(章节标题, [数据行])]
204
+ current_section = None
205
+ current_table = None
206
+ in_table = False
207
+
208
+ for line in lines:
209
+ stripped = line.strip()
210
+ if stripped.startswith("#"):
211
+ heading = stripped.lstrip("#").strip()
212
+ if detected_root is None:
213
+ detected_root = heading
214
+ current_section = None
215
+ else:
216
+ current_section = heading
217
+ if not any(s[0] == heading for s in sections):
218
+ sections.append([heading, []])
219
+ continue
220
+ if stripped.startswith("|"):
221
+ cells = [c.strip() for c in stripped.strip("|").split("|")]
222
+ if not in_table:
223
+ current_table = {"header": cells, "rows": []}
224
+ in_table = True
225
+ else:
226
+ # skip separator lines (---)
227
+ if all(re.fullmatch(r":?-{2,}:?", c) for c in cells):
228
+ continue
229
+ if current_section is None:
230
+ current_section = "未命名章节"
231
+ if not any(s[0] == current_section for s in sections):
232
+ sections.append([current_section, []])
233
+ for entry in sections:
234
+ if entry[0] == current_section:
235
+ entry[1].append((current_table, cells))
236
+ break
237
+ else:
238
+ sections.append([current_section, [(current_table, cells)]])
239
+ else:
240
+ in_table = False
241
+ current_table = None
242
+
243
+ tree = []
244
+ for section_title, rows in sections:
245
+ cases = []
246
+ for table, row in rows:
247
+ case_node = _row_to_case(table["header"], row, case_type)
248
+ if case_node is not None:
249
+ cases.append(case_node)
250
+ if cases:
251
+ tree.append({"t": section_title, "c": cases})
252
+ return root_title or detected_root or DEFAULT_ROOT_TITLE, tree
253
+
254
+
255
+ def _row_to_case(header, row, case_type):
256
+ """Convert one table row into a case node; return None to skip (empty row / reused header)"""
257
+ cells = dict(zip(header, row))
258
+ no = cells.get("编号") or ""
259
+ name = cells.get("用例") or cells.get("用例名") or cells.get("用例名称") or ""
260
+ if not name or no.startswith("编号"):
261
+ return None
262
+
263
+ children = []
264
+ pc = cells.get("前置") or cells.get("前置条件") or ""
265
+ if pc:
266
+ children.append({"t": "pc: " + circle_text(pc)})
267
+ steps = cells.get("步骤") or cells.get("场景") or ""
268
+ if steps:
269
+ children.append({"t": "步骤: " + circle_text(steps)})
270
+ expect = cells.get("预期") or cells.get("预期结果") or ""
271
+ if expect:
272
+ children.append({"t": "预期: " + circle_text(expect)})
273
+ sql = cells.get("sql核对") or ""
274
+ if sql:
275
+ children.append({"t": "SQL核对: " + sql})
276
+ actual = cells.get("实际") or ""
277
+ if actual:
278
+ children.append({"t": "实际: " + actual})
279
+
280
+ level = _priority_from_no(no)
281
+ title = "tc-%s-%s:%s" % (level, case_type, name)
282
+ return {"t": title, "c": children}
283
+
284
+
285
+ def parse_input(path, module_var=DEFAULT_MODULE_VAR, root_title=None, case_type="功能测试"):
286
+ """按文件扩展名分派解析,统一返回 (root_title, tree)。
287
+
288
+ :param path: 输入文件(.json / .py / .md),或 "-" 表示从标准输入读 JSON
289
+ :param module_var: .py 文件中的用例树变量名,默认 TREE
290
+ :param root_title: 覆盖根节点标题(仅 .md/.json 生效;.py 用模块内 ROOT)
291
+ :param case_type: .md 用例类型
292
+ :return: (root_title, tree)
293
+ """
294
+ if path == "-":
295
+ # stdin (piped JSON text, convenient for direct agent/LLM rendering)
296
+ # read bytes with multi-encoding fallback (Windows pipes often emit GBK/UTF-16)
297
+ data_bytes = sys.stdin.buffer.read()
298
+ text = None
299
+ for encoding in ("utf-8-sig", "utf-8", "utf-16", "gbk"):
300
+ try:
301
+ text = data_bytes.decode(encoding)
302
+ break
303
+ except (UnicodeDecodeError, UnicodeError):
304
+ continue
305
+ if text is None:
306
+ text = data_bytes.decode("utf-8", errors="replace")
307
+ parsed_root, tree = parse_json_text(text)
308
+ return root_title or parsed_root, tree
309
+ ext = os.path.splitext(path)[1].lower()
310
+ if ext == ".json":
311
+ parsed_root, tree = parse_json_file(path)
312
+ elif ext == ".py":
313
+ parsed_root, tree = parse_python_file(path, module_var)
314
+ elif ext in (".md", ".markdown"):
315
+ parsed_root, tree = parse_markdown(path, root_title, case_type)
316
+ else:
317
+ raise ValueError("不支持的输入类型: %s(仅支持 .json/.py/.md/或 - 标准输入)" % ext)
318
+ return root_title or parsed_root, tree
mtkit/review.py ADDED
@@ -0,0 +1,274 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Contract quality gate (rule engine): deterministic checks on the contract JSON before rendering.
4
+
5
+ check items:
6
+ 1. structure consistency: each case has the same steps/expects count (contract requires 1:1 pairing)
7
+ 2. SQL source traceability: contract sql table names must be traceable in facts (sqls/db_schema)
8
+ 3. column-level check: with db configured, SELECT column names are compared against schema columns
9
+ 4. coverage matrix: contract cases vs facts features/interfaces, output the 「requirement->case」 mapping and the missing list
10
+
11
+ product: issue list + coverage matrix markdown; caller exits 1 when issues exist.
12
+ """
13
+ import json
14
+ import re
15
+
16
+ from .db import columns_of, qualified_columns, tables_of
17
+
18
+
19
+ # methodology badge -> required evidence extraction
20
+ _NUMBER_PATTERN = re.compile(r"\d+")
21
+ _METHOD_PATTERN = re.compile(r"[((]([^))]+)[))]")
22
+ _TRANSITION_WORDS = ("状态迁移", "状态流转", "状态转换")
23
+ _BOUNDARY_WORDS = ("边界值", "边界")
24
+ _EQUIVALENCE_WORDS = ("等价类", "等价")
25
+ _ENUM_COVERAGE_WORDS = ("枚举覆盖", "枚举")
26
+
27
+
28
+ # column extraction from SELECT (between SELECT and FROM, comma separated) -- moved down to db.columns_of
29
+
30
+
31
+ def _load_json(path):
32
+ with open(path, "r", encoding="utf-8-sig") as fp:
33
+ return json.load(fp)
34
+
35
+
36
+ def _iter_cases(contract):
37
+ for chapter in contract.get("chapters") or []:
38
+ for case in chapter.get("cases") or []:
39
+ yield case
40
+
41
+
42
+ def check_structure(contract):
43
+ """Structure consistency: steps/expects counts match, titles compliant.
44
+
45
+ :return: issues list ([{case, rule, message}])
46
+ """
47
+ issues = []
48
+ for chapter in contract.get("chapters") or []:
49
+ for case in chapter.get("cases") or []:
50
+ title = case.get("t") or ""
51
+ steps = case.get("steps") or []
52
+ expects = case.get("expects") or []
53
+ if not title.startswith("tc-"):
54
+ issues.append({"case": title or "(无标题)", "rule": "标题",
55
+ "message": "用例标题必须以 tc- 开头"})
56
+ if len(steps) != len(expects):
57
+ issues.append({"case": title, "rule": "结构",
58
+ "message": "steps(%d 条)与 expects(%d 条)条数不一致" % (len(steps), len(expects))})
59
+ if not steps or not expects:
60
+ issues.append({"case": title, "rule": "结构",
61
+ "message": "steps/expects 不能为空"})
62
+ return issues
63
+
64
+
65
+ def check_sql_traceability(contract, facts):
66
+ """SQL source traceability: contract sql table names must appear in facts (sqls/db_schema).
67
+
68
+ :param facts: facts.json output (with sqls/db_schema), may be None
69
+ """
70
+ issues = []
71
+ known_tables = set()
72
+ for sql_item in (facts or {}).get("sqls") or []:
73
+ known_tables.update(tables_of(sql_item.get("sql") or ""))
74
+ for table in ((facts or {}).get("db_schema") or {}).get("tables") or []:
75
+ known_tables.add(table.get("name") or "")
76
+ if not known_tables:
77
+ return issues # 无事实来源时跳过追溯
78
+ for case in _iter_cases(contract):
79
+ for sql in case.get("sql") or []:
80
+ for table in tables_of(sql):
81
+ if table not in known_tables:
82
+ issues.append({"case": case.get("t") or "", "rule": "SQL来源",
83
+ "message": "表 %s 在 facts(sqls/db_schema)中无来源" % table})
84
+ return issues
85
+
86
+
87
+ def _case_text(case):
88
+ """Full case text: title + steps + expects (methodology evidence scan)."""
89
+ return " ".join(
90
+ [case.get("t") or ""]
91
+ + list(case.get("steps") or [])
92
+ + list(case.get("expects") or [])
93
+ )
94
+
95
+
96
+ def check_methodology(contract, facts=None):
97
+ """Methodology gate: the method declared by a case must have matching evidence.
98
+
99
+ rules:
100
+ - boundary value: numbers must appear in steps/expects text (e.g. -1/0/max+1)
101
+ - state transition: text must cover the matching enum values in facts.enums
102
+ - enum overall coverage: only when state transition cases exist, all enum values must be covered by cases overall (W-14 gating)
103
+ """
104
+ issues = []
105
+ enums = (facts or {}).get("enums") or []
106
+ cases = list(_iter_cases(contract))
107
+ has_transition = False
108
+ covered_enum_values = set()
109
+ all_enum_values = set()
110
+ for enum in enums:
111
+ values = set(enum.get("values") or [])
112
+ all_enum_values |= values
113
+ for case in cases:
114
+ method = (case.get("method") or "").strip()
115
+ text = _case_text(case)
116
+ if _BOUNDARY_WORDS[0] in method or _BOUNDARY_WORDS[1] in method:
117
+ # boundary value cases need numeric evidence in steps/expects only
118
+ steps_expects = " ".join(
119
+ list(case.get("steps") or []) + list(case.get("expects") or [])
120
+ )
121
+ if not _NUMBER_PATTERN.search(steps_expects):
122
+ issues.append({"case": case.get("t") or "", "rule": "方法学",
123
+ "message": "声明边界值法但 steps/expects 无数值证据"})
124
+ if any(w in method for w in _TRANSITION_WORDS):
125
+ has_transition = True
126
+ for enum in enums:
127
+ values = set(enum.get("values") or [])
128
+ for value in values:
129
+ if value in text:
130
+ covered_enum_values.add(value)
131
+ if has_transition and all_enum_values:
132
+ missing = all_enum_values - covered_enum_values
133
+ if missing:
134
+ issues.append({"case": "(整体)", "rule": "方法学",
135
+ "message": "状态迁移用例未覆盖枚举取值: %s" % "、".join(sorted(missing))})
136
+ return issues
137
+
138
+
139
+ def check_sql_columns(contract, provider=None):
140
+ """Column-level check: SELECT column names compared against db schema columns; explicit warning when the data source has no schema.
141
+
142
+ W-05: in multi-table JOIN scenarios qualified columns only check the qualifying table, unqualified columns pass when any referenced table has them.
143
+ """
144
+ issues = []
145
+ if provider is None:
146
+ return issues
147
+ schema = getattr(provider, "schema", None)
148
+ if not schema:
149
+ return issues
150
+ table_columns = {}
151
+ for table in schema.get("tables") or []:
152
+ table_columns[table.get("name") or ""] = {
153
+ (c.get("name") or "") for c in (table.get("columns") or [])
154
+ }
155
+ for case in _iter_cases(contract):
156
+ for sql in case.get("sql") or []:
157
+ names = tables_of(sql)
158
+ checked = set()
159
+ for table, column in qualified_columns(sql):
160
+ known = table_columns.get(table)
161
+ if known is not None and column not in known:
162
+ issues.append({"case": case.get("t") or "", "rule": "SQL列",
163
+ "message": "表 %s 不存在列 %s" % (table, column)})
164
+ checked.add(column)
165
+ for column in columns_of(sql):
166
+ if column in checked:
167
+ continue
168
+ known_tables = [t for t in names if t in table_columns and table_columns[t]]
169
+ if known_tables and not any(column in table_columns[t] for t in known_tables):
170
+ issues.append({"case": case.get("t") or "", "rule": "SQL列",
171
+ "message": "引用表 %s 不存在列 %s" % (", ".join(names), column)})
172
+ return issues
173
+
174
+
175
+ def build_coverage_matrix(contract, facts):
176
+ """Coverage matrix: requirement points (features/interfaces) vs contract cases, text containment match.
177
+
178
+ :return: {covered: [(item, case_title)], missing: [item]}
179
+ """
180
+ from .coverage import flatten_text # 用例树压平
181
+
182
+ # contract to temporary case tree (title text only)
183
+ text = "\n".join(
184
+ ((case.get("t") or "") + " " + " ".join(case.get("steps") or []) + " " + " ".join(case.get("expects") or []))
185
+ for case in _iter_cases(contract)
186
+ )
187
+ covered = []
188
+ missing = []
189
+ items = []
190
+ for feature in (facts or {}).get("features") or []:
191
+ items.append(("功能点", feature))
192
+ for iface in (facts or {}).get("interfaces") or []:
193
+ url = iface.get("url") or ""
194
+ if url:
195
+ items.append(("接口", "%s %s" % (iface.get("method") or "?", url)))
196
+ for kind, item in items:
197
+ keys = [item]
198
+ url_match = re.search(r"(/\S+)", item)
199
+ if url_match:
200
+ keys.append(url_match.group(1))
201
+ if any(key in text for key in keys):
202
+ covered.append((item, ""))
203
+ else:
204
+ missing.append(item)
205
+ return {"covered": covered, "missing": missing}
206
+
207
+
208
+ def review_contract(contract, facts=None, provider=None):
209
+ """执行全部规则检查,返回 {issues, coverage}。
210
+
211
+ :param contract: 契约 dict
212
+ :param facts: facts.json 产物(dict 或 None)
213
+ :param provider: 数据库 Provider(可选,列级校验)
214
+ """
215
+ facts = facts or {}
216
+ issues = []
217
+ issues.extend(check_structure(contract))
218
+ issues.extend(check_sql_traceability(contract, facts))
219
+ issues.extend(check_methodology(contract, facts))
220
+ if provider is not None and not getattr(provider, "schema", None):
221
+ # explicit warning: current data source does not support column-level checks
222
+ issues.append({"case": "(整体)", "rule": "SQL列",
223
+ "message": "当前数据源不支持列级校验(无 schema 信息),SQL 列正确性请人工复核"})
224
+ issues.extend(check_sql_columns(contract, provider))
225
+ coverage = build_coverage_matrix(contract, facts)
226
+ return {"issues": issues, "coverage": coverage}
227
+
228
+
229
+ def render_report(result, contract):
230
+ """生成门禁报告 markdown 文本。
231
+
232
+ :param result: review_contract 产物
233
+ :param contract: 契约 dict
234
+ """
235
+ issues = result["issues"]
236
+ coverage = result["coverage"]
237
+ case_count = sum(1 for _ in _iter_cases(contract))
238
+ lines = []
239
+ lines.append("契约质量门禁报告")
240
+ lines.append("")
241
+ lines.append("| 检查项 | 结果 |")
242
+ lines.append("|---|---|")
243
+ lines.append("| 用例总数 | %d |" % case_count)
244
+ lines.append("| 规则问题 | %d |" % len(issues))
245
+ lines.append("| 已覆盖需求点 | %d |" % len(coverage["covered"]))
246
+ lines.append("| 未覆盖需求点 | %d |" % len(coverage["missing"]))
247
+ lines.append("")
248
+ if issues:
249
+ lines.append("## 问题清单")
250
+ lines.append("")
251
+ for issue in issues:
252
+ lines.append("- [%s] %s | %s" % (issue["rule"], issue["case"], issue["message"]))
253
+ lines.append("")
254
+ else:
255
+ lines.append("## 问题清单")
256
+ lines.append("")
257
+ lines.append("无规则问题")
258
+ lines.append("")
259
+ lines.append("## 覆盖矩阵")
260
+ lines.append("")
261
+ if coverage["covered"]:
262
+ lines.append("已覆盖:")
263
+ for item, _ in coverage["covered"]:
264
+ lines.append("- " + item)
265
+ lines.append("")
266
+ if coverage["missing"]:
267
+ lines.append("未覆盖:")
268
+ for item in coverage["missing"]:
269
+ lines.append("- " + item)
270
+ lines.append("")
271
+ else:
272
+ lines.append("无未覆盖需求点")
273
+ lines.append("")
274
+ return "\n".join(lines)