@buaa_smat/hometrans 0.1.17 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -56
- package/agents/code-reviewer.md +321 -65
- package/agents/logic-coder.md +113 -88
- package/agents/logic-context-builder.md +47 -29
- package/agents/scripts/hmos-precheck/backends/arkts.mjs +567 -0
- package/agents/scripts/hmos-precheck/backends/arkts_diff.mjs +159 -0
- package/agents/scripts/hmos-precheck/backends/arkts_project_rules.mjs +398 -0
- package/agents/scripts/hmos-precheck/backends/codelinter.mjs +250 -0
- package/agents/scripts/hmos-precheck/backends/project_integrity.mjs +321 -0
- package/agents/scripts/hmos-precheck/backends/static_precheck.mjs +247 -0
- package/agents/scripts/hmos-precheck/core/config.mjs +184 -0
- package/agents/scripts/hmos-precheck/core/diagnostic_scope.mjs +20 -0
- package/agents/scripts/hmos-precheck/core/process_adapter.mjs +47 -0
- package/agents/scripts/hmos-precheck/core/project_catalog.mjs +50 -0
- package/agents/scripts/hmos-precheck/core/result_projection.mjs +147 -0
- package/agents/scripts/hmos-precheck/core/scope_plan.mjs +131 -0
- package/agents/scripts/hmos-precheck/core/sdk_context.mjs +67 -0
- package/agents/scripts/hmos-precheck/docs/architecture.md +37 -0
- package/agents/scripts/hmos-precheck/docs/performance-optimization.md +28 -0
- package/agents/scripts/hmos-precheck/docs/upstream-reference.json +19 -0
- package/agents/scripts/hmos-precheck/docs/validation.md +50 -0
- package/agents/scripts/hmos-precheck/index.mjs +17 -0
- package/agents/scripts/hmos-precheck/invocation.mjs +231 -0
- package/agents/scripts/hmos-precheck/rules/rule_case_matrix.csv +32 -0
- package/agents/scripts/hmos-precheck/rules/rule_inventory.csv +64 -0
- package/agents/scripts/hmos-precheck/rules/rule_inventory.mjs +59 -0
- package/agents/scripts/hmos-precheck/rules/rule_policy.mjs +54 -0
- package/agents/scripts/platform_query.mjs +626 -0
- package/agents/scripts/platform_query.test.mjs +422 -0
- package/agents/self-test-fixer.md +36 -34
- package/agents/self-tester.md +35 -376
- package/agents/test-case-generation-generator.md +317 -0
- package/agents/test-case-generation-validator.md +231 -0
- package/dist/cli/config-store.js +19 -146
- package/dist/cli/config.js +6 -8
- package/dist/cli/env-vars.js +1 -3
- package/dist/cli/index.js +0 -11
- package/dist/cli/init.js +147 -235
- package/dist/cli/uninstall.js +5 -129
- package/dist/utils/regex.js +8 -0
- package/env-requirements.json +57 -55
- package/package.json +6 -8
- package/resource/convert_pipeline_process.svg +103 -0
- package/resource/project_architecture.svg +122 -0
- package/resource/title_dark.png +0 -0
- package/skills/hmos-batch-ui-align/SKILL.md +345 -43
- package/skills/hmos-batch-ui-align/references/conversion-procedure.md +661 -180
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
- package/skills/hmos-batch-ui-align/references/mvvm/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
- package/skills/hmos-batch-ui-align/references/mvvm/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
- package/skills/hmos-batch-ui-align/references/mvvm/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
- package/skills/hmos-batch-ui-align/references/mvvm/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
- package/skills/hmos-batch-ui-align/references/mvvm/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
- package/skills/hmos-batch-ui-align/references/mvvm/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
- package/skills/hmos-batch-ui-align/references/mvvm/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
- package/skills/hmos-batch-ui-align/references/mvvm/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
- package/skills/hmos-batch-ui-align/references/mvvm/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
- package/skills/hmos-batch-ui-align/references/mvvm/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
- package/skills/hmos-batch-ui-align/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -911
- package/skills/hmos-batch-ui-align/references/mvvm/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
- package/skills/hmos-batch-ui-align/references/mvvm//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
- package/skills/hmos-batch-ui-align/references/mvvm-v2/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md +206 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Computed/350/243/205/351/245/260/345/231/250/357/274/232/350/256/241/347/256/227/345/261/236/346/200/247.md +373 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Event/350/243/205/351/245/260/345/231/250/357/274/232/350/247/204/350/214/203/347/273/204/344/273/266/350/276/223/345/207/272.md +158 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Local/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/351/203/250/347/212/266/346/200/201.md +750 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Monitor/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/344/277/256/346/224/271/345/274/202/346/255/245/347/233/221/345/220/254.md +1704 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@ObservedV2/350/243/205/351/245/260/345/231/250/345/222/214@Trace/350/243/205/351/245/260/345/231/250/357/274/232/347/261/273/345/261/236/346/200/247/345/217/230/345/214/226/350/247/202/346/265/213.md +1012 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Once/350/243/205/351/245/260/345/231/250/357/274/232/345/210/235/345/247/213/345/214/226/345/220/214/346/255/245/344/270/200/346/254/241.md +164 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Param/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/244/226/351/203/250/350/276/223/345/205/245.md +840 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Provider/350/243/205/351/245/260/345/231/250/345/222/214@Consumer/350/243/205/351/245/260/345/231/250/357/274/232/350/267/250/347/273/204/344/273/266/345/261/202/347/272/247/345/217/214/345/220/221/345/220/214/346/255/245.md +856 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Type/350/243/205/351/245/260/345/231/250/357/274/232/346/240/207/350/256/260/347/261/273/345/261/236/346/200/247/347/232/204/347/261/273/345/236/213.md +83 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/AppStorageV2/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200UI/347/212/266/346/200/201/345/255/230/345/202/250.md +294 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md +1407 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/PersistenceV2/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +1220 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +47 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/_/350/243/205/351/245/260/345/231/250/351/200/237/346/237/245.md +133 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2//347/212/266/346/200/201/347/256/241/347/220/206V1/345/220/221V2/350/277/201/347/247/273/344/270/216/346/267/267/347/224/250/346/214/207/345/257/274.md +840 -0
- package/skills/hmos-batch-ui-align/scripts/android_parse_fast.ts +1798 -0
- package/skills/hmos-batch-ui-align/scripts/arkts_static_check.ts +1592 -0
- package/skills/hmos-batch-ui-align/scripts/measure_pack.ts +752 -0
- package/skills/hmos-convert-pipeline/SKILL.md +188 -131
- package/skills/hmos-fix-build-errors/SKILL.md +87 -67
- package/skills/hmos-fix-build-errors/references/arkts-strict-patterns.md +219 -219
- package/skills/hmos-fix-build-errors/references/known-patterns.md +157 -157
- package/skills/hmos-fix-build-errors/references/rdb-entity-pattern.md +131 -131
- package/skills/hmos-incremental-ui-align/README.md +57 -40
- package/skills/hmos-incremental-ui-align/SKILL.md +180 -24
- package/skills/hmos-incremental-ui-align/diff_analysis.md +52 -52
- package/skills/hmos-incremental-ui-align/page_align.md +62 -62
- package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +38 -2
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/MVVM/346/250/241/345/274/217V1.md +911 -911
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md +206 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Computed/350/243/205/351/245/260/345/231/250/357/274/232/350/256/241/347/256/227/345/261/236/346/200/247.md +373 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Event/350/243/205/351/245/260/345/231/250/357/274/232/350/247/204/350/214/203/347/273/204/344/273/266/350/276/223/345/207/272.md +158 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Local/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/351/203/250/347/212/266/346/200/201.md +750 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Monitor/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/344/277/256/346/224/271/345/274/202/346/255/245/347/233/221/345/220/254.md +1704 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@ObservedV2/350/243/205/351/245/260/345/231/250/345/222/214@Trace/350/243/205/351/245/260/345/231/250/357/274/232/347/261/273/345/261/236/346/200/247/345/217/230/345/214/226/350/247/202/346/265/213.md +1012 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Once/350/243/205/351/245/260/345/231/250/357/274/232/345/210/235/345/247/213/345/214/226/345/220/214/346/255/245/344/270/200/346/254/241.md +164 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Param/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/244/226/351/203/250/350/276/223/345/205/245.md +840 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Provider/350/243/205/351/245/260/345/231/250/345/222/214@Consumer/350/243/205/351/245/260/345/231/250/357/274/232/350/267/250/347/273/204/344/273/266/345/261/202/347/272/247/345/217/214/345/220/221/345/220/214/346/255/245.md +856 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Type/350/243/205/351/245/260/345/231/250/357/274/232/346/240/207/350/256/260/347/261/273/345/261/236/346/200/247/347/232/204/347/261/273/345/236/213.md +83 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/AppStorageV2/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200UI/347/212/266/346/200/201/345/255/230/345/202/250.md +294 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md +1407 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/PersistenceV2/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +1220 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +47 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2//347/212/266/346/200/201/347/256/241/347/220/206V1/345/220/221V2/350/277/201/347/247/273/344/270/216/346/267/267/347/224/250/346/214/207/345/257/274.md +840 -0
- package/skills/hmos-incremental-ui-align/references/State_Model_Template.md +74 -0
- package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +34 -4
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
- package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.ts +937 -0
- package/skills/hmos-incremental-ui-align/scripts/extract_checklist.ts +343 -0
- package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +44 -5
- package/skills/hmos-incremental-ui-align/scripts/page_capture.ts +977 -0
- package/skills/hmos-incremental-ui-align/scripts/page_capture_burst.ts +188 -0
- package/skills/hmos-integration-test/README.md +111 -79
- package/skills/hmos-integration-test/SKILL.md +216 -132
- package/skills/hmos-integration-test/scripts/report-tool.ts +791 -0
- package/skills/hmos-integration-test/scripts/resolve-metadata-tool.ts +125 -0
- package/skills/hmos-integration-test/scripts/self-test-runner.ts +756 -0
- package/skills/hmos-integration-test/scripts/testcases-tool.ts +239 -0
- package/skills/hmos-resources-convert/SKILL.md +334 -66
- package/skills/hmos-resources-convert/references/code-vector-icon-rules.md +335 -0
- package/skills/hmos-resources-convert/references/conversion-rules.md +676 -663
- package/skills/hmos-resources-convert/references/dependency-analysis-rules.md +410 -388
- package/skills/hmos-resources-convert/references/lottie-conversion-rules.md +219 -0
- package/skills/hmos-resources-convert/references/resource-mapping-rules.md +482 -457
- package/skills/hmos-resources-convert/references/xml-drawable-to-svg-rules.md +592 -513
- package/skills/hmos-resources-convert/scripts/a2h_resource_convert.ts +2163 -0
- package/skills/hmos-resources-convert/scripts/code_vector_icons.ts +591 -0
- package/skills/hmos-resources-convert/scripts/svg_fidelity_check.ts +632 -0
- package/skills/hmos-spec-generate/SKILL.md +293 -214
- package/skills/hmos-spec-generate/scripts/parse_requirements.ts +515 -0
- package/skills/hmos-spec-generate/template/REQ.txt +22 -0
- package/skills/hmos-spec-generate/template/REQ.xlsx +0 -0
- package/skills/hmos-test-case-generation/README.md +241 -0
- package/skills/hmos-test-case-generation/SKILL.md +324 -0
- package/skills/hmos-test-case-generation/references/contract.md +315 -0
- package/skills/hmos-test-case-generation/references/review-notes-template.md +84 -0
- package/skills/hmos-test-case-generation/references/ui-elements-schema.md +142 -0
- package/skills/hmos-test-case-generation/tools/convert_to_ui_elements.ts +550 -0
- package/skills/hmos-test-case-generation/tools/validate.ts +1312 -0
- package/tools/bfs-crawl/README.md +73 -0
- package/tools/bfs-crawl/android_viewtree_bfs_crawler.ts +1662 -0
- package/agents/build-fixer.md +0 -385
- package/agents/logic-coder/scripts/platform_context_query.py +0 -568
- package/agents/review-fixer.md +0 -405
- package/agents/spec-generator.md +0 -541
- package/dist/cli/mcp-setup.js +0 -258
- package/dist/cli/mcp.js +0 -94
- package/dist/context/index.js +0 -694
- package/resource/migration_process.svg +0 -94
- package/resource/migration_process_transparent.svg +0 -93
- package/skills/hmos-batch-ui-align/scripts/android_parse_fast.py +0 -1606
- package/skills/hmos-incremental-ui-align/scripts/__pycache__/app_feature_verify.cpython-314.pyc +0 -0
- package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.py +0 -542
- package/skills/hmos-incremental-ui-align/scripts/page_capture.py +0 -597
- package/skills/hmos-resources-convert/evals/evals.json +0 -171
- package/skills/hmos-resources-convert/template/AppScope/app.json5 +0 -10
- package/skills/hmos-resources-convert/template/AppScope/resources/base/element/string.json +0 -8
- package/skills/hmos-resources-convert/template/AppScope/resources/base/media/background.png +0 -0
- package/skills/hmos-resources-convert/template/AppScope/resources/base/media/foreground.png +0 -0
- package/skills/hmos-resources-convert/template/AppScope/resources/base/media/layered_image.json +0 -7
- package/skills/hmos-resources-convert/template/build-profile.json5 +0 -42
- package/skills/hmos-resources-convert/template/code-linter.json5 +0 -32
- package/skills/hmos-resources-convert/template/entry/build-profile.json5 +0 -33
- package/skills/hmos-resources-convert/template/entry/hvigorfile.ts +0 -6
- package/skills/hmos-resources-convert/template/entry/obfuscation-rules.txt +0 -23
- package/skills/hmos-resources-convert/template/entry/oh-package.json5 +0 -10
- package/skills/hmos-resources-convert/template/entry/src/main/ets/entryability/EntryAbility.ets +0 -48
- package/skills/hmos-resources-convert/template/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +0 -16
- package/skills/hmos-resources-convert/template/entry/src/main/ets/pages/Index.ets +0 -23
- package/skills/hmos-resources-convert/template/entry/src/main/module.json5 +0 -55
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/color.json +0 -8
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/float.json +0 -8
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/string.json +0 -16
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/background.png +0 -0
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/foreground.png +0 -0
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/layered_image.json +0 -7
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/startIcon.png +0 -0
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/backup_config.json +0 -3
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/main_pages.json +0 -5
- package/skills/hmos-resources-convert/template/entry/src/main/resources/dark/element/color.json +0 -8
- package/skills/hmos-resources-convert/template/entry/src/mock/mock-config.json5 +0 -2
- package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/Ability.test.ets +0 -35
- package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/List.test.ets +0 -5
- package/skills/hmos-resources-convert/template/entry/src/ohosTest/module.json5 +0 -16
- package/skills/hmos-resources-convert/template/entry/src/test/List.test.ets +0 -5
- package/skills/hmos-resources-convert/template/entry/src/test/LocalUnit.test.ets +0 -33
- package/skills/hmos-resources-convert/template/hvigor/hvigor-config.json5 +0 -23
- package/skills/hmos-resources-convert/template/hvigorfile.ts +0 -6
- package/skills/hmos-resources-convert/template/oh-package-lock.json5 +0 -28
- package/skills/hmos-resources-convert/template/oh-package.json5 +0 -10
- package/skills/hmos-resources-convert/tools/apktool_3.0.1.jar +0 -0
- package/skills/hmos-spec-generate/references/android-platform-tokens.md +0 -105
- package/skills/hmos-spec-generate/references/spec-sample-1.md +0 -78
- package/skills/hmos-spec-generate/references/spec-sample-2.md +0 -58
- package/skills/hmos-spec-generate/references/spec-sample-3.md +0 -116
- package/skills/hmos-spec-generate/references/step4-report-template.md +0 -33
- package/tools/test-tools/autotest/README.md +0 -238
- package/tools/test-tools/autotest/pyproject.toml +0 -26
- package/tools/test-tools/autotest/report_tool.py +0 -759
- package/tools/test-tools/autotest/self_test_runner.py +0 -895
- package/tools/test-tools/autotest/testcases_schema.md +0 -143
- package/tools/test-tools/autotest/testcases_tool.py +0 -215
- package/tools/test-tools/autotest/uv.lock +0 -3156
- package/tools/test-tools/harmony_autotest-0.1.0-py3-none-any.whl +0 -0
- package/tools/test-tools/hypium-6.1.0.210-py3-none-any.whl +0 -0
- package/tools/test-tools/hypium_mcp-0.6.5-py3-none-any.whl +0 -0
- package/tools/test-tools/xdevice-6.1.0.210-py3-none-any.whl +0 -0
- package/tools/test-tools/xdevice_devicetest-6.1.0.210-py3-none-any.whl +0 -0
- package/tools/test-tools/xdevice_ohos-6.1.0.210-py3-none-any.whl +0 -0
|
@@ -1,895 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
自测执行器 - 统一的进程管理和测试执行
|
|
4
|
-
|
|
5
|
-
子命令:
|
|
6
|
-
run - 准备环境后后台启动 AutoTest.batch
|
|
7
|
-
status - 查询后台执行状态(RUNNING/COMPLETED/CRASHED)
|
|
8
|
-
kill - 终止后台进程
|
|
9
|
-
clean - 重置本目录状态(.venv / 残留中间产物 / 残留进程),不动全局 uv 缓存
|
|
10
|
-
|
|
11
|
-
使用示例:
|
|
12
|
-
python self_test_runner.py run --testcases testcases.json --hap app.hap --bundle-name com.xxx
|
|
13
|
-
python self_test_runner.py run --testcases testcases.jsonl --hap app.hap --bundle-name com.xxx
|
|
14
|
-
python self_test_runner.py status --task-dir task
|
|
15
|
-
python self_test_runner.py kill --task-dir task
|
|
16
|
-
python self_test_runner.py clean
|
|
17
|
-
|
|
18
|
-
`--testcases` 同时接受 JSON 数组(旧 `testcases.json`)与 JSONL,JSON 数组会自动转换成 JSONL。
|
|
19
|
-
|
|
20
|
-
执行流程:
|
|
21
|
-
主进程:清理 + 读取/校验 autotest 配置(~/.hometrans/config.json)+ uv sync + hdc install hap(等待完成)
|
|
22
|
-
↓
|
|
23
|
-
后台:python -m AutoTest.batch(循环执行 testcases.jsonl,cwd 为 task_<timestamp> 子目录)
|
|
24
|
-
|
|
25
|
-
依赖:harmony-autotest 与 hypium_mcp 等 6 个 whl 在 pyproject.toml 中声明为本地路径
|
|
26
|
-
依赖(上一级 tools/test-tools/ 目录);`uv sync` 会安装到本目录 .venv 内,不再需要手动 pip install。
|
|
27
|
-
|
|
28
|
-
AutoTest.batch 启动时 cwd 设为 task_<timestamp>,因此 hypium_mcp.log / tmp_hypium/
|
|
29
|
-
等中间产物会落在 task 子目录内,避免污染插件源码目录。
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
import argparse
|
|
33
|
-
import glob
|
|
34
|
-
import hashlib
|
|
35
|
-
import io
|
|
36
|
-
import json
|
|
37
|
-
import logging
|
|
38
|
-
import os
|
|
39
|
-
import shutil
|
|
40
|
-
import subprocess
|
|
41
|
-
import sys
|
|
42
|
-
import time
|
|
43
|
-
import traceback
|
|
44
|
-
from datetime import datetime
|
|
45
|
-
from pathlib import Path
|
|
46
|
-
|
|
47
|
-
SCRIPT_DIR = Path(__file__).resolve().parent
|
|
48
|
-
HAP_INSTALL_WAIT = 10
|
|
49
|
-
INSTALL_TIMEOUT = 120
|
|
50
|
-
UV_TIMEOUT = 600
|
|
51
|
-
API_KEY_PLACEHOLDER = "YOUR_API_KEY_HERE"
|
|
52
|
-
DEFAULT_CATEGORY = "self_test"
|
|
53
|
-
|
|
54
|
-
logger = logging.getLogger("self_test_runner")
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# =============================================================================
|
|
58
|
-
# 公共函数:进程管理
|
|
59
|
-
# =============================================================================
|
|
60
|
-
|
|
61
|
-
def _get_python_processes():
|
|
62
|
-
if sys.platform != "win32":
|
|
63
|
-
return []
|
|
64
|
-
|
|
65
|
-
ps_cmd = (
|
|
66
|
-
'Get-CimInstance Win32_Process -Filter "Name=\'python.exe\'" '
|
|
67
|
-
'| Select-Object ProcessId,CommandLine '
|
|
68
|
-
'| ForEach-Object { "$($_.ProcessId)|$($_.CommandLine)" }'
|
|
69
|
-
)
|
|
70
|
-
try:
|
|
71
|
-
result = subprocess.run(
|
|
72
|
-
["powershell.exe", "-NoProfile", "-Command", ps_cmd],
|
|
73
|
-
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=15,
|
|
74
|
-
)
|
|
75
|
-
except Exception:
|
|
76
|
-
return []
|
|
77
|
-
|
|
78
|
-
if not result.stdout:
|
|
79
|
-
return []
|
|
80
|
-
|
|
81
|
-
processes = []
|
|
82
|
-
for line in result.stdout.splitlines():
|
|
83
|
-
line = line.strip()
|
|
84
|
-
if not line or "|" not in line:
|
|
85
|
-
continue
|
|
86
|
-
pid_str, cmdline = line.split("|", 1)
|
|
87
|
-
try:
|
|
88
|
-
pid = int(pid_str.strip())
|
|
89
|
-
processes.append((pid, cmdline.strip()))
|
|
90
|
-
except ValueError:
|
|
91
|
-
continue
|
|
92
|
-
return processes
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def _get_process_cmdline(pid: int) -> str | None:
|
|
96
|
-
if sys.platform == "win32":
|
|
97
|
-
ps_cmd = f"(Get-CimInstance Win32_Process -Filter \"ProcessId={pid}\").CommandLine"
|
|
98
|
-
try:
|
|
99
|
-
result = subprocess.run(
|
|
100
|
-
["powershell.exe", "-NoProfile", "-Command", ps_cmd],
|
|
101
|
-
capture_output=True, text=True, timeout=10,
|
|
102
|
-
)
|
|
103
|
-
return result.stdout.strip() or None
|
|
104
|
-
except Exception:
|
|
105
|
-
return None
|
|
106
|
-
else:
|
|
107
|
-
try:
|
|
108
|
-
return Path(f"/proc/{pid}/cmdline").read_text().replace("\x00", " ").strip()
|
|
109
|
-
except Exception:
|
|
110
|
-
return None
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def _pid_alive(pid: int) -> bool:
|
|
114
|
-
if sys.platform == "win32":
|
|
115
|
-
import ctypes
|
|
116
|
-
kernel32 = ctypes.windll.kernel32
|
|
117
|
-
SYNCHRONIZE = 0x00100000
|
|
118
|
-
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
|
|
119
|
-
handle = kernel32.OpenProcess(SYNCHRONIZE | PROCESS_QUERY_LIMITED_INFORMATION, False, pid)
|
|
120
|
-
if handle == 0:
|
|
121
|
-
return False
|
|
122
|
-
ret = kernel32.WaitForSingleObject(handle, 0)
|
|
123
|
-
kernel32.CloseHandle(handle)
|
|
124
|
-
return ret == 0x00000102 # WAIT_TIMEOUT
|
|
125
|
-
else:
|
|
126
|
-
try:
|
|
127
|
-
os.kill(pid, 0)
|
|
128
|
-
return True
|
|
129
|
-
except ProcessLookupError:
|
|
130
|
-
return False
|
|
131
|
-
except PermissionError:
|
|
132
|
-
return True
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
def _kill_process_tree(pid: int):
|
|
136
|
-
if sys.platform == "win32":
|
|
137
|
-
subprocess.run(["taskkill", "/F", "/T", "/PID", str(pid)], capture_output=True, timeout=10)
|
|
138
|
-
else:
|
|
139
|
-
try:
|
|
140
|
-
os.killpg(os.getpgid(pid), 9)
|
|
141
|
-
except Exception:
|
|
142
|
-
os.kill(pid, 9)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
# =============================================================================
|
|
146
|
-
# 公共函数:清理
|
|
147
|
-
# =============================================================================
|
|
148
|
-
|
|
149
|
-
def _pyproject_sha256() -> str:
|
|
150
|
-
"""Hash the active pyproject.toml so we can detect dep changes."""
|
|
151
|
-
return hashlib.sha256((SCRIPT_DIR / "pyproject.toml").read_bytes()).hexdigest()
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def _venv_is_fresh() -> bool:
|
|
155
|
-
"""venv exists AND was built against the current pyproject.toml content."""
|
|
156
|
-
venv = SCRIPT_DIR / ".venv"
|
|
157
|
-
marker = venv / ".pyproject.sha256"
|
|
158
|
-
if not (venv / "pyvenv.cfg").exists() or not marker.exists():
|
|
159
|
-
return False
|
|
160
|
-
try:
|
|
161
|
-
return marker.read_text(encoding="utf-8").strip() == _pyproject_sha256()
|
|
162
|
-
except OSError:
|
|
163
|
-
return False
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
def _stamp_venv() -> None:
|
|
167
|
-
"""Record pyproject hash inside the venv so next run can short-circuit."""
|
|
168
|
-
marker = SCRIPT_DIR / ".venv" / ".pyproject.sha256"
|
|
169
|
-
if marker.parent.exists():
|
|
170
|
-
try:
|
|
171
|
-
marker.write_text(_pyproject_sha256(), encoding="utf-8")
|
|
172
|
-
except OSError as e:
|
|
173
|
-
logger.warning(f"无法写入 venv 标记 {marker}: {e}")
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
def cleanup_before_run(force_reinit: bool = False):
|
|
177
|
-
_kill_stale_processes()
|
|
178
|
-
# 兼容旧版:把之前留在 tools/autotest/ 顶层的 tmp_hypium / hypium_mcp.log
|
|
179
|
-
# 等清掉。新流程下 batch 会在 task_<ts> 目录里生成它们,不会再到这里。
|
|
180
|
-
_clean_stale_artifacts(SCRIPT_DIR)
|
|
181
|
-
if force_reinit:
|
|
182
|
-
logger.info("--force-reinit 指定,强制清理 venv")
|
|
183
|
-
_clean_venv()
|
|
184
|
-
elif _venv_is_fresh():
|
|
185
|
-
logger.info("venv 已就绪(pyproject.toml hash 未变),跳过 venv 清理")
|
|
186
|
-
else:
|
|
187
|
-
logger.info("venv 不存在或 pyproject.toml 已变更,重建 venv")
|
|
188
|
-
_clean_venv()
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
def _kill_stale_processes():
|
|
192
|
-
if sys.platform != "win32":
|
|
193
|
-
return
|
|
194
|
-
|
|
195
|
-
my_pid = os.getpid()
|
|
196
|
-
# 包含 AutoTest.batch 本体 + hypium_mcp(uvicorn 子进程)+ harmony_autotest 模块入口,
|
|
197
|
-
# 三类都可能在中断后变成孤儿。
|
|
198
|
-
markers = [
|
|
199
|
-
"AutoTest.batch",
|
|
200
|
-
"-m AutoTest ",
|
|
201
|
-
"hypium_mcp",
|
|
202
|
-
"harmony_autotest",
|
|
203
|
-
"harmony-autotest",
|
|
204
|
-
]
|
|
205
|
-
|
|
206
|
-
logger.info("=== 清理残留进程 ===")
|
|
207
|
-
|
|
208
|
-
processes = _get_python_processes()
|
|
209
|
-
stale = [(pid, cmd) for pid, cmd in processes if pid != my_pid and any(m in cmd for m in markers)]
|
|
210
|
-
|
|
211
|
-
if not stale:
|
|
212
|
-
logger.info("无残留进程")
|
|
213
|
-
return
|
|
214
|
-
|
|
215
|
-
for pid, cmd in stale:
|
|
216
|
-
logger.warning(f"杀掉残留进程 PID={pid}: {cmd[:80]}...")
|
|
217
|
-
try:
|
|
218
|
-
_kill_process_tree(pid)
|
|
219
|
-
except Exception as e:
|
|
220
|
-
logger.warning(f"杀进程失败 PID={pid}: {e}")
|
|
221
|
-
time.sleep(2)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
_STALE_ARTIFACT_NAMES = (
|
|
225
|
-
"tmp_hypium",
|
|
226
|
-
"hypium_mcp.log",
|
|
227
|
-
"batch.pid",
|
|
228
|
-
"batch_stdout.log",
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
def _clean_stale_artifacts(base_dir: Path):
|
|
233
|
-
"""删除 batch 跑完留下的本地中间产物(在 base_dir 顶层查找)。"""
|
|
234
|
-
for name in _STALE_ARTIFACT_NAMES:
|
|
235
|
-
p = base_dir / name
|
|
236
|
-
if not p.exists():
|
|
237
|
-
continue
|
|
238
|
-
try:
|
|
239
|
-
if p.is_dir():
|
|
240
|
-
shutil.rmtree(p, ignore_errors=True)
|
|
241
|
-
else:
|
|
242
|
-
p.unlink()
|
|
243
|
-
logger.info(f"删除残留: {p}")
|
|
244
|
-
except OSError as e:
|
|
245
|
-
logger.warning(f"无法删除 {p}: {e}")
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
def _clean_venv():
|
|
249
|
-
venv_path = SCRIPT_DIR / ".venv"
|
|
250
|
-
|
|
251
|
-
logger.info("=== 清理虚拟环境 ===")
|
|
252
|
-
if venv_path.exists():
|
|
253
|
-
logger.info(f"删除: {venv_path}")
|
|
254
|
-
try:
|
|
255
|
-
shutil.rmtree(venv_path, ignore_errors=True)
|
|
256
|
-
except OSError as e:
|
|
257
|
-
logger.warning(f"无法删除 {venv_path}: {e}")
|
|
258
|
-
|
|
259
|
-
for pycache in SCRIPT_DIR.rglob("__pycache__"):
|
|
260
|
-
if pycache.is_dir():
|
|
261
|
-
try:
|
|
262
|
-
shutil.rmtree(pycache, ignore_errors=True)
|
|
263
|
-
except Exception:
|
|
264
|
-
pass
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
# =============================================================================
|
|
268
|
-
# run 子命令
|
|
269
|
-
# =============================================================================
|
|
270
|
-
|
|
271
|
-
def setup_logging(output_dir: str):
|
|
272
|
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
273
|
-
log_path = Path(output_dir) / f"self_test_{timestamp}.log"
|
|
274
|
-
log_path.parent.mkdir(parents=True, exist_ok=True)
|
|
275
|
-
fmt = logging.Formatter("[%(asctime)s] %(levelname)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
|
|
276
|
-
fh = logging.FileHandler(str(log_path), mode="w", encoding="utf-8")
|
|
277
|
-
fh.setFormatter(fmt)
|
|
278
|
-
sh = logging.StreamHandler(
|
|
279
|
-
io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
|
|
280
|
-
if hasattr(sys.stdout, "buffer") else sys.stdout
|
|
281
|
-
)
|
|
282
|
-
sh.setFormatter(fmt)
|
|
283
|
-
logger.addHandler(fh)
|
|
284
|
-
logger.addHandler(sh)
|
|
285
|
-
logger.setLevel(logging.DEBUG)
|
|
286
|
-
logger.info(f"日志文件: {log_path}")
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
def run_cmd(cmd, *, check=True, timeout=None, **kwargs):
|
|
290
|
-
cmd_str = cmd if isinstance(cmd, str) else " ".join(str(c) for c in cmd)
|
|
291
|
-
logger.info(f">>> {cmd_str}")
|
|
292
|
-
try:
|
|
293
|
-
result = subprocess.run(cmd, timeout=timeout, **kwargs)
|
|
294
|
-
except subprocess.TimeoutExpired:
|
|
295
|
-
logger.error(f"命令超时 ({timeout}s): {cmd_str}")
|
|
296
|
-
raise
|
|
297
|
-
except Exception:
|
|
298
|
-
logger.error(f"命令异常:\n{traceback.format_exc()}")
|
|
299
|
-
raise
|
|
300
|
-
if result.returncode != 0:
|
|
301
|
-
logger.warning(f"退出码={result.returncode}: {cmd_str}")
|
|
302
|
-
if hasattr(result, "stdout") and result.stdout:
|
|
303
|
-
logger.warning(f" stdout: {result.stdout.strip() if isinstance(result.stdout, str) else result.stdout}")
|
|
304
|
-
if hasattr(result, "stderr") and result.stderr:
|
|
305
|
-
logger.warning(f" stderr: {result.stderr.strip() if isinstance(result.stderr, str) else result.stderr}")
|
|
306
|
-
if check:
|
|
307
|
-
sys.exit(result.returncode)
|
|
308
|
-
else:
|
|
309
|
-
logger.debug(f"成功 (rc=0): {cmd_str}")
|
|
310
|
-
return result
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
def get_hdc():
|
|
314
|
-
hdc = shutil.which("hdc") or shutil.which("hdc.exe")
|
|
315
|
-
if not hdc:
|
|
316
|
-
logger.error("hdc 未找到")
|
|
317
|
-
sys.exit(1)
|
|
318
|
-
return hdc
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
def get_uv():
|
|
322
|
-
"""查找 uv 可执行文件。优先使用 UV_BIN 环境变量,否则在 PATH 中搜索。"""
|
|
323
|
-
uv = os.environ.get("UV_BIN") or shutil.which("uv") or shutil.which("uv.exe")
|
|
324
|
-
if not uv or not Path(uv).exists():
|
|
325
|
-
logger.error(
|
|
326
|
-
"uv 未找到。请确认:\n"
|
|
327
|
-
" 1) uv 已安装且其所在目录在当前 shell 的 PATH 中(PowerShell 中可用 `where.exe uv` 验证)\n"
|
|
328
|
-
" 2) 或显式设置环境变量 UV_BIN 指向 uv 可执行文件的绝对路径"
|
|
329
|
-
)
|
|
330
|
-
sys.exit(1)
|
|
331
|
-
logger.info(f"uv: {uv}")
|
|
332
|
-
return uv
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
def _uv_env():
|
|
336
|
-
# Isolate inner uv calls (`uv sync`, `uv run --project`) from the outer
|
|
337
|
-
# `uv run --no-project` context that launches this script: drop the
|
|
338
|
-
# recursion marker and any inherited VIRTUAL_ENV so the inner uv always
|
|
339
|
-
# targets SCRIPT_DIR/.venv, never the launcher's ephemeral environment.
|
|
340
|
-
env = os.environ.copy()
|
|
341
|
-
env["UV_NO_PROGRESS"] = "1"
|
|
342
|
-
env["RUST_LOG"] = "off"
|
|
343
|
-
env.pop("UV_RUN_RECURSION_DEPTH", None)
|
|
344
|
-
env.pop("VIRTUAL_ENV", None)
|
|
345
|
-
return env
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
def _prepare_testcases_jsonl(input_path: Path, task_subdir: Path) -> Path:
|
|
349
|
-
"""将 `--testcases` 入参规范化为 JSONL 路径。
|
|
350
|
-
|
|
351
|
-
- 若 input 是 JSON 数组(旧 `testcases.json` 格式),转成 JSONL
|
|
352
|
-
落到 `task_subdir/testcases.jsonl`,缺失字段按需补:
|
|
353
|
-
* `uuid` 用 case_name md5 前 8 位(缺 case_name 时用 idx)
|
|
354
|
-
* `spec` 补空字符串
|
|
355
|
-
其它字段原样保留。
|
|
356
|
-
- 若 input 已是 JSONL(每行一个 JSON 对象),原路径透传。
|
|
357
|
-
|
|
358
|
-
检测策略:剥掉 BOM/前导空白后看首字符是否为 `[`。
|
|
359
|
-
"""
|
|
360
|
-
if not input_path.exists():
|
|
361
|
-
logger.error(f"测试用例文件不存在: {input_path}")
|
|
362
|
-
sys.exit(1)
|
|
363
|
-
|
|
364
|
-
text = input_path.read_text(encoding="utf-8-sig")
|
|
365
|
-
stripped = text.lstrip()
|
|
366
|
-
if not stripped:
|
|
367
|
-
logger.error(f"测试用例文件为空: {input_path}")
|
|
368
|
-
sys.exit(1)
|
|
369
|
-
|
|
370
|
-
if stripped[0] == "[":
|
|
371
|
-
try:
|
|
372
|
-
arr = json.loads(text)
|
|
373
|
-
except json.JSONDecodeError as e:
|
|
374
|
-
logger.error(f"测试用例 JSON 数组解析失败 {input_path}: {e}")
|
|
375
|
-
sys.exit(1)
|
|
376
|
-
if not isinstance(arr, list):
|
|
377
|
-
logger.error(f"测试用例文件根不是数组: {input_path}")
|
|
378
|
-
sys.exit(1)
|
|
379
|
-
|
|
380
|
-
out_path = task_subdir / "testcases.jsonl"
|
|
381
|
-
with out_path.open("w", encoding="utf-8") as f:
|
|
382
|
-
for idx, case in enumerate(arr, 1):
|
|
383
|
-
if not isinstance(case, dict):
|
|
384
|
-
logger.error(f"用例 #{idx} 不是 JSON 对象: {case!r}")
|
|
385
|
-
sys.exit(1)
|
|
386
|
-
if not case.get("uuid"):
|
|
387
|
-
seed = case.get("case_name") or f"case_{idx}"
|
|
388
|
-
case["uuid"] = hashlib.md5(seed.encode("utf-8")).hexdigest()[:8]
|
|
389
|
-
if "spec" not in case:
|
|
390
|
-
case["spec"] = ""
|
|
391
|
-
f.write(json.dumps(case, ensure_ascii=False) + "\n")
|
|
392
|
-
logger.info(f"已将 JSON 数组转换为 JSONL: {out_path}({len(arr)} 条用例)")
|
|
393
|
-
return out_path
|
|
394
|
-
|
|
395
|
-
# 视作 JSONL,逐行校验
|
|
396
|
-
lines = [l for l in text.splitlines() if l.strip()]
|
|
397
|
-
for i, line in enumerate(lines, 1):
|
|
398
|
-
try:
|
|
399
|
-
json.loads(line)
|
|
400
|
-
except json.JSONDecodeError as e:
|
|
401
|
-
logger.error(f"JSONL 第 {i} 行解析失败 {input_path}: {e}")
|
|
402
|
-
sys.exit(1)
|
|
403
|
-
logger.info(f"测试用例文件已为 JSONL,原样透传: {input_path}({len(lines)} 条用例)")
|
|
404
|
-
return input_path
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
_MODEL_KEYS = ("unified_model", "execute_model", "decision_model")
|
|
408
|
-
DEFAULT_AGENT_MODE = "single"
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
def _find_hometrans_config(explicit: str | None) -> Path:
|
|
412
|
-
"""定位 HomeTrans 全局配置 `~/.hometrans/config.json`(含 `autotest` 字段)。
|
|
413
|
-
|
|
414
|
-
优先级:显式 --config > 环境变量 HOMETRANS_CONFIG > 由 HOMETRANS_TOOL_PATH
|
|
415
|
-
反推(tools 目录的父目录)> 默认 ~/.hometrans/config.json。
|
|
416
|
-
"""
|
|
417
|
-
if explicit:
|
|
418
|
-
return Path(explicit).resolve()
|
|
419
|
-
env_cfg = os.environ.get("HOMETRANS_CONFIG")
|
|
420
|
-
if env_cfg:
|
|
421
|
-
return Path(env_cfg).resolve()
|
|
422
|
-
tool_path = os.environ.get("HOMETRANS_TOOL_PATH")
|
|
423
|
-
if tool_path:
|
|
424
|
-
cand = Path(tool_path).resolve().parent / "config.json"
|
|
425
|
-
if cand.exists():
|
|
426
|
-
return cand
|
|
427
|
-
return Path.home() / ".hometrans" / "config.json"
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
def _model_dicts(autotest: dict):
|
|
431
|
-
"""遍历 autotest 里存在的模型端点(单层 unified_model / 双层 execute+decision)。"""
|
|
432
|
-
for key in _MODEL_KEYS:
|
|
433
|
-
model = autotest.get(key)
|
|
434
|
-
if isinstance(model, dict):
|
|
435
|
-
yield key, model
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
def load_autotest_config(explicit: str | None) -> dict:
|
|
439
|
-
"""从 `~/.hometrans/config.json` 读取 `autotest` 配置并校验。
|
|
440
|
-
|
|
441
|
-
- 缺文件 / 缺 `autotest` 字段 → 报错退出,提示运行 `ht init`。
|
|
442
|
-
- 模型字段优先用 OS 环境变量 HOMETRANS_MODEL_* 覆盖 config.json
|
|
443
|
-
(api_key 兼容老版本 TEST_API_KEY 作兜底)。
|
|
444
|
-
- 覆盖后仍有未填的 api_key → 报错退出。
|
|
445
|
-
- 缺 `agent_mode` 时默认补 "single"。
|
|
446
|
-
返回可直接物化成 YAML 的 dict。
|
|
447
|
-
"""
|
|
448
|
-
config_path = _find_hometrans_config(explicit)
|
|
449
|
-
if not config_path.exists():
|
|
450
|
-
logger.error(
|
|
451
|
-
f"未找到 HomeTrans 配置文件: {config_path}\n"
|
|
452
|
-
f"请先运行 `ht init` 生成 ~/.hometrans/config.json(其中包含 autotest 配置)。"
|
|
453
|
-
)
|
|
454
|
-
sys.exit(1)
|
|
455
|
-
|
|
456
|
-
try:
|
|
457
|
-
data = json.loads(config_path.read_text(encoding="utf-8"))
|
|
458
|
-
except (OSError, json.JSONDecodeError) as e:
|
|
459
|
-
logger.error(f"无法解析配置文件 {config_path}: {e}")
|
|
460
|
-
sys.exit(1)
|
|
461
|
-
|
|
462
|
-
autotest = data.get("autotest") if isinstance(data, dict) else None
|
|
463
|
-
if not isinstance(autotest, dict):
|
|
464
|
-
logger.error(
|
|
465
|
-
f"配置文件 {config_path} 缺少 `autotest` 配置。请运行 `ht init` 重新生成。"
|
|
466
|
-
)
|
|
467
|
-
sys.exit(1)
|
|
468
|
-
|
|
469
|
-
# 深拷贝,避免改动原始 dict(虽然这里只读不写回)
|
|
470
|
-
autotest = json.loads(json.dumps(autotest))
|
|
471
|
-
|
|
472
|
-
# 统一配置链路「环境变量 → config.json → 报错」:UI 对齐与自测共用同一个多模态
|
|
473
|
-
# 模型,由 `ht init` 导出为 HOMETRANS_MODEL_*。环境变量优先级最高——存在即覆盖
|
|
474
|
-
# config.json 里 unified_model 的对应字段;缺失时才用 config.json 的值。
|
|
475
|
-
# provider 不导出为环境变量(默认 openai),始终取 config.json 的值。
|
|
476
|
-
env_model = {
|
|
477
|
-
"api_key": (
|
|
478
|
-
os.environ.get("HOMETRANS_MODEL_API_KEY", "").strip()
|
|
479
|
-
or os.environ.get("TEST_API_KEY", "").strip() # 兼容老版本
|
|
480
|
-
),
|
|
481
|
-
"name": os.environ.get("HOMETRANS_MODEL_NAME", "").strip(),
|
|
482
|
-
"base_url": os.environ.get("HOMETRANS_MODEL_BASE_URL", "").strip(),
|
|
483
|
-
}
|
|
484
|
-
um = autotest.get("unified_model")
|
|
485
|
-
if isinstance(um, dict):
|
|
486
|
-
for field in ("api_key", "name", "base_url"):
|
|
487
|
-
if env_model[field]:
|
|
488
|
-
um[field] = env_model[field]
|
|
489
|
-
# api_key 为各端点共用:环境变量存在时一并覆盖 execute/decision 双层模式的端点。
|
|
490
|
-
if env_model["api_key"]:
|
|
491
|
-
for _name, model in _model_dicts(autotest):
|
|
492
|
-
model["api_key"] = env_model["api_key"]
|
|
493
|
-
|
|
494
|
-
# 覆盖后仍为占位符/空的 api_key → 收集后报错(链路最后一层:提示用户配置)。
|
|
495
|
-
missing = []
|
|
496
|
-
for name, model in _model_dicts(autotest):
|
|
497
|
-
cur = str(model.get("api_key", "")).strip()
|
|
498
|
-
if not cur or cur == API_KEY_PLACEHOLDER:
|
|
499
|
-
missing.append(f"{name}.api_key")
|
|
500
|
-
|
|
501
|
-
if not list(_model_dicts(autotest)):
|
|
502
|
-
logger.error(
|
|
503
|
-
f"配置文件 {config_path} 的 autotest 未定义任何模型端点"
|
|
504
|
-
f"(unified_model / execute_model / decision_model)。"
|
|
505
|
-
)
|
|
506
|
-
sys.exit(1)
|
|
507
|
-
|
|
508
|
-
if missing:
|
|
509
|
-
logger.error(
|
|
510
|
-
f"autotest 配置中以下 api_key 仍为占位符/空:{', '.join(missing)}。\n"
|
|
511
|
-
f"请在 {config_path} 的 autotest 配置里填入真实 api_key,"
|
|
512
|
-
f"或设置 OS 环境变量 HOMETRANS_MODEL_API_KEY 后重试(可运行 `ht init` 一并配置)。"
|
|
513
|
-
)
|
|
514
|
-
sys.exit(1)
|
|
515
|
-
|
|
516
|
-
autotest.setdefault("agent_mode", DEFAULT_AGENT_MODE)
|
|
517
|
-
logger.info(
|
|
518
|
-
f"已从 {config_path} 读取 autotest 配置(agent_mode={autotest.get('agent_mode')})"
|
|
519
|
-
)
|
|
520
|
-
return autotest
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
def materialize_config(autotest: dict, dest: Path) -> Path:
|
|
524
|
-
"""把 autotest dict 物化成 YAML 文件交给 `AutoTest.batch --config`。
|
|
525
|
-
|
|
526
|
-
优先用 PyYAML 输出标准块状 YAML;系统 Python 没装 PyYAML 时退回写 JSON
|
|
527
|
-
内容(JSON 是合法的 YAML,AutoTest 的 yaml.safe_load 同样可解析)。
|
|
528
|
-
"""
|
|
529
|
-
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
530
|
-
try:
|
|
531
|
-
import yaml # type: ignore
|
|
532
|
-
|
|
533
|
-
text = yaml.safe_dump(autotest, allow_unicode=True, sort_keys=False)
|
|
534
|
-
except Exception:
|
|
535
|
-
text = json.dumps(autotest, ensure_ascii=False, indent=2)
|
|
536
|
-
dest.write_text(text, encoding="utf-8")
|
|
537
|
-
return dest
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
def cmd_run(args):
|
|
541
|
-
"""run 子命令:准备环境 + 后台执行 AutoTest.batch"""
|
|
542
|
-
task_dir = Path(args.task_dir).resolve()
|
|
543
|
-
task_dir.mkdir(parents=True, exist_ok=True)
|
|
544
|
-
output_dir = Path(args.output_dir).resolve() if args.output_dir else task_dir
|
|
545
|
-
output_dir.mkdir(parents=True, exist_ok=True)
|
|
546
|
-
|
|
547
|
-
setup_logging(str(output_dir))
|
|
548
|
-
logger.info(f"Python: {sys.executable}")
|
|
549
|
-
logger.info(
|
|
550
|
-
f"参数: testcases={args.testcases}, hap={args.hap}, bundle={args.bundle_name}, "
|
|
551
|
-
f"task_dir={task_dir}, category={args.category}, config={args.config}"
|
|
552
|
-
)
|
|
553
|
-
logger.info(
|
|
554
|
-
"前置用例(若有)已并入 testcases,以 case_name 前缀 `[PRE]` 标识;"
|
|
555
|
-
"self_test_runner 不再单独处理 pre-case。"
|
|
556
|
-
)
|
|
557
|
-
|
|
558
|
-
target_venv = (SCRIPT_DIR / ".venv").resolve()
|
|
559
|
-
try:
|
|
560
|
-
Path(sys.executable).resolve().relative_to(target_venv)
|
|
561
|
-
msg = (
|
|
562
|
-
f"Refusing to run: this script is executing inside {target_venv}, "
|
|
563
|
-
f"which it is about to delete and recreate (Windows file locks will leave "
|
|
564
|
-
f"the venv in a broken state). Invoke it so the interpreter stays OUT of "
|
|
565
|
-
f"that venv, e.g. `uv run --no-project python self_test_runner.py run ...` "
|
|
566
|
-
f"(NOT plain `uv run python ...`, which would execute inside the project venv)."
|
|
567
|
-
)
|
|
568
|
-
logger.error(msg)
|
|
569
|
-
print(json.dumps({"status": "ERROR", "reason": msg}))
|
|
570
|
-
sys.exit(2)
|
|
571
|
-
except ValueError:
|
|
572
|
-
pass
|
|
573
|
-
|
|
574
|
-
# 创建本次任务专属子目录 task_<timestamp>,供 status 子命令通过 glob 找到
|
|
575
|
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
576
|
-
task_subdir = task_dir / f"task_{timestamp}"
|
|
577
|
-
task_subdir.mkdir(parents=True, exist_ok=True)
|
|
578
|
-
|
|
579
|
-
pid_file = task_dir / "batch.pid"
|
|
580
|
-
stdout_log = task_dir / "batch_stdout.log"
|
|
581
|
-
|
|
582
|
-
# 杀掉上次残留进程
|
|
583
|
-
if pid_file.exists():
|
|
584
|
-
try:
|
|
585
|
-
old_pid = int(pid_file.read_text().strip())
|
|
586
|
-
if _pid_alive(old_pid):
|
|
587
|
-
cmdline = _get_process_cmdline(old_pid)
|
|
588
|
-
if cmdline and "AutoTest.batch" in cmdline:
|
|
589
|
-
logger.warning(f"杀掉上次残留进程 PID={old_pid}")
|
|
590
|
-
_kill_process_tree(old_pid)
|
|
591
|
-
time.sleep(2)
|
|
592
|
-
except (ValueError, OSError):
|
|
593
|
-
pass
|
|
594
|
-
|
|
595
|
-
try:
|
|
596
|
-
# 在删 venv / 跑 uv 之前先校验 uv 与 autotest 配置,避免清理后才发现缺东西
|
|
597
|
-
uv = get_uv()
|
|
598
|
-
|
|
599
|
-
# 从 ~/.hometrans/config.json 读取 autotest 配置,物化成本次任务专属的 YAML
|
|
600
|
-
autotest_cfg = load_autotest_config(args.config)
|
|
601
|
-
config_path = materialize_config(autotest_cfg, task_subdir / "autotest_config.yaml")
|
|
602
|
-
logger.info(f"配置文件(由 config.json 的 autotest 字段生成): {config_path}")
|
|
603
|
-
|
|
604
|
-
cleanup_before_run(force_reinit=args.force_reinit)
|
|
605
|
-
|
|
606
|
-
logger.info("=== Step 1: uv sync(确保 harmony-autotest + 传递依赖已安装) ===")
|
|
607
|
-
run_cmd([uv, "sync"], cwd=str(SCRIPT_DIR), capture_output=True, text=True,
|
|
608
|
-
encoding="utf-8", timeout=UV_TIMEOUT, env=_uv_env())
|
|
609
|
-
_stamp_venv()
|
|
610
|
-
|
|
611
|
-
hdc = get_hdc()
|
|
612
|
-
|
|
613
|
-
logger.info(f"=== Step 2a: uninstall {args.bundle_name} ===")
|
|
614
|
-
run_cmd([hdc, "uninstall", args.bundle_name], capture_output=True, text=True,
|
|
615
|
-
encoding="utf-8", timeout=INSTALL_TIMEOUT, check=False)
|
|
616
|
-
|
|
617
|
-
logger.info(f"=== Step 2b: install {args.hap} ===")
|
|
618
|
-
hap = Path(args.hap)
|
|
619
|
-
if not hap.exists():
|
|
620
|
-
logger.error(f"hap 不存在: {args.hap}")
|
|
621
|
-
sys.exit(1)
|
|
622
|
-
result = run_cmd([hdc, "install", "-r", str(hap)], capture_output=True, text=True,
|
|
623
|
-
encoding="utf-8", timeout=INSTALL_TIMEOUT, check=False)
|
|
624
|
-
if result.returncode == 0 or "successfully" in (result.stdout or ""):
|
|
625
|
-
logger.info("安装成功")
|
|
626
|
-
time.sleep(HAP_INSTALL_WAIT)
|
|
627
|
-
else:
|
|
628
|
-
logger.error(f"安装失败: {result.stdout}")
|
|
629
|
-
sys.exit(1)
|
|
630
|
-
|
|
631
|
-
# 测试用例规范化:旧 JSON 数组 → JSONL;本身就是 JSONL 透传
|
|
632
|
-
# 前置用例(若有)已经是 testcases 的第一条,case_name 以 [PRE] 开头
|
|
633
|
-
testcases_jsonl = _prepare_testcases_jsonl(
|
|
634
|
-
Path(args.testcases).resolve(), task_subdir,
|
|
635
|
-
)
|
|
636
|
-
|
|
637
|
-
# 构建 AutoTest.batch 命令
|
|
638
|
-
# `--project SCRIPT_DIR` 让 uv 在任意 cwd 下都能找到正确的 venv;
|
|
639
|
-
# 而 cwd 设为 task_subdir,hypium_mcp.log / tmp_hypium/ 等中间产物随之落在 task 子目录。
|
|
640
|
-
cmd = [
|
|
641
|
-
uv, "run", "--project", str(SCRIPT_DIR), "python", "-m", "AutoTest.batch",
|
|
642
|
-
"--task-dir", str(task_subdir),
|
|
643
|
-
"--testcases", str(testcases_jsonl),
|
|
644
|
-
"--category", args.category,
|
|
645
|
-
"--work-dir", str(SCRIPT_DIR),
|
|
646
|
-
"--config", str(config_path),
|
|
647
|
-
]
|
|
648
|
-
|
|
649
|
-
# 后台启动 AutoTest.batch
|
|
650
|
-
logger.info("=== Step 3: 后台启动 AutoTest.batch ===")
|
|
651
|
-
# _uv_env() so the detached `uv run --project` also stays isolated from
|
|
652
|
-
# the outer `uv run --no-project` launcher context.
|
|
653
|
-
batch_env = _uv_env()
|
|
654
|
-
batch_env["PYTHONIOENCODING"] = "utf-8"
|
|
655
|
-
batch_env["PYTHONUTF8"] = "1"
|
|
656
|
-
batch_env["PYTHONUNBUFFERED"] = "1"
|
|
657
|
-
|
|
658
|
-
log_fh = open(stdout_log, "w", encoding="utf-8")
|
|
659
|
-
popen_kwargs = dict(
|
|
660
|
-
stdin=subprocess.DEVNULL,
|
|
661
|
-
stdout=log_fh,
|
|
662
|
-
stderr=subprocess.STDOUT,
|
|
663
|
-
env=batch_env,
|
|
664
|
-
)
|
|
665
|
-
if sys.platform == "win32":
|
|
666
|
-
# CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP — survive parent shell exit
|
|
667
|
-
popen_kwargs["creationflags"] = 0x00000010 | 0x00000200
|
|
668
|
-
else:
|
|
669
|
-
popen_kwargs["start_new_session"] = True
|
|
670
|
-
|
|
671
|
-
proc = subprocess.Popen(cmd, cwd=str(task_subdir), **popen_kwargs)
|
|
672
|
-
pid_file.write_text(str(proc.pid), encoding="utf-8")
|
|
673
|
-
|
|
674
|
-
logger.info(f"后台进程 PID={proc.pid}")
|
|
675
|
-
print(json.dumps({
|
|
676
|
-
"status": "RUNNING",
|
|
677
|
-
"pid": proc.pid,
|
|
678
|
-
"pid_file": str(pid_file),
|
|
679
|
-
"stdout_log": str(stdout_log),
|
|
680
|
-
"task_dir": str(task_dir),
|
|
681
|
-
"task_subdir": str(task_subdir),
|
|
682
|
-
}))
|
|
683
|
-
|
|
684
|
-
except SystemExit:
|
|
685
|
-
raise
|
|
686
|
-
except Exception:
|
|
687
|
-
logger.error(f"异常:\n{traceback.format_exc()}")
|
|
688
|
-
sys.exit(1)
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
# =============================================================================
|
|
692
|
-
# status 子命令
|
|
693
|
-
# =============================================================================
|
|
694
|
-
|
|
695
|
-
def _find_task_subdir(task_dir: Path) -> Path | None:
|
|
696
|
-
candidates = sorted(task_dir.glob("task_*"), key=lambda p: p.name, reverse=True)
|
|
697
|
-
return candidates[0] if candidates else None
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
def _find_latest_log(output_dir: Path) -> Path | None:
|
|
701
|
-
candidates = sorted(output_dir.glob("self_test_*.log"), key=lambda p: p.name, reverse=True)
|
|
702
|
-
candidates += sorted(output_dir.glob("batch_stdout.log"), key=lambda p: p.name, reverse=True)
|
|
703
|
-
return candidates[0] if candidates else None
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
def _log_status(task_dir: Path, result: dict):
|
|
707
|
-
log_file = task_dir / "status_history.log"
|
|
708
|
-
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
709
|
-
log_file.parent.mkdir(parents=True, exist_ok=True)
|
|
710
|
-
existing = log_file.read_text(encoding="utf-8") if log_file.exists() else ""
|
|
711
|
-
log_file.write_text(existing + f"[{timestamp}] {json.dumps(result, ensure_ascii=False)}\n", encoding="utf-8")
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
def cmd_status(args):
|
|
715
|
-
"""status 子命令:查询 AutoTest.batch 执行状态"""
|
|
716
|
-
task_dir = Path(args.task_dir)
|
|
717
|
-
output_dir = Path(args.output_dir) if args.output_dir else task_dir
|
|
718
|
-
|
|
719
|
-
pid_file = task_dir / "batch.pid"
|
|
720
|
-
if not pid_file.exists():
|
|
721
|
-
print(json.dumps({"status": "NOT_STARTED"}))
|
|
722
|
-
sys.exit(4)
|
|
723
|
-
|
|
724
|
-
pid = int(pid_file.read_text().strip())
|
|
725
|
-
alive = _pid_alive(pid)
|
|
726
|
-
|
|
727
|
-
task_subdir = _find_task_subdir(task_dir)
|
|
728
|
-
jsonl_file = task_subdir / "task_results.jsonl" if task_subdir else None
|
|
729
|
-
|
|
730
|
-
cases_done = 0
|
|
731
|
-
last_case = ""
|
|
732
|
-
if jsonl_file and jsonl_file.exists():
|
|
733
|
-
lines = jsonl_file.read_text(encoding="utf-8").strip().splitlines()
|
|
734
|
-
cases_done = len(lines)
|
|
735
|
-
if lines:
|
|
736
|
-
last_case = json.loads(lines[-1]).get("case_name", "")
|
|
737
|
-
|
|
738
|
-
summary_file = task_subdir / "summary.json" if task_subdir else None
|
|
739
|
-
has_summary = summary_file and summary_file.exists()
|
|
740
|
-
|
|
741
|
-
log_tail = ""
|
|
742
|
-
log_file = _find_latest_log(output_dir)
|
|
743
|
-
if log_file and log_file.exists():
|
|
744
|
-
log_tail = "\n".join(log_file.read_text(encoding="utf-8").strip().splitlines()[-5:])
|
|
745
|
-
|
|
746
|
-
if has_summary:
|
|
747
|
-
summary = json.loads(summary_file.read_text(encoding="utf-8"))
|
|
748
|
-
result = {
|
|
749
|
-
"status": "COMPLETED",
|
|
750
|
-
"pid": pid,
|
|
751
|
-
"task_subdir": str(task_subdir),
|
|
752
|
-
"cases_done": summary.get("total_cases", cases_done),
|
|
753
|
-
"pass_count": summary.get("pass_count", summary.get("success_count", 0)),
|
|
754
|
-
"fail_count": summary.get("fail_count", 0),
|
|
755
|
-
"unknown_count": summary.get("unknown_count", 0),
|
|
756
|
-
"pass_rate": summary.get("pass_rate", 0),
|
|
757
|
-
"log_tail": log_tail,
|
|
758
|
-
}
|
|
759
|
-
print(json.dumps(result))
|
|
760
|
-
_log_status(task_dir, result)
|
|
761
|
-
sys.exit(0)
|
|
762
|
-
elif alive:
|
|
763
|
-
result = {
|
|
764
|
-
"status": "RUNNING",
|
|
765
|
-
"pid": pid,
|
|
766
|
-
"cases_done": cases_done,
|
|
767
|
-
"last_case": last_case,
|
|
768
|
-
"task_subdir": str(task_subdir) if task_subdir else None,
|
|
769
|
-
"log_tail": log_tail,
|
|
770
|
-
}
|
|
771
|
-
print(json.dumps(result))
|
|
772
|
-
_log_status(task_dir, result)
|
|
773
|
-
sys.exit(2)
|
|
774
|
-
else:
|
|
775
|
-
result = {
|
|
776
|
-
"status": "CRASHED",
|
|
777
|
-
"pid": pid,
|
|
778
|
-
"cases_done": cases_done,
|
|
779
|
-
"last_case": last_case,
|
|
780
|
-
"task_subdir": str(task_subdir) if task_subdir else None,
|
|
781
|
-
"log_tail": log_tail,
|
|
782
|
-
}
|
|
783
|
-
print(json.dumps(result))
|
|
784
|
-
_log_status(task_dir, result)
|
|
785
|
-
sys.exit(3)
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
# =============================================================================
|
|
789
|
-
# kill 子命令
|
|
790
|
-
# =============================================================================
|
|
791
|
-
|
|
792
|
-
def cmd_kill(args):
|
|
793
|
-
"""kill 子命令:终止 AutoTest.batch 进程"""
|
|
794
|
-
task_dir = Path(args.task_dir)
|
|
795
|
-
pid_file = task_dir / "batch.pid"
|
|
796
|
-
|
|
797
|
-
if not pid_file.exists():
|
|
798
|
-
print(json.dumps({"status": "NO_PID_FILE", "killed": False}))
|
|
799
|
-
return
|
|
800
|
-
|
|
801
|
-
pid = int(pid_file.read_text().strip())
|
|
802
|
-
|
|
803
|
-
if not _pid_alive(pid):
|
|
804
|
-
print(json.dumps({"status": "ALREADY_DEAD", "pid": pid, "killed": False}))
|
|
805
|
-
return
|
|
806
|
-
|
|
807
|
-
cmdline = _get_process_cmdline(pid)
|
|
808
|
-
if cmdline and "AutoTest.batch" not in cmdline:
|
|
809
|
-
print(json.dumps({
|
|
810
|
-
"status": "REFUSED", "pid": pid, "killed": False,
|
|
811
|
-
"reason": "非 AutoTest.batch 进程", "cmdline": cmdline,
|
|
812
|
-
}))
|
|
813
|
-
return
|
|
814
|
-
|
|
815
|
-
_kill_process_tree(pid)
|
|
816
|
-
print(json.dumps({"status": "KILLED", "pid": pid, "killed": True}))
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
# =============================================================================
|
|
820
|
-
# clean 子命令
|
|
821
|
-
# =============================================================================
|
|
822
|
-
|
|
823
|
-
def cmd_clean(args):
|
|
824
|
-
"""clean 子命令:彻底重置本地状态以便重跑。
|
|
825
|
-
|
|
826
|
-
动作:
|
|
827
|
-
- 杀掉所有残留 AutoTest.batch / hypium_mcp / harmony_autotest 进程
|
|
828
|
-
- 删除 .venv 及 __pycache__
|
|
829
|
-
- 删除本目录顶层的 tmp_hypium / hypium_mcp.log / batch.pid / batch_stdout.log
|
|
830
|
-
|
|
831
|
-
NOT touched: 全局 uv 缓存。6 个 whl 已改为从本地加载,不走网络;
|
|
832
|
-
单纯"重跑一遍"不需要碰缓存。需要的话用 `uv cache clean` 自己清。
|
|
833
|
-
"""
|
|
834
|
-
# 控制台输出即可,不写 self_test_*.log(避免污染 output-dir)
|
|
835
|
-
logging.basicConfig(
|
|
836
|
-
level=logging.INFO,
|
|
837
|
-
format="[%(asctime)s] %(levelname)s %(message)s",
|
|
838
|
-
datefmt="%Y-%m-%d %H:%M:%S",
|
|
839
|
-
)
|
|
840
|
-
logger.setLevel(logging.INFO)
|
|
841
|
-
|
|
842
|
-
_kill_stale_processes()
|
|
843
|
-
_clean_venv()
|
|
844
|
-
_clean_stale_artifacts(SCRIPT_DIR)
|
|
845
|
-
print(json.dumps({"status": "CLEANED"}, ensure_ascii=False))
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
# =============================================================================
|
|
849
|
-
# 主入口
|
|
850
|
-
# =============================================================================
|
|
851
|
-
|
|
852
|
-
def main():
|
|
853
|
-
parser = argparse.ArgumentParser(description="自测执行器")
|
|
854
|
-
sub = parser.add_subparsers(dest="command", required=True)
|
|
855
|
-
|
|
856
|
-
# run 子命令
|
|
857
|
-
p_run = sub.add_parser("run", help="准备环境并执行用例")
|
|
858
|
-
p_run.add_argument("--testcases", required=True,
|
|
859
|
-
help="测试用例文件,JSON 数组或 JSONL,传入 JSON 数组时会自动转换为 JSONL")
|
|
860
|
-
p_run.add_argument("--hap", required=True, help=".hap 文件")
|
|
861
|
-
p_run.add_argument("--bundle-name", required=True, help="包名")
|
|
862
|
-
p_run.add_argument("--task-dir", default="task", help="任务目录(内部会创建 task_<timestamp> 子目录)")
|
|
863
|
-
p_run.add_argument("--output-dir", default=None, help="日志目录")
|
|
864
|
-
p_run.add_argument("--category", default=DEFAULT_CATEGORY, help="测试分类名称,传给 AutoTest.batch")
|
|
865
|
-
p_run.add_argument("--config", default=None,
|
|
866
|
-
help="HomeTrans 配置文件(config.json)路径;默认 ~/.hometrans/config.json,"
|
|
867
|
-
"从中读取 autotest 配置并物化成临时 YAML 交给 AutoTest.batch")
|
|
868
|
-
p_run.add_argument("--force-reinit", action="store_true",
|
|
869
|
-
help="强制清理 .venv 并重新 uv sync;默认仅在 pyproject.toml 内容变更时才重建")
|
|
870
|
-
p_run.set_defaults(func=cmd_run)
|
|
871
|
-
|
|
872
|
-
# status 子命令
|
|
873
|
-
p_status = sub.add_parser("status", help="查询执行状态")
|
|
874
|
-
p_status.add_argument("--task-dir", required=True)
|
|
875
|
-
p_status.add_argument("--output-dir", default=None)
|
|
876
|
-
p_status.set_defaults(func=cmd_status)
|
|
877
|
-
|
|
878
|
-
# kill 子命令
|
|
879
|
-
p_kill = sub.add_parser("kill", help="终止进程")
|
|
880
|
-
p_kill.add_argument("--task-dir", required=True)
|
|
881
|
-
p_kill.set_defaults(func=cmd_kill)
|
|
882
|
-
|
|
883
|
-
# clean 子命令
|
|
884
|
-
p_clean = sub.add_parser(
|
|
885
|
-
"clean",
|
|
886
|
-
help="重置本地状态(杀残留进程、删 .venv、删本目录残留中间产物),不动全局 uv 缓存",
|
|
887
|
-
)
|
|
888
|
-
p_clean.set_defaults(func=cmd_clean)
|
|
889
|
-
|
|
890
|
-
args = parser.parse_args()
|
|
891
|
-
args.func(args)
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
if __name__ == "__main__":
|
|
895
|
-
main()
|