@autotest/agent 0.0.2 → 0.0.4
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 +166 -95
- package/dist/api/agent_api.d.ts +3 -7
- package/dist/api/agent_api.js +12 -12
- package/dist/api/autotest_agent.d.ts +0 -1
- package/dist/api/autotest_agent.js +0 -1
- package/dist/api/types.d.ts +0 -1
- package/dist/api/types.js +0 -1
- package/dist/autotest-cli.d.ts +0 -1
- package/dist/autotest-cli.js +9 -3
- package/dist/common/case_manager.d.ts +0 -1
- package/dist/common/case_manager.js +0 -1
- package/dist/common/collect_case.d.ts +0 -1
- package/dist/common/collect_case.js +0 -1
- package/dist/common/common_errors.d.ts +0 -1
- package/dist/common/common_errors.js +0 -1
- package/dist/common/config/config.yaml +134 -113
- package/dist/common/config/config_validator.d.ts +0 -1
- package/dist/common/config/config_validator.js +0 -1
- package/dist/common/config/manager.d.ts +0 -1
- package/dist/common/config/manager.js +0 -1
- package/dist/common/config/output.d.ts +0 -1
- package/dist/common/config/output.js +0 -1
- package/dist/common/config/types.d.ts +2243 -2244
- package/dist/common/config/types.js +2 -3
- package/dist/common/dfx/client_factory.d.ts +0 -1
- package/dist/common/dfx/client_factory.js +0 -1
- package/dist/common/dfx/context.d.ts +0 -1
- package/dist/common/dfx/context.js +0 -1
- package/dist/common/dfx/index.d.ts +0 -1
- package/dist/common/dfx/index.js +0 -1
- package/dist/common/dfx/recorder.d.ts +0 -1
- package/dist/common/dfx/recorder.js +0 -1
- package/dist/common/dfx/recording_fetch.d.ts +0 -1
- package/dist/common/dfx/recording_fetch.js +0 -1
- package/dist/common/dfx/source.d.ts +0 -1
- package/dist/common/dfx/source.js +0 -1
- package/dist/common/image_cacher.d.ts +0 -1
- package/dist/common/image_cacher.js +0 -1
- package/dist/common/image_helper.d.ts +0 -1
- package/dist/common/image_helper.js +0 -1
- package/dist/common/image_similarity.d.ts +0 -1
- package/dist/common/image_similarity.js +0 -1
- package/dist/common/llm_cache/cache_transport.d.ts +2 -1
- package/dist/common/llm_cache/cache_transport.js +4 -1
- package/dist/common/llm_cache/prompt_cache.d.ts +53 -0
- package/dist/common/llm_cache/prompt_cache.js +113 -0
- package/dist/common/logger.d.ts +0 -1
- package/dist/common/logger.js +0 -1
- package/dist/common/model/custom_model.d.ts +0 -1
- package/dist/common/model/custom_model.js +57 -6
- package/dist/common/model/index.d.ts +0 -1
- package/dist/common/model/index.js +0 -1
- package/dist/common/path_utils.d.ts +7 -4
- package/dist/common/path_utils.js +12 -6
- package/dist/common/result_parser.d.ts +0 -1
- package/dist/common/result_parser.js +1 -2
- package/dist/common/usage/token_usage.d.ts +0 -1
- package/dist/common/usage/token_usage.js +0 -1
- package/dist/common/utils.d.ts +0 -1
- package/dist/common/utils.js +0 -1
- package/dist/core/agent/layered_agent/ability_helper.d.ts +0 -1
- package/dist/core/agent/layered_agent/ability_helper.js +0 -1
- package/dist/core/agent/layered_agent/agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/agent.js +0 -1
- package/dist/core/agent/layered_agent/agent_registry.d.ts +0 -1
- package/dist/core/agent/layered_agent/agent_registry.js +0 -1
- package/dist/core/agent/layered_agent/decision.d.ts +0 -1
- package/dist/core/agent/layered_agent/decision.js +61 -24
- package/dist/core/agent/layered_agent/execute_agent/action_handler.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.d.ts +1 -2
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/base_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/general_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/i18n.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/index.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/index.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +1 -2
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +5 -6
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +1 -2
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +1 -2
- package/dist/core/agent/layered_agent/execute_agent/parser/index.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +1 -2
- package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +1 -2
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +5 -6
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -1
- package/dist/core/agent/layered_agent/execute_agent/utils.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -1
- package/dist/core/agent/report_analyzer_agent/agent.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/agent.js +0 -1
- package/dist/core/agent/report_analyzer_agent/config.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/config.js +0 -1
- package/dist/core/agent/report_analyzer_agent/data_loader.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -1
- package/dist/core/agent/report_analyzer_agent/guardrails.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -1
- package/dist/core/agent/report_analyzer_agent/hooks.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/hooks.js +0 -1
- package/dist/core/agent/report_analyzer_agent/index.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/index.js +0 -1
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -1
- package/dist/core/agent/report_analyzer_agent/mapping.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/mapping.js +0 -1
- package/dist/core/agent/report_analyzer_agent/parse.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/parse.js +0 -1
- package/dist/core/agent/report_analyzer_agent/prompt.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/prompt.js +0 -1
- package/dist/core/agent/report_analyzer_agent/report_writer.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -1
- package/dist/core/agent/report_analyzer_agent/tools.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/tools.js +0 -1
- package/dist/core/agent/report_analyzer_agent/types.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/types.js +0 -1
- package/dist/core/agent/rewrite_agent/agent.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/agent.js +0 -1
- package/dist/core/agent/rewrite_agent/guardrails.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/guardrails.js +0 -1
- package/dist/core/agent/rewrite_agent/mapping.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/mapping.js +0 -1
- package/dist/core/agent/rewrite_agent/parse.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/parse.js +0 -1
- package/dist/core/agent/rewrite_agent/types.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/types.js +0 -1
- package/dist/core/agent/single_agent/agent.d.ts +0 -1
- package/dist/core/agent/single_agent/agent.js +1 -2
- package/dist/core/agent/single_agent/hook_manager.d.ts +0 -1
- package/dist/core/agent/single_agent/hook_manager.js +0 -1
- package/dist/core/agent/single_agent/hooks.d.ts +0 -1
- package/dist/core/agent/single_agent/hooks.js +0 -1
- package/dist/core/agent/single_agent/image_utils.d.ts +0 -1
- package/dist/core/agent/single_agent/image_utils.js +0 -1
- package/dist/core/agent/single_agent/scroll_search_agent.d.ts +0 -1
- package/dist/core/agent/single_agent/scroll_search_agent.js +0 -1
- package/dist/core/agent/single_agent/subagent_manager.d.ts +0 -1
- package/dist/core/agent/single_agent/subagent_manager.js +0 -1
- package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +0 -1
- package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -1
- package/dist/core/agent/types.d.ts +0 -1
- package/dist/core/agent/types.js +0 -1
- package/dist/core/agent/utils/message_builder.d.ts +0 -1
- package/dist/core/agent/utils/message_builder.js +0 -1
- package/dist/core/device/device_protocol.d.ts +0 -1
- package/dist/core/device/device_protocol.js +0 -1
- package/dist/core/device/hdc/apps.d.ts +0 -1
- package/dist/core/device/hdc/apps.js +0 -1
- package/dist/core/device/hdc/device.d.ts +0 -1
- package/dist/core/device/hdc/device.js +0 -1
- package/dist/core/device/hdc/index.d.ts +0 -1
- package/dist/core/device/hdc/index.js +0 -1
- package/dist/core/device/hdc/input.d.ts +0 -1
- package/dist/core/device/hdc/input.js +0 -1
- package/dist/core/device/hdc/screenshot.d.ts +0 -1
- package/dist/core/device/hdc/screenshot.js +0 -1
- package/dist/core/device/index.d.ts +0 -1
- package/dist/core/device/index.js +0 -1
- package/dist/core/device/types.d.ts +0 -1
- package/dist/core/device/types.js +0 -1
- package/dist/core/knowledge/knowledge_manager.d.ts +0 -1
- package/dist/core/knowledge/knowledge_manager.js +0 -1
- package/dist/core/knowledge/vectordb.d.ts +0 -1
- package/dist/core/knowledge/vectordb.js +0 -1
- package/dist/core/mcp/adapter_factory.d.ts +0 -1
- package/dist/core/mcp/adapter_factory.js +0 -1
- package/dist/core/mcp/android_adapter.d.ts +1 -2
- package/dist/core/mcp/android_adapter.js +0 -1
- package/dist/core/mcp/base_adapter.d.ts +0 -1
- package/dist/core/mcp/base_adapter.js +0 -1
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +9 -1
- package/dist/core/mcp/harmony_hdc_adapter.js +195 -2
- package/dist/core/mcp/ios_adapter.d.ts +1 -2
- package/dist/core/mcp/ios_adapter.js +0 -1
- package/dist/core/mcp/local_tools.d.ts +0 -1
- package/dist/core/mcp/local_tools.js +0 -1
- package/dist/core/mcp/mcp_tools.d.ts +19 -3
- package/dist/core/mcp/mcp_tools.js +40 -13
- package/dist/core/mcp/types.d.ts +0 -1
- package/dist/core/mcp/types.js +0 -1
- package/dist/core/memory/_utils.d.ts +18 -0
- package/dist/core/memory/_utils.js +140 -0
- package/dist/core/memory/compressed_session.d.ts +0 -1
- package/dist/core/memory/compressed_session.js +0 -1
- package/dist/core/memory/context_compressor.d.ts +0 -1
- package/dist/core/memory/context_compressor.js +0 -1
- package/dist/core/memory/index.d.ts +0 -1
- package/dist/core/memory/index.js +0 -1
- package/dist/core/memory/memory_manager.d.ts +0 -1
- package/dist/core/memory/memory_manager.js +0 -1
- package/dist/core/memory/reflector.d.ts +0 -1
- package/dist/core/memory/reflector.js +2 -3
- package/dist/core/memory/replan_manager.d.ts +9 -0
- package/dist/core/memory/replan_manager.js +12 -0
- package/dist/core/memory/session_factory.d.ts +0 -1
- package/dist/core/memory/session_factory.js +0 -1
- package/dist/core/memory/tool_player.d.ts +0 -1
- package/dist/core/memory/tool_player.js +0 -1
- package/dist/core/memory/tool_player_popup.d.ts +66 -0
- package/dist/core/memory/tool_player_popup.js +276 -0
- package/dist/core/memory/tool_player_replan.d.ts +49 -0
- package/dist/core/memory/tool_player_replan.js +226 -0
- package/dist/core/memory/tool_player_xpath.d.ts +52 -0
- package/dist/core/memory/tool_player_xpath.js +139 -0
- package/dist/core/memory/tool_recorder.d.ts +0 -1
- package/dist/core/memory/tool_recorder.js +0 -1
- package/dist/core/preprocessor/task_splitter.d.ts +0 -1
- package/dist/core/preprocessor/task_splitter.js +0 -1
- package/dist/core/prompt/prompt_loader.d.ts +0 -1
- package/dist/core/prompt/prompt_loader.js +3 -2
- package/dist/core/prompt/templates/debug/hypium/hypium_v2.0_optimize_scroll_search.md +310 -0
- package/dist/core/prompt/templates/debug/hypium/hypium_v2.0_relative_1000.md +284 -0
- package/dist/core/prompt/templates/debug/planner/planner_v3.0.md +140 -0
- package/dist/core/prompt/templates/debug/single/single_v2.0_optimize_scroll_search.md +272 -0
- package/dist/core/prompt/templates/debug/single/single_v2.0_relative_1000.md +277 -0
- package/dist/core/prompt/templates/single/single_v2.0_0_1000.md +315 -0
- package/dist/core/skill/skill_manager.d.ts +0 -1
- package/dist/core/skill/skill_manager.js +4 -2
- package/dist/core/skill/skills/cancel-all-follows/SKILL.md +23 -0
- package/dist/core/skill/skills/create-local-image/SKILL.md +12 -0
- package/dist/core/skill/skills/create-local-video/SKILL.md +12 -0
- package/dist/core/skill/skills/dismiss-popups/SKILL.md +39 -0
- package/dist/core/skill/skills/douyin_test_skills.md +16 -0
- package/dist/data_types/action.d.ts +0 -1
- package/dist/data_types/action.js +0 -1
- package/dist/data_types/agent.d.ts +0 -1
- package/dist/data_types/agent.js +0 -1
- package/dist/data_types/case.d.ts +32 -0
- package/dist/data_types/case.js +57 -0
- package/dist/data_types/device.d.ts +0 -1
- package/dist/data_types/device.js +0 -1
- package/dist/data_types/index.d.ts +2 -1
- package/dist/data_types/index.js +6 -2
- package/dist/data_types/report.d.ts +0 -1
- package/dist/data_types/report.js +0 -1
- package/dist/data_types/screen.d.ts +12 -0
- package/dist/data_types/screen.js +23 -0
- package/dist/data_types/task.d.ts +0 -1
- package/dist/data_types/task.js +0 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +37 -9
- package/dist/loop/cli.d.ts +0 -1
- package/dist/loop/cli.js +0 -1
- package/dist/loop/orchestrator.d.ts +0 -1
- package/dist/loop/orchestrator.js +0 -1
- package/dist/loop/result_writer.d.ts +0 -1
- package/dist/loop/result_writer.js +0 -1
- package/dist/loop/types.d.ts +0 -1
- package/dist/loop/types.js +0 -1
- package/dist/mcp-server/server.d.ts +0 -1
- package/dist/mcp-server/server.js +88 -24
- package/dist/mcp-server/types.d.ts +283 -118
- package/dist/mcp-server/types.js +173 -31
- package/dist/reporter/batch_summary.d.ts +0 -1
- package/dist/reporter/batch_summary.js +0 -1
- package/dist/reporter/generator.d.ts +0 -15
- package/dist/reporter/generator.js +18 -505
- package/dist/reporter/html_template/index.d.ts +56 -0
- package/dist/reporter/html_template/index.js +524 -0
- package/dist/reporter/json_report.d.ts +1 -0
- package/dist/reporter/json_report.js +6 -0
- package/dist/reporter/types.d.ts +15 -15
- package/dist/reporter/types.js +1 -1
- package/dist/tools/batch_runner.d.ts +3 -2
- package/dist/tools/batch_runner.js +24 -8
- package/dist/tools/case_runner/report.d.ts +9 -0
- package/dist/tools/case_runner/report.js +264 -0
- package/dist/tools/case_runner/runner.d.ts +57 -0
- package/dist/tools/case_runner/runner.js +410 -0
- package/dist/tools/config/config_tool.d.ts +13 -0
- package/dist/tools/config/config_tool.js +339 -0
- package/dist/tools/prompt_compare/compare_runner.d.ts +13 -0
- package/dist/tools/prompt_compare/compare_runner.js +360 -0
- package/package.json +7 -3
- package/dist/api/agent_api.d.ts.map +0 -1
- package/dist/api/agent_api.js.map +0 -1
- package/dist/api/autotest_agent.d.ts.map +0 -1
- package/dist/api/autotest_agent.js.map +0 -1
- package/dist/api/types.d.ts.map +0 -1
- package/dist/api/types.js.map +0 -1
- package/dist/autotest-cli.d.ts.map +0 -1
- package/dist/autotest-cli.js.map +0 -1
- package/dist/common/case_manager.d.ts.map +0 -1
- package/dist/common/case_manager.js.map +0 -1
- package/dist/common/collect_case.d.ts.map +0 -1
- package/dist/common/collect_case.js.map +0 -1
- package/dist/common/common_errors.d.ts.map +0 -1
- package/dist/common/common_errors.js.map +0 -1
- package/dist/common/config/config_validator.d.ts.map +0 -1
- package/dist/common/config/config_validator.js.map +0 -1
- package/dist/common/config/manager.d.ts.map +0 -1
- package/dist/common/config/manager.js.map +0 -1
- package/dist/common/config/output.d.ts.map +0 -1
- package/dist/common/config/output.js.map +0 -1
- package/dist/common/config/types.d.ts.map +0 -1
- package/dist/common/config/types.js.map +0 -1
- package/dist/common/dfx/client_factory.d.ts.map +0 -1
- package/dist/common/dfx/client_factory.js.map +0 -1
- package/dist/common/dfx/context.d.ts.map +0 -1
- package/dist/common/dfx/context.js.map +0 -1
- package/dist/common/dfx/index.d.ts.map +0 -1
- package/dist/common/dfx/index.js.map +0 -1
- package/dist/common/dfx/recorder.d.ts.map +0 -1
- package/dist/common/dfx/recorder.js.map +0 -1
- package/dist/common/dfx/recording_fetch.d.ts.map +0 -1
- package/dist/common/dfx/recording_fetch.js.map +0 -1
- package/dist/common/dfx/source.d.ts.map +0 -1
- package/dist/common/dfx/source.js.map +0 -1
- package/dist/common/image_cacher.d.ts.map +0 -1
- package/dist/common/image_cacher.js.map +0 -1
- package/dist/common/image_helper.d.ts.map +0 -1
- package/dist/common/image_helper.js.map +0 -1
- package/dist/common/image_similarity.d.ts.map +0 -1
- package/dist/common/image_similarity.js.map +0 -1
- package/dist/common/llm_cache/cache_transport.d.ts.map +0 -1
- package/dist/common/llm_cache/cache_transport.js.map +0 -1
- package/dist/common/logger.d.ts.map +0 -1
- package/dist/common/logger.js.map +0 -1
- package/dist/common/model/custom_model.d.ts.map +0 -1
- package/dist/common/model/custom_model.js.map +0 -1
- package/dist/common/model/index.d.ts.map +0 -1
- package/dist/common/model/index.js.map +0 -1
- package/dist/common/path_utils.d.ts.map +0 -1
- package/dist/common/path_utils.js.map +0 -1
- package/dist/common/result_parser.d.ts.map +0 -1
- package/dist/common/result_parser.js.map +0 -1
- package/dist/common/usage/token_usage.d.ts.map +0 -1
- package/dist/common/usage/token_usage.js.map +0 -1
- package/dist/common/utils.d.ts.map +0 -1
- package/dist/common/utils.js.map +0 -1
- package/dist/core/agent/layered_agent/ability_helper.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/ability_helper.js.map +0 -1
- package/dist/core/agent/layered_agent/agent.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/agent.js.map +0 -1
- package/dist/core/agent/layered_agent/agent_registry.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/agent_registry.js.map +0 -1
- package/dist/core/agent/layered_agent/decision.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/decision.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/action_handler.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/action_handler.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/base_agent.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/base_agent.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/general_agent.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/general_agent.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/i18n.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/i18n.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/index.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/index.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/index.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/index.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/prompts.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/utils.d.ts.map +0 -1
- package/dist/core/agent/layered_agent/execute_agent/utils.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/agent.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/agent.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/config.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/config.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/data_loader.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/data_loader.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/guardrails.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/guardrails.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/hooks.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/hooks.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/index.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/index.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/mapping.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/mapping.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/parse.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/parse.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/prompt.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/prompt.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/report_writer.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/report_writer.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/tools.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/tools.js.map +0 -1
- package/dist/core/agent/report_analyzer_agent/types.d.ts.map +0 -1
- package/dist/core/agent/report_analyzer_agent/types.js.map +0 -1
- package/dist/core/agent/rewrite_agent/agent.d.ts.map +0 -1
- package/dist/core/agent/rewrite_agent/agent.js.map +0 -1
- package/dist/core/agent/rewrite_agent/guardrails.d.ts.map +0 -1
- package/dist/core/agent/rewrite_agent/guardrails.js.map +0 -1
- package/dist/core/agent/rewrite_agent/mapping.d.ts.map +0 -1
- package/dist/core/agent/rewrite_agent/mapping.js.map +0 -1
- package/dist/core/agent/rewrite_agent/parse.d.ts.map +0 -1
- package/dist/core/agent/rewrite_agent/parse.js.map +0 -1
- package/dist/core/agent/rewrite_agent/types.d.ts.map +0 -1
- package/dist/core/agent/rewrite_agent/types.js.map +0 -1
- package/dist/core/agent/single_agent/agent.d.ts.map +0 -1
- package/dist/core/agent/single_agent/agent.js.map +0 -1
- package/dist/core/agent/single_agent/hook_manager.d.ts.map +0 -1
- package/dist/core/agent/single_agent/hook_manager.js.map +0 -1
- package/dist/core/agent/single_agent/hooks.d.ts.map +0 -1
- package/dist/core/agent/single_agent/hooks.js.map +0 -1
- package/dist/core/agent/single_agent/image_utils.d.ts.map +0 -1
- package/dist/core/agent/single_agent/image_utils.js.map +0 -1
- package/dist/core/agent/single_agent/scroll_search_agent.d.ts.map +0 -1
- package/dist/core/agent/single_agent/scroll_search_agent.js.map +0 -1
- package/dist/core/agent/single_agent/subagent_manager.d.ts.map +0 -1
- package/dist/core/agent/single_agent/subagent_manager.js.map +0 -1
- package/dist/core/agent/single_agent/tool_recorder_hook.d.ts.map +0 -1
- package/dist/core/agent/single_agent/tool_recorder_hook.js.map +0 -1
- package/dist/core/agent/types.d.ts.map +0 -1
- package/dist/core/agent/types.js.map +0 -1
- package/dist/core/agent/utils/message_builder.d.ts.map +0 -1
- package/dist/core/agent/utils/message_builder.js.map +0 -1
- package/dist/core/device/device_protocol.d.ts.map +0 -1
- package/dist/core/device/device_protocol.js.map +0 -1
- package/dist/core/device/hdc/apps.d.ts.map +0 -1
- package/dist/core/device/hdc/apps.js.map +0 -1
- package/dist/core/device/hdc/device.d.ts.map +0 -1
- package/dist/core/device/hdc/device.js.map +0 -1
- package/dist/core/device/hdc/index.d.ts.map +0 -1
- package/dist/core/device/hdc/index.js.map +0 -1
- package/dist/core/device/hdc/input.d.ts.map +0 -1
- package/dist/core/device/hdc/input.js.map +0 -1
- package/dist/core/device/hdc/screenshot.d.ts.map +0 -1
- package/dist/core/device/hdc/screenshot.js.map +0 -1
- package/dist/core/device/index.d.ts.map +0 -1
- package/dist/core/device/index.js.map +0 -1
- package/dist/core/device/types.d.ts.map +0 -1
- package/dist/core/device/types.js.map +0 -1
- package/dist/core/knowledge/knowledge_manager.d.ts.map +0 -1
- package/dist/core/knowledge/knowledge_manager.js.map +0 -1
- package/dist/core/knowledge/vectordb.d.ts.map +0 -1
- package/dist/core/knowledge/vectordb.js.map +0 -1
- package/dist/core/mcp/adapter_factory.d.ts.map +0 -1
- package/dist/core/mcp/adapter_factory.js.map +0 -1
- package/dist/core/mcp/android_adapter.d.ts.map +0 -1
- package/dist/core/mcp/android_adapter.js.map +0 -1
- package/dist/core/mcp/base_adapter.d.ts.map +0 -1
- package/dist/core/mcp/base_adapter.js.map +0 -1
- package/dist/core/mcp/harmony_hdc_adapter.d.ts.map +0 -1
- package/dist/core/mcp/harmony_hdc_adapter.js.map +0 -1
- package/dist/core/mcp/ios_adapter.d.ts.map +0 -1
- package/dist/core/mcp/ios_adapter.js.map +0 -1
- package/dist/core/mcp/local_tools.d.ts.map +0 -1
- package/dist/core/mcp/local_tools.js.map +0 -1
- package/dist/core/mcp/mcp_tools.d.ts.map +0 -1
- package/dist/core/mcp/mcp_tools.js.map +0 -1
- package/dist/core/mcp/types.d.ts.map +0 -1
- package/dist/core/mcp/types.js.map +0 -1
- package/dist/core/memory/compressed_session.d.ts.map +0 -1
- package/dist/core/memory/compressed_session.js.map +0 -1
- package/dist/core/memory/context_compressor.d.ts.map +0 -1
- package/dist/core/memory/context_compressor.js.map +0 -1
- package/dist/core/memory/index.d.ts.map +0 -1
- package/dist/core/memory/index.js.map +0 -1
- package/dist/core/memory/memory_manager.d.ts.map +0 -1
- package/dist/core/memory/memory_manager.js.map +0 -1
- package/dist/core/memory/reflector.d.ts.map +0 -1
- package/dist/core/memory/reflector.js.map +0 -1
- package/dist/core/memory/session_factory.d.ts.map +0 -1
- package/dist/core/memory/session_factory.js.map +0 -1
- package/dist/core/memory/tool_player.d.ts.map +0 -1
- package/dist/core/memory/tool_player.js.map +0 -1
- package/dist/core/memory/tool_recorder.d.ts.map +0 -1
- package/dist/core/memory/tool_recorder.js.map +0 -1
- package/dist/core/preprocessor/task_splitter.d.ts.map +0 -1
- package/dist/core/preprocessor/task_splitter.js.map +0 -1
- package/dist/core/prompt/prompt_loader.d.ts.map +0 -1
- package/dist/core/prompt/prompt_loader.js.map +0 -1
- package/dist/core/skill/skill_manager.d.ts.map +0 -1
- package/dist/core/skill/skill_manager.js.map +0 -1
- package/dist/data_types/action.d.ts.map +0 -1
- package/dist/data_types/action.js.map +0 -1
- package/dist/data_types/agent.d.ts.map +0 -1
- package/dist/data_types/agent.js.map +0 -1
- package/dist/data_types/device.d.ts.map +0 -1
- package/dist/data_types/device.js.map +0 -1
- package/dist/data_types/index.d.ts.map +0 -1
- package/dist/data_types/index.js.map +0 -1
- package/dist/data_types/report.d.ts.map +0 -1
- package/dist/data_types/report.js.map +0 -1
- package/dist/data_types/task.d.ts.map +0 -1
- package/dist/data_types/task.js.map +0 -1
- package/dist/hypium_generator/generator.d.ts +0 -38
- package/dist/hypium_generator/generator.d.ts.map +0 -1
- package/dist/hypium_generator/generator.js +0 -847
- package/dist/hypium_generator/generator.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/loop/cli.d.ts.map +0 -1
- package/dist/loop/cli.js.map +0 -1
- package/dist/loop/orchestrator.d.ts.map +0 -1
- package/dist/loop/orchestrator.js.map +0 -1
- package/dist/loop/result_writer.d.ts.map +0 -1
- package/dist/loop/result_writer.js.map +0 -1
- package/dist/loop/types.d.ts.map +0 -1
- package/dist/loop/types.js.map +0 -1
- package/dist/mcp-server/server.d.ts.map +0 -1
- package/dist/mcp-server/server.js.map +0 -1
- package/dist/mcp-server/types.d.ts.map +0 -1
- package/dist/mcp-server/types.js.map +0 -1
- package/dist/reporter/batch_summary.d.ts.map +0 -1
- package/dist/reporter/batch_summary.js.map +0 -1
- package/dist/reporter/generator.d.ts.map +0 -1
- package/dist/reporter/generator.js.map +0 -1
- package/dist/reporter/types.d.ts.map +0 -1
- package/dist/reporter/types.js.map +0 -1
- package/dist/tools/batch_runner.d.ts.map +0 -1
- package/dist/tools/batch_runner.js.map +0 -1
|
@@ -1,847 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Report-to-Hypium converter.
|
|
4
|
-
*
|
|
5
|
-
* Turns a successful dynamic AutoTestAgent report into a reusable Hypium
|
|
6
|
-
* regression script plus a JSON config. It prefers semantic locators from the
|
|
7
|
-
* captured layout and falls back to normalized coordinates when the UI tree
|
|
8
|
-
* does not expose a stable target.
|
|
9
|
-
*
|
|
10
|
-
* An LLM (via {@link LLMCaller}) can be used to generate the Python script from
|
|
11
|
-
* the extracted actions; when no LLM is configured, a deterministic template is
|
|
12
|
-
* used instead.
|
|
13
|
-
*/
|
|
14
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
-
}
|
|
20
|
-
Object.defineProperty(o, k2, desc);
|
|
21
|
-
}) : (function(o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
}));
|
|
25
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
-
}) : function(o, v) {
|
|
28
|
-
o["default"] = v;
|
|
29
|
-
});
|
|
30
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
-
var ownKeys = function(o) {
|
|
32
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
-
var ar = [];
|
|
34
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
-
return ar;
|
|
36
|
-
};
|
|
37
|
-
return ownKeys(o);
|
|
38
|
-
};
|
|
39
|
-
return function (mod) {
|
|
40
|
-
if (mod && mod.__esModule) return mod;
|
|
41
|
-
var result = {};
|
|
42
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
-
__setModuleDefault(result, mod);
|
|
44
|
-
return result;
|
|
45
|
-
};
|
|
46
|
-
})();
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.generateHypiumFromReport = generateHypiumFromReport;
|
|
49
|
-
exports.maybeGenerateHypiumFromSavedReport = maybeGenerateHypiumFromSavedReport;
|
|
50
|
-
const fs = __importStar(require("fs"));
|
|
51
|
-
const path = __importStar(require("path"));
|
|
52
|
-
const logger_1 = require("../common/logger");
|
|
53
|
-
const DEFAULT_TIMING = {
|
|
54
|
-
launch_wait: 4.0,
|
|
55
|
-
action_wait: 0.8,
|
|
56
|
-
assert_wait: 3.0,
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Generate a Hypium regression script + config from a report JSON file.
|
|
60
|
-
*/
|
|
61
|
-
async function generateHypiumFromReport(reportJsonPath, options = {}) {
|
|
62
|
-
const reportDir = path.dirname(reportJsonPath);
|
|
63
|
-
const report = JSON.parse(fs.readFileSync(reportJsonPath, 'utf-8'));
|
|
64
|
-
if (!looksSuccessful(report)) {
|
|
65
|
-
throw new Error('Report does not look successful; skip Hypium generation.');
|
|
66
|
-
}
|
|
67
|
-
const bundleName = extractBundleName(report);
|
|
68
|
-
if (!bundleName) {
|
|
69
|
-
throw new Error('Cannot infer bundle name from report start_app event.');
|
|
70
|
-
}
|
|
71
|
-
const caseId = safeCaseId(String(report.test_case ?? path.basename(reportDir)));
|
|
72
|
-
const task = String(report.task ?? '');
|
|
73
|
-
const actions = extractActions(report, reportDir);
|
|
74
|
-
if (actions.length === 0) {
|
|
75
|
-
throw new Error('No replayable actions found in report.');
|
|
76
|
-
}
|
|
77
|
-
const assertion = extractAssertion(report, reportDir);
|
|
78
|
-
let assertions;
|
|
79
|
-
if (assertion === null) {
|
|
80
|
-
logger_1.logger.warn('No explicit assertion inferred from report; generated script will only replay actions.');
|
|
81
|
-
assertions = [];
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
assertions = [assertion];
|
|
85
|
-
}
|
|
86
|
-
const config = {
|
|
87
|
-
bundle_name: bundleName,
|
|
88
|
-
page_name: 'EntryAbility',
|
|
89
|
-
source_report: reportDir,
|
|
90
|
-
task,
|
|
91
|
-
timing: DEFAULT_TIMING,
|
|
92
|
-
actions,
|
|
93
|
-
assertions,
|
|
94
|
-
};
|
|
95
|
-
const targetDir = options.outputDir ?? defaultAccumulationDir(reportDir);
|
|
96
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
97
|
-
const baseName = `${caseId}_hypium`;
|
|
98
|
-
const configPath = uniquePath(path.join(targetDir, `${baseName}_config.json`));
|
|
99
|
-
const scriptPath = configPath.replace(/_config\.json$/, '.py');
|
|
100
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
|
|
101
|
-
let scriptContent;
|
|
102
|
-
if (options.llmCaller && options.modelConfig) {
|
|
103
|
-
try {
|
|
104
|
-
scriptContent = await generateHypiumScriptWithLLM(config, options.llmCaller, options.modelConfig);
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
logger_1.logger.warn(`LLM Hypium script generation failed, falling back to template: ${e instanceof Error ? e.message : String(e)}`);
|
|
108
|
-
scriptContent = renderHypiumScript();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
scriptContent = renderHypiumScript();
|
|
113
|
-
}
|
|
114
|
-
fs.writeFileSync(scriptPath, scriptContent, 'utf-8');
|
|
115
|
-
let reportCopyScript = null;
|
|
116
|
-
let reportCopyConfig = null;
|
|
117
|
-
const copyToReportDir = options.copyToReportDir ?? true;
|
|
118
|
-
if (copyToReportDir) {
|
|
119
|
-
const reportHypiumDir = path.join(reportDir, 'hypium');
|
|
120
|
-
fs.mkdirSync(reportHypiumDir, { recursive: true });
|
|
121
|
-
reportCopyConfig = path.join(reportHypiumDir, path.basename(configPath));
|
|
122
|
-
reportCopyScript = path.join(reportHypiumDir, path.basename(scriptPath));
|
|
123
|
-
fs.writeFileSync(reportCopyConfig, fs.readFileSync(configPath, 'utf-8'), 'utf-8');
|
|
124
|
-
fs.writeFileSync(reportCopyScript, fs.readFileSync(scriptPath, 'utf-8'), 'utf-8');
|
|
125
|
-
}
|
|
126
|
-
const manifestPath = updateManifest(targetDir, {
|
|
127
|
-
generated_at: new Date().toISOString(),
|
|
128
|
-
case_id: caseId,
|
|
129
|
-
task,
|
|
130
|
-
bundle_name: bundleName,
|
|
131
|
-
source_report: reportDir,
|
|
132
|
-
script: scriptPath,
|
|
133
|
-
config: configPath,
|
|
134
|
-
report_copy_script: reportCopyScript,
|
|
135
|
-
report_copy_config: reportCopyConfig,
|
|
136
|
-
action_count: actions.length,
|
|
137
|
-
assertion_count: assertions.length,
|
|
138
|
-
});
|
|
139
|
-
return {
|
|
140
|
-
reportDir,
|
|
141
|
-
scriptPath,
|
|
142
|
-
configPath,
|
|
143
|
-
manifestPath,
|
|
144
|
-
actionCount: actions.length,
|
|
145
|
-
assertionCount: assertions.length,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Best-effort Hypium generation from a saved report, gated by the
|
|
150
|
-
* AUTOTEST_GENERATE_HYPIUM environment variable.
|
|
151
|
-
*/
|
|
152
|
-
async function maybeGenerateHypiumFromSavedReport(savedFiles, status, options = {}) {
|
|
153
|
-
const enabled = process.env.AUTOTEST_GENERATE_HYPIUM ?? '1';
|
|
154
|
-
if (['0', 'false', 'no', 'off'].includes(enabled.trim().toLowerCase())) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
const jsonPath = savedFiles.json;
|
|
158
|
-
if (!jsonPath) {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
try {
|
|
162
|
-
const report = JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
|
|
163
|
-
if (status === 'FAIL' || !looksSuccessful(report)) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
const outputDir = process.env.AUTOTEST_HYPIUM_OUTPUT_DIR;
|
|
167
|
-
return generateHypiumFromReport(jsonPath, { ...options, outputDir });
|
|
168
|
-
}
|
|
169
|
-
catch (e) {
|
|
170
|
-
logger_1.logger.warn(`Hypium script generation skipped: ${e instanceof Error ? e.message : String(e)}`);
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
// Chinese tokens used in report parsing (kept as escapes so the source stays ASCII).
|
|
175
|
-
// task result / pass / fail tokens
|
|
176
|
-
const RE_TASK_RESULT_FAIL = /(?:\u4efb\u52a1)?\u7ed3\u679c\s*[:\uff1a]\s*\u4e0d\u901a\u8fc7/;
|
|
177
|
-
const RE_MATCH_NO = /\u662f\u5426\u5339\u914d\s*[:\uff1a]\s*\u5426/;
|
|
178
|
-
const RE_STATE_NO = /\u72b6\u6001\u7b26\u5408\u9884\u671f\s*[:\uff1a]\s*\u5426/;
|
|
179
|
-
const RE_TASK_RESULT_PASS = /\u7ed3\u679c\s*[:\uff1a]\s*\u901a\u8fc7/;
|
|
180
|
-
const RE_MATCH_YES = /\u662f\u5426\u5339\u914d\s*[:\uff1a]\s*(\u662f|\u5339\u914d)/;
|
|
181
|
-
const RE_STATE_YES = /\u72b6\u6001\u7b26\u5408\u9884\u671f\s*[:\uff1a]\s*\u662f/;
|
|
182
|
-
const RE_TEST_PASS = /(?:\u6d4b\u8bd5|\u5224\u5b9a|\u786e\u8ba4\u6d4b\u8bd5)(?:\u6d41\u7a0b)?(?:\u7ed3\u679c)?(?:\u4e3a)?\u901a\u8fc7/;
|
|
183
|
-
const RE_NO_BUG = /\u672a\u53d1\u73b0\u4efb\u4f55Bug/;
|
|
184
|
-
const RE_EXPECTED = /\u7b26\u5408\u9884\u671f|\u6b63\u662e\u9884\u671f\u7ed3\u679c/;
|
|
185
|
-
const RE_LAUNCH = /(?:\u6253\u5f00|\u542f\u52a8)\s*([A-Za-z0-9_.]+)/;
|
|
186
|
-
const RE_ONLY_DIGITS_SPACE = /^[\d\s,:\uff1a]+$/;
|
|
187
|
-
const ZH_FROM_CLIPBOARD = '\u6765\u81ea\u526a\u8d34\u677f';
|
|
188
|
-
// expected-result extraction patterns (curly quotes \u201c \u201d)
|
|
189
|
-
const RE_EXPECTED_RESULT = /\u9884\u671f\u7ed3\u679c\s*[:\uff1a].*?[\u201c"]([^\u201d"]+)[\u201d"]/s;
|
|
190
|
-
const RE_EXPECTED_SHORT = /\u9884\u671f\s*[:\uff1a].*?[\u201c"]([^\u201d"]+)[\u201d"]/s;
|
|
191
|
-
const RE_SHOW_QUOTED = /\u663e\u793a\s*[\u201c"]([^\u201d"]+)[\u201d"]/s;
|
|
192
|
-
/** Heuristically decide whether a report represents a successful run. */
|
|
193
|
-
function looksSuccessful(report) {
|
|
194
|
-
const taskEnd = lastEventContent(report, 'task_end');
|
|
195
|
-
const plannerEnd = lastEventContent(report, 'planner_end');
|
|
196
|
-
const content = `${taskEnd}\n${plannerEnd}`;
|
|
197
|
-
if (content.startsWith('Error:') || RE_TASK_RESULT_FAIL.test(content) || RE_MATCH_NO.test(content) || RE_STATE_NO.test(content)) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
if (RE_TASK_RESULT_PASS.test(content))
|
|
201
|
-
return true;
|
|
202
|
-
if (RE_MATCH_YES.test(content))
|
|
203
|
-
return true;
|
|
204
|
-
if (RE_STATE_YES.test(content))
|
|
205
|
-
return true;
|
|
206
|
-
if (RE_TEST_PASS.test(content))
|
|
207
|
-
return true;
|
|
208
|
-
if (RE_NO_BUG.test(content) && RE_EXPECTED.test(content))
|
|
209
|
-
return true;
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
/** Get the content of the last event of a given type. */
|
|
213
|
-
function lastEventContent(report, eventType) {
|
|
214
|
-
const events = report.events ?? [];
|
|
215
|
-
for (let i = events.length - 1; i >= 0; i--) {
|
|
216
|
-
const event = events[i];
|
|
217
|
-
if (event.event_type === eventType) {
|
|
218
|
-
const data = event.data;
|
|
219
|
-
const dataOutput = data?.output;
|
|
220
|
-
return String(dataOutput ?? event.content ?? '');
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return '';
|
|
224
|
-
}
|
|
225
|
-
/** Extract the bundle name from the task description or a start_app event. */
|
|
226
|
-
function extractBundleName(report) {
|
|
227
|
-
const task = String(report.task ?? '');
|
|
228
|
-
const taskMatch = task.match(RE_LAUNCH);
|
|
229
|
-
if (taskMatch && taskMatch[1]) {
|
|
230
|
-
return taskMatch[1];
|
|
231
|
-
}
|
|
232
|
-
const events = report.events ?? [];
|
|
233
|
-
for (const event of events) {
|
|
234
|
-
if (event.event_type !== 'planner_tool_call' && event.event_type !== 'mcp_tool_start') {
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
const data = event.data;
|
|
238
|
-
if (data?.tool_name !== 'start_app') {
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
const args = (data.arguments ?? {});
|
|
242
|
-
return String(args.app_name ?? args.bundle_name ?? '');
|
|
243
|
-
}
|
|
244
|
-
return '';
|
|
245
|
-
}
|
|
246
|
-
/** Extract replayable actions from the report events. */
|
|
247
|
-
function extractActions(report, reportDir) {
|
|
248
|
-
const actions = [];
|
|
249
|
-
const seen = new Set();
|
|
250
|
-
let inputIndex = 1;
|
|
251
|
-
let tapIndex = 1;
|
|
252
|
-
const events = report.events ?? [];
|
|
253
|
-
for (const event of events) {
|
|
254
|
-
if (event.event_type !== 'mcp_tool_start') {
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
const data = (event.data ?? {});
|
|
258
|
-
const tool = String(data.tool_name ?? '');
|
|
259
|
-
if (tool === 'start_app') {
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
const normalizedKey = JSON.stringify({
|
|
263
|
-
step: event.step_number,
|
|
264
|
-
tool,
|
|
265
|
-
arguments: data.arguments,
|
|
266
|
-
point: data.point,
|
|
267
|
-
start: data.start,
|
|
268
|
-
end: data.end,
|
|
269
|
-
});
|
|
270
|
-
if (seen.has(normalizedKey)) {
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
273
|
-
seen.add(normalizedKey);
|
|
274
|
-
if (tool === 'click' || tool === 'double_click' || tool === 'long_press') {
|
|
275
|
-
const pointRatio = extractPointRatio(data);
|
|
276
|
-
if (pointRatio === null) {
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
const layoutNodes = loadLayoutForScreenshot(reportDir, event.screenshot_path);
|
|
280
|
-
const log = String(data.arguments?.log ?? '');
|
|
281
|
-
const candidates = inferLocatorCandidates(layoutNodes, pointRatio, log);
|
|
282
|
-
const locatorName = `tap_${String(tapIndex).padStart(2, '0')}`;
|
|
283
|
-
tapIndex += 1;
|
|
284
|
-
actions.push({
|
|
285
|
-
type: 'tap',
|
|
286
|
-
name: locatorName,
|
|
287
|
-
candidates: candidates.length > 0 ? candidates : [{ strategy: 'point_ratio', value: pointRatio }],
|
|
288
|
-
source: { tool, log, screenshot: event.screenshot_path },
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
else if (tool === 'input_text') {
|
|
292
|
-
const text = String(data.arguments?.text ?? '');
|
|
293
|
-
if (!text) {
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
const compacted = compactInputText(text);
|
|
297
|
-
actions.push({
|
|
298
|
-
type: 'input_text',
|
|
299
|
-
name: `input_text_${String(inputIndex).padStart(2, '0')}`,
|
|
300
|
-
text: compacted,
|
|
301
|
-
source: { tool, screenshot: event.screenshot_path },
|
|
302
|
-
});
|
|
303
|
-
inputIndex += 1;
|
|
304
|
-
}
|
|
305
|
-
else if (tool === 'swipe') {
|
|
306
|
-
const start = extractRatioPair(data, 'start');
|
|
307
|
-
const end = extractRatioPair(data, 'end');
|
|
308
|
-
if (start && end) {
|
|
309
|
-
actions.push({
|
|
310
|
-
type: 'swipe',
|
|
311
|
-
name: `swipe_${String(actions.length + 1).padStart(2, '0')}`,
|
|
312
|
-
start,
|
|
313
|
-
end,
|
|
314
|
-
source: { tool, screenshot: event.screenshot_path },
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return actions;
|
|
320
|
-
}
|
|
321
|
-
function extractPointRatio(data) {
|
|
322
|
-
const point = data.point;
|
|
323
|
-
if (Array.isArray(point) && point.length === 2) {
|
|
324
|
-
return [normalizeRatio(point[0]), normalizeRatio(point[1])];
|
|
325
|
-
}
|
|
326
|
-
const args = (data.arguments ?? {});
|
|
327
|
-
const pos = args.pos;
|
|
328
|
-
if (Array.isArray(pos) && pos.length === 2) {
|
|
329
|
-
return [normalizeRatio(pos[0]), normalizeRatio(pos[1])];
|
|
330
|
-
}
|
|
331
|
-
if ('x' in args && 'y' in args) {
|
|
332
|
-
return [normalizeRatio(args.x), normalizeRatio(args.y)];
|
|
333
|
-
}
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
function extractRatioPair(data, key) {
|
|
337
|
-
const value = data[key];
|
|
338
|
-
if (Array.isArray(value) && value.length === 2) {
|
|
339
|
-
return [normalizeRatio(value[0]), normalizeRatio(value[1])];
|
|
340
|
-
}
|
|
341
|
-
return null;
|
|
342
|
-
}
|
|
343
|
-
function normalizeRatio(value) {
|
|
344
|
-
let num = Number(value);
|
|
345
|
-
if (num > 1) {
|
|
346
|
-
num = num / 1000.0;
|
|
347
|
-
}
|
|
348
|
-
return Math.round(Math.max(0.0, Math.min(1.0, num)) * 10000) / 10000;
|
|
349
|
-
}
|
|
350
|
-
function compactInputText(text) {
|
|
351
|
-
if (text.length <= 160) {
|
|
352
|
-
return text;
|
|
353
|
-
}
|
|
354
|
-
return text.slice(0, 122);
|
|
355
|
-
}
|
|
356
|
-
function inferLocatorCandidates(nodes, pointRatio, log) {
|
|
357
|
-
const point = [Math.floor(pointRatio[0] * 1000), Math.floor(pointRatio[1] * 1000)];
|
|
358
|
-
const candidates = [];
|
|
359
|
-
const quoted = extractQuotedText(log);
|
|
360
|
-
if (quoted) {
|
|
361
|
-
candidates.push({ strategy: 'text', value: quoted });
|
|
362
|
-
}
|
|
363
|
-
const best = bestTextNodeAtPoint(nodes, point);
|
|
364
|
-
if (best && best.text && isUsefulText(best.text) && isGoodSemanticClickTarget(best, point)) {
|
|
365
|
-
const semantic = { strategy: 'text', value: best.text };
|
|
366
|
-
if (!candidates.some((c) => c.value === semantic.value && c.strategy === semantic.strategy)) {
|
|
367
|
-
candidates.push(semantic);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
else if (best && best.description && isUsefulText(best.description)) {
|
|
371
|
-
candidates.push({ strategy: 'description', value: best.description });
|
|
372
|
-
}
|
|
373
|
-
candidates.push({ strategy: 'point_ratio', value: pointRatio });
|
|
374
|
-
return candidates;
|
|
375
|
-
}
|
|
376
|
-
function extractQuotedText(log) {
|
|
377
|
-
const patterns = [/'([^']+)'/, /"([^"]+)"/, /\u201c([^\u201d]+)\u201d/, /\[([^\]]+)\]/];
|
|
378
|
-
for (const pattern of patterns) {
|
|
379
|
-
const match = log.match(pattern);
|
|
380
|
-
if (match && match[1] && isUsefulText(match[1])) {
|
|
381
|
-
return match[1];
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return '';
|
|
385
|
-
}
|
|
386
|
-
function bestTextNodeAtPoint(nodes, point) {
|
|
387
|
-
const containing = nodes.filter((n) => contains(n.bounds, point));
|
|
388
|
-
if (containing.length === 0) {
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
391
|
-
const score = (node) => {
|
|
392
|
-
let textScore = 0;
|
|
393
|
-
if (node.text && isUsefulText(node.text)) {
|
|
394
|
-
textScore += 10;
|
|
395
|
-
}
|
|
396
|
-
if (['Button', 'Text', 'TextInput'].includes(node.nodeType)) {
|
|
397
|
-
textScore += 4;
|
|
398
|
-
}
|
|
399
|
-
if (node.clickable) {
|
|
400
|
-
textScore += 2;
|
|
401
|
-
}
|
|
402
|
-
return [textScore, -area(node.bounds)];
|
|
403
|
-
};
|
|
404
|
-
return containing.reduce((best, node) => {
|
|
405
|
-
const bestScore = score(best);
|
|
406
|
-
const nodeScore = score(node);
|
|
407
|
-
return nodeScore[0] > bestScore[0] ||
|
|
408
|
-
(nodeScore[0] === bestScore[0] && nodeScore[1] > bestScore[1])
|
|
409
|
-
? node
|
|
410
|
-
: best;
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
function contains(bounds, point) {
|
|
414
|
-
if (bounds.length !== 4)
|
|
415
|
-
return false;
|
|
416
|
-
return bounds[0] <= point[0] && point[0] <= bounds[2] && bounds[1] <= point[1] && point[1] <= bounds[3];
|
|
417
|
-
}
|
|
418
|
-
function area(bounds) {
|
|
419
|
-
if (bounds.length !== 4)
|
|
420
|
-
return 10 ** 9;
|
|
421
|
-
return Math.max(1, bounds[2] - bounds[0]) * Math.max(1, bounds[3] - bounds[1]);
|
|
422
|
-
}
|
|
423
|
-
function isUsefulText(text) {
|
|
424
|
-
const trimmed = text.trim();
|
|
425
|
-
if (!trimmed || trimmed.length > 60) {
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
|
-
if (RE_ONLY_DIGITS_SPACE.test(trimmed)) {
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
if (['100', '0', '05', '20', '30', '31', '36', '37'].includes(trimmed)) {
|
|
432
|
-
return false;
|
|
433
|
-
}
|
|
434
|
-
if (trimmed === ZH_FROM_CLIPBOARD) {
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
return true;
|
|
438
|
-
}
|
|
439
|
-
function isGoodSemanticClickTarget(node, point) {
|
|
440
|
-
if (node.nodeType === 'Button' || node.clickable) {
|
|
441
|
-
return true;
|
|
442
|
-
}
|
|
443
|
-
const a = area(node.bounds);
|
|
444
|
-
if (a > 160000) {
|
|
445
|
-
return false;
|
|
446
|
-
}
|
|
447
|
-
const [cx, cy] = node.center;
|
|
448
|
-
return Math.abs(cx - point[0]) <= 120 && Math.abs(cy - point[1]) <= 80;
|
|
449
|
-
}
|
|
450
|
-
function extractAssertion(report, reportDir) {
|
|
451
|
-
const events = report.events ?? [];
|
|
452
|
-
for (let i = events.length - 1; i >= 0; i--) {
|
|
453
|
-
const event = events[i];
|
|
454
|
-
const nodes = loadLayoutForScreenshot(reportDir, event.screenshot_path);
|
|
455
|
-
for (let j = nodes.length - 1; j >= 0; j--) {
|
|
456
|
-
const node = nodes[j];
|
|
457
|
-
if (node.nodeType === 'Toast' && isUsefulText(node.text)) {
|
|
458
|
-
return {
|
|
459
|
-
type: 'toast_or_text',
|
|
460
|
-
name: 'expected_result',
|
|
461
|
-
candidates: [{ strategy: 'text', value: node.text }],
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
const expected = extractExpectedText(String(report.task ?? ''));
|
|
467
|
-
if (expected) {
|
|
468
|
-
return {
|
|
469
|
-
type: 'toast_or_text',
|
|
470
|
-
name: 'expected_result',
|
|
471
|
-
candidates: [{ strategy: 'text', value: expected }],
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
return null;
|
|
475
|
-
}
|
|
476
|
-
function extractExpectedText(task) {
|
|
477
|
-
const patterns = [RE_EXPECTED_RESULT, RE_EXPECTED_SHORT, RE_SHOW_QUOTED];
|
|
478
|
-
for (const pattern of patterns) {
|
|
479
|
-
const match = task.match(pattern);
|
|
480
|
-
if (match && match[1]) {
|
|
481
|
-
return match[1].trim();
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return '';
|
|
485
|
-
}
|
|
486
|
-
function loadLayoutForScreenshot(reportDir, screenshotPath) {
|
|
487
|
-
if (!screenshotPath) {
|
|
488
|
-
return [];
|
|
489
|
-
}
|
|
490
|
-
const screenshot = String(screenshotPath);
|
|
491
|
-
const layoutPath = path.join(reportDir, 'layout', path.basename(screenshot).replace(/\.jpeg$/, '.json'));
|
|
492
|
-
if (!fs.existsSync(layoutPath)) {
|
|
493
|
-
return [];
|
|
494
|
-
}
|
|
495
|
-
return loadLayoutNodes(layoutPath);
|
|
496
|
-
}
|
|
497
|
-
function loadLayoutNodes(filePath) {
|
|
498
|
-
let raw;
|
|
499
|
-
try {
|
|
500
|
-
raw = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
501
|
-
}
|
|
502
|
-
catch {
|
|
503
|
-
return [];
|
|
504
|
-
}
|
|
505
|
-
let rawNodes;
|
|
506
|
-
if (typeof raw === 'string') {
|
|
507
|
-
const parsed = [];
|
|
508
|
-
for (const line of raw.split('\n')) {
|
|
509
|
-
const trimmed = line.trim();
|
|
510
|
-
if (!trimmed)
|
|
511
|
-
continue;
|
|
512
|
-
try {
|
|
513
|
-
parsed.push(JSON.parse(trimmed));
|
|
514
|
-
}
|
|
515
|
-
catch {
|
|
516
|
-
continue;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
rawNodes = parsed;
|
|
520
|
-
}
|
|
521
|
-
else if (Array.isArray(raw)) {
|
|
522
|
-
rawNodes = raw;
|
|
523
|
-
}
|
|
524
|
-
else if (raw && typeof raw === 'object') {
|
|
525
|
-
rawNodes = [raw];
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
rawNodes = [];
|
|
529
|
-
}
|
|
530
|
-
const nodes = [];
|
|
531
|
-
for (const item of rawNodes) {
|
|
532
|
-
if (!item || typeof item !== 'object')
|
|
533
|
-
continue;
|
|
534
|
-
const obj = item;
|
|
535
|
-
const bounds = obj.bounds;
|
|
536
|
-
let center = obj.center;
|
|
537
|
-
if (!Array.isArray(bounds) || bounds.length !== 4)
|
|
538
|
-
continue;
|
|
539
|
-
if (!Array.isArray(center) || center.length !== 2) {
|
|
540
|
-
center = [Math.floor((Number(bounds[0]) + Number(bounds[2])) / 2), Math.floor((Number(bounds[1]) + Number(bounds[3])) / 2)];
|
|
541
|
-
}
|
|
542
|
-
nodes.push({
|
|
543
|
-
text: String(obj.text ?? ''),
|
|
544
|
-
description: String(obj.description ?? ''),
|
|
545
|
-
nodeType: String(obj.type ?? ''),
|
|
546
|
-
bounds: bounds.map((v) => Number(v)),
|
|
547
|
-
center: center.map((v) => Number(v)),
|
|
548
|
-
clickable: Boolean(obj.clickable),
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
return nodes;
|
|
552
|
-
}
|
|
553
|
-
function defaultAccumulationDir(reportDir) {
|
|
554
|
-
const parent = path.basename(path.dirname(reportDir));
|
|
555
|
-
if (/^\d{4}-\d{2}-\d{2}$/.test(parent)) {
|
|
556
|
-
return path.join(path.dirname(path.dirname(reportDir)), 'hypium_cases');
|
|
557
|
-
}
|
|
558
|
-
return path.join(reportDir, 'hypium_cases');
|
|
559
|
-
}
|
|
560
|
-
function safeCaseId(value) {
|
|
561
|
-
const cleaned = value.trim().replace(/[^A-Za-z0-9_-]+/g, '_');
|
|
562
|
-
return cleaned.replace(/^_+|_+$/g, '') || 'generated_case';
|
|
563
|
-
}
|
|
564
|
-
function uniquePath(filePath) {
|
|
565
|
-
if (!fs.existsSync(filePath)) {
|
|
566
|
-
return filePath;
|
|
567
|
-
}
|
|
568
|
-
const ext = path.extname(filePath);
|
|
569
|
-
const stem = path.basename(filePath, ext);
|
|
570
|
-
const dir = path.dirname(filePath);
|
|
571
|
-
let index = 2;
|
|
572
|
-
while (true) {
|
|
573
|
-
const candidate = path.join(dir, `${stem}_${index}${ext}`);
|
|
574
|
-
if (!fs.existsSync(candidate)) {
|
|
575
|
-
return candidate;
|
|
576
|
-
}
|
|
577
|
-
index += 1;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
function updateManifest(outputDir, item) {
|
|
581
|
-
const manifestPath = path.join(outputDir, 'manifest.json');
|
|
582
|
-
let manifest = { cases: [] };
|
|
583
|
-
if (fs.existsSync(manifestPath)) {
|
|
584
|
-
try {
|
|
585
|
-
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
586
|
-
}
|
|
587
|
-
catch {
|
|
588
|
-
manifest = { cases: [] };
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
const cases = manifest.cases ?? [];
|
|
592
|
-
cases.push(item);
|
|
593
|
-
manifest.cases = cases;
|
|
594
|
-
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2), 'utf-8');
|
|
595
|
-
return manifestPath;
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* Use an LLM to generate a Hypium Python regression script from the config.
|
|
599
|
-
*/
|
|
600
|
-
async function generateHypiumScriptWithLLM(config, llmCaller, modelConfig) {
|
|
601
|
-
const systemPrompt = 'You are an expert at generating Hypium (HarmonyOS UI automation) Python regression test scripts. ' +
|
|
602
|
-
'Given a JSON config describing a sequence of actions and assertions, produce a complete, ' +
|
|
603
|
-
'self-contained Python unittest script that uses the hypium UiDriver API. ' +
|
|
604
|
-
'The script must read its config from the HYPIUM_CONFIG environment variable, ' +
|
|
605
|
-
'implement setUpClass/tearDownClass, restart the app, replay each action, ' +
|
|
606
|
-
'and assert the expected toast/text. Output ONLY the Python script, no explanation.';
|
|
607
|
-
const userPrompt = `Generate a Hypium Python unittest regression script for the following test config.\n\n` +
|
|
608
|
-
`Config JSON:\n${JSON.stringify(config, null, 2)}\n\n` +
|
|
609
|
-
`Requirements:\n` +
|
|
610
|
-
`- Read config from env HYPIUM_CONFIG (JSON file).\n` +
|
|
611
|
-
`- Connect UiDriver with optional HYPIUM_DEVICE_SN.\n` +
|
|
612
|
-
`- Restart the app (bundle_name) in setUp.\n` +
|
|
613
|
-
`- Replay each action by type: tap (use candidates: text/point_ratio), input_text, swipe.\n` +
|
|
614
|
-
`- Assert toast_or_text assertions using driver.check_toast / BY.text.\n` +
|
|
615
|
-
`- Write a result JSON to HYPIUM_RESULT_JSON on completion.\n`;
|
|
616
|
-
const result = await llmCaller.call({ systemPrompt, userPrompt, modelConfig });
|
|
617
|
-
return result.text;
|
|
618
|
-
}
|
|
619
|
-
/** Render the deterministic fallback Hypium script template. */
|
|
620
|
-
function renderHypiumScript() {
|
|
621
|
-
return HYPIUM_SCRIPT_TEMPLATE;
|
|
622
|
-
}
|
|
623
|
-
const HYPIUM_SCRIPT_TEMPLATE = `#!/usr/bin/env python3
|
|
624
|
-
# -*- coding: utf-8 -*-
|
|
625
|
-
|
|
626
|
-
"""Generated Hypium regression script.
|
|
627
|
-
|
|
628
|
-
Required:
|
|
629
|
-
HYPIUM_CONFIG=/abs/path/to/generated_config.json
|
|
630
|
-
|
|
631
|
-
Optional:
|
|
632
|
-
HYPIUM_DEVICE_SN=<device serial>
|
|
633
|
-
HYPIUM_RESULT_JSON=/abs/path/to/result.json
|
|
634
|
-
"""
|
|
635
|
-
|
|
636
|
-
from __future__ import annotations
|
|
637
|
-
|
|
638
|
-
import json
|
|
639
|
-
import math
|
|
640
|
-
import os
|
|
641
|
-
import time
|
|
642
|
-
import unittest
|
|
643
|
-
from typing import Any, Dict, List, Optional
|
|
644
|
-
|
|
645
|
-
from hypium import BY, UiDriver
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
CONFIG_PATH = os.getenv("HYPIUM_CONFIG")
|
|
649
|
-
DEVICE_SN = os.getenv("HYPIUM_DEVICE_SN")
|
|
650
|
-
RESULT_JSON_PATH = os.getenv("HYPIUM_RESULT_JSON")
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
def load_config() -> Dict[str, Any]:
|
|
654
|
-
if not CONFIG_PATH:
|
|
655
|
-
raise RuntimeError("HYPIUM_CONFIG is required.")
|
|
656
|
-
with open(CONFIG_PATH, "r", encoding="utf-8") as file:
|
|
657
|
-
return json.load(file)
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
CONFIG = load_config()
|
|
661
|
-
BUNDLE_NAME = CONFIG["bundle_name"]
|
|
662
|
-
PAGE_NAME = CONFIG.get("page_name", "EntryAbility")
|
|
663
|
-
TIMING = CONFIG.get("timing", {})
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
class GeneratedHypiumRegressionTest(unittest.TestCase):
|
|
667
|
-
driver: UiDriver
|
|
668
|
-
display_size: Optional[tuple] = None
|
|
669
|
-
result: Dict[str, Any] = {
|
|
670
|
-
"outcome": "not_run",
|
|
671
|
-
"detail": "",
|
|
672
|
-
"source_report": CONFIG.get("source_report"),
|
|
673
|
-
"task": CONFIG.get("task"),
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
@classmethod
|
|
677
|
-
def setUpClass(cls) -> None:
|
|
678
|
-
if DEVICE_SN:
|
|
679
|
-
cls.driver = UiDriver.connect(device_sn=DEVICE_SN, log_level="debug")
|
|
680
|
-
else:
|
|
681
|
-
cls.driver = UiDriver.connect(log_level="debug")
|
|
682
|
-
try:
|
|
683
|
-
cls.display_size = cls.driver.get_display_size()
|
|
684
|
-
except Exception:
|
|
685
|
-
cls.display_size = None
|
|
686
|
-
|
|
687
|
-
@classmethod
|
|
688
|
-
def tearDownClass(cls) -> None:
|
|
689
|
-
try:
|
|
690
|
-
cls.driver.stop_app(BUNDLE_NAME)
|
|
691
|
-
except Exception:
|
|
692
|
-
pass
|
|
693
|
-
cls.driver.close()
|
|
694
|
-
|
|
695
|
-
def setUp(self) -> None:
|
|
696
|
-
self.restart_app()
|
|
697
|
-
|
|
698
|
-
def restart_app(self) -> None:
|
|
699
|
-
try:
|
|
700
|
-
self.driver.stop_app(BUNDLE_NAME)
|
|
701
|
-
time.sleep(1.0)
|
|
702
|
-
except Exception:
|
|
703
|
-
pass
|
|
704
|
-
self.start_app_with_fallbacks()
|
|
705
|
-
time.sleep(float(TIMING.get("launch_wait", 4.0)))
|
|
706
|
-
try:
|
|
707
|
-
self.driver.start_listen_toast()
|
|
708
|
-
except Exception:
|
|
709
|
-
pass
|
|
710
|
-
|
|
711
|
-
def start_app_with_fallbacks(self) -> None:
|
|
712
|
-
candidates: List[str] = []
|
|
713
|
-
if PAGE_NAME:
|
|
714
|
-
candidates.append(PAGE_NAME)
|
|
715
|
-
short = PAGE_NAME.split(".")[-1]
|
|
716
|
-
if short != PAGE_NAME:
|
|
717
|
-
candidates.append(short)
|
|
718
|
-
if "." not in PAGE_NAME:
|
|
719
|
-
candidates.append(f"{BUNDLE_NAME}.{PAGE_NAME}")
|
|
720
|
-
for candidate in ("EntryAbility", f"{BUNDLE_NAME}.EntryAbility"):
|
|
721
|
-
if candidate not in candidates:
|
|
722
|
-
candidates.append(candidate)
|
|
723
|
-
|
|
724
|
-
last_error: Optional[Exception] = None
|
|
725
|
-
for candidate in candidates:
|
|
726
|
-
try:
|
|
727
|
-
self.driver.start_app(package_name=BUNDLE_NAME, page_name=candidate)
|
|
728
|
-
return
|
|
729
|
-
except Exception as exc:
|
|
730
|
-
last_error = exc
|
|
731
|
-
raise AssertionError(
|
|
732
|
-
"Failed to start app. "
|
|
733
|
-
f"bundle_name={BUNDLE_NAME}, page_name={PAGE_NAME}, "
|
|
734
|
-
f"tried={candidates}, last_error={last_error}"
|
|
735
|
-
)
|
|
736
|
-
|
|
737
|
-
def resolve_point(self, raw_value: Any) -> tuple:
|
|
738
|
-
if not self.display_size:
|
|
739
|
-
raise AssertionError("Display size is unavailable for point_ratio locator.")
|
|
740
|
-
width, height = self.display_size
|
|
741
|
-
x_ratio, y_ratio = raw_value
|
|
742
|
-
return (max(1, int(width * float(x_ratio))), max(1, int(height * float(y_ratio))))
|
|
743
|
-
|
|
744
|
-
def build_locator(self, candidate: Dict[str, Any]) -> Any:
|
|
745
|
-
strategy = candidate["strategy"]
|
|
746
|
-
value = candidate["value"]
|
|
747
|
-
if strategy == "point_ratio":
|
|
748
|
-
return ("point", value)
|
|
749
|
-
factory = getattr(BY, strategy, None)
|
|
750
|
-
if factory is None:
|
|
751
|
-
raise ValueError(f"Unsupported locator strategy: {strategy}")
|
|
752
|
-
return factory(value)
|
|
753
|
-
|
|
754
|
-
def tap_candidates(self, candidates: List[Dict[str, Any]]) -> None:
|
|
755
|
-
last_error: Optional[Exception] = None
|
|
756
|
-
for candidate in candidates:
|
|
757
|
-
try:
|
|
758
|
-
locator = self.build_locator(candidate)
|
|
759
|
-
if isinstance(locator, tuple) and locator[0] == "point":
|
|
760
|
-
point = self.resolve_point(locator[1])
|
|
761
|
-
self.driver.touch((point[0], point[1]))
|
|
762
|
-
else:
|
|
763
|
-
self.driver.touch(locator)
|
|
764
|
-
return
|
|
765
|
-
except Exception as exc:
|
|
766
|
-
last_error = exc
|
|
767
|
-
raise AssertionError(f"Failed to tap candidates: {candidates}. Last error: {last_error}")
|
|
768
|
-
|
|
769
|
-
def perform_action(self, action: Dict[str, Any]) -> None:
|
|
770
|
-
action_type = action["type"]
|
|
771
|
-
if action_type == "tap":
|
|
772
|
-
self.tap_candidates(action["candidates"])
|
|
773
|
-
elif action_type == "input_text":
|
|
774
|
-
self.driver.input_text_on_current_cursor(action["text"])
|
|
775
|
-
elif action_type == "swipe":
|
|
776
|
-
start = self.resolve_point(action["start"])
|
|
777
|
-
end = self.resolve_point(action["end"])
|
|
778
|
-
self.driver.drag(start, end, press_time=0.2, drag_time=0.25)
|
|
779
|
-
else:
|
|
780
|
-
raise ValueError(f"Unsupported generated action type: {action_type}")
|
|
781
|
-
time.sleep(float(TIMING.get("action_wait", 0.8)))
|
|
782
|
-
|
|
783
|
-
def assertion_texts(self, assertion: Dict[str, Any]) -> List[str]:
|
|
784
|
-
texts = []
|
|
785
|
-
for candidate in assertion.get("candidates", []):
|
|
786
|
-
if candidate.get("strategy") == "text":
|
|
787
|
-
texts.append(str(candidate.get("value")))
|
|
788
|
-
return texts
|
|
789
|
-
|
|
790
|
-
def toast_or_text_shown(self, expected_values: List[str]) -> bool:
|
|
791
|
-
timeout = max(1, int(math.ceil(float(TIMING.get("assert_wait", 3.0)))))
|
|
792
|
-
for expected in expected_values:
|
|
793
|
-
try:
|
|
794
|
-
if bool(self.driver.check_toast(expected, timeout=timeout)):
|
|
795
|
-
return True
|
|
796
|
-
except Exception:
|
|
797
|
-
try:
|
|
798
|
-
latest = self.driver.get_latest_toast(timeout=timeout)
|
|
799
|
-
if latest == expected:
|
|
800
|
-
return True
|
|
801
|
-
except Exception:
|
|
802
|
-
pass
|
|
803
|
-
try:
|
|
804
|
-
if bool(self.driver.check_component_exist(BY.text(expected), expect_exist=True, wait_time=timeout)):
|
|
805
|
-
return True
|
|
806
|
-
except Exception:
|
|
807
|
-
pass
|
|
808
|
-
return False
|
|
809
|
-
|
|
810
|
-
def test_generated_regression(self) -> None:
|
|
811
|
-
try:
|
|
812
|
-
for action in CONFIG.get("actions", []):
|
|
813
|
-
self.perform_action(action)
|
|
814
|
-
|
|
815
|
-
for assertion in CONFIG.get("assertions", []):
|
|
816
|
-
if assertion.get("type") != "toast_or_text":
|
|
817
|
-
raise ValueError(f"Unsupported generated assertion type: {assertion.get('type')}")
|
|
818
|
-
expected_values = self.assertion_texts(assertion)
|
|
819
|
-
self.assertTrue(
|
|
820
|
-
self.toast_or_text_shown(expected_values),
|
|
821
|
-
f"Expected toast or text was not shown: {expected_values}",
|
|
822
|
-
)
|
|
823
|
-
|
|
824
|
-
self.__class__.result.update({"outcome": "pass", "detail": "Generated regression passed."})
|
|
825
|
-
except Exception as exc:
|
|
826
|
-
self.__class__.result.update({"outcome": "fail", "detail": str(exc)})
|
|
827
|
-
raise
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
def write_result_json() -> None:
|
|
831
|
-
path = RESULT_JSON_PATH or os.path.join(os.getcwd(), "generated_hypium_result.json")
|
|
832
|
-
payload = {
|
|
833
|
-
"bundle_name": BUNDLE_NAME,
|
|
834
|
-
"page_name": PAGE_NAME,
|
|
835
|
-
"source_report": CONFIG.get("source_report"),
|
|
836
|
-
"result": GeneratedHypiumRegressionTest.result,
|
|
837
|
-
}
|
|
838
|
-
with open(path, "w", encoding="utf-8") as file:
|
|
839
|
-
json.dump(payload, file, ensure_ascii=False, indent=2)
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
if __name__ == "__main__":
|
|
843
|
-
program = unittest.main(verbosity=2, exit=False)
|
|
844
|
-
write_result_json()
|
|
845
|
-
raise SystemExit(0 if program.result.wasSuccessful() else 1)
|
|
846
|
-
`;
|
|
847
|
-
//# sourceMappingURL=generator.js.map
|