@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.
Files changed (32) hide show
  1. package/README.md +18 -0
  2. package/agents/code-reviewer.md +1 -1
  3. package/agents/self-tester.md +33 -354
  4. package/agents/test-case-generation-generator.md +1 -1
  5. package/dist/cli/config-store.js +4 -84
  6. package/dist/cli/config.js +6 -8
  7. package/dist/cli/init.js +29 -36
  8. package/dist/cli/uninstall.js +2 -2
  9. package/env-requirements.json +5 -4
  10. package/package.json +3 -5
  11. package/resource/project_architecture.svg +1 -1
  12. package/skills/hmos-convert-pipeline/SKILL.md +31 -21
  13. package/skills/hmos-incremental-ui-align/README.md +5 -5
  14. package/skills/hmos-incremental-ui-align/SKILL.md +2 -2
  15. package/skills/hmos-integration-test/README.md +58 -17
  16. package/skills/hmos-integration-test/SKILL.md +107 -40
  17. package/{tools/test-tools/autotest/engine → skills/hmos-integration-test/scripts}/report-tool.ts +71 -53
  18. package/skills/hmos-integration-test/scripts/resolve-metadata-tool.ts +125 -0
  19. package/skills/hmos-integration-test/scripts/self-test-runner.ts +756 -0
  20. package/{tools/test-tools/autotest/engine → skills/hmos-integration-test/scripts}/testcases-tool.ts +38 -45
  21. package/skills/hmos-test-case-generation/references/contract.md +3 -3
  22. package/tools/test-tools/autotest/config.ts +0 -175
  23. package/tools/test-tools/autotest/deps/autotest-agent-0.1.1.tgz +0 -0
  24. package/tools/test-tools/autotest/docs/README.md +0 -266
  25. package/tools/test-tools/autotest/docs/testcases_schema.md +0 -143
  26. package/tools/test-tools/autotest/engine/batch-launcher.ts +0 -327
  27. package/tools/test-tools/autotest/engine/self-test-runner.ts +0 -961
  28. package/tools/test-tools/autotest/paths.ts +0 -41
  29. package/tools/test-tools/autotest/resolve-metadata-tool.ts +0 -143
  30. package/tools/test-tools/autotest/runner/logger.ts +0 -45
  31. package/tools/test-tools/autotest/runner/process-utils.ts +0 -41
  32. package/tools/test-tools/autotest/validate.ts +0 -167
package/dist/cli/init.js CHANGED
@@ -12,7 +12,7 @@ import { fileURLToPath } from 'node:url';
12
12
  import chalk from 'chalk';
13
13
  import figlet from 'figlet';
14
14
  import inquirer from 'inquirer';
15
- import { deriveSdkPaths, expandHome, getConfigDir, getConfigPath, getToolsDir, isPlaceholderApiKey, loadHomeTransConfig, saveHomeTransConfig, syncModelEnvIntoConfig, } from './config-store.js';
15
+ import { deriveSdkPaths, expandHome, getConfigDir, getConfigPath, getToolsDir, isPlaceholderApiKey, loadHomeTransConfig, saveHomeTransConfig, } from './config-store.js';
16
16
  import { persistEnvVars } from './env-vars.js';
