@buaa_smat/hometrans 0.1.19 → 0.1.20
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.
- package/README.md +18 -0
- package/agents/code-reviewer.md +1 -1
- package/agents/self-tester.md +33 -354
- package/agents/test-case-generation-generator.md +1 -1
- package/dist/cli/config-store.js +4 -84
- package/dist/cli/config.js +6 -8
- package/dist/cli/init.js +29 -36
- package/dist/cli/uninstall.js +2 -2
- package/env-requirements.json +5 -4
- package/package.json +3 -5
- package/resource/project_architecture.svg +1 -1
- package/skills/hmos-convert-pipeline/SKILL.md +31 -21
- package/skills/hmos-incremental-ui-align/README.md +5 -5
- package/skills/hmos-incremental-ui-align/SKILL.md +2 -2
- package/skills/hmos-integration-test/README.md +58 -17
- package/skills/hmos-integration-test/SKILL.md +107 -40
- package/{tools/test-tools/autotest/engine → skills/hmos-integration-test/scripts}/report-tool.ts +71 -53
- package/skills/hmos-integration-test/scripts/resolve-metadata-tool.ts +125 -0
- package/skills/hmos-integration-test/scripts/self-test-runner.ts +756 -0
- package/{tools/test-tools/autotest/engine → skills/hmos-integration-test/scripts}/testcases-tool.ts +38 -45
- package/skills/hmos-test-case-generation/references/contract.md +3 -3
- package/tools/test-tools/autotest/config.ts +0 -175
- package/tools/test-tools/autotest/deps/autotest-agent-0.1.1.tgz +0 -0
- package/tools/test-tools/autotest/docs/README.md +0 -266
- package/tools/test-tools/autotest/docs/testcases_schema.md +0 -143
- package/tools/test-tools/autotest/engine/batch-launcher.ts +0 -327
- package/tools/test-tools/autotest/engine/self-test-runner.ts +0 -961
- package/tools/test-tools/autotest/paths.ts +0 -41
- package/tools/test-tools/autotest/resolve-metadata-tool.ts +0 -143
- package/tools/test-tools/autotest/runner/logger.ts +0 -45
- package/tools/test-tools/autotest/runner/process-utils.ts +0 -41
- package/tools/test-tools/autotest/validate.ts +0 -167
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
---
|
|
1
|
+
---
|
|
2
2
|
name: hmos-integration-test
|
|
3
3
|
description: "Run on-device self-test for a HarmonyOS app. Parse test_case.md, install the HAP, execute AutoTest, and produce a verification report. Optionally enters a test-and-fix loop. Triggers on phrases like '跑自测', '运行自测', '执行自测', '自动测试', '设备测试', '跑用例', '跑自动化测试', 'self test', 'run autotest'."
|
|
4
4
|
allowed-tools:
|
|
@@ -11,13 +11,13 @@ allowed-tools:
|
|
|
11
11
|
|
|
12
12
|
# Self-Test Skill
|
|
13
13
|
|
|
14
|
-
You are a **Self-Test Runner**. Your job is to
|
|
14
|
+
You are a **Self-Test Runner**. Your job is to orchestrate test execution directly — parse test_case.md, install the HAP, run batch tests, generate reports — and optionally drive a test-and-fix loop (test → fix → build → retest, default up to 3 rounds, configurable via `max-rounds`). You invoke the skill's `scripts/` tools directly via `node`; `self-test-runner.ts` handles HAP install/uninstall, batch execution, polling, and timeout auto-kill in a single call.
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
## Prerequisites
|
|
19
19
|
|
|
20
|
-
The skill requires two user inputs: `test-case-path` and `hap-path`. `project-dir` (the HarmonyOS project root containing `AppScope/app.json5` — the
|
|
20
|
+
The skill requires two user inputs: `test-case-path` and `hap-path`. `project-dir` (the HarmonyOS project root containing `AppScope/app.json5` — the skill resolves `bundle_name`/`app_name` from it via the resolve-metadata tool during round 1 setup) is derived automatically when omitted: walk up from each `hap-path` entry (directory entries first, then file entries' parent dirs), then from `test-case-path`'s directory, looking for a directory containing `AppScope/app.json5`. Ask the user only if derivation finds nothing. `output-path` is optional — if omitted, it defaults to the directory containing `test-case-path`. After the initial test the skill can optionally enter a test-and-fix loop. Each round's outputs are snapshotted into `<output-path>/round-{n}/` (the skill always writes to `<output-path>/` root; round dirs are populated by the snapshot step); the canonical "latest" copies live at `<output-path>/` root.
|
|
21
21
|
|
|
22
22
|
A package is required (this test installs the app on a connected real HarmonyOS device or emulator). `hap-path` accepts **one or more** comma-separated paths; **each entry may be a single `.hap`/`.hsp` file or a directory**. The union of all entries must form the full package set — exactly one entry HAP plus any feature HAPs and **in-app HSPs** (Harmony Shared Packages built together with the app). In-app HSPs cannot install standalone — they depend on the main HAP — so every listed path is gathered and installed together in one `hdc install -r` transaction; the entry HAP and the HSPs **need not live in the same directory**. Confirm the package source(s) with the user before proceeding.
|
|
23
23
|
|
|
@@ -25,14 +25,50 @@ A package is required (this test installs the app on a connected real HarmonyOS
|
|
|
25
25
|
|
|
26
26
|
## Step 0 — Environment Variables Check (run first)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Verify (read env vars with `$env:VAR` in PowerShell on Windows; `echo "$VAR"` on macOS/Linux):
|
|
29
|
+
|
|
30
|
+
| Variable | Purpose | Valid when |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| `HOMETRANS_MODEL_API_KEY` | LLM api key (shared with UI alignment, set by `ht init`) | non-empty |
|
|
33
|
+
| `HOMETRANS_MODEL_NAME` | Model name (e.g. `qwen3.7-plus`) | non-empty |
|
|
34
|
+
| `HOMETRANS_MODEL_BASE_URL` | Model API base URL | non-empty |
|
|
35
|
+
| `HOMETRANS_TOOL_PATH` | HomeTrans tools dir (default `~/.hometrans/tools`) | path exists |
|
|
36
|
+
|
|
37
|
+
If `HOMETRANS_MODEL_API_KEY` is missing or empty, **stop and ask the user** to run `ht init` first.
|
|
38
|
+
|
|
39
|
+
### Step 0a — Generate autotest.yaml (if not exists)
|
|
40
|
+
|
|
41
|
+
If `~/.hometrans/autotest.yaml` does **not** exist, generate it from the env vars above:
|
|
42
|
+
|
|
43
|
+
```yaml
|
|
44
|
+
model:
|
|
45
|
+
unified:
|
|
46
|
+
name: "<HOMETRANS_MODEL_NAME>"
|
|
47
|
+
base_url: "<HOMETRANS_MODEL_BASE_URL>"
|
|
48
|
+
api_key: "<HOMETRANS_MODEL_API_KEY>"
|
|
49
|
+
provider: "openai"
|
|
50
|
+
|
|
51
|
+
agent:
|
|
52
|
+
mode: "single"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Write it to `~/.hometrans/autotest.yaml`. Then tell the user:
|
|
56
|
+
|
|
57
|
+
> autotest.yaml 已生成到 `~/.hometrans/autotest.yaml`。当前为 single 模式。如需启用 layered(Planner+Executor 双 Agent)模式,请编辑此文件添加 `execute`/`decision` 模型配置并将 `mode` 改为 `"layered"`。
|
|
58
|
+
|
|
59
|
+
If `autotest.yaml` already exists, skip generation — the user may have manually configured layered mode. Do **not** overwrite their settings.
|
|
60
|
+
|
|
61
|
+
This yaml is passed to AutoTestAgent's `batch_runner.js` via `--config` flag, read directly by `ConfigManager` — no translation layer needed.
|
|
29
62
|
|
|
30
|
-
|
|
31
|
-
|---|---|---|---|
|
|
32
|
-
| `HOMETRANS_MODEL_API_KEY` | `autotest.unified_model.api_key` | multimodal LLM key AutoTest uses to drive test cases (shared with UI alignment) | non-empty / not the placeholder |
|
|
33
|
-
| `HOMETRANS_TOOL_PATH` | none — no config.json layer; falls back to `~/.hometrans/tools` when env unset | HomeTrans tools dir (`<HOMETRANS_TOOL_PATH>/test-tools/autotest`) — the single tools-dir env var; there is no autotest-specific override | path exists on disk; if unset everywhere, falls back to `~/.hometrans/tools` |
|
|
63
|
+
### Step 0b — @autotest/agent 检查(自动安装)
|
|
34
64
|
|
|
35
|
-
|
|
65
|
+
`self-test-runner.ts` 在启动 batch_runner 前会先定位 `@autotest/agent` 的 `batch_runner.js`(从脚本自身位置向上查找 node_modules,再回退到全局 npm root)。**若找不到,自动安装**:
|
|
66
|
+
|
|
67
|
+
- 先从 `@buaa_smat/hometrans` 的 `package.json` 读取它依赖的 `@autotest/agent` 版本(避免装错成 `latest` 而漏掉所需修复)。
|
|
68
|
+
- 执行 `npm install -g @autotest/agent@<版本>`,然后重试定位。
|
|
69
|
+
- 仍找不到则报错并提示手动安装:`npm install -g <autotest-agent-tarball.tgz>` 或重装 `npm install -g @buaa_smat/hometrans`。
|
|
70
|
+
|
|
71
|
+
> 因此本 skill **不需要**在 Step 0 手动校验 `@autotest/agent`——runner 自愈。仅当 runner 报"auto-install failed"时才需人工介入(典型原因:该版本未发布到 npm,需装 tarball)。
|
|
36
72
|
|
|
37
73
|
## Step 1 — Parse Inputs
|
|
38
74
|
|
|
@@ -42,7 +78,7 @@ Extract the following from the user's message. If any required input is missing,
|
|
|
42
78
|
|----------|----------|---------|------------------|
|
|
43
79
|
| `test-case-path` | yes | Path to test_case.md | "测试用例在...", "用例文件...", "test case path" |
|
|
44
80
|
| `hap-path` | yes | **One or more** comma-separated `.hap`/`.hsp` files or dirs forming the full package set (see **Prerequisites**): one entry HAP + any feature HAPs / in-app HSPs, possibly in different dirs, installed in one transaction. | "HAP路径...", "安装包在...", "包目录...", "hap和hsp在...", "hap/hsp...", "hap file..." |
|
|
45
|
-
| `project-dir` | no (derived from `hap-path` / `test-case-path`; ask only if derivation fails) | Path to the HarmonyOS project root (the directory containing `AppScope/app.json5`). The
|
|
81
|
+
| `project-dir` | no (derived from `hap-path` / `test-case-path`; ask only if derivation fails) | Path to the HarmonyOS project root (the directory containing `AppScope/app.json5`). The skill resolves `bundle_name`/`app_name` from it via the resolve-metadata tool during round 1 setup. | "工程目录...", "HarmonyOS工程...", "项目根...", "project dir..." |
|
|
46
82
|
| `output-path` | no (default: directory of `test-case-path`) | Directory for all output artifacts | "输出到...", "产物目录...", "output to..." |
|
|
47
83
|
| `pre-test-case-path` | no | Path to pre_test_case.md | "前置用例...", "pre test case..." |
|
|
48
84
|
| `android-project-path` | no (for fix loop) | Path to Android source project for reference-based fixing | "Android路径...", "android project..." |
|
|
@@ -94,7 +130,7 @@ Substitute `<MAX_ROUNDS>` in the question text with the parsed value (default `3
|
|
|
94
130
|
|
|
95
131
|
### 2.0 — Loop Setup
|
|
96
132
|
|
|
97
|
-
1. Record `CURRENT_HAP = <hap-path>` (the full comma-separated list as the user gave it) and keep an immutable copy `ORIGINAL_HAP_PATH = <hap-path>`. `CURRENT_HAP` is passed verbatim as `hap-path` to
|
|
133
|
+
1. Record `CURRENT_HAP = <hap-path>` (the full comma-separated list as the user gave it) and keep an immutable copy `ORIGINAL_HAP_PATH = <hap-path>`. `CURRENT_HAP` is passed verbatim as `hap-path` to the skill (package-set format: see **Prerequisites**).
|
|
98
134
|
2. Initialize `round = 1`, `MAX_ROUNDS = <max-rounds from Step 1, default 3>`. If the parsed value is missing or not a positive integer, use `3`.
|
|
99
135
|
3. Set `ROUND_DIR = <output-path>/round-1`. Create the directory.
|
|
100
136
|
4. **Resolve `project-dir`** (if the user did not provide it): walk up from each `hap-path` entry — for directory entries, check the entry itself then each parent; for file entries, start from the file's parent — looking for a directory containing `AppScope/app.json5`. If no `hap-path` entry yields it, repeat the walk from `test-case-path`'s directory. If still nothing, use `AskUserQuestion` to get it. Store as `<project-dir>`.
|
|
@@ -105,38 +141,69 @@ Substitute `<MAX_ROUNDS>` in the question text with the parsed value (default `3
|
|
|
105
141
|
|
|
106
142
|
### 2A — Test (per round)
|
|
107
143
|
|
|
108
|
-
|
|
144
|
+
The skill orchestrates everything via the tool scripts bundled in its own `scripts/` directory (NOT the legacy `$HOMETRANS_TOOL_PATH` copy). Before running any `node` command below, resolve `SKILL_SCRIPTS` to the absolute path of this skill's `scripts/` directory — for opencode that is `~/.config/opencode/skills/hmos-integration-test/scripts`. The scripts locate `@autotest/agent`'s `batch_runner.js` by walking up from their own location and falling back to the global npm root, so they run correctly whether invoked from the repo, the skill dir, or a project.
|
|
109
145
|
|
|
110
|
-
|
|
111
|
-
Agent(
|
|
112
|
-
subagent_type="self-tester",
|
|
113
|
-
description="Run Device Tests (Round 1)",
|
|
114
|
-
prompt="<assembled prompt>"
|
|
115
|
-
)
|
|
116
|
-
```
|
|
146
|
+
The skill calls `self-test-runner.ts` to orchestrate: HAP install/uninstall + batch execution + polling. `self-test-runner.ts` automatically reads `agent.mode` from `autotest.yaml` and forwards it to `batch_runner` via `--mode` (you do not pass `--mode` yourself).
|
|
117
147
|
|
|
118
|
-
|
|
148
|
+
**Round 1 — Setup phase (parse + metadata)**:
|
|
119
149
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
- `setup: true`
|
|
150
|
+
1. **Resolve app metadata**:
|
|
151
|
+
```bash
|
|
152
|
+
node "$SKILL_SCRIPTS/resolve-metadata-tool.ts" --project-dir "<project-dir>" --output "<output-path>/app-metadata.json"
|
|
153
|
+
```
|
|
154
|
+
Read the JSON from stdout → store `bundle_name`, `app_name`, and `project_root` (→ `PROJECT_ROOT`).
|
|
126
155
|
|
|
127
|
-
|
|
156
|
+
2. **Parse test_case.md** → `<output-path>/_extracted.json` → **Generate testcases.json**:
|
|
157
|
+
```bash
|
|
158
|
+
node "$SKILL_SCRIPTS/testcases-tool.ts" "<output-path>/_extracted.json" "<output-path>/testcases.json" --validate
|
|
159
|
+
```
|
|
128
160
|
|
|
129
|
-
**
|
|
161
|
+
**Pre-cases** (run first in the batch): if `pre-test-case-path` was provided (or `pre_test_case.md` was auto-discovered in the same directory as `test-case-path`), parse its `### Scenario` blocks too — same `{case_name, actions, expected_results}` shape — and **prepend each pre-case to the `cases` array of `_extracted.json` with its `case_name` prefixed by `[PRE] `** (so `testcases-tool.ts` composes them into `testcases.json` and `report-tool.ts` flags them as pre-cases via the `[PRE] ` prefix). Pre-cases thus run first in the same batch; their failures are treated as environment/setup issues, not application defects.
|
|
130
162
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
163
|
+
**Round 2+ — skip setup phase**, reuse `<output-path>/testcases.json` and `<output-path>/app-metadata.json`.
|
|
164
|
+
|
|
165
|
+
**All rounds — Run self-test-runner (install + execute + poll)**:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
node "$SKILL_SCRIPTS/self-test-runner.ts" \
|
|
169
|
+
--testcases "<output-path>/testcases.json" \
|
|
170
|
+
--hap "<CURRENT_HAP>" \
|
|
171
|
+
--bundle-name "<bundle_name>" \
|
|
172
|
+
--task-dir "<output-path>/task" \
|
|
173
|
+
--output-dir "<output-path>" \
|
|
174
|
+
--category "<app_name>" \
|
|
175
|
+
--config ~/.hometrans/autotest.yaml \
|
|
176
|
+
--timeout auto
|
|
137
177
|
```
|
|
138
178
|
|
|
139
|
-
|
|
179
|
+
> `--mode` is read automatically from `autotest.yaml`'s `agent.mode`, so do not pass it manually.
|
|
180
|
+
|
|
181
|
+
This single command handles:
|
|
182
|
+
- `hdc uninstall` + `hdc install -r` (HAP installation)
|
|
183
|
+
- Spawn `batch_runner.js` (resolved from `@autotest/agent`) as a detached background process, forwarding `--mode` read from `autotest.yaml`
|
|
184
|
+
- Poll every 60s for `summary.json` (COMPLETED) or process death (CRASHED)
|
|
185
|
+
- Auto-kill on timeout
|
|
186
|
+
|
|
187
|
+
Parse the last line of stdout as terminal status JSON. Branch on `status`:
|
|
188
|
+
|
|
189
|
+
| `status` | Action |
|
|
190
|
+
|-----------|--------|
|
|
191
|
+
| `COMPLETED` | Read `<output-path>/task/task_*/task_results.jsonl` for per-case results; proceed to generate report |
|
|
192
|
+
| `CRASHED` | Write error to user; stop |
|
|
193
|
+
| `TIMEOUT` | Write timeout to user; stop |
|
|
194
|
+
| `FAILED` | Write error to user; stop |
|
|
195
|
+
|
|
196
|
+
5. **Generate report** — after COMPLETED:
|
|
197
|
+
```bash
|
|
198
|
+
node "$SKILL_SCRIPTS/report-tool.ts" \
|
|
199
|
+
--task-subdir "<latest task_* subdir>" \
|
|
200
|
+
--app-metadata "<output-path>/app-metadata.json" \
|
|
201
|
+
--hap "<entry-hap-basename>" \
|
|
202
|
+
--device "<device-serial>" \
|
|
203
|
+
--suite "<suite-name>" \
|
|
204
|
+
--out "<output-path>/self-test-report.md" \
|
|
205
|
+
--validate
|
|
206
|
+
```
|
|
140
207
|
|
|
141
208
|
---
|
|
142
209
|
|
|
@@ -276,7 +343,7 @@ After every round's 2A returns (round 1 and rounds 2+), snapshot these files fro
|
|
|
276
343
|
|--------|-------------|-------|
|
|
277
344
|
| `<output-path>/self-test-report.md` | `<ROUND_DIR>/self-test-report.md` | Always expected after a successful T8. If missing, sentinel-FAIL detection in 2A.1 already routed via `agent_early_exit`. |
|
|
278
345
|
| `<output-path>/task/` | `<ROUND_DIR>/task/` | Per-round runner artifacts. Skip if missing (e.g., agent FAILed before T6 created the dir). |
|
|
279
|
-
| `<output-path>/_extracted.json` | `<ROUND_DIR>/_extracted.json` | Only present after round 1 (
|
|
346
|
+
| `<output-path>/_extracted.json` | `<ROUND_DIR>/_extracted.json` | Only present after round 1 (round 1 setup phase step 2 wrote it). Skip in rounds 2+. |
|
|
280
347
|
|
|
281
348
|
**NOT snapshotted** (these stay at root only as the canonical, cross-round artifacts):
|
|
282
349
|
- `<output-path>/testcases.json` — written once by round 1; rounds 2+ read it in place.
|
|
@@ -354,7 +421,7 @@ After the report, present:
|
|
|
354
421
|
- `no_hap` — the rebuild did not produce an entry HAP in the build output, so the loop cannot continue.
|
|
355
422
|
- `max_rounds_reached` — hit the configured `MAX_ROUNDS` cap (default 3) with failures remaining.
|
|
356
423
|
- `no_testcases` — `<output-path>/testcases.json` contained 0 cases; nothing to run. Surface the path so the user can inspect.
|
|
357
|
-
- `agent_early_exit` —
|
|
424
|
+
- `agent_early_exit` — the skill wrote a sentinel FAIL report (config / device / autotest-dir / batch crash / precondition failure), or no `self-test-report.md` was written (skill failed before producing a report). Surface the captured `early_exit_reason` so the user knows what to fix manually.
|
|
358
425
|
|
|
359
426
|
If failures remain (for `max_rounds_reached`), list them briefly (scenario names from the report overview). Also surface `<ROUND_DIR>/self-test-fix-report.md` when it exists, and describe the final rebuild outcome from the loop summary instead of relying on a removed build-stage report artifact.
|
|
360
427
|
|
|
@@ -368,14 +435,14 @@ If failures remain (for `max_rounds_reached`), list them briefly (scenario names
|
|
|
368
435
|
| any `hap-path` entry does not exist | Name the missing entry, ask user for the correct path, do not proceed |
|
|
369
436
|
| `hap-path` entries all exist but none contributes a `.hap` (no entry package) | Report: "No entry HAP found across the given paths — at least one `.hap` is required." Do not proceed |
|
|
370
437
|
| `output-path` parent does not exist | Create it, proceed |
|
|
371
|
-
| Agent returns error / times out | Report the error to user. Suggest: check device connection (`npx --yes devecocli device list`), verify HAP is valid, check the `HOMETRANS_MODEL_API_KEY` env var
|
|
438
|
+
| Agent returns error / times out | Report the error to user. Suggest: check device connection (`npx --yes devecocli device list`), verify the HAP is valid, check the `HOMETRANS_MODEL_API_KEY` env var, and confirm `~/.hometrans/autotest.yaml` has a real `api_key` |
|
|
372
439
|
| `<output-path>/self-test-report.md` missing after agent completes | Report: "Agent completed but no report was generated. Check agent output at <output-path>." |
|
|
373
440
|
| `self-test-report.md` exists but format is unrecognizable | Show the file path, report the first 80 lines as context, let user investigate |
|
|
374
441
|
| Device not found (agent reports "No device") | Remind user: connect a HarmonyOS device or emulator, verify `npx --yes devecocli device list` shows it |
|
|
375
442
|
| Pre-case failures in report | Note: these are environment issues, not app defects. Highlight regular pass rate |
|
|
376
443
|
| `<output-path>/testcases.json` or `app-metadata.json` missing after round 1 | Round 1 setup may have failed; inspect agent output at `<output-path>/` |
|
|
377
444
|
| `<output-path>/testcases.json` is empty (`total == 0` in 2A) | Report: "testcases.json contains 0 cases — nothing to run." Exit loop with `stop_reason = no_testcases`. Do NOT enter the fix loop. |
|
|
378
|
-
|
|
|
445
|
+
| The skill writes a sentinel FAIL report (first line `status: FAIL`), or no `self-test-report.md` was written (skill failed before producing a report) | Capture the `reason:` line. Exit loop with `stop_reason = agent_early_exit` and surface the captured reason. Do NOT enter the fix loop — these failures (config / device / autotest-dir / crash / timeout / precondition failures / report not produced) are not application defects. |
|
|
379
446
|
| Fixer returns `confirmed == 0` (all false positives) | Exit loop with `stop_reason = no_confirmed_defects`. Surface the fix report summary. |
|
|
380
447
|
| hmos-fix-build-errors produces no HAP in build output | Report: "Build did not produce a HAP — cannot re-test." Exit loop with `stop_reason = no_hap`. |
|
|
381
448
|
| Loop reaches `MAX_ROUNDS` (default 3) with failures remaining | Report `stop_reason = max_rounds_reached`. Surface final pass rate and remaining failures. |
|
|
@@ -385,7 +452,7 @@ If failures remain (for `max_rounds_reached`), list them briefly (scenario names
|
|
|
385
452
|
|
|
386
453
|
## Key Constraints
|
|
387
454
|
|
|
388
|
-
- **
|
|
455
|
+
- **Direct orchestration**: The skill runs test tools directly via `node "$SKILL_SCRIPTS/..."` (scripts bundled in the skill's own `scripts/` directory) and resolves `batch_runner.js` from `@autotest/agent` internally (walk-up + global npm root fallback + auto-install). This SKILL.md is the **single source of truth** for the procedure. The `self-tester` **subagent** (`agents/self-tester.md`) is a thin wrapper that loads this skill — callers (e.g. `hmos-convert-pipeline` Stage 4) may launch it for context isolation on long runs; it forwards the same kebab params and reports the result back, without duplicating any procedure. The legacy `$HOMETRANS_TOOL_PATH` scripts (tools/test-tools/autotest) are no longer used.
|
|
389
456
|
- **Parameter purity**: Pass only parameter values to the agent's prompt in `key: value` format. Do NOT add extra instructions, format descriptions, schema hints, or implementation suggestions. The agent has its own built-in workflow.
|
|
390
457
|
- **Do NOT read full reports**: Self-test reports can be very large (10KB–200KB). Only read the overview (first 80 lines for test report, first 60 lines for fix report). Point the user to the full file; never fabricate results when a report is missing or unreadable.
|
|
391
458
|
- **Quote all paths**: Paths may contain spaces. Always wrap paths in double quotes in commands.
|
package/{tools/test-tools/autotest/engine → skills/hmos-integration-test/scripts}/report-tool.ts
RENAMED
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generate or validate self-test-report.md
|
|
2
|
+
* Generate or validate self-test-report.md.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* CLI (no subcommands — flags):
|
|
5
|
+
* report-tool.ts --task-subdir ... --app-metadata ... --hap ... --device ... \
|
|
6
|
+
* --suite ... --out ... [--validate]
|
|
6
7
|
* Render `self-test-report.md` from a task_<ts>/ directory, optionally
|
|
7
8
|
* re-validating the output in-process.
|
|
8
|
-
*
|
|
9
|
+
* report-tool.ts --check-only <report-path>
|
|
9
10
|
* Check an existing report conforms to the required layout.
|
|
10
11
|
* Exit 0 = PASSED, exit 1 = FAILED.
|
|
11
12
|
*
|
|
12
|
-
* The emitted markdown is a FROZEN contract parsed by
|
|
13
|
-
* hmos-integration-test skill
|
|
13
|
+
* The emitted markdown is a FROZEN contract parsed by the
|
|
14
|
+
* hmos-integration-test skill and validateReport below — template strings are
|
|
14
15
|
* verbatim and must not drift.
|
|
15
16
|
*/
|
|
16
17
|
import fs from 'node:fs';
|
|
17
18
|
import path from 'node:path';
|
|
18
|
-
import { fileURLToPath } from 'node:url';
|
|
19
|
-
import { Command } from 'commander';
|
|
20
19
|
|
|
21
20
|
// Inlined from src/utils/regex.ts so this file is self-contained — no hop into src/.
|
|
22
21
|
function escapeRegExp(s: string): string {
|
|
23
22
|
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
24
23
|
}
|
|
25
24
|
|
|
25
|
+
// Strip a leading UTF-8 BOM (0xFEFF) from file contents before JSON.parse —
|
|
26
|
+
// users (or PowerShell `Set-Content -Encoding utf8`) often produce BOM-prefixed
|
|
27
|
+
// JSON files which would otherwise throw "Unexpected token" in JSON.parse.
|
|
28
|
+
function readJsonSync(filePath: string): unknown {
|
|
29
|
+
let text = fs.readFileSync(filePath, 'utf-8');
|
|
30
|
+
if (text.charCodeAt(0) === 0xfeff) text = text.slice(1);
|
|
31
|
+
return JSON.parse(text);
|
|
32
|
+
}
|
|
33
|
+
|
|
26
34
|
const PRE_PREFIX = '[PRE] ';
|
|
27
35
|
|
|
28
36
|
export interface Case {
|
|
@@ -96,7 +104,7 @@ export function findLatestTaskJson(reportDir: string): string | null {
|
|
|
96
104
|
const datePat = /^\d{4}-\d{2}-\d{2}$/;
|
|
97
105
|
const timePat = /^\d{2}-\d{2}-\d{2}$/;
|
|
98
106
|
|
|
99
|
-
//
|
|
107
|
+
// Stay robust (return null) but
|
|
100
108
|
// surface the cause on stderr so real FS problems aren't silently hidden.
|
|
101
109
|
const subdirs = (dir: string, pat: RegExp): string[] | null => {
|
|
102
110
|
try {
|
|
@@ -145,7 +153,7 @@ export function loadCaseJudgment(reportDir: string): [Record<string, string>, st
|
|
|
145
153
|
|
|
146
154
|
let data: unknown;
|
|
147
155
|
try {
|
|
148
|
-
data =
|
|
156
|
+
data = readJsonSync(jsonPath);
|
|
149
157
|
} catch {
|
|
150
158
|
return [{}, ''];
|
|
151
159
|
}
|
|
@@ -582,7 +590,9 @@ interface SummaryJson {
|
|
|
582
590
|
/** Read task_results.jsonl and hydrate each case with its judgment + thinking. */
|
|
583
591
|
function loadCases(jsonlPath: string): Case[] {
|
|
584
592
|
const cases: Case[] = [];
|
|
585
|
-
|
|
593
|
+
let raw = fs.readFileSync(jsonlPath, 'utf-8');
|
|
594
|
+
if (raw.charCodeAt(0) === 0xfeff) raw = raw.slice(1); // strip BOM
|
|
595
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
586
596
|
const trimmed = line.trim();
|
|
587
597
|
if (!trimmed) continue;
|
|
588
598
|
const case_: Case = JSON.parse(trimmed);
|
|
@@ -610,7 +620,7 @@ export function renderReport(
|
|
|
610
620
|
if (!fs.existsSync(p)) throw new FileNotFoundError(`missing file in task-subdir: ${p}`);
|
|
611
621
|
}
|
|
612
622
|
|
|
613
|
-
const summary: SummaryJson =
|
|
623
|
+
const summary: SummaryJson = readJsonSync(summaryPath) as SummaryJson;
|
|
614
624
|
const cases = loadCases(jsonlPath);
|
|
615
625
|
|
|
616
626
|
const preCases = cases.filter(c => c.case_name.startsWith(PRE_PREFIX));
|
|
@@ -632,9 +642,7 @@ export function renderReport(
|
|
|
632
642
|
regCases.length > 0 ? `${((regularPass / regCases.length) * 100).toFixed(2)}%` : 'N/A',
|
|
633
643
|
};
|
|
634
644
|
|
|
635
|
-
const meta: { bundle_name?: string; app_name?: string } =
|
|
636
|
-
fs.readFileSync(appMetadata, 'utf-8'),
|
|
637
|
-
) as { bundle_name?: string; app_name?: string };
|
|
645
|
+
const meta: { bundle_name?: string; app_name?: string } = readJsonSync(appMetadata) as { bundle_name?: string; app_name?: string };
|
|
638
646
|
|
|
639
647
|
const startTime = summary.start_time ?? '';
|
|
640
648
|
const endTime = summary.end_time ?? '';
|
|
@@ -699,7 +707,7 @@ function printValidation(errors: string[], reportPath: string): number {
|
|
|
699
707
|
return 1;
|
|
700
708
|
}
|
|
701
709
|
|
|
702
|
-
/**
|
|
710
|
+
/** Generate mode: render the report and optionally re-validate. */
|
|
703
711
|
function cmdGenerate(opts: GenerateOpts): void {
|
|
704
712
|
const taskSubdir = path.resolve(opts.taskSubdir);
|
|
705
713
|
if (!fs.existsSync(taskSubdir)) {
|
|
@@ -728,46 +736,56 @@ function cmdGenerate(opts: GenerateOpts): void {
|
|
|
728
736
|
}
|
|
729
737
|
}
|
|
730
738
|
|
|
731
|
-
/**
|
|
739
|
+
/** Validate mode (--check-only): validate an existing report. */
|
|
732
740
|
function cmdValidate(reportPath: string): void {
|
|
733
741
|
const resolved = path.resolve(reportPath);
|
|
734
742
|
process.exit(printValidation(validateReport(resolved), resolved));
|
|
735
743
|
}
|
|
736
744
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
745
|
+
// ---- CLI ----
|
|
746
|
+
|
|
747
|
+
const args = process.argv.slice(2);
|
|
748
|
+
|
|
749
|
+
if (args.includes('-h') || args.includes('--help')) {
|
|
750
|
+
console.log(`Usage: report-tool.ts [options]
|
|
751
|
+
|
|
752
|
+
Options:
|
|
753
|
+
--task-subdir <path> task_<ts>/ directory with summary.json + task_results.jsonl
|
|
754
|
+
--app-metadata <path> app-metadata.json path
|
|
755
|
+
--hap <path> HAP file path
|
|
756
|
+
--device <id> device identifier
|
|
757
|
+
--suite <name> test suite title
|
|
758
|
+
--out <path> output self-test-report.md path
|
|
759
|
+
--validate re-validate after writing
|
|
760
|
+
--check-only <path> validate an existing report without generating
|
|
761
|
+
`);
|
|
762
|
+
process.exit(0);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
if (args.includes('--check-only')) {
|
|
766
|
+
// Validate mode
|
|
767
|
+
const idx = args.indexOf('--check-only');
|
|
768
|
+
const filepath = args[idx + 1];
|
|
769
|
+
if (!filepath) { console.error('Usage: report-tool.ts --check-only <path>'); process.exit(1); }
|
|
770
|
+
cmdValidate(filepath);
|
|
771
|
+
} else {
|
|
772
|
+
// Generate mode (default)
|
|
773
|
+
const opts: GenerateOpts = { taskSubdir: '', appMetadata: '', hap: '', device: '', suite: '', out: '' };
|
|
774
|
+
for (let i = 0; i < args.length; i++) {
|
|
775
|
+
const a = args[i];
|
|
776
|
+
const next = (): string => { if (i + 1 >= args.length) { console.error(`Missing value for ${a}`); process.exit(1); } return args[++i]; };
|
|
777
|
+
switch (a) {
|
|
778
|
+
case '--task-subdir': opts.taskSubdir = next(); break;
|
|
779
|
+
case '--app-metadata': opts.appMetadata = next(); break;
|
|
780
|
+
case '--hap': opts.hap = next(); break;
|
|
781
|
+
case '--device': opts.device = next(); break;
|
|
782
|
+
case '--suite': opts.suite = next(); break;
|
|
783
|
+
case '--out': opts.out = next(); break;
|
|
784
|
+
case '--validate': opts.validate = true; break;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
for (const req of ['taskSubdir', 'appMetadata', 'hap', 'device', 'suite', 'out'] as const) {
|
|
788
|
+
if (!opts[req]) { console.error(`Missing required option: --${req.replace(/([A-Z])/g, '-$1').toLowerCase()}`); process.exit(1); }
|
|
789
|
+
}
|
|
790
|
+
cmdGenerate(opts);
|
|
773
791
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Resolve App Metadata — discover `bundle_name` / `app_name` from a HarmonyOS
|
|
4
|
+
* project and write `app-metadata.json`.
|
|
5
|
+
*
|
|
6
|
+
* Usage: resolve-metadata-tool.ts --project-dir <dir> --output <path>
|
|
7
|
+
* Reads `<project-dir>/AppScope/app.json5` (JSON5 with comments/trailing commas),
|
|
8
|
+
* extracts `app.bundleName` and `app.label` (resolving `$string:xxx` references
|
|
9
|
+
* from the base-qualifier string.json), writes `{bundle_name, app_name, project_root}`
|
|
10
|
+
* to `--output`, and emits the same JSON to stdout.
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
// ---- JSON5 strip (remove comments + trailing commas, then JSON.parse) ----
|
|
16
|
+
|
|
17
|
+
function stripJson5(text: string): string {
|
|
18
|
+
// Remove single-line comments (// ...) — but not inside strings
|
|
19
|
+
let result = '';
|
|
20
|
+
let inString = false;
|
|
21
|
+
let stringChar = '';
|
|
22
|
+
for (let i = 0; i < text.length; i++) {
|
|
23
|
+
const ch = text[i];
|
|
24
|
+
const next = text[i + 1];
|
|
25
|
+
if (inString) {
|
|
26
|
+
result += ch;
|
|
27
|
+
if (ch === '\\' ) { result += next ?? ''; i++; continue; }
|
|
28
|
+
if (ch === stringChar) inString = false;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (ch === '"' || ch === "'") { inString = true; stringChar = ch; result += ch; continue; }
|
|
32
|
+
if (ch === '/' && next === '/') { while (i < text.length && text[i] !== '\n') i++; continue; }
|
|
33
|
+
if (ch === '/' && next === '*') { i += 2; while (i < text.length - 1 && !(text[i] === '*' && text[i + 1] === '/')) i++; i++; continue; }
|
|
34
|
+
result += ch;
|
|
35
|
+
}
|
|
36
|
+
// Remove trailing commas before } or ]
|
|
37
|
+
result = result.replace(/,(\s*[}\]])/g, '$1');
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parseJson5(filePath: string): unknown {
|
|
42
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
43
|
+
return JSON.parse(stripJson5(raw));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ---- string resource resolver ----
|
|
47
|
+
|
|
48
|
+
function resolveStringResource(projectRoot: string, key: string): string | null {
|
|
49
|
+
const stringJson = path.join(projectRoot, 'AppScope', 'resources', 'base', 'element', 'string.json');
|
|
50
|
+
if (!fs.existsSync(stringJson)) return null;
|
|
51
|
+
let doc: unknown;
|
|
52
|
+
try { doc = parseJson5(stringJson); } catch { return null; }
|
|
53
|
+
const arr = (doc as { string?: unknown })?.string;
|
|
54
|
+
if (!Array.isArray(arr)) return null;
|
|
55
|
+
const entry = arr.find((e) => (e as { name?: unknown })?.name === key);
|
|
56
|
+
const value = (entry as { value?: unknown } | undefined)?.value;
|
|
57
|
+
return typeof value === 'string' && value ? value : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ---- main ----
|
|
61
|
+
|
|
62
|
+
function main(): void {
|
|
63
|
+
const args = process.argv.slice(2);
|
|
64
|
+
let projectDir = '';
|
|
65
|
+
let output = '';
|
|
66
|
+
for (let i = 0; i < args.length; i++) {
|
|
67
|
+
if (args[i] === '--project-dir') projectDir = args[++i];
|
|
68
|
+
else if (args[i] === '--output') output = args[++i];
|
|
69
|
+
else if (args[i] === '-h' || args[i] === '--help') {
|
|
70
|
+
console.log('Usage: resolve-metadata-tool.ts --project-dir <dir> --output <path>');
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!projectDir || !output) {
|
|
75
|
+
console.error('Usage: resolve-metadata-tool.ts --project-dir <dir> --output <path>');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const projectRoot = path.resolve(projectDir);
|
|
80
|
+
const appJson5 = path.join(projectRoot, 'AppScope', 'app.json5');
|
|
81
|
+
if (!fs.existsSync(appJson5)) {
|
|
82
|
+
console.error(`not a HarmonyOS project root (no AppScope/app.json5): ${projectRoot}`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let doc: unknown;
|
|
87
|
+
try {
|
|
88
|
+
doc = parseJson5(appJson5);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.error(`failed to parse ${appJson5}: ${e instanceof Error ? e.message : String(e)}`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const app = (doc as { app?: Record<string, unknown> })?.app;
|
|
95
|
+
const bundleName = app?.bundleName;
|
|
96
|
+
if (typeof bundleName !== 'string' || !bundleName) {
|
|
97
|
+
console.error(`missing app.bundleName in ${appJson5}`);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const label = app?.label;
|
|
102
|
+
let appName: string;
|
|
103
|
+
if (typeof label === 'string' && label.startsWith('$string:')) {
|
|
104
|
+
const key = label.slice('$string:'.length);
|
|
105
|
+
const resolved = resolveStringResource(projectRoot, key);
|
|
106
|
+
if (resolved) {
|
|
107
|
+
appName = resolved;
|
|
108
|
+
} else {
|
|
109
|
+
console.error(`warning: string resource '${key}' not found — using literal '${label}'`);
|
|
110
|
+
appName = label;
|
|
111
|
+
}
|
|
112
|
+
} else if (typeof label === 'string' && label) {
|
|
113
|
+
appName = label;
|
|
114
|
+
} else {
|
|
115
|
+
console.error(`warning: missing app.label — using bundleName as app_name`);
|
|
116
|
+
appName = bundleName;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const meta = { bundle_name: bundleName, app_name: appName, project_root: projectRoot };
|
|
120
|
+
fs.mkdirSync(path.dirname(path.resolve(output)), { recursive: true });
|
|
121
|
+
fs.writeFileSync(path.resolve(output), JSON.stringify(meta) + '\n', 'utf-8');
|
|
122
|
+
console.log(JSON.stringify(meta));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
main();
|