@ohos-cpf/3rdloop 0.0.7 → 0.0.9
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 +44 -25
- package/lib/cli.js +54 -29
- package/lib/config-cmd.js +1 -1
- package/lib/config.js +32 -0
- package/lib/doctor.js +266 -48
- package/lib/mcp.js +498 -0
- package/lib/opencode.js +75 -29
- package/lib/orch.js +32 -10
- package/lib/runner.js +8 -5
- package/lib/serve.js +162 -149
- package/lib/step.js +15 -4
- package/lib/web.js +107 -265
- package/lib/workflow.js +18 -8
- package/package.json +6 -2
- package/vendor/Archive/data/.index/meta.json +7 -0
- package/vendor/Archive/data/.index/search.db +0 -0
- package/vendor/Archive/data/docs/experiences/arkts-check-tool-pitfalls-baseline-comparison.md +13 -0
- package/vendor/Archive/data/docs/experiences/arkts-deep-path-import-recognition.md +31 -0
- package/vendor/Archive/data/docs/experiences/arkts-demo-coverage-entry-file-case-mismatch.md +25 -0
- package/vendor/Archive/data/docs/experiences/arkts-demo-coverage-import-trailing-slash.md +20 -0
- package/vendor/Archive/data/docs/experiences/arkts-library-source-files-may-be-ts.md +18 -0
- package/vendor/Archive/data/docs/experiences/arkts-typedarray-buffer-interface-cast-compile-fixes.md +36 -0
- package/vendor/Archive/data/docs/experiences/arkts-xts-compile-error-clustering-fix.md +24 -0
- package/vendor/Archive/data/docs/experiences/arkts-xts-doc-expected-value-runtime-probe.md +35 -0
- package/vendor/Archive/data/docs/experiences/arkts-xts-fixture-rawfile-testability-injection.md +33 -0
- package/vendor/Archive/data/docs/experiences/code-linter-chinese-comment-false-positive.md +16 -0
- package/vendor/Archive/data/docs/experiences/esobject-new-expression-variable-tracking.md +33 -0
- package/vendor/Archive/data/docs/experiences/filesystem-case-sensitivity-module-resolution.md +31 -0
- package/vendor/Archive/data/docs/experiences/gitcode-clone-redirect-warning-normal.md +13 -0
- package/vendor/Archive/data/docs/experiences/kn_msgvq1w585ec8319.md +77 -0
- package/vendor/Archive/data/docs/experiences/kn_msovnm6rd46de72c.md +98 -0
- package/vendor/Archive/data/docs/experiences/kn_mspt8vntfe708576.md +87 -0
- package/vendor/Archive/data/docs/experiences/kn_mspu1ei77adbbb48.md +133 -0
- package/vendor/Archive/data/docs/experiences/kn_mspubgak8d30bfce.md +128 -0
- package/vendor/Archive/data/docs/experiences/kn_mspug2de3cb1f7c3.md +115 -0
- package/vendor/Archive/data/docs/experiences/kn_skill_opt_001.md +38 -0
- package/vendor/Archive/data/docs/experiences/loop-artifacts-verification-evidence-triangle.md +19 -0
- package/vendor/Archive/data/docs/experiences/macos-bash-replace-build-ps1.md +19 -0
- package/vendor/Archive/data/docs/experiences/macos-bsd-diff-q-illegal-option.md +15 -0
- package/vendor/Archive/data/docs/experiences/migrate-cjs-compatible-api-version-map-limit.md +17 -0
- package/vendor/Archive/data/docs/experiences/mp3agic-arkts-library-behavior-quirks.md +21 -0
- package/vendor/Archive/data/docs/experiences/ohos-face-detection-scan-api-mapping.md +15 -0
- package/vendor/Archive/data/docs/experiences/pr-metadata-and-diff-integrity-verification.md +12 -0
- package/vendor/Archive/data/docs/experiences/rn-coverage-index-signature-pseudo-member-false-negative.md +32 -0
- package/vendor/Archive/data/docs/experiences/rn-memory-check-severity-calibration.md +21 -0
- package/vendor/Archive/data/docs/experiences/rn-platform-specific-api-exclusion-evidence.md +24 -0
- package/vendor/Archive/data/docs/experiences/rn-upstream-version-diff-pitfalls.md +17 -0
- package/vendor/Archive/data/docs/experiences/rn-version-gap-risk-rating-rules.md +13 -0
- package/vendor/Archive/data/docs/experiences/rn-view-lib-native-contract-diff-fabric-spec.md +16 -0
- package/vendor/Archive/data/docs/experiences/rnoh-adapter-package-version-field-semantics.md +18 -0
- package/vendor/Archive/data/docs/experiences/rnoh-arkts-sqlite-rows-array-format.md +18 -0
- package/vendor/Archive/data/docs/experiences/rnoh-dependency-residue-scan-strategy.md +18 -0
- package/vendor/Archive/data/docs/experiences/rnoh-example-local-lib-dep-use-tgz.md +53 -0
- package/vendor/Archive/data/docs/experiences/rnoh-example-prereserve-rntesterlist.md +17 -0
- package/vendor/Archive/data/docs/experiences/rnoh-example-template-compatiblesdkversion-upgrade.md +29 -0
- package/vendor/Archive/data/docs/experiences/rnoh-example-turbomodule-shell-adaptation-checklist.md +41 -0
- package/vendor/Archive/data/docs/experiences/rnoh-mcp-build-project-tool-risk.md +18 -0
- package/vendor/Archive/data/docs/experiences/rnoh-npm-devdependencies-version-precheck.md +29 -0
- package/vendor/Archive/data/docs/experiences/rnoh-repo-baseline-version-verification.md +13 -0
- package/vendor/Archive/data/docs/experiences/rnoh-repo-upstream-directory-mapping.md +18 -0
- package/vendor/Archive/data/docs/experiences/rnoh-stateless-library-zero-leak-verification.md +31 -0
- package/vendor/Archive/data/docs/experiences/rnoh-template-npmrc-credential-removal.md +15 -0
- package/vendor/Archive/data/docs/experiences/rnoh-turbomodule-codegen-wiring-verification.md +19 -0
- package/vendor/Archive/data/docs/experiences/rnoh-turbomodule-cpp-methodmap-compatibility-check.md +20 -0
- package/vendor/Archive/data/docs/experiences/scenario-doc-vs-source-signature-diff-four-patterns.md +24 -0
- package/vendor/Archive/data/docs/experiences/static-analysis-grep-cross-validation.md +29 -0
- package/vendor/Archive/demo.js +489 -0
- package/vendor/Archive/index.js +43 -0
- package/vendor/Archive/package.json +16 -0
- package/vendor/Archive/src/constants.js +83 -0
- package/vendor/Archive/src/data/stopwords.txt +110 -0
- package/vendor/Archive/src/data/synonyms.json +25 -0
- package/vendor/Archive/src/data/terms.txt +59 -0
- package/vendor/Archive/src/db/sqlite-backend.js +312 -0
- package/vendor/Archive/src/db/sqlite-schema.js +64 -0
- package/vendor/Archive/src/engine.js +501 -0
- package/vendor/Archive/src/index/index-manager.js +203 -0
- package/vendor/Archive/src/index/index-state.js +94 -0
- package/vendor/Archive/src/index/search-text-builder.js +106 -0
- package/vendor/Archive/src/index.js +22 -0
- package/vendor/Archive/src/parser/api-identifiers.js +121 -0
- package/vendor/Archive/src/parser/api-suffixes.js +48 -0
- package/vendor/Archive/src/parser/heading-normalize.js +40 -0
- package/vendor/Archive/src/parser/markdown-splitter.js +215 -0
- package/vendor/Archive/src/search/catalog-routing.js +87 -0
- package/vendor/Archive/src/search/fts-search.js +289 -0
- package/vendor/Archive/src/search/query-normalizer.js +159 -0
- package/vendor/Archive/src/search/query-rewriter.js +72 -0
- package/vendor/Archive/src/search/search-engine.js +72 -0
- package/vendor/Archive/src/search/snippet.js +64 -0
- package/vendor/Archive/src/store/dir-store.js +103 -0
- package/vendor/Archive/src/store/doc-store.js +36 -0
- package/vendor/Archive/src/tokenizer/lexicon.js +151 -0
- package/vendor/Archive/src/tokenizer/tokenizer.js +167 -0
- package/vendor/Archive/src/types.js +86 -0
- package/vendor/Archive/src/utils/hash.js +16 -0
- package/vendor/Archive/src/utils/lock.js +73 -0
- package/vendor/Archive/src/utils/path-safety.js +96 -0
- package/vendor/Archive/src/utils/paths.js +39 -0
- package/vendor/BadCase/rn/INDEX.md +127 -0
- package/vendor/BadCase/rn/cases/KI-001-webview/350/247/206/351/242/221/346/227/240/346/263/225/346/250/252/345/261/217.md +52 -0
- package/vendor/BadCase/rn/cases/KI-002-fastImage/347/203/255/346/233/264/346/226/260/345/233/276/347/211/207/345/244/261/350/264/245.md +37 -0
- package/vendor/BadCase/rn/cases/KI-003-wechat/347/274/251/347/225/245/345/233/276/346/234/254/345/234/260/345/233/276/347/211/207.md +62 -0
- package/vendor/BadCase/rn/cases/KI-004-wechat/345/233/236/350/260/203/346/227/266/345/272/217.md +47 -0
- package/vendor/BadCase/rn/cases/KI-005-geolocation/345/257/274/345/205/245/350/267/257/345/276/204/345/220/216/347/274/200.md +31 -0
- package/vendor/BadCase/rn/cases/KI-006-SmartRefreshLayout/346/231/272/350/203/275/346/214/207/351/222/210/345/264/251/346/272/203.md +55 -0
- package/vendor/BadCase/rn/cases/KI-007-orientation-locker/344/274/240/346/204/237/345/231/250/345/210/235/345/247/213/345/214/226.md +58 -0
- package/vendor/BadCase/rn/cases/KI-008-orientation-locker/344/274/240/346/204/237/345/231/250/345/274/225/347/224/250/350/256/241/346/225/260.md +47 -0
- package/vendor/BadCase/rn/cases/KI-009-pager-view/345/265/214/345/245/227/346/273/221/345/212/250.md +38 -0
- package/vendor/BadCase/rn/cases/KI-010-screens/346/211/213/345/212/277/345/206/262/347/252/201.md +48 -0
- package/vendor/BadCase/rn/cases/KI-011-spring-scrollview/346/211/213/345/212/277/351/207/215/345/244/215/347/273/221/345/256/232.md +49 -0
- package/vendor/BadCase/rn/cases/KI-012-qr-camera/346/250/252/345/261/217/351/200/202/351/205/215.md +59 -0
- package/vendor/BadCase/rn/cases/KI-013-webview/346/267/261/350/211/262/346/250/241/345/274/217/350/203/214/346/231/257/350/211/262.md +37 -0
- package/vendor/BadCase/rn/cases/KI-014-amap-geolocation/345/233/236/350/260/203/347/274/272/345/244/261.md +42 -0
- package/vendor/BadCase/rn/cases/KI-015-reanimated/350/277/220/350/241/214/346/227/266/346/236/220/346/236/204/345/264/251/346/272/203.md +54 -0
- package/vendor/BadCase/rn/cases/KI-016-fs/346/226/207/344/273/266/350/257/273/345/217/226/347/274/226/347/240/201.md +58 -0
- package/vendor/BadCase/rn/cases/KI-017-blob-util/345/217/202/346/225/260/347/274/226/347/240/201/351/224/231/350/257/257.md +39 -0
- package/vendor/BadCase/rn/cases/KI-018-modal/345/274/271/347/252/227/351/227/252/347/203/201.md +53 -0
- package/vendor/BadCase/rn/cases/KI-019-code-push/351/207/215/345/220/257/351/200/273/350/276/221/345/244/261/346/225/210.md +79 -0
- package/vendor/BadCase/rn/cases/KI-020-netinfo/346/225/217/346/204/237/344/277/241/346/201/257/346/263/204/351/234/262.md +60 -0
- package/vendor/BadCase/rn/cases/KI-021-video/346/234/254/345/234/260/350/247/206/351/242/221/346/222/255/346/224/276/345/274/202/345/270/270.md +79 -0
- package/vendor/BadCase/rn/cases/KI-022-audio-recorder-player/346/236/232/344/270/276/347/274/272/345/244/261.md +38 -0
- package/vendor/BadCase/rn/cases/KI-023-svg/346/270/220/345/217/230/347/273/247/346/211/277/345/244/261/346/225/210.md +62 -0
- package/vendor/BadCase/rn/generalization-log.md +55 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-SmartRefreshLayout-32.json +328 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-SmartRefreshLayout-32.md +382 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-amap-geolocation-27.json +1351 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-amap-geolocation-27.md +1176 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-audio-recorder-player-22.json +538 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-audio-recorder-player-22.md +1488 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-blob-util-23.json +211 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-blob-util-23.md +35 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-code-push-17.json +2048 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-code-push-17.md +3866 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-fast-image-102.json +198 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-fast-image-102.md +40 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-fs-38.json +751 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-fs-38.md +883 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-geolocation-24.json +1544 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-geolocation-24.md +2598 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-modal-20.json +246 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-modal-20.md +554 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-netinfo-31.json +211 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-netinfo-31.md +54 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-orientation-locker-45.json +1626 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-orientation-locker-45.md +2213 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-orientation-locker-51.json +208 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-orientation-locker-51.md +77 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-pager-view-32.json +377 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-pager-view-32.md +174 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-qr-decode-image-camera-37.json +232 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-qr-decode-image-camera-37.md +194 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-reanimated-82.json +198 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-reanimated-82.md +67 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-screens-87.json +198 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-screens-87.md +38 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-screens-93.json +208 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-screens-93.md +34 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-spring-scrollview-38.json +222 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-spring-scrollview-38.md +56 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-svg-117.json +463 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-svg-117.md +383 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-video-66.json +464 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-video-66.md +565 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-webview-112.json +198 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-webview-112.md +47 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-webview-121.json +232 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-webview-121.md +422 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-wechat-lib-15.json +295 -0
- package/vendor/BadCase/rn/pr-info/rntpc_react-native-wechat-lib-15.md +1038 -0
- package/vendor/BadCase/rn/rules/R-01-/345/205/250/345/261/217/347/252/227/345/217/243/347/212/266/346/200/201/347/256/241/347/220/206/345/256/214/346/225/264/346/200/247.md +20 -0
- package/vendor/BadCase/rn/rules/R-02-/350/265/204/346/272/220URI/345/275/242/346/200/201/345/210/206/346/224/257/350/246/206/347/233/226.md +21 -0
- package/vendor/BadCase/rn/rules/R-03-/351/231/204/345/261/236/346/223/215/344/275/234/345/244/261/350/264/245/351/230/273/346/226/255/344/270/273/346/265/201/347/250/213.md +20 -0
- package/vendor/BadCase/rn/rules/R-04-/345/274/202/346/255/245/345/233/236/350/260/203/346/263/250/345/206/214/346/227/266/345/272/217.md +20 -0
- package/vendor/BadCase/rn/rules/R-05-/346/250/241/345/235/227/345/257/274/345/205/245/350/267/257/345/276/204/350/247/204/350/214/203.md +19 -0
- package/vendor/BadCase/rn/rules/R-06-/344/274/240/346/204/237/345/231/250/347/241/254/344/273/266/346/235/203/351/231/220/346/214/211/351/234/200/350/216/267/345/217/226.md +21 -0
- package/vendor/BadCase/rn/rules/R-07-/346/231/272/350/203/275/346/214/207/351/222/210/347/224/237/345/221/275/345/221/250/346/234/237/347/256/241/347/220/206.md +20 -0
- package/vendor/BadCase/rn/rules/R-08-/346/211/213/345/212/277/344/272/213/344/273/266/346/263/250/345/206/214/344/270/216/345/206/262/347/252/201/345/244/204/347/220/206.md +22 -0
- package/vendor/BadCase/rn/rules/R-09-/346/250/252/347/253/226/345/261/217/345/244/232/345/275/242/346/200/201/345/270/203/345/261/200/351/200/202/351/205/215.md +20 -0
- package/vendor/BadCase/rn/rules/R-10-/346/267/261/350/211/262/346/250/241/345/274/217/344/270/273/351/242/230/351/242/234/350/211/262/351/200/202/351/205/215.md +19 -0
- package/vendor/BadCase/rn/rules/R-11-/346/216/245/345/217/243/345/233/236/350/260/203/345/256/236/347/216/260/345/256/214/346/225/264/346/200/247.md +20 -0
- package/vendor/BadCase/rn/rules/R-12-/345/216/237/347/224/237/350/277/220/350/241/214/346/227/266/350/265/204/346/272/220/346/236/220/346/236/204/346/227/266/345/272/217.md +20 -0
- package/vendor/BadCase/rn/rules/R-13-/346/226/207/344/273/266/346/225/260/346/215/256/347/274/226/347/240/201/344/270/216/346/240/274/345/274/217/345/205/274/345/256/271.md +21 -0
- package/vendor/BadCase/rn/rules/R-14-/345/212/250/347/224/273/345/210/235/345/247/213/345/214/226/346/227/266/345/272/217/344/270/216/347/212/266/346/200/201/345/220/214/346/255/245.md +20 -0
- package/vendor/BadCase/rn/rules/R-15-/347/212/266/346/200/201/346/214/201/344/271/205/345/214/226/344/270/216/351/207/215/345/220/257/351/200/273/350/276/221/344/270/200/350/207/264/346/200/247.md +20 -0
- package/vendor/BadCase/rn/rules/R-16-/346/225/217/346/204/237/344/277/241/346/201/257/346/227/245/345/277/227/346/263/204/351/234/262.md +19 -0
- package/vendor/BadCase/rn/rules/R-17-/345/252/222/344/275/223/350/265/204/346/272/220/347/224/237/345/221/275/345/221/250/346/234/237/344/270/216/351/224/231/350/257/257/345/244/204/347/220/206.md +21 -0
- package/vendor/BadCase/rn/rules/R-18-/350/203/275/345/212/233/346/236/232/344/270/276/351/205/215/347/275/256/345/256/214/346/225/264/346/200/247.md +19 -0
- package/vendor/BadCase/rn/rules/R-19-/345/233/276/345/275/242/346/270/262/346/237/223/345/261/236/346/200/247/347/273/247/346/211/277/344/270/216/351/207/215/347/275/256.md +19 -0
- package/vendor/MCP/README.md +490 -0
- package/vendor/MCP/config.json +29 -0
- package/vendor/MCP/package.json +23 -0
- package/vendor/MCP/scripts/analyze-demo-coverage.cjs +1203 -0
- package/vendor/MCP/scripts/analyze-xts-coverage.cjs +1245 -0
- package/vendor/MCP/scripts/deveco_docs.js +247 -0
- package/vendor/MCP/scripts/extract-interfaces.cjs +1487 -0
- package/vendor/MCP/scripts/flutter-analyze-demo-coverage.cjs +666 -0
- package/vendor/MCP/scripts/flutter-analyze-xts-coverage.cjs +684 -0
- package/vendor/MCP/scripts/flutter-extract-interfaces.cjs +1251 -0
- package/vendor/MCP/scripts/flutter-render-spec-doc.cjs +351 -0
- package/vendor/MCP/scripts/render-spec-doc.cjs +347 -0
- package/vendor/MCP/scripts/rn-analyze-demo-coverage.cjs +645 -0
- package/vendor/MCP/scripts/rn-analyze-test-coverage.cjs +614 -0
- package/vendor/MCP/scripts/rn-extract-interfaces.cjs +1462 -0
- package/vendor/MCP/scripts/rn-render-spec-doc.cjs +327 -0
- package/vendor/MCP/scripts/rn-scan-exports.cjs +1336 -0
- package/vendor/MCP/src/client/MCPClientPool.js +220 -0
- package/vendor/MCP/src/config/ConfigLoader.js +189 -0
- package/vendor/MCP/src/executor/ScriptExecutor.js +110 -0
- package/vendor/MCP/src/gateway/Gateway.js +451 -0
- package/vendor/MCP/src/index.js +87 -0
- package/vendor/MCP/src/library/KBToolProvider.js +229 -0
- package/vendor/MCP/src/library/logger.js +60 -0
- package/vendor/MCP/src/registry/ScriptRegistry.js +238 -0
- package/vendor/MCP/src/registry/ToolRegistry.js +111 -0
- package/vendor/MCP/src/types.js +115 -0
- package/vendor/Server/CLI/cli.js +3 -3
- package/vendor/Server/Routes/server.js +3 -3
- package/vendor/Server/Skills/arkts-library-test-coverage-check/references/MCP_TOOL_USAGE.md +4 -2
- package/vendor/Server/Skills/arkts-library-xts-coverage/SKILL.md +3 -3
- package/vendor/Server/Skills/knowledge-import/SKILL.md +1 -1
- package/vendor/Server/Skills/knowledge-import/references/MCP_TOOL_USAGE.md +12 -4
- package/vendor/Server/Skills/ohos-lib-pr-push/SKILL.md +5 -4
- package/vendor/Server/Skills/rn-library-issue-generalizer/SKILL.md +2 -2
- package/vendor/Server/Skills/rn-library-known-issue-check/SKILL.md +2 -2
- package/vendor/Server/Skills/rnoh-lib-demo-coverage/SKILL.md +1 -2
- package/vendor/Server/Skills/rnoh-lib-test-align/references/port-test-demo-guide.md +1 -1
- package/vendor/Server/Skills/rnoh-lib-xts-coverage/SKILL.md +1 -2
- package/vendor/Server/package.json +5 -1
- package/vendor/VERSION +3 -3
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @tool rn_analyze_test_coverage
|
|
4
|
+
* @description 分析 React Native 三方库的测试用例覆盖率。从库源码提取接口规格,扫描测试源码目录(__tests__ 或 test/tests),执行 AST/正则双层覆盖率匹配,输出 Markdown 覆盖率报告。用于评估测试用例对 RN 库 API 的覆盖程度。
|
|
5
|
+
* @param libroot: string - 库根目录路径(RN 三方库的鸿蒙化仓库目录)
|
|
6
|
+
* @param spec: string - 已有的 interface-spec.json 路径(可选,与 libroot 二选一)
|
|
7
|
+
* @param output: string - 输出 Markdown 报告路径(可选,默认 03-xxx-Test覆盖率报告.md)
|
|
8
|
+
* @param mode: string - 匹配模式: auto(默认) | ast | regex(可选)
|
|
9
|
+
* @param version: string - 上游 npm 版本号(可选,如 "2.2.0")
|
|
10
|
+
* @hidden
|
|
11
|
+
* analyze-test-coverage.cjs — 测试用例覆盖率分析脚本
|
|
12
|
+
*
|
|
13
|
+
* 基于 rn-extract-interfaces.cjs 生成的接口规格,分析测试用例源码对接口的覆盖情况。
|
|
14
|
+
* 覆盖率计算逻辑(AST/正则匹配 + 结果聚合 + Markdown 渲染)完整实现在本文件中。
|
|
15
|
+
*
|
|
16
|
+
* 依赖: require('./rn-extract-interfaces.cjs') (loadSpec + 共享工具)
|
|
17
|
+
*
|
|
18
|
+
* 用法:
|
|
19
|
+
* 方式一 (JSON 中间件):
|
|
20
|
+
* node rn-analyze-test-coverage.cjs --spec <spec.json> --libroot <库根目录> \
|
|
21
|
+
* [--output <report.md>] [--mode auto|ast|regex] [--version <上游版本>]
|
|
22
|
+
* 方式二 (直接提取):
|
|
23
|
+
* node rn-analyze-test-coverage.cjs --libroot <库根目录> \
|
|
24
|
+
* [--output <report.md>] [--mode auto|ast|regex] [--version <上游版本>]
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
'use strict';
|
|
28
|
+
|
|
29
|
+
const fs = require('fs');
|
|
30
|
+
const path = require('path');
|
|
31
|
+
const {
|
|
32
|
+
loadSpec, parseArgs, walkDir, escapeRegex, escapeMd, formatParams,
|
|
33
|
+
coverageBadge, loadTypeScript, info, ok, warn,
|
|
34
|
+
} = require('./rn-extract-interfaces.cjs');
|
|
35
|
+
|
|
36
|
+
const ts = loadTypeScript();
|
|
37
|
+
|
|
38
|
+
// ════════════════════════════════════════════════════════════
|
|
39
|
+
// 正则匹配引擎
|
|
40
|
+
// ════════════════════════════════════════════════════════════
|
|
41
|
+
|
|
42
|
+
function extractImportsRegex(content, libName, fullLibName) {
|
|
43
|
+
const namedSymbols = [];
|
|
44
|
+
let defaultAlias = null, hasImport = false;
|
|
45
|
+
const libPatterns = [escapeRegex(libName), escapeRegex(fullLibName), escapeRegex(libName.split('/').pop())].filter((v, i, a) => a.indexOf(v) === i);
|
|
46
|
+
const libRegexStr = libPatterns.join('|');
|
|
47
|
+
let m;
|
|
48
|
+
const esDefaultRegex = new RegExp(`import\\s+(?:type\\s+)?([A-Za-z_$][\\w$]*)(?:\\s*,\\s*\\{[^}]*\\})?\\s+from\\s*['"](?:${libRegexStr})['"]`, 'g');
|
|
49
|
+
while ((m = esDefaultRegex.exec(content)) !== null) { defaultAlias = m[1]; hasImport = true; }
|
|
50
|
+
const esNamespaceRegex = new RegExp(`import\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s*['"](?:${libRegexStr})['"]`, 'g');
|
|
51
|
+
while ((m = esNamespaceRegex.exec(content)) !== null) { defaultAlias = m[1]; hasImport = true; }
|
|
52
|
+
const esNamedRegex = new RegExp(`import\\s+(?:type\\s+)?\\{([^}]*)\\}\\s*from\\s*['"](?:${libRegexStr})['"]`, 'g');
|
|
53
|
+
while ((m = esNamedRegex.exec(content)) !== null) {
|
|
54
|
+
hasImport = true;
|
|
55
|
+
namedSymbols.push(...m[1].split(',').map(s => { const t = s.trim().replace(/\n/g, '').replace(/\s+/g, ' '); const a = t.match(/(\w+)\s+as\s+(\w+)/); return a ? { name: a[1], alias: a[2] } : { name: t, alias: t }; }).filter(s => s.name && s.name.length > 0 && s.name !== 'type'));
|
|
56
|
+
}
|
|
57
|
+
const cjsDefaultRegex = new RegExp(`(?:const|let|var)\\s+([A-Za-z_$][\\w$]*)\\s*=\\s*require\\s*\\(\\s*['"](?:${libRegexStr})['"]\\s*\\)`, 'g');
|
|
58
|
+
while ((m = cjsDefaultRegex.exec(content)) !== null) { if (!defaultAlias) defaultAlias = m[1]; hasImport = true; }
|
|
59
|
+
const cjsNamedRegex = new RegExp(`(?:const|let|var)\\s*\\{([^}]*)\\}\\s*=\\s*require\\s*\\(\\s*['"](?:${libRegexStr})['"]\\s*\\)`, 'g');
|
|
60
|
+
while ((m = cjsNamedRegex.exec(content)) !== null) {
|
|
61
|
+
hasImport = true;
|
|
62
|
+
namedSymbols.push(...m[1].split(',').map(s => { const t = s.trim(); const a = t.match(/(\w+)\s*:\s*(\w+)/); return a ? { name: a[1], alias: a[2] } : { name: t, alias: t }; }).filter(s => s.name && s.name.length > 0));
|
|
63
|
+
}
|
|
64
|
+
if (new RegExp(`import\\s*['"](?:${libRegexStr})['"]`, 'g').test(content)) hasImport = true;
|
|
65
|
+
return { defaultAlias, namedSymbols, hasImport };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function trackInstanceVariablesRegex(content, defaultAlias, namedSymbols, allClassNames) {
|
|
69
|
+
const varMap = {};
|
|
70
|
+
const classSet = new Set(allClassNames);
|
|
71
|
+
if (defaultAlias) {
|
|
72
|
+
for (const regex of [
|
|
73
|
+
new RegExp(`(?:const|let|var)\\s+(\\w+)\\s*=\\s*${escapeRegex(defaultAlias)}\\b(?!\\s*\\.)`, 'g'),
|
|
74
|
+
new RegExp(`(?:const|let|var)\\s+(\\w+)\\s*=\\s*${escapeRegex(defaultAlias)}\\s*\\.\\s*(${[...classSet].map(escapeRegex).join('|')})\\s*\\(`, 'g'),
|
|
75
|
+
]) { let m; while ((m = regex.exec(content)) !== null) { const vn = m[1], cls = m[2] || defaultAlias; if (!varMap[vn]) varMap[vn] = []; if (!varMap[vn].includes(cls)) varMap[vn].push(cls); } }
|
|
76
|
+
}
|
|
77
|
+
for (const sym of namedSymbols) {
|
|
78
|
+
for (const regex of [
|
|
79
|
+
new RegExp(`(?:const|let|var)\\s+(\\w+)\\s*=\\s*new\\s+${sym.alias}\\s*\\(`, 'g'),
|
|
80
|
+
new RegExp(`(?:const|let|var)\\s+(\\w+)\\s*:\\s*${sym.alias}\\b`, 'g'),
|
|
81
|
+
]) { let m; while ((m = regex.exec(content)) !== null) { if (!varMap[m[1]]) varMap[m[1]] = []; if (!varMap[m[1]].includes(sym.alias)) varMap[m[1]].push(sym.alias); } }
|
|
82
|
+
}
|
|
83
|
+
return varMap;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function matchCoverageRegex(interfaces, files, libName, fullLibName) {
|
|
87
|
+
const fileCoverageMap = {};
|
|
88
|
+
const allClassNames = [...new Set(interfaces.filter(i => i.className).map(i => i.className))];
|
|
89
|
+
for (const filePath of files) {
|
|
90
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
91
|
+
const fileName = path.basename(filePath);
|
|
92
|
+
const { defaultAlias, namedSymbols, hasImport } = extractImportsRegex(content, libName, fullLibName);
|
|
93
|
+
const sideEffectInterfaces = interfaces.filter(i => i.type === 'side-effect');
|
|
94
|
+
if (!hasImport && sideEffectInterfaces.length === 0) continue;
|
|
95
|
+
const varMap = trackInstanceVariablesRegex(content, defaultAlias, namedSymbols, allClassNames);
|
|
96
|
+
const fileCovered = [];
|
|
97
|
+
for (const iface of interfaces) {
|
|
98
|
+
if (iface.type === 'side-effect') {
|
|
99
|
+
const mem = escapeRegex(iface.memberName);
|
|
100
|
+
const patterns = [new RegExp(`\\b${mem}\\s*\\(`, 'g')];
|
|
101
|
+
if (iface.className) patterns.push(new RegExp(`${escapeRegex(iface.className)}\\s*\\.\\s*${mem}\\s*\\(`, 'g'));
|
|
102
|
+
for (const r of patterns) { if (r.test(content)) { fileCovered.push(iface.fullName); break; } }
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (iface.className === null) {
|
|
106
|
+
if (new RegExp(`\\b${escapeRegex(iface.memberName)}\\s*\\(`, 'g').test(content)) { fileCovered.push(iface.fullName); continue; }
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const ca = defaultAlias;
|
|
110
|
+
if (ca) {
|
|
111
|
+
const mem = escapeRegex(iface.memberName);
|
|
112
|
+
if (new RegExp(`\\b${escapeRegex(ca)}\\s*\\.\\s*${mem}\\s*\\(`, 'g').test(content)) { fileCovered.push(iface.fullName); continue; }
|
|
113
|
+
if (new RegExp(`\\b${escapeRegex(ca)}\\s*\\.\\s*${mem}\\b`, 'g').test(content)) { fileCovered.push(iface.fullName); continue; }
|
|
114
|
+
}
|
|
115
|
+
const classNameUsed = namedSymbols.find(s => s.name === iface.className || s.alias === iface.className);
|
|
116
|
+
if (classNameUsed) {
|
|
117
|
+
const alias = classNameUsed.alias, mem = escapeRegex(iface.memberName);
|
|
118
|
+
if (iface.isStatic) { if (new RegExp(`\\b${escapeRegex(alias)}\\s*\\.\\s*${mem}\\s*\\(`, 'g').test(content)) { fileCovered.push(iface.fullName); continue; } }
|
|
119
|
+
else {
|
|
120
|
+
for (const [vn, cls] of Object.entries(varMap)) { if (cls.includes(alias) && new RegExp(`(?:this\\s*\\.\\s*)?${escapeRegex(vn)}\\s*\\.\\s*${mem}\\s*\\(`, 'g').test(content)) { fileCovered.push(iface.fullName); break; } }
|
|
121
|
+
if (new RegExp(`\\b${escapeRegex(alias)}\\s*\\.\\s*${mem}\\s*\\(`, 'g').test(content)) { fileCovered.push(iface.fullName); continue; }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (ca && iface.className) { if (new RegExp(`\\b${escapeRegex(ca)}\\s*\\.\\s*${escapeRegex(iface.className)}\\s*\\.\\s*${escapeRegex(iface.memberName)}\\s*\\(`, 'g').test(content)) { fileCovered.push(iface.fullName); continue; } }
|
|
125
|
+
}
|
|
126
|
+
for (const iface of interfaces) {
|
|
127
|
+
if (fileCovered.includes(iface.fullName)) continue;
|
|
128
|
+
if ((iface.kind === 'property' || iface.kind === 'field' || iface.kind === 'method') && iface.memberName && iface.memberName.length >= 2) {
|
|
129
|
+
if (new RegExp(`\\b${escapeRegex(iface.memberName)}\\??\\s*:`, 'g').test(content)) fileCovered.push(iface.fullName);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (defaultAlias) {
|
|
133
|
+
for (const iface of interfaces) {
|
|
134
|
+
if (fileCovered.includes(iface.fullName) || !iface.className || iface.isStatic) continue;
|
|
135
|
+
const mem = escapeRegex(iface.memberName);
|
|
136
|
+
if ((iface.kind === 'method' || iface.kind === 'function') && new RegExp(`\\.${mem}\\s*\\(`, 'g').test(content)) fileCovered.push(iface.fullName);
|
|
137
|
+
else if ((iface.kind === 'property' || iface.kind === 'field') && new RegExp(`\\.${mem}\\b`, 'g').test(content)) fileCovered.push(iface.fullName);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const fullName of fileCovered) {
|
|
141
|
+
if (!fileCoverageMap[fileName]) fileCoverageMap[fileName] = { count: 0, interfaces: [] };
|
|
142
|
+
fileCoverageMap[fileName].count++;
|
|
143
|
+
fileCoverageMap[fileName].interfaces.push(fullName);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return aggregateResults(interfaces, fileCoverageMap, libName, files.length);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ════════════════════════════════════════════════════════════
|
|
150
|
+
// AST 匹配引擎
|
|
151
|
+
// ════════════════════════════════════════════════════════════
|
|
152
|
+
|
|
153
|
+
function extractImportedSymbolsAST(sourceFile, libName, fullLibName) {
|
|
154
|
+
const symbols = new Map();
|
|
155
|
+
const libSuffix = libName.split('/').pop();
|
|
156
|
+
for (const stmt of sourceFile.statements) {
|
|
157
|
+
if (ts.isImportDeclaration(stmt)) {
|
|
158
|
+
const ms = stmt.moduleSpecifier;
|
|
159
|
+
if (!ms || !ts.isStringLiteral(ms)) continue;
|
|
160
|
+
const fromLib = ms.text;
|
|
161
|
+
if (fromLib !== libName && fromLib !== fullLibName && !fromLib.endsWith('/' + libSuffix)) continue;
|
|
162
|
+
const ic = stmt.importClause;
|
|
163
|
+
if (!ic) { symbols.set('__sideEffect__', true); continue; }
|
|
164
|
+
if (ic.name) symbols.set('default', ic.name.text);
|
|
165
|
+
if (ic.namedBindings && ts.isNamespaceImport(ic.namedBindings) && ic.namedBindings.name) symbols.set('default', ic.namedBindings.name.text);
|
|
166
|
+
if (ic.namedBindings && ts.isNamedImports(ic.namedBindings)) for (const el of ic.namedBindings.elements) { const n = el.propertyName ? el.propertyName.text : el.name.text; symbols.set(n, el.name.text); }
|
|
167
|
+
}
|
|
168
|
+
if (ts.isVariableStatement(stmt)) {
|
|
169
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
170
|
+
if (!decl.initializer || !ts.isCallExpression(decl.initializer)) continue;
|
|
171
|
+
const callee = decl.initializer.expression;
|
|
172
|
+
if (!ts.isIdentifier(callee) || callee.text !== 'require' || decl.initializer.arguments.length === 0) continue;
|
|
173
|
+
const arg = decl.initializer.arguments[0];
|
|
174
|
+
if (!ts.isStringLiteral(arg)) continue;
|
|
175
|
+
const fromLib = arg.text;
|
|
176
|
+
if (fromLib !== libName && fromLib !== fullLibName && !fromLib.endsWith('/' + libSuffix)) continue;
|
|
177
|
+
if (ts.isIdentifier(decl.name)) symbols.set('default', decl.name.text);
|
|
178
|
+
if (ts.isObjectBindingPattern(decl.name)) for (const el of decl.name.elements) { if (el.propertyName && ts.isIdentifier(el.propertyName)) symbols.set(el.propertyName.text, ts.isIdentifier(el.name) ? el.name.text : el.propertyName.text); else if (ts.isIdentifier(el.name)) symbols.set(el.name.text, el.name.text); }
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return symbols;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function trackInstanceVariablesAST(sourceFile, checker, importedSymbols) {
|
|
186
|
+
const varMap = {};
|
|
187
|
+
function visit(node) {
|
|
188
|
+
if (ts.isVariableDeclaration(node) && node.name) {
|
|
189
|
+
if (ts.isIdentifier(node.name)) {
|
|
190
|
+
trackVar(node.name.text, node);
|
|
191
|
+
} else if (ts.isArrayBindingPattern(node.name)) {
|
|
192
|
+
let inferredType = null;
|
|
193
|
+
if (node.initializer && ts.isCallExpression(node.initializer) && node.initializer.typeArguments && node.initializer.typeArguments.length > 0) {
|
|
194
|
+
const ta = node.initializer.typeArguments[0];
|
|
195
|
+
if (ta && ts.isTypeReferenceNode(ta) && ts.isIdentifier(ta.typeName)) {
|
|
196
|
+
inferredType = ta.typeName.text;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
for (let i = 0; i < node.name.elements.length; i++) {
|
|
200
|
+
const el = node.name.elements[i];
|
|
201
|
+
if (ts.isBindingElement(el) && ts.isIdentifier(el.name)) {
|
|
202
|
+
trackVar(el.name.text, el);
|
|
203
|
+
if (i === 0 && inferredType) {
|
|
204
|
+
for (const [cn, alias] of importedSymbols) {
|
|
205
|
+
if (cn === inferredType || alias === inferredType) {
|
|
206
|
+
if (!varMap[el.name.text]) varMap[el.name.text] = [];
|
|
207
|
+
const dn = importedSymbols.get(cn) || cn;
|
|
208
|
+
if (!varMap[el.name.text].includes(dn)) varMap[el.name.text].push(dn);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (ts.isParameter(node) && node.name && ts.isIdentifier(node.name)) trackVar(node.name.text, node);
|
|
217
|
+
ts.forEachChild(node, visit);
|
|
218
|
+
}
|
|
219
|
+
function trackVar(varName, node) {
|
|
220
|
+
try {
|
|
221
|
+
const typeStr = checker.typeToString(checker.getTypeAtLocation(node));
|
|
222
|
+
for (const [cn, alias] of importedSymbols) {
|
|
223
|
+
if (cn === 'default' || cn === '__sideEffect__') continue;
|
|
224
|
+
if (typeStr === cn || typeStr === alias || typeStr.startsWith(cn + ' |') || typeStr.startsWith(alias + ' |') || typeStr.includes(cn) || typeStr.includes(alias)) {
|
|
225
|
+
if (!varMap[varName]) varMap[varName] = [];
|
|
226
|
+
const dn = importedSymbols.get(cn) || cn;
|
|
227
|
+
if (!varMap[varName].includes(dn)) varMap[varName].push(dn);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} catch {}
|
|
231
|
+
}
|
|
232
|
+
visit(sourceFile);
|
|
233
|
+
return varMap;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function collectCoverageAST(sourceFile, checker, interfaces, importedSymbols, varMap) {
|
|
237
|
+
const covered = new Set();
|
|
238
|
+
const ifaceByFullName = new Map();
|
|
239
|
+
const ifaceByMemberName = new Map();
|
|
240
|
+
for (const iface of interfaces) {
|
|
241
|
+
ifaceByFullName.set(iface.fullName, iface);
|
|
242
|
+
if (!ifaceByMemberName.has(iface.memberName)) ifaceByMemberName.set(iface.memberName, []);
|
|
243
|
+
ifaceByMemberName.get(iface.memberName).push(iface);
|
|
244
|
+
}
|
|
245
|
+
const importedClassNames = new Set();
|
|
246
|
+
for (const [, alias] of importedSymbols) if (alias !== 'default' && alias !== '__sideEffect__') importedClassNames.add(alias);
|
|
247
|
+
const defaultAlias = importedSymbols.get('default');
|
|
248
|
+
|
|
249
|
+
function visit(node) {
|
|
250
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
251
|
+
const propName = node.name.text;
|
|
252
|
+
const expr = node.expression;
|
|
253
|
+
if (ts.isIdentifier(expr) || (ts.isNonNullExpression(expr) && ts.isIdentifier(expr.expression))) {
|
|
254
|
+
const varName = ts.isIdentifier(expr) ? expr.text : expr.expression.text;
|
|
255
|
+
const classNames = varMap[varName];
|
|
256
|
+
if (classNames) for (const cn of classNames) { const fn = `${cn}.${propName}`; if (ifaceByFullName.has(fn)) covered.add(fn); }
|
|
257
|
+
}
|
|
258
|
+
if (ts.isIdentifier(expr) && importedClassNames.has(expr.text)) { const fn = `${expr.text}.${propName}`; if (ifaceByFullName.has(fn)) covered.add(fn); }
|
|
259
|
+
if (defaultAlias && ts.isIdentifier(expr) && expr.text === defaultAlias) {
|
|
260
|
+
for (const iface of interfaces) if (iface.className && iface.memberName === propName) covered.add(iface.fullName);
|
|
261
|
+
const cands = ifaceByMemberName.get(propName);
|
|
262
|
+
if (cands) for (const c of cands) if (c.className === null) covered.add(c.fullName);
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
const rt = checker.typeToString(checker.getTypeAtLocation(expr));
|
|
266
|
+
if (rt) {
|
|
267
|
+
const rtParts = rt.split('|').map(s => s.trim());
|
|
268
|
+
for (const [cn, alias] of importedSymbols) { if (cn === 'default' || cn === '__sideEffect__') continue; if (rtParts.includes(cn) || rtParts.includes(alias) || rt === cn || rt === alias) { const fn = `${alias}.${propName}`; if (ifaceByFullName.has(fn)) covered.add(fn); } }
|
|
269
|
+
for (const typeName of rtParts) { const fn = `${typeName}.${propName}`; if (ifaceByFullName.has(fn)) covered.add(fn); }
|
|
270
|
+
}
|
|
271
|
+
} catch {}
|
|
272
|
+
}
|
|
273
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
274
|
+
const cands = ifaceByMemberName.get(node.expression.text);
|
|
275
|
+
if (cands) for (const c of cands) if (c.className === null && (c.kind === 'function' || c.kind === 'variable')) covered.add(c.fullName);
|
|
276
|
+
}
|
|
277
|
+
if (ts.isIdentifier(node)) {
|
|
278
|
+
const cands = ifaceByMemberName.get(node.text);
|
|
279
|
+
if (cands) for (const c of cands) if (c.className === null && (c.kind === 'variable' || c.kind === 'function')) covered.add(c.fullName);
|
|
280
|
+
}
|
|
281
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
282
|
+
let ctxType = null;
|
|
283
|
+
try { const t = checker.getContextualType(node); if (t) ctxType = checker.typeToString(t); } catch {}
|
|
284
|
+
for (const prop of node.properties) {
|
|
285
|
+
if (!ts.isPropertyAssignment(prop) && !ts.isShorthandPropertyAssignment(prop)) continue;
|
|
286
|
+
let pn = null;
|
|
287
|
+
if (ts.isIdentifier(prop.name)) pn = prop.name.text;
|
|
288
|
+
else if (ts.isStringLiteral(prop.name)) pn = prop.name.text;
|
|
289
|
+
if (!pn) continue;
|
|
290
|
+
if (ctxType) for (const [cn, alias] of importedSymbols) { if (cn === 'default' || cn === '__sideEffect__') continue; if (ctxType === cn || ctxType === alias || ctxType.startsWith(cn) || ctxType.startsWith(alias)) { const fn = `${alias}.${pn}`; if (ifaceByFullName.has(fn)) covered.add(fn); } }
|
|
291
|
+
if (!ctxType) {
|
|
292
|
+
const cands = ifaceByMemberName.get(pn);
|
|
293
|
+
if (cands) for (const c of cands) if (c.kind === 'property' || c.kind === 'field') covered.add(c.fullName);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (defaultAlias && ts.isPropertyAccessExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === defaultAlias) {
|
|
298
|
+
const fn = `${node.expression.name.text}.${node.name.text}`;
|
|
299
|
+
if (ifaceByFullName.has(fn)) covered.add(fn);
|
|
300
|
+
}
|
|
301
|
+
if (ts.isJsxAttribute(node) && node.name) {
|
|
302
|
+
const attrName = node.name.text;
|
|
303
|
+
const ja = node.parent;
|
|
304
|
+
const oe = ja && ja.parent;
|
|
305
|
+
if (oe && (ts.isJsxOpeningElement(oe) || ts.isJsxSelfClosingElement(oe)) && ts.isIdentifier(oe.tagName)) {
|
|
306
|
+
const tn = oe.tagName.text;
|
|
307
|
+
if ((defaultAlias && tn === defaultAlias) || importedClassNames.has(tn)) {
|
|
308
|
+
const cands = ifaceByMemberName.get(attrName);
|
|
309
|
+
if (cands) for (const c of cands) { if (c.kind === 'property' || c.kind === 'field' || c.kind === 'method') covered.add(c.fullName); }
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (ts.isJsxElement(node) && node.children.length > 0 && node.openingElement) {
|
|
314
|
+
const tagName = ts.isIdentifier(node.openingElement.tagName) ? node.openingElement.tagName.text : null;
|
|
315
|
+
if (tagName && ((defaultAlias && tagName === defaultAlias) || importedClassNames.has(tagName))) {
|
|
316
|
+
const hasRealChildren = node.children.some(child => {
|
|
317
|
+
if (ts.isJsxText(child)) return child.text.trim().length > 0;
|
|
318
|
+
return true;
|
|
319
|
+
});
|
|
320
|
+
if (hasRealChildren) {
|
|
321
|
+
for (const cn of [tagName + 'Props', 'Native' + tagName + 'Props']) {
|
|
322
|
+
const fn = `${cn}.children`;
|
|
323
|
+
if (ifaceByFullName.has(fn)) covered.add(fn);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
ts.forEachChild(node, visit);
|
|
329
|
+
}
|
|
330
|
+
visit(sourceFile);
|
|
331
|
+
return covered;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function matchCoverageAST(interfaces, testFiles, libName, fullLibName, libRoot) {
|
|
335
|
+
if (!ts) { warn('TypeScript 模块不可用,降级到正则模式'); return null; }
|
|
336
|
+
// Windows 兼容:TS 编译器内部使用正斜杠 / 作为路径分隔符
|
|
337
|
+
const toPosix = (p) => p.replace(/\\/g, '/');
|
|
338
|
+
const libSourceFiles = [];
|
|
339
|
+
function collectLibFiles(dir) {
|
|
340
|
+
if (!fs.existsSync(dir)) return;
|
|
341
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
342
|
+
if (['node_modules', 'harmony', 'android', 'ios', '.git'].includes(entry.name)) continue;
|
|
343
|
+
const fp = path.join(dir, entry.name);
|
|
344
|
+
if (entry.isDirectory()) collectLibFiles(fp);
|
|
345
|
+
else if (/\.(ts|tsx|js|jsx|d\.ts)$/.test(entry.name)) libSourceFiles.push(fp);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
collectLibFiles(libRoot);
|
|
349
|
+
const allSourceFiles = [...libSourceFiles, ...testFiles];
|
|
350
|
+
const fileContents = {};
|
|
351
|
+
for (const rp of allSourceFiles) { try { fileContents[toPosix(rp)] = fs.readFileSync(rp, 'utf-8'); } catch {} }
|
|
352
|
+
const posixLibSourceFiles = libSourceFiles.map(toPosix);
|
|
353
|
+
const posixRootNames = allSourceFiles.map(toPosix);
|
|
354
|
+
const compilerOptions = { target: ts.ScriptTarget.ES2021, module: ts.ModuleKind.ESNext, strict: false, skipLibCheck: true, noEmit: true, allowJs: true, allowSyntheticDefaultImports: true, esModuleInterop: true, jsx: ts.JsxEmit.React };
|
|
355
|
+
const host = {
|
|
356
|
+
getSourceFile(fileName, lv) {
|
|
357
|
+
const content = fileContents[fileName] || fileContents[toPosix(fileName)];
|
|
358
|
+
if (content) { const kind = fileName.endsWith('.tsx') ? ts.ScriptKind.TSX : fileName.endsWith('.jsx') ? ts.ScriptKind.JSX : fileName.endsWith('.js') ? ts.ScriptKind.JS : ts.ScriptKind.TS; return ts.createSourceFile(fileName, content, lv, true, kind); }
|
|
359
|
+
try { const c = ts.sys.readFile(fileName); if (c !== undefined) return ts.createSourceFile(fileName, c, lv, true); } catch {}
|
|
360
|
+
return undefined;
|
|
361
|
+
},
|
|
362
|
+
getDefaultLibFileName() { return ts.getDefaultLibFilePath(compilerOptions); },
|
|
363
|
+
writeFile() {}, getCurrentDirectory() { return process.cwd(); },
|
|
364
|
+
getCanonicalFileName(fn) { return fn; }, useCaseSensitiveFileNames() { return true; }, getNewLine() { return '\n'; },
|
|
365
|
+
fileExists(fn) { return !!fileContents[fn] || !!fileContents[toPosix(fn)] || ts.sys.fileExists(fn); },
|
|
366
|
+
readFile(fn) { return fileContents[fn] || fileContents[toPosix(fn)] || ts.sys.readFile(fn); },
|
|
367
|
+
resolveModuleNames(moduleNames, containingFile) {
|
|
368
|
+
const resolved = [];
|
|
369
|
+
for (const moduleName of moduleNames) {
|
|
370
|
+
let rp = null;
|
|
371
|
+
const baseDir = path.dirname(containingFile);
|
|
372
|
+
if (moduleName.startsWith('.')) {
|
|
373
|
+
for (const ext of ['.ts', '.tsx', '.js', '.jsx', '.d.ts']) { const p = toPosix(path.resolve(baseDir, moduleName + ext)); if (fileContents[p] || ts.sys.fileExists(p)) { rp = p; break; } }
|
|
374
|
+
if (!rp) for (const ext of ['.ts', '.tsx', '.js', '.jsx']) { const p = toPosix(path.resolve(baseDir, moduleName, 'index' + ext)); if (fileContents[p] || ts.sys.fileExists(p)) { rp = p; break; } }
|
|
375
|
+
}
|
|
376
|
+
if ((moduleName === libName || moduleName === fullLibName) && !rp) for (const sf of posixLibSourceFiles) if (sf.endsWith('index.ts') || sf.endsWith('index.js') || sf.endsWith('index.tsx')) { rp = sf; break; }
|
|
377
|
+
resolved.push(rp ? { resolvedFileName: rp, extension: '.ts' } : undefined);
|
|
378
|
+
}
|
|
379
|
+
return resolved;
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
const program = ts.createProgram(posixRootNames, compilerOptions, host);
|
|
383
|
+
const checker = program.getTypeChecker();
|
|
384
|
+
const hasSideEffectInterfaces = interfaces.some(i => i.type === 'side-effect');
|
|
385
|
+
const fileCoverageMap = {};
|
|
386
|
+
for (const testFile of testFiles) {
|
|
387
|
+
const sourceFile = program.getSourceFile(toPosix(testFile));
|
|
388
|
+
if (!sourceFile) continue;
|
|
389
|
+
const fileName = path.basename(testFile);
|
|
390
|
+
const importedSymbols = extractImportedSymbolsAST(sourceFile, libName, fullLibName);
|
|
391
|
+
if (importedSymbols.size === 0 && !hasSideEffectInterfaces) continue;
|
|
392
|
+
const varMap = trackInstanceVariablesAST(sourceFile, checker, importedSymbols);
|
|
393
|
+
for (const [cn, alias] of importedSymbols) {
|
|
394
|
+
if (cn === 'default' || cn === '__sideEffect__') continue;
|
|
395
|
+
const varIface = interfaces.find(i => i.memberName === cn && i.className === null && i.kind === 'variable');
|
|
396
|
+
if (varIface && varIface.returnType && varIface.returnType !== '-') {
|
|
397
|
+
const typeParts = varIface.returnType.split('|').map(s => s.trim());
|
|
398
|
+
for (const typeName of typeParts) {
|
|
399
|
+
if (!varMap[alias]) varMap[alias] = [];
|
|
400
|
+
if (!varMap[alias].includes(typeName)) varMap[alias].push(typeName);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const fileCovered = collectCoverageAST(sourceFile, checker, interfaces, importedSymbols, varMap);
|
|
405
|
+
if (hasSideEffectInterfaces) {
|
|
406
|
+
const content = fs.readFileSync(testFile, 'utf-8');
|
|
407
|
+
for (const iface of interfaces) {
|
|
408
|
+
if (iface.type !== 'side-effect' || fileCovered.has(iface.fullName)) continue;
|
|
409
|
+
const mem = escapeRegex(iface.memberName);
|
|
410
|
+
const patterns = [new RegExp(`\\b${mem}\\s*\\(`, 'g')];
|
|
411
|
+
if (iface.className) patterns.push(new RegExp(`${escapeRegex(iface.className)}\\s*\\.\\s*${mem}\\s*\\(`, 'g'));
|
|
412
|
+
for (const r of patterns) { if (r.test(content)) { fileCovered.add(iface.fullName); break; } }
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (fileCovered.size > 0) fileCoverageMap[fileName] = { count: fileCovered.size, interfaces: Array.from(fileCovered) };
|
|
416
|
+
}
|
|
417
|
+
return aggregateResults(interfaces, fileCoverageMap, libName, testFiles.length);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// ════════════════════════════════════════════════════════════
|
|
421
|
+
// 结果聚合
|
|
422
|
+
// ════════════════════════════════════════════════════════════
|
|
423
|
+
|
|
424
|
+
function aggregateResults(interfaces, fileCoverageMap, libName, sourceFileCount) {
|
|
425
|
+
const coveredSet = new Set();
|
|
426
|
+
for (const fc of Object.values(fileCoverageMap)) for (const intf of fc.interfaces) coveredSet.add(intf);
|
|
427
|
+
const classCoverageMap = {}, covered = [], uncovered = [];
|
|
428
|
+
for (const iface of interfaces) {
|
|
429
|
+
const cn = iface.className || '';
|
|
430
|
+
if (!classCoverageMap[cn]) classCoverageMap[cn] = { total: 0, covered: 0 };
|
|
431
|
+
classCoverageMap[cn].total++;
|
|
432
|
+
if (coveredSet.has(iface.fullName)) { classCoverageMap[cn].covered++; covered.push({ ...iface, files: Object.entries(fileCoverageMap).filter(([_, fc]) => fc.interfaces.includes(iface.fullName)).map(([fn]) => fn) }); }
|
|
433
|
+
else uncovered.push(iface);
|
|
434
|
+
}
|
|
435
|
+
const N = interfaces.length, M = coveredSet.size, X = N > 0 ? (M / N * 100).toFixed(2) : '0.00';
|
|
436
|
+
const byKind = {};
|
|
437
|
+
for (const kind of ['method', 'constructor', 'property', 'field', 'enumValue', 'function', 'variable', 'type']) {
|
|
438
|
+
const ki = interfaces.filter(i => i.kind === kind);
|
|
439
|
+
const kc = ki.filter(i => coveredSet.has(i.fullName));
|
|
440
|
+
byKind[kind] = { total: ki.length, covered: kc.length, rate: ki.length > 0 ? (kc.length / ki.length * 100).toFixed(2) : '-' };
|
|
441
|
+
}
|
|
442
|
+
const classCoverage = [];
|
|
443
|
+
for (const [cn, d] of Object.entries(classCoverageMap)) if (cn !== '') classCoverage.push({ className: cn, total: d.total, covered: d.covered, uncovered: d.total - d.covered, rate: d.total > 0 ? (d.covered / d.total * 100).toFixed(2) : '-' });
|
|
444
|
+
return {
|
|
445
|
+
libraryName: libName, totalInterfacesClassLevel: Object.keys(classCoverageMap).filter(k => k !== '').length,
|
|
446
|
+
totalInterfacesMethodLevel: N, coveredMethodCount: M, coverageRateMethodLevel: X,
|
|
447
|
+
byKind, classCoverage, covered, uncovered,
|
|
448
|
+
fileCoverage: Object.entries(fileCoverageMap).map(([file, data]) => ({ file, count: data.count, interfaces: data.interfaces })),
|
|
449
|
+
sourceFileCount,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// ════════════════════════════════════════════════════════════
|
|
454
|
+
// Markdown 渲染
|
|
455
|
+
// ════════════════════════════════════════════════════════════
|
|
456
|
+
|
|
457
|
+
function renderHeader(result, title) {
|
|
458
|
+
let lines = `# ${title || result.libraryName + ' 覆盖率分析报告'}\n\n> 本报告自动生成。\n\n## 基本信息\n\n| 属性 | 值 |\n|------|----|\n| 库名 | \`${result.libraryName}\` |\n| 源文件数 | ${result.sourceFileCount || '-'} |\n| 生成时间 | ${new Date(Date.now() + 8 * 3600 * 1000).toISOString().replace('T', ' ').replace('Z', '+08:00')} |\n`;
|
|
459
|
+
if ((result.filteredTypeDeclCount || 0) > 0 || (result.filteredInternalCmdCount || 0) > 0) {
|
|
460
|
+
lines += `| 过滤类型声明 | ${result.filteredTypeDeclCount || 0} |\n| 过滤内部 Fabric 命令 | ${result.filteredInternalCmdCount || 0} |\n| 实际统计接口 | ${result.totalInterfacesMethodLevel} |\n`;
|
|
461
|
+
}
|
|
462
|
+
return lines;
|
|
463
|
+
}
|
|
464
|
+
function renderOverview(result) {
|
|
465
|
+
const rate = parseFloat(result.coverageRateMethodLevel) || 0;
|
|
466
|
+
const filled = Math.round(rate / 5), empty = 20 - filled;
|
|
467
|
+
return `## 覆盖率总览\n\n### 方法级覆盖率: ${result.coverageRateMethodLevel}% (${coverageBadge(result.coverageRateMethodLevel)})\n\n| 统计项 | 数量 |\n|--------|------|\n| 类/接口总数 (S) | ${result.totalInterfacesClassLevel} |\n| 方法/属性总数 (N) | ${result.totalInterfacesMethodLevel} |\n| 已覆盖 (M) | ${result.coveredMethodCount} |\n| 未覆盖 | ${result.totalInterfacesMethodLevel - result.coveredMethodCount} |\n\n\`\`\`\n覆盖率进度: [${'\u2588'.repeat(filled)}${'\u2591'.repeat(empty)}] ${rate.toFixed(2)}%\n\`\`\`\n`;
|
|
468
|
+
}
|
|
469
|
+
function renderByKind(result) {
|
|
470
|
+
let lines = '### 按接口类型统计\n\n| 类型 | 总数 | 已覆盖 | 覆盖率 | 状态 |\n|------|------|--------|--------|------|\n';
|
|
471
|
+
for (const [kind, d] of Object.entries(result.byKind || {})) if (d.total > 0) lines += `| ${kind} | ${d.total} | ${d.covered} | ${d.rate}% | ${coverageBadge(d.rate)} |\n`;
|
|
472
|
+
return lines + '\n';
|
|
473
|
+
}
|
|
474
|
+
function renderClassCoverage(result) {
|
|
475
|
+
let lines = '## 类级覆盖率\n\n| # | 类名 | 总数 | 已覆盖 | 未覆盖 | 覆盖率 | 状态 |\n|---|------|------|--------|--------|--------|------|\n';
|
|
476
|
+
[...(result.classCoverage || [])].sort((a, b) => (parseFloat(a.rate) || 0) - (parseFloat(b.rate) || 0)).forEach((c, i) => { lines += `| ${i + 1} | \`${c.className}\` | ${c.total} | ${c.covered} | ${c.uncovered} | ${c.rate}% | ${coverageBadge(c.rate)} |\n`; });
|
|
477
|
+
return lines + '\n';
|
|
478
|
+
}
|
|
479
|
+
function renderFileCoverage(result) {
|
|
480
|
+
let lines = '## 文件覆盖详情\n\n| # | 文件 | 覆盖接口数 | 覆盖的接口 |\n|---|------|-----------|-----------|\n';
|
|
481
|
+
[...(result.fileCoverage || [])].sort((a, b) => b.count - a.count).forEach((f, i) => { const ifaces = f.interfaces.slice(0, 10).map(i => `\`${i}\``).join(', '); lines += `| ${i + 1} | \`${f.file}\` | ${f.count} | ${ifaces}${f.interfaces.length > 10 ? ` ... (+${f.interfaces.length - 10})` : ''} |\n`; });
|
|
482
|
+
return lines + '\n';
|
|
483
|
+
}
|
|
484
|
+
function renderCoveredDetails(result) {
|
|
485
|
+
const covered = result.covered || [];
|
|
486
|
+
if (covered.length === 0) return '## 已覆盖接口详情\n\n*暂无已覆盖接口*\n\n';
|
|
487
|
+
const grouped = {};
|
|
488
|
+
for (const c of covered) { const cn = c.className || '(顶层)'; if (!grouped[cn]) grouped[cn] = []; grouped[cn].push(c); }
|
|
489
|
+
let lines = '## 已覆盖接口详情\n\n';
|
|
490
|
+
let idx = 0;
|
|
491
|
+
for (const [cn, members] of Object.entries(grouped)) { idx++; lines += `### ${idx}. ${cn}\n\n| # | 接口 | 类型 | 层级 | 签名 | 覆盖文件 |\n|---|------|------|------|------|----------|\n`; members.forEach((m, i) => { const files = (m.files || []).slice(0, 3).map(f => `\`${f}\``).join(', '); lines += `| ${i + 1} | \`${m.memberName}\` | ${m.kind} | ${m.layer || '-'} | \`${escapeMd(m.signature)}\` | ${files}${m.files && m.files.length > 3 ? ` +${m.files.length - 3}` : ''} |\n`; }); lines += '\n'; }
|
|
492
|
+
return lines;
|
|
493
|
+
}
|
|
494
|
+
function renderUncoveredDetails(result) {
|
|
495
|
+
const uncovered = result.uncovered || [];
|
|
496
|
+
if (uncovered.length === 0) return '## 未覆盖接口详情\n\n*所有接口均已覆盖!*\n\n';
|
|
497
|
+
const grouped = {};
|
|
498
|
+
for (const u of uncovered) { const cn = u.className || '(顶层)'; if (!grouped[cn]) grouped[cn] = []; grouped[cn].push(u); }
|
|
499
|
+
let lines = '## 未覆盖接口详情\n\n';
|
|
500
|
+
let idx = 0;
|
|
501
|
+
for (const [cn, members] of Object.entries(grouped)) { idx++; lines += `### ${idx}. ${cn} (${members.length} 个未覆盖)\n\n| # | 接口 | 类型 | 层级 | 参数 | 返回类型 | 说明 |\n|---|------|------|------|------|----------|------|\n`; members.forEach((m, i) => { lines += `| ${i + 1} | \`${m.memberName}\` | ${m.kind} | ${m.layer || '-'} | ${escapeMd(formatParams(m.params))} | ${escapeMd(m.returnType)} | ${escapeMd(m.description)} |\n`; }); lines += '\n'; }
|
|
502
|
+
return lines;
|
|
503
|
+
}
|
|
504
|
+
function renderRecommendations(result) {
|
|
505
|
+
const uncovered = result.uncovered || [];
|
|
506
|
+
const rate = parseFloat(result.coverageRateMethodLevel) || 0;
|
|
507
|
+
let lines = '## 覆盖率提升建议\n\n';
|
|
508
|
+
lines += rate >= 80 ? '覆盖率优秀!以下接口仍可补充测试:\n' : rate >= 50 ? '覆盖率中等,建议优先补充以下接口的测试:\n' : '覆盖率较低,强烈建议补充以下接口的测试:\n\n';
|
|
509
|
+
const priority = uncovered.sort((a, b) => { const ko = { method: 0, function: 1, property: 2, field: 3, variable: 4, enumValue: 5, type: 6 }; const ka = ko[a.kind] ?? 99, kb = ko[b.kind] ?? 99; return ka !== kb ? ka - kb : (a.className || '').localeCompare(b.className || ''); });
|
|
510
|
+
priority.slice(0, 20).forEach((u, i) => { lines += `${i + 1}. [ ] ${u.className ? `\`${u.className}.\`` : ''}\`${u.memberName}\` — ${u.kind}${u.isStatic ? ' (静态)' : ''}${formatParams(u.params) ? ` (${formatParams(u.params)})` : ''}\n`; });
|
|
511
|
+
if (priority.length > 20) lines += `- ... 还有 ${priority.length - 20} 个未覆盖接口\n`;
|
|
512
|
+
return lines + '\n';
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// ════════════════════════════════════════════════════════════
|
|
516
|
+
// 主入口
|
|
517
|
+
// ════════════════════════════════════════════════════════════
|
|
518
|
+
|
|
519
|
+
const args = parseArgs(process.argv.slice(2));
|
|
520
|
+
|
|
521
|
+
if (!args.spec && !args.libroot && !args.repoDir) {
|
|
522
|
+
console.error('用法: node rn-analyze-test-coverage.cjs --spec <spec.json> --libroot <库根目录>');
|
|
523
|
+
console.error(' 或: node rn-analyze-test-coverage.cjs --libroot <库根目录> [--version <上游版本>]');
|
|
524
|
+
process.exit(1);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const loaded = loadSpec(args);
|
|
528
|
+
if (!loaded) { console.error('无法加载接口规格数据'); process.exit(1); }
|
|
529
|
+
|
|
530
|
+
const { spec, libRoot, specBasename } = loaded;
|
|
531
|
+
|
|
532
|
+
// 自动检测测试源码目录
|
|
533
|
+
function detectTestDir(libRoot) {
|
|
534
|
+
for (const c of [
|
|
535
|
+
path.join(libRoot, 'example', 'src', 'test'),
|
|
536
|
+
path.join(libRoot, 'example', 'src', 'tests'),
|
|
537
|
+
path.join(libRoot, 'example', '__tests__'),
|
|
538
|
+
path.join(libRoot, 'demo', '__tests__'),
|
|
539
|
+
path.join(libRoot, 'demo', 'src', 'test'),
|
|
540
|
+
path.join(libRoot, 'demo', 'src', 'tests'),
|
|
541
|
+
path.join(libRoot, '__tests__'),
|
|
542
|
+
path.join(libRoot, 'test'),
|
|
543
|
+
path.join(libRoot, 'tests'),
|
|
544
|
+
]) { if (fs.existsSync(c)) return c; }
|
|
545
|
+
return path.join(libRoot, '__tests__');
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const srcDir = args.src || detectTestDir(libRoot);
|
|
549
|
+
const mode = args.mode || 'auto';
|
|
550
|
+
const libName = spec.libraryAlias || spec.libraryName || '';
|
|
551
|
+
const fullLibName = spec.libraryName || '';
|
|
552
|
+
const allInterfaces = spec.interfaces || [];
|
|
553
|
+
const jsMethodNames = new Set(
|
|
554
|
+
allInterfaces.filter(i => i.layer === 'js' && i.kind === 'method').map(i => i.memberName)
|
|
555
|
+
);
|
|
556
|
+
const camelSplit = s => s.replace(/([a-z])([A-Z])/g, '$1 $2').split(/\s+/).filter(Boolean).map(t => t.toLowerCase());
|
|
557
|
+
const jsMethodTokens = [...jsMethodNames].map(camelSplit);
|
|
558
|
+
let filteredTypeDeclCount = 0, filteredInternalCmdCount = 0;
|
|
559
|
+
const interfaces = allInterfaces.filter(i => {
|
|
560
|
+
if (i.kind === 'type' && i.memberName === i.className) { filteredTypeDeclCount++; return false; }
|
|
561
|
+
if (i.type === 'fabric-spec' && i.kind === 'method') {
|
|
562
|
+
const fabTokens = camelSplit(i.memberName);
|
|
563
|
+
for (const jsTokens of jsMethodTokens) {
|
|
564
|
+
if (jsTokens.length >= 2 && jsTokens.every(t => fabTokens.includes(t))) { filteredInternalCmdCount++; return false; }
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return true;
|
|
568
|
+
});
|
|
569
|
+
if (filteredTypeDeclCount > 0 || filteredInternalCmdCount > 0) {
|
|
570
|
+
info(`过滤: ${filteredTypeDeclCount} 个类型声明, ${filteredInternalCmdCount} 个内部 Fabric 命令`);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
info('[Test 覆盖率分析]');
|
|
574
|
+
info(`库名: ${libName} (完整: ${fullLibName})`);
|
|
575
|
+
info(`源码目录: ${srcDir}`);
|
|
576
|
+
|
|
577
|
+
let result;
|
|
578
|
+
if (!fs.existsSync(srcDir)) {
|
|
579
|
+
warn(`测试源码目录不存在: ${srcDir}`);
|
|
580
|
+
result = aggregateResults(interfaces, {}, libName, 0);
|
|
581
|
+
} else {
|
|
582
|
+
const testFiles = walkDir(srcDir, { exts: ['.ts', '.tsx', '.js', '.jsx', '.ets'], excludeDirs: ['node_modules', 'harmony', 'android', 'ios', '__mocks__'] }, srcDir);
|
|
583
|
+
info(`扫描到 ${testFiles.length} 个源文件`);
|
|
584
|
+
result = null;
|
|
585
|
+
if (testFiles.length > 0) {
|
|
586
|
+
if (mode === 'ast' || (mode === 'auto' && ts)) {
|
|
587
|
+
info('使用 AST 模式匹配...');
|
|
588
|
+
try { result = matchCoverageAST(interfaces, testFiles, libName, fullLibName, libRoot); } catch (e) { warn(`AST 模式出错: ${e.message}`); result = null; }
|
|
589
|
+
if (!result && mode === 'auto') warn('AST 模式失败,降级到正则模式...');
|
|
590
|
+
}
|
|
591
|
+
if (!result) { info('使用正则模式匹配...'); result = matchCoverageRegex(interfaces, testFiles, libName, fullLibName); }
|
|
592
|
+
} else {
|
|
593
|
+
warn('未找到测试源文件');
|
|
594
|
+
result = aggregateResults(interfaces, {}, libName, 0);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
result.specSummary = spec.summary;
|
|
598
|
+
result.filteredTypeDeclCount = filteredTypeDeclCount;
|
|
599
|
+
result.filteredInternalCmdCount = filteredInternalCmdCount;
|
|
600
|
+
result.noTestFiles = !fs.existsSync(srcDir) || (result.sourceFileCount === 0);
|
|
601
|
+
ok(`匹配完成: ${result.coveredMethodCount}/${result.totalInterfacesMethodLevel} (${result.coverageRateMethodLevel}%)`);
|
|
602
|
+
|
|
603
|
+
const title = args.title || `${spec.libraryName} Test 覆盖率分析报告`;
|
|
604
|
+
const parts = [renderHeader(result, title)];
|
|
605
|
+
if (result.noTestFiles) {
|
|
606
|
+
parts.push(`## 无测试文档声明\n\n> **该库未找到 JS 测试源文件。**\n>\n> 测试源码目录: \`${srcDir}\`\n>\n> 覆盖率: **0%**(所有 ${result.totalInterfacesMethodLevel} 个接口均未被测试覆盖)\n\n请添加测试文件后重新运行分析。\n`);
|
|
607
|
+
}
|
|
608
|
+
parts.push(renderOverview(result), renderByKind(result), renderClassCoverage(result), renderUncoveredDetails(result), renderCoveredDetails(result), renderFileCoverage(result), renderRecommendations(result));
|
|
609
|
+
const markdown = parts.join('\n---\n\n');
|
|
610
|
+
|
|
611
|
+
const outputPath = args.output || path.join(libRoot, `03-${specBasename}-Test覆盖率报告.md`);
|
|
612
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
613
|
+
fs.writeFileSync(outputPath, markdown, 'utf-8');
|
|
614
|
+
ok(`报告渲染完成: ${outputPath}`);
|