17
17
  function ensureChalkColor() {
18
18
  if (process.stdout.isTTY && chalk.level === 0) {
@@ -90,43 +90,33 @@ function maskKey(key) {
90
90
  /**
91
91
  * Model Configuration step — configures the single multimodal (vision) LLM
92
92
  * shared by BOTH the on-device self-test agent AND the UI-alignment phone-agent.
93
- * Stored once in the `autotest.unified_model` block of ~/.hometrans/config.json
94
- * and additionally exported as the HOMETRANS_MODEL_* machine environment
95
- * variables (see maybePersistMachineEnv), so each runtime reads the same config:
96
- * - self_test_runner.ts reads autotest.unified_model from config.json;
97
- * - app_feature_verify.py reads the HOMETRANS_MODEL_* env vars (falling back
98
- * to config.json).
99
- * Prompts for the four essentials (api_key / name / base_url / provider);
100
- * all other parameters (device / agent, temperature, …) keep their defaults —
101
- * edit config.json to tune them.
93
+ * Stored as HOMETRANS_MODEL_* machine environment variables in config.env,
94
+ * exported by maybePersistMachineEnv. UI alignment and self-test both read
95
+ * these env vars at runtime. Agent config is in ~/.hometrans/autotest.yaml
96
+ * (generated by the integration-test skill).
102
97
  */
103
98
  async function promptModelConfig(config) {
104
- const um = config.autotest.unified_model;
99
+ const env = config.env;
105
100
  console.log('');
106
101
  console.log(chalk.blue(' MultiModel LLM Configuration') +
107
102
  chalk.gray(' (MultiModal LLM info for ui alignment + integration test)'));
108
103
  try {
109
104
  const answers = await inquirer.prompt([
110
- { type: 'input', name: 'model_base_url', message: 'model_base_url:', default: um.base_url },
111
- { type: 'input', name: 'model_name', message: 'model_name:', default: um.name },
105
+ { type: 'input', name: 'model_base_url', message: 'model_base_url:', default: env.HOMETRANS_MODEL_BASE_URL || '' },
106
+ { type: 'input', name: 'model_name', message: 'model_name:', default: env.HOMETRANS_MODEL_NAME || '' },
112
107
  {
113
108
  type: 'input',
114
109
  name: 'model_api_key',
115
110
  message: 'model_api_key:',
116
- default: isPlaceholderApiKey(um.api_key) ? undefined : um.api_key,
111
+ default: isPlaceholderApiKey(env.HOMETRANS_MODEL_API_KEY) ? undefined : env.HOMETRANS_MODEL_API_KEY,
117
112
  },
118
113
  ]);
119
114
  if (answers.model_api_key.trim())
120
- um.api_key = answers.model_api_key.trim();
115
+ env.HOMETRANS_MODEL_API_KEY = answers.model_api_key.trim();
121
116
  if (answers.model_name.trim())
122
- um.name = answers.model_name.trim();
117
+ env.HOMETRANS_MODEL_NAME = answers.model_name.trim();
123
118
  if (answers.model_base_url.trim())
124
- um.base_url = answers.model_base_url.trim();
125
- // provider is no longer prompted — default to openai when unset.
126
- if (!um.provider || !um.provider.trim())
127
- um.provider = 'openai';
128
- // Mirror into config.env.HOMETRANS_MODEL_* so config.json stays consistent.
129
- syncModelEnvIntoConfig(config);
119
+ env.HOMETRANS_MODEL_BASE_URL = answers.model_base_url.trim();
130
120
  await saveHomeTransConfig(config);
131
121
  }
132
122
  catch (err) {
@@ -696,8 +686,7 @@ async function detectInstalledEditors(editors) {
696
686
  * those are documented as manual PATH setup.
697
687
  *
698
688
  * The multimodal model config (HOMETRANS_MODEL_*) is included too: its canonical
699
- * store is the `autotest.unified_model` block, but those four fields are mirrored
700
- * into config.env by syncModelEnvIntoConfig so this one list is the single source
689
+ * store is config.env (HOMETRANS_MODEL_* fields), which is the single source
701
690
  * for both config.json's `env` block and the machine env vars. Shared by UI
702
691
  * alignment and self-test.
703
692
  */
@@ -728,10 +717,8 @@ function maskEnvValue(name, value) {
728
717
  * abort init on Ctrl-C.
729
718
  */
730
719
  async function maybePersistMachineEnv(config) {
731
- // Refresh the mirrored HOMETRANS_MODEL_* in config.env from autotest.unified_model
732
- // (the Model Configuration step above just edited the latter), so config.env is
733
- // the single source for both config.json and the machine env vars below.
734
- syncModelEnvIntoConfig(config);
720
+ // HOMETRANS_MODEL_* are written directly to config.env by promptModelConfig,
721
+ // so config.env is the single source for both config.json and the machine env vars.
735
722
  const env = config.env;
736
723
  const allVars = MACHINE_ENV_KEYS.map((k) => [k, (env[k] ?? '').trim()]).filter(([, value]) => value.length > 0);
737
724
  if (allVars.length === 0)
@@ -990,7 +977,7 @@ export async function initCommand(options = {}) {
990
977
  return;
991
978
  }
992
979
  // Generate an initial ~/.hometrans/config.json up front (first-use scenario):
993
- // loadHomeTransConfig writes a complete default file (editors + env + autotest)
980
+ // loadHomeTransConfig writes a complete default file (editors + env)
994
981
  // when none exists, and saveHomeTransConfig flushes it again to be certain it is
995
982
  // on disk before any later step (e.g. Model Configuration) points the user at it.
996
983
  const configPath = getConfigPath();
@@ -1102,9 +1089,16 @@ export async function initCommand(options = {}) {
1102
1089
  console.log(chalk.yellow(' Parameter prompts skipped (non-interactive mode).'));
1103
1090
  }
1104
1091
  // Model Configuration — configure the single multimodal LLM shared by UI
1105
- // alignment and self-test. Stored in autotest.unified_model (config.json) and
1106
- // exported as HOMETRANS_MODEL_* env vars by maybePersistMachineEnv below.
1092
+ // alignment and self-test. Stored as HOMETRANS_MODEL_* in config.env,
1093
+ // exported as machine env vars by maybePersistMachineEnv below.
1107
1094
  await promptModelConfig(config);
1095
+ // Layered mode hint — the user configured unified_model above; if they
1096
+ // want Planner+Executor dual-agent mode, they need to set agent_mode and
1097
+ // fill execute_model / decision_model manually in config.json.
1098
+ console.log('');
1099
+ console.log(chalk.gray(' Tip: to use layered (Planner+Executor) mode for self-test, edit ~/.hometrans/config.json:\n' +
1100
+ ' set "agent_mode": "layered" and fill "execute_model" / "decision_model"\n' +
1101
+ ' with the same model as unified_model (or different models per slot).'));
1108
1102
  // Dependency Installation — auto-provisionable dep: git (required by the
1109
1103
  // diff-based agent precheck). The global npm CLIs (homegraph, arkanalyzer)
1110
1104
  // are intentionally NOT installed here — skills resolve them on demand via
@@ -1132,17 +1126,16 @@ export async function initCommand(options = {}) {
1132
1126
  console.log(chalk.yellow(` ! environment check skipped: ${err.message}`));
1133
1127
  }
1134
1128
  // Copy bundled tools/ into ~/.hometrans/tools and record env.HOMETRANS_TOOL_PATH.
1135
- // self_test_runner.ts (under the installed tools dir) reads the autotest
1136
- // config from ~/.hometrans/config.json at run time — see promptModelConfig.
1129
+ // Scripts under the installed tools dir read HOMETRANS_MODEL_* env vars at run time.
1137
1130
  try {
1138
1131
  await installTools(toolsRoot, config);
1139
1132
  }
1140
1133
  catch (err) {
1141
1134
  console.log(chalk.red(` ! tools copy: ${err.message}`));
1142
1135
  }
1143
- // (The autotest.unified_model block in config.json was already configured by
1144
- // the Model Configuration step above; self_test_runner.ts reads it at run time
1145
- // and the UI-alignment phone-agent reads the exported HOMETRANS_MODEL_* vars.)
1136
+ // (HOMETRANS_MODEL_* env vars were configured by the Model Configuration step
1137
+ // above. UI-alignment reads them at run time. Agent config is in
1138
+ // ~/.hometrans/autotest.yaml, generated by the integration-test skill.)
1146
1139
  // Offer to persist the resolved config values as real OS environment
1147
1140
  // variables (Windows: setx; macOS/Linux: shell rc block). Shows what will be
1148
1141
  // written and asks Y/N first; runs after HOMETRANS_TOOL_PATH is finalized above.
@@ -28,8 +28,8 @@ const __dirname = path.dirname(__filename);
28
28
  const NODE_DEPS = ['homegraph', 'arkanalyzer'];
29
29
  /**
30
30
  * Machine env var names that `ht init` may have set and that have a non-empty
31
- * value in config.env: the SDK paths / tool dir plus the mirrored unified model
32
- * fields (HOMETRANS_MODEL_*, kept in sync with autotest.unified_model on load).
31
+ * value in config.env: the SDK paths / tool dir plus the model fields
32
+ * (HOMETRANS_MODEL_*).
33
33
  */
34
34
  function plannedEnvVarNames(config) {
35
35
  return MACHINE_ENV_KEYS.filter((k) => (config.env[k] ?? '').trim().length > 0);
@@ -105,7 +105,7 @@
105
105
  { "tool": "hdc", "level": "required" },
106
106
  { "tool": "node", "level": "required", "version": { "min": "22.18.0" } }
107
107
  ],
108
- "note": "self-tester agent runs tools via node \"$TOOL_DIR/engine/self-test-runner.ts\" (TOOL_DIR resolved from npm global root); TS scripts use Node native type stripping"
108
+ "note": "the skill runs its bundled tools directly via node \"$SKILL_SCRIPTS/<script>.ts\" where SKILL_SCRIPTS is the skill's own scripts/ directory; batch_runner.js is resolved from @autotest/agent (walk-up from script dir + global npm root fallback + auto-install if missing). Tools are .ts source files run directly via Node type stripping (zero external deps)"
109
109
  },
110
110
  {
111
111
  "name": "hmos-fix-build-errors",
@@ -159,10 +159,11 @@
159
159
  "name": "self-tester",
160
160
  "kind": "agent",
161
161
  "dependencies": [
162
- { "tool": "node", "level": "required", "version": { "min": "22.18.0" } },
163
- { "tool": "hdc", "level": "required" }
162
+ { "tool": "deveco", "level": "optional" },
163
+ { "tool": "hdc", "level": "required" },
164
+ { "tool": "node", "level": "required", "version": { "min": "22.18.0" } }
164
165
  ],
165
- "note": "resolves TOOL_DIR via npm root -g, then runs node \"$TOOL_DIR/engine/self-test-runner.ts\" run/status/kill (TS via Node native type stripping)"
166
+ "note": "thin wrapper that loads the hmos-integration-test skill and runs its procedure (parse test_case.md → install HAP → run AutoTest batch → produce self-test-report.md); the skill's self-test-runner.ts resolves @autotest/agent's batch_runner.js itself (walk-up + global npm root fallback + auto-install if missing — Step 0b); tools are .ts source run via Node type stripping (zero external deps); reports the terminal status (COMPLETED/CRASHED/TIMEOUT/FAILED/NOT_STARTED) + self-test-report.md path back to the caller. No setup param; install/uninstall always runs (real installable HAP required)."
166
167
  },
167
168
  {
168
169
  "name": "self-test-fixer",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buaa_smat/hometrans",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "HomeTrans (Android-to-HarmonyOS) skill + agent installer. Run `ht init` to distribute conversion skills and subagents into AI editors.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,14 +28,12 @@
28
28
  "prepublishOnly": "npm run build"
29
29
  },
30
30
  "dependencies": {
31
- "@autotest/agent": "file:tools/test-tools/autotest/deps/autotest-agent-0.1.1.tgz",
31
+ "@autotest/agent": "0.0.3",
32
32
  "@modelcontextprotocol/sdk": "^1.0.4",
33
33
  "chalk": "^5.6.2",
34
- "commander": "^14.0.0",
35
34
  "figlet": "^1.11.0",
36
35
  "fs-extra": "11.3.0",
37
- "inquirer": "^14.0.0",
38
- "jsonc-parser": "^3.3.1"
36
+ "inquirer": "^14.0.0"
39
37
  },
40
38
  "devDependencies": {
41
39
  "@types/figlet": "^1.7.0",
@@ -74,7 +74,7 @@
74
74
  <text x="522" y="389" text-anchor="middle" class="pout">按场景校验迁移质量</text>
75
75
 
76
76
  <rect x="617" y="326" width="166" height="92" rx="9" fill="#f5f3ff" stroke="#7c3aed" stroke-width="1.6"/>
77
- <text x="700" y="349" text-anchor="middle" class="nts">self-tester</text>
77
+ <text x="700" y="349" text-anchor="middle" class="nts">hmos-integration-test</text>
78
78
  <text x="700" y="369" text-anchor="middle" class="ns">真机自测执行</text>
79
79
  <text x="700" y="389" text-anchor="middle" class="pout">解析 case / 安装包 / AutoTest</text>
80
80
 
@@ -20,7 +20,7 @@ Parse `$ARGUMENTS` as positional tokens:
20
20
  - **Arg 3** (`spec_file_path`): Path to the requirement spec document (required). This is the plan/spec that drives Stage 1 logic development and Stage 3 code review — both stages read it directly from this path.
21
21
  - **Arg 4** (`assets_output_path`): Directory to store all output/report files (optional). When omitted, default to `<harmony_project_dir>/.hometrans` — create the directory if it does not exist.
22
22
  - **Arg 5** (`test_case_path`): Path to the self-test case file driving the Stage 4 self-testing loop (optional). When omitted, default to `OUTPUT/test_case.md`. If the resolved file does not exist, the Stage 4 loop is skipped (see Loop Setup).
23
- - **Arg 6** (`pre_test_case_path`): Path to the pre-test case file (optional). When omitted, default to `OUTPUT/pre_test_case.md`. Only passed to the self-tester when the resolved file exists.
23
+ - **Arg 6** (`pre_test_case_path`): Path to the pre-test case file (optional). When omitted, default to `OUTPUT/pre_test_case.md`. Only passed to the hmos-integration-test skill when the resolved file exists.
24
24
  - **Arg 7** (`max_rounds_review`): Maximum number of Stage 3→3a→3b code-review-fix rounds to run (optional, default `2`). Must be a positive integer `>= 1`.
25
25
  - **Arg 8** (`max_rounds_test`): Maximum number of Stage 4→4a→4b self-test rounds to run (optional, default `2`). Must be a positive integer `>= 1`.
26
26
  - **Arg 9** (`skip_test`): `true` or `false` (optional, default `false`). When `true`, skip Stage 4 / 4a / 4b (Self-Testing Loop) entirely. Use this when no real HarmonyOS device is available for on-device testing.
@@ -44,6 +44,17 @@ Define shorthand variables for the instructions below:
44
44
  | `MAX_ROUNDS_TEST` | max_rounds_test — positive integer (default `2`). Controls Stage 4→4a→4b self-test loop. |
45
45
  | `SKIP_TEST` | skip_test — `true` or `false` (default `false`). When `true`, skip Stage 4 / 4a / 4b entirely (no real device available). |
46
46
 
47
+ ### Parameter Conventions
48
+
49
+ The pipeline sits between two layers that use different param styles — keep them straight when handing off:
50
+
51
+ - **Invoking a skill** (`hmos-integration-test`, `hmos-fix-build-errors`, `hmos-test-case-generation`, …): pass **kebab-case** params matching that skill's documented input table (e.g. `test-case-path`, `hap-path`, `project-dir`, `output-path`, `pre-test-case-path`).
52
+ - **Invoking a subagent** (`self-test-fixer`, `logic-coder`, `logic-context-builder`, `code-reviewer`, …): pass **snake_case** params matching that agent's definition (e.g. `self_test_report_path`, `harmony_project_dir`, `android_project_dir`, `output_path`). These snake_case keys are the agent-layer contract used consistently across all agent invocations in the project.
53
+ - **Exception — `self-tester`**: it is a thin pass-through wrapper around the `hmos-integration-test` skill, so it takes the **same kebab-case params as the skill** (`hap-path`, `test-case-path`, `project-dir`, `output-path`, `pre-test-case-path`, …), not snake_case. It forwards them verbatim to the skill and reports the result back.
54
+ - **This pipeline's own positional args** (Arg 1–9 above): documented as **snake_case labels** (positional; the label does not affect invocation).
55
+
56
+ The user-facing skill layer is uniformly kebab-case; agents use snake_case per their definitions (with `self-tester` as the documented kebab pass-through exception).
57
+
47
58
  ---
48
59
 
49
60
  ## Environment Variables Check (run before Stage 1)
@@ -53,14 +64,14 @@ The pipeline's sub-agents resolve each setting along the standard chain — **OS
53
64
  | Variable | config.json fallback | Needed for | Valid when |
54
65
  |---|---|---|---|
55
66
  | `DEVECO_HOME` *(or `DEVECO_SDK_HOME`)* | `env.DEVECO_HOME` / `env.DEVECO_SDK_HOME` | Stage 2 build + Stage 3b/4b rebuilds | resolves to a valid DevEco install |
56
- | `HOMETRANS_MODEL_API_KEY` | `autotest.unified_model.api_key` | Stage 4 self-test (only when `SKIP_TEST=false`) | non-empty / not the placeholder |
67
+ | `HOMETRANS_MODEL_API_KEY` | `HOMETRANS_MODEL_API_KEY env var` | Stage 4 self-test (only when `SKIP_TEST=false`) | non-empty / not the placeholder |
57
68
  | `HOMETRANS_TOOL_PATH` | env unset → fall back to `~/.hometrans/tools` | Stage 4 self-test AutoTest dir | path exists on disk |
58
69
 
59
70
  For each value, if the env var is unset, fall back to the listed `~/.hometrans/config.json` field. If neither yields a value:
60
71
 
61
72
  - **DevEco path** — **ask the user**; no stage can build without it.
62
73
  - **model api_key** — **ask the user**, or accept `skip_test=true` to drop Stage 4 entirely.
63
- - **`HOMETRANS_TOOL_PATH`** — do not ask and do not fail. The self-tester resolves its own tool directory from the npm package (with `~/.hometrans/tools` as fallback), so an unset value is normal. Record one manifest note and continue; only treat it as a problem if Stage 4 later reports `AutoTest directory not found`.
74
+ - **`HOMETRANS_TOOL_PATH`** — do not ask and do not fail. The hmos-integration-test skill resolves `@autotest/agent` itself (walk-up + global npm root + auto-install), so an unset value is normal. Record one manifest note and continue; only treat it as a problem if Stage 4 later reports `batch_runner.js not found`.
64
75
 
65
76
  Suggest running `ht init` to persist these as machine environment variables.
66
77
 
@@ -180,7 +191,7 @@ For the Stage 4 loop, combine test and fix results into one row per round plus o
180
191
 
181
192
  ### Package-Set Collection (shared procedure)
182
193
 
183
- Several stages below need the **full signed package set** — the entry HAP plus any in-app HSPs (and any feature HAP the build freshly produced) — so the self-tester installs them in one `hdc install -r` transaction (in-app HSPs cannot install standalone). Those stages call this procedure.
194
+ Several stages below need the **full signed package set** — the entry HAP plus any in-app HSPs (and any feature HAP the build freshly produced) — so the skill installs them in one `hdc install -r` transaction (in-app HSPs cannot install standalone). Those stages call this procedure.
184
195
 
185
196
  **Inputs:**
186
197
  - `BUILD_ROOT` — the project root rebuilt by `hmos-fix-build-errors` (= `HMOS`).
@@ -199,7 +210,7 @@ Several stages below need the **full signed package set** — the entry HAP plus
199
210
  6. **Copy** the selected non-entry files into `DEST` (flat). (The entry is already there from step 2.)
200
211
  7. **Invariants:**
201
212
  - **≥ 1 `.hap`** — guaranteed by step 2. If `AUTHORITATIVE_ENTRY` is missing, collection **fails** → caller fallback.
202
- - **Exactly one `entry-*.hap`** (the authoritative one). If the fresh harvest still yields a second, differently-named `entry-*.hap`, **fail** the collection and log the conflict (the self-tester picks `entry-*` first and cannot disambiguate two entries). Non-`entry-*` feature HAPs may be many.
213
+ - **Exactly one `entry-*.hap`** (the authoritative one). If the fresh harvest still yields a second, differently-named `entry-*.hap`, **fail** the collection and log the conflict (the skill picks `entry-*` first and cannot disambiguate two entries). Non-`entry-*` feature HAPs may be many.
203
214
  - On a same-basename collision in `DEST`, abort with a logged error listing sources.
204
215
  - Manifest inventory line: `package-set: 1 entry hap + F feature hap(s) + M signed hsp(s) → DEST` (and `WARNING: K unsigned .hsp skipped — build-config gap` if any).
205
216
  8. **Result:** the caller sets `CURRENT_HAP = DEST`.
@@ -330,7 +341,7 @@ Treat Stage 4 → 4a → 4b as a loop that runs up to `MAX_ROUNDS_TEST` times.
330
341
 
331
342
  #### Loop Setup
332
343
 
333
- 1. **Resolve the initial package set**: The self-tester needs the **complete signed package set** (entry HAP + any in-app HSPs) in one `hdc install -r` transaction (rationale in **Package-Set Collection** above).
344
+ 1. **Resolve the initial package set**: The skill needs the **complete signed package set** (entry HAP + any in-app HSPs) in one `hdc install -r` transaction (rationale in **Package-Set Collection** above).
334
345
  - **Priority 1 — `OUTPUT/package-set/` directory**: If it exists and contains **≥ 1 `.hap`**, set `CURRENT_HAP = OUTPUT/package-set/` (any `.hsp` present comes along; `.hsp` presence is **not** required — a single-module project yields exactly one entry HAP and must still take this branch) (the set mirrored by Stage 2 or, if a review round rebuilt, by the review-loop finalization).
335
346
  - **Priority 2 — Comma-separated assembly**: If `OUTPUT/package-set/` does not exist, find the entry HAP and any HSPs separately and assemble a comma-separated `CURRENT_HAP`:
336
347
  - Entry HAP: `OUTPUT/entry-default-signed.hap` → first `*-signed.hap` in `OUTPUT/` → search `HMOS/entry/build/default/outputs/default/`.
@@ -355,26 +366,25 @@ For each `round` from `1..MAX_ROUNDS_TEST`, set `ROUND_DIR = OUTPUT/round-{round
355
366
  > ⚠️ **`CURRENT_HAP` must reflect the latest build**: If a previous round's Stage 4b produced a new signed package set, `CURRENT_HAP` should already point to it (a directory, e.g. `round-{N-1}/package-set/`; or, via the legacy fallback, a single file like `round-{N-1}/entry-default-signed.hap`). Do NOT reuse the original package from Stage 2/3b in subsequent rounds.
356
367
 
357
368
  1. If `CURRENT_HAP` is missing, do **not** launch the test. Record this round as Stage 4 failure with note "No HAP file available — build may have failed in Stage 2/3b or a previous 4b round".
358
- 2. If `CURRENT_HAP` exists, launch the **self-tester**.
369
+ 2. If `CURRENT_HAP` exists, launch the **self-tester** subagent (a thin wrapper that loads the `hmos-integration-test` skill — used for context isolation on the long test run).
359
370
  3. Input (round 1):
360
- - `hap_path`: `CURRENT_HAP`
361
- - `output_path`: `OUTPUT` (the ROOT — the agent always writes here)
362
- - `project_dir`: `HMOS` (the HarmonyOS project root containing `AppScope/app.json5` — the self-tester resolves `bundle_name`/`app_name` from it via the resolve-metadata tool)
363
- - `test_case_path`: `TEST_CASE`
364
- - `pre_test_case_path`: `PRE_TEST_CASE` (only include this line when the file exists)
365
- - `setup`: `true`
371
+ - `hap-path`: `CURRENT_HAP`
372
+ - `output-path`: `OUTPUT` (the ROOT — the skill always writes here)
373
+ - `project-dir`: `HMOS` (the HarmonyOS project root containing `AppScope/app.json5` — the skill resolves `bundle_name`/`app_name` from it via the resolve-metadata tool)
374
+ - `test-case-path`: `TEST_CASE`
375
+ - `pre-test-case-path`: `PRE_TEST_CASE` (only include this line when the file exists)
366
376
  4. Input (round 2+):
367
- - `hap_path`: `CURRENT_HAP`
368
- - `output_path`: `OUTPUT` (still the ROOT)
369
- - `setup`: `false`
370
- 5. The agent verifies device connectivity, invokes the selftest runner to install the HAP and run test cases. **Pre-cases are folded into `OUTPUT/testcases.json` by the agent's S3/S4 step during round 1's `setup: true` invocation; they run first in the same batch — no separate pre-case file or parameter is needed downstream.** The agent writes `OUTPUT/self-test-report.md`, `OUTPUT/task/`, and (round 1 only) `OUTPUT/testcases.json` + `OUTPUT/app-metadata.json` + `OUTPUT/_extracted.json`.
377
+ - `hap-path`: `CURRENT_HAP`
378
+ - `output-path`: `OUTPUT` (still the ROOT)
379
+ - (round 2+ reuses `OUTPUT/testcases.json` + `OUTPUT/app-metadata.json` written by round 1 — no `setup` flag needed; the skill skips the parse/generate phase in round 2+ per its own procedure, reusing the two JSONs from round 1)
380
+ 5. The skill verifies device connectivity, runs `self-test-runner.ts` to install the HAP and execute test cases. **Pre-cases are folded into `OUTPUT/testcases.json` by the skill's parse+generate step during round 1; they run first in the same batch — no separate pre-case file or parameter is needed downstream.** The skill writes `OUTPUT/self-test-report.md`, `OUTPUT/task/`, and (round 1 only) `OUTPUT/testcases.json` + `OUTPUT/app-metadata.json` + `OUTPUT/_extracted.json`.
371
381
  6. After the agent returns, read `OUTPUT/app-metadata.json` and extract `project_root` → `PROJECT_ROOT`; **Stage 4a passes it as `harmony_project_dir`**. If the file is missing or carries no usable `project_root`, set `PROJECT_ROOT = HMOS` and note the fallback in the manifest. `app-metadata.json` is written once by round 1 and read in place by later rounds — it is never snapshotted into a round directory, so do not look for a round-dir copy.
372
382
  7. Snapshot per-round artifacts to `ROUND_DIR` after the agent returns: copy `OUTPUT/self-test-report.md` → `ROUND_DIR/self-test-report.md`, `OUTPUT/task/` → `ROUND_DIR/task/`, and (round 1 only) `OUTPUT/_extracted.json` → `ROUND_DIR/_extracted.json`. Skip any source that is missing.
373
383
  8. Read `ROUND_DIR/self-test-report.md` and extract total cases, passed, failed, and pass rate when the report exists.
374
- 9. **Sentinel early exit (environmental failure)**: before treating the round as a normal failure, check for the self-tester's early-exit conditions (per the integration-test skill's sentinel semantics, 2A.1 — device / config / tooling failures, not application defects, so the fixer cannot address them). If any of the following holds, record this round as an **environmental failure** — update the Stage 4 task description with the failure and (when captured) `early_exit_reason`, append the `4 Loop - Round {round}` Defect Summary row with note `environmental failure — 4a/4b skipped`, increment `rounds_executed`, set the matching `stop_reason`, mark Stage 4a and Stage 4b `completed` with `Skipped — environmental failure ({stop_reason})` and `Duration = SKIPPED`, then **skip Step B and Step C** and go straight to Loop Finalization:
384
+ 9. **Sentinel early exit (environmental failure)**: before treating the round as a normal failure, check for the skill's early-exit conditions (per the integration-test skill's sentinel semantics, 2A.1 — device / config / tooling failures, not application defects, so the fixer cannot address them). If any of the following holds, record this round as an **environmental failure** — update the Stage 4 task description with the failure and (when captured) `early_exit_reason`, append the `4 Loop - Round {round}` Defect Summary row with note `environmental failure — 4a/4b skipped`, increment `rounds_executed`, set the matching `stop_reason`, mark Stage 4a and Stage 4b `completed` with `Skipped — environmental failure ({stop_reason})` and `Duration = SKIPPED`, then **skip Step B and Step C** and go straight to Loop Finalization:
375
385
  - **No test cases (file-level check)**: `<output-path>/testcases.json` exists and contains 0 cases (the batch launcher returns early without writing `summary.json` when there are 0 cases — nothing to run) → `stop_reason = no_testcases`. (If `testcases.json` does not exist, the agent failed before S4 and is caught by the report-missing or `status: FAIL` branches below.)
376
- - **Report missing**: `<output-path>/self-test-report.md` does not exist (e.g. T8 failure or a hard error not covered by the sentinel set) → `stop_reason = agent_early_exit`, `early_exit_reason = "no self-test-report.md written — agent failed before producing a report"`.
377
- - **Report sentinel `status: FAIL`**: grep the report for the first `status:` line and the first `reason:` line; if the first line matches `status: FAIL` (device not connected, `HOMETRANS_MODEL_API_KEY` / `autotest.unified_model.api_key` not configured, AutoTest directory missing, or the batch launcher crashed) → `stop_reason = agent_early_exit`; capture the `reason:` line into the manifest as `early_exit_reason`.
386
+ - **Report missing**: `<output-path>/self-test-report.md` does not exist (e.g. T8 failure or a hard error not covered by the sentinel set) → `stop_reason = agent_early_exit`, `early_exit_reason = "no self-test-report.md written — skill failed before producing a report"`.
387
+ - **Report sentinel `status: FAIL`**: grep the report for the first `status:` line and the first `reason:` line; if the first line matches `status: FAIL` (device not connected, `HOMETRANS_MODEL_API_KEY` / `HOMETRANS_MODEL_API_KEY env var` not configured, AutoTest directory missing, or the batch launcher crashed) → `stop_reason = agent_early_exit`; capture the `reason:` line into the manifest as `early_exit_reason`.
378
388
  10. Compute `round_all_passed` only when the report can be parsed clearly and:
379
389
  - `总用例数` is known
380
390
  - `失败 == 0`
@@ -409,7 +419,7 @@ For each `round` from `1..MAX_ROUNDS_TEST`, set `ROUND_DIR = OUTPUT/round-{round
409
419
  1. Mark Stage 4b `in_progress` when the first Stage 4b round begins.
410
420
  2. Capture `BUILD_START` (touch a marker), then invoke `hmos-fix-build-errors <HMOS>` (the skill detects signed vs unsigned from `build-profile.json5`; the pipeline does not force a mode).
411
421
  3. Treat this as a compile/fix gate only — do **not** expect rebuild-stage report or commit-info artifacts in `ROUND_DIR`.
412
- 4. ⚠️ **CRITICAL — Update `CURRENT_HAP` for the next round**: If the build succeeds, resolve `AUTHORITATIVE_ENTRY` directly from `HMOS/entry/build/default/outputs/default/` (resolve in order: `entry-default-signed.hap` → any `*-signed.hap` → `entry-default-unsigned.hap` → any `entry-*.hap`), **run Package-Set Collection** with `BUILD_ROOT = HMOS`, `DEST = ROUND_DIR/package-set/`, that resolved `AUTHORITATIVE_ENTRY`, and the captured `BUILD_START`, and then set `CURRENT_HAP = ROUND_DIR/package-set/` so the next round's Stage 4 self-tester uses the freshly built set. If collection **fails** or yields zero HAPs, **keep the previous `CURRENT_HAP`** (the prior round's full set — fresher than any legacy single-file resolution) and record that this round produced no fresh package set.
422
+ 4. ⚠️ **CRITICAL — Update `CURRENT_HAP` for the next round**: If the build succeeds, resolve `AUTHORITATIVE_ENTRY` directly from `HMOS/entry/build/default/outputs/default/` (resolve in order: `entry-default-signed.hap` → any `*-signed.hap` → `entry-default-unsigned.hap` → any `entry-*.hap`), **run Package-Set Collection** with `BUILD_ROOT = HMOS`, `DEST = ROUND_DIR/package-set/`, that resolved `AUTHORITATIVE_ENTRY`, and the captured `BUILD_START`, and then set `CURRENT_HAP = ROUND_DIR/package-set/` so the next round's Stage 4 self-test uses the freshly built set. If collection **fails** or yields zero HAPs, **keep the previous `CURRENT_HAP`** (the prior round's full set — fresher than any legacy single-file resolution) and record that this round produced no fresh package set.
413
423
  5. Append one Defect Summary row for this round by combining the parsed Stage 4 and Stage 4a results into a single row labeled `4 Loop - Round {round}`.
414
424
  6. Update the Stage 4b task description with a brief round summary (for example: `Round 1: build success, hap=...`).
415
425
  7. Increment `rounds_executed`.
@@ -13,7 +13,7 @@ HarmonyOS-Android UI 自动对齐流水线。
13
13
  每多一个页面/弹窗/tab,上述步骤都要重复一遍,非常费时。
14
14
 
15
15
  本 skill 做了三件事:
16
- - 自动**寻路**(视觉模型根据自然语言点到指定页面,模型复用 `~/.hometrans/config.json` 统一配置)
16
+ - 自动**寻路**(视觉模型根据自然语言点到指定页面,模型复用 `HOMETRANS_MODEL_*` 统一配置)
17
17
  - 自动**采集** view tree + 截图(安卓走 adb、鸿蒙走 hdc)
18
18
  - 自动**对比 + 改码**,并按 MVVM 模式把 mock 数据放到 Model 层
19
19
 
@@ -34,7 +34,7 @@ HarmonyOS-Android UI 自动对齐流水线。
34
34
  - 采集脚本 `page_capture.ts` 与寻路脚本 `app_feature_verify.ts` 均为 TypeScript 版,用 Node 直接运行(Node ≥ 22.18 或 ≥ 23.6,原生剥离类型,无需编译、零第三方依赖)。确认 `node --version` 即可,无需 Python / uv。
35
35
 
36
36
  3. **模型配置**(寻路导航用)
37
- 与自测共用同一个多模态模型:`ht init` 把模型四要素(api_key / name / base_url / provider)写入 `~/.hometrans/config.json` 的 `autotest.unified_model`,并导出为 `HOMETRANS_MODEL_*` 环境变量。脚本优先读环境变量,缺失时回落 config.json;都没有时兼容老版本的 `GLM_API_KEY`(走智谱 GLM 端点)。无需单独设置 API Key。
37
+ 与自测共用同一个多模态模型:`ht init` 把模型四要素(api_key / name / base_url / provider)导出为 `HOMETRANS_MODEL_*` 环境变量。脚本优先读环境变量,缺失时回落 `~/.hometrans/autotest.yaml`;都没有时兼容老版本的 `GLM_API_KEY`(走智谱 GLM 端点)。无需单独设置 API Key。
38
38
 
39
39
  4. **鸿蒙 SDK 路径**(给改码阶段查 API 用)
40
40
  取自 OS 环境变量 `OHOS_SDK_PATH` / `HMS_SDK_PATH`(为空时由 `DEVECO_SDK_HOME` 派生),由 `ht init` 写入机器环境变量;例如 DevEco Studio 自带的 `E:\DevEco Studio\sdk\default\openharmony\ets`。
@@ -53,9 +53,9 @@ HarmonyOS-Android UI 自动对齐流水线。
53
53
  | `harmony_project_dir` | 是 | 鸿蒙工程根目录(会被直接修改) |
54
54
  | `capture_output_dir` | 否 | 采集产物输出目录(截图/view tree/分析报告)。默认 `<harmony_project_dir>/.hometrans/capture_output` |
55
55
 
56
- **② 全局配置**(统一链路「环境变量 → `~/.hometrans/config.json` → 询问用户」,由 `ht init` 同时写入机器环境变量与 config.json,无需每次传):
56
+ **② 全局配置**(统一链路「环境变量 → config.json → 询问用户」,由 `ht init` 同时写入机器环境变量与 config.json,无需每次传):
57
57
 
58
- - 模型配置 ← `HOMETRANS_MODEL_*` 环境变量(缺失时回落 `~/.hometrans/config.json` 的 `autotest.unified_model`;与自测共用同一个模型)
58
+ - 模型配置 ← `HOMETRANS_MODEL_*` 环境变量(缺失时回落 `~/.hometrans/autotest.yaml`;与自测共用同一个模型)
59
59
  - 鸿蒙 SDK ETS API 目录 ← 环境变量 `OHOS_SDK_PATH` / `HMS_SDK_PATH`(为空时由 `DEVECO_SDK_HOME` 派生为 `<DEVECO_SDK_HOME>/default/openharmony/ets`、`.../hms/ets`)
60
60
 
61
61
  > **Step 0.0** 会在执行前检查这些环境变量是否存在;缺失时会要求用户输入。
@@ -118,7 +118,7 @@ HarmonyOS-Android UI 自动对齐流水线。
118
118
  skill 会严格按 `SKILL.md` 里的流水线跑:
119
119
 
120
120
  ### Step 0 · 解析入参
121
- 读取调用入参 `android_project_dir` / `harmony_project_dir` / `capture_output_dir`,并按统一链路「环境变量 → config.json → 询问」解析 `HOMETRANS_MODEL_*`(统一模型,回落 `~/.hometrans/config.json` 的 `autotest.unified_model`)与 `OHOS_SDK_PATH` / `HMS_SDK_PATH`(回落 config.json 的 `env.*`;**Step 0.0** 会先做存在性检查,两层都缺失才要求用户输入)。随后 **Step 0.1** 按两个工程目录自动解析两端的 App 显示名与包名(无需手动配置)。
121
+ 读取调用入参 `android_project_dir` / `harmony_project_dir` / `capture_output_dir`,并按统一链路解析 `HOMETRANS_MODEL_*`(统一模型,链路「环境变量 → `~/.hometrans/autotest.yaml` → 询问」)与 `OHOS_SDK_PATH` / `HMS_SDK_PATH`(链路「环境变量 → `~/.hometrans/config.json` 的 `env.*` → 询问」;**Step 0.0** 会先做存在性检查,两层都缺失才要求用户输入)。随后 **Step 0.1** 按两个工程目录自动解析两端的 App 显示名与包名(无需手动配置)。
122
122
 
123
123
  ### Step 1 · 双端页面采集
124
124
  1.1 解析你的需求,拆成一组「基础页」,每个基础页有 `android_nav_path` 和 `hmos_nav_path`
@@ -42,11 +42,11 @@ Resolve each value along the standard chain — **OS environment variable first,
42
42
 
43
43
  | Variable | config.json fallback | Purpose | Valid when |
44
44
  |---|---|---|---|
45
- | `HOMETRANS_MODEL_*` (`HOMETRANS_MODEL_API_KEY` / `HOMETRANS_MODEL_NAME` / `HOMETRANS_MODEL_BASE_URL`) | `autotest.unified_model.{api_key,name,base_url}`(provider 默认 openai,不导出环境变量;再兜底老版本 `GLM_API_KEY` → 智谱 GLM 端点) | 统一多模态模型(UI 对齐 + 自测共用),由 `ht init` 导出 | `HOMETRANS_MODEL_API_KEY` 非空(或 config.json 已配置,或老版本 `GLM_API_KEY` 已设置) |
45
+ | `HOMETRANS_MODEL_*` (`HOMETRANS_MODEL_API_KEY` / `HOMETRANS_MODEL_NAME` / `HOMETRANS_MODEL_BASE_URL`) | `~/.hometrans/autotest.yaml` 的 `model.*.api_key`(provider 默认 openai,不导出环境变量;再兜底老版本 `GLM_API_KEY` → 智谱 GLM 端点) | 统一多模态模型(UI 对齐 + 自测共用),由 `ht init` 导出 | `HOMETRANS_MODEL_API_KEY` 非空(或 autotest.yaml 已配置,或老版本 `GLM_API_KEY` 已设置) |
46
46
  | `OHOS_SDK_PATH` | `env.OHOS_SDK_PATH` | HarmonyOS SDK ETS API reference (Step 3) | path exists on disk |
47
47
  | `HMS_SDK_PATH` | `env.HMS_SDK_PATH` | HMS SDK ETS API reference (Step 3) | path exists on disk |
48
48
 
49
- The model config is resolved automatically by `scripts/app_feature_verify.ts` (env → config.json), so you don't read it by hand — just confirm `HOMETRANS_MODEL_API_KEY` or `autotest.unified_model.api_key` is set. For `OHOS_SDK_PATH` / `HMS_SDK_PATH`, if both the env var and `~/.hometrans/config.json` are empty but `DEVECO_SDK_HOME` is set (env or `env.DEVECO_SDK_HOME` in config.json), derive them as `<DEVECO_SDK_HOME>/default/openharmony/ets` and `<DEVECO_SDK_HOME>/default/hms/ets`.
49
+ The model config is resolved automatically by `scripts/app_feature_verify.ts` (env → autotest.yaml), so you don't read it by hand — just confirm `HOMETRANS_MODEL_API_KEY` is set. For `OHOS_SDK_PATH` / `HMS_SDK_PATH`, if both the env var and `~/.hometrans/config.json` are empty but `DEVECO_SDK_HOME` is set (env or `env.DEVECO_SDK_HOME` in config.json), derive them as `<DEVECO_SDK_HOME>/default/openharmony/ets` and `<DEVECO_SDK_HOME>/default/hms/ets`.
50
50
 
51
51
  For each value that is still missing/empty (or a path that does not exist) after both the env var and `~/.hometrans/config.json`, **stop and ask the user to provide a value**, then use what they give for this run. Suggest running `ht init` to persist them as machine environment variables for next time.
52
52
 
@@ -1,4 +1,4 @@
1
- # Self-Test 使用文档
1
+ # Self-Test 使用文档
2
2
 
3
3
  ## 简介
4
4
 
@@ -47,10 +47,11 @@
47
47
  | `hap-path` | 必填 | 包路径,支持**一个或多个**(用逗号分隔)。每一项可以是 `.hap`/`.hsp` 文件,也可以是目录。所有项汇总起来要凑齐完整包集合:恰好一个 entry HAP + 其余 feature HAP / 应用内 HSP。**entry HAP 和 HSP 可以放在不同目录**——系统会把所有列出路径里的 `.hap`/`.hsp` 收集到一起,一次事务安装(应用内 HSP 不能单独装,必须和主包同一事务)。例:`D:\out\entry-default.hap, D:\hsp_out` |
48
48
  | `output-path` | 可选,默认 = `test-case-path` 所在目录 | 所有产物输出到这个目录(`testcases.json`、`app-metadata.json`、`self-test-report.md`、`task/` 都写在此根目录)。不指定时直接写在用例文件同目录 |
49
49
  | `project-dir` | 可选(自动从 `hap-path` / `test-case-path` 向上查找 `AppScope/app.json5` 推导;推导失败才询问) | HarmonyOS 工程根目录(含 `AppScope/app.json5`),用于解析 `bundle_name` / `app_name` |
50
- | `test-case-path` | `setup=true` 时必填 | `test_case.md` 的路径 |
51
- | `pre-test-case-path` | 可选 | 前置用例 `pre_test_case.md` 的路径。不传会自动在同目录查找 |
50
+ | `test-case-path` | 必填 | `test_case.md` 的路径 |
51
+ | `pre-test-case-path` | 可选 | 前置用例 `pre_test_case.md` 的路径。不传会自动在 `test-case-path` 同目录查找 `pre_test_case.md` |
52
52
  | `max-rounds` | 可选,默认 `3` | 测试修复循环的最大迭代轮数。必须为正整数(`>= 1`)。仅在启用修复循环时生效 |
53
- | `setup` | 可选,默认 `true` | `true` = 解析 `test_case.md` 写出 JSON,再跑测试;`false` = 跳过解析阶段,直接读取 `<output-path>/testcases.json` 与 `<output-path>/app-metadata.json` 跑测试。两个 JSON 都不存在或为空时硬失败,需要重跑一次 `setup=true` |
53
+
54
+ > 首轮(round 1)解析 `test_case.md`(及发现的 `pre_test_case.md`)写出 `testcases.json` + `app-metadata.json` 再跑测试;后续轮(round 2+)跳过解析阶段,直接复用首轮写出的两个 JSON。两个 JSON 都不存在或为空时硬失败,需重跑首轮。
54
55
 
55
56
  ### 自动修复参数
56
57
 
@@ -65,7 +66,7 @@
65
66
 
66
67
  ## 输出产物
67
68
 
68
- `testcases.json` 和 `app-metadata.json` 在首轮(`setup=true`)写入 `output-path/` 根目录,后续轮直接复用,不再重新生成。`self-test-report.md` 与 `task/` 每轮都会在根目录覆盖更新,跑完每轮后由 SKILL 快照到 `output-path/round-{n}/`。循环结束后,最后一轮的 HAP 镜像到根目录。
69
+ `testcases.json` 和 `app-metadata.json` 在首轮(round 1)写入 `output-path/` 根目录,后续轮直接复用,不再重新生成。`self-test-report.md` 与 `task/` 每轮都会在根目录覆盖更新,跑完每轮后由 SKILL 快照到 `output-path/round-{n}/`。循环结束后,最后一轮的 HAP 镜像到根目录。
69
70
 
70
71
  | 文件 | 写入位置 | 内容 |
71
72
  |------|----------|------|
@@ -150,7 +151,7 @@
150
151
  | 达到最大轮数 | `max_rounds_reached` | 已完成配置的最大轮数循环(`max-rounds`,默认 3),仍有失败未解决 |
151
152
  | 编译未产出 HAP(异常) | `no_hap` | 重建后在构建输出中找不到 entry HAP,无法继续测试 |
152
153
  | 用例列表为空(异常) | `no_testcases` | `testcases.json` 里 0 条用例,没有可跑的内容。常见原因:解析阶段没识别到 `### Scenario:` 区块 |
153
- | 自测 agent 早退(异常) | `agent_early_exit` | `self-tester` 在跑用例之前就退出了(设备没连、模型 api_key 没配(`HOMETRANS_MODEL_API_KEY` 环境变量或 `~/.hometrans/config.json` 的 `autotest.unified_model.api_key`)、`test-tools/autotest` 目录找不到(`HOMETRANS_TOOL_PATH` 环境变量未配置或失效)、batch 启动失败 / 超时 / 崩溃、`setup=false` 但所需 JSON 缺失等),或根本没生成 `self-test-report.md`(agent 在产出报告前就失败退出)。报告首行会是 `status: FAIL`,第二行 `reason: <原因>`。**这种情况下不会进入 fix 循环**——这些是环境/前置条件问题,不是应用缺陷 |
154
+ | 自测 agent 早退(异常) | `agent_early_exit` | 集成测试 skill 在跑用例之前就退出了(设备没连、模型 api_key 没配(`HOMETRANS_MODEL_API_KEY` 环境变量或 `~/.hometrans/autotest.yaml`)、`@autotest/agent` 未找到且自动安装失败、batch 启动失败 / 超时 / 崩溃、前置条件不满足但所需 JSON 缺失等),或根本没生成 `self-test-report.md`(skill 在产出报告前就失败退出)。报告首行会是 `status: FAIL`,第二行 `reason: <原因>`。**这种情况下不会进入 fix 循环**——这些是环境/前置条件问题,不是应用缺陷 |
154
155
 
155
156
  ---
156
157
 
@@ -203,12 +204,35 @@
203
204
 
204
205
  ## test_case.md 怎么写
205
206
 
206
- 用 Markdown 写,结构如下:
207
+ 完整格式定义见 `hmos-test-case-generation/references/contract.md`(`hmos-test-case-generation` skill 产出的就是该完整格式)。集成测试的解析器只从中提取 `### Scenario` 的 `动作`/`预期结果`,其余字段(`- 前置条件:`、`## 编号映射表`、`- 测试点:` 等)会被忽略——所以你既可以手写完整格式,也可以手写下面的最小子集。
208
+
209
+ 完整格式(`hmos-test-case-generation` 产出,contract.md 节选):
210
+
211
+ ```markdown
212
+ # 测试套件名
213
+
214
+ ## 编号映射表
215
+ | 功能名称 | SPEC 编号 | REQ 编号 |
216
+ |---------|-----------|----------|
217
+ | 新建歌单 | SPEC-01 | REQ |
218
+
219
+ ## Scenario List
220
+
221
+ ### Scenario 1-1: 新建歌单输入空白名称点击确定时提示名称不得为空 [P0]
222
+ - 前置条件:
223
+ - 条件1: 已安装 被测应用 并授予存储权限(AutoTest 自动处理)
224
+ - 动作:打开 被测应用 -> 进入歌单页面 -> 点击「新建歌单」按钮 -> 输入空白名称 -> 点击确定按钮
225
+ - 预期结果:弹出 toast「歌单名称不得为空」,且新建歌单对话框关闭
226
+ - 测试点:
227
+ - TP-1: 弹出 toast「歌单名称不得为空」
228
+ - TP-2: 新建歌单对话框关闭
229
+ ```
230
+
231
+ 最小手写子集(解析器同样接受,只提取动作/预期结果):
207
232
 
208
233
  ```markdown
209
234
  # 测试套件名
210
235
 
211
- ## Spec: 功能模块
212
236
  ### Scenario: 新建歌单
213
237
  - 动作:点击新建歌单按钮
214
238
  - 预期结果:弹出新建歌单对话框
@@ -216,16 +240,15 @@
216
240
  - 预期结果:歌单创建成功,出现在列表顶部
217
241
  ```
218
242
 
243
+ 字段说明:
219
244
  - `# 标题` → 测试套件名,会出现在报告里
220
- - `## Spec:` → 功能模块,纯逻辑分组,不影响执行
221
- - `### Scenario:` → 一条用例
222
- - `- 动作:` → 测试操作
245
+ - `### Scenario N-M:` → 一条用例(`N` = SPEC 号,`M` = 该 SPEC 内流水号;手写子集可省略编号写成 `### Scenario:`)
246
+ - `- 动作:` → 测试操作(多步用 ` -> ` 分隔)
223
247
  - `- 预期结果:` → 期望结果(多行用中文逗号连接)
248
+ - `- 前置条件:` / `## 编号映射表` / `- 测试点:` → 仅供人工阅读,解析时忽略
224
249
 
225
250
  **不需要手动替换应用名**。动作里写的显示名称(如"简单图库"、"Tuku")系统会自动替换成包名(如 `com.example.tuku`),确保 AutoTest 能正确识别目标应用。
226
251
 
227
- **以下内容会被自动忽略**:`- 前置条件:`、`## 页面描述注解`、`## 编号映射表`。
228
-
229
252
  ---
230
253
 
231
254
  ## 环境要求
@@ -234,13 +257,14 @@
234
257
 
235
258
  - 操作系统:**Windows** 是主要测试目标;macOS/Linux 上的核心命令(`hdc`、POSIX 工具链)也能跑,Skill 里涉及到的复制操作会按可用 shell 自适应
236
259
  - `hdc` 已安装并在 PATH 中
237
- - api_key 已配置(与 UI 对齐共用同一个多模态模型)。统一链路「环境变量 → config.json → 询问」:`self-test-runner.ts` 跑用例前优先读 OS 环境变量 `HOMETRANS_MODEL_API_KEY`(由 `ht init` 导出),缺失时回落 `~/.hometrans/config.json` 的 `autotest.unified_model.api_key`;环境变量存在时会覆盖 config.json 里的对应字段。运行时由脚本读取整个 `autotest` 块、把 api_key/model/device 映射成 `AUTOTEST_*` 环境变量传给 `batch-launcher.ts`(`new AutoTestAgent({...})` 构造器),不再需要 `config.yaml`
260
+ - 模型已配置:`ht init` 导出 `HOMETRANS_MODEL_API_KEY` / `HOMETRANS_MODEL_NAME` / `HOMETRANS_MODEL_BASE_URL` 环境变量。集成测试首次运行时,skill 自动从这些环境变量生成 `~/.hometrans/autotest.yaml`(AutoTestAgent 原生格式),后续运行直接读取,不重复生成。用户可手动编辑此文件启用 layered 模式。
261
+ - **layered 多模型模式**(可选):编辑 `~/.hometrans/autotest.yaml`,将 `agent.mode` 改为 `"layered"`,并添加 `execute` 和 `decision` 模型槽位。此模式下 AutoTest 使用 Planner + Executor 双 Agent 架构。两个槽位都需配置真实的 `name` / `api_key` / `base_url` / `provider`,否则 AutoTestAgent 启动时会报错。
238
262
  - 鸿蒙真机或模拟器已连接,`npx --yes devecocli device list` 能看到设备
239
263
  - `.hap` 文件(多模块应用:把 entry HAP + 应用内 HSP / feature HAP 一并传入;可以放进一个目录整目录传,也可以用逗号列出多个文件/目录,entry HAP 和 HSP 不在同一目录也行)
240
264
 
241
265
  ### 自动修复附加条件
242
266
 
243
- - `app-metadata.json` 存在(setup 阶段自动产出,内含 `project_root`)
267
+ - `app-metadata.json` 存在(round 1 解析阶段自动产出,内含 `project_root`)
244
268
  - 建议项目在 Git 仓库中(不在也可以修复,但不会自动 commit;`commit_id: none`)
245
269
 
246
270
  ---
@@ -253,7 +277,24 @@ A: 检查设备/模拟器连接,跑 `npx --yes devecocli device list` 看看
253
277
 
254
278
  **Q: 报 autotest 配置缺失 或 api_key 没填?**
255
279
 
256
- A: 按统一链路「环境变量 → config.json → 询问」配置 api_key,三选一:① 设置环境变量 `HOMETRANS_MODEL_API_KEY`(优先级最高,`self-test-runner.ts` 跑用例前会用它覆盖 config.json);② 重新跑 `ht init` 配置统一模型,它会写入 `~/.hometrans/config.json` 的 `autotest.unified_model` 并导出 `HOMETRANS_MODEL_*` 环境变量;③ 手动编辑 `~/.hometrans/config.json`,把 `autotest.unified_model.api_key` 的 `YOUR_API_KEY_HERE` 替换成真实的 API Key。
280
+ A: 确认 `ht init` 已完成模型配置(导出 `HOMETRANS_MODEL_API_KEY` 等环境变量)。集成测试首次运行时会自动生成 `autotest.yaml`,如果环境变量缺失会提示先跑 `ht init`。
281
+
282
+ **Q: 启用 layered 模式后报模型配置不完整?**
283
+
284
+ A: layered 模式需要 `execute` 和 `decision` 两个模型槽位。编辑 `~/.hometrans/autotest.yaml`,在 `model:` 下添加:
285
+ ```yaml
286
+ execute:
287
+ name: "gui-plus-2026-02-26"
288
+ base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
289
+ api_key: "sk-xxx"
290
+ provider: "mai-ui"
291
+ decision:
292
+ name: "qwen3.7-plus"
293
+ base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
294
+ api_key: "sk-xxx"
295
+ provider: "openai"
296
+ ```
297
+ 并将 `agent.mode` 改为 `"layered"`。
257
298
 
258
299
  **Q: 前置用例失败了要不要修代码?**
259
300
 
@@ -269,7 +310,7 @@ A: 每条用例大约 6 分钟(含 Agent 决策和执行时间)。整体超
269
310
 
270
311
  **Q: 怎么只重跑失败的用例?**
271
312
 
272
- A: 目前每次都跑 `testcases.json` 的全部用例。你可以手动删掉已通过的条目,只保留失败的,然后用 `setup=false` 重新跑(会跳过解析阶段,直接读取 `<output-path>/testcases.json`)。
313
+ A: 目前每次都跑 `testcases.json` 的全部用例。你可以手动删掉已通过的条目,只保留失败的,然后重跑(round 2+ 会跳过解析阶段,直接读取 `<output-path>/testcases.json`)。
273
314
 
274
315
  **Q: 产物在哪个目录?**
275
316