@web-auto/webauto 0.1.1 → 0.1.2
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 +247 -12
- 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 +37 -9
- 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,188 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* 测试 1: 容器匹配基础功能
|
|
4
|
-
* 验证后端能否成功匹配容器并返回正确的数据结构
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { execSync } from 'child_process';
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
|
|
10
|
-
console.log('📋 测试 1: 容器匹配基础功能');
|
|
11
|
-
console.log('='.repeat(60));
|
|
12
|
-
|
|
13
|
-
const LOG_FILE = '/tmp/test-container-match.log';
|
|
14
|
-
const TEST_PROFILE = 'weibo_fresh';
|
|
15
|
-
const TEST_URL = 'https://weibo.com';
|
|
16
|
-
|
|
17
|
-
// 清理旧日志
|
|
18
|
-
if (fs.existsSync(LOG_FILE)) fs.unlinkSync(LOG_FILE);
|
|
19
|
-
|
|
20
|
-
const log = (msg) => {
|
|
21
|
-
console.log(msg);
|
|
22
|
-
fs.appendFileSync(LOG_FILE, `${msg}\n`);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// 步骤 1: 启动服务
|
|
26
|
-
log('\n[步骤 1] 启动 Unified API 和 Browser Service...');
|
|
27
|
-
let unifiedPid, browserPid;
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
// 启动 Unified API
|
|
31
|
-
const unified = execSync('node services/unified-api/server.mjs > /tmp/unified-api.log 2>&1 & echo $!', {
|
|
32
|
-
encoding: 'utf8',
|
|
33
|
-
shell: '/bin/bash'
|
|
34
|
-
});
|
|
35
|
-
unifiedPid = unified.trim();
|
|
36
|
-
log(`✓ Unified API 启动: PID ${unifiedPid}`);
|
|
37
|
-
|
|
38
|
-
// 等待端口可用
|
|
39
|
-
await new Promise(r => setTimeout(r, 2000));
|
|
40
|
-
|
|
41
|
-
// 健康检查
|
|
42
|
-
const health = execSync('curl -s http://127.0.0.1:7701/health', { encoding: 'utf8' });
|
|
43
|
-
const healthData = JSON.parse(health);
|
|
44
|
-
if (!healthData.ok) throw new Error('Unified API 健康检查失败');
|
|
45
|
-
log(`✓ Unified API 健康: ${health.trim()}`);
|
|
46
|
-
|
|
47
|
-
// 启动 Browser Service
|
|
48
|
-
const browser = execSync('node dist/modules/camo-backend/src/index.js --host 127.0.0.1 --port 7704 > /tmp/browser-service.log 2>&1 & echo $!', {
|
|
49
|
-
encoding: 'utf8',
|
|
50
|
-
shell: '/bin/bash'
|
|
51
|
-
});
|
|
52
|
-
browserPid = browser.trim();
|
|
53
|
-
log(`✓ Browser Service 启动: PID ${browserPid}`);
|
|
54
|
-
|
|
55
|
-
await new Promise(r => setTimeout(r, 2000));
|
|
56
|
-
|
|
57
|
-
const browserHealth = execSync('curl -s http://127.0.0.1:7704/health', { encoding: 'utf8' });
|
|
58
|
-
const browserHealthData = JSON.parse(browserHealth);
|
|
59
|
-
if (!browserHealthData.ok) throw new Error('Browser Service 健康检查失败');
|
|
60
|
-
log(`✓ Browser Service 健康: ${browserHealth.trim()}`);
|
|
61
|
-
|
|
62
|
-
} catch (err) {
|
|
63
|
-
log(`✗ 服务启动失败: ${err.message}`);
|
|
64
|
-
cleanup();
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 步骤 2: 创建浏览器会话
|
|
69
|
-
log('\n[步骤 2] 创建浏览器会话...');
|
|
70
|
-
try {
|
|
71
|
-
const sessionCmd = `curl -s -X POST http://127.0.0.1:7704/start \\
|
|
72
|
-
-H 'Content-Type: application/json' \\
|
|
73
|
-
-d '{"profileId":"${TEST_PROFILE}","url":"${TEST_URL}","headless":false}'`;
|
|
74
|
-
|
|
75
|
-
const sessionResult = execSync(sessionCmd, { encoding: 'utf8' });
|
|
76
|
-
const sessionData = JSON.parse(sessionResult);
|
|
77
|
-
|
|
78
|
-
if (!sessionData.ok) {
|
|
79
|
-
throw new Error(`创建会话失败: ${sessionData.error || 'unknown'}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
log(`✓ 会话创建成功: ${sessionResult.substring(0, 100)}...`);
|
|
83
|
-
|
|
84
|
-
// 等待页面加载
|
|
85
|
-
await new Promise(r => setTimeout(r, 3000));
|
|
86
|
-
|
|
87
|
-
} catch (err) {
|
|
88
|
-
log(`✗ 会话创建失败: ${err.message}`);
|
|
89
|
-
cleanup();
|
|
90
|
-
process.exit(1);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// 步骤 3: 执行容器匹配
|
|
94
|
-
log('\n[步骤 3] 执行容器匹配...');
|
|
95
|
-
try {
|
|
96
|
-
const matchCmd = `curl -s -X POST http://127.0.0.1:7701/v1/containers/match \\
|
|
97
|
-
-H 'Content-Type: application/json' \\
|
|
98
|
-
-d '{"profileId":"${TEST_PROFILE}","url":"${TEST_URL}"}'`;
|
|
99
|
-
|
|
100
|
-
const matchResult = execSync(matchCmd, { encoding: 'utf8', maxBuffer: 10 * 1024 * 1024 });
|
|
101
|
-
|
|
102
|
-
// 保存完整响应
|
|
103
|
-
fs.writeFileSync('/tmp/container-match-result.json', matchResult);
|
|
104
|
-
|
|
105
|
-
const matchData = JSON.parse(matchResult);
|
|
106
|
-
|
|
107
|
-
log('\n[验证结果]');
|
|
108
|
-
log(`✓ 响应成功: ${matchData.success || matchData.ok}`);
|
|
109
|
-
log(`✓ 是否匹配: ${matchData.matched || (matchData.data && matchData.data.matched)}`);
|
|
110
|
-
|
|
111
|
-
const snapshot = matchData.snapshot || (matchData.data && matchData.data.snapshot);
|
|
112
|
-
if (!snapshot) {
|
|
113
|
-
throw new Error('响应中没有 snapshot 数据');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
log(`✓ 容器树存在: ${!!snapshot.container_tree}`);
|
|
117
|
-
log(`✓ DOM 树存在: ${!!snapshot.dom_tree}`);
|
|
118
|
-
|
|
119
|
-
// 验证容器树结构
|
|
120
|
-
if (snapshot.container_tree) {
|
|
121
|
-
const container = snapshot.container_tree;
|
|
122
|
-
log(`\n[容器树分析]`);
|
|
123
|
-
log(` 根容器 ID: ${container.id || container.name}`);
|
|
124
|
-
log(` 子容器数量: ${container.children?.length || 0}`);
|
|
125
|
-
|
|
126
|
-
// 检查匹配信息
|
|
127
|
-
if (container.match && container.match.nodes) {
|
|
128
|
-
log(` 根容器匹配节点数: ${container.match.nodes.length}`);
|
|
129
|
-
container.match.nodes.forEach((node, i) => {
|
|
130
|
-
log(` 节点 ${i + 1}: selector="${node.selector}", dom_path="${node.dom_path}"`);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// 检查子容器
|
|
135
|
-
if (container.children && container.children.length > 0) {
|
|
136
|
-
log(`\n[子容器分析]`);
|
|
137
|
-
container.children.forEach((child, i) => {
|
|
138
|
-
log(` 子容器 ${i + 1}: ${child.id || child.name}`);
|
|
139
|
-
if (child.match && child.match.nodes) {
|
|
140
|
-
log(` 匹配节点数: ${child.match.nodes.length}`);
|
|
141
|
-
child.match.nodes.slice(0, 2).forEach((node, j) => {
|
|
142
|
-
log(` 节点 ${j + 1}: dom_path="${node.dom_path}"`);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// 验证 DOM 树
|
|
150
|
-
if (snapshot.dom_tree) {
|
|
151
|
-
const dom = snapshot.dom_tree;
|
|
152
|
-
log(`\n[DOM 树分析]`);
|
|
153
|
-
log(` 根节点路径: ${dom.path}`);
|
|
154
|
-
log(` 根节点标签: ${dom.tag}`);
|
|
155
|
-
log(` 根节点子节点数: ${dom.children?.length || 0}`);
|
|
156
|
-
log(` 根节点 childCount: ${dom.childCount || 0}`);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
log('\n✅ 容器匹配测试通过');
|
|
160
|
-
log(`\n完整结果已保存到: /tmp/container-match-result.json`);
|
|
161
|
-
|
|
162
|
-
} catch (err) {
|
|
163
|
-
log(`✗ 容器匹配失败: ${err.message}`);
|
|
164
|
-
if (err.stderr) log(` 错误输出: ${err.stderr}`);
|
|
165
|
-
cleanup();
|
|
166
|
-
process.exit(1);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// 清理
|
|
170
|
-
function cleanup() {
|
|
171
|
-
log('\n[清理]');
|
|
172
|
-
if (unifiedPid) {
|
|
173
|
-
try {
|
|
174
|
-
execSync(`kill ${unifiedPid}`, { stdio: 'ignore' });
|
|
175
|
-
log(`✓ 停止 Unified API (PID ${unifiedPid})`);
|
|
176
|
-
} catch (e) {}
|
|
177
|
-
}
|
|
178
|
-
if (browserPid) {
|
|
179
|
-
try {
|
|
180
|
-
execSync(`kill ${browserPid}`, { stdio: 'ignore' });
|
|
181
|
-
log(`✓ 停止 Browser Service (PID ${browserPid})`);
|
|
182
|
-
} catch (e) {}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
cleanup();
|
|
187
|
-
log('\n' + '='.repeat(60));
|
|
188
|
-
log(`测试日志已保存到: ${LOG_FILE}`);
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* 测试 2: DOM 分支拉取功能
|
|
4
|
-
* 验证 dom:branch:2 action 是否正确工作
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { execSync } from 'child_process';
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
|
|
10
|
-
console.log('📋 测试 2: DOM 分支拉取功能');
|
|
11
|
-
console.log('='.repeat(60));
|
|
12
|
-
|
|
13
|
-
const LOG_FILE = '/tmp/test-dom-branch.log';
|
|
14
|
-
|
|
15
|
-
if (fs.existsSync(LOG_FILE)) fs.unlinkSync(LOG_FILE);
|
|
16
|
-
|
|
17
|
-
const log = (msg) => {
|
|
18
|
-
console.log(msg);
|
|
19
|
-
fs.appendFileSync(LOG_FILE, `${msg}\n`);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// 读取容器匹配结果
|
|
23
|
-
log('\n[步骤 1] 读取容器匹配结果...');
|
|
24
|
-
if (!fs.existsSync('/tmp/container-match-result.json')) {
|
|
25
|
-
log('✗ 请先运行 01-test-container-match.mjs');
|
|
26
|
-
process.exit(1);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const matchResult = JSON.parse(fs.readFileSync('/tmp/container-match-result.json', 'utf8'));
|
|
30
|
-
const snapshot = matchResult.snapshot || (matchResult.data && matchResult.data.snapshot);
|
|
31
|
-
|
|
32
|
-
if (!snapshot || !snapshot.container_tree) {
|
|
33
|
-
log('✗ 容器匹配结果中没有容器树');
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 收集需要拉取的 DOM 路径
|
|
38
|
-
log('\n[步骤 2] 收集需要拉取的 DOM 路径...');
|
|
39
|
-
const paths = new Set();
|
|
40
|
-
|
|
41
|
-
function collectPaths(node) {
|
|
42
|
-
if (node.match && node.match.nodes) {
|
|
43
|
-
node.match.nodes.forEach(m => {
|
|
44
|
-
if (m.dom_path && m.dom_path !== 'root') {
|
|
45
|
-
paths.add(m.dom_path);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
if (node.children) {
|
|
50
|
-
node.children.forEach(c => collectPaths(c));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
collectPaths(snapshot.container_tree);
|
|
55
|
-
log(`✓ 发现 ${paths.size} 个需要拉取的路径`);
|
|
56
|
-
paths.forEach((path, i) => {
|
|
57
|
-
log(` ${i + 1}. ${path}`);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
if (paths.size === 0) {
|
|
61
|
-
log('⚠ 没有需要拉取的路径,测试跳过');
|
|
62
|
-
process.exit(0);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// 检查 Action 映射
|
|
66
|
-
log('\n[步骤 3] 检查 dom:branch:2 action 映射...');
|
|
67
|
-
try {
|
|
68
|
-
const controllerPath = 'services/unified-api/controller.mjs';
|
|
69
|
-
if (!fs.existsSync(controllerPath)) {
|
|
70
|
-
log(`✗ Controller 文件不存在: ${controllerPath}`);
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const controllerCode = fs.readFileSync(controllerPath, 'utf8');
|
|
75
|
-
|
|
76
|
-
// 检查是否有 dom:branch 相关处理
|
|
77
|
-
if (controllerCode.includes('dom:branch')) {
|
|
78
|
-
log('✓ Controller 中包含 dom:branch 处理');
|
|
79
|
-
} else {
|
|
80
|
-
log('⚠ Controller 中未找到 dom:branch 处理');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 检查通用 action 处理
|
|
84
|
-
if (controllerCode.includes('handleAction')) {
|
|
85
|
-
log('✓ Controller 支持通用 action 处理');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
} catch (err) {
|
|
89
|
-
log(`✗ 检查 Controller 失败: ${err.message}`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// 测试 DOM 分支拉取
|
|
93
|
-
log('\n[步骤 4] 测试 DOM 分支拉取...');
|
|
94
|
-
|
|
95
|
-
const testPath = Array.from(paths)[0]; // 测试第一个路径
|
|
96
|
-
log(`测试路径: ${testPath}`);
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
const branchCmd = `curl -s -X POST http://127.0.0.1:7701/ws \\
|
|
100
|
-
-H 'Content-Type: application/json' \\
|
|
101
|
-
-d '{
|
|
102
|
-
"action": "dom:branch:2",
|
|
103
|
-
"payload": {
|
|
104
|
-
"profile": "weibo_fresh",
|
|
105
|
-
"url": "https://weibo.com",
|
|
106
|
-
"path": "${testPath}",
|
|
107
|
-
"maxDepth": 3,
|
|
108
|
-
"maxChildren": 8
|
|
109
|
-
}
|
|
110
|
-
}'`;
|
|
111
|
-
|
|
112
|
-
log('\n发送请求...');
|
|
113
|
-
const result = execSync(branchCmd, {
|
|
114
|
-
encoding: 'utf8',
|
|
115
|
-
timeout: 10000,
|
|
116
|
-
maxBuffer: 10 * 1024 * 1024
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// 保存结果
|
|
120
|
-
fs.writeFileSync('/tmp/dom-branch-result.json', result);
|
|
121
|
-
|
|
122
|
-
log('\n[验证结果]');
|
|
123
|
-
|
|
124
|
-
// 尝试解析 JSON
|
|
125
|
-
try {
|
|
126
|
-
const data = JSON.parse(result);
|
|
127
|
-
log(`✓ 返回有效 JSON`);
|
|
128
|
-
log(` success: ${data.success}`);
|
|
129
|
-
log(` has data: ${!!data.data}`);
|
|
130
|
-
log(` has node: ${!!(data.data && data.data.node)}`);
|
|
131
|
-
|
|
132
|
-
if (data.data && data.data.node) {
|
|
133
|
-
const node = data.data.node;
|
|
134
|
-
log(`\n[节点信息]`);
|
|
135
|
-
log(` path: ${node.path}`);
|
|
136
|
-
log(` tag: ${node.tag}`);
|
|
137
|
-
log(` children: ${node.children?.length || 0}`);
|
|
138
|
-
log(` childCount: ${node.childCount || 0}`);
|
|
139
|
-
|
|
140
|
-
log('\n✅ DOM 分支拉取测试通过');
|
|
141
|
-
} else {
|
|
142
|
-
log('✗ 返回数据中没有 node');
|
|
143
|
-
log(`完整返回: ${result.substring(0, 200)}`);
|
|
144
|
-
process.exit(1);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
} catch (parseErr) {
|
|
148
|
-
log(`✗ 返回不是有效 JSON`);
|
|
149
|
-
log(`返回内容: ${result.substring(0, 200)}`);
|
|
150
|
-
process.exit(1);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
} catch (err) {
|
|
154
|
-
log(`✗ DOM 分支拉取失败: ${err.message}`);
|
|
155
|
-
if (err.stderr) log(` 错误输出: ${err.stderr}`);
|
|
156
|
-
process.exit(1);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
log('\n' + '='.repeat(60));
|
|
160
|
-
log(`测试日志已保存到: ${LOG_FILE}`);
|
|
161
|
-
log(`结果已保存到: /tmp/dom-branch-result.json`);
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'ws';
|
|
2
|
-
import http from 'node:http';
|
|
3
|
-
|
|
4
|
-
const HOST = '127.0.0.1';
|
|
5
|
-
const PORT = 7701;
|
|
6
|
-
const WS_URL = `ws://${HOST}:${PORT}/ws`;
|
|
7
|
-
const API_HOST = `http://${HOST}:${PORT}`;
|
|
8
|
-
const LOG_FILE = '/tmp/test-operation-system.log';
|
|
9
|
-
|
|
10
|
-
function log(msg) {
|
|
11
|
-
console.log(msg);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function httpPost(path, data) {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const payload = JSON.stringify(data || {});
|
|
17
|
-
const req = http.request(
|
|
18
|
-
`${API_HOST}${path}`,
|
|
19
|
-
{
|
|
20
|
-
method: 'POST',
|
|
21
|
-
headers: {
|
|
22
|
-
'Content-Type': 'application/json',
|
|
23
|
-
'Content-Length': Buffer.byteLength(payload)
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
(res) => {
|
|
27
|
-
let body = '';
|
|
28
|
-
res.on('data', (chunk) => body += chunk);
|
|
29
|
-
res.on('end', () => {
|
|
30
|
-
try {
|
|
31
|
-
resolve(JSON.parse(body));
|
|
32
|
-
} catch (err) {
|
|
33
|
-
reject(err);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
req.on('error', reject);
|
|
39
|
-
req.write(payload);
|
|
40
|
-
req.end();
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function testSubscription() {
|
|
45
|
-
log('[TEST] Subscribing to container status...');
|
|
46
|
-
const res = await httpPost('/v1/container/test-container/subscribe', {});
|
|
47
|
-
if (!res.success) throw new Error('Subscription failed');
|
|
48
|
-
log('[TEST] Subscription OK');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function testWebSocketEvent() {
|
|
52
|
-
log('[TEST] Connecting WebSocket...');
|
|
53
|
-
const ws = new WebSocket(WS_URL);
|
|
54
|
-
|
|
55
|
-
const ready = new Promise((resolve, reject) => {
|
|
56
|
-
ws.on('open', resolve);
|
|
57
|
-
ws.on('error', reject);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
await ready;
|
|
61
|
-
log('[TEST] WebSocket connected');
|
|
62
|
-
|
|
63
|
-
return new Promise((resolve, reject) => {
|
|
64
|
-
ws.on('message', (data) => {
|
|
65
|
-
const msg = JSON.parse(data.toString());
|
|
66
|
-
if (msg.type === 'ready') {
|
|
67
|
-
log('[TEST] WS ready');
|
|
68
|
-
resolve(true);
|
|
69
|
-
ws.close();
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
setTimeout(() => {
|
|
74
|
-
reject(new Error('Timeout waiting for WS ready'));
|
|
75
|
-
ws.close();
|
|
76
|
-
}, 5000);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function run() {
|
|
81
|
-
try {
|
|
82
|
-
await testSubscription();
|
|
83
|
-
await testWebSocketEvent();
|
|
84
|
-
log('[TEST] ✅ Operation System integration test passed');
|
|
85
|
-
} catch (err) {
|
|
86
|
-
console.error('[TEST] ❌ Operation System integration test failed', err.message);
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
run();
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* 容器生命周期事件跟踪闭环测试 - 无会话依赖版
|
|
4
|
-
*
|
|
5
|
-
* 测试流程:
|
|
6
|
-
* 1. 启动 Unified API
|
|
7
|
-
* 2. 连接 WebSocket 监听事件
|
|
8
|
-
* 3. 订阅容器状态
|
|
9
|
-
* 4. 模拟事件发送
|
|
10
|
-
* 5. 验证事件流
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { WebSocket } from 'ws';
|
|
14
|
-
import http from 'node:http';
|
|
15
|
-
|
|
16
|
-
const HOST = '127.0.0.1';
|
|
17
|
-
const UNIFIED_API_PORT = 7701;
|
|
18
|
-
const WS_URL = `ws://${HOST}:${UNIFIED_API_PORT}/ws`;
|
|
19
|
-
const API_HOST = `http://${HOST}:${UNIFIED_API_PORT}`;
|
|
20
|
-
|
|
21
|
-
const events = [];
|
|
22
|
-
let ws = null;
|
|
23
|
-
|
|
24
|
-
function log(msg) {
|
|
25
|
-
console.log(`[LIFECYCLE] ${msg}`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function httpPost(path, data) {
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
const payload = JSON.stringify(data || {});
|
|
31
|
-
const req = http.request(
|
|
32
|
-
`${API_HOST}${path}`,
|
|
33
|
-
{
|
|
34
|
-
method: 'POST',
|
|
35
|
-
headers: {
|
|
36
|
-
'Content-Type': 'application/json',
|
|
37
|
-
'Content-Length': Buffer.byteLength(payload)
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
(res) => {
|
|
41
|
-
let body = '';
|
|
42
|
-
res.on('data', (chunk) => body += chunk);
|
|
43
|
-
res.on('end', () => {
|
|
44
|
-
try {
|
|
45
|
-
resolve(JSON.parse(body));
|
|
46
|
-
} catch (err) {
|
|
47
|
-
resolve({ body, statusCode: res.statusCode });
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
req.on('error', reject);
|
|
53
|
-
req.write(payload);
|
|
54
|
-
req.end();
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function httpGet(path) {
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
http.get(`${API_HOST}${path}`, (res) => {
|
|
61
|
-
let body = '';
|
|
62
|
-
res.on('data', (chunk) => body += chunk);
|
|
63
|
-
res.on('end', () => {
|
|
64
|
-
try {
|
|
65
|
-
resolve(JSON.parse(body));
|
|
66
|
-
} catch (err) {
|
|
67
|
-
resolve({ body, statusCode: res.statusCode });
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}).on('error', reject);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async function connectWebSocket() {
|
|
75
|
-
return new Promise((resolve, reject) => {
|
|
76
|
-
ws = new WebSocket(WS_URL);
|
|
77
|
-
|
|
78
|
-
ws.on('open', () => {
|
|
79
|
-
log('WebSocket 连接成功');
|
|
80
|
-
resolve();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
ws.on('message', (data) => {
|
|
84
|
-
const msg = JSON.parse(data.toString());
|
|
85
|
-
events.push(msg);
|
|
86
|
-
|
|
87
|
-
// 打印容器相关事件
|
|
88
|
-
if (msg.type === 'event' && msg.topic && msg.topic.includes('container')) {
|
|
89
|
-
log(`收到事件: ${msg.topic}`);
|
|
90
|
-
if (msg.payload) {
|
|
91
|
-
const preview = JSON.stringify(msg.payload).substring(0, 100);
|
|
92
|
-
log(` 数据: ${preview}...`);
|
|
93
|
-
}
|
|
94
|
-
} else if (msg.type === 'ready' || msg.type === 'pong') {
|
|
95
|
-
log(`收到系统事件: ${msg.type}`);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
ws.on('error', reject);
|
|
100
|
-
setTimeout(() => reject(new Error('WebSocket 连接超时')), 5000);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function checkHealth() {
|
|
105
|
-
log('检查健康状态...');
|
|
106
|
-
const health = await httpGet('/health');
|
|
107
|
-
if (!health.ok) {
|
|
108
|
-
throw new Error('服务不健康');
|
|
109
|
-
}
|
|
110
|
-
log('✓ 服务健康');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function subscribeToContainer(containerId) {
|
|
114
|
-
log(`订阅容器: ${containerId}`);
|
|
115
|
-
const result = await httpPost(`/v1/container/${containerId}/subscribe`, {});
|
|
116
|
-
|
|
117
|
-
if (!result.success) {
|
|
118
|
-
throw new Error(`订阅失败: ${result.error || '未知错误'}`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
log(`✓ 容器订阅成功: ${containerId}`);
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function simulateEventFlow() {
|
|
126
|
-
log('模拟事件流...');
|
|
127
|
-
|
|
128
|
-
// 模拟发送一些容器相关的事件(这需要在实际的事件系统中触发)
|
|
129
|
-
// 由于我们没有真实的容器发现流程,我们只等待事件
|
|
130
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
131
|
-
|
|
132
|
-
log('✓ 事件流模拟完成');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function analyzeEvents() {
|
|
136
|
-
log('\n=== 事件分析 ===');
|
|
137
|
-
log(`总共收到 ${events.length} 个事件`);
|
|
138
|
-
|
|
139
|
-
// 分类事件
|
|
140
|
-
const containerEvents = events.filter(e =>
|
|
141
|
-
e.type === 'event' && e.topic && e.topic.includes('container')
|
|
142
|
-
);
|
|
143
|
-
const systemEvents = events.filter(e =>
|
|
144
|
-
e.type === 'ready' || e.type === 'pong'
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
log(`容器相关事件: ${containerEvents.length} 个`);
|
|
148
|
-
log(`系统事件: ${systemEvents.length} 个`);
|
|
149
|
-
|
|
150
|
-
// 打印容器事件详情
|
|
151
|
-
containerEvents.forEach((event, index) => {
|
|
152
|
-
log(`[${index + 1}] ${event.topic}`);
|
|
153
|
-
if (event.payload) {
|
|
154
|
-
const keys = Object.keys(event.payload);
|
|
155
|
-
log(` 字段: ${keys.join(', ')}`);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
return { containerEvents, systemEvents };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async function testEventFlow() {
|
|
163
|
-
log('\n=== 测试事件流程 ===');
|
|
164
|
-
|
|
165
|
-
// 模拟在 WebSocket 中发送一个测试事件
|
|
166
|
-
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
167
|
-
ws.send(JSON.stringify({
|
|
168
|
-
type: 'action',
|
|
169
|
-
action: 'ping',
|
|
170
|
-
requestId: 'test-ping'
|
|
171
|
-
}));
|
|
172
|
-
|
|
173
|
-
log('✓ 发送测试 ping 事件');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async function main() {
|
|
180
|
-
try {
|
|
181
|
-
// Step 1: 检查健康
|
|
182
|
-
await checkHealth();
|
|
183
|
-
|
|
184
|
-
// Step 2: 连接 WebSocket
|
|
185
|
-
await connectWebSocket();
|
|
186
|
-
|
|
187
|
-
// Step 3: 订阅容器
|
|
188
|
-
await subscribeToContainer('test-container');
|
|
189
|
-
|
|
190
|
-
// Step 4: 测试事件流程
|
|
191
|
-
await testEventFlow();
|
|
192
|
-
|
|
193
|
-
// Step 5: 模拟事件流
|
|
194
|
-
await simulateEventFlow();
|
|
195
|
-
|
|
196
|
-
// Step 6: 分析事件
|
|
197
|
-
const analysis = await analyzeEvents();
|
|
198
|
-
|
|
199
|
-
// Step 7: 总结
|
|
200
|
-
log('\n=== 测试总结 ===');
|
|
201
|
-
log('✓ WebSocket 连接: 通过');
|
|
202
|
-
log('✓ 容器订阅: 通过');
|
|
203
|
-
log(`✓ 事件接收: 通过 (${events.length} 个事件)`);
|
|
204
|
-
|
|
205
|
-
if (analysis.containerEvents.length > 0) {
|
|
206
|
-
log('✓ 容器事件: 通过');
|
|
207
|
-
} else {
|
|
208
|
-
log('⚠ 容器事件: 未收到(这可能是因为没有实际的容器发现流程)');
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
log('\n✅ 容器生命周期事件跟踪闭环测试完成!');
|
|
212
|
-
|
|
213
|
-
ws.close();
|
|
214
|
-
process.exit(0);
|
|
215
|
-
|
|
216
|
-
} catch (error) {
|
|
217
|
-
console.error('\n❌ 测试失败:', error.message);
|
|
218
|
-
console.error(error.stack);
|
|
219
|
-
if (ws) ws.close();
|
|
220
|
-
process.exit(1);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
main();
|