@buaa_smat/hometrans 26.0.5 → 26.0.6

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 (472) hide show
  1. package/README.md +249 -279
  2. package/agents/code-reviewer.md +1 -1
  3. package/dist/cli/editors.json +20 -0
  4. package/dist/platform/registry.js +1 -0
  5. package/dist/platform/validate.js +2 -1
  6. package/i18n/agents/code-reviewer.md +1 -1
  7. package/i18n/platforms/atomcode/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  8. package/i18n/platforms/claude-code/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  9. package/i18n/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +8 -0
  10. package/i18n/platforms/codex/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  11. package/i18n/platforms/cursor/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  12. package/i18n/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  13. package/i18n/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +10 -0
  14. package/i18n/platforms/qoder/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  15. package/i18n/platforms/qoder-cn/skills/a2h-app-migrate/SKILL.unique.md +8 -0
  16. package/i18n/platforms/trae/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  17. package/i18n/platforms/trae-cn/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  18. package/i18n/skills/a2h-app-migrate/SKILL.md +32 -15
  19. package/i18n/skills/a2h-app-migrate/references/stage-map.md +4 -2
  20. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +148 -89
  21. package/i18n/skills/a2h-app-migrate/scripts/env_preflight.mjs +1 -1
  22. package/i18n/skills/a2h-app-migrate/scripts/validate_workflow.mjs +51 -2
  23. package/i18n/skills/a2h-app-migrate/test/test_build_fixer_contract.mjs +1 -1
  24. package/i18n/skills/a2h-app-migrate/test/test_interaction.mjs +0 -2
  25. package/i18n/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
  26. package/i18n/skills/a2h-app-migrate/test/test_skill_doc.mjs +1 -1
  27. package/i18n/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +1 -1
  28. package/i18n/skills/a2h-app-migrate/test/test_utg_static_done.mjs +9 -3
  29. package/i18n/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +4 -2
  30. package/i18n/skills/a2h-arkts-logic-coder/SKILL.md +8 -7
  31. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -2
  32. package/i18n/skills/a2h-arkts-logic-coder/references/code-generation.md +33 -12
  33. package/i18n/skills/a2h-batch-ui-align/SKILL.md +14 -12
  34. package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -0
  35. package/i18n/skills/a2h-batch-ui-align/references/cards/canvas.md +1 -0
  36. package/i18n/skills/a2h-batch-ui-align/references/cards/dynamics.md +32 -1
  37. package/i18n/skills/a2h-batch-ui-align/references/cards/geometry.md +3 -2
  38. package/i18n/skills/a2h-batch-ui-align/references/cards/interaction.md +4 -0
  39. package/i18n/skills/a2h-batch-ui-align/references/cards/resources.md +19 -1
  40. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +13 -1
  41. package/i18n/skills/a2h-batch-ui-align/references/cards/window.md +2 -2
  42. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +205 -7
  43. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +10 -17
  44. package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +3 -4
  45. package/i18n/skills/a2h-batch-ui-align/references/lottie-integration.md +47 -2
  46. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +52 -328
  47. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +1 -138
  48. package/i18n/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +2 -11
  49. package/i18n/skills/a2h-batch-ui-align/references/state-mgmt/_paradigm-selection.md +1 -1
  50. package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +8 -23
  51. package/i18n/skills/a2h-batch-ui-align/references/step4-prepare.md +2 -1
  52. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +17 -9
  53. package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +239 -16
  54. package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +6 -0
  55. package/i18n/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +6 -3
  56. package/i18n/skills/a2h-batch-ui-align/scripts/measure_pack.ts +170 -10
  57. package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +42 -1
  58. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/main.ts +20 -1
  59. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +81 -0
  60. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/click_handler.ts +140 -0
  61. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/collapsing_toolbar.ts +124 -0
  62. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/compose_semantics.ts +287 -0
  63. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/flowitem_width.ts +78 -0
  64. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +194 -8
  65. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/inset_stacked.ts +138 -0
  66. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/int_division.ts +181 -0
  67. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +62 -2
  68. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_path.ts +77 -0
  69. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_ready.ts +109 -0
  70. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +88 -18
  71. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_cycle.ts +140 -0
  72. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +2 -2
  73. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/see_through_overlay.ts +149 -0
  74. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_builder.ts +139 -0
  75. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_show_close.ts +53 -0
  76. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/space_between_optional.ts +115 -0
  77. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +7 -1
  78. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/width_fill.ts +160 -0
  79. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_inset_stacked.test.mjs +155 -0
  80. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +60 -0
  81. package/i18n/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +38 -0
  82. package/i18n/skills/a2h-module-semantic-docs/SKILL.md +3 -2
  83. package/i18n/skills/a2h-page-specgen/SKILL.md +36 -5
  84. package/i18n/skills/a2h-page-specgen/references/behavior-ledger.md +89 -21
  85. package/i18n/skills/a2h-page-specgen/references/gates.md +33 -7
  86. package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +67 -13
  87. package/i18n/skills/a2h-page-specgen/references/spec-example.md +166 -32
  88. package/i18n/skills/a2h-page-specgen/references/spec-template.md +8 -5
  89. package/i18n/skills/a2h-page-specgen/scripts/behavior-audit.mjs +37 -1
  90. package/i18n/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +241 -22
  91. package/i18n/skills/a2h-page-specgen/scripts/behavior-model.mjs +29 -2
  92. package/i18n/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +32 -0
  93. package/i18n/skills/a2h-page-specgen/scripts/contract-calls.mjs +715 -0
  94. package/i18n/skills/a2h-page-specgen/scripts/footprint.mjs +129 -2
  95. package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +19 -10
  96. package/i18n/skills/a2h-page-specgen/scripts/lib/contracts.mjs +62 -3
  97. package/i18n/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +27 -0
  98. package/i18n/skills/a2h-page-specgen/scripts/lib/hg.mjs +116 -6
  99. package/i18n/skills/a2h-page-specgen/scripts/operation-evidence.mjs +270 -29
  100. package/i18n/skills/a2h-page-specgen/scripts/prepare.mjs +26 -14
  101. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +118 -25
  102. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +104 -19
  103. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +118 -25
  104. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +104 -19
  105. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +216 -216
  106. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +1 -1
  107. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +2 -2
  108. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +118 -25
  109. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +100 -15
  110. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +118 -25
  111. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +104 -19
  112. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +155 -3
  113. package/i18n/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +529 -1
  114. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +27 -0
  115. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +158 -0
  116. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +11 -13
  117. package/i18n/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +97 -0
  118. package/i18n/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +737 -0
  119. package/i18n/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +75 -3
  120. package/i18n/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +24 -0
  121. package/i18n/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +124 -0
  122. package/i18n/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +6 -2
  123. package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +106 -1
  124. package/i18n/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +32 -0
  125. package/i18n/skills/a2h-page-specgen/scripts/test/hg.test.mjs +12 -0
  126. package/i18n/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +6 -1
  127. package/i18n/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +11 -3
  128. package/i18n/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +1 -1
  129. package/i18n/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +1 -0
  130. package/i18n/skills/a2h-page-specgen/scripts/test/submit.test.mjs +159 -27
  131. package/i18n/skills/a2h-resource-convert/SKILL.md +1 -1
  132. package/i18n/skills/a2h-resource-convert/references/lottie-conversion-rules.md +2 -2
  133. package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +124 -8
  134. package/i18n/skills/a2h-resource-convert/scripts/sync-framework-strings.mjs +147 -0
  135. package/i18n/skills/a2h-resource-convert/scripts/tests/framework_strings.test.mjs +131 -0
  136. package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +15 -12
  137. package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +38 -10
  138. package/i18n/skills/a2h-spec-design-pipeline/references/initialization.md +2 -2
  139. package/i18n/skills/a2h-spec-design-pipeline/references/post-loop.md +2 -2
  140. package/i18n/skills/a2h-spec-design-pipeline/references/reply-recovery.md +172 -0
  141. package/i18n/skills/a2h-spec-design-pipeline/references/review-loop.md +2 -2
  142. package/i18n/skills/a2h-spec-design-pipeline/references/scripts.md +5 -3
  143. package/i18n/skills/a2h-spec-design-pipeline/references/state-and-resume.md +7 -1
  144. package/i18n/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +1 -1
  145. package/i18n/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +2 -0
  146. package/i18n/skills/a2h-spec-generate/references/input-formats.md +1 -1
  147. package/i18n/skills/a2h-utg-explorer/SKILL.md +11 -5
  148. package/i18n/skills/a2h-utg-explorer/references/architecture.md +37 -19
  149. package/i18n/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +48 -3
  150. package/i18n/skills/a2h-utg-explorer/scripts/final_utg.mjs +21 -0
  151. package/i18n/skills/a2h-utg-explorer/scripts/recover_d.mjs +67 -8
  152. package/i18n/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +32 -0
  153. package/i18n/skills/a2h-utg-explorer/scripts/tests/dialog_own_layout.test.mjs +40 -0
  154. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +63 -2
  155. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +143 -14
  156. package/i18n/skills/a2h-utg-static/SKILL.md +3 -3
  157. package/i18n/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +4 -3
  158. package/i18n/skills/a2h-utg-static/scripts/click_paths.mjs +1 -1
  159. package/i18n/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +25 -0
  160. package/i18n/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +1 -0
  161. package/package.json +2 -1
  162. package/platforms/atomcode/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  163. package/platforms/claude-code/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  164. package/platforms/codebuddy/agents/build-fixer.frontmatter.md +5 -0
  165. package/platforms/codebuddy/agents/code-reviewer.frontmatter.md +5 -0
  166. package/platforms/codebuddy/agents/model-render-worker.frontmatter.md +5 -0
  167. package/platforms/codebuddy/agents/model-worker.frontmatter.md +5 -0
  168. package/platforms/codebuddy/agents/specgen-worker.frontmatter.md +5 -0
  169. package/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +8 -0
  170. package/platforms/codex/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  171. package/platforms/cursor/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  172. package/platforms/deveco/agents/build-fixer.frontmatter.md +2 -0
  173. package/platforms/deveco/agents/code-reviewer.frontmatter.md +2 -0
  174. package/platforms/deveco/agents/model-render-worker.frontmatter.md +2 -0
  175. package/platforms/deveco/agents/model-worker.frontmatter.md +2 -0
  176. package/platforms/deveco/agents/specgen-worker.frontmatter.md +2 -0
  177. package/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  178. package/platforms/opencode/agents/build-fixer.frontmatter.md +2 -0
  179. package/platforms/opencode/agents/code-reviewer.frontmatter.md +2 -0
  180. package/platforms/opencode/agents/model-render-worker.frontmatter.md +2 -0
  181. package/platforms/opencode/agents/model-worker.frontmatter.md +2 -0
  182. package/platforms/opencode/agents/specgen-worker.frontmatter.md +2 -0
  183. package/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +10 -0
  184. package/platforms/qoder/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  185. package/platforms/qoder-cn/skills/a2h-app-migrate/SKILL.unique.md +8 -0
  186. package/platforms/trae/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  187. package/platforms/trae-cn/skills/a2h-app-migrate/SKILL.unique.md +3 -0
  188. package/skills/a2h-app-migrate/SKILL.md +31 -14
  189. package/skills/a2h-app-migrate/references/stage-map.md +4 -2
  190. package/skills/a2h-app-migrate/references/workflow.yaml +152 -89
  191. package/skills/a2h-app-migrate/scripts/assert_dag_complete.mjs +1 -1
  192. package/skills/a2h-app-migrate/scripts/check_ui_batch_done.mjs +28 -11
  193. package/skills/a2h-app-migrate/scripts/dag_action_catalog.mjs +76 -0
  194. package/skills/a2h-app-migrate/scripts/dag_production_executor.mjs +60 -5
  195. package/skills/a2h-app-migrate/scripts/dag_runner.mjs +184 -4
  196. package/skills/a2h-app-migrate/scripts/env_preflight.mjs +1 -1
  197. package/skills/a2h-app-migrate/scripts/ledger.mjs +2 -2
  198. package/skills/a2h-app-migrate/scripts/resume_plan.mjs +3 -3
  199. package/skills/a2h-app-migrate/scripts/validate_workflow.mjs +51 -2
  200. package/skills/a2h-app-migrate/test/test_dag_blocked_guard.mjs +291 -0
  201. package/skills/a2h-app-migrate/test/test_dag_production.mjs +40 -0
  202. package/skills/a2h-app-migrate/test/test_dag_runner.mjs +4 -3
  203. package/skills/a2h-app-migrate/test/test_i18n_engine_mirror.mjs +1 -1
  204. package/skills/a2h-app-migrate/test/test_interaction.mjs +0 -2
  205. package/skills/a2h-app-migrate/test/test_resume_plan.mjs +1 -1
  206. package/skills/a2h-app-migrate/test/test_skill_doc.mjs +1 -1
  207. package/skills/a2h-app-migrate/test/test_spec_engine_contract.mjs +1 -1
  208. package/skills/a2h-app-migrate/test/test_specs_json_preflight.mjs +1 -1
  209. package/skills/a2h-app-migrate/test/test_ui_batch_done.mjs +36 -0
  210. package/skills/a2h-app-migrate/test/test_utg_static_done.mjs +19 -6
  211. package/skills/a2h-app-migrate/test/test_validate_workflow_bilingual.mjs +4 -2
  212. package/skills/a2h-arkts-logic-coder/SKILL.md +8 -7
  213. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -2
  214. package/skills/a2h-arkts-logic-coder/references/code-generation.md +33 -12
  215. package/skills/a2h-batch-ui-align/SKILL.md +14 -12
  216. package/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -0
  217. package/skills/a2h-batch-ui-align/references/cards/canvas.md +1 -0
  218. package/skills/a2h-batch-ui-align/references/cards/dynamics.md +32 -1
  219. package/skills/a2h-batch-ui-align/references/cards/geometry.md +3 -2
  220. package/skills/a2h-batch-ui-align/references/cards/interaction.md +4 -0
  221. package/skills/a2h-batch-ui-align/references/cards/resources.md +19 -1
  222. package/skills/a2h-batch-ui-align/references/cards/widgets.md +13 -1
  223. package/skills/a2h-batch-ui-align/references/cards/window.md +2 -2
  224. package/skills/a2h-batch-ui-align/references/checker-rules.md +205 -7
  225. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +10 -17
  226. package/skills/a2h-batch-ui-align/references/incremental-scope.md +3 -4
  227. package/skills/a2h-batch-ui-align/references/lottie-integration.md +47 -2
  228. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +52 -328
  229. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +1 -138
  230. package/skills/a2h-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +2 -11
  231. package/skills/a2h-batch-ui-align/references/state-mgmt/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +1 -1
  232. package/skills/a2h-batch-ui-align/references/step3-capture.md +8 -23
  233. package/skills/a2h-batch-ui-align/references/step4-prepare.md +2 -1
  234. package/skills/a2h-batch-ui-align/references/step5-convert.md +17 -9
  235. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +239 -16
  236. package/skills/a2h-batch-ui-align/scripts/group_commit.mjs +6 -1
  237. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +6 -0
  238. package/skills/a2h-batch-ui-align/scripts/group_pass.mjs +270 -0
  239. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +134 -16
  240. package/skills/a2h-batch-ui-align/scripts/group_watch.mjs +39 -8
  241. package/skills/a2h-batch-ui-align/scripts/icon_coverage.mjs +6 -3
  242. package/skills/a2h-batch-ui-align/scripts/measure_pack.ts +170 -10
  243. package/skills/a2h-batch-ui-align/scripts/module_placement.mjs +189 -0
  244. package/skills/a2h-batch-ui-align/scripts/overlay_effects.mjs +205 -0
  245. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +42 -1
  246. package/skills/a2h-batch-ui-align/scripts/static_check/main.ts +20 -1
  247. package/skills/a2h-batch-ui-align/scripts/static_check/registry.ts +28 -0
  248. package/skills/a2h-batch-ui-align/scripts/static_check/rules/attr_chain.ts +81 -0
  249. package/skills/a2h-batch-ui-align/scripts/static_check/rules/click_handler.ts +140 -0
  250. package/skills/a2h-batch-ui-align/scripts/static_check/rules/collapsing_toolbar.ts +124 -0
  251. package/skills/a2h-batch-ui-align/scripts/static_check/rules/compose_semantics.ts +287 -0
  252. package/skills/a2h-batch-ui-align/scripts/static_check/rules/flowitem_width.ts +78 -0
  253. package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +194 -8
  254. package/skills/a2h-batch-ui-align/scripts/static_check/rules/inset_stacked.ts +138 -0
  255. package/skills/a2h-batch-ui-align/scripts/static_check/rules/int_division.ts +181 -0
  256. package/skills/a2h-batch-ui-align/scripts/static_check/rules/layout_placement.ts +62 -2
  257. package/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_path.ts +77 -0
  258. package/skills/a2h-batch-ui-align/scripts/static_check/rules/lottie_ready.ts +109 -0
  259. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +88 -18
  260. package/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_cycle.ts +140 -0
  261. package/skills/a2h-batch-ui-align/scripts/static_check/rules/relative_container_height.ts +2 -2
  262. package/skills/a2h-batch-ui-align/scripts/static_check/rules/see_through_overlay.ts +149 -0
  263. package/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_builder.ts +139 -0
  264. package/skills/a2h-batch-ui-align/scripts/static_check/rules/sheet_show_close.ts +53 -0
  265. package/skills/a2h-batch-ui-align/scripts/static_check/rules/space_between_optional.ts +115 -0
  266. package/skills/a2h-batch-ui-align/scripts/static_check/rules/theme_color.ts +7 -1
  267. package/skills/a2h-batch-ui-align/scripts/static_check/rules/width_fill.ts +160 -0
  268. package/skills/a2h-batch-ui-align/scripts/static_check/scan_file.ts +28 -0
  269. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_chrome_defaults.test.mjs +328 -0
  270. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_click_handler.test.mjs +127 -0
  271. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_compose_semantics.test.mjs +150 -0
  272. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +117 -0
  273. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_inset_stacked.test.mjs +155 -0
  274. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_layout_placement.test.mjs +60 -0
  275. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_rule_smoke.test.mjs +413 -0
  276. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_runtime_api.test.mjs +159 -0
  277. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_sheet_builder.test.mjs +192 -0
  278. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_theme.test.mjs +4 -2
  279. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set.test.mjs +38 -0
  280. package/skills/a2h-batch-ui-align/scripts/tests/build_conversion_set_compose.test.mjs +106 -0
  281. package/skills/a2h-batch-ui-align/scripts/tests/group_commit.test.mjs +15 -0
  282. package/skills/a2h-batch-ui-align/scripts/tests/group_pass.test.mjs +150 -0
  283. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +125 -0
  284. package/skills/a2h-batch-ui-align/scripts/tests/group_watch.test.mjs +56 -0
  285. package/skills/a2h-batch-ui-align/scripts/tests/measure_pack_icon_leaf.test.mjs +143 -0
  286. package/skills/a2h-batch-ui-align/scripts/tests/module_placement.test.mjs +248 -0
  287. package/skills/a2h-batch-ui-align/scripts/tests/overlay_effects.test.mjs +214 -0
  288. package/skills/a2h-fix-build-errors/references/known-patterns.md +5 -5
  289. package/skills/a2h-module-semantic-docs/SKILL.md +3 -2
  290. package/skills/a2h-module-semantic-docs/scripts/commit_module_state.mjs +10 -0
  291. package/skills/a2h-module-semantic-docs/scripts/design_baseline.mjs +158 -0
  292. package/skills/a2h-module-semantic-docs/test/test_design_baseline.mjs +128 -0
  293. package/skills/a2h-page-specgen/SKILL.md +36 -5
  294. package/skills/a2h-page-specgen/references/behavior-ledger.md +88 -21
  295. package/skills/a2h-page-specgen/references/evidence.md +2 -1
  296. package/skills/a2h-page-specgen/references/execution-model.md +13 -5
  297. package/skills/a2h-page-specgen/references/gates.md +33 -7
  298. package/skills/a2h-page-specgen/references/scenario-authoring.md +67 -13
  299. package/skills/a2h-page-specgen/references/spec-example.md +166 -32
  300. package/skills/a2h-page-specgen/references/spec-template.md +8 -5
  301. package/skills/a2h-page-specgen/scripts/behavior-audit.mjs +40 -2
  302. package/skills/a2h-page-specgen/scripts/behavior-discovery.mjs +241 -22
  303. package/skills/a2h-page-specgen/scripts/behavior-model.mjs +29 -2
  304. package/skills/a2h-page-specgen/scripts/behavior-reconcile.mjs +35 -2
  305. package/skills/a2h-page-specgen/scripts/contract-calls.mjs +715 -0
  306. package/skills/a2h-page-specgen/scripts/finalize.mjs +55 -2
  307. package/skills/a2h-page-specgen/scripts/footprint.mjs +129 -2
  308. package/skills/a2h-page-specgen/scripts/gate.mjs +20 -11
  309. package/skills/a2h-page-specgen/scripts/lib/contracts.mjs +56 -3
  310. package/skills/a2h-page-specgen/scripts/lib/graph-evidence.mjs +27 -0
  311. package/skills/a2h-page-specgen/scripts/lib/hg.mjs +114 -5
  312. package/skills/a2h-page-specgen/scripts/lib/ledger.mjs +20 -3
  313. package/skills/a2h-page-specgen/scripts/operation-evidence.mjs +270 -29
  314. package/skills/a2h-page-specgen/scripts/prepare.mjs +25 -14
  315. package/skills/a2h-page-specgen/scripts/report.mjs +26 -5
  316. package/skills/a2h-page-specgen/scripts/submission.mjs +69 -2
  317. package/skills/a2h-page-specgen/scripts/submit.mjs +105 -4
  318. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +110 -18
  319. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +97 -12
  320. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +110 -18
  321. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +97 -12
  322. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.discovery.json +224 -224
  323. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +1 -1
  324. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +2 -2
  325. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +110 -18
  326. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +97 -12
  327. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +110 -18
  328. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +97 -12
  329. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/run.mjs +153 -3
  330. package/skills/a2h-page-specgen/scripts/test/android-operation-evidence.test.mjs +529 -1
  331. package/skills/a2h-page-specgen/scripts/test/behavior-audit-pre.test.mjs +27 -0
  332. package/skills/a2h-page-specgen/scripts/test/behavior-discovery.test.mjs +158 -0
  333. package/skills/a2h-page-specgen/scripts/test/behavior-fixtures.mjs +11 -13
  334. package/skills/a2h-page-specgen/scripts/test/behavior-reconcile.test.mjs +97 -0
  335. package/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +737 -0
  336. package/skills/a2h-page-specgen/scripts/test/contracts.test.mjs +82 -3
  337. package/skills/a2h-page-specgen/scripts/test/finalize.test.mjs +24 -0
  338. package/skills/a2h-page-specgen/scripts/test/fixtures/hg.mkdb.mjs +11 -0
  339. package/skills/a2h-page-specgen/scripts/test/footprint-resolve.test.mjs +6 -2
  340. package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +94 -1
  341. package/skills/a2h-page-specgen/scripts/test/graph-evidence.test.mjs +32 -0
  342. package/skills/a2h-page-specgen/scripts/test/hg.test.mjs +14 -0
  343. package/skills/a2h-page-specgen/scripts/test/ledger.test.mjs +49 -1
  344. package/skills/a2h-page-specgen/scripts/test/operation-reviews.test.mjs +6 -1
  345. package/skills/a2h-page-specgen/scripts/test/prompt-tpl.test.mjs +12 -4
  346. package/skills/a2h-page-specgen/scripts/test/protocol-docs.test.mjs +1 -1
  347. package/skills/a2h-page-specgen/scripts/test/recovery-e2e.test.mjs +1 -0
  348. package/skills/a2h-page-specgen/scripts/test/report.test.mjs +80 -1
  349. package/skills/a2h-page-specgen/scripts/test/submit.test.mjs +159 -27
  350. package/skills/a2h-page-specgen/scripts/test/waker-process.test.mjs +23 -0
  351. package/skills/a2h-page-specgen/scripts/waker.mjs +8 -1
  352. package/skills/a2h-resource-convert/SKILL.md +1 -1
  353. package/skills/a2h-resource-convert/data/framework-strings/NOTICE +10 -0
  354. package/skills/a2h-resource-convert/data/framework-strings/manifest.json +90 -0
  355. package/skills/a2h-resource-convert/data/framework-strings/strings.json +382 -0
  356. package/skills/a2h-resource-convert/references/conversion-rules.md +7 -1
  357. package/skills/a2h-resource-convert/references/lottie-conversion-rules.md +2 -2
  358. package/skills/a2h-resource-convert/references/step5-reference-resolution.md +16 -0
  359. package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +124 -8
  360. package/skills/a2h-resource-convert/scripts/sync-framework-strings.mjs +147 -0
  361. package/skills/a2h-resource-convert/scripts/tests/framework_strings.test.mjs +131 -0
  362. package/skills/a2h-spec-design-pipeline/SKILL.md +14 -11
  363. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +38 -10
  364. package/skills/a2h-spec-design-pipeline/references/execution-model.md +3 -0
  365. package/skills/a2h-spec-design-pipeline/references/final-report-template.md +6 -3
  366. package/skills/a2h-spec-design-pipeline/references/initialization.md +2 -2
  367. package/skills/a2h-spec-design-pipeline/references/post-loop.md +2 -2
  368. package/skills/a2h-spec-design-pipeline/references/reply-recovery.md +172 -0
  369. package/skills/a2h-spec-design-pipeline/references/review-loop.md +2 -2
  370. package/skills/a2h-spec-design-pipeline/references/scripts.md +4 -3
  371. package/skills/a2h-spec-design-pipeline/references/shared-layer.md +24 -19
  372. package/skills/a2h-spec-design-pipeline/references/state-and-resume.md +7 -1
  373. package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +12 -5
  374. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +5 -0
  375. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +4 -0
  376. package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/README.md +27 -3
  377. package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-param-contract.json +46 -1
  378. package/skills/a2h-spec-design-pipeline/rules/migration-rules/data/api-permission-map.json +2511 -295
  379. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-cn.md +27 -72
  380. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/api-permission-declared-en.md +39 -83
  381. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +132 -101
  382. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +158 -115
  383. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-cn.md +60 -93
  384. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/platform-api-contract-en.md +73 -100
  385. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/route-page-side-effect-import-cn.md +52 -0
  386. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/route-page-side-effect-import-en.md +59 -0
  387. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ApiPermissionDeclaredCheck.js +57 -8
  388. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +475 -18
  389. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/PlatformApiContractCheck.js +472 -4
  390. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/RoutePageSideEffectImportCheck.js +570 -0
  391. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/arkui/RouteParamCarrierSubCheck.js +1053 -0
  392. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/sql/SqlIdentifierAnalysis.js +427 -0
  393. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +7 -1
  394. package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +1 -1
  395. package/skills/a2h-spec-design-pipeline/scripts/plan_groups.ts +1 -1
  396. package/skills/a2h-spec-design-pipeline/scripts/settle.ts +785 -0
  397. package/skills/a2h-spec-design-pipeline/scripts/test_api_permission_declared.ts +286 -0
  398. package/skills/a2h-spec-design-pipeline/scripts/test_arkui_runtime_pitfall.ts +166 -2
  399. package/skills/a2h-spec-design-pipeline/scripts/test_docs_refresh_contract.ts +40 -0
  400. package/skills/a2h-spec-design-pipeline/scripts/test_plan_groups.ts +2 -0
  401. package/skills/a2h-spec-design-pipeline/scripts/test_platform_api_contract.ts +350 -7
  402. package/skills/a2h-spec-design-pipeline/scripts/test_route_page_side_effect_import.ts +185 -0
  403. package/skills/a2h-spec-design-pipeline/scripts/test_route_param_carrier.ts +341 -0
  404. package/skills/a2h-spec-design-pipeline/scripts/test_settle.ts +593 -0
  405. package/skills/a2h-spec-design-pipeline/scripts/test_shared_layer_docs.ts +92 -1
  406. package/skills/a2h-spec-design-pipeline/scripts/test_sql_identifier_analysis.ts +137 -0
  407. package/skills/a2h-spec-generate/references/input-formats.md +1 -1
  408. package/skills/a2h-utg-explorer/SKILL.md +11 -5
  409. package/skills/a2h-utg-explorer/references/architecture.md +37 -19
  410. package/skills/a2h-utg-explorer/scripts/audit.mjs +6 -2
  411. package/skills/a2h-utg-explorer/scripts/close_phases.mjs +8 -5
  412. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +95 -19
  413. package/skills/a2h-utg-explorer/scripts/d_prereqs.mjs +192 -4
  414. package/skills/a2h-utg-explorer/scripts/final_utg.mjs +21 -0
  415. package/skills/a2h-utg-explorer/scripts/panel_routes.mjs +1 -1
  416. package/skills/a2h-utg-explorer/scripts/plan.mjs +16 -1
  417. package/skills/a2h-utg-explorer/scripts/predicates.mjs +270 -0
  418. package/skills/a2h-utg-explorer/scripts/promote_dynamic.mjs +2 -0
  419. package/skills/a2h-utg-explorer/scripts/recover.mjs +4 -3
  420. package/skills/a2h-utg-explorer/scripts/recover_d.mjs +67 -8
  421. package/skills/a2h-utg-explorer/scripts/rejudge.mjs +4 -3
  422. package/skills/a2h-utg-explorer/scripts/report.mjs +32 -2
  423. package/skills/a2h-utg-explorer/scripts/run_cycle.mjs +103 -36
  424. package/skills/a2h-utg-explorer/scripts/run_device.mjs +3 -8
  425. package/skills/a2h-utg-explorer/scripts/schedule_states.mjs +189 -0
  426. package/skills/a2h-utg-explorer/scripts/tests/calendar_round_fixes.test.mjs +9 -0
  427. package/skills/a2h-utg-explorer/scripts/tests/coverage_rules.test.mjs +11 -0
  428. package/skills/a2h-utg-explorer/scripts/tests/d_prereqs.test.mjs +31 -2
  429. package/skills/a2h-utg-explorer/scripts/tests/device_lock_retry.test.mjs +1 -1
  430. package/skills/a2h-utg-explorer/scripts/tests/diagnostics.test.mjs +32 -0
  431. package/skills/a2h-utg-explorer/scripts/tests/dialog_own_layout.test.mjs +40 -0
  432. package/skills/a2h-utg-explorer/scripts/tests/explorer_review_fixes.test.mjs +4 -1
  433. package/skills/a2h-utg-explorer/scripts/tests/hybrid_route.test.mjs +6 -28
  434. package/skills/a2h-utg-explorer/scripts/tests/in_route_surface.test.mjs +125 -0
  435. package/skills/a2h-utg-explorer/scripts/tests/list_probe_target_wait.test.mjs +86 -0
  436. package/skills/a2h-utg-explorer/scripts/tests/multi_host.test.mjs +167 -0
  437. package/skills/a2h-utg-explorer/scripts/tests/nested_list.test.mjs +58 -0
  438. package/skills/a2h-utg-explorer/scripts/tests/overlay_opener.test.mjs +100 -0
  439. package/skills/a2h-utg-explorer/scripts/tests/pipeline.test.mjs +8 -1
  440. package/skills/a2h-utg-explorer/scripts/tests/pr169_review_fixes.test.mjs +1 -0
  441. package/skills/a2h-utg-explorer/scripts/tests/pr191_review_fixes.test.mjs +2 -31
  442. package/skills/a2h-utg-explorer/scripts/tests/review_fixes.test.mjs +1 -1
  443. package/skills/a2h-utg-explorer/scripts/tests/run_cycle.test.mjs +56 -7
  444. package/skills/a2h-utg-explorer/scripts/tests/snapshot_integrity.test.mjs +117 -6
  445. package/skills/a2h-utg-explorer/scripts/tests/state_inventory.test.mjs +414 -0
  446. package/skills/a2h-utg-explorer/scripts/tests/tree_unreliable.test.mjs +197 -0
  447. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +196 -30
  448. package/skills/a2h-utg-explorer/scripts/utg_explorer/hosts.mjs +146 -0
  449. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +63 -2
  450. package/skills/a2h-utg-explorer/scripts/utg_explorer/states.mjs +286 -0
  451. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +197 -19
  452. package/skills/a2h-utg-static/SKILL.md +3 -3
  453. package/skills/a2h-utg-static/references/extractors.md +7 -0
  454. package/skills/a2h-utg-static/references/ui-elements-static-utg-schema.md +4 -3
  455. package/skills/a2h-utg-static/scripts/click_paths.mjs +1 -1
  456. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +642 -22
  457. package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +25 -0
  458. package/skills/a2h-utg-static/scripts/tests/test_in_route_surface.mjs +123 -0
  459. package/skills/a2h-utg-static/scripts/tests/test_overlay_host_effects.mjs +239 -0
  460. package/skills/a2h-utg-static/scripts/tests/test_shared_host_depths.mjs +48 -0
  461. package/skills/a2h-utg-static/scripts/utg_html.mjs +2 -0
  462. package/skills/a2h-utg-static/tools/convert_static_utg_to_ui_elements.ts +1 -0
  463. package/i18n/skills/a2h-app-migrate/references/specs.example.json +0 -19
  464. package/i18n/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +0 -79
  465. package/i18n/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +0 -47
  466. package/resource/convert_pipeline_process.svg +0 -114
  467. package/resource/project_architecture.svg +0 -120
  468. package/resource/set_environment.png +0 -0
  469. package/resource/set_multimodel.png +0 -0
  470. package/skills/a2h-app-migrate/references/specs.example.json +0 -19
  471. package/skills/a2h-batch-ui-align/scripts/databinding_analyzer_design.md +0 -79
  472. package/skills/a2h-utg-explorer/scripts/utg_explorer/state_phase.mjs +0 -47
