astsight 0.1.0__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.
- astsight/__init__.py +18 -0
- astsight/__main__.py +4 -0
- astsight/agent/__init__.py +44 -0
- astsight/agent/case_design.py +421 -0
- astsight/agent/casegen.py +196 -0
- astsight/agent/data_prep.py +265 -0
- astsight/agent/diagnosis.py +221 -0
- astsight/agent/errors.py +15 -0
- astsight/agent/flow.py +1345 -0
- astsight/agent/jar.py +235 -0
- astsight/agent/mock_semantics.py +136 -0
- astsight/agent/mockplan.py +481 -0
- astsight/agent/models.py +285 -0
- astsight/agent/repair.py +538 -0
- astsight/agent/rule_analysis.py +150 -0
- astsight/agent/semantic.py +250 -0
- astsight/agent/sut.py +442 -0
- astsight/artifacts.py +73 -0
- astsight/cases/__init__.py +5 -0
- astsight/cases/adapters.py +79 -0
- astsight/cases/context.py +764 -0
- astsight/cases/data_refs.py +167 -0
- astsight/cases/deleted_cleanup.py +121 -0
- astsight/cases/draft.py +575 -0
- astsight/cases/expressions.py +256 -0
- astsight/cases/proposal.py +1500 -0
- astsight/cases/regexsample.py +242 -0
- astsight/cases/relations.py +193 -0
- astsight/cases/requirements.py +269 -0
- astsight/cases/store.py +362 -0
- astsight/cases/strength.py +77 -0
- astsight/cases/templates.py +613 -0
- astsight/cases/validate.py +738 -0
- astsight/cases/validate_assertions.py +733 -0
- astsight/cases/validate_base.py +418 -0
- astsight/cases/validate_coverage.py +288 -0
- astsight/cases/validate_data.py +227 -0
- astsight/cases/validate_dubbo.py +300 -0
- astsight/cases/validate_mqmock.py +349 -0
- astsight/cases/validate_profile.py +168 -0
- astsight/cases/validate_rules.py +280 -0
- astsight/cases/validate_semantics.py +199 -0
- astsight/cases/validate_steps.py +510 -0
- astsight/changes/__init__.py +13 -0
- astsight/changes/contract_diff.py +310 -0
- astsight/changes/deleted.py +161 -0
- astsight/changes/git_diff.py +182 -0
- astsight/changes/impact.py +464 -0
- astsight/changes/symbol_diff.py +431 -0
- astsight/changes/transport_contracts.py +385 -0
- astsight/cli.py +1537 -0
- astsight/codegen/__init__.py +5 -0
- astsight/codegen/pytest_gen.py +1814 -0
- astsight/commands/__init__.py +1 -0
- astsight/commands/_shared.py +42 -0
- astsight/commands/data.py +490 -0
- astsight/commands/init.py +172 -0
- astsight/commands/mock.py +333 -0
- astsight/commands/rules.py +360 -0
- astsight/data/__init__.py +124 -0
- astsight/data/annotations.py +458 -0
- astsight/data/apply.py +310 -0
- astsight/data/catalog.py +402 -0
- astsight/data/codeconst.py +1281 -0
- astsight/data/connection.py +74 -0
- astsight/data/dbml.py +727 -0
- astsight/data/ddl.py +642 -0
- astsight/data/dialects.py +156 -0
- astsight/data/fixtures.py +193 -0
- astsight/data/plan.py +444 -0
- astsight/data/reflect.py +667 -0
- astsight/data/render.py +133 -0
- astsight/data/seed.py +142 -0
- astsight/data/semantics.py +211 -0
- astsight/data/states.py +1214 -0
- astsight/data/validate.py +234 -0
- astsight/evaluation.py +205 -0
- astsight/execute/__init__.py +6 -0
- astsight/execute/diagnose.py +192 -0
- astsight/execute/dubbo_targets.py +734 -0
- astsight/execute/runner.py +357 -0
- astsight/feedback.py +573 -0
- astsight/inventory.py +406 -0
- astsight/llm/__init__.py +28 -0
- astsight/llm/client.py +634 -0
- astsight/mock/__init__.py +122 -0
- astsight/mock/evidence.py +388 -0
- astsight/mock/gripmock_binary.py +246 -0
- astsight/mock/grpc_descriptor.py +299 -0
- astsight/mock/grpc_runtime.py +423 -0
- astsight/mock/identity.py +482 -0
- astsight/mock/matching.py +75 -0
- astsight/mock/plan.py +1246 -0
- astsight/mock/replies.py +84 -0
- astsight/mock/routes.py +231 -0
- astsight/mock/runtime.py +225 -0
- astsight/mock/semantic.py +539 -0
- astsight/mock/server.py +1481 -0
- astsight/mock/sessions.py +222 -0
- astsight/mq/__init__.py +1 -0
- astsight/mq/inject/capture.py +337 -0
- astsight/mq/inject/sitecustomize.py +14 -0
- astsight/persistence.py +86 -0
- astsight/pipeline.py +1733 -0
- astsight/profile/__init__.py +36 -0
- astsight/profile/builder.py +297 -0
- astsight/profile/callsite.py +46 -0
- astsight/profile/downstream.py +1967 -0
- astsight/profile/dubbo.py +2141 -0
- astsight/profile/grpc_downstream.py +758 -0
- astsight/profile/javaclass.py +431 -0
- astsight/profile/javadeps.py +277 -0
- astsight/profile/javatypes.py +1037 -0
- astsight/profile/langroutes.py +1051 -0
- astsight/profile/langscan.py +1363 -0
- astsight/profile/mq.py +804 -0
- astsight/profile/openapi.py +288 -0
- astsight/report/__init__.py +5 -0
- astsight/report/merge.py +1098 -0
- astsight/rules/__init__.py +102 -0
- astsight/rules/conflicts.py +269 -0
- astsight/rules/context.py +552 -0
- astsight/rules/contract.py +233 -0
- astsight/rules/contract_model.py +1361 -0
- astsight/rules/coverage.py +127 -0
- astsight/rules/diff.py +143 -0
- astsight/rules/draft.py +152 -0
- astsight/rules/grounding.py +110 -0
- astsight/rules/relations.py +319 -0
- astsight/rules/render.py +413 -0
- astsight/rules/store.py +547 -0
- astsight/rules/validate.py +399 -0
- astsight/sidecar/__init__.py +37 -0
- astsight/sidecar/dubbo.py +449 -0
- astsight/sidecar/package.py +251 -0
- astsight/sidecar/triple.py +258 -0
- astsight-0.1.0.dist-info/METADATA +1348 -0
- astsight-0.1.0.dist-info/RECORD +158 -0
- astsight-0.1.0.dist-info/WHEEL +5 -0
- astsight-0.1.0.dist-info/entry_points.txt +2 -0
- astsight-0.1.0.dist-info/top_level.txt +3 -0
- codegraph/__init__.py +55 -0
- codegraph/bridge/codegraph_worker.mjs +548 -0
- codegraph/client.py +158 -0
- codegraph/embedded.py +561 -0
- codegraph/memory.py +89 -0
- codegraph/route_repair.py +1680 -0
- codegraph/runtime.py +270 -0
- contracts/__init__.py +245 -0
- contracts/base.py +37 -0
- contracts/cases.py +100 -0
- contracts/data.py +209 -0
- contracts/entities.py +436 -0
- contracts/enums.py +355 -0
- contracts/mock.py +350 -0
- contracts/mock_plan.py +209 -0
- contracts/mock_semantic.py +89 -0
- contracts/rules.py +340 -0
astsight/report/merge.py
ADDED
|
@@ -0,0 +1,1098 @@
|
|
|
1
|
+
"""C7.4 报告合并。
|
|
2
|
+
|
|
3
|
+
门禁口径(对齐设计文档 C7.4):
|
|
4
|
+
- **只认真实缺陷**(`code_defect`)与覆盖边界(`unmapped`),不认“重试后通过率”;
|
|
5
|
+
- 未执行/未生成的接口单列,不得计入通过率分母;
|
|
6
|
+
- 重试恢复单列 `recovered`,作为稳定性信号,不是质量结论。
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections import Counter, defaultdict
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from contracts import AssertStrength
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _contract_parts(diff: dict) -> str:
|
|
17
|
+
parts: list[str] = []
|
|
18
|
+
for key, label in (
|
|
19
|
+
("added", "新增"),
|
|
20
|
+
("removed", "删除"),
|
|
21
|
+
("required_added", "新增必填"),
|
|
22
|
+
("required_removed", "取消必填"),
|
|
23
|
+
("added_status_codes", "新增状态码"),
|
|
24
|
+
("removed_status_codes", "删除状态码"),
|
|
25
|
+
("success_added", "新增成功码"),
|
|
26
|
+
("success_removed", "删除成功码"),
|
|
27
|
+
):
|
|
28
|
+
values = diff.get(key) or []
|
|
29
|
+
if values:
|
|
30
|
+
parts.append(f"{label} {', '.join(str(item) for item in values)}")
|
|
31
|
+
changed = diff.get("type_changed") or []
|
|
32
|
+
if changed:
|
|
33
|
+
parts.append(
|
|
34
|
+
"类型变化 "
|
|
35
|
+
+ ", ".join(
|
|
36
|
+
f"{item['field']}: {item['before']} → {item['after']}"
|
|
37
|
+
for item in changed
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
fields = diff.get("fields") or {}
|
|
41
|
+
for code, item in sorted(fields.items()):
|
|
42
|
+
if item.get("added"):
|
|
43
|
+
parts.append(f"{code} 字段新增 {', '.join(item['added'])}")
|
|
44
|
+
if item.get("removed"):
|
|
45
|
+
parts.append(f"{code} 字段删除 {', '.join(item['removed'])}")
|
|
46
|
+
return ",".join(parts)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _transport_contract_parts(item: dict) -> list[str]:
|
|
50
|
+
parts = ["变化 " + ", ".join(item.get("change_kinds") or [])]
|
|
51
|
+
for label in ("request", "response"):
|
|
52
|
+
diff = item.get(label) or {}
|
|
53
|
+
bits = []
|
|
54
|
+
if diff.get("added"):
|
|
55
|
+
bits.append(f"新增 {len(diff['added'])}")
|
|
56
|
+
if diff.get("removed"):
|
|
57
|
+
bits.append(f"删除 {len(diff['removed'])}")
|
|
58
|
+
if diff.get("changed"):
|
|
59
|
+
bits.append(f"变更 {len(diff['changed'])}")
|
|
60
|
+
if bits:
|
|
61
|
+
parts.append(f"{label}字段 " + ",".join(bits))
|
|
62
|
+
if item.get("return_type"):
|
|
63
|
+
diff = item["return_type"]
|
|
64
|
+
parts.append(
|
|
65
|
+
f"返回类型 {diff['before']} → {diff['after']}"
|
|
66
|
+
)
|
|
67
|
+
if item.get("parameter_types"):
|
|
68
|
+
diff = item["parameter_types"]
|
|
69
|
+
parts.append(
|
|
70
|
+
"参数类型 "
|
|
71
|
+
+ f"{diff['before']} → {diff['after']}"
|
|
72
|
+
)
|
|
73
|
+
for label in ("parameter_schema", "result_schema"):
|
|
74
|
+
diff = item.get(label) or {}
|
|
75
|
+
bits = []
|
|
76
|
+
if diff.get("added"):
|
|
77
|
+
bits.append(f"新增 {len(diff['added'])}")
|
|
78
|
+
if diff.get("removed"):
|
|
79
|
+
bits.append(f"删除 {len(diff['removed'])}")
|
|
80
|
+
if diff.get("changed"):
|
|
81
|
+
bits.append(f"变更 {len(diff['changed'])}")
|
|
82
|
+
if bits:
|
|
83
|
+
parts.append(f"{label} " + ",".join(bits))
|
|
84
|
+
return parts
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _rate(numerator: int, denominator: int) -> float:
|
|
88
|
+
return round(numerator / denominator, 4) if denominator else 0.0
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def build_report(
|
|
92
|
+
*,
|
|
93
|
+
run_meta: dict,
|
|
94
|
+
changes: dict,
|
|
95
|
+
impact: dict,
|
|
96
|
+
profiles: list[dict],
|
|
97
|
+
cases: list[Any],
|
|
98
|
+
records: list[dict],
|
|
99
|
+
unmapped: dict,
|
|
100
|
+
route_audit: dict,
|
|
101
|
+
codegen: dict,
|
|
102
|
+
gate_config: dict | None = None,
|
|
103
|
+
case_store: dict | None = None,
|
|
104
|
+
mock_evidence: dict | None = None,
|
|
105
|
+
data_plan: dict | None = None,
|
|
106
|
+
rules: dict | None = None,
|
|
107
|
+
) -> dict:
|
|
108
|
+
gate_config = gate_config or {}
|
|
109
|
+
cases_by_id = {c.id: c for c in cases}
|
|
110
|
+
|
|
111
|
+
def _bucket() -> dict:
|
|
112
|
+
return {"total": 0, "passed": 0, "failed": 0, "blocked": 0}
|
|
113
|
+
|
|
114
|
+
by_endpoint: dict[str, dict] = defaultdict(_bucket)
|
|
115
|
+
by_category: dict[str, dict] = defaultdict(_bucket)
|
|
116
|
+
by_transport: dict[str, dict] = defaultdict(_bucket)
|
|
117
|
+
by_reason: Counter = Counter()
|
|
118
|
+
failures: list[dict] = []
|
|
119
|
+
blocked_records: list[dict] = []
|
|
120
|
+
flaky: list[str] = []
|
|
121
|
+
|
|
122
|
+
first_pass = 0
|
|
123
|
+
final_pass = 0
|
|
124
|
+
recovered = 0
|
|
125
|
+
sut_defects = 0
|
|
126
|
+
unknown = 0
|
|
127
|
+
blocked = 0
|
|
128
|
+
|
|
129
|
+
executed_ids = {r["case_id"] for r in records if r.get("case_id")}
|
|
130
|
+
|
|
131
|
+
for record in records:
|
|
132
|
+
case = cases_by_id.get(record.get("case_id", ""))
|
|
133
|
+
endpoint = record.get("endpoint") or (case.endpoint if case else "")
|
|
134
|
+
category = record.get("category") or (case.category if case else "")
|
|
135
|
+
attempts = record.get("attempts") or []
|
|
136
|
+
diagnosis = record.get("diagnosis") or {}
|
|
137
|
+
first_ok = bool(attempts) and attempts[0].get("status") == "pass"
|
|
138
|
+
final_ok = record.get("outcome") == "passed"
|
|
139
|
+
is_blocked = record.get("outcome") == "blocked"
|
|
140
|
+
is_skipped = record.get("outcome") == "skipped"
|
|
141
|
+
|
|
142
|
+
transport_value = getattr(case, "transport", None) if case is not None else None
|
|
143
|
+
transport = (
|
|
144
|
+
getattr(transport_value, "value", None)
|
|
145
|
+
or (str(transport_value) if transport_value is not None else "unknown")
|
|
146
|
+
)
|
|
147
|
+
by_endpoint[endpoint]["total"] += 1
|
|
148
|
+
by_category[category]["total"] += 1
|
|
149
|
+
by_transport[transport]["total"] += 1
|
|
150
|
+
bucket = "passed" if final_ok else (
|
|
151
|
+
"blocked" if (is_blocked or is_skipped) else "failed"
|
|
152
|
+
)
|
|
153
|
+
by_endpoint[endpoint][bucket] += 1
|
|
154
|
+
by_category[category][bucket] += 1
|
|
155
|
+
by_transport[transport][bucket] += 1
|
|
156
|
+
if is_skipped:
|
|
157
|
+
# skip 只是没有执行,不是失败,也不进入通过率分母。
|
|
158
|
+
continue
|
|
159
|
+
first_pass += int(first_ok)
|
|
160
|
+
final_pass += int(final_ok)
|
|
161
|
+
if is_blocked:
|
|
162
|
+
# 造数/DB 未就绪是用例未真正执行,不计入通过率分母,也不伪装为失败。
|
|
163
|
+
blocked += 1
|
|
164
|
+
blocked_records.append(
|
|
165
|
+
{
|
|
166
|
+
"case_id": record.get("case_id"),
|
|
167
|
+
"endpoint": endpoint,
|
|
168
|
+
"category": category,
|
|
169
|
+
"reason": diagnosis.get("reason") or "data_unavailable",
|
|
170
|
+
"message": (record.get("message") or "")[:2000],
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
continue
|
|
174
|
+
if not first_ok and final_ok:
|
|
175
|
+
recovered += 1
|
|
176
|
+
if diagnosis.get("reason") == "env_flake":
|
|
177
|
+
flaky.append(record.get("case_id", ""))
|
|
178
|
+
if diagnosis.get("root_cause") == "code_defect":
|
|
179
|
+
sut_defects += 1
|
|
180
|
+
if diagnosis.get("reason") == "unknown" and not final_ok:
|
|
181
|
+
unknown += 1
|
|
182
|
+
if not final_ok:
|
|
183
|
+
by_reason[diagnosis.get("reason", "unknown")] += 1
|
|
184
|
+
failures.append(
|
|
185
|
+
{
|
|
186
|
+
"case_id": record.get("case_id"),
|
|
187
|
+
"endpoint": endpoint,
|
|
188
|
+
"category": category,
|
|
189
|
+
"reason": diagnosis.get("reason"),
|
|
190
|
+
"root_cause": diagnosis.get("root_cause"),
|
|
191
|
+
"action_target": diagnosis.get("action_target"),
|
|
192
|
+
"detail": diagnosis.get("detail"),
|
|
193
|
+
"attempts": attempts,
|
|
194
|
+
"message": (record.get("message") or "")[:2000],
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
skipped_ids = {
|
|
199
|
+
record.get("case_id")
|
|
200
|
+
for record in records
|
|
201
|
+
if record.get("outcome") == "skipped" and record.get("case_id")
|
|
202
|
+
}
|
|
203
|
+
unexecuted = []
|
|
204
|
+
for case in cases:
|
|
205
|
+
if case.id not in executed_ids:
|
|
206
|
+
unexecuted.append(
|
|
207
|
+
{
|
|
208
|
+
"case_id": case.id,
|
|
209
|
+
"endpoint": case.endpoint,
|
|
210
|
+
"reason": "not_executed",
|
|
211
|
+
}
|
|
212
|
+
)
|
|
213
|
+
elif case.id in skipped_ids:
|
|
214
|
+
unexecuted.append(
|
|
215
|
+
{
|
|
216
|
+
"case_id": case.id,
|
|
217
|
+
"endpoint": case.endpoint,
|
|
218
|
+
"reason": "skipped",
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
total = len(cases)
|
|
223
|
+
# skipped 不是执行结果:既不算失败,也不进入通过率分母。
|
|
224
|
+
runnable = sum(
|
|
225
|
+
1 for record in records
|
|
226
|
+
if record.get("outcome") in {"passed", "failed"}
|
|
227
|
+
)
|
|
228
|
+
executed = runnable
|
|
229
|
+
pass_rate = _rate(final_pass, runnable)
|
|
230
|
+
|
|
231
|
+
contract_incomplete = [
|
|
232
|
+
p["endpoint"] for p in profiles if p.get("contract_incomplete")
|
|
233
|
+
]
|
|
234
|
+
generated_endpoints = {c.endpoint for c in cases}
|
|
235
|
+
changed_endpoints = {a["handler"] for a in impact.get("changed_apis", [])}
|
|
236
|
+
endpoints_without_cases = sorted(changed_endpoints - generated_endpoints)
|
|
237
|
+
|
|
238
|
+
blockers: list[str] = []
|
|
239
|
+
warnings: list[str] = []
|
|
240
|
+
if sut_defects:
|
|
241
|
+
blockers.append(f"存在 {sut_defects} 个真实缺陷(code_defect)")
|
|
242
|
+
if codegen.get("errors"):
|
|
243
|
+
blockers.append(f"生成代码有 {len(codegen['errors'])} 个语法错误")
|
|
244
|
+
has_unmapped = bool(
|
|
245
|
+
unmapped.get("symbols")
|
|
246
|
+
or unmapped.get("routes")
|
|
247
|
+
or unmapped.get("profile_unmapped")
|
|
248
|
+
or unmapped.get("unsupported_files")
|
|
249
|
+
or contract_incomplete
|
|
250
|
+
or endpoints_without_cases
|
|
251
|
+
)
|
|
252
|
+
if has_unmapped and not gate_config.get("allow_unmapped"):
|
|
253
|
+
blockers.append("存在未映射范围(unmapped):变更符号/路由/契约缺口未闭合")
|
|
254
|
+
if unexecuted:
|
|
255
|
+
warnings.append(
|
|
256
|
+
f"{len(unexecuted)} 条用例未执行(unexecuted),不计入通过率分母"
|
|
257
|
+
)
|
|
258
|
+
if executed == 0:
|
|
259
|
+
warnings.append("未执行用例:未提供 base_url 或执行被跳过")
|
|
260
|
+
if blocked:
|
|
261
|
+
blockers.append(
|
|
262
|
+
f"存在 {blocked} 条用例因造数前置未就绪被阻断(blocked/data_unavailable)"
|
|
263
|
+
)
|
|
264
|
+
if runnable and pass_rate < float(gate_config.get("min_pass_rate", 0.95)):
|
|
265
|
+
warnings.append(f"最终通过率 {pass_rate:.2%} 低于 {gate_config.get('min_pass_rate', 0.95):.0%}")
|
|
266
|
+
if case_store:
|
|
267
|
+
blockers.extend(case_store.get("gate_blockers") or [])
|
|
268
|
+
warnings.extend(case_store.get("gate_warnings") or [])
|
|
269
|
+
if case_store.get("degraded"):
|
|
270
|
+
warnings.append(
|
|
271
|
+
"本次运行使用已批准用例库的快照,但存在待审/漂移警告(degraded)"
|
|
272
|
+
)
|
|
273
|
+
if case_store.get("summary", {}).get("deprecated"):
|
|
274
|
+
warnings.append(
|
|
275
|
+
f"用例库存在 {case_store['summary']['deprecated']} 条 deprecated 用例,不参与执行"
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
mock = mock_evidence or {
|
|
279
|
+
"checked": False,
|
|
280
|
+
"reason": "mock_evidence_not_configured",
|
|
281
|
+
}
|
|
282
|
+
executed_case_ids = {
|
|
283
|
+
str(record.get("case_id") or "")
|
|
284
|
+
for record in records
|
|
285
|
+
if record.get("case_id")
|
|
286
|
+
}
|
|
287
|
+
weak_oracle: list[str] = []
|
|
288
|
+
mock_bound = [
|
|
289
|
+
case
|
|
290
|
+
for case in cases
|
|
291
|
+
if case.id in executed_case_ids
|
|
292
|
+
and getattr(case, "mock_bindings", None)
|
|
293
|
+
and getattr(case, "assert_strength", None) == AssertStrength.L1
|
|
294
|
+
]
|
|
295
|
+
if mock.get("checked"):
|
|
296
|
+
mock_by_case = mock.get("by_case") or {}
|
|
297
|
+
for case in mock_bound:
|
|
298
|
+
calls = int((mock_by_case.get(case.id) or {}).get("calls") or 0)
|
|
299
|
+
if calls == 0:
|
|
300
|
+
weak_oracle.append(case.id)
|
|
301
|
+
if weak_oracle:
|
|
302
|
+
warnings.append(
|
|
303
|
+
f"{len(weak_oracle)} 条用例只有状态码断言且 Mock 未命中"
|
|
304
|
+
"(weak_oracle)"
|
|
305
|
+
)
|
|
306
|
+
elif mock_bound:
|
|
307
|
+
# 没有 Mock 证据时,mock-bound 用例的命中无法证明,按弱断言处理。
|
|
308
|
+
weak_oracle = [case.id for case in mock_bound]
|
|
309
|
+
warnings.append(
|
|
310
|
+
f"Mock 证据未配置:{len(weak_oracle)} 条 mock-bound 用例"
|
|
311
|
+
"无法验证 Mock 命中(weak_oracle)"
|
|
312
|
+
)
|
|
313
|
+
if mock.get("checked"):
|
|
314
|
+
blocking = int(mock.get("blocking_errors") or 0)
|
|
315
|
+
if blocking:
|
|
316
|
+
blockers.append(
|
|
317
|
+
f"Mock 调用存在 {blocking} 个阻断类错误"
|
|
318
|
+
"(unknown/ambiguous/unbound/branch_missing)"
|
|
319
|
+
)
|
|
320
|
+
by_result = mock.get("by_result") or {}
|
|
321
|
+
late = int(by_result.get("late") or 0)
|
|
322
|
+
if late:
|
|
323
|
+
warnings.append(
|
|
324
|
+
f"Mock 晚到/过期调用 {late} 次:drain 窗口不足或 SUT 存在异步调用(degraded)"
|
|
325
|
+
)
|
|
326
|
+
if mock.get("invalid_lines"):
|
|
327
|
+
warnings.append(
|
|
328
|
+
f"mock_calls.jsonl 有 {mock['invalid_lines']} 行无法解析(degraded)"
|
|
329
|
+
)
|
|
330
|
+
if mock.get("unattributed_calls"):
|
|
331
|
+
warnings.append(
|
|
332
|
+
f"Mock 有 {mock['unattributed_calls']} 次调用无法归因到用例"
|
|
333
|
+
)
|
|
334
|
+
unused = int(mock.get("unused_binding_count") or 0)
|
|
335
|
+
if unused:
|
|
336
|
+
blockers.append(
|
|
337
|
+
f"Mock 有 {unused} 个会话绑定的下游依赖零调用(mock_not_used)"
|
|
338
|
+
)
|
|
339
|
+
if mock.get("sessions_reason"):
|
|
340
|
+
warnings.append(
|
|
341
|
+
f"Mock 会话绑定未校验:{mock['sessions_reason']}(degraded)"
|
|
342
|
+
)
|
|
343
|
+
elif not mock.get("sessions_checked"):
|
|
344
|
+
warnings.append(
|
|
345
|
+
"Mock 会话绑定未校验:未提供会话历史(degraded)"
|
|
346
|
+
)
|
|
347
|
+
if mock.get("sessions_missing"):
|
|
348
|
+
warnings.append(
|
|
349
|
+
f"Mock 证据中有 {mock['sessions_missing']} 个会话不在会话历史中,"
|
|
350
|
+
"mock_not_used 校验不完整(degraded)"
|
|
351
|
+
)
|
|
352
|
+
elif mock.get("reason") not in (None, "mock_evidence_not_configured"):
|
|
353
|
+
warnings.append(f"Mock 证据未读取:{mock.get('reason')}")
|
|
354
|
+
|
|
355
|
+
plan = mock.get("plan") or {}
|
|
356
|
+
if plan:
|
|
357
|
+
for item in plan.get("warnings") or []:
|
|
358
|
+
warnings.append(f"Mock 计划告警:{item}")
|
|
359
|
+
unsupported = int(plan.get("unsupported_count") or 0)
|
|
360
|
+
if unsupported:
|
|
361
|
+
warnings.append(
|
|
362
|
+
f"Mock 计划有 {unsupported} 个下游无法注入(unsupported),"
|
|
363
|
+
"相关用例可能未真正隔离"
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
dubbo_routes = int(plan.get("dubbo_route_count") or 0)
|
|
367
|
+
if dubbo_routes:
|
|
368
|
+
agent_state = mock.get("agent") or {}
|
|
369
|
+
heartbeat = agent_state.get("heartbeat") or {}
|
|
370
|
+
dubbo_agent = heartbeat.get("dubbo") or {}
|
|
371
|
+
if not heartbeat:
|
|
372
|
+
blockers.append(
|
|
373
|
+
"计划内 Dubbo 下游未确认 Filter 在消费端链上"
|
|
374
|
+
f"(filter_not_in_chain):{agent_state.get('reason') or 'agent_heartbeat_missing'}"
|
|
375
|
+
)
|
|
376
|
+
elif not dubbo_agent.get("installed"):
|
|
377
|
+
blockers.append(
|
|
378
|
+
"计划内 Dubbo 下游已登记,但 agent 心跳未上报 Dubbo Filter"
|
|
379
|
+
"(filter_not_in_chain:dubbo.installed=false)"
|
|
380
|
+
)
|
|
381
|
+
elif int(dubbo_agent.get("filter_instantiated") or 0) <= 0:
|
|
382
|
+
blockers.append(
|
|
383
|
+
"计划内 Dubbo 下游已登记,但消费端 Filter 从未实例化"
|
|
384
|
+
"(filter_not_in_chain:dubbo.filter_instantiated=0)"
|
|
385
|
+
)
|
|
386
|
+
if heartbeat and not dubbo_agent.get("serialization_verified", False):
|
|
387
|
+
warnings.append(
|
|
388
|
+
"Dubbo 桩响应 serialization_verified=false:"
|
|
389
|
+
"跳过 Hessian2 链路,序列化保真未验证(degraded)"
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
mq_routes = int(plan.get("mq_route_count") or 0)
|
|
393
|
+
if mq_routes:
|
|
394
|
+
agent_state = mock.get("agent") or {}
|
|
395
|
+
heartbeat = agent_state.get("heartbeat") or {}
|
|
396
|
+
mq_agent = heartbeat.get("mq") or {}
|
|
397
|
+
if not heartbeat:
|
|
398
|
+
blockers.append(
|
|
399
|
+
"计划内 MQ 下游未确认生产者拦截已安装"
|
|
400
|
+
f"(mq_producer_not_installed):"
|
|
401
|
+
f"{agent_state.get('reason') or 'agent_heartbeat_missing'}"
|
|
402
|
+
)
|
|
403
|
+
elif not mq_agent.get("installed"):
|
|
404
|
+
blockers.append(
|
|
405
|
+
"计划内 MQ 下游已登记,但 agent 心跳未上报 MQ 生产者拦截"
|
|
406
|
+
"(mq_producer_not_installed:mq.installed=false)"
|
|
407
|
+
)
|
|
408
|
+
else:
|
|
409
|
+
required_clients = {
|
|
410
|
+
str(item) for item in plan.get("mq_clients") or [] if item
|
|
411
|
+
}
|
|
412
|
+
installed_clients = {
|
|
413
|
+
str(item) for item in mq_agent.get("clients") or [] if item
|
|
414
|
+
}
|
|
415
|
+
missing = sorted(required_clients - installed_clients)
|
|
416
|
+
if missing:
|
|
417
|
+
blockers.append(
|
|
418
|
+
"计划内 MQ 客户端缺少生产者拦截模块:"
|
|
419
|
+
f"{', '.join(missing)}(mq_producer_not_installed)"
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
contract_state = impact.get("contract_changes") or {}
|
|
423
|
+
contract_count = (
|
|
424
|
+
len(contract_state.get("changes") or [])
|
|
425
|
+
+ len((contract_state.get("grpc") or {}).get("changes") or [])
|
|
426
|
+
+ len((contract_state.get("dubbo") or {}).get("changes") or [])
|
|
427
|
+
)
|
|
428
|
+
if contract_count:
|
|
429
|
+
warnings.append(
|
|
430
|
+
f"本次变更涉及 {contract_count} 个接口的契约字段变化"
|
|
431
|
+
"(contract_change)"
|
|
432
|
+
)
|
|
433
|
+
for item in contract_state.get("warnings") or []:
|
|
434
|
+
warnings.append(f"契约 diff 未完成:{item}")
|
|
435
|
+
|
|
436
|
+
deleted_state = impact.get("deleted_apis") or {}
|
|
437
|
+
if deleted_state.get("deleted"):
|
|
438
|
+
cleanup = deleted_state.get("case_cleanup") or {}
|
|
439
|
+
deprecated = cleanup.get("deprecated") or []
|
|
440
|
+
if deprecated:
|
|
441
|
+
warnings.append(
|
|
442
|
+
f"本次变更删除了 {len(deleted_state['deleted'])} 个接口,"
|
|
443
|
+
f"已自动逻辑删除 {len(deprecated)} 条旧用例(deleted_api)"
|
|
444
|
+
)
|
|
445
|
+
else:
|
|
446
|
+
warnings.append(
|
|
447
|
+
f"本次变更删除了 {len(deleted_state['deleted'])} 个接口,"
|
|
448
|
+
"旧用例可能已失效(deleted_api)"
|
|
449
|
+
)
|
|
450
|
+
for item in deleted_state.get("warnings") or []:
|
|
451
|
+
warnings.append(f"删除接口扫描未完成:{item}")
|
|
452
|
+
|
|
453
|
+
route_health = (route_audit or {}).get("health") or {}
|
|
454
|
+
if route_health.get("status") == "degraded":
|
|
455
|
+
reasons = ",".join(route_health.get("reasons") or [])
|
|
456
|
+
warnings.append(
|
|
457
|
+
"路由清单可能不完整(route_inventory_degraded)"
|
|
458
|
+
+ (f":{reasons}" if reasons else "")
|
|
459
|
+
+ ";受影响接口可能被少报"
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
if rules:
|
|
463
|
+
blockers.extend(rules.get("gate_blockers") or [])
|
|
464
|
+
warnings.extend(rules.get("gate_warnings") or [])
|
|
465
|
+
|
|
466
|
+
if warnings:
|
|
467
|
+
# 通过率不是门禁的唯一依据,但必须显式暴露
|
|
468
|
+
pass
|
|
469
|
+
|
|
470
|
+
if blockers:
|
|
471
|
+
verdict = "fail"
|
|
472
|
+
elif executed == 0:
|
|
473
|
+
verdict = "not_run"
|
|
474
|
+
else:
|
|
475
|
+
verdict = "pass"
|
|
476
|
+
|
|
477
|
+
report = {
|
|
478
|
+
"run": run_meta,
|
|
479
|
+
"summary": {
|
|
480
|
+
"generated_cases": total,
|
|
481
|
+
"executed_cases": executed,
|
|
482
|
+
"first_pass": first_pass,
|
|
483
|
+
"final_pass": final_pass,
|
|
484
|
+
"first_pass_rate": _rate(first_pass, runnable),
|
|
485
|
+
"final_pass_rate": pass_rate,
|
|
486
|
+
"sut_defects": sut_defects,
|
|
487
|
+
"recovered_by_retry": recovered,
|
|
488
|
+
"unknown_attribution": unknown,
|
|
489
|
+
"flaky_candidates": flaky,
|
|
490
|
+
"weak_oracle": weak_oracle,
|
|
491
|
+
"unexecuted_cases": len(unexecuted),
|
|
492
|
+
"blocked_cases": blocked,
|
|
493
|
+
},
|
|
494
|
+
"gate": {
|
|
495
|
+
"verdict": verdict,
|
|
496
|
+
"blockers": blockers,
|
|
497
|
+
"warnings": warnings,
|
|
498
|
+
"config": gate_config,
|
|
499
|
+
},
|
|
500
|
+
"changes": changes,
|
|
501
|
+
"impact": impact,
|
|
502
|
+
"coverage": {
|
|
503
|
+
"changed_endpoints": len(changed_endpoints),
|
|
504
|
+
"profiled_endpoints": len(profiles),
|
|
505
|
+
"generated_endpoints": len(generated_endpoints),
|
|
506
|
+
"executed_endpoints": len({r.get("endpoint") for r in records if r.get("endpoint")}),
|
|
507
|
+
"contract_incomplete": sorted(contract_incomplete),
|
|
508
|
+
"changed_endpoints_without_cases": endpoints_without_cases,
|
|
509
|
+
},
|
|
510
|
+
"case_store": case_store,
|
|
511
|
+
"mock": mock,
|
|
512
|
+
"data_plan": data_plan,
|
|
513
|
+
"rules": rules,
|
|
514
|
+
"blocked": blocked_records,
|
|
515
|
+
"routes": route_audit,
|
|
516
|
+
"unmapped": {
|
|
517
|
+
**unmapped,
|
|
518
|
+
"contract_incomplete": sorted(contract_incomplete),
|
|
519
|
+
"changed_endpoints_without_cases": endpoints_without_cases,
|
|
520
|
+
},
|
|
521
|
+
"by_endpoint": dict(by_endpoint),
|
|
522
|
+
"by_category": dict(by_category),
|
|
523
|
+
"by_transport": dict(by_transport),
|
|
524
|
+
"by_reason": dict(by_reason),
|
|
525
|
+
"failures": failures,
|
|
526
|
+
"unexecuted": unexecuted,
|
|
527
|
+
"codegen": codegen,
|
|
528
|
+
"audit": {
|
|
529
|
+
"egress_guard": {"status": "not_implemented"},
|
|
530
|
+
"weak_oracle": {
|
|
531
|
+
"checked": bool(mock.get("checked")),
|
|
532
|
+
"count": len(weak_oracle),
|
|
533
|
+
},
|
|
534
|
+
"mock_sessions": {
|
|
535
|
+
"checked": bool(mock.get("sessions_checked")),
|
|
536
|
+
"evidence": len(mock.get("session_evidence") or []),
|
|
537
|
+
"truncated": bool(mock.get("session_evidence_truncated")),
|
|
538
|
+
"binding_fields": "dep_id/branch/calls",
|
|
539
|
+
},
|
|
540
|
+
"transport_coverage": {"status": "not_implemented"},
|
|
541
|
+
"transport_fallback": {"status": "not_applicable"},
|
|
542
|
+
"instance": {"status": "not_applicable"},
|
|
543
|
+
"token_usage": {"status": "not_available"},
|
|
544
|
+
},
|
|
545
|
+
}
|
|
546
|
+
return report
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def render_markdown(report: dict) -> str:
|
|
550
|
+
run = report["run"]
|
|
551
|
+
summary = report["summary"]
|
|
552
|
+
gate = report["gate"]
|
|
553
|
+
lines: list[str] = []
|
|
554
|
+
lines.append(f"# AstSight 运行报告 · {run.get('run_id', '')}")
|
|
555
|
+
lines.append("")
|
|
556
|
+
lines.append(f"- 模式:`{run.get('mode')}`")
|
|
557
|
+
lines.append(f"- 项目:`{run.get('project')}`")
|
|
558
|
+
if run.get("base"):
|
|
559
|
+
lines.append(f"- 范围:`{run.get('base')}...{run.get('target')}`({run.get('comparison')})")
|
|
560
|
+
lines.append(f"- 门禁:**{gate['verdict'].upper()}**")
|
|
561
|
+
if gate["blockers"]:
|
|
562
|
+
for blocker in gate["blockers"]:
|
|
563
|
+
lines.append(f" - ⛔ {blocker}")
|
|
564
|
+
for warning in gate["warnings"]:
|
|
565
|
+
lines.append(f" - ⚠️ {warning}")
|
|
566
|
+
lines.append("")
|
|
567
|
+
|
|
568
|
+
lines.append("## 结果概览")
|
|
569
|
+
lines.append("")
|
|
570
|
+
lines.append("| 指标 | 值 |")
|
|
571
|
+
lines.append("|---|---|")
|
|
572
|
+
lines.append(f"| 生成用例 | {summary['generated_cases']} |")
|
|
573
|
+
lines.append(f"| 执行用例 | {summary['executed_cases']} |")
|
|
574
|
+
lines.append(f"| 首次通过 | {summary['first_pass']} ({summary['first_pass_rate']:.1%}) |")
|
|
575
|
+
lines.append(f"| 最终通过 | {summary['final_pass']} ({summary['final_pass_rate']:.1%}) |")
|
|
576
|
+
lines.append(f"| 真实缺陷 | {summary['sut_defects']} |")
|
|
577
|
+
lines.append(f"| 重试恢复 | {summary['recovered_by_retry']} |")
|
|
578
|
+
lines.append(f"| 未执行 | {summary['unexecuted_cases']} |")
|
|
579
|
+
lines.append(f"| 数据阻断(blocked) | {summary.get('blocked_cases', 0)} |")
|
|
580
|
+
weak_oracle = summary.get("weak_oracle") or []
|
|
581
|
+
if weak_oracle:
|
|
582
|
+
lines.append(f"| 弱断言(weak_oracle) | {len(weak_oracle)} |")
|
|
583
|
+
if report.get("case_store"):
|
|
584
|
+
store = report["case_store"]
|
|
585
|
+
coverage = store.get("requirement_coverage") or {}
|
|
586
|
+
lines.append(
|
|
587
|
+
f"| 需求覆盖 | {coverage.get('covered', 0)}/{coverage.get('total', 0)}"
|
|
588
|
+
f" ({float(coverage.get('rate') or 0):.1%}) |"
|
|
589
|
+
)
|
|
590
|
+
lines.append(f"| 待审 proposal | {store.get('pending_proposals', 0)} |")
|
|
591
|
+
lines.append("")
|
|
592
|
+
|
|
593
|
+
impact = report["impact"]
|
|
594
|
+
scope = impact.get("scope")
|
|
595
|
+
if scope == "cases":
|
|
596
|
+
lines.append("## 本次接口范围(已审核用例)")
|
|
597
|
+
elif scope == "full":
|
|
598
|
+
lines.append("## 本次接口范围(全量)")
|
|
599
|
+
else:
|
|
600
|
+
lines.append("## 本次变更影响的接口")
|
|
601
|
+
lines.append("")
|
|
602
|
+
changed = impact.get("changed_apis") or []
|
|
603
|
+
if not changed:
|
|
604
|
+
lines.append("_无(或未执行变更感知)_")
|
|
605
|
+
else:
|
|
606
|
+
lines.append("| 接口 | 置信度 | 证据 | 归因 | 变更符号 |")
|
|
607
|
+
lines.append("|---|---|---|---|---|")
|
|
608
|
+
for api in changed:
|
|
609
|
+
lines.append(
|
|
610
|
+
f"| `{api['handler']}` | {api['confidence']} | {api['evidence']} | "
|
|
611
|
+
f"{api.get('attribution') or '-'} | "
|
|
612
|
+
f"{', '.join(api.get('changed_symbols', [])[:4])} |"
|
|
613
|
+
)
|
|
614
|
+
lines.append("")
|
|
615
|
+
|
|
616
|
+
contract_state = impact.get("contract_changes") or {}
|
|
617
|
+
if contract_state.get("checked"):
|
|
618
|
+
changes = contract_state.get("changes") or []
|
|
619
|
+
lines.append("## 契约字段变化")
|
|
620
|
+
lines.append("")
|
|
621
|
+
if not changes:
|
|
622
|
+
lines.append("_无_")
|
|
623
|
+
else:
|
|
624
|
+
for item in changes:
|
|
625
|
+
parts = []
|
|
626
|
+
params = item.get("params") or {}
|
|
627
|
+
body = item.get("request_body") or {}
|
|
628
|
+
responses = item.get("responses") or {}
|
|
629
|
+
if params:
|
|
630
|
+
parts.append("参数 " + _contract_parts(params))
|
|
631
|
+
if body:
|
|
632
|
+
parts.append("请求体 " + _contract_parts(body))
|
|
633
|
+
if responses:
|
|
634
|
+
parts.append("响应 " + _contract_parts(responses))
|
|
635
|
+
lines.append(
|
|
636
|
+
f"- `{item.get('endpoint')}`:"
|
|
637
|
+
+ ";".join(part for part in parts if part)
|
|
638
|
+
)
|
|
639
|
+
for transport, label in (("grpc", "gRPC"), ("dubbo", "Dubbo")):
|
|
640
|
+
section = contract_state.get(transport) or {}
|
|
641
|
+
for item in section.get("changes") or []:
|
|
642
|
+
parts = _transport_contract_parts(item)
|
|
643
|
+
lines.append(
|
|
644
|
+
f"- `{label}` `{item.get('endpoint')}`:"
|
|
645
|
+
+ ";".join(parts)
|
|
646
|
+
)
|
|
647
|
+
if section.get("added_methods"):
|
|
648
|
+
lines.append(
|
|
649
|
+
f"- `{label}` 新增:{', '.join(section['added_methods'])}"
|
|
650
|
+
)
|
|
651
|
+
if section.get("removed_methods"):
|
|
652
|
+
lines.append(
|
|
653
|
+
f"- `{label}` 删除:{', '.join(section['removed_methods'])}"
|
|
654
|
+
)
|
|
655
|
+
lines.append("")
|
|
656
|
+
|
|
657
|
+
deleted_state = impact.get("deleted_apis") or {}
|
|
658
|
+
if deleted_state.get("checked"):
|
|
659
|
+
deleted = deleted_state.get("deleted") or []
|
|
660
|
+
lines.append("## 被删除的接口")
|
|
661
|
+
lines.append("")
|
|
662
|
+
if not deleted:
|
|
663
|
+
lines.append("_无_")
|
|
664
|
+
else:
|
|
665
|
+
lines.append("| 接口 | handler | 文件 |")
|
|
666
|
+
lines.append("|---|---|---|")
|
|
667
|
+
for item in deleted:
|
|
668
|
+
lines.append(
|
|
669
|
+
f"| `{item['endpoint']}` | {item.get('handler') or '-'} | "
|
|
670
|
+
f"{item.get('file') or '-'}:{item.get('line') or 0} |"
|
|
671
|
+
)
|
|
672
|
+
deprecated = (
|
|
673
|
+
(deleted_state.get("case_cleanup") or {}).get("deprecated") or []
|
|
674
|
+
)
|
|
675
|
+
if deprecated:
|
|
676
|
+
lines.append("")
|
|
677
|
+
lines.append(
|
|
678
|
+
f"已自动逻辑删除 {len(deprecated)} 条指向已删除接口的用例"
|
|
679
|
+
"(deprecated,不进入运行):"
|
|
680
|
+
)
|
|
681
|
+
lines.append("")
|
|
682
|
+
lines.append("| 用例 | 端点 | case_key |")
|
|
683
|
+
lines.append("|---|---|---|")
|
|
684
|
+
for item in deprecated:
|
|
685
|
+
lines.append(
|
|
686
|
+
f"| `{item['id']}` | `{item['endpoint']}` | "
|
|
687
|
+
f"{item['case_key']} |"
|
|
688
|
+
)
|
|
689
|
+
lines.append("")
|
|
690
|
+
elif deleted_state.get("warnings"):
|
|
691
|
+
lines.append("## 被删除的接口")
|
|
692
|
+
lines.append("")
|
|
693
|
+
lines.append("_扫描未完成_:" + ";".join(deleted_state["warnings"][:5]))
|
|
694
|
+
lines.append("")
|
|
695
|
+
|
|
696
|
+
if report.get("case_store"):
|
|
697
|
+
store = report["case_store"]
|
|
698
|
+
store_summary = store.get("summary") or {}
|
|
699
|
+
coverage = store.get("requirement_coverage") or {}
|
|
700
|
+
lines.append("## 用例审核与版本")
|
|
701
|
+
lines.append("")
|
|
702
|
+
lines.append(
|
|
703
|
+
f"- 用例库:`{store.get('case_base', '')}`,store v{store.get('store_version', 0)}"
|
|
704
|
+
)
|
|
705
|
+
lines.append(
|
|
706
|
+
f"- 已批准 {store_summary.get('approved', 0)} / 废弃 "
|
|
707
|
+
f"{store_summary.get('deprecated', 0)} / 历史版本 "
|
|
708
|
+
f"{store_summary.get('history_versions', 0)}"
|
|
709
|
+
)
|
|
710
|
+
lines.append(
|
|
711
|
+
f"- 最近批准:{store.get('approved_at') or '-'} by "
|
|
712
|
+
f"{store.get('approved_by') or '-'}"
|
|
713
|
+
)
|
|
714
|
+
pending = store.get("pending_proposals") or 0
|
|
715
|
+
lines.append(
|
|
716
|
+
f"- 待审 proposal:{pending}"
|
|
717
|
+
+ (
|
|
718
|
+
"(" + ", ".join(store.get("pending_proposal_paths") or []) + ")"
|
|
719
|
+
if pending else ""
|
|
720
|
+
)
|
|
721
|
+
)
|
|
722
|
+
lines.append(
|
|
723
|
+
f"- 需求覆盖:{coverage.get('covered', 0)}/{coverage.get('total', 0)}"
|
|
724
|
+
f" ({float(coverage.get('rate') or 0):.1%})"
|
|
725
|
+
)
|
|
726
|
+
contract = store.get("contract_drift") or {}
|
|
727
|
+
if contract.get("checked"):
|
|
728
|
+
lines.append(
|
|
729
|
+
f"- OpenAPI 漂移:{'有' if contract.get('changed') else '无'}"
|
|
730
|
+
)
|
|
731
|
+
else:
|
|
732
|
+
lines.append("- OpenAPI 漂移:未校验")
|
|
733
|
+
requirement_drift = store.get("requirement_drift") or {}
|
|
734
|
+
if requirement_drift.get("checked"):
|
|
735
|
+
changed_docs = requirement_drift.get("changed_docs") or []
|
|
736
|
+
missing_docs = requirement_drift.get("missing_docs") or []
|
|
737
|
+
lines.append(
|
|
738
|
+
f"- 需求文档漂移:变更 {len(changed_docs)} / 缺失 {len(missing_docs)}"
|
|
739
|
+
)
|
|
740
|
+
uncovered = coverage.get("uncovered") or []
|
|
741
|
+
if uncovered:
|
|
742
|
+
lines.append("")
|
|
743
|
+
lines.append("<details><summary>未覆盖需求</summary>")
|
|
744
|
+
for item in uncovered[:50]:
|
|
745
|
+
lines.append(
|
|
746
|
+
f"- `{item.get('doc')}#{item.get('section')}`"
|
|
747
|
+
f":`{item.get('reason')}`"
|
|
748
|
+
)
|
|
749
|
+
lines.append("</details>")
|
|
750
|
+
review_tail = store.get("review_log_tail") or []
|
|
751
|
+
if review_tail:
|
|
752
|
+
lines.append("")
|
|
753
|
+
lines.append("<details><summary>最近审核记录</summary>")
|
|
754
|
+
for item in review_tail[-10:]:
|
|
755
|
+
lines.append(
|
|
756
|
+
f"- {item.get('at')} `{item.get('case_id') or '-'}` "
|
|
757
|
+
f"{item.get('action')} {item.get('decision')} "
|
|
758
|
+
f"by {item.get('reviewer')}"
|
|
759
|
+
)
|
|
760
|
+
lines.append("</details>")
|
|
761
|
+
lines.append("")
|
|
762
|
+
|
|
763
|
+
rules = report.get("rules") or {}
|
|
764
|
+
if rules:
|
|
765
|
+
lines.append("## 规则与覆盖")
|
|
766
|
+
lines.append("")
|
|
767
|
+
if not rules.get("checked"):
|
|
768
|
+
lines.append(f"- 规则库未校验:`{rules.get('reason')}`")
|
|
769
|
+
if rules.get("error"):
|
|
770
|
+
lines.append(f"- 错误:`{str(rules['error'])[:500]}`")
|
|
771
|
+
lines.append("")
|
|
772
|
+
else:
|
|
773
|
+
counts = rules.get("counts") or {}
|
|
774
|
+
business = (rules.get("coverage") or {}).get("business") or {}
|
|
775
|
+
contract = (rules.get("coverage") or {}).get("contract") or {}
|
|
776
|
+
br_stats = business.get("stats") or {}
|
|
777
|
+
cr_stats = contract.get("stats") or {}
|
|
778
|
+
lines.append(
|
|
779
|
+
f"- 规则库:`{rules.get('ruleset_id') or '-'}` v{rules.get('version')} "
|
|
780
|
+
f"hash `{str(rules.get('hash') or '')[:12]}`"
|
|
781
|
+
)
|
|
782
|
+
if rules.get("path"):
|
|
783
|
+
lines.append(f"- 规则文件:`{rules.get('path')}`")
|
|
784
|
+
lines.append(
|
|
785
|
+
f"- BR:{counts.get('business_rules', 0)} 条,"
|
|
786
|
+
f"覆盖 {br_stats.get('covered', 0)}/{br_stats.get('active', 0)}"
|
|
787
|
+
f" ({float(br_stats.get('ratio') or 0):.1%})"
|
|
788
|
+
)
|
|
789
|
+
lines.append(
|
|
790
|
+
f"- CR:{counts.get('contract_rules', 0)} 条,"
|
|
791
|
+
f"覆盖 {cr_stats.get('covered', 0)}/{cr_stats.get('active', 0)}"
|
|
792
|
+
f" ({float(cr_stats.get('ratio') or 0):.1%})"
|
|
793
|
+
)
|
|
794
|
+
lines.append(
|
|
795
|
+
f"- 待确认:问题 {len(rules.get('questions') or [])} / "
|
|
796
|
+
f"缺口 {len(rules.get('gaps') or [])} / "
|
|
797
|
+
f"冲突 {len(rules.get('conflicts') or [])}(用例审核时确认)"
|
|
798
|
+
)
|
|
799
|
+
drift = rules.get("rule_drift") or {}
|
|
800
|
+
lines.append(
|
|
801
|
+
f"- 规则漂移:{'有' if drift.get('changed') else '无'}"
|
|
802
|
+
f"(store `{str(drift.get('store_hash') or '')[:12] or '-'}` → "
|
|
803
|
+
f"current `{str(drift.get('current_hash') or '')[:12]}`)"
|
|
804
|
+
)
|
|
805
|
+
orphaned = rules.get("orphaned_rule_keys") or []
|
|
806
|
+
if orphaned:
|
|
807
|
+
lines.append(f"- 孤立规则引用:{len(orphaned)}(用例引用的规则已不存在)")
|
|
808
|
+
stale_cases = rules.get("stale_rule_cases") or []
|
|
809
|
+
if stale_cases:
|
|
810
|
+
lines.append(f"- 引用非 active 规则的用例:{len(stale_cases)}")
|
|
811
|
+
uncovered = [
|
|
812
|
+
item
|
|
813
|
+
for item in (business.get("rules") or [])
|
|
814
|
+
if not item.get("covered") and item.get("status") == "active"
|
|
815
|
+
]
|
|
816
|
+
if uncovered:
|
|
817
|
+
lines.append("")
|
|
818
|
+
lines.append("<details><summary>未覆盖的 BR 规则</summary>")
|
|
819
|
+
for item in uncovered[:50]:
|
|
820
|
+
lines.append(
|
|
821
|
+
f"- `{item.get('rule_id')}` {item.get('rule_key')} "
|
|
822
|
+
f"({item.get('authority')})"
|
|
823
|
+
)
|
|
824
|
+
lines.append("</details>")
|
|
825
|
+
lines.append("")
|
|
826
|
+
|
|
827
|
+
mock = report.get("mock") or {}
|
|
828
|
+
if mock.get("checked"):
|
|
829
|
+
lines.append("## 下游 Mock")
|
|
830
|
+
lines.append("")
|
|
831
|
+
lines.append(
|
|
832
|
+
f"- 调用 {mock.get('calls', 0)} 次 / 会话 {mock.get('sessions', 0)} 个 / "
|
|
833
|
+
f"无法归因 {mock.get('unattributed_calls', 0)} 次"
|
|
834
|
+
)
|
|
835
|
+
by_result = mock.get("by_result") or {}
|
|
836
|
+
lines.append(
|
|
837
|
+
"- 结果:" + ",".join(f"{key}={value}" for key, value in by_result.items())
|
|
838
|
+
)
|
|
839
|
+
if mock.get("sessions_checked"):
|
|
840
|
+
lines.append(
|
|
841
|
+
f"- 会话绑定:{mock.get('session_records', 0)} 个会话 / "
|
|
842
|
+
f"未命中 `dep_id` {mock.get('unused_binding_count', 0)} 个"
|
|
843
|
+
)
|
|
844
|
+
if mock.get("sessions_missing"):
|
|
845
|
+
lines.append(
|
|
846
|
+
f"- 会话历史缺失:{mock['sessions_missing']} 个证据会话未出现在历史中"
|
|
847
|
+
)
|
|
848
|
+
if mock.get("degraded"):
|
|
849
|
+
lines.append("- 状态:**degraded**(存在晚到、阻断类错误或损坏证据)")
|
|
850
|
+
unused = mock.get("unused_bindings") or []
|
|
851
|
+
if unused:
|
|
852
|
+
lines.append("")
|
|
853
|
+
lines.append(
|
|
854
|
+
f"<details><summary>绑定但零调用({mock.get('unused_binding_count', 0)})</summary>"
|
|
855
|
+
)
|
|
856
|
+
for item in unused:
|
|
857
|
+
lines.append(
|
|
858
|
+
f"- `{item.get('case_id') or '-'}` / `{item.get('dep_id') or '-'}` "
|
|
859
|
+
f"→ `{item.get('branch') or '-'}`(session `{item.get('session_id')}`)"
|
|
860
|
+
)
|
|
861
|
+
lines.append("</details>")
|
|
862
|
+
late_calls = mock.get("late_calls") or []
|
|
863
|
+
if late_calls:
|
|
864
|
+
lines.append("")
|
|
865
|
+
lines.append(f"<details><summary>晚到调用({len(late_calls)})</summary>")
|
|
866
|
+
for call in late_calls:
|
|
867
|
+
lines.append(
|
|
868
|
+
f"- `{call.get('case_id') or '-'}` / `{call.get('dep_id') or '-'}` "
|
|
869
|
+
f"`{call.get('path')}`:{call.get('error') or '-'} at {call.get('at')}"
|
|
870
|
+
)
|
|
871
|
+
lines.append("</details>")
|
|
872
|
+
errors = mock.get("errors") or []
|
|
873
|
+
if errors:
|
|
874
|
+
lines.append("")
|
|
875
|
+
lines.append(f"<details><summary>阻断类调用({len(errors)})</summary>")
|
|
876
|
+
for call in errors:
|
|
877
|
+
lines.append(
|
|
878
|
+
f"- `{call.get('case_id') or '-'}` / `{call.get('dep_id') or '-'}` "
|
|
879
|
+
f"`{call.get('path')}`:`{call.get('result')}` "
|
|
880
|
+
f"{call.get('error') or '-'}"
|
|
881
|
+
)
|
|
882
|
+
lines.append("</details>")
|
|
883
|
+
evidence = mock.get("session_evidence") or []
|
|
884
|
+
if evidence:
|
|
885
|
+
lines.append("")
|
|
886
|
+
lines.append(
|
|
887
|
+
f"<details><summary>逐用例会话证据({len(evidence)})</summary>"
|
|
888
|
+
)
|
|
889
|
+
for item in evidence:
|
|
890
|
+
calls = sum(
|
|
891
|
+
int(binding.get("calls") or 0)
|
|
892
|
+
for binding in item.get("bindings") or []
|
|
893
|
+
)
|
|
894
|
+
lines.append(
|
|
895
|
+
f"- `{item.get('case_id') or '-'}` / session "
|
|
896
|
+
f"`{item.get('session_id') or '-'}`:"
|
|
897
|
+
f"状态 `{item.get('status') or '-'}`,调用 {calls} 次"
|
|
898
|
+
)
|
|
899
|
+
lines.append("</details>")
|
|
900
|
+
lines.append("")
|
|
901
|
+
agent_state = mock.get("agent") or {}
|
|
902
|
+
if int((mock.get("plan") or {}).get("dubbo_route_count") or 0):
|
|
903
|
+
heartbeat = agent_state.get("heartbeat") or {}
|
|
904
|
+
dubbo_agent = heartbeat.get("dubbo") or {}
|
|
905
|
+
lines.append("## Dubbo Filter")
|
|
906
|
+
lines.append("")
|
|
907
|
+
if not heartbeat:
|
|
908
|
+
lines.append(
|
|
909
|
+
f"- Filter 未确认在链上:`{agent_state.get('reason') or 'agent_heartbeat_missing'}`"
|
|
910
|
+
)
|
|
911
|
+
else:
|
|
912
|
+
lines.append(
|
|
913
|
+
f"- 版本:`{dubbo_agent.get('version') or '-'}` / "
|
|
914
|
+
f"实例化 {dubbo_agent.get('filter_instantiated', 0)} 次 / "
|
|
915
|
+
f"命中 {dubbo_agent.get('filter_hits', 0)} 次 / "
|
|
916
|
+
f"放行 {dubbo_agent.get('passthrough', 0)} 次 / "
|
|
917
|
+
f"错误 {dubbo_agent.get('errors', 0)} 次"
|
|
918
|
+
)
|
|
919
|
+
lines.append(
|
|
920
|
+
"- 序列化保真:"
|
|
921
|
+
+ ("已验证" if dubbo_agent.get("serialization_verified") else "未验证(serialization_verified=false)")
|
|
922
|
+
)
|
|
923
|
+
lines.append("")
|
|
924
|
+
elif mock.get("reason") not in (None, "mock_evidence_not_configured"):
|
|
925
|
+
lines.append("## 下游 Mock")
|
|
926
|
+
lines.append("")
|
|
927
|
+
lines.append(f"- 证据未读取:`{mock.get('reason')}`")
|
|
928
|
+
lines.append("")
|
|
929
|
+
|
|
930
|
+
if int((mock.get("plan") or {}).get("mq_route_count") or 0):
|
|
931
|
+
heartbeat = agent_state.get("heartbeat") or {}
|
|
932
|
+
mq_agent = heartbeat.get("mq") or {}
|
|
933
|
+
lines.append("## MQ 生产者拦截")
|
|
934
|
+
lines.append("")
|
|
935
|
+
if not heartbeat:
|
|
936
|
+
lines.append(
|
|
937
|
+
f"- 生产者拦截未确认:`{agent_state.get('reason') or 'agent_heartbeat_missing'}`"
|
|
938
|
+
)
|
|
939
|
+
else:
|
|
940
|
+
clients = ", ".join(mq_agent.get("clients") or []) or "-"
|
|
941
|
+
lines.append(
|
|
942
|
+
f"- 客户端:{clients} / 已上报 {mq_agent.get('published', 0)} 次 / "
|
|
943
|
+
f"拦截 {mq_agent.get('suppressed', 0)} 次 / "
|
|
944
|
+
f"错误 {mq_agent.get('errors', 0)} 次"
|
|
945
|
+
)
|
|
946
|
+
lines.append("- 消息未真正发送到 broker;只验证 SUT 准备发出的内容")
|
|
947
|
+
lines.append("")
|
|
948
|
+
|
|
949
|
+
plan = mock.get("plan") or {}
|
|
950
|
+
if plan:
|
|
951
|
+
lines.append("## 下游 Mock 计划")
|
|
952
|
+
lines.append("")
|
|
953
|
+
lines.append(
|
|
954
|
+
f"- 模式:`{plan.get('mode')}` / SUT `{plan.get('sut_id')}` "
|
|
955
|
+
f"/ namespace `{plan.get('namespace')}`"
|
|
956
|
+
)
|
|
957
|
+
if plan.get("plan"):
|
|
958
|
+
lines.append(f"- 计划文件:`{plan.get('plan')}`")
|
|
959
|
+
if plan.get("endpoint"):
|
|
960
|
+
lines.append(f"- 内嵌地址:`{plan.get('endpoint')}`(不含 token)")
|
|
961
|
+
lines.append(
|
|
962
|
+
f"- 路由 {plan.get('route_count', 0)} 个 / 注入 {plan.get('injection_count', 0)} 个"
|
|
963
|
+
f" / unsupported {plan.get('unsupported_count', 0)} 个"
|
|
964
|
+
)
|
|
965
|
+
if plan.get("warnings"):
|
|
966
|
+
lines.append("")
|
|
967
|
+
lines.append("<details><summary>计划告警</summary>")
|
|
968
|
+
for item in plan["warnings"]:
|
|
969
|
+
lines.append(f"- `{item}`")
|
|
970
|
+
lines.append("</details>")
|
|
971
|
+
lines.append("")
|
|
972
|
+
|
|
973
|
+
data_plan = report.get("data_plan") or {}
|
|
974
|
+
if data_plan:
|
|
975
|
+
lines.append("## 造数计划")
|
|
976
|
+
lines.append("")
|
|
977
|
+
lines.append(f"- 运行域:`{data_plan.get('run_scope') or '-'}`")
|
|
978
|
+
lines.append(
|
|
979
|
+
f"- 计划数:{data_plan.get('plans', 0)} / "
|
|
980
|
+
f"数据库:{'已配置' if data_plan.get('database_url_configured') else '未配置'}"
|
|
981
|
+
)
|
|
982
|
+
if data_plan.get("path"):
|
|
983
|
+
lines.append(f"- 计划文件:`{data_plan.get('path')}`")
|
|
984
|
+
missing = data_plan.get("missing_plans") or []
|
|
985
|
+
if missing:
|
|
986
|
+
lines.append(
|
|
987
|
+
f"- 缺少造数计划的前置用例:{len(missing)}("
|
|
988
|
+
+ ", ".join(str(item) for item in missing[:20]) + ")"
|
|
989
|
+
)
|
|
990
|
+
lines.append("")
|
|
991
|
+
|
|
992
|
+
blocked = report.get("blocked") or []
|
|
993
|
+
if blocked:
|
|
994
|
+
lines.append("## 数据阻断(blocked)")
|
|
995
|
+
lines.append("")
|
|
996
|
+
for item in blocked[:50]:
|
|
997
|
+
lines.append(
|
|
998
|
+
f"- {item.get('case_id') or '-'} `{item.get('endpoint')}`:"
|
|
999
|
+
f"`{item.get('reason')}` {item.get('message') or ''}"
|
|
1000
|
+
)
|
|
1001
|
+
lines.append("")
|
|
1002
|
+
|
|
1003
|
+
lines.append("## 覆盖边界(unmapped)")
|
|
1004
|
+
lines.append("")
|
|
1005
|
+
route_health = (report.get("routes") or {}).get("health") or {}
|
|
1006
|
+
if route_health:
|
|
1007
|
+
lines.append(
|
|
1008
|
+
f"- 路由清单健康度:{route_health.get('status')}"
|
|
1009
|
+
f"(可归因路由 {route_health.get('attributed_routes', 0)}"
|
|
1010
|
+
f" / 总路由 {route_health.get('total_routes', 0)}"
|
|
1011
|
+
f" / Controller 文件 {route_health.get('controller_files') or '-'}"
|
|
1012
|
+
f" / OpenAPI operation {route_health.get('openapi_operations') or '-'})"
|
|
1013
|
+
)
|
|
1014
|
+
for reason in route_health.get("reasons") or []:
|
|
1015
|
+
lines.append(f" - ⚠️ `{reason}`")
|
|
1016
|
+
unmapped = report["unmapped"]
|
|
1017
|
+
lines.append(f"- 未追溯符号:{len(unmapped.get('symbols', []))}")
|
|
1018
|
+
lines.append(f"- 路由冲突/不可判:{len(unmapped.get('routes', []))}")
|
|
1019
|
+
lines.append(f"- 画像未闭环:{len(unmapped.get('profile_unmapped', []))}")
|
|
1020
|
+
lines.append(f"- 语言不支持文件:{len(unmapped.get('unsupported_files', []))}")
|
|
1021
|
+
lines.append(f"- 契约缺失接口:{len(unmapped.get('contract_incomplete', []))}")
|
|
1022
|
+
lines.append(f"- 变更接口无用例:{len(unmapped.get('changed_endpoints_without_cases', []))}")
|
|
1023
|
+
if unmapped.get("symbols"):
|
|
1024
|
+
lines.append("")
|
|
1025
|
+
lines.append("<details><summary>未追溯符号明细</summary>")
|
|
1026
|
+
for item in unmapped["symbols"][:50]:
|
|
1027
|
+
lines.append(f"- `{item.get('symbol')}`({item.get('reason')})")
|
|
1028
|
+
lines.append("</details>")
|
|
1029
|
+
lines.append("")
|
|
1030
|
+
|
|
1031
|
+
lines.append("## 失败明细")
|
|
1032
|
+
lines.append("")
|
|
1033
|
+
failures = report.get("failures") or []
|
|
1034
|
+
if not failures:
|
|
1035
|
+
lines.append("_无失败_")
|
|
1036
|
+
else:
|
|
1037
|
+
lines.append("| 用例 | 接口 | 类别 | 归因 | 归属 | 尝试 |")
|
|
1038
|
+
lines.append("|---|---|---|---|---|---|")
|
|
1039
|
+
for failure in failures:
|
|
1040
|
+
attempts = " → ".join(
|
|
1041
|
+
f"{a.get('n')}:{a.get('status')}" for a in failure.get("attempts", [])
|
|
1042
|
+
)
|
|
1043
|
+
lines.append(
|
|
1044
|
+
f"| {failure['case_id']} | `{failure['endpoint']}` | {failure['category']} | "
|
|
1045
|
+
f"{failure.get('reason')} | {failure.get('action_target') or '-'} | {attempts} |"
|
|
1046
|
+
)
|
|
1047
|
+
lines.append("")
|
|
1048
|
+
|
|
1049
|
+
if report.get("unexecuted"):
|
|
1050
|
+
lines.append("## 未执行用例")
|
|
1051
|
+
lines.append("")
|
|
1052
|
+
for item in report["unexecuted"][:30]:
|
|
1053
|
+
lines.append(f"- {item['case_id']} `{item['endpoint']}`({item['reason']})")
|
|
1054
|
+
lines.append("")
|
|
1055
|
+
|
|
1056
|
+
audit = report.get("audit") or {}
|
|
1057
|
+
if audit:
|
|
1058
|
+
lines.append("## 审计完整性")
|
|
1059
|
+
lines.append("")
|
|
1060
|
+
labels = {
|
|
1061
|
+
"not_implemented": "未实现",
|
|
1062
|
+
"not_applicable": "不适用",
|
|
1063
|
+
"not_available": "无数据",
|
|
1064
|
+
}
|
|
1065
|
+
for name, item in audit.items():
|
|
1066
|
+
status = item.get("status")
|
|
1067
|
+
if status in labels:
|
|
1068
|
+
lines.append(f"- `{name}`:{labels[status]}")
|
|
1069
|
+
elif item.get("checked") is False:
|
|
1070
|
+
lines.append(f"- `{name}`:未检查")
|
|
1071
|
+
elif item.get("checked") is not None:
|
|
1072
|
+
detail = "已检查"
|
|
1073
|
+
if name == "weak_oracle":
|
|
1074
|
+
detail += f",{item.get('count', 0)} 条弱断言"
|
|
1075
|
+
if name == "mock_sessions":
|
|
1076
|
+
detail += f",{item.get('evidence', 0)} 条会话证据"
|
|
1077
|
+
lines.append(f"- `{name}`:{detail}")
|
|
1078
|
+
lines.append("")
|
|
1079
|
+
|
|
1080
|
+
usage = report.get("token_usage") or {}
|
|
1081
|
+
if usage.get("calls"):
|
|
1082
|
+
lines.append("## Token 用量")
|
|
1083
|
+
lines.append("")
|
|
1084
|
+
lines.append(
|
|
1085
|
+
f"- 调用 {usage.get('calls', 0)} 次 / 输入 "
|
|
1086
|
+
f"{usage.get('total_input_tokens', 0)} / 输出 "
|
|
1087
|
+
f"{usage.get('total_output_tokens', 0)}"
|
|
1088
|
+
)
|
|
1089
|
+
if usage.get("by_node_status") == "not_available":
|
|
1090
|
+
lines.append("- 按节点统计不可用:当前 LLMUsage 未记录节点标签")
|
|
1091
|
+
lines.append("")
|
|
1092
|
+
|
|
1093
|
+
lines.append("## 产物")
|
|
1094
|
+
lines.append("")
|
|
1095
|
+
for name, path in (report.get("artifacts") or {}).items():
|
|
1096
|
+
lines.append(f"- `{name}`:`{path}`")
|
|
1097
|
+
lines.append("")
|
|
1098
|
+
return "\n".join(lines)
|