ohos-devloop 0.1.2__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.
- ohos_devloop/__init__.py +2 -0
- ohos_devloop/_version.py +24 -0
- ohos_devloop/agents/skills/collab-delegate/SKILL.md +79 -0
- ohos_devloop/agents/skills/loop-iterate/SKILL.md +54 -0
- ohos_devloop/agents/skills/openharmony-ci/SKILL.md +71 -0
- ohos_devloop/agents/skills/openharmony-ci/agents/openai.yaml +4 -0
- ohos_devloop/agents/skills/openharmony-ci/scripts/openharmony_ci.py +520 -0
- ohos_devloop/agents/skills/pool-status/SKILL.md +47 -0
- ohos_devloop/config/e2e-cases.yaml +31 -0
- ohos_devloop/config/e2e-hap.yaml +54 -0
- ohos_devloop/config/inventory-template.yaml +35 -0
- ohos_devloop/config/inventory.yaml +68 -0
- ohos_devloop/config/report-templates/analysis-report.md +48 -0
- ohos_devloop/config/report-templates/impl-report.md +47 -0
- ohos_devloop/config/task-template.md +21 -0
- ohos_devloop/config/tdd-board.yaml +31 -0
- ohos_devloop/config/tdd-coverage.yaml +47 -0
- ohos_devloop/config/tdd-emulator.yaml +36 -0
- ohos_devloop/config/tdd-host.yaml +26 -0
- ohos_devloop/config/tdd-suites.yaml +34 -0
- ohos_devloop/config/templates/agents-user.md +11 -0
- ohos_devloop/config/templates/quickstart.md +82 -0
- ohos_devloop/config/verify.yaml +45 -0
- ohos_devloop/examples/anchor-e2e.yaml +55 -0
- ohos_devloop/examples/assert-smoke.yaml +33 -0
- ohos_devloop/examples/diffcov-fixture/cov.json +6688 -0
- ohos_devloop/examples/diffcov-fixture/diff.txt +24 -0
- ohos_devloop/examples/diffcov-smoke.yaml +32 -0
- ohos_devloop/examples/e2e-emu-smoke.yaml +45 -0
- ohos_devloop/examples/layout-fixture.norm.json +1 -0
- ohos_devloop/examples/smoke.yaml +27 -0
- ohos_devloop/ohos_cli.py +131 -0
- ohos_devloop/scripts/agent-run-v3.sh +149 -0
- ohos_devloop/scripts/apply.py +1448 -0
- ohos_devloop/scripts/check_env.py +284 -0
- ohos_devloop/scripts/collab.py +303 -0
- ohos_devloop/scripts/diffcov.py +211 -0
- ohos_devloop/scripts/flash.py +511 -0
- ohos_devloop/scripts/mount_ws.py +192 -0
- ohos_devloop/scripts/release.py +2645 -0
- ohos_devloop/scripts/release_audit.py +260 -0
- ohos_devloop/scripts/release_metadata.py +397 -0
- ohos_devloop/scripts/release_smoke.py +287 -0
- ohos_devloop/scripts/report_draft.py +234 -0
- ohos_devloop/scripts/server_init.py +310 -0
- ohos_devloop/scripts/sgrep.py +82 -0
- ohos_devloop/scripts/sign_hap.py +256 -0
- ohos_devloop/scripts/telemetry.py +260 -0
- ohos_devloop/scripts/ui_probe.py +396 -0
- ohos_devloop/scripts/verify_frame_diff.py +138 -0
- ohos_devloop/scripts/ws_init.py +131 -0
- ohos_devloop/scripts/wsroot.py +192 -0
- ohos_devloop-0.1.2.dist-info/METADATA +177 -0
- ohos_devloop-0.1.2.dist-info/RECORD +58 -0
- ohos_devloop-0.1.2.dist-info/WHEEL +5 -0
- ohos_devloop-0.1.2.dist-info/entry_points.txt +2 -0
- ohos_devloop-0.1.2.dist-info/licenses/LICENSE +202 -0
- ohos_devloop-0.1.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
diffcov.py —— TDD 差分覆盖率(库 + CLI):gcovr JSON × git diff 新增行 → 覆盖/未覆盖清单
|
|
5
|
+
|
|
6
|
+
小循环证据层:worker 改码(大仓子仓)产生的新增分支是否被 TDD 用例实际踏到,
|
|
7
|
+
红绿灯(PASSED/FAILED/钉数)看不出来。本模块把「新增/修改行 × 覆盖数据」相交出清单与判据。
|
|
8
|
+
|
|
9
|
+
判据口径(diffcov-20261111 任务合成 A/B 判别力实测定稿):
|
|
10
|
+
- 行级是硬门:新增可执行行 count=0 → UNCOVERED(B 分支体实测 0、A 分支体实测 23,判别力成立)
|
|
11
|
+
- 分支方向级(taken/total)只作参考:`if (cond) {X}` 无 else 时 guard 的 false 方向不被踏
|
|
12
|
+
不等于缺陷(合成 A 的 false 方向也 0),不能硬门——但 guard true 侧体行没被踏到会体现在行级
|
|
13
|
+
|
|
14
|
+
配方接线:apply.py tdd_host 步骤 coverage 模式(构建 --gn-args use_clang_coverage=true →
|
|
15
|
+
跑套件 → .gcda 随对象树落盘 → gcovr 转换 → 本模块差分);CLI 形态供 smoke 自测与事后重析。
|
|
16
|
+
细节与坑位见 RUNBOOK「TDD 差分覆盖率」节。
|
|
17
|
+
|
|
18
|
+
CLI:
|
|
19
|
+
python scripts/diffcov.py --json cov.json --diff diff.txt \
|
|
20
|
+
--anchor foundation/arkui/ace_engine [--line-min 100] \
|
|
21
|
+
[--out-md list.md] [--out-json list.json]
|
|
22
|
+
退出码:0=达标 2=未达标 1=输入错误
|
|
23
|
+
"""
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import argparse
|
|
27
|
+
import json
|
|
28
|
+
import re
|
|
29
|
+
import sys
|
|
30
|
+
|
|
31
|
+
# 构建会刷改的生成物(agent-run-v3.sh 噪音清单同源)——差分侧剔除,不进判据
|
|
32
|
+
# 实测覆盖:koala_projects/<proj>/**/generated/**(callback_kind.h 等)
|
|
33
|
+
# interfaces/native/<可选一层>/generated/**(arkoala_api / converter_generated.h)
|
|
34
|
+
NOISE_RE = re.compile(
|
|
35
|
+
r"(^|/)(frameworks/bridge/arkts_frontend/koala_projects/[^/]+/.*?/generated/"
|
|
36
|
+
r"|frameworks/core/interfaces/native/([^/]+/)?generated/)"
|
|
37
|
+
)
|
|
38
|
+
SOURCE_EXT = (".cpp", ".cc", ".cxx", ".c", ".h", ".hpp")
|
|
39
|
+
HUNK_RE = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def parse_git_diff(diff_text: str) -> dict[str, list[int]]:
|
|
43
|
+
"""`git diff -U0/-U3 --no-color` 文本 → {仓库相对文件: [新增侧行号]}(删除行不计)。"""
|
|
44
|
+
added: dict[str, set[int]] = {}
|
|
45
|
+
cur_file: str | None = None
|
|
46
|
+
cur_line: int | None = None
|
|
47
|
+
for line in diff_text.splitlines():
|
|
48
|
+
if line.startswith("+++ b/"):
|
|
49
|
+
cur_file, cur_line = line[6:], None
|
|
50
|
+
elif line.startswith("@@"):
|
|
51
|
+
m = HUNK_RE.match(line)
|
|
52
|
+
if m and cur_file:
|
|
53
|
+
cur_line = int(m.group(1))
|
|
54
|
+
elif cur_line is not None and line.startswith("+"):
|
|
55
|
+
added.setdefault(cur_file, set()).add(cur_line)
|
|
56
|
+
cur_line += 1
|
|
57
|
+
elif cur_line is not None and line.startswith("-"):
|
|
58
|
+
pass # 删除行不推进新增侧行号
|
|
59
|
+
elif cur_line is not None:
|
|
60
|
+
cur_line += 1 # 上下文行(-U3 时出现)
|
|
61
|
+
return {f: sorted(ls) for f, ls in added.items()}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def is_noise(repo_rel: str) -> bool:
|
|
65
|
+
return bool(NOISE_RE.search(repo_rel)) or not repo_rel.endswith(SOURCE_EXT)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def changed_source_files(diff_text: str) -> list[str]:
|
|
69
|
+
"""差分文本里真正参与覆盖判定的源码文件(剔生成物/非 C-C++ 源)。"""
|
|
70
|
+
return sorted(f for f in parse_git_diff(diff_text) if not is_noise(f))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _cov_index(cov_json_path: str, anchors: list[str]) -> dict[str, dict]:
|
|
74
|
+
"""gcovr --json → {子仓相对文件: {行号: {count, branches:[(count, fallthrough, throw)]}}}。
|
|
75
|
+
|
|
76
|
+
gcovr 路径是 `-r` 根相对(也兼容绝对路径):锚(子仓名)首次出现之后的部分即子仓相对路径。
|
|
77
|
+
"""
|
|
78
|
+
with open(cov_json_path, "r", encoding="utf-8") as f:
|
|
79
|
+
cov = json.load(f)
|
|
80
|
+
idx: dict[str, dict] = {}
|
|
81
|
+
for entry in cov.get("files", []):
|
|
82
|
+
p = entry.get("file", "")
|
|
83
|
+
for a in anchors:
|
|
84
|
+
seg = a.rstrip("/") + "/"
|
|
85
|
+
pos = p.find(seg)
|
|
86
|
+
if pos >= 0:
|
|
87
|
+
rel = p[pos + len(seg):]
|
|
88
|
+
lines: dict[int, dict] = {}
|
|
89
|
+
for le in entry.get("lines", []):
|
|
90
|
+
lines[int(le["line_number"])] = {
|
|
91
|
+
"count": int(le.get("count", 0)),
|
|
92
|
+
"branches": [
|
|
93
|
+
(int(b.get("count", 0)), bool(b.get("fallthrough")), bool(b.get("throw")))
|
|
94
|
+
for b in le.get("branches", [])
|
|
95
|
+
],
|
|
96
|
+
}
|
|
97
|
+
idx[rel] = lines
|
|
98
|
+
break
|
|
99
|
+
return idx
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def compute(diff_text: str, cov_json_path: str, anchors: list[str],
|
|
103
|
+
line_min: int = 100) -> dict:
|
|
104
|
+
"""差分覆盖主计算:新增行 × 覆盖数据 → rows/summary/verdict(不落盘,落盘由调用方定)。
|
|
105
|
+
|
|
106
|
+
- 行在 gcovr 数据里 → COVERED/UNCOVERED/NOT-EXECUTABLE(含分支 taken/total)
|
|
107
|
+
- 文件不在数据里(未编进该 target 等)→ no_cov_data(只报告不判据)
|
|
108
|
+
- 生成物/非源码 → noise(剔除)
|
|
109
|
+
"""
|
|
110
|
+
added = parse_git_diff(diff_text)
|
|
111
|
+
idx = _cov_index(cov_json_path, anchors)
|
|
112
|
+
|
|
113
|
+
rows, no_data, noise = [], [], []
|
|
114
|
+
for rel in sorted(added):
|
|
115
|
+
if is_noise(rel):
|
|
116
|
+
noise.append(rel)
|
|
117
|
+
continue
|
|
118
|
+
lines = idx.get(rel)
|
|
119
|
+
if lines is None:
|
|
120
|
+
no_data.append(rel)
|
|
121
|
+
continue
|
|
122
|
+
for no in added[rel]:
|
|
123
|
+
le = lines.get(no)
|
|
124
|
+
if le is None:
|
|
125
|
+
rows.append({"file": rel, "line": no, "status": "NOT-EXECUTABLE",
|
|
126
|
+
"count": None, "branches_total": 0, "branches_taken": 0})
|
|
127
|
+
continue
|
|
128
|
+
taken = sum(1 for c, _, _ in le["branches"] if c > 0)
|
|
129
|
+
rows.append({"file": rel, "line": no, "status": "COVERED" if le["count"] > 0 else "UNCOVERED",
|
|
130
|
+
"count": le["count"],
|
|
131
|
+
"branches_total": len(le["branches"]), "branches_taken": taken})
|
|
132
|
+
|
|
133
|
+
exe = [r for r in rows if r["status"] != "NOT-EXECUTABLE"]
|
|
134
|
+
covd = [r for r in exe if r["status"] == "COVERED"]
|
|
135
|
+
uncovd = [r for r in exe if r["status"] == "UNCOVERED"]
|
|
136
|
+
nb_total = sum(r["branches_total"] for r in exe)
|
|
137
|
+
nb_taken = sum(r["branches_taken"] for r in exe)
|
|
138
|
+
line_pct = round(100.0 * len(covd) / len(exe), 1) if exe else None
|
|
139
|
+
summary = {
|
|
140
|
+
"added_lines": len(rows), "executable": len(exe),
|
|
141
|
+
"covered": len(covd), "uncovered": len(uncovd), "line_pct": line_pct,
|
|
142
|
+
"branches_total": nb_total, "branches_taken": nb_taken,
|
|
143
|
+
"branch_pct": round(100.0 * nb_taken / nb_total, 1) if nb_total else None,
|
|
144
|
+
"no_cov_data_files": no_data, "noise_files": noise,
|
|
145
|
+
"line_min": line_min,
|
|
146
|
+
}
|
|
147
|
+
# 无可执行新增行(纯注释/无数据)不判败;有可执行行则按行级阈值硬门
|
|
148
|
+
ok = True if not exe else (line_pct is not None and line_pct >= line_min)
|
|
149
|
+
return {"ok": ok, "rows": rows, "summary": summary,
|
|
150
|
+
"uncovered_rows": [r for r in uncovd]}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def render_md(res: dict) -> str:
|
|
154
|
+
s = res["summary"]
|
|
155
|
+
out = ["# 差分覆盖清单(仅新增/修改行)", ""]
|
|
156
|
+
out.append(f"- 判据: 行级覆盖 ≥ {s['line_min']}%(分支方向级仅参考,见 RUNBOOK「TDD 差分覆盖率」)")
|
|
157
|
+
out.append(f"- 新增/修改行: {s['added_lines']}(可执行 {s['executable']})")
|
|
158
|
+
if s["line_pct"] is not None:
|
|
159
|
+
out.append(f"- 行覆盖: {s['covered']}/{s['executable']} = {s['line_pct']}%")
|
|
160
|
+
if s["branch_pct"] is not None:
|
|
161
|
+
out.append(f"- 分支方向: {s['branches_taken']}/{s['branches_total']} = {s['branch_pct']}%(参考)")
|
|
162
|
+
if s["no_cov_data_files"]:
|
|
163
|
+
out.append(f"- 无覆盖数据文件(不判据): {', '.join(s['no_cov_data_files'][:5])}"
|
|
164
|
+
+ (f" 等 {len(s['no_cov_data_files'])} 个" if len(s["no_cov_data_files"]) > 5 else ""))
|
|
165
|
+
if s["noise_files"]:
|
|
166
|
+
out.append(f"- 生成物噪音剔除: {len(s['noise_files'])} 个文件")
|
|
167
|
+
out += ["", "| 文件 | 行 | 状态 | count | 分支 taken/total |", "|---|---|---|---|---|"]
|
|
168
|
+
for r in res["rows"]:
|
|
169
|
+
out.append("| {} | {} | {} | {} | {}/{} |".format(
|
|
170
|
+
r["file"], r["line"], r["status"],
|
|
171
|
+
"-" if r["count"] is None else r["count"],
|
|
172
|
+
r["branches_taken"], r["branches_total"]))
|
|
173
|
+
out.append("")
|
|
174
|
+
out.append(f"**判定: {'PASS' if res['ok'] else 'FAIL'}**")
|
|
175
|
+
return "\n".join(out) + "\n"
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def main() -> int:
|
|
179
|
+
ap = argparse.ArgumentParser(description="TDD 差分覆盖率:gcovr JSON × git diff 新增行")
|
|
180
|
+
ap.add_argument("--json", required=True, help="gcovr --json 输出文件")
|
|
181
|
+
ap.add_argument("--diff", required=True, help="git diff --no-color -U0/-U3 文本文件")
|
|
182
|
+
ap.add_argument("--anchor", action="append", default=["foundation/arkui/ace_engine"],
|
|
183
|
+
help="子仓路径锚(可多次;gcovr 路径中去掉锚后=子仓相对路径)")
|
|
184
|
+
ap.add_argument("--line-min", type=int, default=100, help="行级覆盖阈值%%(默认 100=零未覆盖)")
|
|
185
|
+
ap.add_argument("--out-md", help="清单 markdown 输出")
|
|
186
|
+
ap.add_argument("--out-json", help="清单 json 输出")
|
|
187
|
+
a = ap.parse_args()
|
|
188
|
+
|
|
189
|
+
try:
|
|
190
|
+
diff_text = open(a.diff, "r", encoding="utf-8", errors="replace").read()
|
|
191
|
+
res = compute(diff_text, a.json, a.anchor, a.line_min)
|
|
192
|
+
except (OSError, json.JSONDecodeError) as e:
|
|
193
|
+
print(f"ERROR: {e}", file=sys.stderr)
|
|
194
|
+
return 1
|
|
195
|
+
|
|
196
|
+
s = res["summary"]
|
|
197
|
+
print("executable={exe} covered={cov} uncovered={unc} line_pct={lp} branches={bt}/{btt} "
|
|
198
|
+
"no_data_files={ndf} noise={nz}".format(
|
|
199
|
+
exe=s["executable"], cov=s["covered"], unc=s["uncovered"],
|
|
200
|
+
lp=s["line_pct"], bt=s["branches_taken"], btt=s["branches_total"],
|
|
201
|
+
ndf=len(s["no_cov_data_files"]), nz=len(s["noise_files"])))
|
|
202
|
+
if a.out_md:
|
|
203
|
+
open(a.out_md, "w", encoding="utf-8").write(render_md(res))
|
|
204
|
+
if a.out_json:
|
|
205
|
+
open(a.out_json, "w", encoding="utf-8").write(
|
|
206
|
+
json.dumps(res, ensure_ascii=False, indent=2))
|
|
207
|
+
return 0 if res["ok"] else 2
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
if __name__ == "__main__":
|
|
211
|
+
sys.exit(main())
|