universal-dev-standards 6.13.1 → 6.14.0-beta.10
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 +13 -3
- package/bin/uds.js +75 -3
- package/bundled/ai/options/code-review/pr-review.ai.yaml +20 -1
- package/bundled/ai/options/commit-message/traditional-chinese.ai.yaml +69 -67
- package/bundled/ai/standards/ai-response-navigation.ai.yaml +43 -3
- package/bundled/ai/standards/checkin-standards.ai.yaml +25 -6
- package/bundled/ai/standards/code-review.ai.yaml +15 -2
- package/bundled/ai/standards/commit-message.ai.yaml +18 -4
- package/bundled/ai/standards/developer-memory.ai.yaml +12 -2
- package/bundled/ai/standards/full-coverage-testing.ai.yaml +86 -7
- package/bundled/ai/standards/open-work-tracking.ai.yaml +254 -4
- package/bundled/ai/standards/pipeline-security-gates.ai.yaml +53 -4
- package/bundled/ai/standards/project-context-memory.ai.yaml +12 -2
- package/bundled/ai/standards/turn-completion-integrity.ai.yaml +14 -7
- package/bundled/core/ai-response-navigation.md +128 -12
- package/bundled/core/code-review-checklist.md +20 -2
- package/bundled/core/commit-message-guide.md +22 -19
- package/bundled/core/developer-memory.md +12 -2
- package/bundled/core/full-coverage-testing.md +99 -5
- package/bundled/core/open-work-tracking.md +251 -8
- package/bundled/core/pipeline-security-gates.md +63 -0
- package/bundled/core/project-context-memory.md +10 -2
- package/bundled/core/turn-completion-integrity.md +58 -11
- package/bundled/extensions/frameworks/fat-free-patterns.md +937 -0
- package/bundled/extensions/languages/csharp-style.md +464 -0
- package/bundled/extensions/languages/php-style.md +700 -0
- package/bundled/extensions/locales/zh-cn.md +717 -0
- package/bundled/extensions/locales/zh-tw.md +717 -0
- package/bundled/hooks/check-turn-completion-agy.mjs +147 -0
- package/bundled/hooks/turn-completion/locales/en.mjs +54 -5
- package/bundled/hooks/turn-completion/locales/zh-TW.mjs +37 -6
- package/bundled/locales/COVERAGE.md +5 -4
- package/bundled/locales/zh-CN/CHANGELOG.md +211 -3
- package/bundled/locales/zh-CN/README.md +3 -3
- package/bundled/locales/zh-CN/SECURITY.md +3 -1
- package/bundled/locales/zh-CN/STANDARDS-MAPPING.md +103 -6
- package/bundled/locales/zh-CN/adoption/ADOPTION-GUIDE.md +81 -101
- package/bundled/locales/zh-CN/adoption/DAILY-WORKFLOW-GUIDE.md +2 -1
- package/bundled/locales/zh-CN/adoption/STATIC-DYNAMIC-GUIDE.md +14 -9
- package/bundled/locales/zh-CN/adoption/checklists/enterprise.md +88 -81
- package/bundled/locales/zh-CN/adoption/checklists/minimal.md +31 -17
- package/bundled/locales/zh-CN/adoption/checklists/recommended.md +56 -47
- package/bundled/locales/zh-CN/ai/MAINTENANCE.md +44 -9
- package/bundled/locales/zh-CN/ai/options/commit-message/traditional-chinese.ai.yaml +63 -55
- package/bundled/locales/zh-CN/core/acceptance-criteria-traceability.md +61 -14
- package/bundled/locales/zh-CN/core/acceptance-test-driven-development.md +2 -1
- package/bundled/locales/zh-CN/core/adr-standards.md +155 -32
- package/bundled/locales/zh-CN/core/agent-communication-protocol.md +2 -1
- package/bundled/locales/zh-CN/core/agent-dispatch.md +68 -33
- package/bundled/locales/zh-CN/core/ai-agreement-standards.md +23 -22
- package/bundled/locales/zh-CN/core/ai-command-behavior.md +2 -1
- package/bundled/locales/zh-CN/core/ai-instruction-standards.md +71 -49
- package/bundled/locales/zh-CN/core/ai-response-navigation.md +111 -12
- package/bundled/locales/zh-CN/core/anti-sycophancy-prompting.md +34 -33
- package/bundled/locales/zh-CN/core/api-design-standards.md +144 -58
- package/bundled/locales/zh-CN/core/behavior-driven-development.md +2 -1
- package/bundled/locales/zh-CN/core/branch-completion.md +75 -20
- package/bundled/locales/zh-CN/core/capability-declaration.md +44 -94
- package/bundled/locales/zh-CN/core/change-batching-standards.md +2 -1
- package/bundled/locales/zh-CN/core/checkin-standards.md +176 -116
- package/bundled/locales/zh-CN/core/circuit-breaker.md +43 -77
- package/bundled/locales/zh-CN/core/code-review-checklist.md +54 -23
- package/bundled/locales/zh-CN/core/context-aware-loading.md +103 -29
- package/bundled/locales/zh-CN/core/database-standards.md +115 -114
- package/bundled/locales/zh-CN/core/developer-memory.md +159 -60
- package/bundled/locales/zh-CN/core/documentation-lifecycle.md +20 -16
- package/bundled/locales/zh-CN/core/dual-phase-output.md +37 -70
- package/bundled/locales/zh-CN/core/execution-history.md +2 -1
- package/bundled/locales/zh-CN/core/failure-source-taxonomy.md +71 -84
- package/bundled/locales/zh-CN/core/full-coverage-testing.md +103 -9
- package/bundled/locales/zh-CN/core/git-workflow.md +148 -262
- package/bundled/locales/zh-CN/core/git-worktree.md +59 -26
- package/bundled/locales/zh-CN/core/guides/file-placement-guide.md +132 -48
- package/bundled/locales/zh-CN/core/guides/performance-guide.md +61 -59
- package/bundled/locales/zh-CN/core/guides/security-guide.md +2 -0
- package/bundled/locales/zh-CN/core/health-check-standards.md +46 -104
- package/bundled/locales/zh-CN/core/immutability-first.md +83 -60
- package/bundled/locales/zh-CN/core/knowledge-transfer-standards.md +94 -31
- package/bundled/locales/zh-CN/core/pipeline-integration-standards.md +2 -1
- package/bundled/locales/zh-CN/core/pipeline-security-gates.md +64 -4
- package/bundled/locales/zh-CN/core/project-context-memory.md +5 -0
- package/bundled/locales/zh-CN/core/recovery-recipe-registry.md +54 -114
- package/bundled/locales/zh-CN/core/refactoring-standards.md +141 -556
- package/bundled/locales/zh-CN/core/requirement-engineering.md +7 -6
- package/bundled/locales/zh-CN/core/retry-standards.md +46 -101
- package/bundled/locales/zh-CN/core/security-decision.md +45 -70
- package/bundled/locales/zh-CN/core/skill-standard-alignment-check.md +105 -71
- package/bundled/locales/zh-CN/core/standard-admission-criteria.md +25 -31
- package/bundled/locales/zh-CN/core/standard-lifecycle-management.md +49 -57
- package/bundled/locales/zh-CN/core/structured-task-definition.md +2 -1
- package/bundled/locales/zh-CN/core/systematic-debugging.md +87 -42
- package/bundled/locales/zh-CN/core/test-completeness-dimensions.md +262 -190
- package/bundled/locales/zh-CN/core/test-driven-development.md +21 -1022
- package/bundled/locales/zh-CN/core/test-governance.md +94 -43
- package/bundled/locales/zh-CN/core/testing-standards.md +83 -37
- package/bundled/locales/zh-CN/core/timeout-standards.md +45 -85
- package/bundled/locales/zh-CN/core/token-budget.md +44 -80
- package/bundled/locales/zh-CN/core/translation-lifecycle-standards.md +48 -36
- package/bundled/locales/zh-CN/core/turn-completion-integrity.md +46 -13
- package/bundled/locales/zh-CN/core/verification-evidence.md +44 -22
- package/bundled/locales/zh-CN/core/virtual-organization-standards.md +30 -29
- package/bundled/locales/zh-CN/core/workflow-enforcement.md +9 -8
- package/bundled/locales/zh-CN/core/workflow-state-protocol.md +9 -8
- package/bundled/locales/zh-CN/docs/AVAILABLE-STANDARDS.md +70 -0
- package/bundled/locales/zh-CN/docs/CHEATSHEET.md +11 -2
- package/bundled/locales/zh-CN/docs/CLI-FLOW.md +2 -1
- package/bundled/locales/zh-CN/docs/CLI-INIT-OPTIONS.md +76 -40
- package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +32 -15
- package/bundled/locales/zh-CN/docs/STANDARDS-REFERENCE.md +2 -1
- package/bundled/locales/zh-CN/docs/USAGE-MODES-COMPARISON.md +139 -138
- package/bundled/locales/zh-CN/docs/USER-MANUAL.md +11 -3
- package/bundled/locales/zh-CN/docs/WINDOWS-GUIDE.md +12 -3
- package/bundled/locales/zh-CN/docs/specs/system/memory-adoption-strategy.md +2 -0
- package/bundled/locales/zh-CN/docs/user/FAQ.md +2 -0
- package/bundled/locales/zh-CN/docs/user/GETTING-STARTED.md +46 -0
- package/bundled/locales/zh-CN/docs/user/GLOSSARY.md +2 -0
- package/bundled/locales/zh-CN/docs/user/README.md +4 -2
- package/bundled/locales/zh-CN/docs/user/TROUBLESHOOTING.md +2 -0
- package/bundled/locales/zh-CN/integrations/codex/AGENTS.md +136 -2
- package/bundled/locales/zh-CN/integrations/codex/README.md +62 -10
- package/bundled/locales/zh-CN/integrations/gemini-cli/GEMINI.md +59 -1
- package/bundled/locales/zh-CN/integrations/gemini-cli/README.md +9 -2
- package/bundled/locales/zh-CN/integrations/github-copilot/COPILOT-CHAT-REFERENCE.md +7 -1
- package/bundled/locales/zh-CN/integrations/github-copilot/README.md +8 -2
- package/bundled/locales/zh-CN/integrations/github-copilot/copilot-instructions.md +146 -12
- package/bundled/locales/zh-CN/integrations/github-copilot/skills-mapping.md +7 -1
- package/bundled/locales/zh-CN/integrations/google-antigravity/AGENTS.md +110 -3
- package/bundled/locales/zh-CN/integrations/google-antigravity/README.md +7 -1
- package/bundled/locales/zh-CN/integrations/opencode/AGENTS.md +140 -2
- package/bundled/locales/zh-CN/integrations/opencode/README.md +7 -1
- package/bundled/locales/zh-CN/integrations/opencode/skills-mapping.md +8 -2
- package/bundled/locales/zh-CN/integrations/openspec/AGENTS.md +46 -1
- package/bundled/locales/zh-CN/integrations/openspec/README.md +7 -1
- package/bundled/locales/zh-CN/integrations/spec-kit/AGENTS.md +20 -2
- package/bundled/locales/zh-CN/integrations/spec-kit/README.md +7 -1
- package/bundled/locales/zh-CN/options/changelog/auto-generated.md +2 -0
- package/bundled/locales/zh-CN/options/changelog/keep-a-changelog.md +2 -0
- package/bundled/locales/zh-CN/options/code-review/automated-review.md +2 -0
- package/bundled/locales/zh-CN/options/code-review/pair-programming.md +2 -0
- package/bundled/locales/zh-CN/options/code-review/pr-review.md +13 -2
- package/bundled/locales/zh-CN/options/commit-message/bilingual.md +139 -50
- package/bundled/locales/zh-CN/options/commit-message/english.md +159 -42
- package/bundled/locales/zh-CN/options/commit-message/traditional-chinese.md +156 -75
- package/bundled/locales/zh-CN/options/documentation/api-docs.md +3 -1
- package/bundled/locales/zh-CN/options/documentation/markdown-docs.md +2 -0
- package/bundled/locales/zh-CN/options/documentation/wiki-style.md +2 -0
- package/bundled/locales/zh-CN/options/git-workflow/gitflow.md +105 -77
- package/bundled/locales/zh-CN/options/git-workflow/github-flow.md +75 -57
- package/bundled/locales/zh-CN/options/git-workflow/merge-commit.md +155 -44
- package/bundled/locales/zh-CN/options/git-workflow/rebase-ff.md +168 -53
- package/bundled/locales/zh-CN/options/git-workflow/squash-merge.md +122 -37
- package/bundled/locales/zh-CN/options/git-workflow/trunk-based.md +108 -61
- package/bundled/locales/zh-CN/options/project-structure/dotnet.md +266 -47
- package/bundled/locales/zh-CN/options/project-structure/go.md +301 -43
- package/bundled/locales/zh-CN/options/project-structure/java.md +268 -48
- package/bundled/locales/zh-CN/options/project-structure/kotlin.md +2 -0
- package/bundled/locales/zh-CN/options/project-structure/nodejs.md +168 -51
- package/bundled/locales/zh-CN/options/project-structure/php.md +2 -0
- package/bundled/locales/zh-CN/options/project-structure/python.md +210 -52
- package/bundled/locales/zh-CN/options/project-structure/ruby.md +2 -0
- package/bundled/locales/zh-CN/options/project-structure/rust.md +2 -0
- package/bundled/locales/zh-CN/options/project-structure/swift.md +2 -0
- package/bundled/locales/zh-CN/options/testing/contract-testing.md +2 -0
- package/bundled/locales/zh-CN/options/testing/e2e-testing.md +227 -66
- package/bundled/locales/zh-CN/options/testing/industry-pyramid.md +2 -0
- package/bundled/locales/zh-CN/options/testing/integration-testing.md +185 -73
- package/bundled/locales/zh-CN/options/testing/istqb-framework.md +2 -0
- package/bundled/locales/zh-CN/options/testing/performance-testing.md +2 -0
- package/bundled/locales/zh-CN/options/testing/security-testing.md +2 -0
- package/bundled/locales/zh-CN/options/testing/system-testing.md +270 -96
- package/bundled/locales/zh-CN/options/testing/unit-testing.md +185 -71
- package/bundled/locales/zh-CN/skills/CONTRIBUTING.template.md +43 -42
- package/bundled/locales/zh-CN/skills/INTEGRATION-GUIDE.md +2 -1
- package/bundled/locales/zh-CN/skills/README.md +3 -1
- package/bundled/locales/zh-CN/skills/_shared/README.md +2 -1
- package/bundled/locales/zh-CN/skills/adr-assistant/guide.md +240 -4
- package/bundled/locales/zh-CN/skills/agents/README.md +180 -82
- package/bundled/locales/zh-CN/skills/agents/code-architect.md +3 -1
- package/bundled/locales/zh-CN/skills/agents/doc-writer.md +3 -1
- package/bundled/locales/zh-CN/skills/agents/reviewer.md +4 -2
- package/bundled/locales/zh-CN/skills/agents/spec-analyst.md +3 -1
- package/bundled/locales/zh-CN/skills/agents/test-specialist.md +3 -1
- package/bundled/locales/zh-CN/skills/ai-collaboration-standards/SKILL.md +91 -81
- package/bundled/locales/zh-CN/skills/ai-collaboration-standards/anti-hallucination.md +79 -59
- package/bundled/locales/zh-CN/skills/ai-collaboration-standards/certainty-labels.md +66 -40
- package/bundled/locales/zh-CN/skills/ai-friendly-architecture/SKILL.md +23 -36
- package/bundled/locales/zh-CN/skills/api-design-assistant/SKILL.md +13 -2
- package/bundled/locales/zh-CN/skills/atdd-assistant/SKILL.md +16 -2
- package/bundled/locales/zh-CN/skills/atdd-assistant/acceptance-criteria-guide.md +2 -1
- package/bundled/locales/zh-CN/skills/atdd-assistant/atdd-workflow.md +98 -1
- package/bundled/locales/zh-CN/skills/audit-assistant/SKILL.md +5 -2
- package/bundled/locales/zh-CN/skills/bdd-assistant/SKILL.md +16 -2
- package/bundled/locales/zh-CN/skills/bdd-assistant/bdd-workflow.md +2 -1
- package/bundled/locales/zh-CN/skills/bdd-assistant/gherkin-guide.md +2 -1
- package/bundled/locales/zh-CN/skills/changelog-guide/SKILL.md +9 -2
- package/bundled/locales/zh-CN/skills/checkin-assistant/SKILL.md +12 -2
- package/bundled/locales/zh-CN/skills/ci-cd-assistant/SKILL.md +14 -2
- package/bundled/locales/zh-CN/skills/code-review-assistant/SKILL.md +12 -2
- package/bundled/locales/zh-CN/skills/code-review-assistant/checkin-checklist.md +79 -78
- package/bundled/locales/zh-CN/skills/code-review-assistant/review-checklist.md +89 -88
- package/bundled/locales/zh-CN/skills/commands/ac-coverage.md +43 -1
- package/bundled/locales/zh-CN/skills/commands/api-design.md +2 -1
- package/bundled/locales/zh-CN/skills/commands/atdd.md +71 -1
- package/bundled/locales/zh-CN/skills/commands/audit.md +2 -1
- package/bundled/locales/zh-CN/skills/commands/bdd.md +160 -62
- package/bundled/locales/zh-CN/skills/commands/changelog.md +36 -1
- package/bundled/locales/zh-CN/skills/commands/check.md +53 -1
- package/bundled/locales/zh-CN/skills/commands/checkin.md +45 -1
- package/bundled/locales/zh-CN/skills/commands/ci-cd.md +3 -2
- package/bundled/locales/zh-CN/skills/commands/code-review.md +41 -1
- package/bundled/locales/zh-CN/skills/commands/commit.md +56 -1
- package/bundled/locales/zh-CN/skills/commands/config.md +50 -1
- package/bundled/locales/zh-CN/skills/commands/coverage.md +43 -1
- package/bundled/locales/zh-CN/skills/commands/database.md +4 -3
- package/bundled/locales/zh-CN/skills/commands/derive-all.md +42 -1
- package/bundled/locales/zh-CN/skills/commands/derive-atdd.md +35 -1
- package/bundled/locales/zh-CN/skills/commands/derive-bdd.md +41 -1
- package/bundled/locales/zh-CN/skills/commands/derive-tdd.md +42 -1
- package/bundled/locales/zh-CN/skills/commands/derive.md +60 -4
- package/bundled/locales/zh-CN/skills/commands/dev-workflow.md +58 -8
- package/bundled/locales/zh-CN/skills/commands/discover.md +41 -1
- package/bundled/locales/zh-CN/skills/commands/docgen.md +37 -1
- package/bundled/locales/zh-CN/skills/commands/docs.md +136 -5
- package/bundled/locales/zh-CN/skills/commands/durable.md +4 -3
- package/bundled/locales/zh-CN/skills/commands/e2e.md +85 -1
- package/bundled/locales/zh-CN/skills/commands/guide.md +2 -1
- package/bundled/locales/zh-CN/skills/commands/incident.md +5 -4
- package/bundled/locales/zh-CN/skills/commands/init.md +57 -1
- package/bundled/locales/zh-CN/skills/commands/methodology.md +166 -77
- package/bundled/locales/zh-CN/skills/commands/metrics.md +3 -2
- package/bundled/locales/zh-CN/skills/commands/migrate.md +5 -4
- package/bundled/locales/zh-CN/skills/commands/observability.md +48 -3
- package/bundled/locales/zh-CN/skills/commands/pr.md +4 -3
- package/bundled/locales/zh-CN/skills/commands/refactor.md +76 -38
- package/bundled/locales/zh-CN/skills/commands/release.md +82 -1
- package/bundled/locales/zh-CN/skills/commands/requirement.md +40 -1
- package/bundled/locales/zh-CN/skills/commands/reverse-bdd.md +36 -1
- package/bundled/locales/zh-CN/skills/commands/reverse-sdd.md +44 -1
- package/bundled/locales/zh-CN/skills/commands/reverse-tdd.md +42 -1
- package/bundled/locales/zh-CN/skills/commands/reverse.md +43 -1
- package/bundled/locales/zh-CN/skills/commands/runbook.md +50 -3
- package/bundled/locales/zh-CN/skills/commands/scan.md +3 -2
- package/bundled/locales/zh-CN/skills/commands/sdd-retro.md +50 -1
- package/bundled/locales/zh-CN/skills/commands/sdd.md +182 -1
- package/bundled/locales/zh-CN/skills/commands/security.md +3 -2
- package/bundled/locales/zh-CN/skills/commands/slo.md +51 -3
- package/bundled/locales/zh-CN/skills/commands/tdd.md +74 -5
- package/bundled/locales/zh-CN/skills/commands/update.md +70 -8
- package/bundled/locales/zh-CN/skills/commit-standards/SKILL.md +2 -2
- package/bundled/locales/zh-CN/skills/commit-standards/conventional-commits.md +45 -44
- package/bundled/locales/zh-CN/skills/commit-standards/language-options.md +50 -47
- package/bundled/locales/zh-CN/skills/comprehension-ladder/SKILL.md +289 -0
- package/bundled/locales/zh-CN/skills/comprehension-ladder/eval-cases.md +261 -0
- package/bundled/locales/zh-CN/skills/contract-test-assistant/guide.md +76 -1
- package/bundled/locales/zh-CN/skills/database-assistant/SKILL.md +18 -5
- package/bundled/locales/zh-CN/skills/dev-methodology/create-methodology.md +2 -0
- package/bundled/locales/zh-CN/skills/dev-methodology/runtime.md +2 -0
- package/bundled/locales/zh-CN/skills/docs-generator/SKILL.md +16 -2
- package/bundled/locales/zh-CN/skills/documentation-guide/SKILL.md +209 -184
- package/bundled/locales/zh-CN/skills/documentation-guide/documentation-structure.md +73 -72
- package/bundled/locales/zh-CN/skills/documentation-guide/readme-template.md +37 -36
- package/bundled/locales/zh-CN/skills/durable-execution-assistant/SKILL.md +28 -2
- package/bundled/locales/zh-CN/skills/e2e-assistant/SKILL.md +21 -6
- package/bundled/locales/zh-CN/skills/error-code-guide/SKILL.md +76 -95
- package/bundled/locales/zh-CN/skills/git-workflow-guide/SKILL.md +80 -87
- package/bundled/locales/zh-CN/skills/git-workflow-guide/branch-naming.md +44 -43
- package/bundled/locales/zh-CN/skills/git-workflow-guide/git-workflow.md +66 -65
- package/bundled/locales/zh-CN/skills/incident-response-assistant/SKILL.md +31 -13
- package/bundled/locales/zh-CN/skills/metrics-dashboard-assistant/SKILL.md +38 -2
- package/bundled/locales/zh-CN/skills/observability-assistant/SKILL.md +75 -1
- package/bundled/locales/zh-CN/skills/pr-automation-assistant/SKILL.md +32 -6
- package/bundled/locales/zh-CN/skills/project-discovery/SKILL.md +8 -2
- package/bundled/locales/zh-CN/skills/project-structure-guide/SKILL.md +49 -46
- package/bundled/locales/zh-CN/skills/project-structure-guide/language-patterns.md +8 -7
- package/bundled/locales/zh-CN/skills/refactoring-assistant/SKILL.md +22 -2
- package/bundled/locales/zh-CN/skills/release-standards/SKILL.md +66 -23
- package/bundled/locales/zh-CN/skills/release-standards/changelog-format.md +42 -41
- package/bundled/locales/zh-CN/skills/release-standards/release-workflow.md +131 -95
- package/bundled/locales/zh-CN/skills/release-standards/semantic-versioning.md +62 -61
- package/bundled/locales/zh-CN/skills/requirement-assistant/SKILL.md +24 -15
- package/bundled/locales/zh-CN/skills/requirement-assistant/requirement-checklist.md +128 -127
- package/bundled/locales/zh-CN/skills/requirement-assistant/requirement-writing.md +121 -120
- package/bundled/locales/zh-CN/skills/retrospective-assistant/guide.md +206 -2
- package/bundled/locales/zh-CN/skills/reverse-engineer/bdd-extraction.md +2 -1
- package/bundled/locales/zh-CN/skills/reverse-engineer/tdd-analysis.md +2 -1
- package/bundled/locales/zh-CN/skills/reverse-engineer/workflow.md +2 -1
- package/bundled/locales/zh-CN/skills/runbook-assistant/SKILL.md +9 -2
- package/bundled/locales/zh-CN/skills/security-assistant/SKILL.md +24 -6
- package/bundled/locales/zh-CN/skills/security-scan-assistant/SKILL.md +34 -10
- package/bundled/locales/zh-CN/skills/slo-assistant/SKILL.md +2 -1
- package/bundled/locales/zh-CN/skills/spec-driven-dev/guide.md +38 -6
- package/bundled/locales/zh-CN/skills/tdd-assistant/SKILL.md +16 -3
- package/bundled/locales/zh-CN/skills/tdd-assistant/language-examples.md +727 -82
- package/bundled/locales/zh-CN/skills/tdd-assistant/tdd-workflow.md +396 -214
- package/bundled/locales/zh-CN/skills/test-coverage-assistant/SKILL.md +14 -5
- package/bundled/locales/zh-CN/skills/testing-guide/testing-pyramid.md +99 -98
- package/bundled/locales/zh-CN/skills/testing-guide/testing-theory.md +3 -1
- package/bundled/locales/zh-CN/skills/tools/cline/README.md +2 -1
- package/bundled/locales/zh-CN/skills/tools/copilot/README.md +65 -18
- package/bundled/locales/zh-CN/skills/tools/copilot/copilot-instructions.md +2 -1
- package/bundled/locales/zh-CN/skills/tools/cursor/README.md +2 -1
- package/bundled/locales/zh-CN/skills/tools/windsurf/README.md +2 -1
- package/bundled/locales/zh-CN/skills/workflows/README.md +4 -2
- package/bundled/locales/zh-CN/templates/reverse-spec-template.md +50 -1
- package/bundled/locales/zh-TW/CHANGELOG.md +211 -3
- package/bundled/locales/zh-TW/README.md +3 -3
- package/bundled/locales/zh-TW/SECURITY.md +3 -1
- package/bundled/locales/zh-TW/STANDARDS-MAPPING.md +103 -6
- package/bundled/locales/zh-TW/adoption/ADOPTION-GUIDE.md +59 -97
- package/bundled/locales/zh-TW/adoption/DAILY-WORKFLOW-GUIDE.md +2 -1
- package/bundled/locales/zh-TW/adoption/STATIC-DYNAMIC-GUIDE.md +10 -2
- package/bundled/locales/zh-TW/adoption/checklists/enterprise.md +17 -10
- package/bundled/locales/zh-TW/adoption/checklists/minimal.md +19 -5
- package/bundled/locales/zh-TW/adoption/checklists/recommended.md +14 -5
- package/bundled/locales/zh-TW/ai/MAINTENANCE.md +34 -14
- package/bundled/locales/zh-TW/ai/options/commit-message/traditional-chinese.ai.yaml +48 -40
- package/bundled/locales/zh-TW/core/acceptance-criteria-traceability.md +56 -10
- package/bundled/locales/zh-TW/core/acceptance-test-driven-development.md +2 -1
- package/bundled/locales/zh-TW/core/adr-standards.md +2 -1
- package/bundled/locales/zh-TW/core/agent-communication-protocol.md +2 -1
- package/bundled/locales/zh-TW/core/ai-command-behavior.md +2 -1
- package/bundled/locales/zh-TW/core/ai-instruction-standards.md +16 -13
- package/bundled/locales/zh-TW/core/ai-response-navigation.md +111 -13
- package/bundled/locales/zh-TW/core/anti-sycophancy-prompting.md +2 -1
- package/bundled/locales/zh-TW/core/api-design-standards.md +2 -1
- package/bundled/locales/zh-TW/core/behavior-driven-development.md +3 -17
- package/bundled/locales/zh-TW/core/capability-declaration.md +41 -79
- package/bundled/locales/zh-TW/core/change-batching-standards.md +2 -1
- package/bundled/locales/zh-TW/core/changelog-standards.md +14 -9
- package/bundled/locales/zh-TW/core/checkin-standards.md +84 -26
- package/bundled/locales/zh-TW/core/circuit-breaker.md +48 -87
- package/bundled/locales/zh-TW/core/code-review-checklist.md +36 -7
- package/bundled/locales/zh-TW/core/commit-message-guide.md +218 -87
- package/bundled/locales/zh-TW/core/database-standards.md +2 -1
- package/bundled/locales/zh-TW/core/developer-memory.md +111 -12
- package/bundled/locales/zh-TW/core/documentation-lifecycle.md +2 -1
- package/bundled/locales/zh-TW/core/documentation-structure.md +17 -8
- package/bundled/locales/zh-TW/core/dual-phase-output.md +28 -90
- package/bundled/locales/zh-TW/core/error-code-standards.md +17 -6
- package/bundled/locales/zh-TW/core/execution-history.md +2 -1
- package/bundled/locales/zh-TW/core/failure-source-taxonomy.md +59 -117
- package/bundled/locales/zh-TW/core/frontend-design-standards.md +120 -8
- package/bundled/locales/zh-TW/core/full-coverage-testing.md +103 -9
- package/bundled/locales/zh-TW/core/git-workflow.md +197 -37
- package/bundled/locales/zh-TW/core/git-worktree.md +79 -49
- package/bundled/locales/zh-TW/core/guides/file-placement-guide.md +86 -2
- package/bundled/locales/zh-TW/core/guides/performance-guide.md +2 -0
- package/bundled/locales/zh-TW/core/guides/security-guide.md +2 -0
- package/bundled/locales/zh-TW/core/health-check-standards.md +46 -104
- package/bundled/locales/zh-TW/core/immutability-first.md +45 -85
- package/bundled/locales/zh-TW/core/knowledge-graph-memory.md +2 -1
- package/bundled/locales/zh-TW/core/knowledge-transfer-standards.md +103 -40
- package/bundled/locales/zh-TW/core/open-work-tracking.md +164 -9
- package/bundled/locales/zh-TW/core/pipeline-integration-standards.md +2 -1
- package/bundled/locales/zh-TW/core/pipeline-security-gates.md +64 -4
- package/bundled/locales/zh-TW/core/privacy-standards.md +153 -46
- package/bundled/locales/zh-TW/core/project-context-memory.md +215 -31
- package/bundled/locales/zh-TW/core/project-structure.md +240 -19
- package/bundled/locales/zh-TW/core/recovery-recipe-registry.md +54 -114
- package/bundled/locales/zh-TW/core/refactoring-standards.md +153 -48
- package/bundled/locales/zh-TW/core/requirement-engineering.md +8 -37
- package/bundled/locales/zh-TW/core/retrospective-standards.md +127 -7
- package/bundled/locales/zh-TW/core/retry-standards.md +41 -105
- package/bundled/locales/zh-TW/core/reverse-engineering-standards.md +5 -1
- package/bundled/locales/zh-TW/core/security-decision.md +43 -84
- package/bundled/locales/zh-TW/core/security-standards.md +204 -25
- package/bundled/locales/zh-TW/core/self-review-protocol.md +2 -1
- package/bundled/locales/zh-TW/core/skill-standard-alignment-check.md +103 -69
- package/bundled/locales/zh-TW/core/standard-admission-criteria.md +22 -28
- package/bundled/locales/zh-TW/core/standard-lifecycle-management.md +40 -48
- package/bundled/locales/zh-TW/core/structured-task-definition.md +2 -1
- package/bundled/locales/zh-TW/core/supply-chain-security-standards.md +137 -10
- package/bundled/locales/zh-TW/core/systematic-debugging.md +94 -38
- package/bundled/locales/zh-TW/core/tech-debt-standards.md +170 -54
- package/bundled/locales/zh-TW/core/test-completeness-dimensions.md +101 -12
- package/bundled/locales/zh-TW/core/test-data-standards.md +245 -23
- package/bundled/locales/zh-TW/core/test-driven-development.md +4 -1
- package/bundled/locales/zh-TW/core/test-governance.md +92 -32
- package/bundled/locales/zh-TW/core/testing-standards.md +61 -14
- package/bundled/locales/zh-TW/core/timeout-standards.md +45 -85
- package/bundled/locales/zh-TW/core/token-budget.md +41 -112
- package/bundled/locales/zh-TW/core/translation-lifecycle-standards.md +28 -16
- package/bundled/locales/zh-TW/core/turn-completion-integrity.md +46 -13
- package/bundled/locales/zh-TW/core/verification-evidence.md +2 -1
- package/bundled/locales/zh-TW/core/versioning.md +6 -2
- package/bundled/locales/zh-TW/core/virtual-organization-standards.md +42 -36
- package/bundled/locales/zh-TW/core/workflow-enforcement.md +2 -1
- package/bundled/locales/zh-TW/core/workflow-state-protocol.md +2 -1
- package/bundled/locales/zh-TW/docs/AVAILABLE-STANDARDS.md +70 -0
- package/bundled/locales/zh-TW/docs/CHEATSHEET.md +11 -2
- package/bundled/locales/zh-TW/docs/CLI-FLOW.md +2 -1
- package/bundled/locales/zh-TW/docs/CLI-INIT-OPTIONS.md +69 -33
- package/bundled/locales/zh-TW/docs/DEV-WORKFLOW-MAPPING.md +2 -1
- package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +32 -15
- package/bundled/locales/zh-TW/docs/STANDARDS-REFERENCE.md +2 -1
- package/bundled/locales/zh-TW/docs/USAGE-MODES-COMPARISON.md +8 -7
- package/bundled/locales/zh-TW/docs/USER-MANUAL.md +9 -1
- package/bundled/locales/zh-TW/docs/WINDOWS-GUIDE.md +11 -2
- package/bundled/locales/zh-TW/docs/specs/system/memory-adoption-strategy.md +2 -0
- package/bundled/locales/zh-TW/docs/user/FAQ.md +2 -0
- package/bundled/locales/zh-TW/docs/user/GETTING-STARTED.md +46 -0
- package/bundled/locales/zh-TW/docs/user/GLOSSARY.md +2 -0
- package/bundled/locales/zh-TW/docs/user/README.md +2 -0
- package/bundled/locales/zh-TW/docs/user/TROUBLESHOOTING.md +2 -0
- package/bundled/locales/zh-TW/integrations/claude-code/README.md +2 -1
- package/bundled/locales/zh-TW/integrations/codex/AGENTS.md +136 -2
- package/bundled/locales/zh-TW/integrations/codex/README.md +7 -1
- package/bundled/locales/zh-TW/integrations/gemini-cli/GEMINI.md +59 -1
- package/bundled/locales/zh-TW/integrations/gemini-cli/README.md +8 -1
- package/bundled/locales/zh-TW/integrations/github-copilot/COPILOT-CHAT-REFERENCE.md +7 -1
- package/bundled/locales/zh-TW/integrations/github-copilot/README.md +9 -3
- package/bundled/locales/zh-TW/integrations/github-copilot/copilot-instructions.md +146 -12
- package/bundled/locales/zh-TW/integrations/github-copilot/skills-mapping.md +7 -1
- package/bundled/locales/zh-TW/integrations/google-antigravity/AGENTS.md +110 -3
- package/bundled/locales/zh-TW/integrations/google-antigravity/README.md +7 -1
- package/bundled/locales/zh-TW/integrations/opencode/AGENTS.md +140 -2
- package/bundled/locales/zh-TW/integrations/opencode/README.md +7 -1
- package/bundled/locales/zh-TW/integrations/opencode/skills-mapping.md +8 -2
- package/bundled/locales/zh-TW/integrations/openspec/AGENTS.md +46 -1
- package/bundled/locales/zh-TW/integrations/openspec/README.md +7 -1
- package/bundled/locales/zh-TW/integrations/spec-kit/AGENTS.md +20 -2
- package/bundled/locales/zh-TW/integrations/spec-kit/README.md +7 -1
- package/bundled/locales/zh-TW/options/changelog/auto-generated.md +2 -0
- package/bundled/locales/zh-TW/options/changelog/keep-a-changelog.md +2 -0
- package/bundled/locales/zh-TW/options/code-review/automated-review.md +2 -0
- package/bundled/locales/zh-TW/options/code-review/pair-programming.md +2 -0
- package/bundled/locales/zh-TW/options/code-review/pr-review.md +13 -2
- package/bundled/locales/zh-TW/options/commit-message/bilingual.md +93 -5
- package/bundled/locales/zh-TW/options/commit-message/english.md +118 -1
- package/bundled/locales/zh-TW/options/commit-message/traditional-chinese.md +82 -1
- package/bundled/locales/zh-TW/options/documentation/api-docs.md +2 -0
- package/bundled/locales/zh-TW/options/documentation/markdown-docs.md +2 -0
- package/bundled/locales/zh-TW/options/documentation/wiki-style.md +2 -0
- package/bundled/locales/zh-TW/options/git-workflow/gitflow.md +99 -71
- package/bundled/locales/zh-TW/options/git-workflow/github-flow.md +68 -50
- package/bundled/locales/zh-TW/options/git-workflow/merge-commit.md +131 -20
- package/bundled/locales/zh-TW/options/git-workflow/rebase-ff.md +142 -27
- package/bundled/locales/zh-TW/options/git-workflow/squash-merge.md +100 -15
- package/bundled/locales/zh-TW/options/git-workflow/trunk-based.md +103 -56
- package/bundled/locales/zh-TW/options/project-structure/dotnet.md +233 -14
- package/bundled/locales/zh-TW/options/project-structure/go.md +270 -12
- package/bundled/locales/zh-TW/options/project-structure/java.md +235 -15
- package/bundled/locales/zh-TW/options/project-structure/kotlin.md +2 -0
- package/bundled/locales/zh-TW/options/project-structure/nodejs.md +136 -19
- package/bundled/locales/zh-TW/options/project-structure/php.md +2 -0
- package/bundled/locales/zh-TW/options/project-structure/python.md +177 -19
- package/bundled/locales/zh-TW/options/project-structure/ruby.md +2 -0
- package/bundled/locales/zh-TW/options/project-structure/rust.md +2 -0
- package/bundled/locales/zh-TW/options/project-structure/swift.md +2 -0
- package/bundled/locales/zh-TW/options/testing/contract-testing.md +2 -0
- package/bundled/locales/zh-TW/options/testing/e2e-testing.md +182 -21
- package/bundled/locales/zh-TW/options/testing/industry-pyramid.md +2 -0
- package/bundled/locales/zh-TW/options/testing/integration-testing.md +134 -22
- package/bundled/locales/zh-TW/options/testing/istqb-framework.md +2 -0
- package/bundled/locales/zh-TW/options/testing/performance-testing.md +2 -0
- package/bundled/locales/zh-TW/options/testing/security-testing.md +2 -0
- package/bundled/locales/zh-TW/options/testing/system-testing.md +175 -1
- package/bundled/locales/zh-TW/options/testing/unit-testing.md +123 -9
- package/bundled/locales/zh-TW/skills/CONTRIBUTING.template.md +3 -2
- package/bundled/locales/zh-TW/skills/INTEGRATION-GUIDE.md +2 -1
- package/bundled/locales/zh-TW/skills/README.md +3 -1
- package/bundled/locales/zh-TW/skills/_shared/README.md +2 -1
- package/bundled/locales/zh-TW/skills/ac-coverage/SKILL.md +15 -4
- package/bundled/locales/zh-TW/skills/adr-assistant/guide.md +123 -3
- package/bundled/locales/zh-TW/skills/agents/README.md +99 -1
- package/bundled/locales/zh-TW/skills/agents/code-architect.md +2 -0
- package/bundled/locales/zh-TW/skills/agents/doc-writer.md +2 -0
- package/bundled/locales/zh-TW/skills/agents/reviewer.md +3 -1
- package/bundled/locales/zh-TW/skills/agents/spec-analyst.md +2 -0
- package/bundled/locales/zh-TW/skills/agents/test-specialist.md +2 -0
- package/bundled/locales/zh-TW/skills/ai-collaboration-standards/SKILL.md +48 -37
- package/bundled/locales/zh-TW/skills/ai-collaboration-standards/anti-hallucination.md +22 -2
- package/bundled/locales/zh-TW/skills/ai-collaboration-standards/certainty-labels.md +29 -3
- package/bundled/locales/zh-TW/skills/ai-friendly-architecture/SKILL.md +23 -36
- package/bundled/locales/zh-TW/skills/ai-instruction-standards/SKILL.md +12 -36
- package/bundled/locales/zh-TW/skills/api-design-assistant/SKILL.md +21 -5
- package/bundled/locales/zh-TW/skills/atdd-assistant/SKILL.md +40 -15
- package/bundled/locales/zh-TW/skills/atdd-assistant/acceptance-criteria-guide.md +2 -1
- package/bundled/locales/zh-TW/skills/atdd-assistant/atdd-workflow.md +98 -1
- package/bundled/locales/zh-TW/skills/atdd-assistant/guide.md +24 -8
- package/bundled/locales/zh-TW/skills/audit-assistant/SKILL.md +8 -2
- package/bundled/locales/zh-TW/skills/bdd-assistant/SKILL.md +29 -6
- package/bundled/locales/zh-TW/skills/bdd-assistant/bdd-workflow.md +2 -1
- package/bundled/locales/zh-TW/skills/bdd-assistant/gherkin-guide.md +2 -1
- package/bundled/locales/zh-TW/skills/bdd-assistant/guide.md +9 -8
- package/bundled/locales/zh-TW/skills/changelog-guide/SKILL.md +12 -3
- package/bundled/locales/zh-TW/skills/changelog-guide/guide.md +11 -7
- package/bundled/locales/zh-TW/skills/checkin-assistant/SKILL.md +19 -3
- package/bundled/locales/zh-TW/skills/checkin-assistant/guide.md +5 -3
- package/bundled/locales/zh-TW/skills/ci-cd-assistant/SKILL.md +35 -16
- package/bundled/locales/zh-TW/skills/code-review-assistant/SKILL.md +19 -2
- package/bundled/locales/zh-TW/skills/code-review-assistant/checkin-checklist.md +2 -1
- package/bundled/locales/zh-TW/skills/code-review-assistant/guide.md +81 -6
- package/bundled/locales/zh-TW/skills/code-review-assistant/review-checklist.md +2 -1
- package/bundled/locales/zh-TW/skills/commands/ac-coverage.md +47 -2
- package/bundled/locales/zh-TW/skills/commands/api-design.md +3 -2
- package/bundled/locales/zh-TW/skills/commands/atdd.md +80 -10
- package/bundled/locales/zh-TW/skills/commands/audit.md +3 -2
- package/bundled/locales/zh-TW/skills/commands/bdd.md +114 -16
- package/bundled/locales/zh-TW/skills/commands/changelog.md +45 -9
- package/bundled/locales/zh-TW/skills/commands/check.md +74 -21
- package/bundled/locales/zh-TW/skills/commands/checkin.md +56 -11
- package/bundled/locales/zh-TW/skills/commands/ci-cd.md +2 -1
- package/bundled/locales/zh-TW/skills/commands/code-review.md +43 -2
- package/bundled/locales/zh-TW/skills/commands/commit.md +58 -4
- package/bundled/locales/zh-TW/skills/commands/config.md +52 -4
- package/bundled/locales/zh-TW/skills/commands/coverage.md +45 -4
- package/bundled/locales/zh-TW/skills/commands/database.md +3 -2
- package/bundled/locales/zh-TW/skills/commands/derive-all.md +44 -2
- package/bundled/locales/zh-TW/skills/commands/derive-atdd.md +37 -2
- package/bundled/locales/zh-TW/skills/commands/derive-bdd.md +44 -3
- package/bundled/locales/zh-TW/skills/commands/derive-tdd.md +45 -3
- package/bundled/locales/zh-TW/skills/commands/derive.md +62 -5
- package/bundled/locales/zh-TW/skills/commands/dev-workflow.md +60 -9
- package/bundled/locales/zh-TW/skills/commands/discover.md +43 -2
- package/bundled/locales/zh-TW/skills/commands/docgen.md +39 -2
- package/bundled/locales/zh-TW/skills/commands/docs.md +139 -7
- package/bundled/locales/zh-TW/skills/commands/durable.md +3 -2
- package/bundled/locales/zh-TW/skills/commands/e2e.md +86 -3
- package/bundled/locales/zh-TW/skills/commands/guide.md +4 -2
- package/bundled/locales/zh-TW/skills/commands/incident.md +3 -2
- package/bundled/locales/zh-TW/skills/commands/init.md +72 -15
- package/bundled/locales/zh-TW/skills/commands/methodology.md +117 -28
- package/bundled/locales/zh-TW/skills/commands/metrics.md +2 -1
- package/bundled/locales/zh-TW/skills/commands/migrate.md +2 -1
- package/bundled/locales/zh-TW/skills/commands/observability.md +45 -2
- package/bundled/locales/zh-TW/skills/commands/pr.md +2 -1
- package/bundled/locales/zh-TW/skills/commands/refactor.md +54 -13
- package/bundled/locales/zh-TW/skills/commands/release.md +83 -2
- package/bundled/locales/zh-TW/skills/commands/requirement.md +41 -2
- package/bundled/locales/zh-TW/skills/commands/reverse-bdd.md +37 -2
- package/bundled/locales/zh-TW/skills/commands/reverse-sdd.md +45 -2
- package/bundled/locales/zh-TW/skills/commands/reverse-tdd.md +43 -2
- package/bundled/locales/zh-TW/skills/commands/reverse.md +44 -2
- package/bundled/locales/zh-TW/skills/commands/runbook.md +47 -2
- package/bundled/locales/zh-TW/skills/commands/scan.md +3 -2
- package/bundled/locales/zh-TW/skills/commands/sdd-retro.md +52 -3
- package/bundled/locales/zh-TW/skills/commands/sdd.md +209 -28
- package/bundled/locales/zh-TW/skills/commands/security.md +3 -2
- package/bundled/locales/zh-TW/skills/commands/slo.md +48 -2
- package/bundled/locales/zh-TW/skills/commands/tdd.md +71 -2
- package/bundled/locales/zh-TW/skills/commands/update.md +64 -2
- package/bundled/locales/zh-TW/skills/commit-standards/SKILL.md +2 -2
- package/bundled/locales/zh-TW/skills/commit-standards/conventional-commits.md +2 -1
- package/bundled/locales/zh-TW/skills/commit-standards/language-options.md +21 -18
- package/bundled/locales/zh-TW/skills/comprehension-ladder/SKILL.md +289 -0
- package/bundled/locales/zh-TW/skills/comprehension-ladder/eval-cases.md +261 -0
- package/bundled/locales/zh-TW/skills/contract-test-assistant/guide.md +81 -1
- package/bundled/locales/zh-TW/skills/database-assistant/SKILL.md +21 -5
- package/bundled/locales/zh-TW/skills/deploy-assistant/SKILL.md +2 -1
- package/bundled/locales/zh-TW/skills/dev-methodology/SKILL.md +4 -1
- package/bundled/locales/zh-TW/skills/dev-methodology/create-methodology.md +2 -0
- package/bundled/locales/zh-TW/skills/dev-methodology/runtime.md +2 -0
- package/bundled/locales/zh-TW/skills/docs-generator/SKILL.md +19 -2
- package/bundled/locales/zh-TW/skills/documentation-guide/SKILL.md +67 -42
- package/bundled/locales/zh-TW/skills/documentation-guide/documentation-structure.md +2 -1
- package/bundled/locales/zh-TW/skills/documentation-guide/readme-template.md +2 -1
- package/bundled/locales/zh-TW/skills/durable-execution-assistant/SKILL.md +32 -3
- package/bundled/locales/zh-TW/skills/e2e-assistant/SKILL.md +25 -7
- package/bundled/locales/zh-TW/skills/error-code-guide/SKILL.md +17 -34
- package/bundled/locales/zh-TW/skills/git-workflow-guide/SKILL.md +33 -38
- package/bundled/locales/zh-TW/skills/git-workflow-guide/branch-naming.md +2 -1
- package/bundled/locales/zh-TW/skills/git-workflow-guide/git-workflow.md +2 -1
- package/bundled/locales/zh-TW/skills/incident-response-assistant/SKILL.md +35 -14
- package/bundled/locales/zh-TW/skills/journey-test-assistant/SKILL.md +2 -14
- package/bundled/locales/zh-TW/skills/knowledge-graph/SKILL.md +6 -2
- package/bundled/locales/zh-TW/skills/metrics-dashboard-assistant/SKILL.md +42 -3
- package/bundled/locales/zh-TW/skills/pr-automation-assistant/SKILL.md +27 -3
- package/bundled/locales/zh-TW/skills/project-discovery/SKILL.md +11 -3
- package/bundled/locales/zh-TW/skills/project-discovery/guide.md +5 -3
- package/bundled/locales/zh-TW/skills/project-discovery/workflow.md +2 -1
- package/bundled/locales/zh-TW/skills/project-structure-guide/SKILL.md +19 -16
- package/bundled/locales/zh-TW/skills/project-structure-guide/language-patterns.md +2 -1
- package/bundled/locales/zh-TW/skills/refactoring-assistant/SKILL.md +26 -3
- package/bundled/locales/zh-TW/skills/refactoring-assistant/guide.md +4 -2
- package/bundled/locales/zh-TW/skills/release-standards/changelog-format.md +4 -3
- package/bundled/locales/zh-TW/skills/release-standards/guide.md +14 -5
- package/bundled/locales/zh-TW/skills/release-standards/release-workflow.md +5 -1
- package/bundled/locales/zh-TW/skills/release-standards/semantic-versioning.md +2 -1
- package/bundled/locales/zh-TW/skills/requirement-assistant/SKILL.md +15 -6
- package/bundled/locales/zh-TW/skills/requirement-assistant/guide.md +18 -8
- package/bundled/locales/zh-TW/skills/requirement-assistant/requirement-checklist.md +2 -1
- package/bundled/locales/zh-TW/skills/requirement-assistant/requirement-writing.md +2 -1
- package/bundled/locales/zh-TW/skills/retrospective-assistant/guide.md +200 -6
- package/bundled/locales/zh-TW/skills/reverse-engineer/bdd-extraction.md +2 -1
- package/bundled/locales/zh-TW/skills/reverse-engineer/guide.md +161 -36
- package/bundled/locales/zh-TW/skills/reverse-engineer/tdd-analysis.md +2 -1
- package/bundled/locales/zh-TW/skills/reverse-engineer/workflow.md +2 -1
- package/bundled/locales/zh-TW/skills/runbook-assistant/SKILL.md +9 -1
- package/bundled/locales/zh-TW/skills/security-assistant/SKILL.md +25 -5
- package/bundled/locales/zh-TW/skills/security-scan-assistant/SKILL.md +34 -8
- package/bundled/locales/zh-TW/skills/skill-builder/SKILL.md +3 -21
- package/bundled/locales/zh-TW/skills/slo-assistant/SKILL.md +3 -1
- package/bundled/locales/zh-TW/skills/spec-derivation/SKILL.md +2 -1
- package/bundled/locales/zh-TW/skills/spec-driven-dev/guide.md +35 -2
- package/bundled/locales/zh-TW/skills/sweep/SKILL.md +2 -1
- package/bundled/locales/zh-TW/skills/tdd-assistant/SKILL.md +10 -2
- package/bundled/locales/zh-TW/skills/tdd-assistant/guide.md +68 -9
- package/bundled/locales/zh-TW/skills/tdd-assistant/tdd-workflow.md +183 -1
- package/bundled/locales/zh-TW/skills/test-coverage-assistant/SKILL.md +15 -5
- package/bundled/locales/zh-TW/skills/test-coverage-assistant/guide.md +26 -13
- package/bundled/locales/zh-TW/skills/testing-guide/testing-pyramid.md +2 -1
- package/bundled/locales/zh-TW/skills/testing-guide/testing-theory.md +3 -1
- package/bundled/locales/zh-TW/skills/tools/cline/README.md +2 -1
- package/bundled/locales/zh-TW/skills/tools/copilot/README.md +65 -18
- package/bundled/locales/zh-TW/skills/tools/copilot/copilot-instructions.md +2 -1
- package/bundled/locales/zh-TW/skills/tools/cursor/README.md +2 -1
- package/bundled/locales/zh-TW/skills/tools/windsurf/README.md +2 -1
- package/bundled/locales/zh-TW/skills/workflows/README.md +11 -9
- package/bundled/locales/zh-TW/templates/reverse-spec-template.md +50 -1
- package/bundled/skills/README.md +1 -0
- package/bundled/skills/SKILL_NAMING.md +9 -0
- package/bundled/skills/commit-standards/SKILL.md +2 -2
- package/bundled/skills/commit-standards/guide.md +3 -2
- package/bundled/skills/commit-standards/language-options.md +19 -17
- package/bundled/skills/comprehension-ladder/SKILL.md +283 -0
- package/bundled/skills/comprehension-ladder/eval-cases.md +255 -0
- package/bundled/templates/gates/check-anti-fake-tests.mjs +1291 -0
- package/bundled/templates/gates/check-stubs.mjs +644 -0
- package/package.json +5 -3
- package/src/commands/audit.js +20 -2
- package/src/commands/check.js +155 -28
- package/src/commands/deps.js +31 -1
- package/src/commands/hitl.js +3 -0
- package/src/commands/init.js +173 -49
- package/src/commands/list.js +12 -3
- package/src/commands/mcp.js +2 -3
- package/src/commands/open-work.js +123 -0
- package/src/commands/quickstart.js +29 -13
- package/src/commands/release.js +102 -19
- package/src/commands/run-intent.js +10 -0
- package/src/commands/simulate.js +20 -8
- package/src/commands/skills.js +59 -33
- package/src/commands/spec-split.js +30 -17
- package/src/commands/spec.js +55 -21
- package/src/commands/uninstall.js +146 -32
- package/src/commands/update.js +471 -93
- package/src/core/install-records.js +192 -0
- package/src/core/manifest.js +12 -10
- package/src/core/marketplace-sentinel.js +5 -0
- package/src/core/open-work-config.js +122 -0
- package/src/core/project-config.js +92 -38
- package/src/flows/init-flow.js +10 -0
- package/src/hitl/manager.js +4 -2
- package/src/i18n/messages.js +413 -78
- package/src/installers/hooks-installer.js +320 -24
- package/src/installers/integration-installer.js +5 -1
- package/src/installers/skills-installer.js +3 -1
- package/src/installers/standards-installer.js +16 -23
- package/src/mcp/__tests__/server.test.js +0 -1
- package/src/mcp/server.js +16 -4
- package/src/prompts/init.js +148 -13
- package/src/reconciler/backup-locations.js +80 -0
- package/src/reconciler/backup-manager.js +451 -123
- package/src/reconciler/index.js +86 -10
- package/src/reconciler/install-roots.js +90 -0
- package/src/reconciler/plan-executor.js +37 -15
- package/src/uninstallers/hook-uninstaller.js +323 -33
- package/src/uninstallers/integration-uninstaller.js +35 -5
- package/src/uninstallers/skills-uninstaller.js +95 -16
- package/src/uninstallers/standards-uninstaller.js +56 -7
- package/src/utils/agents-installer.js +10 -17
- package/src/utils/available-standards-report.js +144 -0
- package/src/utils/available-standards.js +216 -0
- package/src/utils/command-hash-ownership.js +103 -0
- package/src/utils/commit-message-judge.js +155 -0
- package/src/utils/copier.js +80 -2
- package/src/utils/deps-applicability.js +25 -0
- package/src/utils/detector.js +46 -1
- package/src/utils/friction-detector.js +27 -0
- package/src/utils/gate-scripts.js +141 -0
- package/src/utils/git-hooks.js +139 -7
- package/src/utils/hasher.js +36 -0
- package/src/utils/health-scorer.js +10 -7
- package/src/utils/installed-names-ownership.js +114 -0
- package/src/utils/integration-generator.js +36 -24
- package/src/utils/legacy-hook-migration.js +112 -0
- package/src/utils/locale.js +19 -0
- package/src/utils/open-work-tracking.mjs +1754 -0
- package/src/utils/prompt-closed.js +18 -0
- package/src/utils/sdd-header.js +66 -0
- package/src/utils/skill-frontmatter.js +102 -0
- package/src/utils/skill-hash-ownership.js +64 -0
- package/src/utils/skill-name-collision.js +169 -0
- package/src/utils/skills-install-paths.js +114 -0
- package/src/utils/skills-installer.js +75 -106
- package/src/utils/standard-validator.js +98 -27
- package/src/utils/test-change-check.js +160 -0
- package/src/utils/test-policy.js +214 -0
- package/src/utils/transient-fs.js +113 -0
- package/src/utils/update-summary.js +29 -0
- package/src/vibe/micro-spec.js +15 -0
- package/standards-registry.json +48 -9
|
@@ -0,0 +1,1291 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
//
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
// check-anti-fake-tests —— 假測試掃描(UDS full-coverage-testing 的出貨閘門)
|
|
6
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
7
|
+
//
|
|
8
|
+
// What it finds, in the test files of any project (no test framework is assumed):
|
|
9
|
+
// no-assertion a test whose body contains nothing that can fail
|
|
10
|
+
// tautology a test whose only assertions can never fail (expect(true).toBe(true)), or whose
|
|
11
|
+
// expected value is not independent of the code under test (XSPEC-470): the
|
|
12
|
+
// assertion calls the same function with the same arguments on both sides, or
|
|
13
|
+
// recomputes the expected value from the same input with reduce/map/filter.
|
|
14
|
+
// (JavaScript/TypeScript only; other languages are a reviewer's judgment call.)
|
|
15
|
+
// all-skipped a test file in which every test is skipped or marked todo
|
|
16
|
+
//
|
|
17
|
+
// Written into your project by `uds init` (XSPEC-444 R5). It is YOURS: edit it, or replace
|
|
18
|
+
// it. `uds update` never overwrites it. `uds check` (which your pre-commit hook runs) calls
|
|
19
|
+
// it and prints what it finds as a WARNING; it does not stop your commit unless you set
|
|
20
|
+
// "mode": "block" in .standards/test-policy.json.
|
|
21
|
+
//
|
|
22
|
+
// Usage:
|
|
23
|
+
// node scripts/check-anti-fake-tests.mjs scan every test file under the project
|
|
24
|
+
// node scripts/check-anti-fake-tests.mjs --staged scan only the test files staged for commit
|
|
25
|
+
// node scripts/check-anti-fake-tests.mjs --json machine-readable result
|
|
26
|
+
//
|
|
27
|
+
// Exit codes: 0 nothing found | 1 findings (run on its own, this is a hard failure —
|
|
28
|
+
// wire it into CI to enforce) | 2 could not judge (the scanner's own self-test failed,
|
|
29
|
+
// or git was unreadable in --staged mode). 2 is never a pass.
|
|
30
|
+
//
|
|
31
|
+
// Which files are tests, and which extensions are code, comes from `.standards/test-policy.json`
|
|
32
|
+
// (optional; see the UDS docs). Test files in a language this script has no rule for are
|
|
33
|
+
// LISTED as "not scanned" — never counted as clean.
|
|
34
|
+
//
|
|
35
|
+
// Extra "this call is an assertion" names for your own helpers:
|
|
36
|
+
// .standards/test-policy.json → "assertionPatterns": ["\\bmustMatch\\w*\\s*\\("]
|
|
37
|
+
//
|
|
38
|
+
// Heuristic by nature: it reads text, it does not run your tests. A helper that asserts
|
|
39
|
+
// under a name this script cannot recognise will be reported as "no-assertion" — name it
|
|
40
|
+
// assert*/verify*/expect*, or list it in assertionPatterns.
|
|
41
|
+
|
|
42
|
+
import { existsSync, readFileSync, readdirSync, lstatSync, realpathSync } from 'node:fs';
|
|
43
|
+
import { join } from 'node:path';
|
|
44
|
+
import { execFileSync } from 'node:child_process';
|
|
45
|
+
import { fileURLToPath } from 'node:url';
|
|
46
|
+
|
|
47
|
+
// ---- BEGIN SHARED POLICY (identical in templates/gates/check-anti-fake-tests.mjs and check-stubs.mjs; test-policy-drift.test.js compares them) ----
|
|
48
|
+
/** Where an adopter's policy lives (inside `.standards/`, beside release-config.yaml). */
|
|
49
|
+
export const POLICY_FILE = '.standards/test-policy.json';
|
|
50
|
+
|
|
51
|
+
export const DEFAULT_POLICY = Object.freeze({
|
|
52
|
+
mode: 'warn',
|
|
53
|
+
testDirs: Object.freeze(['test', 'tests', '__tests__', 'spec', 'e2e']),
|
|
54
|
+
testPatterns: Object.freeze([
|
|
55
|
+
'*.test.*', '*.spec.*', '*_test.*', '*_spec.*', 'test_*.*', 'conftest.py',
|
|
56
|
+
'*Test.*', '*Tests.*', '*Spec.scala', '*Spec.kt', '*Spec.groovy'
|
|
57
|
+
]),
|
|
58
|
+
sourceExtensions: Object.freeze([
|
|
59
|
+
'js', 'mjs', 'cjs', 'jsx', 'ts', 'tsx', 'mts', 'cts', 'vue', 'svelte', 'astro',
|
|
60
|
+
'py', 'pyi', 'java', 'kt', 'kts', 'scala', 'groovy', 'go', 'rs', 'rb', 'php', 'cs', 'fs', 'vb',
|
|
61
|
+
'swift', 'm', 'mm', 'dart', 'c', 'h', 'cc', 'cpp', 'cxx', 'hpp', 'hh',
|
|
62
|
+
'ex', 'exs', 'erl', 'hrl', 'lua', 'pl', 'pm', 'r', 'jl', 'clj', 'cljs', 'hs', 'ml', 'mli',
|
|
63
|
+
'sh', 'bash', 'zsh', 'ps1'
|
|
64
|
+
]),
|
|
65
|
+
nonCodeExtensions: Object.freeze([
|
|
66
|
+
'md', 'mdx', 'txt', 'rst', 'adoc', 'json', 'jsonc', 'json5', 'yaml', 'yml', 'toml', 'ini', 'cfg',
|
|
67
|
+
'conf', 'properties', 'env', 'lock', 'xml', 'csv', 'tsv', 'svg', 'png', 'jpg', 'jpeg', 'gif', 'ico',
|
|
68
|
+
'webp', 'avif', 'pdf', 'woff', 'woff2', 'ttf', 'otf', 'eot', 'map', 'html', 'htm', 'css', 'scss',
|
|
69
|
+
'sass', 'less', 'sql', 'gitignore', 'gitattributes', 'editorconfig', 'npmrc', 'nvmrc', 'license',
|
|
70
|
+
'log', 'snap'
|
|
71
|
+
]),
|
|
72
|
+
nonCodeNames: Object.freeze([
|
|
73
|
+
'LICENSE', 'README', 'CHANGELOG', 'NOTICE', 'AUTHORS', 'CODEOWNERS', 'Dockerfile', 'Makefile', 'Procfile'
|
|
74
|
+
]),
|
|
75
|
+
ignoreDirs: Object.freeze([
|
|
76
|
+
'node_modules', 'vendor', 'dist', 'build', 'coverage', '.git', '.standards', '.claude', '.husky',
|
|
77
|
+
'.github', 'docs', 'target', '__pycache__', '.venv', 'venv', '.next', '.nuxt', '.idea', '.vscode',
|
|
78
|
+
'.ruff_cache', '.pytest_cache', '.mypy_cache', '.tox', '.gradle', '.cache', '.turbo', '.svelte-kit',
|
|
79
|
+
'.parcel-cache', '.terraform', '.dart_tool', '.eggs'
|
|
80
|
+
]),
|
|
81
|
+
ignore: Object.freeze(['**/*.min.js', '**/*.min.css', '**/*.d.ts']),
|
|
82
|
+
exempt: Object.freeze([])
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const norm = (p) => String(p).replace(/\\/g, '/').replace(/^\.\//, '');
|
|
86
|
+
|
|
87
|
+
/** Glob → RegExp. `*` stays inside a path segment, `**` crosses them, `?` is one non-slash character. */
|
|
88
|
+
export function globToRegex(glob) {
|
|
89
|
+
const g = norm(glob);
|
|
90
|
+
let re = '';
|
|
91
|
+
for (let i = 0; i < g.length; i++) {
|
|
92
|
+
const c = g[i];
|
|
93
|
+
if (c === '*') {
|
|
94
|
+
if (g[i + 1] === '*') {
|
|
95
|
+
if (g[i + 2] === '/') { re += '(?:.*/)?'; i += 2; } else { re += '.*'; i += 1; }
|
|
96
|
+
} else {
|
|
97
|
+
re += '[^/]*';
|
|
98
|
+
}
|
|
99
|
+
} else if (c === '?') {
|
|
100
|
+
re += '[^/]';
|
|
101
|
+
} else if ('\\^$+.()|{}[]'.includes(c)) {
|
|
102
|
+
re += '\\' + c;
|
|
103
|
+
} else {
|
|
104
|
+
re += c;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return new RegExp(`^${re}$`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A glob with no slash is a file-name glob (matches the basename anywhere); otherwise it matches the whole path. */
|
|
111
|
+
function matchesGlob(relPath, glob) {
|
|
112
|
+
const p = norm(relPath);
|
|
113
|
+
const g = norm(glob);
|
|
114
|
+
const target = g.includes('/') ? p : p.split('/').pop();
|
|
115
|
+
return globToRegex(g).test(target);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const extOf = (relPath) => {
|
|
119
|
+
const base = norm(relPath).split('/').pop();
|
|
120
|
+
const i = base.lastIndexOf('.');
|
|
121
|
+
return i > 0 ? base.slice(i + 1).toLowerCase() : '';
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Read `.standards/test-policy.json` and merge it over the defaults.
|
|
126
|
+
* @returns {{ policy: object, problems: string[], source: string|null }}
|
|
127
|
+
* `problems` is never swallowed: an unreadable file or a bad value is reported, and the
|
|
128
|
+
* defaults (mode "warn") are what runs.
|
|
129
|
+
*/
|
|
130
|
+
export function loadPolicy(projectPath) {
|
|
131
|
+
const problems = [];
|
|
132
|
+
const policy = {
|
|
133
|
+
mode: DEFAULT_POLICY.mode,
|
|
134
|
+
testDirs: [...DEFAULT_POLICY.testDirs],
|
|
135
|
+
testPatterns: [...DEFAULT_POLICY.testPatterns],
|
|
136
|
+
sourceExtensions: [...DEFAULT_POLICY.sourceExtensions],
|
|
137
|
+
nonCodeExtensions: [...DEFAULT_POLICY.nonCodeExtensions],
|
|
138
|
+
nonCodeNames: [...DEFAULT_POLICY.nonCodeNames],
|
|
139
|
+
ignoreDirs: [...DEFAULT_POLICY.ignoreDirs],
|
|
140
|
+
ignore: [...DEFAULT_POLICY.ignore],
|
|
141
|
+
exempt: []
|
|
142
|
+
};
|
|
143
|
+
const file = join(projectPath, POLICY_FILE);
|
|
144
|
+
if (!existsSync(file)) return { policy, problems, source: null };
|
|
145
|
+
|
|
146
|
+
let raw;
|
|
147
|
+
try {
|
|
148
|
+
raw = JSON.parse(readFileSync(file, 'utf-8').replace(/^\uFEFF/, ''));
|
|
149
|
+
} catch (e) {
|
|
150
|
+
problems.push(`${POLICY_FILE} cannot be read (${e.message}); defaults are in effect`);
|
|
151
|
+
return { policy, problems, source: POLICY_FILE };
|
|
152
|
+
}
|
|
153
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
154
|
+
problems.push(`${POLICY_FILE} must be a JSON object; defaults are in effect`);
|
|
155
|
+
return { policy, problems, source: POLICY_FILE };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (raw.mode !== undefined) {
|
|
159
|
+
if (raw.mode === 'warn' || raw.mode === 'block') policy.mode = raw.mode;
|
|
160
|
+
else problems.push(`${POLICY_FILE}: "mode" must be "warn" or "block", got ${JSON.stringify(raw.mode)}; "warn" is in effect`);
|
|
161
|
+
}
|
|
162
|
+
for (const key of ['testDirs', 'testPatterns', 'sourceExtensions', 'nonCodeExtensions', 'ignore']) {
|
|
163
|
+
if (raw[key] === undefined) continue;
|
|
164
|
+
if (!Array.isArray(raw[key]) || raw[key].some((v) => typeof v !== 'string' || !v)) {
|
|
165
|
+
problems.push(`${POLICY_FILE}: "${key}" must be an array of non-empty strings; it is ignored`);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const add = key === 'sourceExtensions' || key === 'nonCodeExtensions'
|
|
169
|
+
? raw[key].map((v) => v.replace(/^\./, '').toLowerCase())
|
|
170
|
+
: raw[key];
|
|
171
|
+
policy[key] = [...policy[key], ...add];
|
|
172
|
+
}
|
|
173
|
+
if (raw.exempt !== undefined) {
|
|
174
|
+
if (!Array.isArray(raw.exempt)) {
|
|
175
|
+
problems.push(`${POLICY_FILE}: "exempt" must be an array; it is ignored`);
|
|
176
|
+
} else {
|
|
177
|
+
raw.exempt.forEach((e, i) => {
|
|
178
|
+
const okPattern = e && typeof e.pattern === 'string' && e.pattern.trim();
|
|
179
|
+
const okReason = e && typeof e.reason === 'string' && e.reason.trim();
|
|
180
|
+
if (!okPattern) problems.push(`${POLICY_FILE}: exempt[${i}] has no "pattern"; it is ignored`);
|
|
181
|
+
else if (!okReason) problems.push(`${POLICY_FILE}: exempt[${i}] ("${e.pattern}") has no "reason" and is NOT honored — an exemption must say why`);
|
|
182
|
+
else policy.exempt.push({ pattern: e.pattern, reason: e.reason.trim() });
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { policy, problems, source: POLICY_FILE };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Classify one project-relative path.
|
|
191
|
+
* @returns {{ kind: 'ignored'|'noncode'|'test'|'source'|'unclassified', ext: string, exempt?: {pattern:string, reason:string} }}
|
|
192
|
+
*/
|
|
193
|
+
export function classifyPath(relPath, policy = DEFAULT_POLICY) {
|
|
194
|
+
const p = norm(relPath);
|
|
195
|
+
const segments = p.split('/');
|
|
196
|
+
const base = segments[segments.length - 1];
|
|
197
|
+
const dirs = segments.slice(0, -1);
|
|
198
|
+
const ext = extOf(p);
|
|
199
|
+
const sets = {
|
|
200
|
+
source: new Set(policy.sourceExtensions || DEFAULT_POLICY.sourceExtensions),
|
|
201
|
+
noncode: new Set(policy.nonCodeExtensions || DEFAULT_POLICY.nonCodeExtensions),
|
|
202
|
+
names: new Set(policy.nonCodeNames || DEFAULT_POLICY.nonCodeNames),
|
|
203
|
+
ignoreDirs: new Set(policy.ignoreDirs || DEFAULT_POLICY.ignoreDirs)
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
if (dirs.some((d) => sets.ignoreDirs.has(d))) return { kind: 'ignored', ext };
|
|
207
|
+
if ((policy.ignore || DEFAULT_POLICY.ignore).some((g) => matchesGlob(p, g))) return { kind: 'ignored', ext };
|
|
208
|
+
|
|
209
|
+
const docsLike = sets.noncode.has(ext) || sets.names.has(base) || sets.names.has(base.replace(/\.[^.]*$/, ''));
|
|
210
|
+
const inTestDir = dirs.some((d) => (policy.testDirs || DEFAULT_POLICY.testDirs).includes(d));
|
|
211
|
+
const testNamed = (policy.testPatterns || DEFAULT_POLICY.testPatterns).some((g) => matchesGlob(p, g));
|
|
212
|
+
|
|
213
|
+
// A test is a test even when its data is JSON; but a README inside tests/ is documentation.
|
|
214
|
+
if ((inTestDir || testNamed) && !['md', 'mdx', 'txt', 'rst', 'adoc'].includes(ext)) return { kind: 'test', ext };
|
|
215
|
+
// Dot-files (.prettierrc, .eslintrc.js, .env.local ...) are tool configuration, not product code.
|
|
216
|
+
if (docsLike || base.startsWith('.')) return { kind: 'noncode', ext };
|
|
217
|
+
if (sets.source.has(ext)) {
|
|
218
|
+
const exempt = (policy.exempt || []).find((e) => matchesGlob(p, e.pattern));
|
|
219
|
+
return exempt ? { kind: 'source', ext, exempt } : { kind: 'source', ext };
|
|
220
|
+
}
|
|
221
|
+
return { kind: 'unclassified', ext };
|
|
222
|
+
}
|
|
223
|
+
// ---- END SHARED POLICY ----
|
|
224
|
+
|
|
225
|
+
// ---- BEGIN SHARED ENGINE (identical in check-anti-fake-tests.mjs and check-stubs.mjs; test-policy-drift.test.js compares them) ----
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Language families this script has rules for, keyed by file extension.
|
|
229
|
+
* An extension that is not here is UNSUPPORTED: the script says so by name. It never
|
|
230
|
+
* counts a file it cannot read as a file that passed.
|
|
231
|
+
*/
|
|
232
|
+
export const FAMILY_BY_EXT = Object.freeze({
|
|
233
|
+
js: 'js', mjs: 'js', cjs: 'js', jsx: 'js', ts: 'js', tsx: 'js', mts: 'js', cts: 'js', vue: 'js', svelte: 'js',
|
|
234
|
+
py: 'python', pyi: 'python',
|
|
235
|
+
java: 'jvm', kt: 'jvm', kts: 'jvm', scala: 'jvm', groovy: 'jvm', cs: 'jvm',
|
|
236
|
+
go: 'go', rs: 'rust', rb: 'ruby', ex: 'elixir', exs: 'elixir',
|
|
237
|
+
php: 'php', swift: 'swift', dart: 'dart', lua: 'lua',
|
|
238
|
+
c: 'cpp', h: 'cpp', cc: 'cpp', cpp: 'cpp', cxx: 'cpp', hpp: 'cpp', hh: 'cpp'
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
const LEX = {
|
|
242
|
+
js: { line: ['//'], block: [['/*', '*/']], quotes: ['\'', '"', '`'], triple: [], regex: true },
|
|
243
|
+
python: { line: ['#'], block: [], quotes: ['\'', '"'], triple: ['"""', '\'\'\''] },
|
|
244
|
+
jvm: { line: ['//'], block: [['/*', '*/']], quotes: ['\'', '"'], triple: ['"""'] },
|
|
245
|
+
go: { line: ['//'], block: [['/*', '*/']], quotes: ['\'', '"', '`'], triple: [] },
|
|
246
|
+
rust: { line: ['//'], block: [['/*', '*/']], quotes: ['"', '\''], triple: [], rustChar: true },
|
|
247
|
+
ruby: { line: ['#'], block: [], quotes: ['\'', '"'], triple: [] },
|
|
248
|
+
elixir: { line: ['#'], block: [], quotes: ['"', '\''], triple: ['"""'] },
|
|
249
|
+
php: { line: ['//', '#'], block: [['/*', '*/']], quotes: ['\'', '"'], triple: [], phpAttr: true },
|
|
250
|
+
swift: { line: ['//'], block: [['/*', '*/']], quotes: ['"'], triple: ['"""'] },
|
|
251
|
+
dart: { line: ['//'], block: [['/*', '*/']], quotes: ['\'', '"'], triple: ['"""', '\'\'\''] },
|
|
252
|
+
lua: { line: ['--'], block: [['--[[', ']]']], quotes: ['\'', '"'], triple: [] },
|
|
253
|
+
cpp: { line: ['//'], block: [['/*', '*/']], quotes: ['\'', '"'], triple: [] },
|
|
254
|
+
other: { line: ['//', '#'], block: [['/*', '*/']], quotes: ['\'', '"'], triple: [] }
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Same-length copies of `text`: `noComments` (comments blanked) and `noStrings` (comments
|
|
259
|
+
* AND the inside of string literals blanked). Same length means an index found in one is
|
|
260
|
+
* the same place in the other and in the original — which is how names are read back.
|
|
261
|
+
*/
|
|
262
|
+
export function maskSource(text, family) {
|
|
263
|
+
const lex = LEX[family] || LEX.other;
|
|
264
|
+
const nc = text.split('');
|
|
265
|
+
const ns = text.split('');
|
|
266
|
+
const n = text.length;
|
|
267
|
+
const blank = (arr, from, to) => { for (let k = from; k < to; k++) if (arr[k] !== '\n') arr[k] = ' '; };
|
|
268
|
+
let i = 0;
|
|
269
|
+
while (i < n) {
|
|
270
|
+
let hit = false;
|
|
271
|
+
for (const [open, close] of lex.block) {
|
|
272
|
+
if (text.startsWith(open, i)) {
|
|
273
|
+
const end = text.indexOf(close, i + open.length);
|
|
274
|
+
const stop = end === -1 ? n : end + close.length;
|
|
275
|
+
blank(nc, i, stop); blank(ns, i, stop);
|
|
276
|
+
i = stop; hit = true; break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (hit) continue;
|
|
280
|
+
for (const lc of lex.line) {
|
|
281
|
+
if (text.startsWith(lc, i) && !(lex.phpAttr && lc === '#' && text[i + 1] === '[')) {
|
|
282
|
+
let end = text.indexOf('\n', i);
|
|
283
|
+
if (end === -1) end = n;
|
|
284
|
+
blank(nc, i, end); blank(ns, i, end);
|
|
285
|
+
i = end; hit = true; break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (hit) continue;
|
|
289
|
+
const triple = lex.triple.find((t) => text.startsWith(t, i));
|
|
290
|
+
if (triple) {
|
|
291
|
+
const end = text.indexOf(triple, i + 3);
|
|
292
|
+
// The delimiters go too: a closing `"""` left at column 0 would end an indented block early.
|
|
293
|
+
const stop = end === -1 ? n : end + 3;
|
|
294
|
+
blank(ns, i, stop);
|
|
295
|
+
i = stop;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const ch = text[i];
|
|
299
|
+
if (lex.regex && ch === '/') {
|
|
300
|
+
// A regex literal may hold a quote or a backtick; read it as one token so it cannot open a string.
|
|
301
|
+
let p = i - 1;
|
|
302
|
+
while (p >= 0 && /[ \t]/.test(text[p])) p--;
|
|
303
|
+
const before = p < 0 ? '' : text[p];
|
|
304
|
+
const word = /(?:^|[^\w$])(return|typeof|case|in|of|void|delete|throw|yield|await)$/.test(text.slice(Math.max(0, p - 9), p + 1));
|
|
305
|
+
if (p < 0 || '(,=:[!&|?{};+-*%<>~^\n'.includes(before) || word) {
|
|
306
|
+
let j = i + 1;
|
|
307
|
+
let inClass = false;
|
|
308
|
+
while (j < n) {
|
|
309
|
+
const c = text[j];
|
|
310
|
+
if (c === '\\') { j += 2; continue; }
|
|
311
|
+
if (c === '\n') { j = -1; break; }
|
|
312
|
+
if (c === '[') inClass = true;
|
|
313
|
+
else if (c === ']') inClass = false;
|
|
314
|
+
else if (c === '/' && !inClass) break;
|
|
315
|
+
j++;
|
|
316
|
+
}
|
|
317
|
+
if (j > i && j < n) { blank(ns, i + 1, j); i = j + 1; continue; }
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (lex.quotes.includes(ch)) {
|
|
321
|
+
if (lex.rustChar && ch === '\'') {
|
|
322
|
+
const isChar = text[i + 2] === '\'' || (text[i + 1] === '\\' && text[i + 3] === '\'');
|
|
323
|
+
if (!isChar) { i++; continue; }
|
|
324
|
+
}
|
|
325
|
+
const multiline = ch === '`';
|
|
326
|
+
let j = i + 1;
|
|
327
|
+
while (j < n) {
|
|
328
|
+
if (text[j] === '\\') { j += 2; continue; }
|
|
329
|
+
if (text[j] === ch) break;
|
|
330
|
+
if (text[j] === '\n' && !multiline) break;
|
|
331
|
+
j++;
|
|
332
|
+
}
|
|
333
|
+
blank(ns, i + 1, Math.min(j, n));
|
|
334
|
+
i = j + 1;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
i++;
|
|
338
|
+
}
|
|
339
|
+
return { noComments: nc.join(''), noStrings: ns.join('') };
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Index of the bracket that closes the one at `open` (counting only that bracket pair), or -1. */
|
|
343
|
+
export function matchClose(s, open) {
|
|
344
|
+
const pairs = { '(': ')', '{': '}', '[': ']' };
|
|
345
|
+
const o = s[open];
|
|
346
|
+
const c = pairs[o];
|
|
347
|
+
if (!c) return -1;
|
|
348
|
+
let depth = 0;
|
|
349
|
+
for (let i = open; i < s.length; i++) {
|
|
350
|
+
if (s[i] === o) depth++;
|
|
351
|
+
else if (s[i] === c && --depth === 0) return i;
|
|
352
|
+
}
|
|
353
|
+
return -1;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** A function that maps a character index to its 1-based line number. */
|
|
357
|
+
export function lineIndex(text) {
|
|
358
|
+
const starts = [0];
|
|
359
|
+
for (let i = 0; i < text.length; i++) if (text[i] === '\n') starts.push(i + 1);
|
|
360
|
+
return (idx) => {
|
|
361
|
+
let lo = 0; let hi = starts.length - 1;
|
|
362
|
+
while (lo < hi) {
|
|
363
|
+
const mid = (lo + hi + 1) >> 1;
|
|
364
|
+
if (starts[mid] <= idx) lo = mid; else hi = mid - 1;
|
|
365
|
+
}
|
|
366
|
+
return lo + 1;
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** Every project-relative file under `root`, skipping the policy's ignored directories and symlinks. */
|
|
371
|
+
export function walkFiles(root, policy) {
|
|
372
|
+
const skip = new Set(policy.ignoreDirs);
|
|
373
|
+
const out = [];
|
|
374
|
+
const stack = [''];
|
|
375
|
+
while (stack.length > 0 && out.length < 200000) {
|
|
376
|
+
const rel = stack.pop();
|
|
377
|
+
let entries;
|
|
378
|
+
try { entries = readdirSync(join(root, rel), { withFileTypes: true }); } catch { continue; }
|
|
379
|
+
for (const e of entries) {
|
|
380
|
+
const r = rel ? `${rel}/${e.name}` : e.name;
|
|
381
|
+
if (e.isSymbolicLink()) continue;
|
|
382
|
+
if (e.isDirectory()) { if (!skip.has(e.name)) stack.push(r); } else if (e.isFile()) out.push(r);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return out.sort();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** Files staged for the next commit (added, copied, modified, renamed), or `{ error }`. */
|
|
389
|
+
export function stagedFiles(root) {
|
|
390
|
+
try {
|
|
391
|
+
const out = execFileSync('git', ['-c', 'core.quotepath=off', 'diff', '--cached', '--name-only', '--diff-filter=ACMR', '-z'], {
|
|
392
|
+
cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 64 * 1024 * 1024
|
|
393
|
+
});
|
|
394
|
+
return { files: out.split('\0').filter(Boolean) };
|
|
395
|
+
} catch (e) {
|
|
396
|
+
return { error: String(e.stderr || e.message || 'git diff failed').trim().split('\n')[0] };
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** File text, or `{ skipped }` when it is binary or larger than 2 MB (said, never silently dropped). */
|
|
401
|
+
export function readText(abs) {
|
|
402
|
+
try {
|
|
403
|
+
if (lstatSync(abs).size > 2 * 1024 * 1024) return { skipped: 'larger than 2 MB' };
|
|
404
|
+
const buf = readFileSync(abs);
|
|
405
|
+
if (buf.subarray(0, 8000).includes(0)) return { skipped: 'binary', quiet: true };
|
|
406
|
+
return { text: buf.toString('utf8').replace(/^\uFEFF/, '') };
|
|
407
|
+
} catch (e) {
|
|
408
|
+
return { skipped: `unreadable (${e.code || e.message})` };
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export function extOfPath(p) {
|
|
413
|
+
const base = String(p).replace(/\\/g, '/').split('/').pop();
|
|
414
|
+
const i = base.lastIndexOf('.');
|
|
415
|
+
return i > 0 ? base.slice(i + 1).toLowerCase() : '';
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Is this module the one being run (not imported)? Resolves symlinks so `node scripts/x.mjs` and a symlinked path agree. */
|
|
419
|
+
export function isMain(metaUrl) {
|
|
420
|
+
try {
|
|
421
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(metaUrl));
|
|
422
|
+
} catch {
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export const indentOf = (l) => l.match(/^[ \t]*/)[0].replace(/\t/g, ' ').length;
|
|
428
|
+
|
|
429
|
+
/** Indented block that follows line `startLine` (0-based index into `lines`): every following line that is blank or indented deeper than `indent`. */
|
|
430
|
+
export function indentBlock(lines, startLine, indent) {
|
|
431
|
+
let end = startLine + 1;
|
|
432
|
+
let lastBody = startLine;
|
|
433
|
+
while (end < lines.length) {
|
|
434
|
+
const l = lines[end];
|
|
435
|
+
if (l.trim() === '') { end++; continue; }
|
|
436
|
+
const ind = indentOf(l);
|
|
437
|
+
if (ind <= indent) break;
|
|
438
|
+
lastBody = end;
|
|
439
|
+
end++;
|
|
440
|
+
}
|
|
441
|
+
return { first: startLine + 1, last: lastBody };
|
|
442
|
+
}
|
|
443
|
+
// ---- END SHARED ENGINE ----
|
|
444
|
+
|
|
445
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
446
|
+
// Test-case finders: one per language family. Each returns the cases it can see:
|
|
447
|
+
// { name, idx, bodyStart, bodyEnd, skipped, credit }
|
|
448
|
+
// `bodyStart..bodyEnd` is the text the assertion count is taken from.
|
|
449
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
450
|
+
|
|
451
|
+
const nameFrom = (original, from, to) => {
|
|
452
|
+
const m = /(['"`])((?:\\.|(?!\1)[^\\])*)\1/.exec(original.slice(from, to));
|
|
453
|
+
return m ? m[2].trim() : '(unnamed)';
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
/** `it('x', () => {...})`, `test('x', fn)`, `it.skip(...)`, `it.each(rows)('x', fn)`, `test("x") { ... }` */
|
|
457
|
+
function findCallCases(text, ns, nc, { names = 'it|test|specify', trailingBrace = false } = {}) {
|
|
458
|
+
const re = new RegExp(`(?<![.\\w$])(x?(?:${names}))((?:\\.\\w+)*)\\s*(?=\\()`, 'g');
|
|
459
|
+
const cases = [];
|
|
460
|
+
let unparsed = 0;
|
|
461
|
+
let m;
|
|
462
|
+
while ((m = re.exec(ns)) !== null) {
|
|
463
|
+
const mods = m[2].split('.').filter(Boolean);
|
|
464
|
+
let pos = m.index + m[0].length;
|
|
465
|
+
if (mods.includes('each')) {
|
|
466
|
+
const c1 = matchClose(ns, pos);
|
|
467
|
+
if (c1 === -1) { unparsed++; continue; }
|
|
468
|
+
pos = c1 + 1;
|
|
469
|
+
while (/\s/.test(ns[pos] || '')) pos++;
|
|
470
|
+
if (ns[pos] !== '(') continue;
|
|
471
|
+
}
|
|
472
|
+
let close = matchClose(ns, pos);
|
|
473
|
+
if (close === -1) { unparsed++; continue; }
|
|
474
|
+
const args = ns.slice(pos + 1, close);
|
|
475
|
+
const pending = !args.includes(',');
|
|
476
|
+
let bodyEnd = close;
|
|
477
|
+
if (trailingBrace) {
|
|
478
|
+
let k = close + 1;
|
|
479
|
+
while (/\s/.test(ns[k] || '')) k++;
|
|
480
|
+
if (ns[k] === '{') {
|
|
481
|
+
const c = matchClose(ns, k);
|
|
482
|
+
if (c !== -1) bodyEnd = c;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
const skipped = mods.includes('skip') || mods.includes('todo') || (m[1].length > 1 && m[1][0] === 'x') ||
|
|
486
|
+
m[1] === 'pending' || pending || /\bskip\s*:\s*(?!false\b)/.test(args);
|
|
487
|
+
cases.push({
|
|
488
|
+
name: nameFrom(text, pos + 1, close), idx: m.index, bodyStart: pos + 1, bodyEnd, skipped, credit: 0
|
|
489
|
+
});
|
|
490
|
+
re.lastIndex = bodyEnd + 1;
|
|
491
|
+
}
|
|
492
|
+
return { cases, unparsed };
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const linesAbove = (s, idx, n) => {
|
|
496
|
+
let start = idx;
|
|
497
|
+
for (let k = 0; k <= n && start > 0; k++) start = s.lastIndexOf('\n', start - 1) + 0;
|
|
498
|
+
return s.slice(Math.max(0, start), idx);
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
/** A test marked by an annotation/attribute: `@Test`, `[Fact]`, `#[test]`, `#[Test]`, Swift `@Test` ... */
|
|
502
|
+
function findAnnotationCases(text, ns, nc, annotationRe) {
|
|
503
|
+
const cases = [];
|
|
504
|
+
const re = new RegExp(annotationRe.source, annotationRe.flags.includes('g') ? annotationRe.flags : annotationRe.flags + 'g');
|
|
505
|
+
let m;
|
|
506
|
+
while ((m = re.exec(ns)) !== null) {
|
|
507
|
+
let pos = m.index + m[0].length;
|
|
508
|
+
// step over any further annotations between this one and the declaration
|
|
509
|
+
for (;;) {
|
|
510
|
+
while (/\s/.test(ns[pos] || '')) pos++;
|
|
511
|
+
const rest = ns.slice(pos, pos + 3);
|
|
512
|
+
if (rest[0] === '@') {
|
|
513
|
+
pos++;
|
|
514
|
+
while (/[\w.]/.test(ns[pos] || '')) pos++;
|
|
515
|
+
if (ns[pos] === '(') { const c = matchClose(ns, pos); if (c === -1) break; pos = c + 1; }
|
|
516
|
+
} else if (rest.startsWith('#[')) {
|
|
517
|
+
const c = matchClose(ns, pos + 1);
|
|
518
|
+
if (c === -1) break;
|
|
519
|
+
pos = c + 1;
|
|
520
|
+
} else if (rest[0] === '[' ) {
|
|
521
|
+
const c = matchClose(ns, pos);
|
|
522
|
+
if (c === -1) break;
|
|
523
|
+
pos = c + 1;
|
|
524
|
+
} else break;
|
|
525
|
+
}
|
|
526
|
+
const open = ns.indexOf('(', pos);
|
|
527
|
+
if (open === -1) continue;
|
|
528
|
+
const declText = text.slice(pos, open);
|
|
529
|
+
const nameM = /(?:`([^`]+)`|([\w$]+))\s*(?:<[^>]*>)?\s*$/.exec(declText);
|
|
530
|
+
const name = nameM ? (nameM[1] || nameM[2]) : '(unnamed)';
|
|
531
|
+
const pc = matchClose(ns, open);
|
|
532
|
+
if (pc === -1) continue;
|
|
533
|
+
let k = pc + 1;
|
|
534
|
+
while (k < ns.length && !'{=;'.includes(ns[k])) k++;
|
|
535
|
+
if (k >= ns.length || ns[k] === ';') continue; // abstract / interface: no body
|
|
536
|
+
let bodyStart; let bodyEnd;
|
|
537
|
+
if (ns[k] === '{') {
|
|
538
|
+
bodyStart = k + 1;
|
|
539
|
+
bodyEnd = matchClose(ns, k);
|
|
540
|
+
if (bodyEnd === -1) continue;
|
|
541
|
+
} else {
|
|
542
|
+
bodyStart = k + 1;
|
|
543
|
+
let e = bodyStart;
|
|
544
|
+
while (e < ns.length && !'{;\n'.includes(ns[e])) e++;
|
|
545
|
+
bodyEnd = ns[e] === '{' ? matchClose(ns, e) : e;
|
|
546
|
+
if (bodyEnd === -1) continue;
|
|
547
|
+
}
|
|
548
|
+
const header = linesAbove(nc, m.index, 5) + nc.slice(m.index, open);
|
|
549
|
+
const skipped = /@(?:Ignore|Disabled|Skip)\b|\[(?:Ignore|Skip)\b|#\[ignore\b|\bSkip\s*=|\.disabled\b/.test(header);
|
|
550
|
+
const credit = /\bexpected\s*=|ExpectedException|should_panic/.test(header) ? 1 : 0;
|
|
551
|
+
cases.push({ name, idx: m.index, bodyStart, bodyEnd, skipped, credit });
|
|
552
|
+
re.lastIndex = Math.max(re.lastIndex, bodyStart);
|
|
553
|
+
}
|
|
554
|
+
return { cases, unparsed: 0 };
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** `func TestX(t *testing.T) {`, `function testX() {`, `func testX() {` — a named function opens the case. */
|
|
558
|
+
function findFuncCases(text, ns, nc, funcRe, { skipRe } = {}) {
|
|
559
|
+
const cases = [];
|
|
560
|
+
let unparsed = 0;
|
|
561
|
+
const re = new RegExp(funcRe.source, funcRe.flags.includes('g') ? funcRe.flags : funcRe.flags + 'g');
|
|
562
|
+
let m;
|
|
563
|
+
while ((m = re.exec(ns)) !== null) {
|
|
564
|
+
const open = m.index + m[0].length - 1;
|
|
565
|
+
const close = matchClose(ns, open);
|
|
566
|
+
if (close === -1) { unparsed++; continue; }
|
|
567
|
+
const body = ns.slice(open + 1, close);
|
|
568
|
+
cases.push({
|
|
569
|
+
name: m[1], idx: m.index, bodyStart: open + 1, bodyEnd: close,
|
|
570
|
+
skipped: skipRe ? skipRe.test(body) : false, credit: 0
|
|
571
|
+
});
|
|
572
|
+
re.lastIndex = close + 1;
|
|
573
|
+
}
|
|
574
|
+
return { cases, unparsed };
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function offsetsOf(s) {
|
|
578
|
+
const off = [0];
|
|
579
|
+
for (let i = 0; i < s.length; i++) if (s[i] === '\n') off.push(i + 1);
|
|
580
|
+
return off;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function findPythonCases(text, ns, nc) {
|
|
584
|
+
const lines = ns.split('\n');
|
|
585
|
+
const ncLines = nc.split('\n');
|
|
586
|
+
const off = offsetsOf(ns);
|
|
587
|
+
const cases = [];
|
|
588
|
+
for (let li = 0; li < lines.length; li++) {
|
|
589
|
+
const m = /^([ \t]*)(?:async\s+)?def\s+(test\w*)\s*\(/.exec(lines[li]);
|
|
590
|
+
if (!m) continue;
|
|
591
|
+
const indent = indentOf(m[1] + 'x') - 1;
|
|
592
|
+
const open = off[li] + lines[li].indexOf('(');
|
|
593
|
+
const pc = matchClose(ns, open);
|
|
594
|
+
if (pc === -1) continue;
|
|
595
|
+
const colon = ns.indexOf(':', pc);
|
|
596
|
+
if (colon === -1) continue;
|
|
597
|
+
const colonLine = off.findIndex((o, i) => o <= colon && (i === off.length - 1 || off[i + 1] > colon));
|
|
598
|
+
const { first, last } = indentBlock(lines, colonLine, indent);
|
|
599
|
+
const bodyStart = colon + 1;
|
|
600
|
+
const bodyEnd = last >= first ? (off[last + 1] !== undefined ? off[last + 1] - 1 : ns.length) : (off[colonLine + 1] !== undefined ? off[colonLine + 1] - 1 : ns.length);
|
|
601
|
+
let decorators = '';
|
|
602
|
+
for (let k = li - 1; k >= 0 && /^\s*@/.test(ncLines[k]); k--) decorators += ncLines[k] + '\n';
|
|
603
|
+
const body = ns.slice(bodyStart, bodyEnd);
|
|
604
|
+
const skipped = /@(?:pytest\.mark\.skip|unittest\.skip|skip)\b(?!if)/.test(decorators) ||
|
|
605
|
+
/^\s*(?:pytest\.skip|self\.skipTest)\s*\(/.test(body.replace(/^[\s]*/, ''));
|
|
606
|
+
cases.push({ name: m[2], idx: off[li], bodyStart, bodyEnd, skipped, credit: 0 });
|
|
607
|
+
}
|
|
608
|
+
return { cases, unparsed: 0 };
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function findRubyCases(text, ns, nc) {
|
|
612
|
+
const lines = ns.split('\n');
|
|
613
|
+
const off = offsetsOf(ns);
|
|
614
|
+
const cases = [];
|
|
615
|
+
for (let li = 0; li < lines.length; li++) {
|
|
616
|
+
const line = lines[li];
|
|
617
|
+
let m = /^([ \t]*)def\s+(test_\w+)/.exec(line);
|
|
618
|
+
let name; let kind;
|
|
619
|
+
if (m) { name = m[2]; kind = 'def'; } else {
|
|
620
|
+
m = /^([ \t]*)(x?it|x?specify|x?example|x?scenario|test)\b(?![_?!:\w])\s*(.*)$/.exec(line);
|
|
621
|
+
if (!m) continue;
|
|
622
|
+
const rest = m[3];
|
|
623
|
+
if (!/^\(?\s*['":%]/.test(rest) && !/^(?:do\b|\{)/.test(rest)) continue;
|
|
624
|
+
kind = m[2];
|
|
625
|
+
name = nameFrom(text, off[li], off[li] + line.length);
|
|
626
|
+
}
|
|
627
|
+
const indent = indentOf(m[1] + 'x') - 1;
|
|
628
|
+
const hasDo = /\bdo\b(?:\s*\|[^|]*\|)?\s*$/.test(line);
|
|
629
|
+
const braceAt = line.indexOf('{');
|
|
630
|
+
let bodyStart; let bodyEnd; let skipped = kind.length > 2 && kind[0] === 'x' && kind !== 'example';
|
|
631
|
+
if (kind === 'def' || hasDo) {
|
|
632
|
+
const { first, last } = indentBlock(lines, li, indent);
|
|
633
|
+
bodyStart = off[li] + line.length; bodyEnd = last >= first ? (off[last + 1] !== undefined ? off[last + 1] - 1 : ns.length) : bodyStart;
|
|
634
|
+
} else if (braceAt !== -1) {
|
|
635
|
+
const c = matchClose(ns, off[li] + braceAt);
|
|
636
|
+
bodyStart = off[li] + braceAt + 1; bodyEnd = c === -1 ? off[li] + line.length : c;
|
|
637
|
+
} else { bodyStart = off[li] + line.length; bodyEnd = bodyStart; skipped = true; }
|
|
638
|
+
if (/^\s*(?:skip|pending)\b/.test(ns.slice(bodyStart, bodyEnd).replace(/^[\s]*/, ''))) skipped = true;
|
|
639
|
+
cases.push({ name, idx: off[li], bodyStart, bodyEnd, skipped, credit: 0 });
|
|
640
|
+
}
|
|
641
|
+
return { cases, unparsed: 0 };
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function findElixirCases(text, ns, nc) {
|
|
645
|
+
const lines = ns.split('\n');
|
|
646
|
+
const ncLines = nc.split('\n');
|
|
647
|
+
const off = offsetsOf(ns);
|
|
648
|
+
const cases = [];
|
|
649
|
+
for (let li = 0; li < lines.length; li++) {
|
|
650
|
+
const m = /^([ \t]*)test\s+"[^"\n]*"(?:\s*,\s*[^\n]*?)?\s+do\s*$/.exec(lines[li]);
|
|
651
|
+
if (!m) continue;
|
|
652
|
+
const indent = indentOf(m[1] + 'x') - 1;
|
|
653
|
+
const { first, last } = indentBlock(lines, li, indent);
|
|
654
|
+
const bodyStart = off[li] + lines[li].length;
|
|
655
|
+
const bodyEnd = last >= first ? (off[last + 1] !== undefined ? off[last + 1] - 1 : ns.length) : bodyStart;
|
|
656
|
+
const above = ncLines.slice(Math.max(0, li - 3), li).join('\n');
|
|
657
|
+
cases.push({ name: nameFrom(text, off[li], off[li] + lines[li].length), idx: off[li], bodyStart, bodyEnd, skipped: /@tag\s+(?::skip|skip:)/.test(above), credit: 0 });
|
|
658
|
+
}
|
|
659
|
+
return { cases, unparsed: 0 };
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function findCppCases(text, ns, nc) {
|
|
663
|
+
const re = /\b(TEST|TEST_F|TEST_P|TYPED_TEST|TYPED_TEST_P|TEST_CASE|SCENARIO|BOOST_AUTO_TEST_CASE|BOOST_FIXTURE_TEST_CASE|BOOST_DATA_TEST_CASE)\s*\(/g;
|
|
664
|
+
const cases = [];
|
|
665
|
+
let unparsed = 0;
|
|
666
|
+
let m;
|
|
667
|
+
while ((m = re.exec(ns)) !== null) {
|
|
668
|
+
const open = m.index + m[0].length - 1;
|
|
669
|
+
const close = matchClose(ns, open);
|
|
670
|
+
if (close === -1) { unparsed++; continue; }
|
|
671
|
+
let k = close + 1;
|
|
672
|
+
while (/\s/.test(ns[k] || '')) k++;
|
|
673
|
+
if (ns[k] !== '{') continue;
|
|
674
|
+
const end = matchClose(ns, k);
|
|
675
|
+
if (end === -1) { unparsed++; continue; }
|
|
676
|
+
const argsOriginal = text.slice(open + 1, close);
|
|
677
|
+
cases.push({
|
|
678
|
+
name: argsOriginal.replace(/\s+/g, ' ').trim(), idx: m.index, bodyStart: k + 1, bodyEnd: end,
|
|
679
|
+
skipped: /DISABLED_|\[\.\]|\[!hide\]/.test(argsOriginal), credit: 0
|
|
680
|
+
});
|
|
681
|
+
re.lastIndex = end + 1;
|
|
682
|
+
}
|
|
683
|
+
return { cases, unparsed };
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const LIT = '[\\w.$\'"]+';
|
|
687
|
+
const JS_TOKENS = /\b(?:expect\w*|assert\w*|verify\w*|should\w*)\s*\(|\bfail\s*\(|\.should\b|\bassert\s*\.|\bexpect\s*\.|\bt\.(?:is|not|true|false|truthy|falsy|deepEqual|throws|notThrows|pass|fail|equal|ok|same|match|rejects|snapshot|assert|like|plan)\w*\s*\(/g;
|
|
688
|
+
const JS_TAUT = [
|
|
689
|
+
new RegExp(`\\bexpect\\(\\s*(${LIT})\\s*\\)\\s*\\.\\s*(?:toBe|toEqual|toStrictEqual)\\s*\\(\\s*\\1\\s*\\)`, 'g'),
|
|
690
|
+
/\bexpect\(\s*(?:true|1)\s*\)\s*\.\s*toBeTruthy\s*\(\s*\)/g,
|
|
691
|
+
/\bexpect\(\s*(?:false|0|null|undefined)\s*\)\s*\.\s*toBeFalsy\s*\(\s*\)/g,
|
|
692
|
+
/\bexpect\(\s*true\s*\)\s*\.\s*to\s*\.\s*(?:be\s*\.\s*)?(?:true|ok)\b/g,
|
|
693
|
+
/\bassert(?:\s*\.\s*ok)?\s*\(\s*(?:true|1)\s*[),]/g,
|
|
694
|
+
new RegExp(`\\bassert\\s*\\.\\s*(?:equal|strictEqual|deepEqual|deepStrictEqual)\\s*\\(\\s*(${LIT})\\s*,\\s*\\1\\s*[),]`, 'g')
|
|
695
|
+
];
|
|
696
|
+
const JVM_TOKENS = /\b(?:assert\w*|Assert\w*|verify\w*|Verify\w*|expect|expectThat|expectThrows|Expect|fail|check|require)\s*[(.]|\b(?:should\w*|must\w*)\b|\.Should\w*\s*[(.]/g;
|
|
697
|
+
const JVM_TAUT = [
|
|
698
|
+
/\bassert(?:True)?\s*\(\s*true\s*[),]/gi,
|
|
699
|
+
/\bAssert\s*\.\s*(?:True|IsTrue)\s*\(\s*true\s*[),]/gi,
|
|
700
|
+
new RegExp(`\\bassert(?:Equals?|Same|AreEqual|Equal)\\s*\\(\\s*(${LIT})\\s*,\\s*\\1\\s*[),]`, 'gi'),
|
|
701
|
+
new RegExp(`\\bAssert\\s*\\.\\s*(?:AreEqual|Equal)\\s*\\(\\s*(${LIT})\\s*,\\s*\\1\\s*[),]`, 'gi')
|
|
702
|
+
];
|
|
703
|
+
|
|
704
|
+
const FAMILY_RULES = {
|
|
705
|
+
js: {
|
|
706
|
+
tokens: JS_TOKENS, taut: JS_TAUT,
|
|
707
|
+
find: (t, ns, nc) => findCallCases(t, ns, nc)
|
|
708
|
+
},
|
|
709
|
+
python: {
|
|
710
|
+
tokens: /^[ \t]*assert\b|\bself\.(?:assert|fail)\w*\s*\(|\bpytest\.(?:raises|warns|fail)\b|\.assert_\w+\s*\(|\bassert_\w+\s*\(|\braise\s+AssertionError\b|\bexpect\s*\(|\b(?:verify|check)_\w+\s*\(/gm,
|
|
711
|
+
taut: [
|
|
712
|
+
/^[ \t]*assert\s+(?:True|1)\s*(?:,.*)?$/gm,
|
|
713
|
+
new RegExp(`^[ \\t]*assert\\s+(${LIT})\\s*==\\s*\\1\\s*(?:,.*)?$`, 'gm'),
|
|
714
|
+
/\bself\.assertTrue\(\s*(?:True|1)\s*[),]/g,
|
|
715
|
+
new RegExp(`\\bself\\.assertEqual\\(\\s*(${LIT})\\s*,\\s*\\1\\s*[),]`, 'g')
|
|
716
|
+
],
|
|
717
|
+
find: findPythonCases
|
|
718
|
+
},
|
|
719
|
+
jvm: {
|
|
720
|
+
tokens: JVM_TOKENS, taut: JVM_TAUT,
|
|
721
|
+
find: (t, ns, nc, ext) => {
|
|
722
|
+
const a = findAnnotationCases(t, ns, nc, /(@(?:\w+\.)*(?:Test|ParameterizedTest|RepeatedTest|TestFactory|TestTemplate)\b(?:\s*\([^)]*\))?|\[(?:Fact|Theory|Test|TestMethod|TestCase|DataTestMethod)\b[^\]]*\])/);
|
|
723
|
+
if (ext === 'scala' || ext === 'kt' || ext === 'kts') {
|
|
724
|
+
const b = findCallCases(t, ns, nc, { names: 'test|it', trailingBrace: true });
|
|
725
|
+
return { cases: [...a.cases, ...b.cases], unparsed: a.unparsed + b.unparsed };
|
|
726
|
+
}
|
|
727
|
+
return a;
|
|
728
|
+
}
|
|
729
|
+
},
|
|
730
|
+
go: {
|
|
731
|
+
tokens: /\bt\.(?:Error|Errorf|Fatal|Fatalf|Fail|FailNow|Run)\b|\b(?:assert|require)\.\w+\s*\(|\bcmp\.(?:Diff|Equal)\s*\(|\bsuite\.\w+|\b\w+\s*\(\s*t\s*[,)]|\bExpect\s*\(|\.Should\s*\(|\bgomega\.\w+/g,
|
|
732
|
+
taut: [
|
|
733
|
+
/\bassert\.True\s*\(\s*t\s*,\s*true\s*\)/g,
|
|
734
|
+
new RegExp(`\\bassert\\.Equal\\s*\\(\\s*t\\s*,\\s*(${LIT})\\s*,\\s*\\1\\s*\\)`, 'g')
|
|
735
|
+
],
|
|
736
|
+
find: (t, ns, nc) => findFuncCases(t, ns, nc, /^func\s+(Test\w*|Example\w*|Fuzz\w*)\s*\(\s*\w+\s+\*testing\.[TF]\s*\)\s*\{/m, { skipRe: /^\s*t\.Skip\w*\(/ })
|
|
737
|
+
},
|
|
738
|
+
rust: {
|
|
739
|
+
tokens: /\b(?:assert\w*|debug_assert\w*|prop_assert\w*)!|\bpanic!|\bunreachable!|\.unwrap\s*\(|\.expect\s*\(|\bunwrap_err\s*\(|\?\s*;/g,
|
|
740
|
+
taut: [/\bassert!\s*\(\s*true\s*[),]/g, new RegExp(`\\bassert_eq!\\s*\\(\\s*(${LIT})\\s*,\\s*\\1\\s*[),]`, 'g')],
|
|
741
|
+
find: (t, ns, nc) => findAnnotationCases(t, ns, nc, /#\[(?:\w+::)*(?:test|rstest|test_case)\b[^\]]*\]/)
|
|
742
|
+
},
|
|
743
|
+
ruby: {
|
|
744
|
+
tokens: /\b(?:assert\w*|refute\w*|flunk|verify\w*)\b|\bexpect\b|\bis_expected\b|\.should(?:_not)?\b|\bshould(?:_not)?\b|\bmust_\w+|\bwont_\w+/g,
|
|
745
|
+
taut: [
|
|
746
|
+
/\bassert\s*\(?\s*true\s*\)?[ \t]*$/gm,
|
|
747
|
+
/\bassert_equal\s*\(?\s*([\w:'"]+)\s*,\s*\1\s*\)?[ \t]*$/gm,
|
|
748
|
+
/\bexpect\(\s*(?:true|1)\s*\)\.to\s+(?:be_truthy|be\s*\(?\s*true|eq\(\s*(?:true|1)\s*\))/g
|
|
749
|
+
],
|
|
750
|
+
find: findRubyCases
|
|
751
|
+
},
|
|
752
|
+
elixir: {
|
|
753
|
+
tokens: /\b(?:assert\w*|refute\w*|flunk|catch_\w+)\b/g,
|
|
754
|
+
taut: [/\bassert\s+true\b/g, /\bassert\s+([\w:'"]+)\s*==\s*\1\b/g],
|
|
755
|
+
find: findElixirCases
|
|
756
|
+
},
|
|
757
|
+
php: {
|
|
758
|
+
tokens: /\$this\s*->\s*(?:assert\w*|expect\w*|fail)\s*\(|\b(?:Assert\s*::\s*\w+|assert\w*|expect\w*|self\s*::\s*assert\w*|static\s*::\s*assert\w*)\s*\(|->\s*(?:shouldReceive|expects|verify)\w*\s*\(/g,
|
|
759
|
+
taut: [
|
|
760
|
+
/\$this\s*->\s*assertTrue\s*\(\s*true\s*\)/g,
|
|
761
|
+
/\$this\s*->\s*assert(?:Equals|Same)\s*\(\s*([\w.'"$]+)\s*,\s*\1\s*\)/g
|
|
762
|
+
],
|
|
763
|
+
find: (t, ns, nc) => {
|
|
764
|
+
const a = findFuncCases(t, ns, nc, /\bfunction\s+(test\w*)\s*\([^)]*\)\s*(?::\s*\??[\w\\]+\s*)?\{/, { skipRe: /^\s*\$this\s*->\s*markTest(?:Skipped|Incomplete)\s*\(/ });
|
|
765
|
+
const b = findAnnotationCases(t, ns, nc, /#\[(?:\\?[\w\\]+\\)?Test\b[^\]]*\]/);
|
|
766
|
+
const c = findCallCases(t, ns, nc, { names: 'it|test' });
|
|
767
|
+
const seen = new Set(a.cases.map((x) => x.bodyStart));
|
|
768
|
+
const extra = [...b.cases, ...c.cases].filter((x) => !seen.has(x.bodyStart));
|
|
769
|
+
return { cases: [...a.cases, ...extra], unparsed: a.unparsed + b.unparsed + c.unparsed };
|
|
770
|
+
}
|
|
771
|
+
},
|
|
772
|
+
swift: {
|
|
773
|
+
tokens: /\bXCT(?:Assert\w*|Fail|Unwrap|ExpectFailure)\b|#(?:expect|require)\b|\bIssue\.record\b|\b(?:expect|require)\s*\(/g,
|
|
774
|
+
taut: [
|
|
775
|
+
/\bXCTAssertTrue\s*\(\s*true\s*[),]/g,
|
|
776
|
+
new RegExp(`\\bXCTAssertEqual\\s*\\(\\s*(${LIT})\\s*,\\s*\\1\\s*[),]`, 'g'),
|
|
777
|
+
/#expect\s*\(\s*true\s*\)/g
|
|
778
|
+
],
|
|
779
|
+
find: (t, ns, nc) => {
|
|
780
|
+
const a = findFuncCases(t, ns, nc, /\bfunc\s+(test\w*)\s*\([^)]*\)\s*(?:async\s*)?(?:throws\s*)?\{/, { skipRe: /XCTSkip/ });
|
|
781
|
+
const b = findAnnotationCases(t, ns, nc, /@Test\b(?:\s*\([^)]*\))?/);
|
|
782
|
+
const seen = new Set(a.cases.map((x) => x.bodyStart));
|
|
783
|
+
return { cases: [...a.cases, ...b.cases.filter((x) => !seen.has(x.bodyStart))], unparsed: a.unparsed };
|
|
784
|
+
}
|
|
785
|
+
},
|
|
786
|
+
dart: {
|
|
787
|
+
tokens: JS_TOKENS,
|
|
788
|
+
taut: [
|
|
789
|
+
/\bexpect\(\s*true\s*,\s*(?:isTrue|true|equals\(\s*true\s*\))\s*\)/g,
|
|
790
|
+
new RegExp(`\\bexpect\\(\\s*(${LIT})\\s*,\\s*(?:equals\\(\\s*\\1\\s*\\)|\\1)\\s*\\)`, 'g')
|
|
791
|
+
],
|
|
792
|
+
find: (t, ns, nc) => findCallCases(t, ns, nc, { names: 'test|testWidgets|it' })
|
|
793
|
+
},
|
|
794
|
+
lua: {
|
|
795
|
+
tokens: /\bassert\w*\s*[.(]|\bspy\b|\bstub\b|\bmock\b|\bexpect\s*[(.]|\bshould\b/g,
|
|
796
|
+
taut: [
|
|
797
|
+
/\bassert\.is_true\s*\(\s*true\s*\)/g,
|
|
798
|
+
/\bassert\s*\(\s*true\s*\)/g,
|
|
799
|
+
new RegExp(`\\bassert\\.are\\.equal\\s*\\(\\s*(${LIT})\\s*,\\s*\\1\\s*\\)`, 'g')
|
|
800
|
+
],
|
|
801
|
+
find: (t, ns, nc) => findCallCases(t, ns, nc, { names: 'it|test|pending' })
|
|
802
|
+
},
|
|
803
|
+
cpp: {
|
|
804
|
+
tokens: /\b(?:ASSERT|EXPECT)_\w+\s*\(|\b(?:CHECK|REQUIRE|CHECK_THAT|REQUIRE_THAT|ADD_FAILURE|FAIL|SUCCEED|GTEST_FAIL|GTEST_SKIP)\w*\s*\(|\bBOOST_(?:CHECK|REQUIRE|TEST|ERROR|FAIL)\w*\s*\(|\bassert\s*\(/g,
|
|
805
|
+
taut: [
|
|
806
|
+
/\b(?:ASSERT|EXPECT)_TRUE\s*\(\s*true\s*\)/g,
|
|
807
|
+
new RegExp(`\\b(?:ASSERT|EXPECT)_EQ\\s*\\(\\s*(${LIT})\\s*,\\s*\\1\\s*\\)`, 'g'),
|
|
808
|
+
/\b(?:CHECK|REQUIRE|BOOST_CHECK)\s*\(\s*true\s*\)/g
|
|
809
|
+
],
|
|
810
|
+
find: findCppCases
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
const countMatches = (re, s) => {
|
|
815
|
+
const r = new RegExp(re.source, re.flags.includes('g') ? re.flags : re.flags + 'g');
|
|
816
|
+
let n = 0;
|
|
817
|
+
while (r.exec(s) !== null) { n++; if (r.lastIndex === 0) break; }
|
|
818
|
+
return n;
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
822
|
+
// Expected values that are not independent of the code under test (XSPEC-470 R1)
|
|
823
|
+
//
|
|
824
|
+
// An oracle is the source that says what the right answer is (UDS `verification-oracle`).
|
|
825
|
+
// A test whose expected value is produced by the code under test — or by the same logic re-typed
|
|
826
|
+
// in the test — has the implementation as its own oracle, so it cannot disagree with it. Two
|
|
827
|
+
// shapes are mechanical enough to judge from text, and they are the only ones judged here:
|
|
828
|
+
//
|
|
829
|
+
// same-call expect(total(items)).toBe(total(items)) same function, same arguments, both sides
|
|
830
|
+
// recomputed expect(total(items)).toBe(items.reduce(...)) expected value is built from the same
|
|
831
|
+
// input with reduce / map / flatMap / filter
|
|
832
|
+
// by a callback that uses nothing but its own
|
|
833
|
+
// parameters (and pure built-ins), holds no
|
|
834
|
+
// literal and is not just `(x) => x` / `({ ...x })`.
|
|
835
|
+
// Only the text of the assertion is read: a name set
|
|
836
|
+
// on an earlier line is not looked through.
|
|
837
|
+
//
|
|
838
|
+
// Left alone on purpose, because they cannot be told from a sound test by reading the text:
|
|
839
|
+
// a lookup in a fixed table expect(priceOf(ids)).toEqual(ids.map((id) => KNOWN_PRICES[id]))
|
|
840
|
+
// a pick by a literal expect(activeOf(users)).toEqual(users.filter((u) => u.id === 2))
|
|
841
|
+
// a call inside the call expect(render(now())).toBe(render(now())) (two now() are two values)
|
|
842
|
+
// expect(parse(serialize(rows))).toEqual(rows.map((r) => r)) (a round trip)
|
|
843
|
+
// a property of the result expect(sortUsers(users).length).toBe(users.filter((u) => u.name).length)
|
|
844
|
+
// a callback that only returns expect(clone(input)).toEqual(input.map((x) => x)) (a copy, no logic)
|
|
845
|
+
// or shallow-copies its input expect(clone(users)).toEqual(users.map((u) => ({ ...u })))
|
|
846
|
+
// or rebuilds a destructured expect(clone(pairs)).toEqual(pairs.map(([k, v]) => [k, v]))
|
|
847
|
+
// parameter in the same shape
|
|
848
|
+
// a name set on an earlier line const before = items.map((i) => i.price); freezeCart(items);
|
|
849
|
+
// expect(pricesOf(items)).toEqual(before) (before / after)
|
|
850
|
+
// Everything else (a hand-rolled loop, a helper that re-derives the answer, a snapshot taken from
|
|
851
|
+
// the implementation's own output) is a reviewer's question, not this script's: when it cannot be
|
|
852
|
+
// decided from the text, it is NOT reported. A false alarm teaches people to switch the scanner off.
|
|
853
|
+
// Deliberately narrow: JavaScript/TypeScript matchers toBe / toEqual / toStrictEqual, chai
|
|
854
|
+
// to.equal / to.eql, node assert.equal / strictEqual / deepEqual / deepStrictEqual.
|
|
855
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
856
|
+
|
|
857
|
+
/** A test named like this compares two calls ON PURPOSE (determinism, caching, identity): not judged. */
|
|
858
|
+
const DELIBERATE_COMPARISON_NAME = /determinis|idempot|\bsame\b|identical|\bstable\b|stability|consisten|\bcach(?:e|es|ed|ing)\b|memo|singleton|twice|repeat|\bagain\b|reuse|reference|identity|\bpure\b|決定|確定性|相同|一致|同一|冪等|快取|重複|兩次|不變/i;
|
|
859
|
+
|
|
860
|
+
const SKIP_WORDS = new Set(['true', 'false', 'null', 'undefined', 'this', 'new', 'typeof', 'void', 'await', 'async', 'function', 'return']);
|
|
861
|
+
|
|
862
|
+
/** Top-level (bracket-depth 0) comma-separated pieces of `ns[from, to)`, as [start, end) pairs. */
|
|
863
|
+
function topLevelPieces(ns, from, to) {
|
|
864
|
+
const out = [];
|
|
865
|
+
let depth = 0;
|
|
866
|
+
let begin = from;
|
|
867
|
+
for (let i = from; i < to; i++) {
|
|
868
|
+
const ch = ns[i];
|
|
869
|
+
if (ch === '(' || ch === '[' || ch === '{') depth++;
|
|
870
|
+
else if (ch === ')' || ch === ']' || ch === '}') depth--;
|
|
871
|
+
else if (ch === ',' && depth === 0) { out.push([begin, i]); begin = i + 1; }
|
|
872
|
+
}
|
|
873
|
+
out.push([begin, to]);
|
|
874
|
+
return out.filter(([a, b]) => ns.slice(a, b).trim() !== '');
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/** Canonical form for "is this the same expression?": no `await`, no spacing, no trailing comma. */
|
|
878
|
+
const canonicalExpr = (s) => s
|
|
879
|
+
.replace(/^\s*await\s+/, '')
|
|
880
|
+
.replace(/\s+/g, ' ')
|
|
881
|
+
.replace(/\s*([(),.\[\]])\s*/g, '$1')
|
|
882
|
+
.replace(/,\)/g, ')')
|
|
883
|
+
.trim()
|
|
884
|
+
.replace(/,$/, '');
|
|
885
|
+
|
|
886
|
+
/** Does this canonical expression call something with at least one argument (and is not a `new` expression)? */
|
|
887
|
+
const callsWithArguments = (expr) => !/^new\b/.test(expr) && /[A-Za-z_$][\w$]*\(['"`\w$\[{(-]/.test(expr);
|
|
888
|
+
|
|
889
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
890
|
+
|
|
891
|
+
/** If `ns` (canonical, strings blanked) is exactly `callee(args)` (nothing after it), the identifier paths used in args. */
|
|
892
|
+
function callInputs(ns) {
|
|
893
|
+
const m = /^([A-Za-z_$][\w$.]*)\(/.exec(ns);
|
|
894
|
+
if (!m || /^new\b/.test(ns)) return null;
|
|
895
|
+
const open = m[0].length - 1;
|
|
896
|
+
const close = matchClose(ns, open);
|
|
897
|
+
if (close === -1) return null;
|
|
898
|
+
// Something after the call (`.length`, `.name`, `[0]`) means the value under test is a property of the result,
|
|
899
|
+
// not the result: the expected value on the other side is then not "the same computation", and which of the
|
|
900
|
+
// two is right cannot be read from the text. Not judged.
|
|
901
|
+
if (ns.slice(close + 1) !== '') return null;
|
|
902
|
+
const args = ns.slice(open + 1, close);
|
|
903
|
+
const paths = new Set();
|
|
904
|
+
const re = /(?<![\w$.])([A-Za-z_$][\w$]*(?:(?:\?\.|\.)[A-Za-z_$][\w$]*)*)(?!\w|\$)(?!\()/g;
|
|
905
|
+
let p;
|
|
906
|
+
while ((p = re.exec(args)) !== null) if (!SKIP_WORDS.has(p[1])) paths.add(p[1]);
|
|
907
|
+
return [...paths];
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/** Words that can appear in a callback body without naming anything outside it. */
|
|
911
|
+
const CALLBACK_KEYWORDS = new Set(['return', 'if', 'else', 'typeof', 'void', 'in', 'of', 'instanceof', 'const', 'let', 'var', 'for', 'while', 'do', 'switch', 'case', 'break', 'continue', 'default']);
|
|
912
|
+
/** Built-ins that compute from their arguments only, so using them does not bring in anything from outside the callback. */
|
|
913
|
+
const CALLBACK_GLOBALS = new Set(['Math', 'Number', 'String', 'Boolean', 'Array', 'Object', 'JSON', 'Infinity', 'NaN', 'parseInt', 'parseFloat']);
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Is this callback "the same logic re-typed in the test"? Only when it is self-contained: it uses nothing but
|
|
917
|
+
* its own parameters (so it cannot be looking an answer up in a table, a constant or a helper the test brings in)
|
|
918
|
+
* and it holds no literal (a literal inside the callback is knowledge the test author supplied: `u.id === 2`,
|
|
919
|
+
* `x * 2`, `'abc'`, `/re/`). Anything else is not decidable from text, and what is not decidable is not reported.
|
|
920
|
+
* @param {string} arg the callback as written (strings blanked), e.g. `(s, i) => s + i.price`
|
|
921
|
+
*/
|
|
922
|
+
function isSelfContainedCallback(arg) {
|
|
923
|
+
let params;
|
|
924
|
+
let body;
|
|
925
|
+
const arrow = /^(?:async\s*)?(?:\(([^()]*)\)|([A-Za-z_$][\w$]*))\s*=>\s*([\s\S]*)$/.exec(arg.trim());
|
|
926
|
+
const fn = /^(?:async\s*)?function\s*[A-Za-z_$]*\s*\(([^()]*)\)\s*\{([\s\S]*)\}$/.exec(arg.trim());
|
|
927
|
+
if (arrow) {
|
|
928
|
+
params = arrow[1] ?? arrow[2];
|
|
929
|
+
body = arrow[3].trim();
|
|
930
|
+
if (body.startsWith('{')) {
|
|
931
|
+
const close = matchClose(body, 0);
|
|
932
|
+
if (close !== body.length - 1) return false;
|
|
933
|
+
body = body.slice(1, close);
|
|
934
|
+
}
|
|
935
|
+
} else if (fn) {
|
|
936
|
+
params = fn[1];
|
|
937
|
+
body = fn[2];
|
|
938
|
+
} else {
|
|
939
|
+
return false; // a named function, or a shape not understood: not judged
|
|
940
|
+
}
|
|
941
|
+
if (params.includes('=')) return false; // default values can call anything
|
|
942
|
+
// A callback that only hands its parameter back (`(r) => r`, `x => { return x; }`) computes nothing, so
|
|
943
|
+
// there is no logic in it that could be "the same as the implementation".
|
|
944
|
+
const only = body.replace(/^\s*return\b/, '').replace(/[;\s]+$/g, '').replace(/^\s*\(\s*|\s*\)\s*$/g, '').trim();
|
|
945
|
+
// A destructured parameter put straight back into the same shape (`([k, v]) => [k, v]`, `({ a, b }) => ({ a, b })`)
|
|
946
|
+
// is a copy as well: the body is the parameter list itself.
|
|
947
|
+
if (/[{[]/.test(params) && only.replace(/\s+/g, '') === params.replace(/\s+/g, '')) return false;
|
|
948
|
+
if (!/[{[]/.test(params)) {
|
|
949
|
+
// A shallow copy of the parameter (`{ ...u }`, `[...u]`) is a copy, not logic: the same family as the identity callback.
|
|
950
|
+
const copied = /^[{[]\s*\.\.\.\s*([A-Za-z_$][\w$]*)\s*[}\]]$/.exec(only);
|
|
951
|
+
if (copied && new RegExp(`(?<![\\w$])${escapeRe(copied[1])}(?![\\w$])`).test(params)) return false;
|
|
952
|
+
if (/^[A-Za-z_$][\w$]*$/.test(only) && new RegExp(`(?<![\\w$])${escapeRe(only)}(?![\\w$])`).test(params)) return false;
|
|
953
|
+
}
|
|
954
|
+
if (/['"`]/.test(body)) return false; // a string literal (their contents are blanked, their quotes are not)
|
|
955
|
+
if (/(?<![\w$.])\d|(?<=\.)\d/.test(body)) return false; // a number literal
|
|
956
|
+
if (/(?:^|[(,=:[!&|?{};>+\-*%<~^]|\breturn\b)\s*\//.test(body)) return false; // a regex literal
|
|
957
|
+
if (/\b(?:true|false|null|undefined)\b/.test(body)) return false; // a keyword literal
|
|
958
|
+
if (/\b(?:this|arguments|new|await|yield|function)\b|=>/.test(body)) return false; // outside state, or a nested function
|
|
959
|
+
const known = new Set([...params.matchAll(/[A-Za-z_$][\w$]*/g)].map((m) => m[0]));
|
|
960
|
+
for (const d of body.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)/g)) known.add(d[1]);
|
|
961
|
+
for (const id of body.matchAll(/(?<![\w$.])(?<!\?\.)([A-Za-z_$][\w$]*)/g)) {
|
|
962
|
+
const name = id[1];
|
|
963
|
+
if (!known.has(name) && !CALLBACK_KEYWORDS.has(name) && !CALLBACK_GLOBALS.has(name)) return false; // something from outside the callback
|
|
964
|
+
}
|
|
965
|
+
return true;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/** Is `rhs` the input `x` run through reduce / map / flatMap / filter by a callback that re-types the logic (see above)? */
|
|
969
|
+
function recomputesFrom(rhs, x) {
|
|
970
|
+
const X = escapeRe(x).replace(/\\\./g, '(?:\\?\\.|\\.)');
|
|
971
|
+
const source = `(?:${X}|\\[\\.\\.\\.${X}\\]|Object\\.(?:values|keys|entries)\\(${X}\\)|Array\\.from\\(${X}\\))`;
|
|
972
|
+
const verb = '(?:reduce|reduceRight|map|flatMap|filter)(?:<[^>()]*>)?\\(';
|
|
973
|
+
const re = new RegExp(`(?<![\\w$.])${source}(?:\\?\\.|\\.)${verb}`, 'g');
|
|
974
|
+
for (const m of rhs.matchAll(re)) {
|
|
975
|
+
const open = m.index + m[0].length - 1;
|
|
976
|
+
const close = matchClose(rhs, open);
|
|
977
|
+
if (close === -1) continue;
|
|
978
|
+
const [callback] = topLevelPieces(rhs, open + 1, close);
|
|
979
|
+
if (callback && isSelfContainedCallback(rhs.slice(callback[0], callback[1]))) return true;
|
|
980
|
+
}
|
|
981
|
+
return false;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* The assertions in one test body whose expected value is not independent.
|
|
986
|
+
* @param {string} ncBody the body with comments blanked (strings intact)
|
|
987
|
+
* @param {string} nsBody the same body with comments AND string contents blanked (same offsets)
|
|
988
|
+
* @param {string} testName
|
|
989
|
+
* @returns {{ form: 'same-call'|'recomputed', offset: number }[]}
|
|
990
|
+
*/
|
|
991
|
+
export function findNonIndependentExpectations(ncBody, nsBody, testName = '') {
|
|
992
|
+
const hits = [];
|
|
993
|
+
const judge = (lhsFrom, lhsTo, rhsFrom, rhsTo, offset) => {
|
|
994
|
+
const rawL = canonicalExpr(ncBody.slice(lhsFrom, lhsTo));
|
|
995
|
+
const rawR = canonicalExpr(ncBody.slice(rhsFrom, rhsTo));
|
|
996
|
+
if (rawL === rawR && !callsWithArguments(rawL)) return; // `x` against `x`: the literal rule above counts it
|
|
997
|
+
// same-call is judged on the text as written. A name set earlier (`const before = snapshot(x)`) holds the
|
|
998
|
+
// value from an EARLIER moment: `expect(snapshot(x)).toEqual(before)` after an action asks "did it change?",
|
|
999
|
+
// which is a real question. Only two calls inside one statement cannot differ in time.
|
|
1000
|
+
if (rawL === rawR && callsWithArguments(rawL)) {
|
|
1001
|
+
// Another call inside the expression (`render(now())`, `total(load())`) may return something different the
|
|
1002
|
+
// second time, so the two sides are not known to be the same value: not judged.
|
|
1003
|
+
const callCount = (canonicalExpr(nsBody.slice(lhsFrom, lhsTo)).match(/[A-Za-z_$][\w$]*\(/g) || []).length;
|
|
1004
|
+
const hasNew = /\bnew\b/.test(canonicalExpr(nsBody.slice(lhsFrom, lhsTo)));
|
|
1005
|
+
if (callCount <= 1 && !hasNew && !DELIBERATE_COMPARISON_NAME.test(testName)) hits.push({ form: 'same-call', offset });
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
// Only the text of the assertion itself is read. A name set on an earlier line (`const before = items.map(...)`)
|
|
1009
|
+
// holds a value from an EARLIER moment, and what happened in between (`freezeCart(items)`, `users.push(x)`)
|
|
1010
|
+
// is exactly what such a test is asking about, so a name is never expanded here (same-call reads it the same way).
|
|
1011
|
+
const l = { ns: canonicalExpr(nsBody.slice(lhsFrom, lhsTo)) };
|
|
1012
|
+
const r = { ns: canonicalExpr(nsBody.slice(rhsFrom, rhsTo)) };
|
|
1013
|
+
// Same guard as same-call: another call (or `new`) inside the call under test (`parse(serialize(rows))`) is a
|
|
1014
|
+
// round trip or a pipeline, not the implementation's own arithmetic typed again. Not judged.
|
|
1015
|
+
if ((l.ns.match(/[A-Za-z_$][\w$]*\(/g) || []).length > 1 || /\bnew\b/.test(l.ns)) return;
|
|
1016
|
+
const inputs = callInputs(l.ns);
|
|
1017
|
+
if (inputs && inputs.some((x) => recomputesFrom(r.ns, x))) hits.push({ form: 'recomputed', offset });
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
const expectRe = /(?<![.\w$])expect\s*\(/g;
|
|
1021
|
+
let m;
|
|
1022
|
+
while ((m = expectRe.exec(nsBody)) !== null) {
|
|
1023
|
+
const open = m.index + m[0].length - 1;
|
|
1024
|
+
const close = matchClose(nsBody, open);
|
|
1025
|
+
if (close === -1) continue;
|
|
1026
|
+
const after = /^\s*\.\s*(?:(?:toBe|toEqual|toStrictEqual)|to\s*\.\s*(?:deep\s*\.\s*)?(?:equal|equals|eql))\s*\(/.exec(nsBody.slice(close + 1, close + 60));
|
|
1027
|
+
if (!after) continue; // `.not.`, `.resolves`, `.toThrow`, ... are not judged
|
|
1028
|
+
const mOpen = close + 1 + after[0].length - 1;
|
|
1029
|
+
const mClose = matchClose(nsBody, mOpen);
|
|
1030
|
+
if (mClose === -1) continue;
|
|
1031
|
+
const [first] = topLevelPieces(nsBody, mOpen + 1, mClose);
|
|
1032
|
+
if (!first) continue;
|
|
1033
|
+
judge(open + 1, close, first[0], first[1], m.index);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
const assertRe = /(?<![.\w$])assert\s*\.\s*(?:equal|strictEqual|deepEqual|deepStrictEqual)\s*\(/g;
|
|
1037
|
+
while ((m = assertRe.exec(nsBody)) !== null) {
|
|
1038
|
+
const open = m.index + m[0].length - 1;
|
|
1039
|
+
const close = matchClose(nsBody, open);
|
|
1040
|
+
if (close === -1) continue;
|
|
1041
|
+
const pieces = topLevelPieces(nsBody, open + 1, close);
|
|
1042
|
+
if (pieces.length < 2) continue;
|
|
1043
|
+
judge(pieces[0][0], pieces[0][1], pieces[1][0], pieces[1][1], m.index);
|
|
1044
|
+
}
|
|
1045
|
+
return hits;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* The independence detectors, by language family. `count` is what analyzeTestText subtracts from the
|
|
1050
|
+
* assertions it credits; `find` says which assertions and why. Passed in (not read from a global) so a
|
|
1051
|
+
* test can hand the scanner a weakened set and watch the self-test and the samples catch it.
|
|
1052
|
+
*/
|
|
1053
|
+
export const INDEPENDENCE_DETECTORS = Object.freeze({
|
|
1054
|
+
count: (family, ncBody, nsBody, testName) => (family === 'js' ? findNonIndependentExpectations(ncBody, nsBody, testName).length : 0),
|
|
1055
|
+
find: (family, ncBody, nsBody, testName) => (family === 'js' ? findNonIndependentExpectations(ncBody, nsBody, testName) : [])
|
|
1056
|
+
});
|
|
1057
|
+
|
|
1058
|
+
const FORM_DETAIL = {
|
|
1059
|
+
'same-call': 'the expected value is the same call as the code under test (same function, same arguments)',
|
|
1060
|
+
recomputed: 'the expected value is recomputed from the same input as the code under test (reduce/map/filter with a callback that uses only its own parameters), so it is not an independent oracle'
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
/**
|
|
1064
|
+
* Analyze one test file's text.
|
|
1065
|
+
* @returns {{ family: string|null, cases: number, skipped: number, unparsed: number,
|
|
1066
|
+
* findings: { rule: string, line: number|null, name: string, detail: string }[] }}
|
|
1067
|
+
*/
|
|
1068
|
+
export function analyzeTestText(text, ext, extraAssertion = [], detectors = INDEPENDENCE_DETECTORS) {
|
|
1069
|
+
const family = FAMILY_BY_EXT[ext] || null;
|
|
1070
|
+
const rules = family && FAMILY_RULES[family];
|
|
1071
|
+
if (!rules) return { family: null, cases: 0, skipped: 0, unparsed: 0, findings: [] };
|
|
1072
|
+
const { noComments, noStrings } = maskSource(text, family);
|
|
1073
|
+
const { cases, unparsed } = rules.find(text, noStrings, noComments, ext);
|
|
1074
|
+
const lineOf = lineIndex(text);
|
|
1075
|
+
const findings = [];
|
|
1076
|
+
let skipped = 0;
|
|
1077
|
+
for (const c of cases) {
|
|
1078
|
+
if (c.skipped) { skipped++; continue; }
|
|
1079
|
+
const nsBody = noStrings.slice(c.bodyStart, c.bodyEnd);
|
|
1080
|
+
const ncBody = noComments.slice(c.bodyStart, c.bodyEnd);
|
|
1081
|
+
let tokens = countMatches(rules.tokens, nsBody);
|
|
1082
|
+
for (const re of extraAssertion) tokens += countMatches(re, nsBody);
|
|
1083
|
+
let taut = 0;
|
|
1084
|
+
for (const re of rules.taut) taut += countMatches(re, ncBody);
|
|
1085
|
+
const regexTaut = taut;
|
|
1086
|
+
taut += detectors.count(family, ncBody, nsBody, c.name);
|
|
1087
|
+
const real = Math.max(0, tokens - taut) + c.credit;
|
|
1088
|
+
if (real > 0) continue;
|
|
1089
|
+
if (taut === 0) {
|
|
1090
|
+
findings.push({ rule: 'no-assertion', line: lineOf(c.idx), name: c.name, detail: 'the body contains nothing that can fail an assertion' });
|
|
1091
|
+
continue;
|
|
1092
|
+
}
|
|
1093
|
+
const hits = detectors.find(family, ncBody, nsBody, c.name);
|
|
1094
|
+
const forms = [...new Set(hits.map((h) => h.form))];
|
|
1095
|
+
const finding = { rule: 'tautology', line: lineOf(c.idx), name: c.name, detail: 'its only assertion(s) can never fail' };
|
|
1096
|
+
if (forms.length > 0) {
|
|
1097
|
+
const parts = forms.map((f) => FORM_DETAIL[f]);
|
|
1098
|
+
if (regexTaut > 0) parts.unshift('an assertion that can never fail');
|
|
1099
|
+
finding.detail = `its only assertion(s) are not independent of the code under test: ${parts.join('; ')} (see verification-oracle)`;
|
|
1100
|
+
finding.forms = forms;
|
|
1101
|
+
finding.assertions = hits.map((h) => ({ line: lineOf(c.bodyStart + h.offset), form: h.form }));
|
|
1102
|
+
}
|
|
1103
|
+
findings.push(finding);
|
|
1104
|
+
}
|
|
1105
|
+
if (cases.length > 0 && skipped === cases.length) {
|
|
1106
|
+
findings.push({ rule: 'all-skipped', line: null, name: '(file)', detail: `every test in this file is skipped or todo (${skipped})` });
|
|
1107
|
+
}
|
|
1108
|
+
return { family, cases: cases.length, skipped, unparsed, findings };
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1112
|
+
// Self-test — runs on EVERY invocation, before a single project file is read.
|
|
1113
|
+
// A scanner that always says "clean" and a scanner that works print the same report;
|
|
1114
|
+
// so the scanner must first catch fakes it was handed and let real tests through.
|
|
1115
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1116
|
+
|
|
1117
|
+
const SELF_TEST = [
|
|
1118
|
+
{ ext: 'js', rules: ['no-assertion'], text: "it('does nothing', () => { const a = 1; });\n" },
|
|
1119
|
+
{ ext: 'js', rules: ['tautology'], text: "it('always passes', () => { expect(true).toBe(true); });\n" },
|
|
1120
|
+
{ ext: 'js', rules: [], text: "it('adds', () => { expect(add(1, 2)).toBe(3); });\ntest('t', async () => { await expect(f()).rejects.toThrow(); });\n" },
|
|
1121
|
+
{ ext: 'js', rules: ['all-skipped'], text: "it.skip('a', () => { expect(1).toBe(2); });\nit.todo('b');\n" },
|
|
1122
|
+
{ ext: 'js', rules: ['no-assertion'], text: "it('commented out', () => {\n // expect(a).toBe(b);\n const s = \"expect(a).toBe(b)\";\n});\n" },
|
|
1123
|
+
// XSPEC-470: an expected value that is not independent of the code under test.
|
|
1124
|
+
{ ext: 'js', rules: ['tautology'], text: "it('totals', () => { expect(calculateTotal(items)).toBe(calculateTotal(items)); });\n" },
|
|
1125
|
+
{ ext: 'js', rules: ['tautology'], text: "it('totals', () => { expect(calculateTotal(items)).toBe(items.reduce((s, i) => s + i.price, 0)); });\n" },
|
|
1126
|
+
{ ext: 'js', rules: ['tautology'], text: "it('names', () => { expect(namesOf(users)).toEqual(users.map((u) => u.name)); });\n" },
|
|
1127
|
+
// A name set on an earlier line is a value from an earlier moment: never looked through (XSPEC-470, third review).
|
|
1128
|
+
{ ext: 'js', rules: [], text: "it('totals', () => {\n const expected = items.reduce((s, i) => s + i.price, 0);\n expect(calculateTotal(items)).toBe(expected);\n});\n" },
|
|
1129
|
+
{ ext: 'js', rules: [], text: "it('freezing changes no price', () => {\n const before = items.map((i) => i.price);\n freezeCart(items);\n expect(pricesOf(items)).toEqual(before);\n});\n" },
|
|
1130
|
+
{ ext: 'js', rules: [], text: "it('pushing a user keeps the old names', () => {\n const result = users.map((u) => u.name);\n users.push(extra);\n expect(namesOf(users)).toEqual(result);\n});\n" },
|
|
1131
|
+
{ ext: 'js', rules: [], text: "it('totals', () => { expect(calculateTotal([{ price: 10 }, { price: 5 }])).toBe(15); });\n" },
|
|
1132
|
+
{ ext: 'js', rules: [], text: "it('totals', () => { expect(calculateTotal(a)).toBe(calculateTotal(b)); });\n" },
|
|
1133
|
+
{ ext: 'js', rules: [], text: "it('totals', () => { expect(calculateTotal(cart)).toBe(items.reduce((s, i) => s + i.price, 0)); });\n" },
|
|
1134
|
+
{ ext: 'js', rules: [], text: "it('is deterministic', () => { expect(calculateTotal(items)).toBe(calculateTotal(items)); });\n" },
|
|
1135
|
+
{ ext: 'js', rules: [], text: "it('changes nothing', () => {\n const before = snapshot(dir);\n preview(dir);\n expect(snapshot(dir)).toEqual(before);\n});\n" },
|
|
1136
|
+
{ ext: 'js', rules: [], text: "it('totals', () => { expect(calculateTotal(items)).toBe(calculateTotal(items)); expect(calculateTotal([])).toBe(0); });\n" },
|
|
1137
|
+
{ ext: 'js', rules: [], text: "it('totals', () => { expect(calculateTotal(first)).not.toBe(calculateTotal(first)); });\n" },
|
|
1138
|
+
// XSPEC-470: look-alikes the rule must let through (the false alarms the first review measured).
|
|
1139
|
+
{ ext: 'js', rules: [], text: "it('prices', () => { expect(priceOf(ids)).toEqual(ids.map((id) => KNOWN_PRICES[id])); });\n" },
|
|
1140
|
+
{ ext: 'js', rules: [], text: "it('active', () => { expect(activeOf(users)).toEqual(users.filter((u) => u.id === 2)); });\n" },
|
|
1141
|
+
{ ext: 'js', rules: [], text: "it('renders', () => { expect(render(now())).toBe(render(now())); });\n" },
|
|
1142
|
+
// XSPEC-470: the second review's false alarms, and the neighbours of both rounds (all must stay silent).
|
|
1143
|
+
{ ext: 'js', rules: [], text: "it('round trip', () => { expect(parse(serialize(rows))).toEqual(rows.map((r) => r)); });\n" },
|
|
1144
|
+
{ ext: 'js', rules: [], text: "it('round trip, callback computes', () => { expect(parse(serialize(rows))).toEqual(rows.map((r) => r.id)); });\n" },
|
|
1145
|
+
{ ext: 'js', rules: [], text: "it('identity callback', () => { expect(clone(input)).toEqual(input.map((x) => x)); });\n" },
|
|
1146
|
+
{ ext: 'js', rules: [], text: "it('shallow copy callback', () => { expect(clone(users)).toEqual(users.map((u) => ({ ...u }))); });\n" },
|
|
1147
|
+
{ ext: 'js', rules: [], text: "it('pairs put back', () => { expect(clone(pairs)).toEqual(pairs.map(([k, v]) => [k, v])); });\n" },
|
|
1148
|
+
{ ext: 'js', rules: [], text: "it('rows put back', () => { expect(clone(rows)).toEqual(rows.map(({ a, b }) => ({ a, b }))); });\n" },
|
|
1149
|
+
{ ext: 'js', rules: ['tautology'], text: "it('expected value wrapped', () => { expect(total(items)).toBe(Number(items.reduce((s, i) => s + i.price, 0))); });\n" },
|
|
1150
|
+
{ ext: 'js', rules: ['tautology'], text: "it('pairs swapped', () => { expect(flip(pairs)).toEqual(pairs.map(([k, v]) => [v, k])); });\n" },
|
|
1151
|
+
{ ext: 'js', rules: [], text: "it('shallow copy callback, block', () => { expect(clone(users)).toEqual(users.map((u) => { return { ...u }; })); });\n" },
|
|
1152
|
+
{ ext: 'js', rules: [], text: "it('property of the result', () => { expect(sortUsers(users).length).toBe(users.filter((u) => u.name).length); });\n" },
|
|
1153
|
+
{ ext: 'js', rules: [], text: "it('helper outside the callback', () => { expect(calculateTotal(items)).toBe(items.reduce((s, i) => s + priceOf(i), 0)); });\n" },
|
|
1154
|
+
{ ext: 'js', rules: [], text: "it('literal in the callback', () => { expect(doubled(xs)).toEqual(xs.map((x) => x * 2)); });\n" },
|
|
1155
|
+
{ ext: 'js', rules: [], text: "it('constant outside the callback', () => { expect(calculateTotal(items)).toBe(items.reduce((s, i) => s + i.price * TAX_RATE, 0)); });\n" },
|
|
1156
|
+
{ ext: 'js', rules: [], text: "it('new inside the call', () => { expect(render(new Date())).toBe(render(new Date())); });\n" },
|
|
1157
|
+
// ...and what must still be named after the narrowing.
|
|
1158
|
+
{ ext: 'js', rules: ['tautology'], text: "it('active', () => { assert.deepStrictEqual(activeOf(accounts), accounts.filter((a) => a.active)); });\n" },
|
|
1159
|
+
{ ext: 'js', rules: ['tautology'], text: "it('names', () => { expect(namesOf(users)).toEqual(users.map(({ name }) => name)); });\n" },
|
|
1160
|
+
{ ext: 'js', rules: ['tautology'], text: "it('destructured reduce', () => { expect(calculateTotal(items)).toBe(items.reduce((s, { price }) => s + price, 0)); });\n" },
|
|
1161
|
+
{ ext: 'js', rules: ['tautology'], text: "it('function expression', () => { expect(calculateTotal(items)).toBe(items.reduce(function (s, i) { return s + i.price; }, 0)); });\n" },
|
|
1162
|
+
{ ext: 'js', rules: ['tautology'], text: "it('block arrow', () => { expect(calculateTotal(items)).toBe(items.reduce((s, i) => { return s + i.qty * i.price; }, 0)); });\n" },
|
|
1163
|
+
{ ext: 'py', rules: ['no-assertion'], text: "def test_nothing():\n x = 1\n pass\n" },
|
|
1164
|
+
{ ext: 'py', rules: ['tautology'], text: "def test_true():\n assert True\n" },
|
|
1165
|
+
{ ext: 'py', rules: [], text: "def test_ok():\n assert add(1, 2) == 3\n\n\ndef test_raises():\n with pytest.raises(ValueError):\n f()\n" },
|
|
1166
|
+
{ ext: 'go', rules: ['no-assertion'], text: 'func TestNothing(t *testing.T) {\n\tx := 1\n\t_ = x\n}\n' },
|
|
1167
|
+
{ ext: 'go', rules: [], text: 'func TestOk(t *testing.T) {\n\tif got := Add(1, 2); got != 3 {\n\t\tt.Errorf("got %d", got)\n\t}\n}\n' },
|
|
1168
|
+
{ ext: 'java', rules: ['no-assertion'], text: 'class A {\n @Test\n public void doesNothing() {\n int a = 1;\n }\n}\n' },
|
|
1169
|
+
{ ext: 'java', rules: ['tautology'], text: 'class A {\n @Test\n void t() {\n assertTrue(true);\n }\n}\n' },
|
|
1170
|
+
{ ext: 'java', rules: [], text: 'class A {\n @Test\n void t() {\n assertEquals(3, add(1, 2));\n }\n}\n' },
|
|
1171
|
+
{ ext: 'rs', rules: ['no-assertion'], text: '#[test]\nfn does_nothing() {\n let a = 1;\n}\n' },
|
|
1172
|
+
{ ext: 'rs', rules: [], text: '#[test]\nfn adds() {\n assert_eq!(add(1, 2), 3);\n}\n' },
|
|
1173
|
+
{ ext: 'rb', rules: ['no-assertion'], text: "describe 'x' do\n it 'does nothing' do\n a = 1\n end\nend\n" },
|
|
1174
|
+
{ ext: 'rb', rules: [], text: "describe 'x' do\n it 'adds' do\n expect(add(1, 2)).to eq(3)\n end\nend\n" },
|
|
1175
|
+
{ ext: 'php', rules: ['no-assertion'], text: "<?php\nclass T {\n public function testNothing() {\n $a = 1;\n }\n}\n" },
|
|
1176
|
+
{ ext: 'cpp', rules: ['no-assertion'], text: 'TEST(Suite, Nothing) {\n int a = 1;\n}\n' },
|
|
1177
|
+
{ ext: 'cpp', rules: [], text: 'TEST(Suite, Adds) {\n EXPECT_EQ(3, Add(1, 2));\n}\n' }
|
|
1178
|
+
];
|
|
1179
|
+
|
|
1180
|
+
/** @returns {string[]} what went wrong; empty = the scanner behaves on every known sample */
|
|
1181
|
+
export function selfTest() {
|
|
1182
|
+
const problems = [];
|
|
1183
|
+
for (const [i, s] of SELF_TEST.entries()) {
|
|
1184
|
+
const got = analyzeTestText(s.text, s.ext).findings.map((f) => f.rule).sort();
|
|
1185
|
+
const want = [...s.rules].sort();
|
|
1186
|
+
if (JSON.stringify(got) !== JSON.stringify(want)) {
|
|
1187
|
+
problems.push(`self-test #${i} (.${s.ext}): expected [${want.join(', ')}], got [${got.join(', ')}]`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return problems;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1194
|
+
// Run
|
|
1195
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
1196
|
+
|
|
1197
|
+
function readAssertionPatterns(root) {
|
|
1198
|
+
const file = join(root, POLICY_FILE);
|
|
1199
|
+
if (!existsSync(file)) return { patterns: [], problems: [] };
|
|
1200
|
+
try {
|
|
1201
|
+
const raw = JSON.parse(readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
1202
|
+
const list = Array.isArray(raw.assertionPatterns) ? raw.assertionPatterns : [];
|
|
1203
|
+
const patterns = [];
|
|
1204
|
+
const problems = [];
|
|
1205
|
+
for (const s of list) {
|
|
1206
|
+
try { patterns.push(new RegExp(String(s), 'g')); } catch (e) { problems.push(`assertionPatterns: "${s}" is not a valid regular expression (${e.message})`); }
|
|
1207
|
+
}
|
|
1208
|
+
return { patterns, problems };
|
|
1209
|
+
} catch {
|
|
1210
|
+
return { patterns: [], problems: [] }; // loadPolicy already reported an unreadable file
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
// Directories under a test tree that hold data, not tests.
|
|
1215
|
+
const FIXTURE_DIRS = new Set(['fixtures', 'fixture', '__fixtures__', '__snapshots__', 'snapshots', 'testdata', '__mocks__']);
|
|
1216
|
+
|
|
1217
|
+
export function scan(root, { staged = false } = {}) {
|
|
1218
|
+
const { policy, problems } = loadPolicy(root);
|
|
1219
|
+
const extra = readAssertionPatterns(root);
|
|
1220
|
+
problems.push(...extra.problems);
|
|
1221
|
+
let files;
|
|
1222
|
+
if (staged) {
|
|
1223
|
+
const s = stagedFiles(root);
|
|
1224
|
+
if (s.error) return { error: `cannot read the staged files: ${s.error}`, problems };
|
|
1225
|
+
files = s.files;
|
|
1226
|
+
} else {
|
|
1227
|
+
files = walkFiles(root, policy);
|
|
1228
|
+
}
|
|
1229
|
+
const result = {
|
|
1230
|
+
mode: staged ? 'staged' : 'all', problems, testFiles: 0, cases: 0, skippedCases: 0, unparsed: 0,
|
|
1231
|
+
findings: [], unsupported: [], unreadable: []
|
|
1232
|
+
};
|
|
1233
|
+
for (const rel of files) {
|
|
1234
|
+
if (classifyPath(rel, policy).kind !== 'test') continue;
|
|
1235
|
+
const base = rel.split('/').pop();
|
|
1236
|
+
if (policy.nonCodeNames.includes(base) || base === 'conftest.py' || base.startsWith('.')) continue;
|
|
1237
|
+
if (rel.split('/').some((d) => FIXTURE_DIRS.has(d))) continue;
|
|
1238
|
+
const ext = extOfPath(rel);
|
|
1239
|
+
// A test-directory file that is not code at all (a JSON fixture, a snapshot) is not a test case holder.
|
|
1240
|
+
if (!FAMILY_BY_EXT[ext]) {
|
|
1241
|
+
if (policy.sourceExtensions.includes(ext) || !policy.nonCodeExtensions.includes(ext)) result.unsupported.push(rel);
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
const r = readText(join(root, rel));
|
|
1245
|
+
if (r.skipped) { if (!r.quiet) result.unreadable.push(`${rel} (${r.skipped})`); continue; }
|
|
1246
|
+
const a = analyzeTestText(r.text, ext, extra.patterns);
|
|
1247
|
+
result.testFiles++;
|
|
1248
|
+
result.cases += a.cases;
|
|
1249
|
+
result.skippedCases += a.skipped;
|
|
1250
|
+
result.unparsed += a.unparsed;
|
|
1251
|
+
for (const f of a.findings) result.findings.push({ file: rel, ...f });
|
|
1252
|
+
}
|
|
1253
|
+
return result;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
function report(r) {
|
|
1257
|
+
const out = [];
|
|
1258
|
+
for (const p of r.problems) out.push(` ! ${p}`);
|
|
1259
|
+
out.push(`check-anti-fake-tests: scanned ${r.testFiles} test file(s), ${r.cases} test case(s) (${r.mode === 'staged' ? 'staged files only' : 'whole project'})`);
|
|
1260
|
+
for (const f of r.findings) {
|
|
1261
|
+
out.push(` ✗ ${f.file}${f.line ? `:${f.line}` : ''} ${f.rule} "${f.name}" — ${f.detail}`);
|
|
1262
|
+
}
|
|
1263
|
+
if (r.unsupported.length > 0) {
|
|
1264
|
+
const exts = [...new Set(r.unsupported.map((p) => `.${extOfPath(p) || '(none)'}`))].join(', ');
|
|
1265
|
+
out.push(` · NOT scanned — no rule for this language (${exts}): ${r.unsupported.slice(0, 5).join(', ')}${r.unsupported.length > 5 ? `, +${r.unsupported.length - 5} more` : ''}`);
|
|
1266
|
+
out.push(' These files were not judged. Fake tests in them would not be found by this script.');
|
|
1267
|
+
}
|
|
1268
|
+
for (const u of r.unreadable) out.push(` · NOT scanned — ${u}`);
|
|
1269
|
+
if (r.unparsed > 0) out.push(` · ${r.unparsed} test call(s) could not be parsed (unbalanced brackets) and were not judged`);
|
|
1270
|
+
if (r.testFiles === 0 && r.unsupported.length === 0 && r.mode === 'all') out.push(' · no test files found — nothing was measured');
|
|
1271
|
+
out.push(r.findings.length > 0 ? `RESULT: ${r.findings.length} finding(s)` : 'RESULT: no fake tests found among the files scanned');
|
|
1272
|
+
return out.join('\n');
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
export function main(argv, root = process.cwd()) {
|
|
1276
|
+
const bad = selfTest();
|
|
1277
|
+
if (bad.length > 0) {
|
|
1278
|
+
console.error('check-anti-fake-tests: the scanner failed its own self-test, so its result would mean nothing:');
|
|
1279
|
+
for (const b of bad) console.error(` ${b}`);
|
|
1280
|
+
return 2;
|
|
1281
|
+
}
|
|
1282
|
+
const r = scan(root, { staged: argv.includes('--staged') });
|
|
1283
|
+
if (r.error) {
|
|
1284
|
+
console.error(`check-anti-fake-tests: ${r.error}`);
|
|
1285
|
+
return 2;
|
|
1286
|
+
}
|
|
1287
|
+
console.log(argv.includes('--json') ? JSON.stringify(r, null, 2) : report(r));
|
|
1288
|
+
return r.findings.length > 0 ? 1 : 0;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
if (isMain(import.meta.url)) process.exitCode = main(process.argv.slice(2));
|