@ohos-cpf/3rdloop 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +290 -244
- package/bin/3rdloop.mjs +46 -46
- package/lib/cli.js +781 -781
- package/lib/config-cmd.js +451 -451
- package/lib/config.js +318 -318
- package/lib/doctor.js +113 -113
- package/lib/exit-codes.js +30 -30
- package/lib/opencode.js +155 -155
- package/lib/orch.js +426 -426
- package/lib/queries.js +263 -263
- package/lib/step.js +325 -325
- package/lib/ui.js +222 -222
- package/lib/update.js +279 -279
- package/lib/workflow.js +308 -308
- package/lib/workflows.js +131 -131
- package/package.json +50 -50
- package/vendor/Server/Agent/SkillSelector/README.md +343 -343
- package/vendor/Server/Agent/SkillSelector/core/Agent.js +207 -207
- package/vendor/Server/Agent/SkillSelector/index.js +14 -14
- package/vendor/Server/Agent/SkillSelector/llm/llmClient.js +313 -313
- package/vendor/Server/Agent/SkillSelector/llm/prompts.js +161 -161
- package/vendor/Server/Agent/SkillSelector/llm/reactSteps.js +144 -144
- package/vendor/Server/Agent/SkillSelector/matcher/fuzzyMatcher.js +433 -433
- package/vendor/Server/Agent/SkillSelector/scanner/skillScanner.js +382 -382
- package/vendor/Server/Agent/SkillSelector/utils/actionWords.js +59 -59
- package/vendor/Server/Brain/AnalysisStrategies.js +422 -422
- package/vendor/Server/Brain/Brain.js +686 -686
- package/vendor/Server/Brain/DecompositionStrategies.js +621 -621
- package/vendor/Server/Brain/PlanPersistence.js +196 -196
- package/vendor/Server/Brain/SkillExecutor.js +251 -251
- package/vendor/Server/Brain/index.js +11 -11
- package/vendor/Server/CLI/cli.js +275 -275
- package/vendor/Server/CLI/deveco-code/index.js +71 -71
- package/vendor/Server/CLI/deveco-code.js +5 -5
- package/vendor/Server/CLI/opencode/index.js +817 -818
- package/vendor/Server/CLI/opencode.js +5 -5
- package/vendor/Server/DbUse/MessageArchive.js +61 -61
- package/vendor/Server/DbUse/StorageManager.js +107 -107
- package/vendor/Server/DbUse/adapters/BaseAdapter.js +94 -94
- package/vendor/Server/DbUse/adapters/FileAdapter.js +138 -138
- package/vendor/Server/DbUse/adapters/JsonAdapter.js +138 -138
- package/vendor/Server/DbUse/adapters/JsonlAdapter.js +114 -114
- package/vendor/Server/DbUse/adapters/SqliteAdapter.js +157 -157
- package/vendor/Server/DbUse/index.js +160 -160
- package/vendor/Server/DbUse/stores/SessionStore.js +279 -279
- package/vendor/Server/DbUse/stores/TaskExecutionStore.js +133 -133
- package/vendor/Server/DbUse/stores/TaskRegistryStore.js +262 -262
- package/vendor/Server/DbUse/stores/TaskStepStore.js +279 -279
- package/vendor/Server/FlexRunner/FlexRunner.js +1759 -1759
- package/vendor/Server/FlexRunner/index.js +12 -12
- package/vendor/Server/Knowledge/KnowledgeImporter.js +523 -523
- package/vendor/Server/Knowledge/KnowledgeManager.js +341 -341
- package/vendor/Server/Knowledge/index.js +33 -33
- package/vendor/Server/LoopEngine/LoopEngine.js +1133 -1133
- package/vendor/Server/LoopEngine/index.js +11 -11
- package/vendor/Server/Orchestrator/Orchestrator.js +0 -3
- package/vendor/Server/Orchestrator/StepNode.js +312 -312
- package/vendor/Server/Orchestrator/index.js +13 -13
- package/vendor/Server/Routes/controllers/BrainController.js +241 -241
- package/vendor/Server/Routes/controllers/FlexRunnerController.js +1125 -1125
- package/vendor/Server/Routes/controllers/HealthController.js +44 -44
- package/vendor/Server/Routes/controllers/KnowledgeImportController.js +355 -355
- package/vendor/Server/Routes/controllers/LoopEngineController.js +788 -788
- package/vendor/Server/Routes/controllers/StatsController.js +57 -57
- package/vendor/Server/Routes/controllers/StreamController.js +67 -67
- package/vendor/Server/Routes/library/logger.js +179 -179
- package/vendor/Server/Routes/library/zipArchive.js +172 -172
- package/vendor/Server/Routes/router/Router.js +204 -204
- package/vendor/Server/Routes/routes/brain.js +47 -47
- package/vendor/Server/Routes/routes/flexrunner.js +72 -72
- package/vendor/Server/Routes/routes/health.js +28 -28
- package/vendor/Server/Routes/routes/index.js +57 -57
- package/vendor/Server/Routes/routes/knowledge.js +55 -55
- package/vendor/Server/Routes/routes/loopengine.js +58 -58
- package/vendor/Server/Routes/routes/orchestrator.js +61 -61
- package/vendor/Server/Routes/routes/registry.js +97 -97
- package/vendor/Server/Routes/routes/stats.js +23 -23
- package/vendor/Server/Routes/routes/stream.js +30 -30
- package/vendor/Server/Routes/server.js +203 -203
- package/vendor/Server/Routes/sse/SseHub.js +308 -308
- package/vendor/Server/Skills/acceptance-check/SKILL.md +191 -191
- package/vendor/Server/Skills/acceptance-check/references/PHASE1_ARTIFACT_COLLECTION.md +52 -52
- package/vendor/Server/Skills/acceptance-check/references/PHASE2_CRITERIA_EVALUATION.md +77 -77
- package/vendor/Server/Skills/acceptance-check/references/PHASE2_EVIDENCE_VERIFICATION.md +70 -70
- package/vendor/Server/Skills/arkts-code-check/SKILL.md +320 -320
- package/vendor/Server/Skills/arkts-code-check/references/CODE_CHECK_GUIDE.md +210 -210
- package/vendor/Server/Skills/arkts-code-check/references/FILE_TYPE_GUIDE.md +28 -28
- package/vendor/Server/Skills/arkts-code-check/references/PHASE1_INFO_COLLECTION.md +233 -233
- package/vendor/Server/Skills/arkts-code-check/references/REPORT_TEMPLATE.md +219 -219
- package/vendor/Server/Skills/arkts-library-compile-validate/SKILL.md +328 -328
- package/vendor/Server/Skills/arkts-library-compile-validate/scripts/build.ps1 +93 -93
- package/vendor/Server/Skills/arkts-library-compile-validate/scripts/code-linter.cjs +432 -432
- package/vendor/Server/Skills/arkts-library-compile-validate/scripts/migrate.cjs +851 -851
- package/vendor/Server/Skills/arkts-library-compile-validate/scripts/ohpm-switch.cjs +788 -788
- package/vendor/Server/Skills/arkts-library-demo-code/SKILL.md +291 -291
- package/vendor/Server/Skills/arkts-library-demo-code/references/API_SIGNATURE_CHECKS.md +68 -68
- package/vendor/Server/Skills/arkts-library-demo-code/references/BUILD_VALIDATION.md +184 -184
- package/vendor/Server/Skills/arkts-library-demo-code/references/CODE_STANDARDS.md +337 -337
- package/vendor/Server/Skills/arkts-library-demo-code/references/EXAMPLES.md +400 -400
- package/vendor/Server/Skills/arkts-library-demo-code/references/SYSTEM_API_LOOKUP.md +98 -98
- package/vendor/Server/Skills/arkts-library-demo-code/references/TEMPLATE.md +544 -544
- package/vendor/Server/Skills/arkts-library-demo-code/scripts/build.ps1 +93 -93
- package/vendor/Server/Skills/arkts-library-demo-code/scripts/code-linter.cjs +432 -432
- package/vendor/Server/Skills/arkts-library-demo-code/scripts/migrate.cjs +851 -851
- package/vendor/Server/Skills/arkts-library-demo-code/scripts/ohpm-switch.cjs +788 -788
- package/vendor/Server/Skills/arkts-library-demo-coverage/SKILL.md +174 -174
- package/vendor/Server/Skills/arkts-library-demo-scenario/SKILL.md +321 -321
- package/vendor/Server/Skills/arkts-library-demo-scenario/references/EXAMPLES.md +100 -100
- package/vendor/Server/Skills/arkts-library-demo-scenario/references/TEMPLATE.md +185 -185
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/SKILL.md +233 -233
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/assets/REPORT_TEMPLATE.md +102 -102
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/CHECK_DIMENSIONS.md +89 -89
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/COMPLIANCE_CHECKLIST.md +62 -62
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/KB_QUERY_GUIDE.md +107 -107
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/MCP_TOOL_DISCOVERY.md +124 -124
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/REPORT_TEMPLATE.md +90 -90
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/references/SCORING_FORMULA.md +57 -57
- package/vendor/Server/Skills/arkts-library-documentation-quality-check/scripts/validate-skill.cjs +259 -259
- package/vendor/Server/Skills/arkts-library-interface-spec/SKILL.md +97 -97
- package/vendor/Server/Skills/arkts-library-memory-leak-check/SKILL.md +391 -391
- package/vendor/Server/Skills/arkts-library-source-clone/SKILL.md +113 -113
- package/vendor/Server/Skills/arkts-library-stability-check/SKILL.md +312 -312
- package/vendor/Server/Skills/arkts-library-stability-check/assets/REPORT_TEMPLATE.md +154 -154
- package/vendor/Server/Skills/arkts-library-stability-check/references/CHECKLIST.md +165 -165
- package/vendor/Server/Skills/arkts-library-stability-check/references/CODE_EXAMPLES.md +308 -308
- package/vendor/Server/Skills/arkts-library-stability-check/references/SCORING_RULES.md +90 -90
- package/vendor/Server/Skills/arkts-library-stability-check/scripts/validate-skill.cjs +282 -282
- package/vendor/Server/Skills/arkts-library-test-coverage-check/SKILL.md +360 -360
- package/vendor/Server/Skills/arkts-library-test-coverage-check/assets/REPORT_TEMPLATE.md +145 -145
- package/vendor/Server/Skills/arkts-library-test-coverage-check/references/CHECKLIST.md +252 -252
- package/vendor/Server/Skills/arkts-library-test-coverage-check/references/MCP_TOOL_USAGE.md +114 -114
- package/vendor/Server/Skills/arkts-library-test-coverage-check/scripts/validate-skill.cjs +262 -262
- package/vendor/Server/Skills/arkts-library-xts-code/SKILL.md +455 -455
- package/vendor/Server/Skills/arkts-library-xts-code/assets/report-template.md +60 -60
- package/vendor/Server/Skills/arkts-library-xts-code/references/ACCESS_MODIFIER_PRECHECK.md +76 -76
- package/vendor/Server/Skills/arkts-library-xts-code/references/BUILD_VERIFICATION.md +200 -200
- package/vendor/Server/Skills/arkts-library-xts-code/references/CODE_STANDARDS.md +518 -518
- package/vendor/Server/Skills/arkts-library-xts-code/references/SUBAGENT_PROMPT_TEMPLATE.md +276 -276
- package/vendor/Server/Skills/arkts-library-xts-code/references/SYSTEM_API_LOOKUP.md +92 -92
- package/vendor/Server/Skills/arkts-library-xts-code/references/XTS_TEMPLATE.md +767 -767
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/build.ps1 +93 -93
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/code-linter.cjs +432 -432
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/migrate.cjs +851 -851
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/ohpm-switch.cjs +788 -788
- package/vendor/Server/Skills/arkts-library-xts-code/scripts/precheck-access-modifiers.cjs +221 -221
- package/vendor/Server/Skills/arkts-library-xts-code-fix/SKILL.md +228 -228
- package/vendor/Server/Skills/arkts-library-xts-coverage/SKILL.md +97 -97
- package/vendor/Server/Skills/arkts-library-xts-doc/SKILL.md +194 -194
- package/vendor/Server/Skills/arkts-library-xts-doc/references/EXAMPLES.md +575 -575
- package/vendor/Server/Skills/arkts-library-xts-doc/references/TEMPLATE.md +574 -574
- package/vendor/Server/Skills/arkts-library-xts-doc/references/TESTABILITY_GUIDE.md +182 -182
- package/vendor/Server/Skills/arkts-library-xts-execution/SKILL.md +490 -490
- package/vendor/Server/Skills/arkts-library-xts-execution/references/error-fixing-examples.md +217 -217
- package/vendor/Server/Skills/arkts-library-xts-execution/scripts/build.ps1 +93 -93
- package/vendor/Server/Skills/arkts-library-xts-execution/scripts/code-linter.cjs +432 -432
- package/vendor/Server/Skills/arkts-library-xts-execution/scripts/migrate.cjs +851 -851
- package/vendor/Server/Skills/arkts-library-xts-execution/scripts/ohpm-switch.cjs +788 -788
- package/vendor/Server/Skills/flutter-code-check/SKILL.md +299 -299
- package/vendor/Server/Skills/flutter-code-check/assets/OUTPUT_TEMPLATE.md +311 -311
- package/vendor/Server/Skills/flutter-code-check/references/CHECKLIST.md +190 -190
- package/vendor/Server/Skills/flutter-code-check/references/PLATFORMS.md +133 -133
- package/vendor/Server/Skills/flutter-code-check/scripts/validate-skill.cjs +259 -259
- package/vendor/Server/Skills/flutter-interface/README.md +75 -75
- package/vendor/Server/Skills/flutter-interface/SKILL.md +291 -291
- package/vendor/Server/Skills/flutter-interface/references/EXAMPLES.md +336 -336
- package/vendor/Server/Skills/flutter-interface/references/GIT_CLONE_GUIDE.md +190 -190
- package/vendor/Server/Skills/flutter-interface/references/SCRIPT_REFERENCE.md +258 -258
- package/vendor/Server/Skills/flutter-interface/references/TEMPLATE.md +254 -254
- package/vendor/Server/Skills/flutter-library-consistency-check/SKILL.md +517 -517
- package/vendor/Server/Skills/flutter-library-consistency-check/references/CHECKLIST.md +381 -381
- package/vendor/Server/Skills/flutter-library-consistency-check/references/FUNCTION_COMPARISON_GUIDE.md +341 -341
- package/vendor/Server/Skills/flutter-library-consistency-check/references/PLATFORM_LIMITATION_GUIDE.md +71 -71
- package/vendor/Server/Skills/flutter-library-documentation-quality-check/SKILL.md +518 -518
- package/vendor/Server/Skills/flutter-library-documentation-quality-check/references/CHECKLIST.md +406 -406
- package/vendor/Server/Skills/flutter-library-memory-leak-check/SKILL.md +652 -652
- package/vendor/Server/Skills/flutter-library-memory-leak-check/references/CHECKLIST.md +396 -396
- package/vendor/Server/Skills/flutter-library-stability-check/SKILL.md +744 -744
- package/vendor/Server/Skills/flutter-library-stability-check/references/CHECKLIST.md +720 -720
- package/vendor/Server/Skills/flutter-library-test-coverage-check/SKILL.md +414 -414
- package/vendor/Server/Skills/flutter-library-test-coverage-check/assets/REPORT_TEMPLATE.md +150 -150
- package/vendor/Server/Skills/flutter-library-test-coverage-check/references/CHECKLIST.md +304 -304
- package/vendor/Server/Skills/flutter-library-test-coverage-check/references/SCORING_RULES.md +265 -265
- package/vendor/Server/Skills/flutter-library-test-coverage-check/references/SCRIPT_USAGE.md +286 -286
- package/vendor/Server/Skills/knowledge-import/SKILL.md +383 -383
- package/vendor/Server/Skills/knowledge-import/references/MCP_TOOL_USAGE.md +165 -165
- package/vendor/Server/Skills/knowledge-import/references/SKILL_LOCATOR_GUIDE.md +91 -91
- package/vendor/Server/Skills/knowledge-import/references/SKILL_OPTIMIZATION_GUIDE.md +127 -127
- package/vendor/Server/Skills/ohos-lib-pr-push/SKILL.md +453 -301
- package/vendor/Server/Skills/ohos-lib-pr-push/assets/PR_CHECKLIST.md +151 -0
- package/vendor/Server/Skills/ohos-lib-pr-push/assets/PR_ISSUE_TEMPLATE.md +257 -105
- package/vendor/Server/Skills/ohos-lib-pr-push/references/GITCODE_API.md +191 -127
- package/vendor/Server/Skills/ohos-lib-pr-push/scripts/gitcode-api.cjs +317 -208
- package/vendor/Server/Skills/rn-code-check/SKILL.md +320 -320
- package/vendor/Server/Skills/rn-code-check/references/API-GUIDE.md +234 -234
- package/vendor/Server/Skills/rn-code-check/references/CHECKLIST.md +188 -188
- package/vendor/Server/Skills/rn-code-check/references/REPORT-TEMPLATE.md +246 -246
- package/vendor/Server/Skills/rn-lib-add-example/SKILL.md +198 -198
- package/vendor/Server/Skills/rn-lib-add-example/references/APP_RENAME_GUIDE.md +40 -40
- package/vendor/Server/Skills/rn-lib-add-example/references/SHELL_ADAPTATION_CHECKLIST.md +78 -78
- package/vendor/Server/Skills/rn-lib-add-example/references/TEMPLATE_REPO_GUIDE.md +70 -70
- package/vendor/Server/Skills/rn-lib-add-example/references/VERIFICATION_GUIDE.md +47 -47
- package/vendor/Server/Skills/rn-lib-add-example/scripts/create-example.cjs +252 -252
- package/vendor/Server/Skills/rn-lib-update-doc/SKILL.md +176 -176
- package/vendor/Server/Skills/rn-lib-update-doc/config.json +5 -5
- package/vendor/Server/Skills/rn-lib-update-doc/references/changelog-template.md +35 -35
- package/vendor/Server/Skills/rn-lib-update-doc/references/format-diff.md +137 -137
- package/vendor/Server/Skills/rn-lib-update-doc/references/link-registry.json +33 -33
- package/vendor/Server/Skills/rn-lib-update-doc/references/model-0.4.2-overview.md +40 -40
- package/vendor/Server/Skills/rn-lib-update-doc/references/model-0.4.2.md +429 -429
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/detect-readme-format.cjs +105 -105
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/find-usage-doc.cjs +90 -90
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/link-verify.cjs +213 -213
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/normalize-changelog.cjs +73 -73
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/normalize-package-meta.cjs +258 -258
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/normalize-readme-links.cjs +341 -341
- package/vendor/Server/Skills/rn-lib-update-doc/scripts/resolve-usage-docs.cjs +67 -67
- package/vendor/Server/Skills/rn-library-consistency-check/SKILL.md +299 -299
- package/vendor/Server/Skills/rn-library-consistency-check/assets/REPORT_TEMPLATE.md +293 -293
- package/vendor/Server/Skills/rn-library-consistency-check/references/ARKTS_COMPONENT_CHECK_GUIDE.md +857 -857
- package/vendor/Server/Skills/rn-library-consistency-check/references/ARKTS_TURBOMODULE_CHECK_GUIDE.md +856 -856
- package/vendor/Server/Skills/rn-library-consistency-check/references/CHECKLIST.md +157 -157
- package/vendor/Server/Skills/rn-library-consistency-check/references/CPP_COMPONENT_CHECK_GUIDE.md +801 -801
- package/vendor/Server/Skills/rn-library-consistency-check/references/CPP_TURBOMODULE_CHECK_GUIDE.md +683 -683
- package/vendor/Server/Skills/rn-library-consistency-check/references/FUNCTION_COMPARISON_GUIDE.md +233 -233
- package/vendor/Server/Skills/rn-library-consistency-check/references/NATIVE_COMPONENT_IDENTIFICATION.md +1373 -1373
- package/vendor/Server/Skills/rn-library-consistency-check/references/SCORING_STANDARD.md +220 -220
- package/vendor/Server/Skills/rn-library-consistency-check/scripts/validate-skill.py +245 -245
- package/vendor/Server/Skills/rn-library-documentation-quality-check/SKILL.md +263 -263
- package/vendor/Server/Skills/rn-library-documentation-quality-check/assets/MODEL.md +414 -414
- package/vendor/Server/Skills/rn-library-documentation-quality-check/assets/MODEL_en.md +413 -413
- package/vendor/Server/Skills/rn-library-documentation-quality-check/assets/REPORT_TEMPLATE.md +311 -311
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/CHECK_CHECKLIST.md +355 -355
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/CROSS_VALIDATION_GUIDE.md +115 -115
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/DOC_COLLECTION_GUIDE.md +139 -139
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/EXAMPLES.md +586 -586
- package/vendor/Server/Skills/rn-library-documentation-quality-check/references/GOTCHAS.md +57 -57
- package/vendor/Server/Skills/rn-library-documentation-quality-check/scripts/validate-skill.py +259 -259
- package/vendor/Server/Skills/rn-library-interface-analyzer/SKILL.md +301 -301
- package/vendor/Server/Skills/rn-library-interface-analyzer/assets/REPORT_TEMPLATE.md +148 -148
- package/vendor/Server/Skills/rn-library-interface-analyzer/references/DOC_ANNOTATION_GUIDE.md +118 -118
- package/vendor/Server/Skills/rn-library-interface-analyzer/references/SCRIPT_USAGE_GUIDE.md +168 -168
- package/vendor/Server/Skills/rn-library-interface-analyzer/references/URL_PARSING_RULES.md +176 -176
- package/vendor/Server/Skills/rn-library-issue-generalizer/SKILL.md +274 -274
- package/vendor/Server/Skills/rn-library-issue-generalizer/assets/case-template.md +45 -45
- package/vendor/Server/Skills/rn-library-issue-generalizer/assets/rule-template.md +25 -25
- package/vendor/Server/Skills/rn-library-issue-generalizer/references/PR_FETCH_GUIDE.md +61 -61
- package/vendor/Server/Skills/rn-library-issue-generalizer/references/RULE_TEMPLATE_GUIDE.md +165 -165
- package/vendor/Server/Skills/rn-library-issue-generalizer/scripts/fetch-pr-info.py +239 -239
- package/vendor/Server/Skills/rn-library-known-issue-check/SKILL.md +263 -263
- package/vendor/Server/Skills/rn-library-known-issue-check/assets/REPORT_TEMPLATE.md +96 -96
- package/vendor/Server/Skills/rn-library-known-issue-check/references/COMPLIANCE_CHECKLIST.md +57 -57
- package/vendor/Server/Skills/rn-library-known-issue-check/references/INSPECTION_GUIDE.md +99 -99
- package/vendor/Server/Skills/rn-library-known-issue-check/references/PRESCREEN_GUIDE.md +64 -64
- package/vendor/Server/Skills/rn-library-known-issue-check/references/SOURCE_PREP_GUIDE.md +74 -74
- package/vendor/Server/Skills/rn-library-known-issue-check/scripts/validate-known-issue-report.py +164 -164
- package/vendor/Server/Skills/rn-library-memory-leak-check/SKILL.md +356 -339
- package/vendor/Server/Skills/rn-library-memory-leak-check/assets/REPORT_TEMPLATE.md +85 -83
- package/vendor/Server/Skills/rn-library-memory-leak-check/references/CHECKLIST.md +905 -859
- package/vendor/Server/Skills/rn-library-memory-leak-check/references/HARMONY_CODE_PATTERNS.md +124 -122
- package/vendor/Server/Skills/rn-library-memory-leak-check/scripts/scan_harmony_code.py +287 -279
- package/vendor/Server/Skills/rn-library-stability-check/SKILL.md +273 -273
- package/vendor/Server/Skills/rn-library-stability-check/assets/REPORT_TEMPLATE.md +129 -129
- package/vendor/Server/Skills/rn-library-stability-check/references/CHECKLIST.md +581 -581
- package/vendor/Server/Skills/rn-library-stability-check/references/SCORING_RULES.md +138 -138
- package/vendor/Server/Skills/rn-library-stability-check/scripts/scan-harmony-code.py +168 -168
- package/vendor/Server/Skills/rn-library-test-coverage-check/SKILL.md +526 -506
- package/vendor/Server/Skills/rn-library-test-coverage-check/references/CHECKLIST.md +321 -280
- package/vendor/Server/Skills/rn-library-test-coverage-check/references/DEMO_LOCATION.md +221 -221
- package/vendor/Server/Skills/rn-library-test-coverage-check/references/REPORT_TEMPLATE.md +220 -209
- package/vendor/Server/Skills/rn-library-test-coverage-check/references/SCRIPT_USAGE.md +325 -325
- package/vendor/Server/Skills/rn-ohos-xts-generator/SKILL.md +279 -279
- package/vendor/Server/Skills/rn-ohos-xts-generator/assets/TEST_FILE_TEMPLATES.md +404 -404
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/BUILD_TROUBLESHOOTING.md +185 -185
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/BUILD_WORKFLOW.md +265 -265
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/COMMON_CONFIG.md +189 -189
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/CONFIG_GUIDE.md +203 -203
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/COVERAGE_ANALYZER.md +147 -147
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/DESIGN_DOC_GUIDE.md +148 -148
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/GENERATION_FLOW.md +165 -165
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/GENERATION_STRATEGY.md +195 -195
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/HARMONY_SCANNER.md +249 -249
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/JEST_FRAMEWORK.md +235 -235
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/PLATFORM_COMPAT.md +161 -161
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/RN_TEST_PATTERNS.md +413 -413
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/SOURCE_PARSER.md +235 -235
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/TEST_CONVENTIONS.md +245 -245
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/TROUBLESHOOTING.md +282 -282
- package/vendor/Server/Skills/rn-ohos-xts-generator/references/USAGE_GUIDE.md +251 -251
- package/vendor/Server/Skills/rnoh-cptf-api-test/SKILL.md +469 -469
- package/vendor/Server/Skills/rnoh-cptf-api-test/assets/CPTF_TEST_TEMPLATE.md +310 -310
- package/vendor/Server/Skills/rnoh-cptf-api-test/assets/DEMO_PAGE_TEMPLATE.md +303 -303
- package/vendor/Server/Skills/rnoh-cptf-api-test/references/CPTF_TEST_GENERATION_GUIDE.md +421 -421
- package/vendor/Server/Skills/rnoh-cptf-api-test/references/DEMO_GENERATION_GUIDE.md +358 -358
- package/vendor/Server/Skills/rnoh-cptf-api-test/references/QUALITY_CHECKLIST.md +114 -114
- package/vendor/Server/Skills/rnoh-cptf-api-test/references/SPEC_PARSING_GUIDE.md +274 -274
- package/vendor/Server/Skills/rnoh-cptf-api-test/scripts/validate-rnoh-cptf-api-test.sh +185 -185
- package/vendor/Server/Skills/rnoh-cptf-demo-test/SKILL.md +191 -191
- package/vendor/Server/Skills/rnoh-cptf-demo-test/assets/TEST_TEMPLATE.md +216 -216
- package/vendor/Server/Skills/rnoh-cptf-demo-test/references/CPTF_SETUP.md +107 -107
- package/vendor/Server/Skills/rnoh-cptf-demo-test/references/DEMO_ANALYSIS.md +120 -120
- package/vendor/Server/Skills/rnoh-cptf-demo-test/scripts/validate-rnoh-cptf-test.sh +108 -108
- package/vendor/Server/Skills/rnoh-cptf-test-run/SKILL.md +237 -237
- package/vendor/Server/Skills/rnoh-cptf-test-run/references/DEBUG_PLAYBOOK.md +261 -261
- package/vendor/Server/Skills/rnoh-cptf-test-run/scripts/validate-run-env.sh +112 -112
- package/vendor/Server/Skills/rnoh-lib-code-adapt/SKILL.md +497 -497
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/adapt-checklist.md +270 -270
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/api-migration-checklist.md +164 -164
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/common-compile-errors.md +556 -556
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/deveco-cli-tools.md +459 -459
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/edge-cases.md +65 -65
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/har-tgz-build.md +512 -512
- package/vendor/Server/Skills/rnoh-lib-code-adapt/references/version-compat-matrix.md +132 -132
- package/vendor/Server/Skills/rnoh-lib-code-adapt/scripts/auto-integrate.sh +424 -424
- package/vendor/Server/Skills/rnoh-lib-demo-coverage/SKILL.md +137 -137
- package/vendor/Server/Skills/rnoh-lib-demo-create/SKILL.md +306 -306
- package/vendor/Server/Skills/rnoh-lib-demo-create/assets/DEMO_PAGE_TEMPLATE.md +485 -485
- package/vendor/Server/Skills/rnoh-lib-demo-create/assets/INDEX_TEMPLATE.md +172 -172
- package/vendor/Server/Skills/rnoh-lib-demo-create/references/DEMO_CODE_RULES.md +422 -422
- package/vendor/Server/Skills/rnoh-lib-demo-create/references/QUALITY_CHECKLIST.md +95 -95
- package/vendor/Server/Skills/rnoh-lib-demo-create/references/SOURCE_EXPLORATION.md +169 -169
- package/vendor/Server/Skills/rnoh-lib-demo-doc/SKILL.md +554 -554
- package/vendor/Server/Skills/rnoh-lib-demo-doc/assets/DEMO_DOC_TEMPLATE.md +106 -106
- package/vendor/Server/Skills/rnoh-lib-demo-doc/references/COVERAGE_INCREMENTAL.md +216 -216
- package/vendor/Server/Skills/rnoh-lib-demo-doc/references/DEMO_DESIGN_RULES.md +413 -413
- package/vendor/Server/Skills/rnoh-lib-demo-doc/references/OUTPUT_FORMAT.md +269 -269
- package/vendor/Server/Skills/rnoh-lib-demo-doc/references/QUALITY_CHECKLIST.md +98 -98
- package/vendor/Server/Skills/rnoh-lib-func-test/SKILL.md +337 -337
- package/vendor/Server/Skills/rnoh-lib-rnt-search/SKILL.md +722 -722
- package/vendor/Server/Skills/rnoh-lib-rnt-search/assets/PORT_REPORT_TEMPLATE.md +219 -219
- package/vendor/Server/Skills/rnoh-lib-rnt-search/references/DEMO_PORTING_GUIDE.md +345 -345
- package/vendor/Server/Skills/rnoh-lib-rnt-search/references/PORT_VERIFICATION.md +269 -269
- package/vendor/Server/Skills/rnoh-lib-rnt-search/references/RNT_PROJECT_STRUCTURE.md +173 -173
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/analyze-demo-deps.cjs +267 -267
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/detect-rnoh-version.cjs +174 -174
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/find-rnt-demo.sh +111 -111
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/port-demo.sh +186 -186
- package/vendor/Server/Skills/rnoh-lib-rnt-search/scripts/read-lib-meta.cjs +150 -150
- package/vendor/Server/Skills/rnoh-lib-test-align/SKILL.md +296 -296
- package/vendor/Server/Skills/rnoh-lib-test-align/references/jest-troubleshooting.md +371 -371
- package/vendor/Server/Skills/rnoh-lib-test-align/references/port-test-demo-guide.md +212 -212
- package/vendor/Server/Skills/rnoh-lib-test-align/references/runtime-troubleshooting.md +345 -345
- package/vendor/Server/Skills/rnoh-lib-test-align/references/unit-test-template.md +223 -223
- package/vendor/Server/Skills/rnoh-lib-test-align/scripts/port-test-demo.sh +1053 -1053
- package/vendor/Server/Skills/rnoh-lib-version-diff/SKILL.md +295 -255
- package/vendor/Server/Skills/rnoh-lib-version-diff/references/OHOS_ADAPTATION.md +82 -77
- package/vendor/Server/Skills/rnoh-lib-version-diff/references/OHOS_API_LOOKUP.md +224 -224
- package/vendor/Server/Skills/rnoh-lib-version-diff/references/script-reference.md +175 -174
- package/vendor/Server/Skills/rnoh-lib-version-diff/scripts/detect-upstream-version.js +967 -967
- package/vendor/Server/Skills/rnoh-lib-version-diff/scripts/generate-diff.js +1798 -1798
- package/vendor/Server/Skills/rnoh-lib-version-diff/scripts/package.json +5 -5
- package/vendor/Server/Skills/rnoh-lib-version-diff/templates/report-template.md +180 -137
- package/vendor/Server/Skills/rnoh-lib-xts-coverage/SKILL.md +145 -145
- package/vendor/Server/Skills/skill-generator/SKILL.md +365 -365
- package/vendor/Server/Skills/skill-generator/assets/SKILL_TEMPLATE.md +183 -183
- package/vendor/Server/Skills/skill-generator/references/COMPLIANCE_CHECKLIST.md +82 -82
- package/vendor/Server/Skills/skill-generator/references/KB_QUERY_GUIDE.md +110 -110
- package/vendor/Server/Skills/skill-generator/references/MCP_TOOL_DISCOVERY.md +122 -122
- package/vendor/Server/Skills/skill-generator/references/SKILL_SPEC.md +121 -121
- package/vendor/Server/Skills/skill-generator/scripts/validate-skill.cjs +259 -259
- package/vendor/Server/Skills/task-analysis/SKILL.md +234 -234
- package/vendor/Server/Skills/task-analysis/assets/OUTPUT_EXAMPLES.md +160 -160
- package/vendor/Server/Skills/task-analysis/references/ACCEPTANCE_CRITERIA_GUIDE.md +190 -190
- package/vendor/Server/Skills/task-analysis/references/ANALYSIS_SCHEMA.md +224 -224
- package/vendor/Server/Skills/task-analysis/references/INTEGRATION_CONTEXT.md +162 -162
- package/vendor/Server/Skills/task-analysis/references/LESSONS_LEARNED.md +55 -55
- package/vendor/Server/Skills/task-analysis/references/REPLAN_CONTEXT_GUIDE.md +126 -126
- package/vendor/Server/Skills/task-analysis/scripts/validate-analysis-output.sh +256 -256
- package/vendor/Server/Skills/task-decomposition/SKILL.md +528 -528
- package/vendor/Server/Skills/task-decomposition/assets/OUTPUT_EXAMPLES.md +451 -451
- package/vendor/Server/Skills/task-decomposition/references/ACCEPTANCE_CRITERIA_GUIDE.md +179 -179
- package/vendor/Server/Skills/task-decomposition/references/DEPENDENCY_GRAPH_GUIDE.md +152 -152
- package/vendor/Server/Skills/task-decomposition/references/INTEGRATION_CONTEXT.md +175 -175
- package/vendor/Server/Skills/task-decomposition/references/REPLAN_CONTEXT_GUIDE.md +195 -195
- package/vendor/Server/Skills/task-decomposition/references/TASK_DECOMPOSITION_TEMPLATES.md +226 -226
- package/vendor/Server/Skills/task-decomposition/scripts/list-available-skills.cjs +263 -263
- package/vendor/Server/Skills/task-decomposition/scripts/skill-blacklist.json +29 -29
- package/vendor/Server/Skills/task-decomposition/scripts/validate-decomposition-output.cjs +376 -376
- package/vendor/Server/Skills/task-decomposition/scripts/validate-param-consistency.cjs +259 -259
- package/vendor/Server/Skills/task-decomposition/scripts/validate-specified-skills.cjs +216 -216
- package/vendor/Server/Skills/task-decomposition/scripts/validate-step-graph.cjs +424 -424
- package/vendor/Server/Skills/tpc-cpp-check/SKILL.md +427 -427
- package/vendor/Server/Skills/tpc-cpp-check/references/CHECKLIST.md +214 -214
- package/vendor/Server/Skills/tpc-cpp-check/references/HPKBUILD_GUIDE.md +235 -235
- package/vendor/Server/Skills/tpc-cpp-check/references/REPORT_TEMPLATE.md +250 -250
- package/vendor/Server/TestCheck/TestCheck.js +775 -775
- package/vendor/Server/TestCheck/index.js +11 -11
- package/vendor/Server/library/McpToolGuide.js +280 -280
- package/vendor/Server/library/StatsService.js +126 -126
- package/vendor/Server/library/cstTime.js +16 -16
- package/vendor/VERSION +3 -3
- package/workflows/pr-check.mjs +105 -105
- package/workflows/pr-push.mjs +192 -192
- package/vendor/Server/Agent/SkillSelector/types.js +0 -63
|
@@ -1,519 +1,519 @@
|
|
|
1
|
-
# XTS 测试代码生成规范速查
|
|
2
|
-
|
|
3
|
-
本文档为 `arkts-library-xts-code` 技能提供编码规范速查,涵盖文件命名、ArkTS 禁止项、日志规范、注释规范、错误处理、hypium 测试框架使用等。
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 一、文件命名规范
|
|
8
|
-
|
|
9
|
-
### 测试文件命名
|
|
10
|
-
|
|
11
|
-
格式:`{LibraryName}XtsTest.test.ets`
|
|
12
|
-
|
|
13
|
-
所有测试文件统一放在 `entry/src/ohosTest/ets/test/` 目录。
|
|
14
|
-
|
|
15
|
-
> ⚠️ **扩展名必须为 `.test.ets`**,不能用 `.ts` 或 `.ets`。OpenHarmony XTS 测试框架要求测试文件使用 `.test.ets` 扩展名。
|
|
16
|
-
|
|
17
|
-
| 规则 | 说明 | 示例 |
|
|
18
|
-
|------|------|------|
|
|
19
|
-
| LibraryName | 库名(PascalCase) | `Lodash`、`Axios`、`BlurKit` |
|
|
20
|
-
| 完整文件名 | `{LibraryName}XtsTest.test.ets` | `LodashXtsTest.test.ets` |
|
|
21
|
-
|
|
22
|
-
**示例映射**:
|
|
23
|
-
|
|
24
|
-
| 库名 | 测试文件路径 |
|
|
25
|
-
|------|---------------------------------------|
|
|
26
|
-
| lodash | `entry/src/ohosTest/ets/test/LodashXtsTest.test.ets` |
|
|
27
|
-
| axios | `entry/src/ohosTest/ets/test/AxiosXtsTest.test.ets` |
|
|
28
|
-
| blur-kit | `entry/src/ohosTest/ets/test/BlurKitXtsTest.test.ets` |
|
|
29
|
-
|
|
30
|
-
### 测试函数命名
|
|
31
|
-
|
|
32
|
-
格式:`{function_snake_case}_{SEQ}`
|
|
33
|
-
|
|
34
|
-
| 规则 | 说明 | 示例 |
|
|
35
|
-
|------|------|------|
|
|
36
|
-
| function_snake_case | 英文功能描述(小写+下划线,≤20字符) | `chunk_basic`、`get_set_path` |
|
|
37
|
-
| SEQ | 三位数字序号 | `001`、`007`、`012` |
|
|
38
|
-
| 完整函数名 | `{描述}_{序号}` | `chunk_basic_001` |
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## 二、ArkTS 编译禁止项(必查)
|
|
43
|
-
|
|
44
|
-
生成的所有代码必须规避以下 ArkTS 严格模式编译报错:
|
|
45
|
-
|
|
46
|
-
| 禁止项 | 错误标识 | 正确替代 |
|
|
47
|
-
|-------|---------|---------|
|
|
48
|
-
| `any` 类型 | `arkts-no-any` | 具体类型或泛型 `T` |
|
|
49
|
-
| `Object`/`ESObject` | `arkts-no-esobj` | 定义 `interface` 或具体类型 |
|
|
50
|
-
| 动态属性访问 `obj['key']` | `arkts-no-dynamic-property` | `obj.key` 类型安全访问 |
|
|
51
|
-
| 内联匿名对象类型 | `arkts-no-obj-literals-as-types` | 定义命名 `interface` |
|
|
52
|
-
| `prototype` 扩展 | `arkts-no-prototype-assignment` | 类继承或组合 |
|
|
53
|
-
| `delete` 操作符 | `arkts-no-delete` | 设为 `undefined` 或重构对象 |
|
|
54
|
-
| `arguments` 对象 | `arkts-no-arguments` | 展开参数 `...args: T[]` |
|
|
55
|
-
| `unknown` 关键字及双重 `as unknown as T` | `arkts-no-any-unknown` | `unknown` 关键字在 ArkTS 严格模式下被完全禁止,不能用于类型转换中间层。替代方案:① 传递空但合法的对象(如 `new BleDevice('', '')` 代替 `null as BleDevice`);② 对需要 null 参数的异常测试,改测空字符串/零值参数的行为;③ 构造最小必填字段对象字面量并 `as Type`(如 `as ble.ScanResult`);④ 不需要实际功能的参数用 `{} as Type`(如 `{} as common.Context`) |
|
|
56
|
-
| `for...in` | `arkts-no-for-in` | `Object.keys().forEach()` |
|
|
57
|
-
| `eval()` | `arkts-no-eval` | 禁止使用 |
|
|
58
|
-
| `catch(e)` 中直接 `throw e` | `arkts-limited-throw` | **禁止重新抛出任意类型异常**。改用 try-catch + 布尔标记模式,catch 中仅设标记,不 throw |
|
|
59
|
-
| `null as SomeType` 强转 | 类型不兼容错误 | `{} as common.Context`(用于不需要实际功能的参数),或 null 检查 + `throw new Error()` |
|
|
60
|
-
| `undefined as SomeType` | 类型不兼容错误 | null 检查 + 安全默认值或 `throw new Error()` |
|
|
61
|
-
| catch 子句类型注解 | `arkts-no-types-in-catch` | `catch (e)` 不带类型注解,e 默认为 Object 类型(非 any),不违反 `arkts-no-any-unknown` |
|
|
62
|
-
| `as Object` 后访问属性 | `Property 'X' does not exist on type 'Object'` | 保留原始类型不做 `as Object` 转型;仅在不需要属性访问时用 `as Object`(如验证非 null) |
|
|
63
|
-
| 枚举成员直接比较 | `types 'A' and 'B' have no overlap` | `(Enum.A as number) !== (Enum.B as number)` 转型后比较 |
|
|
64
|
-
| 无类型对象字面量 | `arkts-no-untyped-obj-literals` | `{}` 或 `{ key: value }` 必须对应命名 interface/class;定义 `class MockTarget { prop: string = ''; }` 代替 `let x: Object = {}` |
|
|
65
|
-
| 向 `@ts-nocheck` 库 API 传 `null` 实参 | `Argument of type 'null' is not assignable to parameter of type 'string'` | 库源码的 `@ts-nocheck` **不豁免测试文件**,调用处仍受严格空值检查约束。库内部用 `if (x)` 判空时,空串 `''`/空数组 `[]` 与 null 语义等价 → 改传等价 falsy 值覆盖同一守卫路径(如 `new ID3v1Tag('')`),并在注释中说明等价性依据 |
|
|
66
|
-
| 断言裸函数调用 | `Cannot find name 'assertTrue'`(批量) | hypium 断言只存在于 `expect()` 返回对象上,**不存在独立全局函数**。`assertTrue(x)`/`assertEqual(a, b)` 裸调用是编译错误,必须写 `expect(x).assertTrue()` 链式调用 |
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## 三、日志规范
|
|
71
|
-
|
|
72
|
-
### 3.1 DOMAIN 与 TAG 分配
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
// ✅ 正确:每个测试文件有独立 TAG,DOMAIN 在工程中统一范围
|
|
76
|
-
const DOMAIN: number = 0xD001; // 单个工程统一使用一个域值
|
|
77
|
-
const TAG: string = 'Lodash_XtsTest'; // {库名}_XtsTest
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
**TAG 命名规则**:`{LibraryName}_XtsTest`,不超过 32 字符,只含字母数字下划线。
|
|
81
|
-
|
|
82
|
-
### 3.2 日志级别选择
|
|
83
|
-
|
|
84
|
-
| 级别 | 函数 | 使用场景 |
|
|
85
|
-
|------|------|---------|
|
|
86
|
-
| DEBUG | `hilog.debug(...)` | 测试执行结果、中间状态 |
|
|
87
|
-
| INFO | `hilog.info(...)` | 测试开始/结束、套件生命周期 |
|
|
88
|
-
| ERROR | `hilog.error(...)` | 测试失败、捕获到异常 |
|
|
89
|
-
|
|
90
|
-
### 3.3 格式化参数
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
// ✅ 公开数据(测试结果、参数)用 %{public}s
|
|
94
|
-
hilog.debug(DOMAIN, TAG, 'Result: %{public}s', JSON.stringify(result));
|
|
95
|
-
|
|
96
|
-
// ✅ 敏感数据用 %{private}s(日志中显示为 <private>)
|
|
97
|
-
hilog.debug(DOMAIN, TAG, 'Token: %{private}s', token);
|
|
98
|
-
|
|
99
|
-
// ❌ 禁止将敏感信息用 %{public}s 输出
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### 3.4 必须添加日志的位置
|
|
103
|
-
|
|
104
|
-
| 位置 | 日志级别 | 示例 |
|
|
105
|
-
|------|---------|------|
|
|
106
|
-
| 测试函数开始 | INFO | `hilog.info(..., 'Test XXX started')` |
|
|
107
|
-
| 测试执行结果 | DEBUG | `hilog.debug(..., 'Result: %{public}s', ...)` |
|
|
108
|
-
| 测试成功完成 | INFO | `hilog.info(..., 'Test XXX passed')` |
|
|
109
|
-
| 测试失败 | ERROR | `hilog.error(..., 'Test XXX failed: %{public}s', msg)` |
|
|
110
|
-
| beforeAll/afterAll | INFO | `hilog.info(..., 'Suite started/finished')` |
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
## 四、注释规范
|
|
115
|
-
|
|
116
|
-
### 4.1 文件头部注释
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
/**
|
|
120
|
-
* {LibraryName} XTS 测试用例
|
|
121
|
-
*
|
|
122
|
-
* 基于 XTS 用例描述文档生成,验证 {LibraryName} 的核心功能。
|
|
123
|
-
* 文档来源:ohos_{LibraryName}xts用例描述.md
|
|
124
|
-
*
|
|
125
|
-
* 用例总数:{N}
|
|
126
|
-
* 可测试接口数:{M}
|
|
127
|
-
*
|
|
128
|
-
* @author lalhan
|
|
129
|
-
*/
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### 4.2 测试函数注释
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
/**
|
|
136
|
-
* 用例 {SEQ}: {用例名称}
|
|
137
|
-
*
|
|
138
|
-
* 用例描述:{从用例描述文档提取的详细描述}
|
|
139
|
-
* 涉及接口:{接口签名列表}
|
|
140
|
-
* 预期结果:
|
|
141
|
-
* 1. {预期结果 1}
|
|
142
|
-
* 2. {预期结果 2}
|
|
143
|
-
*/
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### 4.3 测试步骤注释
|
|
147
|
-
|
|
148
|
-
使用区块注释分隔测试步骤:
|
|
149
|
-
|
|
150
|
-
```typescript
|
|
151
|
-
// ─── 步骤 1:{步骤功能} ───────────────────────────────────────────────────
|
|
152
|
-
const step1Result = interface1Call();
|
|
153
|
-
|
|
154
|
-
// ─── 步骤 2:{步骤功能} ───────────────────────────────────────────────────
|
|
155
|
-
const step2Result = interface2Call();
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### 4.4 注释风格对比
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
// ✅ 推荐:使用块注释说明测试步骤和区块分隔
|
|
162
|
-
/**
|
|
163
|
-
* ─── 步骤 1:设置属性 ───────────────────────────────────────────────────
|
|
164
|
-
* 验证 _.set 能正确设置嵌套属性
|
|
165
|
-
*/
|
|
166
|
-
const setResult = _.set(obj, 'a.b.c', 1);
|
|
167
|
-
|
|
168
|
-
// ❌ 避免:过多单行注释影响可读性
|
|
169
|
-
// 调用 set 方法
|
|
170
|
-
// 设置属性 a.b.c
|
|
171
|
-
// 值为 1
|
|
172
|
-
const setResult = _.set(obj, 'a.b.c', 1);
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
---
|
|
176
|
-
|
|
177
|
-
## 五、错误处理规范
|
|
178
|
-
|
|
179
|
-
### 5.1 必须包含错误处理的位置
|
|
180
|
-
|
|
181
|
-
| 位置 | 处理方式 |
|
|
182
|
-
|------|---------|
|
|
183
|
-
| 预期异常测试 | try-catch + 布尔标记模式,catch 中禁止 `throw e` |
|
|
184
|
-
| 空值输入测试 | 验证不崩溃 + 验证返回安全默认值 |
|
|
185
|
-
| 大数据量测试 | 记录执行时间 + 验证不超时不崩溃 |
|
|
186
|
-
| 正常测试 | 不需要 try-catch,让 expect 断言和框架自动处理失败 |
|
|
187
|
-
|
|
188
|
-
### 5.2 预期异常测试模板
|
|
189
|
-
|
|
190
|
-
```typescript
|
|
191
|
-
// ✅ 推荐:try-catch + 布尔标记模式
|
|
192
|
-
let caught: boolean = false;
|
|
193
|
-
try {
|
|
194
|
-
libraryFunc(null);
|
|
195
|
-
} catch (e) {
|
|
196
|
-
caught = true;
|
|
197
|
-
// 禁止 throw e(arkts-limited-throw)
|
|
198
|
-
}
|
|
199
|
-
expect(caught).assertTrue();
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### 5.3 null 值输入测试模板
|
|
203
|
-
|
|
204
|
-
```typescript
|
|
205
|
-
// 对于需要传入 null 但参数类型不允许 null-as-Type 强转的场景
|
|
206
|
-
// 使用 null 检查 + throw new Error() 模式
|
|
207
|
-
let caught: boolean = false;
|
|
208
|
-
try {
|
|
209
|
-
const emptyInput: SomeType | null = null;
|
|
210
|
-
if (emptyInput === null) {
|
|
211
|
-
throw new Error('Input cannot be null');
|
|
212
|
-
}
|
|
213
|
-
new SomeClass(emptyInput);
|
|
214
|
-
} catch (e) {
|
|
215
|
-
caught = true;
|
|
216
|
-
}
|
|
217
|
-
expect(caught).assertTrue();
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### 5.4 空对象作为 Mock Context
|
|
221
|
-
|
|
222
|
-
```typescript
|
|
223
|
-
// processRenderScript 等需要 Context 参数但不实际使用时
|
|
224
|
-
// ✅ 正确:空对象 as common.Context
|
|
225
|
-
const mockContext: common.Context = {} as common.Context;
|
|
226
|
-
manager.processRenderScript(mockContext, radius);
|
|
227
|
-
|
|
228
|
-
// ❌ 错误:null as common.Context(类型不兼容,ArkTS 编译报错)
|
|
229
|
-
// ❌ 错误:null as image.PixelMap(类型不兼容)
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
### 5.5 异常类型断言(instanceof)与深层路径导入
|
|
233
|
-
|
|
234
|
-
自定义异常类通常未从 `library/index.ets` 根入口导出,做 `instanceof` 类型断言前必须深层路径导入真实异常类(未导出的实现类同理):
|
|
235
|
-
|
|
236
|
-
```typescript
|
|
237
|
-
// ✅ 正确:深层路径导入真实异常类后做 instanceof 断言
|
|
238
|
-
import { NoSuchTagException } from '@ohos/{LibraryName}/src/main/ets/components/{lib}/NoSuchTagException';
|
|
239
|
-
|
|
240
|
-
let isTarget: boolean = false;
|
|
241
|
-
try {
|
|
242
|
-
someCall();
|
|
243
|
-
} catch (e) {
|
|
244
|
-
isTarget = e instanceof NoSuchTagException; // 必须真实 import,禁止用 e.message 字符串匹配替代
|
|
245
|
-
}
|
|
246
|
-
expect(isTarget).assertTrue();
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
> 深层导入路径以库源码实际目录为准。仅做异常"是否抛出"的布尔断言时无需导入异常类;需要断言"异常类型正确"时才用本模式。
|
|
250
|
-
|
|
251
|
-
---
|
|
252
|
-
|
|
253
|
-
## 六、hypium 测试框架使用指南
|
|
254
|
-
|
|
255
|
-
### 6.1 核心 API
|
|
256
|
-
|
|
257
|
-
| API | 用途 | 示例 |
|
|
258
|
-
|-----|------|------|
|
|
259
|
-
| `describe(name, fn)` | 定义测试套件 | `describe('LodashXtsTest', () => { ... })` |
|
|
260
|
-
| `it(name, fn)` | 定义单个测试 | `it('chunk_basic_001', () => { ... })` |
|
|
261
|
-
| `expect(value)` | 创建断言对象 | `expect(result).assertEqual(1)` |
|
|
262
|
-
| `beforeAll(fn)` | 套件开始前执行一次 | 全局初始化 |
|
|
263
|
-
| `afterAll(fn)` | 套件结束后执行一次 | 全局清理 |
|
|
264
|
-
| `beforeEach(fn)` | 每个测试前执行 | 测试数据准备 |
|
|
265
|
-
| `afterEach(fn)` | 每个测试后执行 | 测试数据清理 |
|
|
266
|
-
|
|
267
|
-
### 6.2 常用断言方法
|
|
268
|
-
|
|
269
|
-
> ⚠️ **重要**:`@ohos/hypium` 的 `expect()` 对象上**不存在** Jest 风格的 `toBe`/`toEqual`/`toBeTruthy`/`toBeFalsy`/`toThrow` 等方法。必须使用以下 hypium 专用断言方法:
|
|
270
|
-
|
|
271
|
-
| 断言方法 | 用途 | 示例 |
|
|
272
|
-
|---------|------|------|
|
|
273
|
-
| `assertEqual(value)` | 严格相等(===) | `expect(result).assertEqual(1)` |
|
|
274
|
-
| `assertContain(item)` | 包含判断(数组/字符串) | `expect(arr).assertContain(1)` |
|
|
275
|
-
| `assertLarger(value)` | 大于判断 | `expect(count).assertLarger(0)` |
|
|
276
|
-
| `assertNull()` | null 判断 | `expect(result).assertNull()` |
|
|
277
|
-
| `assertTrue()` | 布尔真判断 | `expect(x !== null).assertTrue()` |
|
|
278
|
-
| `assertFalse()` | 布尔假判断 | `expect(x === null).assertFalse()` |
|
|
279
|
-
|
|
280
|
-
### 6.3 Jest 风格方法替代方案
|
|
281
|
-
|
|
282
|
-
| Jest 风格(❌ 不存在) | hypium 替代(✅ 正确) | 说明 |
|
|
283
|
-
|----------------------|----------------------|------|
|
|
284
|
-
| `expect(x).toBe(y)` | `expect(x).assertEqual(y)` | 严格相等 |
|
|
285
|
-
| `expect(x).toEqual(y)` | `expect(x).assertEqual(y)` | 深度相等也用 assertEqual |
|
|
286
|
-
| `expect(x).toBeNull()` | `expect(x).assertNull()` | null 判断 |
|
|
287
|
-
| `expect(x).toBeTruthy()` | `expect(x !== null).assertTrue()` | 真值 → 布尔表达式 |
|
|
288
|
-
| `expect(x).toBeFalsy()` | `expect(x).assertFalse()` | 假值 |
|
|
289
|
-
| `expect(x).not.toBeNull()` | `expect(x !== null).assertTrue()` | 否定断言 → 布尔表达式 |
|
|
290
|
-
| `expect(fn).toThrow()` | try-catch + 布尔标记 | 见下方说明 |
|
|
291
|
-
| `expect(x).toBeGreaterThan(n)` | `expect(x).assertLarger(n)` | 大于 |
|
|
292
|
-
| `expect(x).toBeLessThan(n)` | `expect(n).assertLarger(x)` | 小于(反转方向) |
|
|
293
|
-
| `expect(x).toContain(y)` | `expect(x).assertContain(y)` | 包含 |
|
|
294
|
-
| `expect(x).not.toBe(y)` | `expect(x === y).assertFalse()` | 否定断言 → 布尔表达式 |
|
|
295
|
-
|
|
296
|
-
**`toThrow()` 替代方案**:
|
|
297
|
-
|
|
298
|
-
```typescript
|
|
299
|
-
// ❌ 错误:hypium 不支持 toThrow()
|
|
300
|
-
expect(() => func(null)).toThrow();
|
|
301
|
-
|
|
302
|
-
// ✅ 正确:try-catch + 布尔标记模式
|
|
303
|
-
let caught: boolean = false;
|
|
304
|
-
try {
|
|
305
|
-
func(null);
|
|
306
|
-
} catch (e) {
|
|
307
|
-
caught = true;
|
|
308
|
-
}
|
|
309
|
-
expect(caught).assertTrue();
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
**`toBeLessThan()` 替代方案**:
|
|
313
|
-
|
|
314
|
-
```typescript
|
|
315
|
-
// ❌ 错误:hypium 不支持 toBeLessThan()
|
|
316
|
-
expect(duration).toBeLessThan(10000);
|
|
317
|
-
|
|
318
|
-
// ✅ 正确:反转比较方向
|
|
319
|
-
expect(10000).assertLarger(duration); // 即 10000 > duration
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
### 6.4 异步测试
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
// 异步测试使用 async/await
|
|
326
|
-
it('async_test', async () => {
|
|
327
|
-
const result = await asyncFunc();
|
|
328
|
-
expect(result).assertEqual(expected);
|
|
329
|
-
});
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
> ⚠️ **同步方法内部委托异步方法的陷阱**:若库的某个同步方法(如 `saveIntoFile`)内部实际委托给异步方法(如 `saveIntoFileAsync`),则测试时必须使用 `async` 函数 + `await`,否则异步操作尚未完成就执行了后续断言。
|
|
333
|
-
>
|
|
334
|
-
> ```typescript
|
|
335
|
-
> // ❌ 错误:saveIntoFile 内部是异步的,同步调用后立即检查文件
|
|
336
|
-
> it('save_test', 0, () => {
|
|
337
|
-
> manager.saveIntoFile(path); // 内部调用 saveIntoFileAsync(异步)
|
|
338
|
-
> expect(fs.accessSync(path)).assertTrue(); // 文件可能还没写入!
|
|
339
|
-
> });
|
|
340
|
-
>
|
|
341
|
-
> // ✅ 正确:使用 async + await
|
|
342
|
-
> it('save_test', 0, async () => {
|
|
343
|
-
> await manager.saveIntoFileAsync(path); // 等待异步写入完成
|
|
344
|
-
> expect(fs.accessSync(path)).assertTrue(); // 文件已写入
|
|
345
|
-
> });
|
|
346
|
-
> ```
|
|
347
|
-
|
|
348
|
-
### 6.5 测试套件导出与注册
|
|
349
|
-
|
|
350
|
-
```typescript
|
|
351
|
-
// 测试文件必须导出默认函数
|
|
352
|
-
export default function LodashXtsTest() {
|
|
353
|
-
describe('LodashXtsTest', () => {
|
|
354
|
-
// 测试用例...
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// 在入口文件中导入注册(import 路径不带 .ets 扩展名,保留 .test 部分)
|
|
359
|
-
import LodashXtsTest from './test/LodashXtsTest.test';
|
|
360
|
-
|
|
361
|
-
export default function testsuite() {
|
|
362
|
-
LodashXtsTest();
|
|
363
|
-
}
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
### 6.6 文件路径规范
|
|
367
|
-
|
|
368
|
-
> ⚠️ **禁止硬编码文件路径**。测试中涉及文件操作(如 `saveIntoFile`、`saveIntoFileAsync`),必须通过 `abilityDelegatorRegistry` 获取应用沙箱目录。
|
|
369
|
-
>
|
|
370
|
-
> ```typescript
|
|
371
|
-
> // ❌ 错误:硬编码路径在应用沙箱中不可访问
|
|
372
|
-
> const testFilePath = '/data/local/tmp/test.png';
|
|
373
|
-
> const testFilePath = '/data/storage/el2/base/haps/entry/files/test.png';
|
|
374
|
-
>
|
|
375
|
-
> // ✅ 正确:通过 AbilityDelegator 获取真实沙箱目录
|
|
376
|
-
> import { abilityDelegatorRegistry } from '@kit.TestKit';
|
|
377
|
-
> import { common } from '@kit.AbilityKit';
|
|
378
|
-
>
|
|
379
|
-
> let tempDir: string = '';
|
|
380
|
-
>
|
|
381
|
-
> beforeAll(() => {
|
|
382
|
-
> const delegator = abilityDelegatorRegistry.getAbilityDelegator();
|
|
383
|
-
> const appContext: common.Context = delegator.getAppContext();
|
|
384
|
-
> tempDir = appContext.tempDir;
|
|
385
|
-
> });
|
|
386
|
-
>
|
|
387
|
-
> // 使用时拼接
|
|
388
|
-
> const testFilePath: string = tempDir + '/test.png';
|
|
389
|
-
> ```
|
|
390
|
-
>
|
|
391
|
-
> Context 提供的沙箱目录:
|
|
392
|
-
> | 属性 | 说明 | 适用场景 |
|
|
393
|
-
> |------|------|---------|
|
|
394
|
-
> | `tempDir` | 临时目录,系统可能自动清理 | 测试文件输出 |
|
|
395
|
-
> | `filesDir` | 文件目录,持久存储 | 需持久化的文件 |
|
|
396
|
-
> | `cacheDir` | 缓存目录 | 缓存文件 |
|
|
397
|
-
|
|
398
|
-
---
|
|
399
|
-
|
|
400
|
-
## 七、代码质量检查清单
|
|
401
|
-
|
|
402
|
-
生成代码后,按以下清单逐项检查:
|
|
403
|
-
|
|
404
|
-
### 7.1 编译检查
|
|
405
|
-
|
|
406
|
-
- ✅ 无 `any` 类型使用
|
|
407
|
-
- ✅ 无 `Object`/`ESObject` 类型使用
|
|
408
|
-
- ✅ 无动态属性访问 `obj['key']`
|
|
409
|
-
- ✅ 所有变量有明确类型声明
|
|
410
|
-
- ✅ 无 Jest 风格断言(toBe/equal/toThrow/toBeNull/toBeTruthy 等)
|
|
411
|
-
- ✅ 断言全部为 `expect(x).assertXxx()` 链式调用(无 `assertTrue(x)`/`assertEqual(a, b)` 裸函数调用)
|
|
412
|
-
- ✅ 无向库 API 直传 `null` 实参(用等价 falsy 值覆盖守卫路径并注释依据)
|
|
413
|
-
- ✅ 无硬编码文件路径(使用 abilityDelegatorRegistry 获取沙箱目录)
|
|
414
|
-
- ✅ 无 `null as SomeType` 不兼容强转
|
|
415
|
-
- ✅ 无 `unknown` 关键字使用(包括 `as unknown as` 双重转换,arkts-no-any-unknown)
|
|
416
|
-
- ✅ 无 `catch(e) { throw e }` 模式(arkts-limited-throw)
|
|
417
|
-
- ✅ hilog 使用 `@kit.PerformanceAnalysisKit` 导入(非 `@ohos.hilog`)
|
|
418
|
-
- ✅ 文件扩展名为 `.test.ets`(非 `.ts`)
|
|
419
|
-
|
|
420
|
-
### 7.2 空值/异常/大数据测试检查
|
|
421
|
-
|
|
422
|
-
- ✅ 每个可测试接口至少有 1 个空值/null/undefined 输入用例
|
|
423
|
-
- ✅ 每个可测试接口至少有 1 个异常参数或边界值输入用例
|
|
424
|
-
- ✅ 接受集合类型参数的接口至少有 1 个大数据量输入用例
|
|
425
|
-
- ✅ 空值输入用例验证不崩溃 + 验证返回安全默认值
|
|
426
|
-
- ✅ 异常/边界值用例验证抛出异常或返回合理处理结果
|
|
427
|
-
- ✅ 大数据量用例验证结果正确性(长度/首尾/深层值)+ 不超时 + 不崩溃
|
|
428
|
-
- ✅ 大数据量用例的测试数据构建使用类型安全方式(定义 interface,禁止 any/Object)
|
|
429
|
-
- ✅ 所有导入路径正确
|
|
430
|
-
|
|
431
|
-
### 7.3 日志检查
|
|
432
|
-
|
|
433
|
-
- ✅ 所有测试函数开始有 INFO 日志
|
|
434
|
-
- ✅ 测试执行结果有 DEBUG 日志
|
|
435
|
-
- ✅ 测试失败有 ERROR 日志
|
|
436
|
-
- ✅ beforeAll/afterAll 有 INFO 日志
|
|
437
|
-
- ✅ 日志格式化参数正确(public/private)
|
|
438
|
-
- ✅ DOMAIN 和 TAG 定义正确
|
|
439
|
-
|
|
440
|
-
### 7.4 注释检查
|
|
441
|
-
|
|
442
|
-
- ✅ 文件头部有完整注释
|
|
443
|
-
- ✅ 每个测试函数有 JSDoc 注释
|
|
444
|
-
- ✅ 测试步骤有区块分隔注释
|
|
445
|
-
- ✅ 注释内容清晰明了
|
|
446
|
-
|
|
447
|
-
### 7.5 错误处理检查
|
|
448
|
-
|
|
449
|
-
- ✅ 预期异常测试使用 try-catch + 布尔标记模式
|
|
450
|
-
- ✅ catch 中禁止 `throw e`(arkts-limited-throw)
|
|
451
|
-
- ✅ 正常测试不需要 try-catch 包裹
|
|
452
|
-
- ✅ null 值输入测试使用 null 检查 + `throw new Error()` 或空对象 mock
|
|
453
|
-
- ✅ instanceof 异常类型断言已深层路径导入真实异常类(见 5.5)
|
|
454
|
-
- ✅ 文件路径通过 abilityDelegatorRegistry 获取,不硬编码
|
|
455
|
-
|
|
456
|
-
### 7.6 测试逻辑检查
|
|
457
|
-
|
|
458
|
-
- ✅ 预期结果断言完整
|
|
459
|
-
- ✅ 多接口用例调用顺序正确
|
|
460
|
-
- ✅ 测试数据准备充分
|
|
461
|
-
- ✅ 边界值覆盖完整
|
|
462
|
-
|
|
463
|
-
### 7.7 测试隔离检查
|
|
464
|
-
|
|
465
|
-
- ✅ 单例状态隔离:库使用 `getInstance()` 单例模式时,断言单例状态的用例必须在断言前重置状态
|
|
466
|
-
- ✅ 跨用例污染检查:同一测试文件中排在前面的用例是否可能修改了被断言的全局/单例状态
|
|
467
|
-
- ✅ `beforeAll` vs `beforeEach`:单例状态重置应使用 `beforeEach`(每个用例前都执行),而非 `beforeAll`(仅执行一次)
|
|
468
|
-
- ✅ 初始状态断言守则:断言"初始状态/默认状态"时,必须确认该状态在当前运行环境中确实可达(前面用例未修改)
|
|
469
|
-
|
|
470
|
-
### 7.8 期望值验证检查
|
|
471
|
-
|
|
472
|
-
- ✅ 程序化数据期望值:测试数据通过 `for` 循环、取余、映射等程序化方式生成时,期望值必须用表达式计算或手动计算后注释计算过程
|
|
473
|
-
- ✅ 取余/循环计算验证:涉及 `%`(取余)操作的测试数据,必须实际计算目标索引处的值(如 `9999 % 256 = 15`),禁止从"循环范围上界"联想
|
|
474
|
-
- ✅ 语义联想禁止:禁止从报告描述(如"0-255 循环"、"递增序列")直接推断具体索引处的期望值,必须基于生成公式计算
|
|
475
|
-
- ✅ 计算过程注释:硬编码期望值旁建议添加注释记录计算依据(如 `// 9999 % 256 = 15`)
|
|
476
|
-
|
|
477
|
-
### 7.9 访问修饰符预检检查
|
|
478
|
-
|
|
479
|
-
- ✅ Phase 1.5 预检已执行(条件性):`precheck-access-modifiers.cjs` 脚本已运行(当输入含旧格式规格文档时),`precheck-access-modifiers.json` 已生成
|
|
480
|
-
- ✅ private/protected 成员排除清单已建立:所有 `private`/`protected` 属性和方法已记录
|
|
481
|
-
- ✅ private/protected 成员已跳过:未为 private/protected 成员生成任何用例
|
|
482
|
-
- ✅ 并行 Agent 预检规则已注入:每个 Agent 的 prompt 包含排除清单
|
|
483
|
-
- ✅ 无 `Property 'X' is private` 编译错误残留
|
|
484
|
-
- ✅ 输入经标准链路生成(xts-doc 已过滤 private/protected)时,可跳过此预检并说明依据
|
|
485
|
-
|
|
486
|
-
---
|
|
487
|
-
|
|
488
|
-
## 八、常见编译错误及修复
|
|
489
|
-
|
|
490
|
-
| 错误 | 常见原因 | 修复方法 |
|
|
491
|
-
|------|---------|---------|
|
|
492
|
-
| private/protected 访问 | 接口规格未标注访问修饰符,测试代码直接调用 | Phase 1.5 预检排除(已执行时);残留的删除直接访问或跳过该用例 |
|
|
493
|
-
| arkts-no-any | 使用了 any 类型 | 定义具体类型 `interface ResultType { ... }` |
|
|
494
|
-
| arkts-no-any-unknown | 使用了 `unknown` 关键字或 `null as unknown as Type` 双重转换 | `unknown` 被完全禁止。改用空但合法的对象(如 `new BleDevice('', '')`)、构造最小字段对象字面量 `as Type`、或 `{} as Type`(不需实际功能的参数) |
|
|
495
|
-
| arkts-no-types-in-catch | catch 子句带类型注解 `catch (e: Object)` | `catch (e)` 不带类型注解,e 默认为 Object 类型 |
|
|
496
|
-
| Property does not exist on type 'Object' | `as Object` 转型后访问属性 | 保留原始类型不做 `as Object` 转型;或用 `as SpecificType` |
|
|
497
|
-
| types have no overlap | 枚举成员直接 `===` 比较 | `(Enum.A as number) !== (Enum.B as number)` |
|
|
498
|
-
| arkts-no-untyped-obj-literals | `{}` 赋值给 Object 类型变量 | 定义命名 class/interface,用 `new MockClass()` 代替 `{}` |
|
|
499
|
-
| Type 'null' is not assignable to type 'Object' | `null as Object` 转型 | 直接用 `null`,不做 `as Object` 转型 |
|
|
500
|
-
| arkts-no-esobj | 使用了 Object 类型 | 定义命名 interface |
|
|
501
|
-
| arkts-limited-throw | `throw e` 其中 e 非Error类型 | 仅允许 `throw new Error(msg)`,改用 try-catch + 布尔标记 |
|
|
502
|
-
| 类型不兼容 | `null as SomeType` 强转 | 使用 `{} as common.Context` 或 null 检查 + throw new Error |
|
|
503
|
-
| 类型推断失败 | 类型定义不明确 | 添加显式类型声明 `const result: number = ...` |
|
|
504
|
-
| 导入路径错误 | 库包名不正确 | 检查 `library/index.ets` 的导出路径 |
|
|
505
|
-
| 函数签名不匹配 | 参数类型/数量错误 | 检查接口规格文档中的函数签名 |
|
|
506
|
-
| 未找到模块 | 模块未安装 | 运行 `ohpm install` 安装依赖 |
|
|
507
|
-
| hilog 导入错误 | 使用 `import hilog from '@ohos.hilog'` | 改为 `import { hilog } from '@kit.PerformanceAnalysisKit'` |
|
|
508
|
-
| 断言方法不存在 | 使用 Jest 风格如 toBe/toThrow | 改用 hypium 断言:assertEqual/assertNull/assertTrue/assertFalse/assertLarger/assertContain |
|
|
509
|
-
| `Cannot find name 'assertTrue'`(批量) | 生成了 `assertTrue(x)`/`assertEqual(a,b)` 裸函数调用而非 `expect(x).assertXxx()` 链式调用(hypium 断言只存在于 expect 对象上) | 脚本批量转换(括号配平、顶层逗号切分双参断言、单参直接包裹);生成前 prompt 给断言正反例预防 |
|
|
510
|
-
| 接口赋值类型不兼容 | `The types returned by 'getX()' are incompatible` + `is missing the following properties from type` —— 库接口方法返回类型声明与实现类不一致(Demo 不暴露,测试首次触达才显现) | 修接口声明对齐实现类实际返回类型(如 `Array<>` 改实际容器类型,属源库机械性修正 ⚠️),禁止在测试中强转绕过 |
|
|
511
|
-
| `Argument of type 'null' is not assignable to parameter of type 'string'` | 测试代码向库 API 传 null 实参(库源码 `@ts-nocheck` 不豁免测试文件的严格检查) | 库内部用 `if (x)` 判空时空串/空数组与 null 语义等价,改传等价 falsy 值(如 `new ID3v1Tag('')`)覆盖同一守卫路径并注释等价依据 |
|
|
512
|
-
| instanceof 异常类型断言失效/异常类未导出 | 自定义异常类未从 `library/index.ets` 导出,无法 import | 深层路径导入(如 `@ohos/mp3agic/src/main/ets/components/mp3agic/NoSuchTagException`),import 真实类后做 `e instanceof XxxException` |
|
|
513
|
-
| 文件路径不可写 | 硬编码 `/data/local/tmp/` 等 | 通过 abilityDelegatorRegistry 获取沙箱 tempDir/filesDir |
|
|
514
|
-
| 不安全转型 | `arkts-no-unsafe-cast` | 正确定义类型,避免双重 `as unknown as` |
|
|
515
|
-
| 缺少权限 | — | 在 ohosTest 的 module.json5 中声明 |
|
|
516
|
-
|
|
517
|
-
---
|
|
518
|
-
|
|
1
|
+
# XTS 测试代码生成规范速查
|
|
2
|
+
|
|
3
|
+
本文档为 `arkts-library-xts-code` 技能提供编码规范速查,涵盖文件命名、ArkTS 禁止项、日志规范、注释规范、错误处理、hypium 测试框架使用等。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 一、文件命名规范
|
|
8
|
+
|
|
9
|
+
### 测试文件命名
|
|
10
|
+
|
|
11
|
+
格式:`{LibraryName}XtsTest.test.ets`
|
|
12
|
+
|
|
13
|
+
所有测试文件统一放在 `entry/src/ohosTest/ets/test/` 目录。
|
|
14
|
+
|
|
15
|
+
> ⚠️ **扩展名必须为 `.test.ets`**,不能用 `.ts` 或 `.ets`。OpenHarmony XTS 测试框架要求测试文件使用 `.test.ets` 扩展名。
|
|
16
|
+
|
|
17
|
+
| 规则 | 说明 | 示例 |
|
|
18
|
+
|------|------|------|
|
|
19
|
+
| LibraryName | 库名(PascalCase) | `Lodash`、`Axios`、`BlurKit` |
|
|
20
|
+
| 完整文件名 | `{LibraryName}XtsTest.test.ets` | `LodashXtsTest.test.ets` |
|
|
21
|
+
|
|
22
|
+
**示例映射**:
|
|
23
|
+
|
|
24
|
+
| 库名 | 测试文件路径 |
|
|
25
|
+
|------|---------------------------------------|
|
|
26
|
+
| lodash | `entry/src/ohosTest/ets/test/LodashXtsTest.test.ets` |
|
|
27
|
+
| axios | `entry/src/ohosTest/ets/test/AxiosXtsTest.test.ets` |
|
|
28
|
+
| blur-kit | `entry/src/ohosTest/ets/test/BlurKitXtsTest.test.ets` |
|
|
29
|
+
|
|
30
|
+
### 测试函数命名
|
|
31
|
+
|
|
32
|
+
格式:`{function_snake_case}_{SEQ}`
|
|
33
|
+
|
|
34
|
+
| 规则 | 说明 | 示例 |
|
|
35
|
+
|------|------|------|
|
|
36
|
+
| function_snake_case | 英文功能描述(小写+下划线,≤20字符) | `chunk_basic`、`get_set_path` |
|
|
37
|
+
| SEQ | 三位数字序号 | `001`、`007`、`012` |
|
|
38
|
+
| 完整函数名 | `{描述}_{序号}` | `chunk_basic_001` |
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 二、ArkTS 编译禁止项(必查)
|
|
43
|
+
|
|
44
|
+
生成的所有代码必须规避以下 ArkTS 严格模式编译报错:
|
|
45
|
+
|
|
46
|
+
| 禁止项 | 错误标识 | 正确替代 |
|
|
47
|
+
|-------|---------|---------|
|
|
48
|
+
| `any` 类型 | `arkts-no-any` | 具体类型或泛型 `T` |
|
|
49
|
+
| `Object`/`ESObject` | `arkts-no-esobj` | 定义 `interface` 或具体类型 |
|
|
50
|
+
| 动态属性访问 `obj['key']` | `arkts-no-dynamic-property` | `obj.key` 类型安全访问 |
|
|
51
|
+
| 内联匿名对象类型 | `arkts-no-obj-literals-as-types` | 定义命名 `interface` |
|
|
52
|
+
| `prototype` 扩展 | `arkts-no-prototype-assignment` | 类继承或组合 |
|
|
53
|
+
| `delete` 操作符 | `arkts-no-delete` | 设为 `undefined` 或重构对象 |
|
|
54
|
+
| `arguments` 对象 | `arkts-no-arguments` | 展开参数 `...args: T[]` |
|
|
55
|
+
| `unknown` 关键字及双重 `as unknown as T` | `arkts-no-any-unknown` | `unknown` 关键字在 ArkTS 严格模式下被完全禁止,不能用于类型转换中间层。替代方案:① 传递空但合法的对象(如 `new BleDevice('', '')` 代替 `null as BleDevice`);② 对需要 null 参数的异常测试,改测空字符串/零值参数的行为;③ 构造最小必填字段对象字面量并 `as Type`(如 `as ble.ScanResult`);④ 不需要实际功能的参数用 `{} as Type`(如 `{} as common.Context`) |
|
|
56
|
+
| `for...in` | `arkts-no-for-in` | `Object.keys().forEach()` |
|
|
57
|
+
| `eval()` | `arkts-no-eval` | 禁止使用 |
|
|
58
|
+
| `catch(e)` 中直接 `throw e` | `arkts-limited-throw` | **禁止重新抛出任意类型异常**。改用 try-catch + 布尔标记模式,catch 中仅设标记,不 throw |
|
|
59
|
+
| `null as SomeType` 强转 | 类型不兼容错误 | `{} as common.Context`(用于不需要实际功能的参数),或 null 检查 + `throw new Error()` |
|
|
60
|
+
| `undefined as SomeType` | 类型不兼容错误 | null 检查 + 安全默认值或 `throw new Error()` |
|
|
61
|
+
| catch 子句类型注解 | `arkts-no-types-in-catch` | `catch (e)` 不带类型注解,e 默认为 Object 类型(非 any),不违反 `arkts-no-any-unknown` |
|
|
62
|
+
| `as Object` 后访问属性 | `Property 'X' does not exist on type 'Object'` | 保留原始类型不做 `as Object` 转型;仅在不需要属性访问时用 `as Object`(如验证非 null) |
|
|
63
|
+
| 枚举成员直接比较 | `types 'A' and 'B' have no overlap` | `(Enum.A as number) !== (Enum.B as number)` 转型后比较 |
|
|
64
|
+
| 无类型对象字面量 | `arkts-no-untyped-obj-literals` | `{}` 或 `{ key: value }` 必须对应命名 interface/class;定义 `class MockTarget { prop: string = ''; }` 代替 `let x: Object = {}` |
|
|
65
|
+
| 向 `@ts-nocheck` 库 API 传 `null` 实参 | `Argument of type 'null' is not assignable to parameter of type 'string'` | 库源码的 `@ts-nocheck` **不豁免测试文件**,调用处仍受严格空值检查约束。库内部用 `if (x)` 判空时,空串 `''`/空数组 `[]` 与 null 语义等价 → 改传等价 falsy 值覆盖同一守卫路径(如 `new ID3v1Tag('')`),并在注释中说明等价性依据 |
|
|
66
|
+
| 断言裸函数调用 | `Cannot find name 'assertTrue'`(批量) | hypium 断言只存在于 `expect()` 返回对象上,**不存在独立全局函数**。`assertTrue(x)`/`assertEqual(a, b)` 裸调用是编译错误,必须写 `expect(x).assertTrue()` 链式调用 |
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 三、日志规范
|
|
71
|
+
|
|
72
|
+
### 3.1 DOMAIN 与 TAG 分配
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// ✅ 正确:每个测试文件有独立 TAG,DOMAIN 在工程中统一范围
|
|
76
|
+
const DOMAIN: number = 0xD001; // 单个工程统一使用一个域值
|
|
77
|
+
const TAG: string = 'Lodash_XtsTest'; // {库名}_XtsTest
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**TAG 命名规则**:`{LibraryName}_XtsTest`,不超过 32 字符,只含字母数字下划线。
|
|
81
|
+
|
|
82
|
+
### 3.2 日志级别选择
|
|
83
|
+
|
|
84
|
+
| 级别 | 函数 | 使用场景 |
|
|
85
|
+
|------|------|---------|
|
|
86
|
+
| DEBUG | `hilog.debug(...)` | 测试执行结果、中间状态 |
|
|
87
|
+
| INFO | `hilog.info(...)` | 测试开始/结束、套件生命周期 |
|
|
88
|
+
| ERROR | `hilog.error(...)` | 测试失败、捕获到异常 |
|
|
89
|
+
|
|
90
|
+
### 3.3 格式化参数
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// ✅ 公开数据(测试结果、参数)用 %{public}s
|
|
94
|
+
hilog.debug(DOMAIN, TAG, 'Result: %{public}s', JSON.stringify(result));
|
|
95
|
+
|
|
96
|
+
// ✅ 敏感数据用 %{private}s(日志中显示为 <private>)
|
|
97
|
+
hilog.debug(DOMAIN, TAG, 'Token: %{private}s', token);
|
|
98
|
+
|
|
99
|
+
// ❌ 禁止将敏感信息用 %{public}s 输出
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 3.4 必须添加日志的位置
|
|
103
|
+
|
|
104
|
+
| 位置 | 日志级别 | 示例 |
|
|
105
|
+
|------|---------|------|
|
|
106
|
+
| 测试函数开始 | INFO | `hilog.info(..., 'Test XXX started')` |
|
|
107
|
+
| 测试执行结果 | DEBUG | `hilog.debug(..., 'Result: %{public}s', ...)` |
|
|
108
|
+
| 测试成功完成 | INFO | `hilog.info(..., 'Test XXX passed')` |
|
|
109
|
+
| 测试失败 | ERROR | `hilog.error(..., 'Test XXX failed: %{public}s', msg)` |
|
|
110
|
+
| beforeAll/afterAll | INFO | `hilog.info(..., 'Suite started/finished')` |
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 四、注释规范
|
|
115
|
+
|
|
116
|
+
### 4.1 文件头部注释
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
/**
|
|
120
|
+
* {LibraryName} XTS 测试用例
|
|
121
|
+
*
|
|
122
|
+
* 基于 XTS 用例描述文档生成,验证 {LibraryName} 的核心功能。
|
|
123
|
+
* 文档来源:ohos_{LibraryName}xts用例描述.md
|
|
124
|
+
*
|
|
125
|
+
* 用例总数:{N}
|
|
126
|
+
* 可测试接口数:{M}
|
|
127
|
+
*
|
|
128
|
+
* @author lalhan
|
|
129
|
+
*/
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 4.2 测试函数注释
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
/**
|
|
136
|
+
* 用例 {SEQ}: {用例名称}
|
|
137
|
+
*
|
|
138
|
+
* 用例描述:{从用例描述文档提取的详细描述}
|
|
139
|
+
* 涉及接口:{接口签名列表}
|
|
140
|
+
* 预期结果:
|
|
141
|
+
* 1. {预期结果 1}
|
|
142
|
+
* 2. {预期结果 2}
|
|
143
|
+
*/
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 4.3 测试步骤注释
|
|
147
|
+
|
|
148
|
+
使用区块注释分隔测试步骤:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// ─── 步骤 1:{步骤功能} ───────────────────────────────────────────────────
|
|
152
|
+
const step1Result = interface1Call();
|
|
153
|
+
|
|
154
|
+
// ─── 步骤 2:{步骤功能} ───────────────────────────────────────────────────
|
|
155
|
+
const step2Result = interface2Call();
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 4.4 注释风格对比
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// ✅ 推荐:使用块注释说明测试步骤和区块分隔
|
|
162
|
+
/**
|
|
163
|
+
* ─── 步骤 1:设置属性 ───────────────────────────────────────────────────
|
|
164
|
+
* 验证 _.set 能正确设置嵌套属性
|
|
165
|
+
*/
|
|
166
|
+
const setResult = _.set(obj, 'a.b.c', 1);
|
|
167
|
+
|
|
168
|
+
// ❌ 避免:过多单行注释影响可读性
|
|
169
|
+
// 调用 set 方法
|
|
170
|
+
// 设置属性 a.b.c
|
|
171
|
+
// 值为 1
|
|
172
|
+
const setResult = _.set(obj, 'a.b.c', 1);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## 五、错误处理规范
|
|
178
|
+
|
|
179
|
+
### 5.1 必须包含错误处理的位置
|
|
180
|
+
|
|
181
|
+
| 位置 | 处理方式 |
|
|
182
|
+
|------|---------|
|
|
183
|
+
| 预期异常测试 | try-catch + 布尔标记模式,catch 中禁止 `throw e` |
|
|
184
|
+
| 空值输入测试 | 验证不崩溃 + 验证返回安全默认值 |
|
|
185
|
+
| 大数据量测试 | 记录执行时间 + 验证不超时不崩溃 |
|
|
186
|
+
| 正常测试 | 不需要 try-catch,让 expect 断言和框架自动处理失败 |
|
|
187
|
+
|
|
188
|
+
### 5.2 预期异常测试模板
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
// ✅ 推荐:try-catch + 布尔标记模式
|
|
192
|
+
let caught: boolean = false;
|
|
193
|
+
try {
|
|
194
|
+
libraryFunc(null);
|
|
195
|
+
} catch (e) {
|
|
196
|
+
caught = true;
|
|
197
|
+
// 禁止 throw e(arkts-limited-throw)
|
|
198
|
+
}
|
|
199
|
+
expect(caught).assertTrue();
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### 5.3 null 值输入测试模板
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
// 对于需要传入 null 但参数类型不允许 null-as-Type 强转的场景
|
|
206
|
+
// 使用 null 检查 + throw new Error() 模式
|
|
207
|
+
let caught: boolean = false;
|
|
208
|
+
try {
|
|
209
|
+
const emptyInput: SomeType | null = null;
|
|
210
|
+
if (emptyInput === null) {
|
|
211
|
+
throw new Error('Input cannot be null');
|
|
212
|
+
}
|
|
213
|
+
new SomeClass(emptyInput);
|
|
214
|
+
} catch (e) {
|
|
215
|
+
caught = true;
|
|
216
|
+
}
|
|
217
|
+
expect(caught).assertTrue();
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 5.4 空对象作为 Mock Context
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
// processRenderScript 等需要 Context 参数但不实际使用时
|
|
224
|
+
// ✅ 正确:空对象 as common.Context
|
|
225
|
+
const mockContext: common.Context = {} as common.Context;
|
|
226
|
+
manager.processRenderScript(mockContext, radius);
|
|
227
|
+
|
|
228
|
+
// ❌ 错误:null as common.Context(类型不兼容,ArkTS 编译报错)
|
|
229
|
+
// ❌ 错误:null as image.PixelMap(类型不兼容)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### 5.5 异常类型断言(instanceof)与深层路径导入
|
|
233
|
+
|
|
234
|
+
自定义异常类通常未从 `library/index.ets` 根入口导出,做 `instanceof` 类型断言前必须深层路径导入真实异常类(未导出的实现类同理):
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
// ✅ 正确:深层路径导入真实异常类后做 instanceof 断言
|
|
238
|
+
import { NoSuchTagException } from '@ohos/{LibraryName}/src/main/ets/components/{lib}/NoSuchTagException';
|
|
239
|
+
|
|
240
|
+
let isTarget: boolean = false;
|
|
241
|
+
try {
|
|
242
|
+
someCall();
|
|
243
|
+
} catch (e) {
|
|
244
|
+
isTarget = e instanceof NoSuchTagException; // 必须真实 import,禁止用 e.message 字符串匹配替代
|
|
245
|
+
}
|
|
246
|
+
expect(isTarget).assertTrue();
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
> 深层导入路径以库源码实际目录为准。仅做异常"是否抛出"的布尔断言时无需导入异常类;需要断言"异常类型正确"时才用本模式。
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## 六、hypium 测试框架使用指南
|
|
254
|
+
|
|
255
|
+
### 6.1 核心 API
|
|
256
|
+
|
|
257
|
+
| API | 用途 | 示例 |
|
|
258
|
+
|-----|------|------|
|
|
259
|
+
| `describe(name, fn)` | 定义测试套件 | `describe('LodashXtsTest', () => { ... })` |
|
|
260
|
+
| `it(name, fn)` | 定义单个测试 | `it('chunk_basic_001', () => { ... })` |
|
|
261
|
+
| `expect(value)` | 创建断言对象 | `expect(result).assertEqual(1)` |
|
|
262
|
+
| `beforeAll(fn)` | 套件开始前执行一次 | 全局初始化 |
|
|
263
|
+
| `afterAll(fn)` | 套件结束后执行一次 | 全局清理 |
|
|
264
|
+
| `beforeEach(fn)` | 每个测试前执行 | 测试数据准备 |
|
|
265
|
+
| `afterEach(fn)` | 每个测试后执行 | 测试数据清理 |
|
|
266
|
+
|
|
267
|
+
### 6.2 常用断言方法
|
|
268
|
+
|
|
269
|
+
> ⚠️ **重要**:`@ohos/hypium` 的 `expect()` 对象上**不存在** Jest 风格的 `toBe`/`toEqual`/`toBeTruthy`/`toBeFalsy`/`toThrow` 等方法。必须使用以下 hypium 专用断言方法:
|
|
270
|
+
|
|
271
|
+
| 断言方法 | 用途 | 示例 |
|
|
272
|
+
|---------|------|------|
|
|
273
|
+
| `assertEqual(value)` | 严格相等(===) | `expect(result).assertEqual(1)` |
|
|
274
|
+
| `assertContain(item)` | 包含判断(数组/字符串) | `expect(arr).assertContain(1)` |
|
|
275
|
+
| `assertLarger(value)` | 大于判断 | `expect(count).assertLarger(0)` |
|
|
276
|
+
| `assertNull()` | null 判断 | `expect(result).assertNull()` |
|
|
277
|
+
| `assertTrue()` | 布尔真判断 | `expect(x !== null).assertTrue()` |
|
|
278
|
+
| `assertFalse()` | 布尔假判断 | `expect(x === null).assertFalse()` |
|
|
279
|
+
|
|
280
|
+
### 6.3 Jest 风格方法替代方案
|
|
281
|
+
|
|
282
|
+
| Jest 风格(❌ 不存在) | hypium 替代(✅ 正确) | 说明 |
|
|
283
|
+
|----------------------|----------------------|------|
|
|
284
|
+
| `expect(x).toBe(y)` | `expect(x).assertEqual(y)` | 严格相等 |
|
|
285
|
+
| `expect(x).toEqual(y)` | `expect(x).assertEqual(y)` | 深度相等也用 assertEqual |
|
|
286
|
+
| `expect(x).toBeNull()` | `expect(x).assertNull()` | null 判断 |
|
|
287
|
+
| `expect(x).toBeTruthy()` | `expect(x !== null).assertTrue()` | 真值 → 布尔表达式 |
|
|
288
|
+
| `expect(x).toBeFalsy()` | `expect(x).assertFalse()` | 假值 |
|
|
289
|
+
| `expect(x).not.toBeNull()` | `expect(x !== null).assertTrue()` | 否定断言 → 布尔表达式 |
|
|
290
|
+
| `expect(fn).toThrow()` | try-catch + 布尔标记 | 见下方说明 |
|
|
291
|
+
| `expect(x).toBeGreaterThan(n)` | `expect(x).assertLarger(n)` | 大于 |
|
|
292
|
+
| `expect(x).toBeLessThan(n)` | `expect(n).assertLarger(x)` | 小于(反转方向) |
|
|
293
|
+
| `expect(x).toContain(y)` | `expect(x).assertContain(y)` | 包含 |
|
|
294
|
+
| `expect(x).not.toBe(y)` | `expect(x === y).assertFalse()` | 否定断言 → 布尔表达式 |
|
|
295
|
+
|
|
296
|
+
**`toThrow()` 替代方案**:
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
// ❌ 错误:hypium 不支持 toThrow()
|
|
300
|
+
expect(() => func(null)).toThrow();
|
|
301
|
+
|
|
302
|
+
// ✅ 正确:try-catch + 布尔标记模式
|
|
303
|
+
let caught: boolean = false;
|
|
304
|
+
try {
|
|
305
|
+
func(null);
|
|
306
|
+
} catch (e) {
|
|
307
|
+
caught = true;
|
|
308
|
+
}
|
|
309
|
+
expect(caught).assertTrue();
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
**`toBeLessThan()` 替代方案**:
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
// ❌ 错误:hypium 不支持 toBeLessThan()
|
|
316
|
+
expect(duration).toBeLessThan(10000);
|
|
317
|
+
|
|
318
|
+
// ✅ 正确:反转比较方向
|
|
319
|
+
expect(10000).assertLarger(duration); // 即 10000 > duration
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### 6.4 异步测试
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
// 异步测试使用 async/await
|
|
326
|
+
it('async_test', async () => {
|
|
327
|
+
const result = await asyncFunc();
|
|
328
|
+
expect(result).assertEqual(expected);
|
|
329
|
+
});
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
> ⚠️ **同步方法内部委托异步方法的陷阱**:若库的某个同步方法(如 `saveIntoFile`)内部实际委托给异步方法(如 `saveIntoFileAsync`),则测试时必须使用 `async` 函数 + `await`,否则异步操作尚未完成就执行了后续断言。
|
|
333
|
+
>
|
|
334
|
+
> ```typescript
|
|
335
|
+
> // ❌ 错误:saveIntoFile 内部是异步的,同步调用后立即检查文件
|
|
336
|
+
> it('save_test', 0, () => {
|
|
337
|
+
> manager.saveIntoFile(path); // 内部调用 saveIntoFileAsync(异步)
|
|
338
|
+
> expect(fs.accessSync(path)).assertTrue(); // 文件可能还没写入!
|
|
339
|
+
> });
|
|
340
|
+
>
|
|
341
|
+
> // ✅ 正确:使用 async + await
|
|
342
|
+
> it('save_test', 0, async () => {
|
|
343
|
+
> await manager.saveIntoFileAsync(path); // 等待异步写入完成
|
|
344
|
+
> expect(fs.accessSync(path)).assertTrue(); // 文件已写入
|
|
345
|
+
> });
|
|
346
|
+
> ```
|
|
347
|
+
|
|
348
|
+
### 6.5 测试套件导出与注册
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
// 测试文件必须导出默认函数
|
|
352
|
+
export default function LodashXtsTest() {
|
|
353
|
+
describe('LodashXtsTest', () => {
|
|
354
|
+
// 测试用例...
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// 在入口文件中导入注册(import 路径不带 .ets 扩展名,保留 .test 部分)
|
|
359
|
+
import LodashXtsTest from './test/LodashXtsTest.test';
|
|
360
|
+
|
|
361
|
+
export default function testsuite() {
|
|
362
|
+
LodashXtsTest();
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### 6.6 文件路径规范
|
|
367
|
+
|
|
368
|
+
> ⚠️ **禁止硬编码文件路径**。测试中涉及文件操作(如 `saveIntoFile`、`saveIntoFileAsync`),必须通过 `abilityDelegatorRegistry` 获取应用沙箱目录。
|
|
369
|
+
>
|
|
370
|
+
> ```typescript
|
|
371
|
+
> // ❌ 错误:硬编码路径在应用沙箱中不可访问
|
|
372
|
+
> const testFilePath = '/data/local/tmp/test.png';
|
|
373
|
+
> const testFilePath = '/data/storage/el2/base/haps/entry/files/test.png';
|
|
374
|
+
>
|
|
375
|
+
> // ✅ 正确:通过 AbilityDelegator 获取真实沙箱目录
|
|
376
|
+
> import { abilityDelegatorRegistry } from '@kit.TestKit';
|
|
377
|
+
> import { common } from '@kit.AbilityKit';
|
|
378
|
+
>
|
|
379
|
+
> let tempDir: string = '';
|
|
380
|
+
>
|
|
381
|
+
> beforeAll(() => {
|
|
382
|
+
> const delegator = abilityDelegatorRegistry.getAbilityDelegator();
|
|
383
|
+
> const appContext: common.Context = delegator.getAppContext();
|
|
384
|
+
> tempDir = appContext.tempDir;
|
|
385
|
+
> });
|
|
386
|
+
>
|
|
387
|
+
> // 使用时拼接
|
|
388
|
+
> const testFilePath: string = tempDir + '/test.png';
|
|
389
|
+
> ```
|
|
390
|
+
>
|
|
391
|
+
> Context 提供的沙箱目录:
|
|
392
|
+
> | 属性 | 说明 | 适用场景 |
|
|
393
|
+
> |------|------|---------|
|
|
394
|
+
> | `tempDir` | 临时目录,系统可能自动清理 | 测试文件输出 |
|
|
395
|
+
> | `filesDir` | 文件目录,持久存储 | 需持久化的文件 |
|
|
396
|
+
> | `cacheDir` | 缓存目录 | 缓存文件 |
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## 七、代码质量检查清单
|
|
401
|
+
|
|
402
|
+
生成代码后,按以下清单逐项检查:
|
|
403
|
+
|
|
404
|
+
### 7.1 编译检查
|
|
405
|
+
|
|
406
|
+
- ✅ 无 `any` 类型使用
|
|
407
|
+
- ✅ 无 `Object`/`ESObject` 类型使用
|
|
408
|
+
- ✅ 无动态属性访问 `obj['key']`
|
|
409
|
+
- ✅ 所有变量有明确类型声明
|
|
410
|
+
- ✅ 无 Jest 风格断言(toBe/equal/toThrow/toBeNull/toBeTruthy 等)
|
|
411
|
+
- ✅ 断言全部为 `expect(x).assertXxx()` 链式调用(无 `assertTrue(x)`/`assertEqual(a, b)` 裸函数调用)
|
|
412
|
+
- ✅ 无向库 API 直传 `null` 实参(用等价 falsy 值覆盖守卫路径并注释依据)
|
|
413
|
+
- ✅ 无硬编码文件路径(使用 abilityDelegatorRegistry 获取沙箱目录)
|
|
414
|
+
- ✅ 无 `null as SomeType` 不兼容强转
|
|
415
|
+
- ✅ 无 `unknown` 关键字使用(包括 `as unknown as` 双重转换,arkts-no-any-unknown)
|
|
416
|
+
- ✅ 无 `catch(e) { throw e }` 模式(arkts-limited-throw)
|
|
417
|
+
- ✅ hilog 使用 `@kit.PerformanceAnalysisKit` 导入(非 `@ohos.hilog`)
|
|
418
|
+
- ✅ 文件扩展名为 `.test.ets`(非 `.ts`)
|
|
419
|
+
|
|
420
|
+
### 7.2 空值/异常/大数据测试检查
|
|
421
|
+
|
|
422
|
+
- ✅ 每个可测试接口至少有 1 个空值/null/undefined 输入用例
|
|
423
|
+
- ✅ 每个可测试接口至少有 1 个异常参数或边界值输入用例
|
|
424
|
+
- ✅ 接受集合类型参数的接口至少有 1 个大数据量输入用例
|
|
425
|
+
- ✅ 空值输入用例验证不崩溃 + 验证返回安全默认值
|
|
426
|
+
- ✅ 异常/边界值用例验证抛出异常或返回合理处理结果
|
|
427
|
+
- ✅ 大数据量用例验证结果正确性(长度/首尾/深层值)+ 不超时 + 不崩溃
|
|
428
|
+
- ✅ 大数据量用例的测试数据构建使用类型安全方式(定义 interface,禁止 any/Object)
|
|
429
|
+
- ✅ 所有导入路径正确
|
|
430
|
+
|
|
431
|
+
### 7.3 日志检查
|
|
432
|
+
|
|
433
|
+
- ✅ 所有测试函数开始有 INFO 日志
|
|
434
|
+
- ✅ 测试执行结果有 DEBUG 日志
|
|
435
|
+
- ✅ 测试失败有 ERROR 日志
|
|
436
|
+
- ✅ beforeAll/afterAll 有 INFO 日志
|
|
437
|
+
- ✅ 日志格式化参数正确(public/private)
|
|
438
|
+
- ✅ DOMAIN 和 TAG 定义正确
|
|
439
|
+
|
|
440
|
+
### 7.4 注释检查
|
|
441
|
+
|
|
442
|
+
- ✅ 文件头部有完整注释
|
|
443
|
+
- ✅ 每个测试函数有 JSDoc 注释
|
|
444
|
+
- ✅ 测试步骤有区块分隔注释
|
|
445
|
+
- ✅ 注释内容清晰明了
|
|
446
|
+
|
|
447
|
+
### 7.5 错误处理检查
|
|
448
|
+
|
|
449
|
+
- ✅ 预期异常测试使用 try-catch + 布尔标记模式
|
|
450
|
+
- ✅ catch 中禁止 `throw e`(arkts-limited-throw)
|
|
451
|
+
- ✅ 正常测试不需要 try-catch 包裹
|
|
452
|
+
- ✅ null 值输入测试使用 null 检查 + `throw new Error()` 或空对象 mock
|
|
453
|
+
- ✅ instanceof 异常类型断言已深层路径导入真实异常类(见 5.5)
|
|
454
|
+
- ✅ 文件路径通过 abilityDelegatorRegistry 获取,不硬编码
|
|
455
|
+
|
|
456
|
+
### 7.6 测试逻辑检查
|
|
457
|
+
|
|
458
|
+
- ✅ 预期结果断言完整
|
|
459
|
+
- ✅ 多接口用例调用顺序正确
|
|
460
|
+
- ✅ 测试数据准备充分
|
|
461
|
+
- ✅ 边界值覆盖完整
|
|
462
|
+
|
|
463
|
+
### 7.7 测试隔离检查
|
|
464
|
+
|
|
465
|
+
- ✅ 单例状态隔离:库使用 `getInstance()` 单例模式时,断言单例状态的用例必须在断言前重置状态
|
|
466
|
+
- ✅ 跨用例污染检查:同一测试文件中排在前面的用例是否可能修改了被断言的全局/单例状态
|
|
467
|
+
- ✅ `beforeAll` vs `beforeEach`:单例状态重置应使用 `beforeEach`(每个用例前都执行),而非 `beforeAll`(仅执行一次)
|
|
468
|
+
- ✅ 初始状态断言守则:断言"初始状态/默认状态"时,必须确认该状态在当前运行环境中确实可达(前面用例未修改)
|
|
469
|
+
|
|
470
|
+
### 7.8 期望值验证检查
|
|
471
|
+
|
|
472
|
+
- ✅ 程序化数据期望值:测试数据通过 `for` 循环、取余、映射等程序化方式生成时,期望值必须用表达式计算或手动计算后注释计算过程
|
|
473
|
+
- ✅ 取余/循环计算验证:涉及 `%`(取余)操作的测试数据,必须实际计算目标索引处的值(如 `9999 % 256 = 15`),禁止从"循环范围上界"联想
|
|
474
|
+
- ✅ 语义联想禁止:禁止从报告描述(如"0-255 循环"、"递增序列")直接推断具体索引处的期望值,必须基于生成公式计算
|
|
475
|
+
- ✅ 计算过程注释:硬编码期望值旁建议添加注释记录计算依据(如 `// 9999 % 256 = 15`)
|
|
476
|
+
|
|
477
|
+
### 7.9 访问修饰符预检检查
|
|
478
|
+
|
|
479
|
+
- ✅ Phase 1.5 预检已执行(条件性):`precheck-access-modifiers.cjs` 脚本已运行(当输入含旧格式规格文档时),`precheck-access-modifiers.json` 已生成
|
|
480
|
+
- ✅ private/protected 成员排除清单已建立:所有 `private`/`protected` 属性和方法已记录
|
|
481
|
+
- ✅ private/protected 成员已跳过:未为 private/protected 成员生成任何用例
|
|
482
|
+
- ✅ 并行 Agent 预检规则已注入:每个 Agent 的 prompt 包含排除清单
|
|
483
|
+
- ✅ 无 `Property 'X' is private` 编译错误残留
|
|
484
|
+
- ✅ 输入经标准链路生成(xts-doc 已过滤 private/protected)时,可跳过此预检并说明依据
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
488
|
+
## 八、常见编译错误及修复
|
|
489
|
+
|
|
490
|
+
| 错误 | 常见原因 | 修复方法 |
|
|
491
|
+
|------|---------|---------|
|
|
492
|
+
| private/protected 访问 | 接口规格未标注访问修饰符,测试代码直接调用 | Phase 1.5 预检排除(已执行时);残留的删除直接访问或跳过该用例 |
|
|
493
|
+
| arkts-no-any | 使用了 any 类型 | 定义具体类型 `interface ResultType { ... }` |
|
|
494
|
+
| arkts-no-any-unknown | 使用了 `unknown` 关键字或 `null as unknown as Type` 双重转换 | `unknown` 被完全禁止。改用空但合法的对象(如 `new BleDevice('', '')`)、构造最小字段对象字面量 `as Type`、或 `{} as Type`(不需实际功能的参数) |
|
|
495
|
+
| arkts-no-types-in-catch | catch 子句带类型注解 `catch (e: Object)` | `catch (e)` 不带类型注解,e 默认为 Object 类型 |
|
|
496
|
+
| Property does not exist on type 'Object' | `as Object` 转型后访问属性 | 保留原始类型不做 `as Object` 转型;或用 `as SpecificType` |
|
|
497
|
+
| types have no overlap | 枚举成员直接 `===` 比较 | `(Enum.A as number) !== (Enum.B as number)` |
|
|
498
|
+
| arkts-no-untyped-obj-literals | `{}` 赋值给 Object 类型变量 | 定义命名 class/interface,用 `new MockClass()` 代替 `{}` |
|
|
499
|
+
| Type 'null' is not assignable to type 'Object' | `null as Object` 转型 | 直接用 `null`,不做 `as Object` 转型 |
|
|
500
|
+
| arkts-no-esobj | 使用了 Object 类型 | 定义命名 interface |
|
|
501
|
+
| arkts-limited-throw | `throw e` 其中 e 非Error类型 | 仅允许 `throw new Error(msg)`,改用 try-catch + 布尔标记 |
|
|
502
|
+
| 类型不兼容 | `null as SomeType` 强转 | 使用 `{} as common.Context` 或 null 检查 + throw new Error |
|
|
503
|
+
| 类型推断失败 | 类型定义不明确 | 添加显式类型声明 `const result: number = ...` |
|
|
504
|
+
| 导入路径错误 | 库包名不正确 | 检查 `library/index.ets` 的导出路径 |
|
|
505
|
+
| 函数签名不匹配 | 参数类型/数量错误 | 检查接口规格文档中的函数签名 |
|
|
506
|
+
| 未找到模块 | 模块未安装 | 运行 `ohpm install` 安装依赖 |
|
|
507
|
+
| hilog 导入错误 | 使用 `import hilog from '@ohos.hilog'` | 改为 `import { hilog } from '@kit.PerformanceAnalysisKit'` |
|
|
508
|
+
| 断言方法不存在 | 使用 Jest 风格如 toBe/toThrow | 改用 hypium 断言:assertEqual/assertNull/assertTrue/assertFalse/assertLarger/assertContain |
|
|
509
|
+
| `Cannot find name 'assertTrue'`(批量) | 生成了 `assertTrue(x)`/`assertEqual(a,b)` 裸函数调用而非 `expect(x).assertXxx()` 链式调用(hypium 断言只存在于 expect 对象上) | 脚本批量转换(括号配平、顶层逗号切分双参断言、单参直接包裹);生成前 prompt 给断言正反例预防 |
|
|
510
|
+
| 接口赋值类型不兼容 | `The types returned by 'getX()' are incompatible` + `is missing the following properties from type` —— 库接口方法返回类型声明与实现类不一致(Demo 不暴露,测试首次触达才显现) | 修接口声明对齐实现类实际返回类型(如 `Array<>` 改实际容器类型,属源库机械性修正 ⚠️),禁止在测试中强转绕过 |
|
|
511
|
+
| `Argument of type 'null' is not assignable to parameter of type 'string'` | 测试代码向库 API 传 null 实参(库源码 `@ts-nocheck` 不豁免测试文件的严格检查) | 库内部用 `if (x)` 判空时空串/空数组与 null 语义等价,改传等价 falsy 值(如 `new ID3v1Tag('')`)覆盖同一守卫路径并注释等价依据 |
|
|
512
|
+
| instanceof 异常类型断言失效/异常类未导出 | 自定义异常类未从 `library/index.ets` 导出,无法 import | 深层路径导入(如 `@ohos/mp3agic/src/main/ets/components/mp3agic/NoSuchTagException`),import 真实类后做 `e instanceof XxxException` |
|
|
513
|
+
| 文件路径不可写 | 硬编码 `/data/local/tmp/` 等 | 通过 abilityDelegatorRegistry 获取沙箱 tempDir/filesDir |
|
|
514
|
+
| 不安全转型 | `arkts-no-unsafe-cast` | 正确定义类型,避免双重 `as unknown as` |
|
|
515
|
+
| 缺少权限 | — | 在 ohosTest 的 module.json5 中声明 |
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
519
|
> 编译验证与运行验证的完整流程(迁移 → Linter → 编译修复循环)参见 [BUILD_VERIFICATION.md](BUILD_VERIFICATION.md);分批生成时注入 subagent 的规则速查已内置于 [SUBAGENT_PROMPT_TEMPLATE.md](SUBAGENT_PROMPT_TEMPLATE.md),无需单独抄录。
|