@@ -0,0 +1,414 @@
1
+ // Data states as evidence (utg_explorer/states.mjs, predicates.mjs, schedule_states.mjs,
2
+ // d_prereqs initial, recover_d baseProblem). Measured (universalapp TV 2026-11-25): the device was
3
+ // handed over logged in with a non-empty device list; d_prereqs' pm clear lost that, the state
4
+ // phases blocked for want of a fixture, and D's wait-only recipes on first-launch data (which lands
5
+ // on the agreement dialog) failed their probes six times on the device.
6
+ import { test, describe, beforeEach } from 'node:test';
7
+ import assert from 'node:assert/strict';
8
+ import * as fs from 'node:fs';
9
+ import * as os from 'node:os';
10
+ import * as path from 'node:path';
11
+ import * as st from '../utg_explorer/states.mjs';
12
+ import * as pr from '../predicates.mjs';
13
+ import * as ss from '../schedule_states.mjs';
14
+ import * as dp from '../d_prereqs.mjs';
15
+ import { baseProblem, phasesNeedingState } from '../recover_d.mjs';
16
+ import { unrunnable } from '../close_phases.mjs';
17
+ import { AdapterError, assertDataChangeAllowed } from '../utg_explorer/adapters.mjs';
18
+ import { tinyTar } from './tar_fixture.mjs';
19
+
20
+ const PKG = 'x.app';
21
+ const ACT = 'x.app.Splash';
22
+ const rid = (r) => `${PKG}:id/${r}`;
23
+ const node = (r, text = '') => ({ resource_id: rid(r), text, visible: true, enabled: true });
24
+ const LIST = 'fragment:DeviceList';
25
+ const AGREE = 'fragment:AgreementDialog';
26
+ const LOGIN = 'activity:Login';
27
+ const DETAIL = 'activity:DeviceDetail';
28
+ const CONTENT = '{"kind": "data-state", "text": "device list not empty"}';
29
+
30
+ function campaign() {
31
+ return {
32
+ page_catalog: {
33
+ [LIST]: { kind: 'fragment', widget_ids: ['rootView', 'family', 'recycleViewDevice', 'include_empty_device'], hidden_ids: ['include_empty_device'] },
34
+ [AGREE]: { kind: 'dialog', widget_ids: ['agree', 'reject', 'summary'] },
35
+ [LOGIN]: { kind: 'activity', widget_ids: ['phone'] },
36
+ [DETAIL]: { kind: 'activity', widget_ids: ['power'] },
37
+ 'activity:Splash': { kind: 'activity', component: ACT, widget_ids: [] },
38
+ },
39
+ nodes: [
40
+ { id: LIST, kind: 'fragment', required_state: ['content'] },
41
+ { id: LOGIN, kind: 'activity', required_state: ['login'] },
42
+ { id: DETAIL, kind: 'activity' },
43
+ ],
44
+ phases: [
45
+ { id: 'p0-fresh', requires: [], obligations: [{ type: 'node', id: AGREE }], status: 'done' },
46
+ { id: 'state-login', requires: ['login'], obligations: [{ type: 'node', id: LOGIN }], status: 'pending' },
47
+ { id: 'state-dev', requires: ['content', CONTENT], obligations: [{ type: 'node', id: LIST }, { type: 'node', id: DETAIL }], status: 'pending' },
48
+ ],
49
+ tasks: [
50
+ { task_id: 't-agree-user', phase: 'p0-fresh', status: 'compiled', source_static: AGREE, target_static: 'fragment:UserTerms', requires: [] },
51
+ { task_id: 't-detail', phase: 'state-dev', status: 'compiled', source_static: LIST, target_static: DETAIL, requires: ['content', CONTENT] },
52
+ { task_id: 't-login', phase: 'state-login', status: 'compiled', source_static: 'activity:Splash', target_static: LOGIN, requires: ['login'] },
53
+ ],
54
+ events: [
55
+ { kind: 'task_result', payload: { task_id: 't-agree-user', outcome: 'failed', stage: 'source', reason: `source-unverified:${AGREE}`, target_static: 'fragment:UserTerms' } },
56
+ ],
57
+ };
58
+ }
59
+
60
+ let root;
61
+ let seq = 0;
62
+ function writeObs(oid, nodes, activity = ACT) {
63
+ const d = path.join(root, 'artifacts', oid); fs.mkdirSync(d, { recursive: true });
64
+ fs.writeFileSync(path.join(d, 'observation.json'), JSON.stringify({ observation_id: oid, package: PKG, activity, window: 'main', nodes }));
65
+ }
66
+ function events(list) {
67
+ fs.writeFileSync(path.join(root, 'events.jsonl'), list.map((e) => JSON.stringify({ ts: ++seq, ...e })).join('\n') + '\n');
68
+ }
69
+ const mapping = (oid, sid) => ({ kind: 'mapping', payload: { observation_id: oid, static_id: sid } });
70
+ const act = (type, extra = {}, after = null) => ({ kind: 'action_result', payload: { outcome: 'succeeded', action: { type, ...extra }, after } });
71
+ const listNodes = (rows) => [node('rootView'), node('family'), node('recycleViewDevice'), ...(rows ? [node('fl_device_1', 'Router')] : [node('include_empty_device', 'No devices')])];
72
+
73
+ beforeEach(() => {
74
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'states-'));
75
+ fs.writeFileSync(path.join(root, 'campaign.json'), JSON.stringify(campaign()));
76
+ seq = 0;
77
+ });
78
+
79
+ describe('a data wipe that never reported', () => {
80
+ const started = (id, type) => ({ id, kind: 'attempt_started', payload: { atomic: true, action: { type, archive: 'x.tar' } } });
81
+ test('a restore whose act() threw leaves the device in no known state: later captures are nobody\'s', () => {
82
+ st.recordState(root, { id: 'initial', archive: null, restorable: false, landing: null }, 0);
83
+ events([mapping('o1', 'p:A'), started('a1', 'restore_app_data'),
84
+ { kind: 'task_result', payload: { task_id: 't', outcome: 'failed' } }, mapping('o2', 'p:Login')]);
85
+ const d = st.deriveStates(root);
86
+ assert.equal(d.live, null);
87
+ assert.deepEqual(Object.keys(d.states.find((s) => s.id === 'initial').pages), ['p:A']);
88
+ });
89
+ test('a restore that reported keeps working as before', () => {
90
+ st.recordState(root, { id: 'initial', archive: null, restorable: false, landing: null }, 0);
91
+ st.recordState(root, { id: 'x', archive: 'x.tar', restorable: true, landing: null }, 0);
92
+ events([started('a1', 'restore_app_data'),
93
+ { kind: 'action_result', payload: { attempt_id: 'a1', outcome: 'no_effect', action: { type: 'restore_app_data', archive: 'x.tar' } } },
94
+ mapping('o2', 'p:B')]);
95
+ const d = st.deriveStates(root);
96
+ assert.equal(d.live, 'x');
97
+ assert.deepEqual(d.states.find((s) => s.id === 'x').pages, { 'p:B': ['o2'] });
98
+ });
99
+ test('the last event being an unreported clear: live is unknown', () => {
100
+ st.recordState(root, { id: 'initial', archive: null, restorable: false, landing: null }, 0);
101
+ events([started('a1', 'clear_app_data')]);
102
+ assert.equal(st.deriveStates(root).live, null);
103
+ });
104
+ test('a fixture snapshot kept from an earlier run (D#2, a resumed run) is entered as when it was written', () => {
105
+ st.recordState(root, { id: 'fresh', archive: 'fresh.tar', restorable: true, landing: null }, 0);
106
+ events([
107
+ { kind: 'action_result', payload: { outcome: 'succeeded', action: { type: 'restore_app_data', archive: 'fresh.tar' } } },
108
+ { kind: 'fixture_snapshot_kept', payload: { phase: 'recD-login', type: 'snapshot_app_data', archive: '/snap/login.tar' } },
109
+ mapping('o-home', 'p:Home')]);
110
+ const d = st.deriveStates(root);
111
+ assert.equal(d.live, 'login');
112
+ assert.deepEqual(d.states.find((s) => s.id === 'login').pages, { 'p:Home': ['o-home'] });
113
+ assert.deepEqual(d.states.find((s) => s.id === 'fresh').pages, {}, 'not credited to the base');
114
+ });
115
+ });
116
+
117
+ describe('states.json and the event log', () => {
118
+ test('captures are attributed to the data state the device held; a recipe snapshot becomes a state with its landing', () => {
119
+ writeObs('o-list', listNodes(true));
120
+ writeObs('o-agree', [node('agree', 'Agree'), node('reject'), node('summary')]);
121
+ st.recordState(root, { id: 'initial', archive: 'C:\\snap\\initial.tar', restorable: true, landing: null }, 0);
122
+ st.recordState(root, { id: 'fresh', archive: '/snap/fresh.tar', restorable: true, landing: null }, 0);
123
+ events([mapping('o-list', LIST),
124
+ act('restore_app_data', { archive: 'D:/other/host/fresh.tar' }), mapping('o-agree', AGREE),
125
+ act('snapshot_app_data', { archive: '/snap/recD-x.tar' }), act('launch', {}, 'o-agree')]);
126
+ const d = st.deriveStates(root, PKG, campaign().page_catalog);
127
+ const by = Object.fromEntries(d.states.map((s) => [s.id, s]));
128
+ assert.deepEqual(Object.keys(by.initial.pages), [LIST]);
129
+ assert.deepEqual(Object.keys(by.fresh.pages), [AGREE]);
130
+ assert.equal(by['recD-x'].landing.static_id, AGREE, 'resolved against the catalog');
131
+ assert.equal(d.live, 'recD-x');
132
+ });
133
+
134
+ test('a landing probe names the page\'s own ids, so another screen of the same activity fails it', () => {
135
+ const rule = st.landingRule({ package: PKG, activity: ACT, static_id: LIST, ids: listNodes(true).map((n) => n.resource_id) }, campaign().page_catalog);
136
+ assert.equal(rule.activity, ACT);
137
+ assert.deepEqual(rule.all.map((s) => s.resource_id.split('/').pop()), ['rootView', 'family', 'recycleViewDevice']);
138
+ });
139
+ });
140
+
141
+ describe('requirements against states', () => {
142
+ const ctx = (predicates = {}) => ({ guarded: st.guardedPages(campaign()), predicates, root });
143
+
144
+ test('a page proves the requirements on its route, never its own guard', () => {
145
+ const g = st.guardedPages(campaign());
146
+ assert.ok(g.get('content').has(DETAIL), 'a device page opens only from a device card');
147
+ assert.ok(!g.get('content').has(LIST), 'the list renders empty too');
148
+ assert.ok(!g.get('login').has(LOGIN), 'the login page renders when NOT logged in');
149
+ });
150
+
151
+ test('a compiled predicate decides on the captures of its page in that state', () => {
152
+ writeObs('o-full', listNodes(true)); writeObs('o-empty', listNodes(false));
153
+ const pred = { status: 'compiled', clauses: [{ page: LIST, rule: { any: [{ resource_name: 'fl_device_1' }], none: [{ resource_name: 'include_empty_device' }] } }] };
154
+ const c = ctx({ content: pred });
155
+ assert.equal(st.requirementHolds('content', { pages: { [LIST]: ['o-full'] } }, c).kind, 'predicate');
156
+ assert.equal(st.requirementHolds('content', { pages: { [LIST]: ['o-empty'] } }, c), null);
157
+ assert.equal(st.requirementHolds('content', { pages: {} }, c), null);
158
+ });
159
+
160
+ test('an unevaluable requirement is assumed, never proven', () => {
161
+ const c = ctx({ [CONTENT]: { status: 'unevaluable', why: 'code branch' } });
162
+ assert.equal(st.requirementHolds(CONTENT, { pages: {} }, c).kind, 'assumed');
163
+ });
164
+ });
165
+
166
+ describe('predicates.mjs', () => {
167
+ test('extract lists each plan requirement once with the pages the device showed; apply grounds every selector', () => {
168
+ writeObs('o-list', listNodes(true));
169
+ events([mapping('o-list', LIST)]);
170
+ const wl = pr.extract(root);
171
+ assert.deepEqual(wl.items.map((i) => i.requirement).sort(), [CONTENT, 'content', 'login'].sort());
172
+ const item = wl.items.find((i) => i.requirement === 'content');
173
+ const facts = item.candidate_pages.find((p) => p.page === LIST);
174
+ assert.ok(facts.captured_ids.includes('fl_device_1'), 'row ids come from captures, not the layout');
175
+ const login = wl.items.find((i) => i.requirement === 'login');
176
+ fs.writeFileSync(path.join(root, 'predicates_answers.json'), JSON.stringify([
177
+ { key: item.key, verdict: 'predicate', clauses: [{ page: LIST, rule: { any: [{ resource_name: 'fl_device_1' }] } }] },
178
+ { key: login.key, verdict: 'predicate', clauses: [{ page: LIST, rule: { any: [{ resource_name: 'invented' }] } }] },
179
+ { key: wl.items.find((i) => i.requirement === CONTENT).key, verdict: 'unevaluable', why: 'branch' },
180
+ ]));
181
+ const rep = pr.apply(root);
182
+ assert.deepEqual(rep.map((r) => r.status), ['compiled', 'rejected', 'unevaluable']);
183
+ assert.match(rep[1].why, /invented/);
184
+ const out = JSON.parse(fs.readFileSync(path.join(root, 'predicates.json'), 'utf8'));
185
+ assert.equal(out.items.content.status, 'compiled');
186
+ assert.equal(pr.extract(root).items.length, 1, 'only the rejected one is asked again');
187
+ });
188
+
189
+ test('a text that only differs in spacing / width compiles to the text the page shows (the device matches exactly)', () => {
190
+ writeObs('o-list', listNodes(true));
191
+ events([mapping('o-list', LIST)]);
192
+ const item = pr.extract(root).items.find((i) => i.requirement === 'content');
193
+ fs.writeFileSync(path.join(root, 'predicates_answers.json'), JSON.stringify([
194
+ { key: item.key, verdict: 'predicate', clauses: [{ page: LIST, rule: { any: [{ text: ' Router ' }] } }] },
195
+ ]));
196
+ assert.deepEqual(pr.apply(root).map((r) => r.status), ['compiled']);
197
+ const out = JSON.parse(fs.readFileSync(path.join(root, 'predicates.json'), 'utf8'));
198
+ assert.deepEqual(out.items.content.clauses[0].rule.any, [{ text: 'Router' }]);
199
+ });
200
+ });
201
+
202
+ describe('schedule_states.mjs', () => {
203
+ function setup() {
204
+ writeObs('o-list', listNodes(true));
205
+ writeObs('o-agree', [node('agree', 'Agree'), node('reject'), node('summary')]);
206
+ st.recordState(root, { id: 'initial', archive: '/snap/initial.tar', restorable: true,
207
+ landing: { observation_id: 'o-list', package: PKG, activity: ACT, static_id: LIST, ids: listNodes(true).map((n) => n.resource_id), texts: [] } }, 0);
208
+ st.recordState(root, { id: 'fresh', archive: '/snap/fresh.tar', restorable: true,
209
+ landing: { observation_id: 'o-agree', package: PKG, activity: ACT, static_id: AGREE, ids: [rid('agree'), rid('reject'), rid('summary')], texts: ['Agree'] } }, 0);
210
+ st.noteLive(root, 'fresh', 'snapshot', 1);
211
+ events([]);
212
+ const predicates = {
213
+ content: { status: 'compiled', clauses: [{ page: LIST, rule: { any: [{ resource_name: 'fl_device_1' }] } }] },
214
+ [CONTENT]: { status: 'compiled', clauses: [{ page: LIST, rule: { any: [{ resource_name: 'fl_device_1' }] } }] },
215
+ login: { status: 'compiled', clauses: [{ page: LIST }] },
216
+ };
217
+ return predicates;
218
+ }
219
+
220
+ test('a phase runs in the state its requirements hold in; a failed source page runs where it renders', () => {
221
+ const predicates = setup();
222
+ const doc = campaign(); const config = { launch_component: `${PKG}/${ACT}` };
223
+ const derived = st.deriveStates(root, PKG, doc.page_catalog);
224
+ const { phases, report } = ss.plan(doc, config, derived, predicates, root);
225
+ const byKey = Object.fromEntries(report.map((r) => [r.key, r]));
226
+ assert.equal(byKey['phase:state-dev'].state, 'initial');
227
+ assert.equal(byKey['phase:state-login'].state, 'initial');
228
+ assert.equal(byKey[`source:${AGREE}`].state, 'fresh');
229
+ const dev = doc.phases.find((p) => p.id === byKey['phase:state-dev'].phase);
230
+ assert.equal(dev.serves, 'state-dev');
231
+ assert.equal(config.fixtures[dev.id][0].type, 'restore_app_data', 'initial is not live: restored');
232
+ assert.ok(config.phase_probes[dev.id][0].all.length > 0, 'its probe is the landing');
233
+ const src = doc.phases.find((p) => p.id === byKey[`source:${AGREE}`].phase);
234
+ assert.equal(config.fixtures[src.id][0].type, 'restore_app_data');
235
+ assert.ok(doc.tasks.some((t) => t.task_id === `t-agree-user@${src.id}`));
236
+ assert.equal(phases.length, 3);
237
+ // served phases are neither D's nor blocked by close_phases; scheduling again adds nothing
238
+ const devPhase = doc.phases.find((p) => p.id === 'state-dev');
239
+ assert.equal(unrunnable(devPhase, config, doc), false);
240
+ assert.ok(!phasesNeedingState(doc, config).some((p) => p.id === 'state-dev'));
241
+ assert.equal(ss.plan(doc, config, derived, predicates, root).phases.length, 0);
242
+ // a variant that blocked hands the phase back to D
243
+ dev.status = 'blocked';
244
+ assert.ok(phasesNeedingState(doc, config).some((p) => p.id === 'state-dev'));
245
+ });
246
+
247
+ test('no state with the requirements: left to D', () => {
248
+ setup();
249
+ const doc = campaign(); const config = {};
250
+ const { report } = ss.plan(doc, config, st.deriveStates(root, PKG, doc.page_catalog), {}, root);
251
+ assert.equal(report.find((r) => r.key === 'phase:state-dev').status, 'unsatisfied');
252
+ });
253
+
254
+ test('a variant whose tasks all failed hands the phase back', () => {
255
+ const predicates = setup();
256
+ const doc = campaign(); const config = { launch_component: `${PKG}/${ACT}` };
257
+ const derived = st.deriveStates(root, PKG, doc.page_catalog);
258
+ const { phases } = ss.plan(doc, config, derived, predicates, root);
259
+ assert.equal(phases.length, 3);
260
+ const devVid = phases.find((id) => doc.phases.find((p) => p.id === id)?.serves === 'state-dev');
261
+ // variant ran but all tasks failed
262
+ const vTasks = doc.tasks.filter((t) => t.phase === devVid);
263
+ assert.ok(vTasks.length >= 1);
264
+ assert.equal(ss.isServed(doc, doc.phases.find((p) => p.id === 'state-dev')), true, 'not run yet: still served');
265
+ doc.events.push({ kind: 'task_result', ts: 2, payload: { task_id: vTasks[0].task_id, outcome: 'confirmed' } });
266
+ assert.equal(ss.isServed(doc, doc.phases.find((p) => p.id === 'state-dev')), true, 'a confirmation serves it');
267
+ doc.events.pop();
268
+ for (const t of vTasks) {
269
+ doc.events.push({ kind: 'task_result', ts: 2, payload: { task_id: t.task_id, outcome: 'failed' } });
270
+ }
271
+ assert.equal(ss.isServed(doc, doc.phases.find((p) => p.id === 'state-dev')), false);
272
+ assert.ok(phasesNeedingState(doc, config).some((p) => p.id === 'state-dev'));
273
+ });
274
+
275
+ test('data actions with no_effect still switch the live state', () => {
276
+ writeObs('o-list', listNodes(true));
277
+ st.recordState(root, { id: 'initial', archive: null, restorable: false, landing: null }, 0);
278
+ st.recordState(root, { id: 'fresh', archive: '/snap/fresh.tar', restorable: true, landing: null }, 0);
279
+ // restore_app_data emitted no_effect (screen was already the app launcher)
280
+ events([{ kind: 'action_result', ts: 10, payload: { outcome: 'no_effect',
281
+ action: { type: 'restore_app_data', archive: '/snap/fresh.tar' },
282
+ before: 'o1', after: 'o1' } }]);
283
+ const derived = st.deriveStates(root, PKG);
284
+ assert.equal(derived.live, 'fresh', 'restore with no_effect still moves live to fresh');
285
+ });
286
+
287
+ test('a resumed campaign\'s initial (data already changed) is never the live state', () => {
288
+ st.recordState(root, { id: 'initial', origin: 'resumed', archive: null, restorable: false, landing: null }, 0);
289
+ events([]);
290
+ assert.equal(st.deriveStates(root, PKG).live, null);
291
+ });
292
+
293
+ test('the live state needs no restore when it has no archive', () => {
294
+ writeObs('o-list', listNodes(true));
295
+ st.recordState(root, { id: 'initial', archive: null, restorable: false,
296
+ landing: { observation_id: 'o-list', package: PKG, activity: ACT, static_id: LIST, ids: listNodes(true).map((n) => n.resource_id), texts: [] } }, 0);
297
+ events([]);
298
+ const derived = st.deriveStates(root, PKG);
299
+ assert.equal(derived.live, 'initial');
300
+ assert.deepEqual(st.enterFixtures(derived.states[0], derived, { launch_component: 'c' }).map((f) => f.type), ['launch', 'wait']);
301
+ });
302
+ });
303
+
304
+ describe('user data is never lost', () => {
305
+ class FakeDevice {
306
+ static calls = []; static runAs = true; static entries = ['databases', 'app_webview'];
307
+ runAsAvailable() { return FakeDevice.runAs; }
308
+ appDataEntries() { return FakeDevice.entries; }
309
+ act(a) { FakeDevice.calls.push(a.type); if (a.type === 'snapshot_app_data') { fs.writeFileSync(a.archive, tinyTar()); } }
310
+ observe() { return { observation_id: 'o', package: PKG, activity: ACT, nodes: [node('rootView', 'Home')] }; }
311
+ }
312
+ const withDevice = (fn) => { const s = dp.deps.DeviceAdapter; dp.deps.DeviceAdapter = FakeDevice; try { return fn(); } finally { dp.deps.DeviceAdapter = s; } };
313
+ let cfg;
314
+ beforeEach(() => {
315
+ cfg = path.join(root, 'config.json');
316
+ fs.writeFileSync(cfg, JSON.stringify({ serial: 'states-test-' + process.pid, package: PKG, launch_component: 'c', device_lock_wait_s: 0.2 }));
317
+ FakeDevice.calls = []; FakeDevice.runAs = true; FakeDevice.entries = ['databases', 'app_webview'];
318
+ });
319
+
320
+ test('initial archives the handed-over data before any clear, once', () => {
321
+ const r = withDevice(() => dp.initial(cfg, 0));
322
+ assert.equal(r.restorable, true);
323
+ assert.deepEqual(FakeDevice.calls, ['snapshot_app_data', 'launch'], 'no clear_app_data');
324
+ const s = st.loadStates(root).states[0];
325
+ assert.equal(s.id, 'initial');
326
+ assert.deepEqual(s.landing.texts, ['Home']);
327
+ assert.equal(withDevice(() => dp.initial(cfg, 0)).created, false);
328
+ });
329
+
330
+ test('an app that never ran: initial is recorded empty, not an error, and restore-initial clears', () => {
331
+ FakeDevice.entries = [];
332
+ const r = withDevice(() => dp.initial(cfg, 0));
333
+ assert.equal(r.empty, true);
334
+ assert.deepEqual(FakeDevice.calls, ['launch'], 'nothing to archive, nothing cleared');
335
+ const s = st.loadStates(root).states[0];
336
+ assert.equal(s.empty, true);
337
+ assert.equal(s.archive, null);
338
+ assert.notEqual(JSON.parse(fs.readFileSync(cfg, 'utf8')).user_state_protected, true, 'no data to protect');
339
+ FakeDevice.calls = [];
340
+ assert.equal(withDevice(() => dp.restoreInitial(cfg)).restored, true);
341
+ assert.deepEqual(FakeDevice.calls, ['clear_app_data', 'launch']);
342
+ // a config without serial never clears data on whatever device adb picks
343
+ const c = JSON.parse(fs.readFileSync(cfg, 'utf8')); delete c.serial; fs.writeFileSync(cfg, JSON.stringify(c));
344
+ FakeDevice.calls = [];
345
+ assert.throws(() => withDevice(() => dp.restoreInitial(cfg)), (e) => e instanceof AdapterError && /serial/.test(e.message));
346
+ assert.deepEqual(FakeDevice.calls, []);
347
+ });
348
+
349
+ test('a torn initial.tar left by a crashed initial is moved aside and taken again', () => {
350
+ const snap = path.join(root, 'snapshots');
351
+ fs.mkdirSync(snap, { recursive: true });
352
+ fs.writeFileSync(path.join(snap, 'initial.tar'), tinyTar().subarray(0, 512));
353
+ withDevice(() => dp.initial(cfg, 0));
354
+ assert.deepEqual(FakeDevice.calls, ['snapshot_app_data', 'launch']);
355
+ assert.ok(fs.readdirSync(snap).some((f) => f.startsWith('initial.tar.corrupt-')));
356
+ });
357
+
358
+ test('a whole initial.tar another campaign left in a shared snapshot_dir is never taken as this one\'s data', () => {
359
+ const snap = path.join(root, 'snapshots');
360
+ fs.mkdirSync(snap, { recursive: true });
361
+ const old = tinyTar(['databases', 'old_campaign']);
362
+ fs.writeFileSync(path.join(snap, 'initial.tar'), old);
363
+ const r = withDevice(() => dp.initial(cfg, 0));
364
+ assert.equal(r.kept_aside.length, 1, "the result lists what was kept aside, for cleanup");
365
+ assert.deepEqual(FakeDevice.calls, ['snapshot_app_data', 'launch'], 'archived from the device again');
366
+ assert.notDeepEqual(fs.readFileSync(path.join(snap, 'initial.tar')), old);
367
+ const kept = fs.readdirSync(snap).find((f) => f.startsWith('initial.tar.prev-'));
368
+ assert.ok(kept, 'the old archive is kept aside, not deleted');
369
+ assert.deepEqual(fs.readFileSync(path.join(snap, kept)), old);
370
+ const again = withDevice(() => dp.initial(cfg, 0));
371
+ assert.equal(again.created, false, 'recorded now: not taken again');
372
+ });
373
+
374
+ test('restoring a state clears every data entry, not only databases/shared_prefs/files', () => {
375
+ const fx = st.enterFixtures({ id: 'x', archive: 'x.tar', restorable: true }, { live: null }, { launch_component: 'c' });
376
+ assert.equal(fx[0].clear_dirs, 'all');
377
+ });
378
+
379
+ test('without run-as the data stays live-only and every later wipe is refused', () => {
380
+ FakeDevice.runAs = false;
381
+ const r = withDevice(() => dp.initial(cfg, 0));
382
+ assert.equal(r.restorable, false);
383
+ const c = JSON.parse(fs.readFileSync(cfg, 'utf8'));
384
+ assert.equal(c.user_state_protected, true);
385
+ assert.equal(withDevice(() => dp.snapshot(cfg, 'fresh', 0)).mode, 'none', 'no pm clear for a fresh base');
386
+ assert.throws(() => assertDataChangeAllowed(c, 'clear_app_data'), (e) => e instanceof AdapterError && /user-state-protected/.test(e.message));
387
+ assert.doesNotThrow(() => assertDataChangeAllowed({}, 'clear_app_data'));
388
+ });
389
+
390
+ test('allow_unarchived_wipe (a test device): no protection, D keeps its replay base', () => {
391
+ FakeDevice.runAs = false;
392
+ const c0 = JSON.parse(fs.readFileSync(cfg, 'utf8')); c0.allow_unarchived_wipe = true;
393
+ c0.snapshot_dir = path.join(root, 'snapshots');
394
+ fs.writeFileSync(cfg, JSON.stringify(c0));
395
+ const r = withDevice(() => dp.initial(cfg, 0));
396
+ assert.equal(r.restorable, false);
397
+ assert.match(r.why, /allow_unarchived_wipe/);
398
+ assert.notEqual(JSON.parse(fs.readFileSync(cfg, 'utf8')).user_state_protected, true);
399
+ assert.equal(withDevice(() => dp.snapshot(cfg, 'fresh', 0)).mode, 'replay');
400
+ });
401
+ });
402
+
403
+ describe('recover_d: a recipe must lead from its base landing to its probe', () => {
404
+ const landing = { activity: ACT, static_id: AGREE, texts: ['Welcome to the app, please read'], ids: [rid('agree')] };
405
+ const probes = [{ all: [{ text: 'Network quality' }] }];
406
+ test('wait-only on a base that lands elsewhere is rejected before the device', () => {
407
+ assert.match(baseProblem({ base: 'fresh.tar', steps: [{ type: 'wait', seconds: 2 }], probes }, landing), /lands on fragment:AgreementDialog/);
408
+ });
409
+ test('steps through the landing, or a base already showing the probe, pass', () => {
410
+ assert.equal(baseProblem({ base: 'fresh.tar', steps: [{ type: 'click', selector: { text: 'Agree' } }], probes }, landing), null);
411
+ assert.equal(baseProblem({ base: 'i.tar', steps: [{ type: 'wait' }], probes }, { ...landing, texts: ['Network quality'] }), null);
412
+ assert.equal(baseProblem({ base: 'x.tar', steps: [{ type: 'wait' }], probes }, null), null, 'no recorded landing: not decided here');
413
+ });
414
+ });
@@ -0,0 +1,197 @@
1
+ // A Compose Popup / Dialog is a window of its own: a dump of the wrong (or not yet laid out) window
2
+ // holds only an invisible root while the screenshot shows the popup. The adapter dumps every window
3
+ // once more; a tree still empty is `tree_unreliable`: a candidate of the task's expected target,
4
+ // never `unmapped`, and never a new dynamic node.
5
+ import { test, describe } from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ import * as fs from 'node:fs';
8
+ import * as os from 'node:os';
9
+ import * as path from 'node:path';
10
+ import { deflateSync } from 'node:zlib';
11
+ import { DeviceAdapter, pngUniform, sparseAppTree, topWindowOf, topWindowOfWindows, time } from '../utg_explorer/adapters.mjs';
12
+ import { Runner, treeUnreliableResolution } from '../utg_explorer/task_runner.mjs';
13
+ import { keepTreeUnreliable } from '../utg_explorer/semantics.mjs';
14
+ import { buildFinal } from '../final_utg.mjs';
15
+ import { etFromString } from '../utg_explorer/_py.mjs';
16
+
17
+ const PKG = 'com.example.app';
18
+ const FULL = `${PKG}/${PKG}.MainActivity`;
19
+ const tmp = (p) => fs.mkdtempSync(path.join(os.tmpdir(), p));
20
+
21
+ /** An 8-bit RGB PNG of w x h; `px(x, y)` -> [r, g, b]. CRCs are left zero (the reader skips them). */
22
+ function png(w, h, px) {
23
+ const chunk = (type, body) => { const len = Buffer.alloc(4); len.writeUInt32BE(body.length);
24
+ return Buffer.concat([len, Buffer.from(type, 'latin1'), body, Buffer.alloc(4)]); };
25
+ const ihdr = Buffer.alloc(13); ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 4); ihdr[8] = 8; ihdr[9] = 2;
26
+ const raw = Buffer.alloc(h * (1 + w * 3));
27
+ for (let y = 0; y < h; y++) {
28
+ raw[y * (1 + w * 3)] = 0;
29
+ for (let x = 0; x < w; x++) { const [r, g, b] = px(x, y); raw.set([r, g, b], y * (1 + w * 3) + 1 + x * 3); }
30
+ }
31
+ return Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk('IHDR', ihdr),
32
+ chunk('IDAT', deflateSync(raw)), chunk('IEND', Buffer.alloc(0))]);
33
+ }
34
+ const BLANK = png(64, 64, () => [255, 255, 255]);
35
+ const POPUP = png(64, 64, (x, y) => (y > 20 && y < 44 ? [180, 140, 60] : [240, 240, 240]));
36
+
37
+ const node = (attrs, kids = '') => `<node package="${PKG}" class="android.view.View"${attrs.includes('text=') ? '' : ' text=""'} ${attrs}>${kids}</node>`;
38
+ const EMPTY_ROOT = `<hierarchy rotation="0">${node('visible-to-user="false" bounds="[0,0][1080,2400]"')}</hierarchy>`;
39
+ const POPUP_TREE = `<hierarchy rotation="0">${node('visible-to-user="true" bounds="[42,310][1038,1505]"',
40
+ node('visible-to-user="true" text="130 - Moderate" bounds="[84,869][262,918]"') + node('visible-to-user="true" text="AQI 130" bounds="[84,992][297,1032]"'))}</hierarchy>`;
41
+
42
+ describe('screen and tree checks', () => {
43
+ test('pngUniform: one colour is blank, a popup is not, unreadable is unknown', () => {
44
+ assert.equal(pngUniform(BLANK), true);
45
+ assert.equal(pngUniform(POPUP), false);
46
+ assert.equal(pngUniform(Buffer.from('not a png')), null);
47
+ });
48
+
49
+ test('sparseAppTree: only an invisible root, or under two visible app nodes', () => {
50
+ assert.equal(sparseAppTree([{ package: PKG, visible: false }], PKG), true);
51
+ assert.equal(sparseAppTree([{ package: PKG, visible: true }], PKG), true);
52
+ assert.equal(sparseAppTree([{ package: PKG, visible: true }, { package: 'other', visible: true }], PKG), true);
53
+ assert.equal(sparseAppTree([{ package: PKG, visible: true }, { package: PKG, visible: true }], PKG), false);
54
+ });
55
+ });
56
+
57
+ describe('window choice', () => {
58
+ const allWindows = `<hierarchy rotation="0">${node('visible-to-user="false" bounds="[0,0][1080,2400]"')}`
59
+ + `${node('visible-to-user="true"', node('visible-to-user="true" text="Main"'))}</hierarchy>`;
60
+ test('topWindowOf keeps the topmost app root; skipEmpty passes over one that draws nothing', () => {
61
+ assert.match(topWindowOf(allWindows, PKG), /visible-to-user="false"/);
62
+ const cut = topWindowOf(allWindows, PKG, { skipEmpty: true });
63
+ assert.match(cut, /text="Main"/);
64
+ assert.doesNotMatch(cut, /visible-to-user="false"/);
65
+ // every app root empty: still the first one
66
+ assert.match(topWindowOf(EMPTY_ROOT, PKG, { skipEmpty: true }), /visible-to-user="false"/);
67
+ });
68
+
69
+ test('topWindowOfWindows: the same for `uiautomator dump --windows`', () => {
70
+ const xml = `<windows><window><hierarchy>${node('visible-to-user="false"')}</hierarchy></window>`
71
+ + `<window><hierarchy>${node('visible-to-user="true"', node('visible-to-user="true" text="Main"'))}</hierarchy></window></windows>`;
72
+ assert.match(topWindowOfWindows(xml, PKG), /visible-to-user="false"/);
73
+ assert.match(topWindowOfWindows(xml, PKG, { skipEmpty: true }), /text="Main"/);
74
+ });
75
+ });
76
+
77
+ /** A DeviceAdapter answering `dumps` in turn (each written to the tree file like a real dump). */
78
+ function adapter(dumps, screen, focus = '') {
79
+ const d = Object.create(DeviceAdapter.prototype);
80
+ d.config = { focus_settle_seconds: 0, settle_seconds: 0, tree_redump_settle_seconds: 0 };
81
+ d.artifact_dir = tmp('utg-tree-');
82
+ d._foreground = () => [FULL, ` mCurrentFocus=Window{abc u0 ${FULL}}\n${focus}`];
83
+ d._shell = () => '';
84
+ d.dumpCalls = [];
85
+ d._dumpUiautomator = (tree, component, popupPkg, opts = {}) => {
86
+ d.dumpCalls.push([popupPkg, opts.skipEmpty ?? false]);
87
+ const xml = dumps.length > 1 ? dumps.shift() : dumps[0];
88
+ fs.writeFileSync(tree, xml);
89
+ return etFromString(xml);
90
+ };
91
+ d._screenshot = () => screen;
92
+ d.deviceInfo = () => ({});
93
+ return d;
94
+ }
95
+
96
+ describe('observe re-dumps an empty tree under a non-blank screen', () => {
97
+ test('the all-windows re-dump replaces the empty tree, on disk too', () => {
98
+ const d = adapter([EMPTY_ROOT, POPUP_TREE], POPUP);
99
+ const obs = d.observe('env');
100
+ assert.deepEqual(d.dumpCalls, [[null, false], [PKG, true]]);
101
+ assert.equal(obs.tree_redump, 'all-windows');
102
+ assert.equal(obs.tree_unreliable, undefined);
103
+ assert.ok(obs.nodes.some((n) => n.text === 'AQI 130'));
104
+ assert.match(fs.readFileSync(obs.artifacts.tree, 'utf8'), /AQI 130/);
105
+ });
106
+
107
+ test('still empty after the re-dump: tree_unreliable once the app has shown a tree; the first dump kept', () => {
108
+ const d = adapter([EMPTY_ROOT], POPUP);
109
+ d._appShowedTree = true;
110
+ const obs = d.observe('env');
111
+ assert.equal(obs.tree_unreliable, 'no-visible-app-node');
112
+ assert.equal(obs.tree_redump, undefined);
113
+ assert.equal(fs.readFileSync(obs.artifacts.tree, 'utf8'), EMPTY_ROOT);
114
+ });
115
+
116
+ test('a blank screenshot is a blank screen (no re-dump, not unreliable)', () => {
117
+ const d = adapter([EMPTY_ROOT], BLANK);
118
+ d._appShowedTree = true;
119
+ const obs = d.observe('env');
120
+ assert.equal(d.dumpCalls.length, 1);
121
+ assert.equal(obs.tree_unreliable, undefined);
122
+ });
123
+
124
+ test('a visible app popup window keeps the topmost app root (no fall-through to the activity under it)', () => {
125
+ const popupWin = ' Window #5 Window{aaa u0 PopupWindow}:\n mOwnerUid=1 showForAllUsers=false package=' + PKG
126
+ + ' appop=NONE\n mAttrs={ty=APPLICATION_SUB_PANEL\n fl=NOT_FOCUSABLE WATCH_OUTSIDE_TOUCH\n isVisible=true\n';
127
+ const d = adapter([EMPTY_ROOT], POPUP, popupWin);
128
+ d.observe('env');
129
+ assert.deepEqual(d.dumpCalls[1], [PKG, false]);
130
+ });
131
+ });
132
+
133
+ describe('an unreliable tree is a candidate of the expected target, never a page', () => {
134
+ const unreliableObs = (oid) => ({ observation_id: oid, package: PKG, activity: `${PKG}.MainActivity`, window: 'main',
135
+ nodes: [{ package: PKG, class: 'android.widget.FrameLayout', visible: false, bounds: [0, 0, 1080, 2400] }],
136
+ environment_id: 'p', tree_unreliable: 'no-visible-app-node', identity: { family: 'x', state: {}, status: 'unmapped' },
137
+ artifacts: { screenshot: 'screen.png', tree: 'layout.xml' } });
138
+
139
+ test('capture after a task action: tree-unreliable with the expected target as candidate, and an event', () => {
140
+ const r = Object.create(Runner.prototype);
141
+ r.root = tmp('utg-tree-run-'); r.config = { package: PKG, save_interval: 1e9 }; r.env = 'p';
142
+ r.doc = { events: [] }; r.catalog = {}; r.current = null; r.mapped = new Set(); r.save = () => {};
143
+ r.device = { observe: () => unreliableObs('o1') };
144
+ r.stage = 'target'; r._expectTarget = 'overlay:DetailPopup'; r._expectTask = 't1';
145
+ const obs = r.capture();
146
+ assert.deepEqual(obs.static_resolution, { status: 'tree-unreliable', reason: 'no-visible-app-node', candidates: [],
147
+ candidate_for: 'overlay:DetailPopup' });
148
+ const cand = r.doc.events.find((e) => e.kind === 'candidate_capture').payload;
149
+ assert.deepEqual(cand, { static_id: 'overlay:DetailPopup', observation_id: 'o1', task_id: 't1', basis: 'tree-unreliable', confirmed: false });
150
+ assert.equal(r.doc.events.some((e) => e.kind === 'mapping'), false);
151
+ // outside a task's target stage there is no candidate
152
+ r.stage = 'source'; r.device = { observe: () => unreliableObs('o2') };
153
+ assert.equal(r.capture().static_resolution.candidate_for, undefined);
154
+ });
155
+
156
+ test('a re-judge keeps it unless the new catalog verifies it', () => {
157
+ const o = unreliableObs('o1');
158
+ const prev = treeUnreliableResolution(o, 'overlay:DetailPopup');
159
+ assert.deepEqual(keepTreeUnreliable(o, prev, { status: 'unmapped', candidates: [] }), prev);
160
+ const ok = { status: 'verified', static_id: 'overlay:DetailPopup' };
161
+ assert.equal(keepTreeUnreliable(o, prev, ok), ok);
162
+ const plain = { ...o }; delete plain.tree_unreliable;
163
+ assert.deepEqual(keepTreeUnreliable(plain, null, { status: 'unmapped' }), { status: 'unmapped' });
164
+ });
165
+
166
+ test('final UTG: no dynamic node, an issue, and an unconfirmed candidate on the expected node', () => {
167
+ const root = tmp('utg-tree-final-');
168
+ const o = unreliableObs('o1'); o.static_resolution = treeUnreliableResolution(o, 'overlay:DetailPopup');
169
+ const plain = unreliableObs('o2'); delete plain.tree_unreliable; plain.static_resolution = { status: 'unmapped', candidates: [] };
170
+ const doc = { nodes: [{ id: 'route:Main', kind: 'compose-route' }, { id: 'overlay:DetailPopup', kind: 'dialog' }], edges: [],
171
+ tasks: [], events: [{ id: 'e1', kind: 'observation', environment_id: 'p', payload: o },
172
+ { id: 'e2', kind: 'observation', environment_id: 'p', payload: plain }] };
173
+ const result = buildFinal(doc, root);
174
+ const dynamic = result.nodes.filter((n) => String(n.id).startsWith('dynamic:'));
175
+ assert.equal(dynamic.length, 1, 'only the plain unmapped capture becomes a dynamic node');
176
+ const popup = result.nodes.find((n) => n.id === 'overlay:DetailPopup');
177
+ assert.equal(popup.evidence.candidate_captures[0].observation_id, 'o1');
178
+ assert.notEqual(popup.evidence.coverage, 'observed');
179
+ const issue = result.issues.find((i) => i.kind === 'tree-unreliable-observations');
180
+ assert.deepEqual([issue.count, issue.candidates], [1, { 'overlay:DetailPopup': 1 }]);
181
+ });
182
+ });
183
+
184
+ describe('promote_dynamic', () => {
185
+ test('a tree-unreliable capture is offered to no dynamic-surface reviewer', async () => {
186
+ const { extract } = await import('../promote_dynamic.mjs');
187
+ const root = tmp('utg-tree-promote-');
188
+ const obs = (oid, extra) => JSON.stringify({ kind: 'observation', environment_id: 'p', payload: { observation_id: oid,
189
+ activity: 'A', nodes: [{ text: 'Sheet title', 'resource-id': `${PKG}:id/sheet` }], ...extra } });
190
+ fs.writeFileSync(path.join(root, 'events.jsonl'), [obs('o1', { tree_unreliable: 'no-visible-app-node' }),
191
+ obs('o2', { static_resolution: { status: 'tree-unreliable' } }), obs('o3', {})].join('\n') + '\n');
192
+ const log = console.log; console.log = () => {};
193
+ try { extract(root, null, 1); } finally { console.log = log; }
194
+ const wl = JSON.parse(fs.readFileSync(path.join(root, 'dynamic_promote_worklist.json'), 'utf8'));
195
+ assert.deepEqual(wl.items.flatMap((i) => i.observation_ids), ['o3']);
196
+ });
197
+ });