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,520 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2026 Huawei Device Co., Ltd.
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import io
|
|
21
|
+
import json
|
|
22
|
+
import os
|
|
23
|
+
import re
|
|
24
|
+
import subprocess
|
|
25
|
+
import sys
|
|
26
|
+
import tarfile
|
|
27
|
+
import urllib.error
|
|
28
|
+
import urllib.parse
|
|
29
|
+
import urllib.request
|
|
30
|
+
import zipfile
|
|
31
|
+
from typing import Any, Dict, List, Optional, Sequence, Tuple
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
DCP_EVENT_URL = "https://dcp.openharmony.cn/api/codecheckAccess/ci-portal/v1/event/{event_id}"
|
|
35
|
+
DCP_FILES_URL = "https://dcp.openharmony.cn/api/dataService/ci-portal/v1/files?directoryUrl={directory}"
|
|
36
|
+
CI_DOWNLOAD_URL = "https://cidownload.openharmony.cn/{path}"
|
|
37
|
+
EVENT_ID_PATTERN = re.compile(r"/detail/([0-9a-f]{24})(?:/|$)")
|
|
38
|
+
PR_URL_PATTERN = re.compile(r"/(?:pull|merge_requests)/(\d+)(?:/|$)")
|
|
39
|
+
SUCCESS_RESULTS = {"success", "passed", "pass"}
|
|
40
|
+
FAILURE_RESULTS = {"failed", "fail", "error", "canceled", "cancelled", "skip", "skipped"}
|
|
41
|
+
DEFAULT_XDG_CACHE_HOME = "/tmp/openharmony-ci-cache"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ToolError(RuntimeError):
|
|
45
|
+
"""Domain-specific error for user-facing failures."""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def parse_args() -> argparse.Namespace:
|
|
49
|
+
parser = argparse.ArgumentParser(
|
|
50
|
+
description="Query OpenHarmony CI status and fetch failure logs when needed."
|
|
51
|
+
)
|
|
52
|
+
source_group = parser.add_mutually_exclusive_group(required=True)
|
|
53
|
+
source_group.add_argument("--event-id", help="DCP event id, for example 69c51ede64650f998b1d01a4")
|
|
54
|
+
source_group.add_argument("--pr", type=int, help="GitCode PR number")
|
|
55
|
+
source_group.add_argument("--pr-url", help="GitCode PR URL")
|
|
56
|
+
parser.add_argument(
|
|
57
|
+
"--repo",
|
|
58
|
+
default="openharmony/arkui_ace_engine",
|
|
59
|
+
help="oh-gc repo name when querying PR comments",
|
|
60
|
+
)
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
"--log-mode",
|
|
63
|
+
choices=("auto", "always", "never"),
|
|
64
|
+
default="auto",
|
|
65
|
+
help="auto: fetch logs only for non-success jobs; always: fetch logs for all jobs with artifacts; never: status only",
|
|
66
|
+
)
|
|
67
|
+
parser.add_argument(
|
|
68
|
+
"--log-lines",
|
|
69
|
+
type=int,
|
|
70
|
+
default=80,
|
|
71
|
+
help="Tail line count to keep when summarizing text logs",
|
|
72
|
+
)
|
|
73
|
+
parser.add_argument(
|
|
74
|
+
"--download-dir",
|
|
75
|
+
help="Optional directory for downloaded log archives/files",
|
|
76
|
+
)
|
|
77
|
+
parser.add_argument("--json", action="store_true", help="Print machine-readable JSON")
|
|
78
|
+
return parser.parse_args()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def http_get_json(url: str) -> Dict[str, Any]:
|
|
82
|
+
request = urllib.request.Request(url, headers={"User-Agent": "openharmony-ci/1.0"})
|
|
83
|
+
try:
|
|
84
|
+
with urllib.request.urlopen(request, timeout=30) as response:
|
|
85
|
+
content = response.read()
|
|
86
|
+
except urllib.error.URLError as exc:
|
|
87
|
+
raise ToolError(f"request failed: {url}: {exc}") from exc
|
|
88
|
+
try:
|
|
89
|
+
return json.loads(content.decode("utf-8"))
|
|
90
|
+
except json.JSONDecodeError as exc:
|
|
91
|
+
raise ToolError(f"invalid json from {url}") from exc
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def http_get_bytes(url: str) -> bytes:
|
|
95
|
+
request = urllib.request.Request(url, headers={"User-Agent": "openharmony-ci/1.0"})
|
|
96
|
+
try:
|
|
97
|
+
with urllib.request.urlopen(request, timeout=60) as response:
|
|
98
|
+
return response.read()
|
|
99
|
+
except urllib.error.URLError as exc:
|
|
100
|
+
raise ToolError(f"download failed: {url}: {exc}") from exc
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def build_oh_gc_env() -> Dict[str, str]:
|
|
104
|
+
env = os.environ.copy()
|
|
105
|
+
if not env.get("XDG_CACHE_HOME"):
|
|
106
|
+
env["XDG_CACHE_HOME"] = DEFAULT_XDG_CACHE_HOME
|
|
107
|
+
return env
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def run_oh_gc(args: Sequence[str]) -> Any:
|
|
111
|
+
cmd = ["oh-gc", *args]
|
|
112
|
+
try:
|
|
113
|
+
completed = subprocess.run(cmd, capture_output=True, text=True, check=True, env=build_oh_gc_env())
|
|
114
|
+
except FileNotFoundError as exc:
|
|
115
|
+
raise ToolError("oh-gc is not installed or not in PATH") from exc
|
|
116
|
+
except subprocess.CalledProcessError as exc:
|
|
117
|
+
stderr = (exc.stderr or "").strip()
|
|
118
|
+
stdout = (exc.stdout or "").strip()
|
|
119
|
+
detail = stderr or stdout or f"exit code {exc.returncode}"
|
|
120
|
+
if "Could not connect to GitCode" in detail:
|
|
121
|
+
detail = (
|
|
122
|
+
f"{detail}. This workflow requires network access to GitCode, "
|
|
123
|
+
"and may also need access to dcp.openharmony.cn and cidownload.openharmony.cn"
|
|
124
|
+
)
|
|
125
|
+
raise ToolError(f"oh-gc command failed: {' '.join(cmd)}: {detail}") from exc
|
|
126
|
+
output = completed.stdout.strip()
|
|
127
|
+
if not output:
|
|
128
|
+
return []
|
|
129
|
+
try:
|
|
130
|
+
return json.loads(output)
|
|
131
|
+
except json.JSONDecodeError as exc:
|
|
132
|
+
raise ToolError(f"oh-gc returned non-json output for: {' '.join(cmd)}") from exc
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def parse_pr_number(pr_url: str) -> int:
|
|
136
|
+
match = PR_URL_PATTERN.search(pr_url)
|
|
137
|
+
if not match:
|
|
138
|
+
raise ToolError(f"unable to parse pr number from url: {pr_url}")
|
|
139
|
+
return int(match.group(1))
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def collect_strings(value: Any) -> List[str]:
|
|
143
|
+
if isinstance(value, str):
|
|
144
|
+
return [value]
|
|
145
|
+
if isinstance(value, dict):
|
|
146
|
+
result: List[str] = []
|
|
147
|
+
for nested in value.values():
|
|
148
|
+
result.extend(collect_strings(nested))
|
|
149
|
+
return result
|
|
150
|
+
if isinstance(value, list):
|
|
151
|
+
result = []
|
|
152
|
+
for nested in value:
|
|
153
|
+
result.extend(collect_strings(nested))
|
|
154
|
+
return result
|
|
155
|
+
return []
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def extract_comment_author(comment: Dict[str, Any]) -> str:
|
|
159
|
+
user = comment.get("user")
|
|
160
|
+
if isinstance(user, dict):
|
|
161
|
+
for key in ("login", "name", "username"):
|
|
162
|
+
value = user.get(key)
|
|
163
|
+
if isinstance(value, str) and value:
|
|
164
|
+
return value
|
|
165
|
+
author = comment.get("author")
|
|
166
|
+
if isinstance(author, dict):
|
|
167
|
+
for key in ("username", "name", "login"):
|
|
168
|
+
value = author.get(key)
|
|
169
|
+
if isinstance(value, str) and value:
|
|
170
|
+
return value
|
|
171
|
+
for key in ("author_username", "authorName", "author"):
|
|
172
|
+
value = comment.get(key)
|
|
173
|
+
if isinstance(value, str) and value:
|
|
174
|
+
return value
|
|
175
|
+
return ""
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def extract_comment_text(comment: Dict[str, Any]) -> str:
|
|
179
|
+
for key in ("body", "note", "content", "message"):
|
|
180
|
+
value = comment.get(key)
|
|
181
|
+
if isinstance(value, str) and value:
|
|
182
|
+
return value
|
|
183
|
+
joined = "\n".join(collect_strings(comment))
|
|
184
|
+
return joined
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def extract_event_id_from_text(text: str) -> Optional[str]:
|
|
188
|
+
match = EVENT_ID_PATTERN.search(text)
|
|
189
|
+
if match:
|
|
190
|
+
return match.group(1)
|
|
191
|
+
direct = re.search(r"\b([0-9a-f]{24})\b", text)
|
|
192
|
+
if direct:
|
|
193
|
+
return direct.group(1)
|
|
194
|
+
return None
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def latest_event_id_from_pr(pr_number: int, repo: str) -> Tuple[str, Dict[str, Any]]:
|
|
198
|
+
comments = run_oh_gc(
|
|
199
|
+
["pr:comments", str(pr_number), "--repo", repo, "--comment-type", "pr_comment", "--json"]
|
|
200
|
+
)
|
|
201
|
+
if not isinstance(comments, list):
|
|
202
|
+
raise ToolError("unexpected oh-gc pr:comments response")
|
|
203
|
+
|
|
204
|
+
latest_match: Optional[Tuple[str, Dict[str, Any], str]] = None
|
|
205
|
+
for comment in comments:
|
|
206
|
+
if not isinstance(comment, dict):
|
|
207
|
+
continue
|
|
208
|
+
author = extract_comment_author(comment)
|
|
209
|
+
if author != "openharmony_ci":
|
|
210
|
+
continue
|
|
211
|
+
text = extract_comment_text(comment)
|
|
212
|
+
event_id = extract_event_id_from_text(text)
|
|
213
|
+
if not event_id:
|
|
214
|
+
continue
|
|
215
|
+
created = ""
|
|
216
|
+
for key in ("created_at", "updated_at", "create_at"):
|
|
217
|
+
value = comment.get(key)
|
|
218
|
+
if isinstance(value, str):
|
|
219
|
+
created = value
|
|
220
|
+
break
|
|
221
|
+
if latest_match is None or created >= latest_match[0]:
|
|
222
|
+
latest_match = (created, comment, event_id)
|
|
223
|
+
|
|
224
|
+
if latest_match is None:
|
|
225
|
+
raise ToolError(f"no DCP event id found in openharmony_ci comments for PR #{pr_number}")
|
|
226
|
+
return latest_match[2], latest_match[1]
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def flatten_files_tree(node: Any, prefix: str = "") -> List[Dict[str, str]]:
|
|
230
|
+
results: List[Dict[str, str]] = []
|
|
231
|
+
if not isinstance(node, dict):
|
|
232
|
+
return results
|
|
233
|
+
for name, value in node.items():
|
|
234
|
+
current = f"{prefix}/{name}" if prefix else str(name)
|
|
235
|
+
if isinstance(value, dict) and isinstance(value.get("url"), str):
|
|
236
|
+
results.append({"name": current, "url": value["url"]})
|
|
237
|
+
continue
|
|
238
|
+
results.extend(flatten_files_tree(value, current))
|
|
239
|
+
return results
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def normalize_job(build: Dict[str, Any]) -> Dict[str, Any]:
|
|
243
|
+
debug = build.get("debug", {}) if isinstance(build.get("debug"), dict) else {}
|
|
244
|
+
job_name = build.get("buildTarget") or debug.get("component") or "unknown"
|
|
245
|
+
result = classify_result(
|
|
246
|
+
debug.get("result") or build.get("result") or "",
|
|
247
|
+
debug.get("startTime", ""),
|
|
248
|
+
debug.get("endTime", ""),
|
|
249
|
+
debug.get("buildFailReason", ""),
|
|
250
|
+
debug.get("buildFailType", ""),
|
|
251
|
+
)
|
|
252
|
+
normalized = {
|
|
253
|
+
"job_name": job_name,
|
|
254
|
+
"result": result,
|
|
255
|
+
"fail_reason": debug.get("buildFailReason", ""),
|
|
256
|
+
"fail_type": debug.get("buildFailType", ""),
|
|
257
|
+
"start_time": debug.get("startTime", ""),
|
|
258
|
+
"end_time": debug.get("endTime", ""),
|
|
259
|
+
"pipeline_url": debug.get("pipelineUrl", ""),
|
|
260
|
+
"artifacts": debug.get("Artifacts", ""),
|
|
261
|
+
"build_log": debug.get("buildLog", ""),
|
|
262
|
+
"raw": build,
|
|
263
|
+
}
|
|
264
|
+
return normalized
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def classify_result(raw_result: str, start_time: str, end_time: str, fail_reason: str, fail_type: str) -> str:
|
|
268
|
+
result = str(raw_result or "").strip().lower()
|
|
269
|
+
if result:
|
|
270
|
+
return result
|
|
271
|
+
if fail_reason or fail_type:
|
|
272
|
+
return "failed"
|
|
273
|
+
if start_time and not end_time:
|
|
274
|
+
return "running"
|
|
275
|
+
if start_time and end_time:
|
|
276
|
+
return "unknown"
|
|
277
|
+
return "pending"
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def is_failure_result(result: str) -> bool:
|
|
281
|
+
return str(result).lower() in FAILURE_RESULTS
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def should_fetch_logs(job: Dict[str, Any], log_mode: str) -> bool:
|
|
285
|
+
if log_mode == "never":
|
|
286
|
+
return False
|
|
287
|
+
if log_mode == "always":
|
|
288
|
+
return bool(job.get("artifacts") or job.get("build_log"))
|
|
289
|
+
return is_failure_result(str(job.get("result", "")))
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def infer_overall_result(raw_result: str, jobs: List[Dict[str, Any]]) -> str:
|
|
293
|
+
result = str(raw_result or "").strip().lower()
|
|
294
|
+
if result:
|
|
295
|
+
return result
|
|
296
|
+
job_results = [str(job.get("result", "")).lower() for job in jobs]
|
|
297
|
+
if any(is_failure_result(item) for item in job_results):
|
|
298
|
+
return "failed"
|
|
299
|
+
if any(item == "running" for item in job_results):
|
|
300
|
+
return "running"
|
|
301
|
+
if any(item == "pending" for item in job_results):
|
|
302
|
+
return "pending"
|
|
303
|
+
if job_results and all(item in SUCCESS_RESULTS for item in job_results):
|
|
304
|
+
return "success"
|
|
305
|
+
return "unknown"
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def choose_log_candidate(files: List[Dict[str, str]]) -> Optional[Dict[str, str]]:
|
|
309
|
+
priorities = (
|
|
310
|
+
"error.log",
|
|
311
|
+
"build.log.zip",
|
|
312
|
+
"build.log",
|
|
313
|
+
)
|
|
314
|
+
lowered = [(item, item["name"].lower()) for item in files]
|
|
315
|
+
for priority in priorities:
|
|
316
|
+
for item, name in lowered:
|
|
317
|
+
if name.endswith(priority):
|
|
318
|
+
return item
|
|
319
|
+
return files[0] if files else None
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def tail_text_lines(text: str, line_count: int) -> str:
|
|
323
|
+
lines = text.splitlines()
|
|
324
|
+
if not lines:
|
|
325
|
+
return ""
|
|
326
|
+
return "\n".join(lines[-line_count:])
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def decode_text_payload(data: bytes) -> str:
|
|
330
|
+
for encoding in ("utf-8", "utf-8-sig", "latin1"):
|
|
331
|
+
try:
|
|
332
|
+
return data.decode(encoding)
|
|
333
|
+
except UnicodeDecodeError:
|
|
334
|
+
continue
|
|
335
|
+
return data.decode("utf-8", errors="replace")
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def inspect_archive_bytes(data: bytes, line_count: int) -> Tuple[str, str]:
|
|
339
|
+
buffer = io.BytesIO(data)
|
|
340
|
+
if zipfile.is_zipfile(buffer):
|
|
341
|
+
buffer.seek(0)
|
|
342
|
+
with zipfile.ZipFile(buffer) as archive:
|
|
343
|
+
names = archive.namelist()
|
|
344
|
+
preferred = next((name for name in names if name.endswith("error.log")), None)
|
|
345
|
+
if preferred is None:
|
|
346
|
+
preferred = next((name for name in names if name.endswith("build.log")), None)
|
|
347
|
+
if preferred is None and names:
|
|
348
|
+
preferred = names[0]
|
|
349
|
+
if preferred is None:
|
|
350
|
+
raise ToolError("zip archive is empty")
|
|
351
|
+
content = archive.read(preferred)
|
|
352
|
+
return preferred, tail_text_lines(decode_text_payload(content), line_count)
|
|
353
|
+
buffer.seek(0)
|
|
354
|
+
try:
|
|
355
|
+
with tarfile.open(fileobj=buffer) as archive:
|
|
356
|
+
members = [member for member in archive.getmembers() if member.isfile()]
|
|
357
|
+
preferred_member = next((m for m in members if m.name.endswith("error.log")), None)
|
|
358
|
+
if preferred_member is None:
|
|
359
|
+
preferred_member = next((m for m in members if m.name.endswith("build.log")), None)
|
|
360
|
+
if preferred_member is None and members:
|
|
361
|
+
preferred_member = members[0]
|
|
362
|
+
if preferred_member is None:
|
|
363
|
+
raise ToolError("tar archive is empty")
|
|
364
|
+
extracted = archive.extractfile(preferred_member)
|
|
365
|
+
if extracted is None:
|
|
366
|
+
raise ToolError(f"unable to read member: {preferred_member.name}")
|
|
367
|
+
return preferred_member.name, tail_text_lines(decode_text_payload(extracted.read()), line_count)
|
|
368
|
+
except tarfile.TarError:
|
|
369
|
+
pass
|
|
370
|
+
return "", tail_text_lines(decode_text_payload(data), line_count)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def maybe_write_download(download_dir: Optional[str], source_url: str, data: bytes) -> Optional[str]:
|
|
374
|
+
if not download_dir:
|
|
375
|
+
return None
|
|
376
|
+
os.makedirs(download_dir, exist_ok=True)
|
|
377
|
+
parsed = urllib.parse.urlparse(source_url)
|
|
378
|
+
name = os.path.basename(parsed.path) or "download.bin"
|
|
379
|
+
path = os.path.join(download_dir, name)
|
|
380
|
+
with open(path, "wb") as file_obj:
|
|
381
|
+
file_obj.write(data)
|
|
382
|
+
return path
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def fetch_job_logs(job: Dict[str, Any], log_lines: int, download_dir: Optional[str]) -> Dict[str, Any]:
|
|
386
|
+
files: List[Dict[str, str]] = []
|
|
387
|
+
artifacts = job.get("artifacts") or ""
|
|
388
|
+
build_log = job.get("build_log") or ""
|
|
389
|
+
if artifacts:
|
|
390
|
+
directory = urllib.parse.quote(artifacts, safe="/")
|
|
391
|
+
listing = http_get_json(DCP_FILES_URL.format(directory=directory))
|
|
392
|
+
files = flatten_files_tree(listing.get("data", {}))
|
|
393
|
+
|
|
394
|
+
candidate = choose_log_candidate(files)
|
|
395
|
+
source_path = ""
|
|
396
|
+
if candidate is not None:
|
|
397
|
+
source_path = candidate["url"]
|
|
398
|
+
elif build_log:
|
|
399
|
+
parsed = urllib.parse.urlparse(build_log)
|
|
400
|
+
source_path = parsed.path.lstrip("/")
|
|
401
|
+
|
|
402
|
+
if not source_path:
|
|
403
|
+
return {
|
|
404
|
+
"files": files,
|
|
405
|
+
"selected_log": None,
|
|
406
|
+
"downloaded_to": None,
|
|
407
|
+
"archive_member": None,
|
|
408
|
+
"tail": "",
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
source_url = CI_DOWNLOAD_URL.format(path=source_path.lstrip("/"))
|
|
412
|
+
data = http_get_bytes(source_url)
|
|
413
|
+
direct_text = decode_text_payload(data).strip()
|
|
414
|
+
if direct_text.startswith("http://") or direct_text.startswith("https://"):
|
|
415
|
+
redirected = urllib.parse.urlparse(direct_text)
|
|
416
|
+
if redirected.netloc == "cidownload.openharmony.cn":
|
|
417
|
+
source_url = direct_text
|
|
418
|
+
data = http_get_bytes(source_url)
|
|
419
|
+
downloaded_to = maybe_write_download(download_dir, source_url, data)
|
|
420
|
+
archive_member, tail = inspect_archive_bytes(data, log_lines)
|
|
421
|
+
return {
|
|
422
|
+
"files": files,
|
|
423
|
+
"selected_log": source_url,
|
|
424
|
+
"downloaded_to": downloaded_to,
|
|
425
|
+
"archive_member": archive_member or None,
|
|
426
|
+
"tail": tail,
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def build_output(args: argparse.Namespace) -> Dict[str, Any]:
|
|
431
|
+
pr_number: Optional[int] = args.pr
|
|
432
|
+
comment: Optional[Dict[str, Any]] = None
|
|
433
|
+
if args.pr_url:
|
|
434
|
+
pr_number = parse_pr_number(args.pr_url)
|
|
435
|
+
|
|
436
|
+
if args.event_id:
|
|
437
|
+
event_id = args.event_id
|
|
438
|
+
elif pr_number is not None:
|
|
439
|
+
event_id, comment = latest_event_id_from_pr(pr_number, args.repo)
|
|
440
|
+
else:
|
|
441
|
+
raise ToolError("missing event source")
|
|
442
|
+
|
|
443
|
+
event_payload = http_get_json(DCP_EVENT_URL.format(event_id=event_id))
|
|
444
|
+
event_data = event_payload.get("data", {})
|
|
445
|
+
builds = event_data.get("builds", []) if isinstance(event_data, dict) else []
|
|
446
|
+
jobs = [normalize_job(build) for build in builds if isinstance(build, dict)]
|
|
447
|
+
|
|
448
|
+
failures = [job for job in jobs if is_failure_result(str(job["result"]))]
|
|
449
|
+
for job in jobs:
|
|
450
|
+
if should_fetch_logs(job, args.log_mode):
|
|
451
|
+
job["log_detail"] = fetch_job_logs(job, args.log_lines, args.download_dir)
|
|
452
|
+
|
|
453
|
+
return {
|
|
454
|
+
"pr_number": pr_number,
|
|
455
|
+
"repo": args.repo,
|
|
456
|
+
"event_id": event_id,
|
|
457
|
+
"overall_result": infer_overall_result(event_data.get("result", ""), jobs),
|
|
458
|
+
"timestamp": event_data.get("timestamp", ""),
|
|
459
|
+
"end_timestamp": event_data.get("endTimestamp", ""),
|
|
460
|
+
"jobs": jobs,
|
|
461
|
+
"failure_count": len(failures),
|
|
462
|
+
"failed_jobs": [job["job_name"] for job in failures],
|
|
463
|
+
"source_comment": comment,
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def print_text_report(report: Dict[str, Any]) -> None:
|
|
468
|
+
title_parts = [f"event_id={report['event_id']}", f"overall={report['overall_result']}"]
|
|
469
|
+
if report.get("pr_number") is not None:
|
|
470
|
+
title_parts.insert(0, f"pr=#{report['pr_number']}")
|
|
471
|
+
print(" ".join(title_parts))
|
|
472
|
+
if report.get("failed_jobs"):
|
|
473
|
+
print(f"failed_jobs={', '.join(report['failed_jobs'])}")
|
|
474
|
+
for job in report["jobs"]:
|
|
475
|
+
print("")
|
|
476
|
+
print(f"[{job['job_name']}] result={job['result']}")
|
|
477
|
+
if job.get("fail_reason"):
|
|
478
|
+
print(f"fail_reason={job['fail_reason']}")
|
|
479
|
+
if job.get("fail_type"):
|
|
480
|
+
print(f"fail_type={job['fail_type']}")
|
|
481
|
+
if job.get("start_time"):
|
|
482
|
+
print(f"start_time={job['start_time']}")
|
|
483
|
+
if job.get("end_time"):
|
|
484
|
+
print(f"end_time={job['end_time']}")
|
|
485
|
+
if job.get("pipeline_url"):
|
|
486
|
+
print(f"pipeline_url={job['pipeline_url']}")
|
|
487
|
+
if job.get("artifacts"):
|
|
488
|
+
print(f"artifacts={job['artifacts']}")
|
|
489
|
+
log_detail = job.get("log_detail")
|
|
490
|
+
if not isinstance(log_detail, dict):
|
|
491
|
+
continue
|
|
492
|
+
if log_detail.get("selected_log"):
|
|
493
|
+
print(f"log_url={log_detail['selected_log']}")
|
|
494
|
+
if log_detail.get("downloaded_to"):
|
|
495
|
+
print(f"downloaded_to={log_detail['downloaded_to']}")
|
|
496
|
+
if log_detail.get("archive_member"):
|
|
497
|
+
print(f"log_member={log_detail['archive_member']}")
|
|
498
|
+
tail = log_detail.get("tail") or ""
|
|
499
|
+
if tail:
|
|
500
|
+
print("log_tail:")
|
|
501
|
+
print(tail)
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def main() -> int:
|
|
505
|
+
args = parse_args()
|
|
506
|
+
try:
|
|
507
|
+
report = build_output(args)
|
|
508
|
+
except ToolError as exc:
|
|
509
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
510
|
+
return 1
|
|
511
|
+
|
|
512
|
+
if args.json:
|
|
513
|
+
print(json.dumps(report, ensure_ascii=False, indent=2))
|
|
514
|
+
else:
|
|
515
|
+
print_text_report(report)
|
|
516
|
+
return 0
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
if __name__ == "__main__":
|
|
520
|
+
sys.exit(main())
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pool-status
|
|
3
|
+
description: 列举 OpenHarmony 大仓工作区池的实时状态——每个工作区被哪个工作项占用、哪些空闲可用。会 SSH 到构建服务器实时扫描现存工作区并与本机 workspace_pool.yaml 对账,感知服务器管理后台对工作区的增删(新增的自动入册,已删的标 GHOST)。当用户问"工作区状态/工作区占用/哪些工作区可用/workspace pool/pool status",或领取工作区、sync-repo、给 code-worker 任务挑工作区前使用。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 工作区池实时状态(pool status)
|
|
7
|
+
|
|
8
|
+
一条命令完成"扫描 + 对账"(仓库根目录执行,Python3 + PyYAML,SSH 免密):
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
python scripts/flash.py pool status
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
它做三件事:
|
|
15
|
+
|
|
16
|
+
1. SSH 到 `config/inventory.yaml` 里 servers 条目指向的构建服务器,`ls -d /srv/workspace/openharmony_master_default_*/code` 实时枚举现存工作区;
|
|
17
|
+
2. 与本机 `workspace_pool.yaml`(任务↔工作区映射的唯一事实来源,不上库)对账;
|
|
18
|
+
3. 自动维护登记:服务器新出现的工作区自动入册为 FREE;登记了但服务器已删除的标 GHOST(默认保留,加 `--prune` 才删除登记项)。
|
|
19
|
+
|
|
20
|
+
## 输出解读
|
|
21
|
+
|
|
22
|
+
表格列:工作区 / 状态 / 占用任务 / baseline / 备注。
|
|
23
|
+
|
|
24
|
+
- **FREE** — 空闲可领取。备注含"sync-repo 自动领取优先"的,是 `sync-repo` 不带参数时会自动选中的那个(现存空闲中字典序最大)。
|
|
25
|
+
- **BUSY** — 被"占用任务"列的工作项独占(一工作项一工作区)。
|
|
26
|
+
- **NEW** — 服务器新发现、本次已自动入册为 FREE。
|
|
27
|
+
- **GHOST** — 登记还在但服务器已删除(多半是管理后台清掉了)。若"占用任务"列非空,先核对该占用再决定;确认无用后执行 `python scripts/flash.py pool status --prune` 清理登记。
|
|
28
|
+
|
|
29
|
+
命令末尾有一行汇总:`服务器现存 N = 空闲 x + 占用 y + 新发现 z[;登记失效 w]`。
|
|
30
|
+
|
|
31
|
+
## 向用户汇报
|
|
32
|
+
|
|
33
|
+
用表格转述命令输出(工作区短名即可),汇总一行说清:几个可用、几个被谁占用、有无新发现/失效。GHOST 且带占用记录时必须显式提醒用户核对,不要擅自 `--prune`。若用户传了 "prune"/"--prune" 参数,才允许加该标志执行。
|
|
34
|
+
|
|
35
|
+
## 释放与占用
|
|
36
|
+
|
|
37
|
+
- **正常收尾**:任务设备验证通过后 `python scripts/collab.py close <task-id>` 自动释放其占用的工作区(记 device_verified)。
|
|
38
|
+
- **手工释放/改占用**:`python scripts/flash.py pool release <工作区>` / `pool claim <工作区> <任务ID>`。
|
|
39
|
+
- **领取 + 基线对齐一步**:`python scripts/flash.py sync-repo <工作区> <工作项ID>`(成功后自动记 baseline 与占用)。
|
|
40
|
+
- 本地查看登记(不连服务器):`python scripts/flash.py pool`。
|
|
41
|
+
|
|
42
|
+
给 code-worker 的任务用哪个工作区:task.md 的 repo 字段会从 `workspace_pool.yaml` 里 task==<task-id> 的行自动回填,所以先 claim/sync-repo 再 `collab.py new`。
|
|
43
|
+
|
|
44
|
+
## 相关
|
|
45
|
+
|
|
46
|
+
- collab-delegate skill:任务派发全流程
|
|
47
|
+
- 铁律与细节见 RUNBOOK「刷机准备 → 一工作项一工作区」与「资源清单与调度器」节
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# ============================================================================
|
|
2
|
+
# e2e 用例注册表 —— 真实应用 e2e 用例(hap)的唯一登记处(ROADMAP M1)
|
|
3
|
+
#
|
|
4
|
+
# apply.py 的 hap_build/hap_sign/hap_install/app_run 步骤按 `case:` 名引用条目;
|
|
5
|
+
# job 侧覆盖:python scripts/apply.py <spec> run --params case=<名>
|
|
6
|
+
#
|
|
7
|
+
# 条目字段:
|
|
8
|
+
# project 应用工程根(绝对路径,或相对本仓)——必填
|
|
9
|
+
# bundle 缺省从 <project>/AppScope/app.json5 的 bundleName 自动派生
|
|
10
|
+
# ability 缺省从 entry/src/main/module.json5 的 mainAbility(退化:首个 *Ability)派生
|
|
11
|
+
# hap 缺省 entry/build/default/outputs/default/entry-default-signed.hap(相对 project)
|
|
12
|
+
# notes 用途说明
|
|
13
|
+
# 扩容 = 加条目,不改代码(新用例工程 devecocli create 后在此登记即可)。
|
|
14
|
+
# ============================================================================
|
|
15
|
+
|
|
16
|
+
cases:
|
|
17
|
+
grid-ph:
|
|
18
|
+
project: C:/Project/grid_ph_verify
|
|
19
|
+
notes: Grid 占位(scrollPlaceholder)e2e 验证应用
|
|
20
|
+
wf-ph:
|
|
21
|
+
project: C:/Project/wf_ph_verify
|
|
22
|
+
notes: WaterFlow 占位 e2e 验证应用
|
|
23
|
+
list-ph:
|
|
24
|
+
project: C:/Project/ListPhScroll
|
|
25
|
+
notes: List 占位/滚动 e2e 验证应用
|
|
26
|
+
placeholder-test:
|
|
27
|
+
project: C:/Project/place_holder_test
|
|
28
|
+
notes: 占位通用测试应用
|
|
29
|
+
grid-mvcp:
|
|
30
|
+
project: C:/Project/GridMvcp
|
|
31
|
+
notes: RR-30096947 Grid maintainVisibleContentPosition e2e(attributeModifier 动态调用;埋点 MVCP_ATTR_SET/MISSING/PREPEND_DONE)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# ============================================================================
|
|
2
|
+
# hap 应用 e2e job spec(ROADMAP M1):preflight → 构建 → 签名 → 装板 → 启动 → 取证 → 判定
|
|
3
|
+
#
|
|
4
|
+
# 只需板卡资源(构建在本机 devecocli,不经服务器);用例来自 config/e2e-cases.yaml。
|
|
5
|
+
# 用法:
|
|
6
|
+
# python scripts/apply.py config/e2e-hap.yaml plan
|
|
7
|
+
# python scripts/apply.py config/e2e-hap.yaml run --params case=grid-ph marker="Ability onCreate"
|
|
8
|
+
# python scripts/apply.py config/e2e-hap.yaml run --params case=grid-ph sign_mode=release # release 签名链(跨设备免 UDID)
|
|
9
|
+
# python scripts/apply.py config/e2e-hap.yaml run --from-step hap-sign --run-id <id> # 重签重装续跑
|
|
10
|
+
# ============================================================================
|
|
11
|
+
|
|
12
|
+
job: e2e-hap
|
|
13
|
+
description: hap 应用 e2e:预检 → devecocli 构建 → 离线签名 → 装板 → 启动 → 取证 → 结构化判定
|
|
14
|
+
|
|
15
|
+
resources:
|
|
16
|
+
board: rk3568-01
|
|
17
|
+
|
|
18
|
+
params:
|
|
19
|
+
case: grid-ph # e2e-cases.yaml 用例名(hap_* 步骤共用)
|
|
20
|
+
marker: "" # 应用侧埋的 hilog 标记;非空时 assert 步骤自动兑现为 hilog_marker 断言
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- name: preflight
|
|
24
|
+
type: board_preflight # 校时 + 基线预检 + 熄屏 24h + 存量 faultlog 盘点
|
|
25
|
+
|
|
26
|
+
- name: hap-build
|
|
27
|
+
type: hap_build
|
|
28
|
+
timeout_min: 10
|
|
29
|
+
|
|
30
|
+
- name: hap-sign
|
|
31
|
+
type: hap_sign # 需板在线(取 UDID 重建 debug profile);重启板子后必须重签
|
|
32
|
+
|
|
33
|
+
- name: hap-install
|
|
34
|
+
type: hap_install # 校时 + uninstall→install + bm dump 校验(铁律内置)
|
|
35
|
+
|
|
36
|
+
- name: app-run
|
|
37
|
+
type: app_run
|
|
38
|
+
settle_s: 8 # 启动后静置再取证(首帧渲染/占位挂载完成)
|
|
39
|
+
|
|
40
|
+
- name: capture
|
|
41
|
+
type: capture
|
|
42
|
+
shots: 2
|
|
43
|
+
shot_interval_s: 3
|
|
44
|
+
hilog: true
|
|
45
|
+
layout: true # 组件树标准形与截图成对(语义证据层;raw 同留)
|
|
46
|
+
|
|
47
|
+
- name: assert
|
|
48
|
+
type: assert # params.marker 非空即有判定;也可在此显式列 assertions(frame_diff 等)
|
|
49
|
+
assertions: []
|
|
50
|
+
# 锚定类缺陷配方(round-3 实战教训:marker 只验属性可设置,不验行为):
|
|
51
|
+
# - { name: prepend, type: ui_click, selector: { text_re: "^Prepend" }, settle_s: 2 }
|
|
52
|
+
# - assert: [{ kind: node, selector: { type: GridItem, region: [0,200,720,1280] },
|
|
53
|
+
# fact: text, expect: "^item-0-" }, # 首个可见项不变 = 锚定生效
|
|
54
|
+
# { kind: frame_diff, max_diff_ratio: 0.01 }] # 渲染层零跳动
|