@web-auto/webauto 0.1.1 → 0.1.3
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/apps/desktop-console/default-settings.json +1 -0
- package/apps/desktop-console/dist/main/index.mjs +1618 -0
- package/apps/desktop-console/{src → dist}/main/preload.mjs +10 -0
- package/apps/desktop-console/dist/renderer/index.js +3063 -0
- package/apps/desktop-console/entry/ui-console.mjs +299 -0
- package/apps/webauto/entry/account.mjs +356 -0
- package/apps/webauto/entry/lib/account-detect.mjs +160 -0
- package/apps/webauto/entry/lib/account-store.mjs +587 -0
- package/apps/webauto/entry/lib/profilepool.mjs +1 -1
- package/apps/webauto/entry/xhs-install.mjs +27 -3
- package/apps/webauto/entry/xhs-status.mjs +152 -0
- package/apps/webauto/entry/xhs-unified.mjs +595 -17
- package/bin/webauto.mjs +263 -15
- package/dist/apps/webauto/server.js +66 -0
- package/dist/modules/camo-backend/src/index.js +575 -0
- package/dist/modules/camo-backend/src/internal/BrowserSession.js +817 -0
- package/dist/modules/camo-backend/src/internal/ElementRegistry.js +61 -0
- package/dist/modules/camo-backend/src/internal/ProfileLock.js +85 -0
- package/dist/modules/camo-backend/src/internal/SessionManager.js +172 -0
- package/dist/modules/camo-backend/src/internal/container-matcher.js +852 -0
- package/dist/modules/camo-backend/src/internal/engine-manager.js +258 -0
- package/dist/modules/camo-backend/src/internal/fingerprint.js +203 -0
- package/dist/modules/camo-backend/src/internal/pageRuntime.js +29 -0
- package/dist/modules/camo-backend/src/internal/runtimeInjector.js +30 -0
- package/dist/modules/camo-backend/src/internal/state-bus.js +46 -0
- package/dist/modules/camo-backend/src/internal/storage-paths.js +36 -0
- package/dist/modules/camo-backend/src/internal/ws-server.js +1202 -0
- package/dist/modules/camo-runtime/src/utils/browser-service.mjs +423 -0
- package/dist/modules/camo-runtime/src/utils/config.mjs +77 -0
- package/dist/modules/container-registry/src/index.js +184 -0
- package/dist/modules/logging/src/index.js +92 -0
- package/dist/modules/operations/src/builtin.js +27 -0
- package/dist/modules/operations/src/container-binding.js +75 -0
- package/dist/modules/operations/src/executor.js +146 -0
- package/dist/modules/operations/src/operations/click.js +167 -0
- package/dist/modules/operations/src/operations/extract.js +204 -0
- package/dist/modules/operations/src/operations/find-child.js +17 -0
- package/dist/modules/operations/src/operations/highlight.js +138 -0
- package/dist/modules/operations/src/operations/key.js +61 -0
- package/dist/modules/operations/src/operations/navigate.js +148 -0
- package/dist/modules/operations/src/operations/scroll.js +126 -0
- package/dist/modules/operations/src/operations/type.js +190 -0
- package/dist/modules/operations/src/queue.js +100 -0
- package/dist/modules/operations/src/registry.js +11 -0
- package/dist/modules/operations/src/system/mouse.js +33 -0
- package/dist/modules/state/src/atomic-json.js +33 -0
- package/dist/modules/workflow/blocks/AnchorVerificationBlock.js +71 -0
- package/dist/modules/workflow/blocks/BehaviorRandomizer.js +26 -0
- package/dist/modules/workflow/blocks/CallWorkflowBlock.js +38 -0
- package/dist/modules/workflow/blocks/CloseDetailBlock.js +209 -0
- package/dist/modules/workflow/blocks/CollectBatch.js +137 -0
- package/dist/modules/workflow/blocks/CollectCommentsBlock.js +415 -0
- package/dist/modules/workflow/blocks/CollectSearchListBlock.js +599 -0
- package/dist/modules/workflow/blocks/CollectWeiboPosts.js +229 -0
- package/dist/modules/workflow/blocks/DetectPageStateBlock.js +259 -0
- package/dist/modules/workflow/blocks/EnsureLoginBlock.js +162 -0
- package/dist/modules/workflow/blocks/EnsureSession.js +426 -0
- package/dist/modules/workflow/blocks/ErrorClassifier.js +164 -0
- package/dist/modules/workflow/blocks/ErrorRecoveryBlock.js +319 -0
- package/dist/modules/workflow/blocks/ExpandCommentsBlock.js +1032 -0
- package/dist/modules/workflow/blocks/ExtractDetailBlock.js +310 -0
- package/dist/modules/workflow/blocks/ExtractPostFields.js +88 -0
- package/dist/modules/workflow/blocks/GenerateSmartReplyBlock.js +68 -0
- package/dist/modules/workflow/blocks/GoToSearchBlock.js +497 -0
- package/dist/modules/workflow/blocks/GracefulFallbackBlock.js +104 -0
- package/dist/modules/workflow/blocks/HighlightBlock.js +66 -0
- package/dist/modules/workflow/blocks/InitAutoScroll.js +65 -0
- package/dist/modules/workflow/blocks/LoadContainerDefinition.js +50 -0
- package/dist/modules/workflow/blocks/LoadContainerIndex.js +43 -0
- package/dist/modules/workflow/blocks/LocateAndGuardBlock.js +176 -0
- package/dist/modules/workflow/blocks/LoginRecoveryBlock.js +242 -0
- package/dist/modules/workflow/blocks/MatchContainers.js +64 -0
- package/dist/modules/workflow/blocks/MonitoringBlock.js +190 -0
- package/dist/modules/workflow/blocks/OpenDetailBlock.js +1240 -0
- package/dist/modules/workflow/blocks/OrganizeXhsNotesBlock.js +117 -0
- package/dist/modules/workflow/blocks/PersistXhsNoteBlock.js +270 -0
- package/dist/modules/workflow/blocks/PickSinglePost.js +69 -0
- package/dist/modules/workflow/blocks/ProgressTracker.js +125 -0
- package/dist/modules/workflow/blocks/RecordFixtureBlock.js +44 -0
- package/dist/modules/workflow/blocks/RenderMarkdown.js +48 -0
- package/dist/modules/workflow/blocks/SaveFile.js +54 -0
- package/dist/modules/workflow/blocks/ScrollNextBatch.js +72 -0
- package/dist/modules/workflow/blocks/SessionHealthBlock.js +73 -0
- package/dist/modules/workflow/blocks/StartBrowserService.js +45 -0
- package/dist/modules/workflow/blocks/ValidateContainerDefinition.js +67 -0
- package/dist/modules/workflow/blocks/ValidateExtract.js +35 -0
- package/dist/modules/workflow/blocks/WaitSearchPermitBlock.js +162 -0
- package/dist/modules/workflow/blocks/WaitStable.js +74 -0
- package/dist/modules/workflow/blocks/WarmupCommentsBlock.js +120 -0
- package/dist/modules/workflow/blocks/WorkflowExecutor.js +156 -0
- package/dist/modules/workflow/blocks/XiaohongshuCollectFromLinksBlock.js +1004 -0
- package/dist/modules/workflow/blocks/XiaohongshuCollectLinksBlock.js +1049 -0
- package/dist/modules/workflow/blocks/XiaohongshuFullCollectBlock.js +782 -0
- package/dist/modules/workflow/blocks/helpers/anchorVerify.js +198 -0
- package/dist/modules/workflow/blocks/helpers/asyncWorkQueue.js +53 -0
- package/dist/modules/workflow/blocks/helpers/commentScroller.js +334 -0
- package/dist/modules/workflow/blocks/helpers/commentSectionLocator.js +126 -0
- package/dist/modules/workflow/blocks/helpers/containerAnchors.js +301 -0
- package/dist/modules/workflow/blocks/helpers/debugArtifacts.js +6 -0
- package/dist/modules/workflow/blocks/helpers/downloadPaths.js +29 -0
- package/dist/modules/workflow/blocks/helpers/expandCommentsController.js +53 -0
- package/dist/modules/workflow/blocks/helpers/expandCommentsExtractor.js +129 -0
- package/dist/modules/workflow/blocks/helpers/macosVisionOcrPlugin.js +116 -0
- package/dist/modules/workflow/blocks/helpers/mergeXhsMarkdown.js +109 -0
- package/dist/modules/workflow/blocks/helpers/openDetailController.js +56 -0
- package/dist/modules/workflow/blocks/helpers/openDetailTypes.js +7 -0
- package/dist/modules/workflow/blocks/helpers/openDetailViewport.js +474 -0
- package/dist/modules/workflow/blocks/helpers/openDetailWaiter.js +104 -0
- package/dist/modules/workflow/blocks/helpers/operationLogger.js +195 -0
- package/dist/modules/workflow/blocks/helpers/persistedNotes.js +107 -0
- package/dist/modules/workflow/blocks/helpers/replyExpander.js +260 -0
- package/dist/modules/workflow/blocks/helpers/scrollIntoView.js +138 -0
- package/dist/modules/workflow/blocks/helpers/searchExecutor.js +328 -0
- package/dist/modules/workflow/blocks/helpers/searchGate.js +46 -0
- package/dist/modules/workflow/blocks/helpers/searchPageState.js +164 -0
- package/dist/modules/workflow/blocks/helpers/searchResultWaiter.js +64 -0
- package/dist/modules/workflow/blocks/helpers/simpleAnchor.js +134 -0
- package/dist/modules/workflow/blocks/helpers/smartReply.js +40 -0
- package/dist/modules/workflow/blocks/helpers/systemInput.js +635 -0
- package/dist/modules/workflow/blocks/helpers/targetCountMode.js +9 -0
- package/dist/modules/workflow/blocks/helpers/xhsCliArgs.js +80 -0
- package/dist/modules/workflow/blocks/helpers/xhsCommentDom.js +805 -0
- package/dist/modules/workflow/blocks/helpers/xhsNoteOrganizer.js +140 -0
- package/dist/modules/workflow/blocks/restore/RestorePhaseBlock.js +204 -0
- package/dist/modules/workflow/config/workflowRegistry.js +32 -0
- package/dist/modules/workflow/definitions/batch-collect-workflow.js +63 -0
- package/dist/modules/workflow/definitions/scroll-extract-workflow.js +74 -0
- package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow-v2.js +81 -0
- package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow.js +57 -0
- package/dist/modules/workflow/definitions/xiaohongshu-full-collect-workflow-v3.js +68 -0
- package/dist/modules/workflow/definitions/xiaohongshu-note-collect.js +49 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase1-workflow-v3.js +30 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase2-links-workflow-v3.js +40 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase3-collect-workflow-v1.js +54 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase34-from-links-workflow-v3.js +25 -0
- package/dist/modules/workflow/src/WeiboEventDrivenWorkflowRunner.js +308 -0
- package/dist/modules/workflow/src/context.js +70 -0
- package/dist/modules/workflow/src/index.js +5 -0
- package/dist/modules/workflow/src/orchestrator.js +230 -0
- package/dist/modules/workflow/src/runner.js +55 -0
- package/dist/modules/workflow/src/runtime.js +70 -0
- package/dist/modules/workflow/workflows/WeiboFeedExtractionWorkflow.js +359 -0
- package/dist/modules/workflow/workflows/XiaohongshuLoginWorkflow.js +110 -0
- package/dist/modules/xiaohongshu/app/src/blocks/MatchCommentsBlock.js +139 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1EnsureServicesBlock.js +36 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1MonitorCookieBlock.js +213 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1StartProfileBlock.js +121 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase2CollectLinksBlock.js +1249 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase2SearchBlock.js +703 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseDetailBlock.js +41 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseTabsBlock.js +44 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CollectCommentsBlock.js +150 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ExtractDetailBlock.js +117 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenDetailBlock.js +102 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenTabsBlock.js +109 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34PersistDetailBlock.js +117 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ProcessSingleNoteBlock.js +114 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ValidateLinksBlock.js +90 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase3InteractBlock.js +1009 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase4MultiTabHarvestBlock.js +233 -0
- package/dist/modules/xiaohongshu/app/src/blocks/ReplyInteractBlock.js +291 -0
- package/dist/modules/xiaohongshu/app/src/blocks/XhsDiscoverFallbackBlock.js +240 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatchDsl.js +126 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatcher.js +99 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/evidence.js +27 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/sharding.js +42 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/xhsComments.js +270 -0
- package/dist/modules/xiaohongshu/app/src/index.js +9 -0
- package/dist/modules/xiaohongshu/app/src/utils/checkpoints.js +222 -0
- package/dist/modules/xiaohongshu/app/src/utils/controllerAction.js +43 -0
- package/dist/services/controller/src/controller.js +1476 -0
- package/dist/services/controller/src/index.js +2 -0
- package/dist/services/controller/src/payload-normalizer.js +129 -0
- package/dist/services/shared/heartbeat.js +120 -0
- package/dist/services/shared/lib/errorHandler.js +2 -0
- package/dist/services/shared/serviceProcessLogger.js +139 -0
- package/dist/services/unified-api/RemoteBrowserSession.js +176 -0
- package/dist/services/unified-api/RemoteSessionManager.js +148 -0
- package/dist/services/unified-api/container-operations-handler.js +115 -0
- package/dist/services/unified-api/server.js +652 -0
- package/dist/services/unified-api/state-registry.js +274 -0
- package/dist/services/unified-api/task-persistence.js +66 -0
- package/dist/services/unified-api/task-state.js +130 -0
- package/modules/camo-runtime/src/autoscript/action-providers/xhs/search.mjs +12 -5
- package/modules/xiaohongshu/app/pnpm-lock.yaml +24 -0
- package/package.json +38 -10
- package/.beads/README.md +0 -81
- package/.beads/config.yaml +0 -67
- package/.beads/interactions.jsonl +0 -0
- package/.beads/issues.jsonl +0 -180
- package/.beads/metadata.json +0 -4
- package/.claude/settings.local.json +0 -10
- package/.github/workflows/ci.yml +0 -55
- package/AGENTS.md +0 -253
- package/apps/desktop-console/README.md +0 -27
- package/apps/desktop-console/package-lock.json +0 -897
- package/apps/desktop-console/package.json +0 -20
- package/apps/desktop-console/scripts/build-and-install.mjs +0 -19
- package/apps/desktop-console/scripts/build.mjs +0 -45
- package/apps/desktop-console/scripts/test-preload.mjs +0 -13
- package/apps/desktop-console/src/main/config.mts +0 -26
- package/apps/desktop-console/src/main/core-daemon-manager.mts +0 -131
- package/apps/desktop-console/src/main/desktop-settings.mts +0 -267
- package/apps/desktop-console/src/main/heartbeat-watchdog.mts +0 -50
- package/apps/desktop-console/src/main/heartbeat-watchdog.test.mts +0 -68
- package/apps/desktop-console/src/main/index-streaming.test.mts +0 -20
- package/apps/desktop-console/src/main/index.mts +0 -980
- package/apps/desktop-console/src/main/profile-store.mts +0 -239
- package/apps/desktop-console/src/main/profile-store.test.mts +0 -54
- package/apps/desktop-console/src/main/state-bridge.mts +0 -114
- package/apps/desktop-console/src/main/task-state-types.ts +0 -32
- package/apps/desktop-console/src/renderer/hooks/use-task-state.mts +0 -120
- package/apps/desktop-console/src/renderer/index.mts +0 -133
- package/apps/desktop-console/src/renderer/index.test.mts +0 -34
- package/apps/desktop-console/src/renderer/path-helpers.mts +0 -46
- package/apps/desktop-console/src/renderer/path-helpers.test.mts +0 -14
- package/apps/desktop-console/src/renderer/tabs/debug.mts +0 -48
- package/apps/desktop-console/src/renderer/tabs/debug.test.mts +0 -22
- package/apps/desktop-console/src/renderer/tabs/logs.mts +0 -421
- package/apps/desktop-console/src/renderer/tabs/logs.test.mts +0 -27
- package/apps/desktop-console/src/renderer/tabs/preflight.mts +0 -486
- package/apps/desktop-console/src/renderer/tabs/preflight.test.mts +0 -33
- package/apps/desktop-console/src/renderer/tabs/profile-pool.mts +0 -213
- package/apps/desktop-console/src/renderer/tabs/results.mts +0 -171
- package/apps/desktop-console/src/renderer/tabs/run.test.mts +0 -63
- package/apps/desktop-console/src/renderer/tabs/runtime.mts +0 -151
- package/apps/desktop-console/src/renderer/tabs/settings.mts +0 -146
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/account-flow.mts +0 -486
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/guide-browser-check.mts +0 -56
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/helpers.mts +0 -262
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/layout-block.mts +0 -430
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/live-stats.mts +0 -847
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/run-flow.mts +0 -443
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu-state.mts +0 -425
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu.mts +0 -497
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu.test.mts +0 -291
- package/apps/desktop-console/src/renderer/ui-components.mts +0 -31
- package/docs/README_camoufox_chinese.md +0 -141
- package/docs/USAGE_V3.md +0 -163
- package/docs/arch/OCR_MACOS_PLUGIN.md +0 -39
- package/docs/arch/PORTS.md +0 -40
- package/docs/arch/REGRESSION_CHECKLIST.md +0 -121
- package/docs/arch/SEARCH_GATE.md +0 -224
- package/docs/arch/VIEWPORT_SAFETY.md +0 -182
- package/docs/arch/XIAOHONGSHU_OFFLINE_MOCK_DESIGN.md +0 -267
- package/docs/xiaohongshu-container-driven-summary.md +0 -221
- package/docs/xiaohongshu-full-collect-runbook.md +0 -134
- package/docs/xiaohongshu-next-steps.md +0 -228
- package/docs/xiaohongshu-quickstart.md +0 -73
- package/docs/xiaohongshu-workflow-summary.md +0 -227
- package/modules/container-registry/tests/container-registry.test.ts +0 -16
- package/modules/logging/tests/logging.test.ts +0 -38
- package/modules/operations/tests/operations.test.ts +0 -22
- package/modules/operations/tests/viewport-filter.test.ts +0 -161
- package/modules/operations/tests/visible-only.test.ts +0 -250
- package/modules/session-manager/tests/session-manager.test.ts +0 -23
- package/modules/state/src/atomic-json.test.ts +0 -30
- package/modules/state/src/paths.test.ts +0 -59
- package/modules/state/src/xiaohongshu-collect-state.test.ts +0 -259
- package/modules/workflow/blocks/AnchorVerificationBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/AnchorVerificationBlock.js.map +0 -1
- package/modules/workflow/blocks/DetectPageStateBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/DetectPageStateBlock.js.map +0 -1
- package/modules/workflow/blocks/ErrorRecoveryBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/ErrorRecoveryBlock.js.map +0 -1
- package/modules/workflow/blocks/WaitSearchPermitBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/WaitSearchPermitBlock.js.map +0 -1
- package/modules/workflow/blocks/helpers/containerAnchors.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/containerAnchors.js.map +0 -1
- package/modules/workflow/blocks/helpers/downloadPaths.test.ts +0 -62
- package/modules/workflow/blocks/helpers/mergeXhsMarkdown.test.ts +0 -121
- package/modules/workflow/blocks/helpers/operationLogger.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/operationLogger.js.map +0 -1
- package/modules/workflow/blocks/helpers/persistedNotes.test.ts +0 -268
- package/modules/workflow/blocks/helpers/searchPageState.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/searchPageState.js.map +0 -1
- package/modules/workflow/blocks/helpers/targetCountMode.test.ts +0 -29
- package/modules/workflow/blocks/helpers/xhsCliArgs.test.ts +0 -75
- package/modules/workflow/tests/smartReply.test.ts +0 -32
- package/modules/xiaohongshu/app/src/blocks/Phase3Interact.matcher.test.ts +0 -33
- package/modules/xiaohongshu/app/src/utils/__tests__/checkpoints.test.ts +0 -141
- package/modules/xiaohongshu/app/tests/commentMatchDsl.test.ts +0 -50
- package/modules/xiaohongshu/app/tests/commentMatcher.test.ts +0 -46
- package/modules/xiaohongshu/app/tests/sharding.test.ts +0 -31
- package/package-scripts.json +0 -8
- package/runtime/infra/utils/README.md +0 -13
- package/runtime/infra/utils/scripts/README.md +0 -0
- package/runtime/infra/utils/scripts/development/eval-in-session.mjs +0 -40
- package/runtime/infra/utils/scripts/development/highlight-search-containers.mjs +0 -35
- package/runtime/infra/utils/scripts/service/kill-port.mjs +0 -24
- package/runtime/infra/utils/scripts/service/start-api.mjs +0 -39
- package/runtime/infra/utils/scripts/service/start-browser-service.mjs +0 -106
- package/runtime/infra/utils/scripts/service/stop-api.mjs +0 -18
- package/runtime/infra/utils/scripts/service/stop-browser-service.mjs +0 -104
- package/runtime/infra/utils/scripts/test-services.mjs +0 -94
- package/services/shared/heartbeat.test.ts +0 -102
- package/services/unified-api/__tests__/task-state.test.ts +0 -95
- package/sitecustomize.py +0 -19
- package/tests/README.md +0 -194
- package/tests/e2e/workflows/weibo-feed-extraction.test.ts +0 -171
- package/tests/fixtures/data/container-definitions.json +0 -67
- package/tests/fixtures/pages/simple-page.html +0 -69
- package/tests/integration/01-test-container-match.mjs +0 -188
- package/tests/integration/02-test-dom-branch.mjs +0 -161
- package/tests/integration/03-test-container-operation-system.mjs +0 -91
- package/tests/integration/05-test-container-lifecycle-events.mjs +0 -224
- package/tests/integration/05-test-container-lifecycle-with-events.mjs +0 -250
- package/tests/integration/06-test-container-dom-tree-drawing.mjs +0 -256
- package/tests/integration/07-test-weibo-container-lifecycle.mjs +0 -355
- package/tests/integration/08-test-weibo-feed-workflow.test.mjs +0 -164
- package/tests/integration/10-test-visual-analyzer.mjs +0 -312
- package/tests/integration/11-test-visual-loop.mjs +0 -284
- package/tests/integration/12-test-simple-visual-loop.mjs +0 -242
- package/tests/integration/13-test-visual-robust.mjs +0 -185
- package/tests/integration/14-test-visual-highlight-loop.mjs +0 -271
- package/tests/integration/inspect-page.mjs +0 -50
- package/tests/integration/run-all-tests.mjs +0 -95
- package/tests/patch_verification/CODEX_PATCH_TEST.md +0 -103
- package/tests/patch_verification/PHASE2_ANALYSIS.md +0 -179
- package/tests/patch_verification/PHASE2_OPTIMIZATION_REPORT.md +0 -55
- package/tests/patch_verification/PHASE2_TO_PHASE4_SUMMARY.md +0 -126
- package/tests/patch_verification/QUICK_TEST_SEQUENCE.md +0 -262
- package/tests/patch_verification/README.md +0 -143
- package/tests/patch_verification/RUN_TESTS.md +0 -60
- package/tests/patch_verification/TEST_EXECUTION.md +0 -99
- package/tests/patch_verification/TEST_PLAN.md +0 -328
- package/tests/patch_verification/TEST_RESULTS.md +0 -34
- package/tests/patch_verification/TOOL_TEST_PLAN.md +0 -48
- package/tests/patch_verification/run-tool-test.mjs +0 -121
- package/tests/patch_verification/temp_test_files/test01.txt +0 -1
- package/tests/patch_verification/temp_test_files/test02.txt +0 -3
- package/tests/patch_verification/temp_test_files/test02_gnu.txt +0 -3
- package/tests/patch_verification/temp_test_files/test03.txt +0 -1
- package/tests/patch_verification/temp_test_files/test03_multiline.txt +0 -5
- package/tests/patch_verification/temp_test_files/test04_function.ts +0 -5
- package/tests/patch_verification/temp_test_files/test05_import.ts +0 -4
- package/tests/patch_verification/temp_test_files/test06_special_chars.txt +0 -4
- package/tests/patch_verification/temp_test_files/test07_indentation.ts +0 -5
- package/tests/patch_verification/temp_test_files/test08_mismatch.txt +0 -1
- package/tests/patch_verification/temp_test_files/test_add_02.txt +0 -3
- package/tests/patch_verification/temp_test_files/test_simple.txt +0 -1
- package/tests/runner/TestReporter.mjs +0 -57
- package/tests/runner/TestRunner.mjs +0 -244
- package/tests/unit/commands/profile.test.mjs +0 -10
- package/tests/unit/container/change-notifier.test.mjs +0 -181
- package/tests/unit/lifecycle/session-registry.test.mjs +0 -135
- package/tests/unit/operations/registry.test.ts +0 -73
- package/tests/unit/utils/browser-service.test.mjs +0 -153
- package/tests/unit/utils/config.test.mjs +0 -166
- package/tests/unit/utils/fingerprint.test.mjs +0 -166
- package/tsconfig.json +0 -31
- package/tsconfig.services.json +0 -26
- /package/apps/desktop-console/{src → dist}/renderer/index.html +0 -0
- /package/apps/desktop-console/{src/renderer/tabs → dist/renderer}/run.mts +0 -0
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* 视觉分析器测试 - 测试坐标定位反查 DOM 的可靠性
|
|
4
|
-
*
|
|
5
|
-
* 测试流程:
|
|
6
|
-
* 1. 获取页面上已知元素的边界框
|
|
7
|
-
* 2. 通过坐标反查 DOM 元素
|
|
8
|
-
* 3. 验证反查结果是否正确
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import assert from 'node:assert/strict';
|
|
12
|
-
import http from 'node:http';
|
|
13
|
-
|
|
14
|
-
const UNIFIED_API = 'http://127.0.0.1:7701';
|
|
15
|
-
const PROFILE = 'weibo_fresh';
|
|
16
|
-
|
|
17
|
-
function log(msg) {
|
|
18
|
-
console.log(`[visual-analyzer-test] ${msg}`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function httpPost(path, data) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
const payload = JSON.stringify(data);
|
|
24
|
-
const req = http.request(
|
|
25
|
-
`${UNIFIED_API}${path}`,
|
|
26
|
-
{
|
|
27
|
-
method: 'POST',
|
|
28
|
-
headers: {
|
|
29
|
-
'Content-Type': 'application/json',
|
|
30
|
-
'Content-Length': Buffer.byteLength(payload)
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
(res) => {
|
|
34
|
-
let body = '';
|
|
35
|
-
res.on('data', (chunk) => body += chunk);
|
|
36
|
-
res.on('end', () => {
|
|
37
|
-
try {
|
|
38
|
-
resolve(JSON.parse(body));
|
|
39
|
-
} catch (err) {
|
|
40
|
-
resolve({ body, statusCode: res.statusCode });
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
req.on('error', reject);
|
|
46
|
-
req.write(payload);
|
|
47
|
-
req.end();
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function httpGet(path) {
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
http.get(`${UNIFIED_API}${path}`, (res) => {
|
|
54
|
-
let body = '';
|
|
55
|
-
res.on('data', (chunk) => body += chunk);
|
|
56
|
-
res.on('end', () => {
|
|
57
|
-
try {
|
|
58
|
-
resolve(JSON.parse(body));
|
|
59
|
-
} catch (err) {
|
|
60
|
-
resolve({ body, statusCode: res.statusCode });
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}).on('error', reject);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 测试 1: 获取已知元素的边界框
|
|
69
|
-
*/
|
|
70
|
-
async function testGetElementBounds() {
|
|
71
|
-
log('Test 1: 获取已知元素的边界框');
|
|
72
|
-
|
|
73
|
-
const result = await httpPost('/v1/controller/action', {
|
|
74
|
-
action: 'browser:execute',
|
|
75
|
-
payload: {
|
|
76
|
-
profile: PROFILE,
|
|
77
|
-
script: `
|
|
78
|
-
(function() {
|
|
79
|
-
// 获取多个不同类型的元素
|
|
80
|
-
const elements = [
|
|
81
|
-
{ name: 'body', selector: 'body' },
|
|
82
|
-
{ name: 'main', selector: 'main' },
|
|
83
|
-
{ name: 'first-article', selector: 'article:first-of-type' },
|
|
84
|
-
{ name: 'first-link', selector: 'a:first-of-type' }
|
|
85
|
-
];
|
|
86
|
-
|
|
87
|
-
return elements.map(e => {
|
|
88
|
-
const el = document.querySelector(e.selector);
|
|
89
|
-
if (!el) return null;
|
|
90
|
-
|
|
91
|
-
const rect = el.getBoundingClientRect();
|
|
92
|
-
return {
|
|
93
|
-
name: e.name,
|
|
94
|
-
selector: e.selector,
|
|
95
|
-
bounds: {
|
|
96
|
-
x: Math.round(rect.x),
|
|
97
|
-
y: Math.round(rect.y),
|
|
98
|
-
width: Math.round(rect.width),
|
|
99
|
-
height: Math.round(rect.height)
|
|
100
|
-
},
|
|
101
|
-
center: {
|
|
102
|
-
x: Math.round(rect.x + rect.width / 2),
|
|
103
|
-
y: Math.round(rect.y + rect.height / 2)
|
|
104
|
-
},
|
|
105
|
-
tagName: el.tagName.toLowerCase(),
|
|
106
|
-
className: el.className || '',
|
|
107
|
-
id: el.id || ''
|
|
108
|
-
};
|
|
109
|
-
}).filter(e => e !== null);
|
|
110
|
-
})()
|
|
111
|
-
`
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
if (!result.success || !result.data) {
|
|
116
|
-
log(' ✗ 获取失败');
|
|
117
|
-
log(` success: ${result.success}`);
|
|
118
|
-
log(` data: ${JSON.stringify(result.data)}`);
|
|
119
|
-
throw new Error('Failed to get element bounds');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// 修复:检查返回数据结构
|
|
123
|
-
let elements = result.data;
|
|
124
|
-
if (elements && elements.result) {
|
|
125
|
-
// 如果返回的是 { result: [...] } 结构
|
|
126
|
-
elements = elements.result;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!Array.isArray(elements)) {
|
|
130
|
-
log(' ✗ 返回数据不是数组');
|
|
131
|
-
log(` type: ${typeof elements}`);
|
|
132
|
-
log(` value: ${JSON.stringify(elements)}`);
|
|
133
|
-
return [];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
log(` ✓ 获取了 ${elements.length} 个元素的边界框`);
|
|
137
|
-
|
|
138
|
-
elements.forEach(el => {
|
|
139
|
-
log(` - ${el.name}: ${el.tagName} @ (${el.center.x}, ${el.center.y})`);
|
|
140
|
-
log(` bounds: ${el.bounds.width}x${el.bounds.height}`);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
return elements;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* 测试 2: 通过坐标反查 DOM 元素
|
|
148
|
-
*/
|
|
149
|
-
async function testFindElementByCoordinates(elements) {
|
|
150
|
-
log('\nTest 2: 通过坐标反查 DOM 元素');
|
|
151
|
-
|
|
152
|
-
const results = [];
|
|
153
|
-
|
|
154
|
-
for (const el of elements) {
|
|
155
|
-
const { x, y } = el.center;
|
|
156
|
-
|
|
157
|
-
const result = await httpPost('/v1/controller/action', {
|
|
158
|
-
action: 'browser:execute',
|
|
159
|
-
payload: {
|
|
160
|
-
profile: PROFILE,
|
|
161
|
-
script: `
|
|
162
|
-
(function() {
|
|
163
|
-
const element = document.elementFromPoint(${x}, ${y});
|
|
164
|
-
if (!element) return null;
|
|
165
|
-
|
|
166
|
-
// 生成选择器
|
|
167
|
-
function getSelector(el) {
|
|
168
|
-
if (el.id) return '#' + el.id;
|
|
169
|
-
|
|
170
|
-
let selector = el.tagName.toLowerCase();
|
|
171
|
-
|
|
172
|
-
// 添加 class
|
|
173
|
-
if (el.className && typeof el.className === 'string') {
|
|
174
|
-
const classes = el.className.split(' ').filter(c => c && c.length > 0);
|
|
175
|
-
if (classes.length > 0) {
|
|
176
|
-
// 使用属性选择器匹配动态 class
|
|
177
|
-
const stableClass = classes.find(c => !(/[A-Z0-9]{5,}/.test(c)));
|
|
178
|
-
if (stableClass) {
|
|
179
|
-
selector += '.' + stableClass;
|
|
180
|
-
} else {
|
|
181
|
-
const prefix = classes[0].replace(/[_-][A-Z0-9]+$/, '');
|
|
182
|
-
selector += '[class*="' + prefix + '"]';
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return selector;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// 验证元素是否可见
|
|
191
|
-
function isVisible(el) {
|
|
192
|
-
const style = window.getComputedStyle(el);
|
|
193
|
-
return style.display !== 'none' &&
|
|
194
|
-
style.visibility !== 'hidden' &&
|
|
195
|
-
parseFloat(style.opacity) > 0;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return {
|
|
199
|
-
selector: getSelector(element),
|
|
200
|
-
tagName: element.tagName.toLowerCase(),
|
|
201
|
-
className: element.className || '',
|
|
202
|
-
id: element.id || '',
|
|
203
|
-
textContent: (element.textContent || '').substring(0, 100),
|
|
204
|
-
isVisible: isVisible(element),
|
|
205
|
-
rect: {
|
|
206
|
-
x: Math.round(element.getBoundingClientRect().x),
|
|
207
|
-
y: Math.round(element.getBoundingClientRect().y),
|
|
208
|
-
width: Math.round(element.getBoundingClientRect().width),
|
|
209
|
-
height: Math.round(element.getBoundingClientRect().height)
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
})()
|
|
213
|
-
`
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
if (!result.success || !result.data) {
|
|
218
|
-
log(` ✗ 坐标 (${x}, ${y}) 反查失败`);
|
|
219
|
-
results.push({ original: el, found: null, matched: false });
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const found = result.data;
|
|
224
|
-
|
|
225
|
-
// 验证是否匹配
|
|
226
|
-
const matched = found.tagName === el.tagName;
|
|
227
|
-
|
|
228
|
-
log(` ${matched ? '✓' : '✗'} 原始: ${el.name} (${el.tagName})`);
|
|
229
|
-
log(` 坐标: (${x}, ${y})`);
|
|
230
|
-
log(` 反查: ${found.tagName}`);
|
|
231
|
-
log(` 选择器: ${found.selector}`);
|
|
232
|
-
log(` 可见: ${found.isVisible}`);
|
|
233
|
-
|
|
234
|
-
if (!matched) {
|
|
235
|
-
log(` ⚠️ 标签不匹配!期望 ${el.tagName},实际 ${found.tagName}`);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
results.push({ original: el, found, matched });
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return results;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async function main() {
|
|
245
|
-
try {
|
|
246
|
-
log('========================================');
|
|
247
|
-
log('视觉分析器可靠性测试');
|
|
248
|
-
log('========================================\n');
|
|
249
|
-
|
|
250
|
-
// 检查服务健康
|
|
251
|
-
log('检查服务健康...');
|
|
252
|
-
const health = await httpGet('/health');
|
|
253
|
-
if (!health.ok) {
|
|
254
|
-
throw new Error('服务不健康,请先启动: node scripts/start-headful.mjs');
|
|
255
|
-
}
|
|
256
|
-
log(' ✓ 服务正常\n');
|
|
257
|
-
|
|
258
|
-
// 测试 1: 获取元素边界框
|
|
259
|
-
const elements = await testGetElementBounds();
|
|
260
|
-
|
|
261
|
-
if (elements.length === 0) {
|
|
262
|
-
log('\n⚠️ 无法获取元素,可能页面未完全加载');
|
|
263
|
-
process.exit(1);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// 测试 2: 坐标反查 DOM
|
|
267
|
-
const results = await testFindElementByCoordinates(elements);
|
|
268
|
-
|
|
269
|
-
// 统计结果
|
|
270
|
-
log('\n========================================');
|
|
271
|
-
log('测试结果统计');
|
|
272
|
-
log('========================================');
|
|
273
|
-
|
|
274
|
-
const matchedCount = results.filter(r => r.matched).length;
|
|
275
|
-
const totalCount = results.length;
|
|
276
|
-
const accuracy = totalCount > 0 ? (matchedCount / totalCount * 100).toFixed(1) : 0;
|
|
277
|
-
|
|
278
|
-
log(`总测试数: ${totalCount}`);
|
|
279
|
-
log(`匹配成功: ${matchedCount}`);
|
|
280
|
-
log(`匹配失败: ${totalCount - matchedCount}`);
|
|
281
|
-
log(`准确率: ${accuracy}%`);
|
|
282
|
-
|
|
283
|
-
if (accuracy < 80) {
|
|
284
|
-
log('\n⚠️ 警告: 准确率低于 80%,坐标定位可能不够可靠');
|
|
285
|
-
} else if (accuracy < 100) {
|
|
286
|
-
log('\n✓ 通过: 准确率 >= 80%,基本可靠');
|
|
287
|
-
} else {
|
|
288
|
-
log('\n✅ 完美: 准确率 100%,非常可靠');
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
log('\n========================================');
|
|
292
|
-
log('结论');
|
|
293
|
-
log('========================================');
|
|
294
|
-
|
|
295
|
-
if (accuracy >= 80) {
|
|
296
|
-
log('✅ 坐标定位反查 DOM 的方式是可靠的');
|
|
297
|
-
log(' 可以用于视觉分析器的 DOM 元素识别');
|
|
298
|
-
} else {
|
|
299
|
-
log('❌ 坐标定位反查 DOM 的方式不够可靠');
|
|
300
|
-
log(' 建议优化选择器生成逻辑或使用其他方法');
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
process.exit(accuracy >= 80 ? 0 : 1);
|
|
304
|
-
|
|
305
|
-
} catch (error) {
|
|
306
|
-
console.error('\n❌ 测试失败:', error.message);
|
|
307
|
-
if (error.stack) console.error(error.stack);
|
|
308
|
-
process.exit(1);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
main();
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* 视觉回环测试
|
|
4
|
-
* 流程:
|
|
5
|
-
* 1) 选择已知目标元素并标记(data-wa-target)
|
|
6
|
-
* 2) 获取目标元素的边界框并绘制标记框
|
|
7
|
-
* 3) 根据坐标反查 DOM(elementFromPoint)
|
|
8
|
-
* 4) 高亮反查的 DOM
|
|
9
|
-
* 5) 验证反查结果与原目标一致
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import assert from 'node:assert/strict';
|
|
13
|
-
import http from 'node:http';
|
|
14
|
-
import fs from 'node:fs/promises';
|
|
15
|
-
import path from 'node:path';
|
|
16
|
-
|
|
17
|
-
const UNIFIED_API = 'http://127.0.0.1:7701';
|
|
18
|
-
const PROFILE = 'weibo_fresh';
|
|
19
|
-
|
|
20
|
-
function log(msg) {
|
|
21
|
-
console.log(`[visual-loop-test] ${msg}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function httpPost(pathname, data) {
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
const payload = JSON.stringify(data);
|
|
27
|
-
const req = http.request(
|
|
28
|
-
`${UNIFIED_API}${pathname}`,
|
|
29
|
-
{
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
'Content-Length': Buffer.byteLength(payload)
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
(res) => {
|
|
37
|
-
let body = '';
|
|
38
|
-
res.on('data', (chunk) => body += chunk);
|
|
39
|
-
res.on('end', () => {
|
|
40
|
-
try {
|
|
41
|
-
resolve(JSON.parse(body));
|
|
42
|
-
} catch (err) {
|
|
43
|
-
resolve({ body, statusCode: res.statusCode });
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
req.on('error', reject);
|
|
49
|
-
req.write(payload);
|
|
50
|
-
req.end();
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function httpGet(pathname) {
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
http.get(`${UNIFIED_API}${pathname}`, (res) => {
|
|
57
|
-
let body = '';
|
|
58
|
-
res.on('data', (chunk) => body += chunk);
|
|
59
|
-
res.on('end', () => {
|
|
60
|
-
try {
|
|
61
|
-
resolve(JSON.parse(body));
|
|
62
|
-
} catch (err) {
|
|
63
|
-
resolve({ body, statusCode: res.statusCode });
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}).on('error', reject);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function execBrowser(script) {
|
|
71
|
-
const result = await httpPost('/v1/controller/action', {
|
|
72
|
-
action: 'browser:execute',
|
|
73
|
-
payload: { profile: PROFILE, script }
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
if (!result.success) {
|
|
77
|
-
throw new Error(`browser:execute failed: ${JSON.stringify(result)}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return result.data;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async function highlightSelector(selector, label) {
|
|
84
|
-
await httpPost('/v1/controller/action', {
|
|
85
|
-
action: 'browser:highlight',
|
|
86
|
-
payload: {
|
|
87
|
-
profile: PROFILE,
|
|
88
|
-
selector,
|
|
89
|
-
options: {
|
|
90
|
-
style: '3px solid #00C853',
|
|
91
|
-
duration: 2000,
|
|
92
|
-
sticky: false,
|
|
93
|
-
label
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function main() {
|
|
100
|
-
try {
|
|
101
|
-
log('========================================');
|
|
102
|
-
log('视觉回环测试(标记->坐标->DOM)');
|
|
103
|
-
log('========================================\n');
|
|
104
|
-
|
|
105
|
-
// 健康检查
|
|
106
|
-
const health = await httpGet('/health');
|
|
107
|
-
if (!health.ok) {
|
|
108
|
-
throw new Error('服务不健康,请先启动: node scripts/start-headful.mjs');
|
|
109
|
-
}
|
|
110
|
-
log('✓ 服务正常');
|
|
111
|
-
|
|
112
|
-
// Step 1: 标记目标元素并获取边界框
|
|
113
|
-
log('Step 1: 标记目标元素并获取边界框');
|
|
114
|
-
const targets = await execBrowser(`
|
|
115
|
-
(function() {
|
|
116
|
-
window.scrollTo(0, 0);
|
|
117
|
-
|
|
118
|
-
const candidates = [
|
|
119
|
-
{ name: 'feed-list', selector: "main[class*='Main_wrap_'] div[class*='Home_feed_']" },
|
|
120
|
-
{ name: 'first-post', selector: "article[class*='Feed_wrap_']" },
|
|
121
|
-
{ name: 'author-link', selector: "header a[href*='weibo.com']" }
|
|
122
|
-
];
|
|
123
|
-
|
|
124
|
-
const targets = [];
|
|
125
|
-
|
|
126
|
-
candidates.forEach((c, idx) => {
|
|
127
|
-
const el = document.querySelector(c.selector);
|
|
128
|
-
if (!el) return;
|
|
129
|
-
el.scrollIntoView({ behavior: 'instant', block: 'center' });
|
|
130
|
-
el.setAttribute('data-wa-target', c.name);
|
|
131
|
-
|
|
132
|
-
const rect = el.getBoundingClientRect();
|
|
133
|
-
targets.push({
|
|
134
|
-
name: c.name,
|
|
135
|
-
selector: c.selector,
|
|
136
|
-
tagName: el.tagName.toLowerCase(),
|
|
137
|
-
bounds: {
|
|
138
|
-
x: Math.round(rect.x),
|
|
139
|
-
y: Math.round(rect.y),
|
|
140
|
-
width: Math.round(rect.width),
|
|
141
|
-
height: Math.round(rect.height)
|
|
142
|
-
},
|
|
143
|
-
center: {
|
|
144
|
-
x: Math.round(rect.x + rect.width / 2),
|
|
145
|
-
y: Math.round(rect.y + rect.height / 2)
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
return targets;
|
|
151
|
-
})();
|
|
152
|
-
`);
|
|
153
|
-
|
|
154
|
-
if (!Array.isArray(targets) || targets.length === 0) {
|
|
155
|
-
throw new Error('未找到任何目标元素');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
targets.forEach(t => {
|
|
159
|
-
log(` - ${t.name}: ${t.selector} @ (${t.center.x}, ${t.center.y})`);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
// Step 2: 绘制标记框
|
|
163
|
-
log('Step 2: 绘制标记框');
|
|
164
|
-
await execBrowser(`
|
|
165
|
-
(function() {
|
|
166
|
-
document.querySelectorAll('.wa-visual-loop-box').forEach(el => el.remove());
|
|
167
|
-
const targets = ${JSON.stringify(targets)};
|
|
168
|
-
targets.forEach(t => {
|
|
169
|
-
const div = document.createElement('div');
|
|
170
|
-
div.className = 'wa-visual-loop-box';
|
|
171
|
-
div.style.cssText =
|
|
172
|
-
'position: fixed;' +
|
|
173
|
-
'left: ' + t.bounds.x + 'px;' +
|
|
174
|
-
'top: ' + t.bounds.y + 'px;' +
|
|
175
|
-
'width: ' + t.bounds.width + 'px;' +
|
|
176
|
-
'height: ' + t.bounds.height + 'px;' +
|
|
177
|
-
'border:3px dashed #FF6B35;' +
|
|
178
|
-
'background: rgba(255,107,53,0.08);' +
|
|
179
|
-
'pointer-events: none;' +
|
|
180
|
-
'z-index: 999999;' +
|
|
181
|
-
'box-sizing: border-box;';
|
|
182
|
-
const label = document.createElement('div');
|
|
183
|
-
label.textContent = t.name;
|
|
184
|
-
label.style.cssText =
|
|
185
|
-
'position: absolute;' +
|
|
186
|
-
'top: -22px;' +
|
|
187
|
-
'left: 0;' +
|
|
188
|
-
'background: #FF6B35;' +
|
|
189
|
-
'color: #fff;' +
|
|
190
|
-
'padding: 2px 6px;' +
|
|
191
|
-
'font-size: 12px;' +
|
|
192
|
-
'border-radius: 3px;' +
|
|
193
|
-
'font-family: monospace;';
|
|
194
|
-
div.appendChild(label);
|
|
195
|
-
document.body.appendChild(div);
|
|
196
|
-
});
|
|
197
|
-
return { marked: targets.length };
|
|
198
|
-
})();
|
|
199
|
-
`);
|
|
200
|
-
|
|
201
|
-
log(` ✓ 标记了 ${targets.length} 个目标`);
|
|
202
|
-
|
|
203
|
-
// Step 3: 坐标反查 DOM
|
|
204
|
-
log('Step 3: 坐标反查 DOM');
|
|
205
|
-
const results = [];
|
|
206
|
-
|
|
207
|
-
for (const t of targets) {
|
|
208
|
-
const found = await execBrowser(`
|
|
209
|
-
(function() {
|
|
210
|
-
const el = document.elementFromPoint(${t.center.x}, ${t.center.y});
|
|
211
|
-
if (!el) return null;
|
|
212
|
-
|
|
213
|
-
const target = el.closest('[data-wa-target]');
|
|
214
|
-
const tagName = el.tagName.toLowerCase();
|
|
215
|
-
const targetName = target ? target.getAttribute('data-wa-target') : null;
|
|
216
|
-
|
|
217
|
-
function getSelector(node) {
|
|
218
|
-
if (node.id) return '#' + node.id;
|
|
219
|
-
let sel = node.tagName.toLowerCase();
|
|
220
|
-
if (node.className && typeof node.className === 'string') {
|
|
221
|
-
const classes = node.className.split(' ').filter(Boolean);
|
|
222
|
-
if (classes.length > 0) {
|
|
223
|
-
const stable = classes[0].replace(/[_-][A-Z0-9]+$/, '');
|
|
224
|
-
sel += '[class*="' + stable + '"]';
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return sel;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return {
|
|
231
|
-
tagName,
|
|
232
|
-
selector: getSelector(el),
|
|
233
|
-
targetName,
|
|
234
|
-
textContent: (el.textContent || '').substring(0, 80)
|
|
235
|
-
};
|
|
236
|
-
})();
|
|
237
|
-
`);
|
|
238
|
-
|
|
239
|
-
if (!found) {
|
|
240
|
-
log(` ✗ 坐标 (${t.center.x}, ${t.center.y}) 未找到元素`);
|
|
241
|
-
results.push({ target: t, found: null, matched: false });
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const matched = found.targetName === t.name;
|
|
246
|
-
log(` ${matched ? '✓' : '✗'} ${t.name} -> ${found.tagName} (${found.selector})`);
|
|
247
|
-
log(` 反查目标: ${found.targetName || 'null'}`);
|
|
248
|
-
|
|
249
|
-
// 高亮反查的 DOM
|
|
250
|
-
await highlightSelector(found.selector, `found:${t.name}`);
|
|
251
|
-
|
|
252
|
-
results.push({ target: t, found, matched });
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Step 4: 统计
|
|
256
|
-
log('\n========================================');
|
|
257
|
-
log('测试结果统计');
|
|
258
|
-
log('========================================');
|
|
259
|
-
|
|
260
|
-
const matchedCount = results.filter(r => r.matched).length;
|
|
261
|
-
const totalCount = results.length;
|
|
262
|
-
const accuracy = totalCount > 0 ? (matchedCount / totalCount * 100).toFixed(1) : '0';
|
|
263
|
-
|
|
264
|
-
log(`总测试数: ${totalCount}`);
|
|
265
|
-
log(`匹配成功: ${matchedCount}`);
|
|
266
|
-
log(`匹配失败: ${totalCount - matchedCount}`);
|
|
267
|
-
log(`准确率: ${accuracy}%`);
|
|
268
|
-
|
|
269
|
-
if (Number(accuracy) >= 80) {
|
|
270
|
-
log('✅ 坐标定位反查 DOM 的方式可靠');
|
|
271
|
-
} else {
|
|
272
|
-
log('❌ 坐标定位反查 DOM 的方式不够可靠');
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
process.exit(Number(accuracy) >= 80 ? 0 : 1);
|
|
276
|
-
|
|
277
|
-
} catch (error) {
|
|
278
|
-
console.error('\n❌ 测试失败:', error.message);
|
|
279
|
-
if (error.stack) console.error(error.stack);
|
|
280
|
-
process.exit(1);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
main();
|