octocode-cli 1.2.6 → 1.2.8
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/LICENSE +21 -63
- package/README.md +85 -142
- package/out/octocode-cli.js +7063 -6934
- package/package.json +8 -6
- package/skills/README.md +97 -120
- package/skills/octocode-code-engineer/.claude/settings.local.json +18 -0
- package/skills/octocode-code-engineer/.octocode/rfc/RFC-code-engineer-weakness-fixes.md +255 -0
- package/skills/octocode-code-engineer/.plan/VALIDATED_PLAN.md +223 -0
- package/skills/octocode-code-engineer/README.md +178 -0
- package/skills/octocode-code-engineer/SKILL.md +418 -0
- package/skills/octocode-code-engineer/coverage/architecture.ts.html +7828 -0
- package/skills/octocode-code-engineer/coverage/ast-helpers.ts.html +211 -0
- package/skills/octocode-code-engineer/coverage/ast-search.ts.html +1795 -0
- package/skills/octocode-code-engineer/coverage/base.css +224 -0
- package/skills/octocode-code-engineer/coverage/block-navigation.js +87 -0
- package/skills/octocode-code-engineer/coverage/cache.ts.html +376 -0
- package/skills/octocode-code-engineer/coverage/cli.ts.html +982 -0
- package/skills/octocode-code-engineer/coverage/clover.xml +3217 -0
- package/skills/octocode-code-engineer/coverage/collect-effects.ts.html +664 -0
- package/skills/octocode-code-engineer/coverage/collect-input-sources.ts.html +577 -0
- package/skills/octocode-code-engineer/coverage/collect-performance.ts.html +331 -0
- package/skills/octocode-code-engineer/coverage/collect-prototype-pollution.ts.html +421 -0
- package/skills/octocode-code-engineer/coverage/collect-security.ts.html +604 -0
- package/skills/octocode-code-engineer/coverage/collect-test-profile.ts.html +589 -0
- package/skills/octocode-code-engineer/coverage/coverage-final.json +30 -0
- package/skills/octocode-code-engineer/coverage/dependencies.ts.html +997 -0
- package/skills/octocode-code-engineer/coverage/dependency-summary.ts.html +688 -0
- package/skills/octocode-code-engineer/coverage/discovery.ts.html +322 -0
- package/skills/octocode-code-engineer/coverage/favicon.png +0 -0
- package/skills/octocode-code-engineer/coverage/graph-analytics.ts.html +1510 -0
- package/skills/octocode-code-engineer/coverage/index.html +536 -0
- package/skills/octocode-code-engineer/coverage/index.ts.html +826 -0
- package/skills/octocode-code-engineer/coverage/metrics.ts.html +553 -0
- package/skills/octocode-code-engineer/coverage/pipeline.ts.html +2044 -0
- package/skills/octocode-code-engineer/coverage/prettify.css +1 -0
- package/skills/octocode-code-engineer/coverage/prettify.js +2 -0
- package/skills/octocode-code-engineer/coverage/report-analysis.ts.html +1570 -0
- package/skills/octocode-code-engineer/coverage/report-writer.ts.html +1102 -0
- package/skills/octocode-code-engineer/coverage/security-detectors.ts.html +1747 -0
- package/skills/octocode-code-engineer/coverage/semantic-detectors.ts.html +2152 -0
- package/skills/octocode-code-engineer/coverage/semantic.ts.html +1897 -0
- package/skills/octocode-code-engineer/coverage/sort-arrow-sprite.png +0 -0
- package/skills/octocode-code-engineer/coverage/sorter.js +210 -0
- package/skills/octocode-code-engineer/coverage/summary-md.ts.html +1222 -0
- package/skills/octocode-code-engineer/coverage/test-quality-detectors.ts.html +1039 -0
- package/skills/octocode-code-engineer/coverage/tree-sitter-analyzer.ts.html +955 -0
- package/skills/octocode-code-engineer/coverage/ts-analyzer.ts.html +1213 -0
- package/skills/octocode-code-engineer/coverage/types.ts.html +2473 -0
- package/skills/octocode-code-engineer/coverage/utils.ts.html +820 -0
- package/skills/octocode-code-engineer/eslint.config.mjs +54 -0
- package/skills/octocode-code-engineer/minify-scripts.mjs +32 -0
- package/skills/octocode-code-engineer/package.json +54 -0
- package/skills/octocode-code-engineer/references/agent-ast-reading-rfc.md +95 -0
- package/skills/octocode-code-engineer/references/architecture-techniques.md +121 -0
- package/skills/octocode-code-engineer/references/ast-search.md +210 -0
- package/skills/octocode-code-engineer/references/ast-tree-search.md +151 -0
- package/skills/octocode-code-engineer/references/cli-reference.md +167 -0
- package/skills/octocode-code-engineer/references/concepts.md +107 -0
- package/skills/octocode-code-engineer/references/finding-categories.md +128 -0
- package/skills/octocode-code-engineer/references/improvement-roadmap.md +304 -0
- package/skills/octocode-code-engineer/references/output-files.md +144 -0
- package/skills/octocode-code-engineer/references/playbooks.md +204 -0
- package/skills/octocode-code-engineer/references/present-results.md +136 -0
- package/skills/octocode-code-engineer/references/tool-workflows.md +566 -0
- package/skills/octocode-code-engineer/references/validate-investigate.md +225 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependencies.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependency-summary.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/discovery.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/graph-analytics.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/helpers.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/metrics.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-sitter.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/ts-analyzer.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/chains.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/effects.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/input-sources.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/performance.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/prototype-pollution.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/test-profile.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/is-direct-run.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/utils.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/code-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cohesion.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/coupling.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cycle.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/dead-code.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/import-style.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/shared.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/test-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cache.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cli.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/main.js +2 -0
- package/skills/octocode-code-engineer/scripts/reporting/analysis.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/summary-md.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/writer.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/constants.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/interfaces.js +1 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.test.ts +545 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.ts +406 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.test.ts +566 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.ts +257 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.test.ts +420 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.ts +87 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.test.ts +449 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.ts +534 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.test.ts +1533 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.ts +830 -0
- package/skills/octocode-code-engineer/src/ast/helpers.test.ts +185 -0
- package/skills/octocode-code-engineer/src/ast/helpers.ts +62 -0
- package/skills/octocode-code-engineer/src/ast/metrics.test.ts +304 -0
- package/skills/octocode-code-engineer/src/ast/metrics.ts +204 -0
- package/skills/octocode-code-engineer/src/ast/search.test.ts +647 -0
- package/skills/octocode-code-engineer/src/ast/search.ts +648 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.test.ts +199 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.ts +392 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.test.ts +407 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.ts +402 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.test.ts +1864 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.ts +509 -0
- package/skills/octocode-code-engineer/src/collectors/chains.ts +74 -0
- package/skills/octocode-code-engineer/src/collectors/effects.test.ts +490 -0
- package/skills/octocode-code-engineer/src/collectors/effects.ts +332 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.test.ts +144 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.ts +196 -0
- package/skills/octocode-code-engineer/src/collectors/performance.test.ts +82 -0
- package/skills/octocode-code-engineer/src/collectors/performance.ts +141 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.test.ts +55 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.ts +162 -0
- package/skills/octocode-code-engineer/src/collectors/security.test.ts +124 -0
- package/skills/octocode-code-engineer/src/collectors/security.ts +309 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.test.ts +97 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.ts +269 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.test.ts +32 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.ts +13 -0
- package/skills/octocode-code-engineer/src/common/utils.test.ts +463 -0
- package/skills/octocode-code-engineer/src/common/utils.ts +304 -0
- package/skills/octocode-code-engineer/src/detectors/code-quality.ts +966 -0
- package/skills/octocode-code-engineer/src/detectors/cohesion.ts +539 -0
- package/skills/octocode-code-engineer/src/detectors/coupling.ts +323 -0
- package/skills/octocode-code-engineer/src/detectors/cycle.ts +349 -0
- package/skills/octocode-code-engineer/src/detectors/dead-code.ts +320 -0
- package/skills/octocode-code-engineer/src/detectors/import-style.ts +376 -0
- package/skills/octocode-code-engineer/src/detectors/index.test.ts +3061 -0
- package/skills/octocode-code-engineer/src/detectors/index.ts +88 -0
- package/skills/octocode-code-engineer/src/detectors/security.test.ts +882 -0
- package/skills/octocode-code-engineer/src/detectors/security.ts +821 -0
- package/skills/octocode-code-engineer/src/detectors/semantic.ts +758 -0
- package/skills/octocode-code-engineer/src/detectors/shared.ts +49 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.test.ts +388 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.ts +367 -0
- package/skills/octocode-code-engineer/src/index.test.ts +4425 -0
- package/skills/octocode-code-engineer/src/index.ts +403 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.test.ts +199 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.ts +130 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.test.ts +493 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.ts +344 -0
- package/skills/octocode-code-engineer/src/pipeline/main.test.ts +174 -0
- package/skills/octocode-code-engineer/src/pipeline/main.ts +1074 -0
- package/skills/octocode-code-engineer/src/pipeline.test.ts +84 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.test.ts +782 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.ts +688 -0
- package/skills/octocode-code-engineer/src/reporting/output-contract.test.ts +463 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.test.ts +421 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.ts +714 -0
- package/skills/octocode-code-engineer/src/reporting/writer.ts +430 -0
- package/skills/octocode-code-engineer/src/sanity.test.ts +47 -0
- package/skills/octocode-code-engineer/src/types/constants.ts +248 -0
- package/skills/octocode-code-engineer/src/types/index.ts +80 -0
- package/skills/octocode-code-engineer/src/types/interfaces.ts +682 -0
- package/skills/octocode-code-engineer/tsconfig.json +17 -0
- package/skills/octocode-code-engineer/vitest.config.ts +8 -0
- package/skills/octocode-documentation-writer/README.md +113 -0
- package/skills/octocode-documentation-writer/SKILL.md +886 -0
- package/skills/octocode-documentation-writer/references/agent-discovery-analysis.md +453 -0
- package/skills/octocode-documentation-writer/references/agent-documentation-writer.md +255 -0
- package/skills/octocode-documentation-writer/references/agent-engineer-questions.md +247 -0
- package/skills/octocode-documentation-writer/references/agent-orchestrator.md +370 -0
- package/skills/octocode-documentation-writer/references/agent-qa-validator.md +227 -0
- package/skills/octocode-documentation-writer/references/agent-researcher.md +250 -0
- package/skills/octocode-documentation-writer/schemas/analysis-schema.json +886 -0
- package/skills/octocode-documentation-writer/schemas/discovery-tasks.json +96 -0
- package/skills/octocode-documentation-writer/schemas/documentation-structure.json +373 -0
- package/skills/octocode-documentation-writer/schemas/partial-discovery-schema.json +102 -0
- package/skills/octocode-documentation-writer/schemas/partial-research-schema.json +98 -0
- package/skills/octocode-documentation-writer/schemas/qa-results-schema.json +113 -0
- package/skills/octocode-documentation-writer/schemas/questions-schema.json +228 -0
- package/skills/octocode-documentation-writer/schemas/research-schema.json +104 -0
- package/skills/octocode-documentation-writer/schemas/state-schema.json +222 -0
- package/skills/octocode-documentation-writer/schemas/work-assignments-schema.json +74 -0
- package/skills/octocode-plan/SKILL.md +122 -116
- package/skills/octocode-prompt-optimizer/SKILL.md +617 -0
- package/skills/octocode-pull-request-reviewer/README.md +249 -0
- package/skills/octocode-pull-request-reviewer/SKILL.md +479 -0
- package/skills/octocode-pull-request-reviewer/references/dependency-check.md +74 -0
- package/skills/octocode-pull-request-reviewer/references/domain-reviewers.md +24 -0
- package/skills/octocode-pull-request-reviewer/references/execution-lifecycle.md +441 -0
- package/skills/octocode-pull-request-reviewer/references/flow-analysis-protocol.md +64 -0
- package/skills/octocode-pull-request-reviewer/references/output-template.md +174 -0
- package/skills/octocode-pull-request-reviewer/references/parallel-agent-protocol.md +182 -0
- package/skills/octocode-pull-request-reviewer/references/review-guidelines.md +26 -0
- package/skills/octocode-pull-request-reviewer/references/verification-checklist.md +40 -0
- package/skills/octocode-research/.claude/settings.local.json +46 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/plan.md +312 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/research.md +212 -0
- package/skills/octocode-research/.octocode/plans/NODE_SERVER_START_PLAN.md +755 -0
- package/skills/octocode-research/.octocode/research/code-review/research.md +371 -0
- package/skills/octocode-research/.octocode/review/IMPROVEMENTS.md +391 -0
- package/skills/octocode-research/.octocode/review/REVIEW_PLAN.md +289 -0
- package/skills/octocode-research/.octocode/review/REVIEW_REPORT.md +356 -0
- package/skills/octocode-research/AGENTS.md +349 -0
- package/skills/octocode-research/README.md +494 -0
- package/skills/octocode-research/SKILL.md +652 -274
- package/skills/octocode-research/docs/API_REFERENCE.md +562 -0
- package/skills/octocode-research/docs/ARCHITECTURE.md +554 -0
- package/skills/octocode-research/docs/FLOWS.md +577 -0
- package/skills/octocode-research/docs/OVERVIEW.md +564 -0
- package/skills/octocode-research/docs/SERVER_FLOWS.md +631 -0
- package/skills/octocode-research/ecosystem.config.cjs +88 -0
- package/skills/octocode-research/eslint.config.mjs +27 -0
- package/skills/octocode-research/package.json +84 -0
- package/skills/octocode-research/references/GUARDRAILS.md +40 -0
- package/skills/octocode-research/references/PARALLEL_AGENT_PROTOCOL.md +178 -0
- package/skills/octocode-research/references/roast-prompt.md +149 -0
- package/skills/octocode-research/scripts/server-init.d.ts +2 -0
- package/skills/octocode-research/scripts/server-init.js +2 -0
- package/skills/octocode-research/scripts/server.d.ts +8 -0
- package/skills/octocode-research/scripts/server.js +445 -0
- package/skills/octocode-research/src/__tests__/integration/circuitBreaker.test.ts +205 -0
- package/skills/octocode-research/src/__tests__/integration/routes.test.ts +374 -0
- package/skills/octocode-research/src/__tests__/unit/circuitBreaker.test.ts +245 -0
- package/skills/octocode-research/src/__tests__/unit/errorHandler.test.ts +183 -0
- package/skills/octocode-research/src/__tests__/unit/httpPreprocess.test.ts +157 -0
- package/skills/octocode-research/src/__tests__/unit/logger.test.ts +143 -0
- package/skills/octocode-research/src/__tests__/unit/queryParser.test.ts +130 -0
- package/skills/octocode-research/src/__tests__/unit/responseBuilder.test.ts +469 -0
- package/skills/octocode-research/src/__tests__/unit/retry.test.ts +205 -0
- package/skills/octocode-research/src/index.ts +186 -0
- package/skills/octocode-research/src/mcpCache.ts +49 -0
- package/skills/octocode-research/src/middleware/errorHandler.ts +65 -0
- package/skills/octocode-research/src/middleware/logger.ts +61 -0
- package/skills/octocode-research/src/middleware/queryParser.ts +115 -0
- package/skills/octocode-research/src/middleware/readiness.ts +17 -0
- package/skills/octocode-research/src/routes/github.ts +197 -0
- package/skills/octocode-research/src/routes/local.ts +175 -0
- package/skills/octocode-research/src/routes/lsp.ts +177 -0
- package/skills/octocode-research/src/routes/package.ts +127 -0
- package/skills/octocode-research/src/routes/prompts.ts +138 -0
- package/skills/octocode-research/src/routes/tools.ts +677 -0
- package/skills/octocode-research/src/server-init.ts +363 -0
- package/skills/octocode-research/src/server.ts +285 -0
- package/skills/octocode-research/src/types/errorGuards.ts +151 -0
- package/skills/octocode-research/src/types/express.d.ts +76 -0
- package/skills/octocode-research/src/types/guards.ts +98 -0
- package/skills/octocode-research/src/types/mcp.ts +119 -0
- package/skills/octocode-research/src/types/responses.ts +199 -0
- package/skills/octocode-research/src/types/toolTypes.ts +33 -0
- package/skills/octocode-research/src/utils/asyncTimeout.ts +116 -0
- package/skills/octocode-research/src/utils/circuitBreaker.ts +492 -0
- package/skills/octocode-research/src/utils/colors.ts +53 -0
- package/skills/octocode-research/src/utils/errorQueue.ts +71 -0
- package/skills/octocode-research/src/utils/logEmoji.ts +103 -0
- package/skills/octocode-research/src/utils/logger.ts +413 -0
- package/skills/octocode-research/src/utils/resilience.ts +169 -0
- package/skills/octocode-research/src/utils/responseBuilder.ts +495 -0
- package/skills/octocode-research/src/utils/responseFactory.ts +100 -0
- package/skills/octocode-research/src/utils/responseParser.ts +272 -0
- package/skills/octocode-research/src/utils/retry.ts +280 -0
- package/skills/octocode-research/src/utils/routeFactory.ts +117 -0
- package/skills/octocode-research/src/utils/url.ts +20 -0
- package/skills/octocode-research/src/validation/httpPreprocess.ts +155 -0
- package/skills/octocode-research/src/validation/index.ts +2 -0
- package/skills/octocode-research/src/validation/schemas.ts +578 -0
- package/skills/octocode-research/src/validation/toolCallSchema.ts +132 -0
- package/skills/octocode-research/tsconfig.json +21 -0
- package/skills/octocode-research/tsdown.config.ts +42 -0
- package/skills/octocode-research/vitest.config.ts +20 -0
- package/skills/octocode-researcher/SKILL.md +461 -0
- package/skills/octocode-researcher/references/fallbacks.md +120 -0
- package/skills/{octocode-local-search → octocode-researcher}/references/tool-reference.md +132 -49
- package/skills/{octocode-local-search → octocode-researcher}/references/workflow-patterns.md +204 -4
- package/skills/octocode-rfc-generator/SKILL.md +223 -0
- package/skills/octocode-rfc-generator/references/rfc-template.md +193 -0
- package/skills/octocode-roast/SKILL.md +63 -21
- package/skills/octocode-implement/SKILL.md +0 -293
- package/skills/octocode-implement/references/execution-phases.md +0 -317
- package/skills/octocode-implement/references/tool-reference.md +0 -403
- package/skills/octocode-implement/references/workflow-patterns.md +0 -385
- package/skills/octocode-local-search/SKILL.md +0 -449
- package/skills/octocode-pr-review/SKILL.md +0 -391
- package/skills/octocode-pr-review/references/domain-reviewers.md +0 -105
- package/skills/octocode-pr-review/references/execution-lifecycle.md +0 -116
- package/skills/octocode-pr-review/references/research-flows.md +0 -75
- package/skills/octocode-research/references/tool-reference.md +0 -304
- package/skills/octocode-research/references/workflow-patterns.md +0 -325
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { DependencyState, Finding } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
export type FindingDraft = Omit<Finding, 'id'>;
|
|
4
|
+
|
|
5
|
+
const MAX_FINDINGS_PER_DETECTOR = 200;
|
|
6
|
+
|
|
7
|
+
export function canAddFinding(findings: FindingDraft[]): boolean {
|
|
8
|
+
return findings.length < MAX_FINDINGS_PER_DETECTOR;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function findImportLine(
|
|
12
|
+
state: DependencyState,
|
|
13
|
+
fromFile: string,
|
|
14
|
+
toFile: string
|
|
15
|
+
): { lineStart: number; lineEnd: number } {
|
|
16
|
+
const imports = state.importedSymbolsByFile.get(fromFile);
|
|
17
|
+
if (imports) {
|
|
18
|
+
for (const ref of imports) {
|
|
19
|
+
if (ref.resolvedModule === toFile && ref.lineStart) {
|
|
20
|
+
return {
|
|
21
|
+
lineStart: ref.lineStart,
|
|
22
|
+
lineEnd: ref.lineEnd ?? ref.lineStart,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const reexports = state.reExportsByFile.get(fromFile);
|
|
28
|
+
if (reexports) {
|
|
29
|
+
for (const ref of reexports) {
|
|
30
|
+
if (ref.resolvedModule === toFile && ref.lineStart) {
|
|
31
|
+
return {
|
|
32
|
+
lineStart: ref.lineStart,
|
|
33
|
+
lineEnd: ref.lineEnd ?? ref.lineStart,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { lineStart: 1, lineEnd: 1 };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function isLikelyEntrypoint(filePath: string): boolean {
|
|
42
|
+
const normalized = filePath.toLowerCase();
|
|
43
|
+
if (
|
|
44
|
+
/(^|\/)(index|main|app|server|cli|public)\.[mc]?[jt]sx?$/.test(normalized)
|
|
45
|
+
)
|
|
46
|
+
return true;
|
|
47
|
+
if (/\.(config)\.[mc]?[jt]sx?$/.test(normalized)) return true;
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
detectExcessiveMocking,
|
|
6
|
+
detectFakeTimersWithoutRestore,
|
|
7
|
+
detectFocusedTests,
|
|
8
|
+
detectLowAssertionDensity,
|
|
9
|
+
detectMissingMockRestoration,
|
|
10
|
+
detectMissingTestCleanup,
|
|
11
|
+
detectSharedMutableState,
|
|
12
|
+
detectTestNoAssertion,
|
|
13
|
+
} from './test-quality.js';
|
|
14
|
+
import { analyzeSourceFile } from '../ast/ts-analyzer.js';
|
|
15
|
+
import { DEFAULT_OPTS } from '../types/index.js';
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
DependencyProfile,
|
|
19
|
+
FileEntry,
|
|
20
|
+
FlowMaps,
|
|
21
|
+
PackageFileSummary,
|
|
22
|
+
} from '../types/index.js';
|
|
23
|
+
|
|
24
|
+
function parse(
|
|
25
|
+
code: string,
|
|
26
|
+
fileName = '/repo/src/feature.spec.ts'
|
|
27
|
+
): ts.SourceFile {
|
|
28
|
+
return ts.createSourceFile(fileName, code, ts.ScriptTarget.ESNext, true);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function emptySummary(): PackageFileSummary {
|
|
32
|
+
return {
|
|
33
|
+
fileCount: 0,
|
|
34
|
+
nodeCount: 0,
|
|
35
|
+
functionCount: 0,
|
|
36
|
+
flowCount: 0,
|
|
37
|
+
kindCounts: {},
|
|
38
|
+
functions: [],
|
|
39
|
+
flows: [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function emptyMaps(): FlowMaps {
|
|
44
|
+
return { flowMap: new Map(), controlMap: new Map() };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const emptyProfile: DependencyProfile = {
|
|
48
|
+
internalDependencies: [],
|
|
49
|
+
externalDependencies: [],
|
|
50
|
+
unresolvedDependencies: [],
|
|
51
|
+
declaredExports: [],
|
|
52
|
+
importedSymbols: [],
|
|
53
|
+
reExports: [],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function analyze(code: string): FileEntry {
|
|
57
|
+
const src = parse(code);
|
|
58
|
+
return analyzeSourceFile(
|
|
59
|
+
src,
|
|
60
|
+
'pkg',
|
|
61
|
+
emptySummary(),
|
|
62
|
+
{ ...DEFAULT_OPTS, root: '/repo' },
|
|
63
|
+
emptyMaps(),
|
|
64
|
+
[],
|
|
65
|
+
emptyProfile
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
describe('focused-test detector', () => {
|
|
70
|
+
it('flags it.only in test files', () => {
|
|
71
|
+
const file = analyze(`describe('suite', () => {
|
|
72
|
+
it.only('only test', () => {
|
|
73
|
+
expect(1).toBe(1);
|
|
74
|
+
});
|
|
75
|
+
});`);
|
|
76
|
+
const findings = detectFocusedTests([file]);
|
|
77
|
+
expect(findings).toHaveLength(1);
|
|
78
|
+
expect(findings[0].category).toBe('focused-test');
|
|
79
|
+
expect(findings[0].severity).toBe('medium');
|
|
80
|
+
expect(findings[0].lineStart).toBeGreaterThan(0);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('ignores plain tests without focus markers', () => {
|
|
84
|
+
const file = analyze(`it('normal test', () => {
|
|
85
|
+
expect(1).toBe(1);
|
|
86
|
+
});`);
|
|
87
|
+
const findings = detectFocusedTests([file]);
|
|
88
|
+
expect(findings).toHaveLength(0);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('fake timer detector', () => {
|
|
93
|
+
it('flags fake timer activation without restore', () => {
|
|
94
|
+
const file = analyze(`test('timer behavior', () => {
|
|
95
|
+
jest.useFakeTimers();
|
|
96
|
+
setTimeout(() => {}, 1000);
|
|
97
|
+
setTimeout(() => {}, 1000);
|
|
98
|
+
});`);
|
|
99
|
+
const findings = detectFakeTimersWithoutRestore([file]);
|
|
100
|
+
expect(findings).toHaveLength(1);
|
|
101
|
+
expect(findings[0].category).toBe('fake-timer-no-restore');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('skips files that restore fake timers', () => {
|
|
105
|
+
const file = analyze(`test('timer behavior', () => {
|
|
106
|
+
vi.useFakeTimers();
|
|
107
|
+
vi.useRealTimers();
|
|
108
|
+
});`);
|
|
109
|
+
const findings = detectFakeTimersWithoutRestore([file]);
|
|
110
|
+
expect(findings).toHaveLength(0);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('mock restoration detector', () => {
|
|
115
|
+
it('flags spy that is never restored', () => {
|
|
116
|
+
const file = analyze(`test('mocked spy', () => {
|
|
117
|
+
const nowSpy = jest.spyOn(Date, 'now').mockReturnValue(0);
|
|
118
|
+
expect(nowSpy).toBeDefined();
|
|
119
|
+
});`);
|
|
120
|
+
const findings = detectMissingMockRestoration([file]);
|
|
121
|
+
expect(findings).toHaveLength(1);
|
|
122
|
+
expect(findings[0].category).toBe('missing-mock-restoration');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('skips files with explicit spy restore', () => {
|
|
126
|
+
const file = analyze(`test('mocked spy', () => {
|
|
127
|
+
const nowSpy = jest.spyOn(Date, 'now').mockReturnValue(0);
|
|
128
|
+
nowSpy.mockRestore();
|
|
129
|
+
});`);
|
|
130
|
+
const findings = detectMissingMockRestoration([file]);
|
|
131
|
+
expect(findings).toHaveLength(0);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('does not treat clear/reset all mocks as a restore', () => {
|
|
135
|
+
const file = analyze(`test('mocked spy', () => {
|
|
136
|
+
const nowSpy = jest.spyOn(Date, 'now').mockReturnValue(0);
|
|
137
|
+
jest.clearAllMocks();
|
|
138
|
+
});`);
|
|
139
|
+
const findings = detectMissingMockRestoration([file]);
|
|
140
|
+
expect(findings).toHaveLength(1);
|
|
141
|
+
expect(findings[0].category).toBe('missing-mock-restoration');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('still reports spies not restored when some spies are restored', () => {
|
|
145
|
+
const file = analyze(`test('multiple spies', () => {
|
|
146
|
+
const nowSpy = jest.spyOn(Date, 'now').mockReturnValue(0);
|
|
147
|
+
const randomSpy = jest.spyOn(Math, 'random');
|
|
148
|
+
nowSpy.mockRestore();
|
|
149
|
+
expect(randomSpy).toBeDefined();
|
|
150
|
+
});`);
|
|
151
|
+
const findings = detectMissingMockRestoration([file]);
|
|
152
|
+
expect(findings).toHaveLength(1);
|
|
153
|
+
expect(findings[0].category).toBe('missing-mock-restoration');
|
|
154
|
+
expect(findings[0].lineStart).toBe(3);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('skips non-restorable mocks', () => {
|
|
158
|
+
const file = analyze(`test('module mock', () => {
|
|
159
|
+
jest.mock('path');
|
|
160
|
+
});`);
|
|
161
|
+
const findings = detectMissingMockRestoration([file] as [FileEntry]);
|
|
162
|
+
expect(findings).toHaveLength(0);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('low assertion density detector', () => {
|
|
167
|
+
it('flags file with tests having <1 assertion per test on average', () => {
|
|
168
|
+
const file = analyze(`describe('suite', () => {
|
|
169
|
+
it('test1', () => { doSomething(); });
|
|
170
|
+
it('test2', () => { doSomething(); });
|
|
171
|
+
it('test3', () => { expect(1).toBe(1); });
|
|
172
|
+
});`);
|
|
173
|
+
const findings = detectLowAssertionDensity([file]);
|
|
174
|
+
expect(findings).toHaveLength(1);
|
|
175
|
+
expect(findings[0].category).toBe('low-assertion-density');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('passes when assertion density >= 1', () => {
|
|
179
|
+
const file = analyze(`describe('suite', () => {
|
|
180
|
+
it('test1', () => { expect(1).toBe(1); });
|
|
181
|
+
it('test2', () => { expect(2).toBe(2); });
|
|
182
|
+
});`);
|
|
183
|
+
const findings = detectLowAssertionDensity([file]);
|
|
184
|
+
expect(findings).toHaveLength(0);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('skips non-test files', () => {
|
|
188
|
+
const src = parse(
|
|
189
|
+
`describe('suite', () => {
|
|
190
|
+
it('test1', () => { doSomething(); });
|
|
191
|
+
});`,
|
|
192
|
+
'/repo/src/feature.ts'
|
|
193
|
+
);
|
|
194
|
+
const entry = analyzeSourceFile(
|
|
195
|
+
src,
|
|
196
|
+
'pkg',
|
|
197
|
+
emptySummary(),
|
|
198
|
+
{ ...DEFAULT_OPTS, root: '/repo' },
|
|
199
|
+
emptyMaps(),
|
|
200
|
+
[],
|
|
201
|
+
emptyProfile
|
|
202
|
+
);
|
|
203
|
+
const findings = detectLowAssertionDensity([entry]);
|
|
204
|
+
expect(findings).toHaveLength(0);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('skips files with no test blocks', () => {
|
|
208
|
+
const file = analyze(`export function helper() { return 42; }`);
|
|
209
|
+
const findings = detectLowAssertionDensity([file]);
|
|
210
|
+
expect(findings).toHaveLength(0);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe('test-no-assertion detector', () => {
|
|
215
|
+
it('flags individual test block with 0 assertions', () => {
|
|
216
|
+
const file = analyze(`it('no assertion', () => { doSomething(); });`);
|
|
217
|
+
const findings = detectTestNoAssertion([file]);
|
|
218
|
+
expect(findings).toHaveLength(1);
|
|
219
|
+
expect(findings[0].category).toBe('test-no-assertion');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('does not flag test blocks with assertions', () => {
|
|
223
|
+
const file = analyze(`it('has assertion', () => { expect(1).toBe(1); });`);
|
|
224
|
+
const findings = detectTestNoAssertion([file]);
|
|
225
|
+
expect(findings).toHaveLength(0);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('flags multiple empty test blocks separately', () => {
|
|
229
|
+
const file = analyze(`describe('suite', () => {
|
|
230
|
+
it('test1', () => { doSomething(); });
|
|
231
|
+
it('test2', () => { doSomethingElse(); });
|
|
232
|
+
});`);
|
|
233
|
+
const findings = detectTestNoAssertion([file]);
|
|
234
|
+
expect(findings).toHaveLength(2);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('skips non-test files', () => {
|
|
238
|
+
const src = parse(
|
|
239
|
+
`it('test', () => { doSomething(); });`,
|
|
240
|
+
'/repo/src/feature.ts'
|
|
241
|
+
);
|
|
242
|
+
const entry = analyzeSourceFile(
|
|
243
|
+
src,
|
|
244
|
+
'pkg',
|
|
245
|
+
emptySummary(),
|
|
246
|
+
{ ...DEFAULT_OPTS, root: '/repo' },
|
|
247
|
+
emptyMaps(),
|
|
248
|
+
[],
|
|
249
|
+
emptyProfile
|
|
250
|
+
);
|
|
251
|
+
const findings = detectTestNoAssertion([entry]);
|
|
252
|
+
expect(findings).toHaveLength(0);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('excessive mocking detector', () => {
|
|
257
|
+
it('flags file exceeding mock threshold', () => {
|
|
258
|
+
const file = analyze(`test('mocked', () => {
|
|
259
|
+
jest.mock('a');
|
|
260
|
+
jest.mock('b');
|
|
261
|
+
jest.mock('c');
|
|
262
|
+
});`);
|
|
263
|
+
const findings = detectExcessiveMocking([file], 2);
|
|
264
|
+
expect(findings).toHaveLength(1);
|
|
265
|
+
expect(findings[0].category).toBe('excessive-mocking');
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('passes when below threshold', () => {
|
|
269
|
+
const file = analyze(`test('mocked', () => {
|
|
270
|
+
jest.mock('a');
|
|
271
|
+
});`);
|
|
272
|
+
const findings = detectExcessiveMocking([file], 2);
|
|
273
|
+
expect(findings).toHaveLength(0);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('skips non-test files', () => {
|
|
277
|
+
const src = parse(
|
|
278
|
+
`jest.mock('a'); jest.mock('b'); jest.mock('c');`,
|
|
279
|
+
'/repo/src/feature.ts'
|
|
280
|
+
);
|
|
281
|
+
const entry = analyzeSourceFile(
|
|
282
|
+
src,
|
|
283
|
+
'pkg',
|
|
284
|
+
emptySummary(),
|
|
285
|
+
{ ...DEFAULT_OPTS, root: '/repo' },
|
|
286
|
+
emptyMaps(),
|
|
287
|
+
[],
|
|
288
|
+
emptyProfile
|
|
289
|
+
);
|
|
290
|
+
const findings = detectExcessiveMocking([entry], 2);
|
|
291
|
+
expect(findings).toHaveLength(0);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
describe('shared mutable state detector', () => {
|
|
296
|
+
it('flags let at describe scope', () => {
|
|
297
|
+
const file = analyze(`describe('suite', () => {
|
|
298
|
+
let counter = 0;
|
|
299
|
+
it('test', () => { counter++; expect(counter).toBe(1); });
|
|
300
|
+
});`);
|
|
301
|
+
const findings = detectSharedMutableState([file]);
|
|
302
|
+
expect(findings).toHaveLength(1);
|
|
303
|
+
expect(findings[0].category).toBe('shared-mutable-state');
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('does not flag const declarations', () => {
|
|
307
|
+
const file = analyze(`describe('suite', () => {
|
|
308
|
+
const value = 42;
|
|
309
|
+
it('test', () => { expect(value).toBe(42); });
|
|
310
|
+
});`);
|
|
311
|
+
const findings = detectSharedMutableState([file]);
|
|
312
|
+
expect(findings).toHaveLength(0);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('skips non-test files', () => {
|
|
316
|
+
const src = parse(`let x = 0;`, '/repo/src/feature.ts');
|
|
317
|
+
const entry = analyzeSourceFile(
|
|
318
|
+
src,
|
|
319
|
+
'pkg',
|
|
320
|
+
emptySummary(),
|
|
321
|
+
{ ...DEFAULT_OPTS, root: '/repo' },
|
|
322
|
+
emptyMaps(),
|
|
323
|
+
[],
|
|
324
|
+
emptyProfile
|
|
325
|
+
);
|
|
326
|
+
const findings = detectSharedMutableState([entry]);
|
|
327
|
+
expect(findings).toHaveLength(0);
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
describe('missing test cleanup detector', () => {
|
|
332
|
+
it('flags beforeAll without afterAll', () => {
|
|
333
|
+
const file = analyze(`describe('suite', () => {
|
|
334
|
+
beforeAll(() => { setup(); });
|
|
335
|
+
it('test', () => { expect(1).toBe(1); });
|
|
336
|
+
});`);
|
|
337
|
+
const findings = detectMissingTestCleanup([file]);
|
|
338
|
+
expect(findings).toHaveLength(1);
|
|
339
|
+
expect(findings[0].category).toBe('missing-test-cleanup');
|
|
340
|
+
expect(findings[0].title).toContain('beforeAll');
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('flags beforeEach without afterEach', () => {
|
|
344
|
+
const file = analyze(`describe('suite', () => {
|
|
345
|
+
beforeEach(() => { setup(); });
|
|
346
|
+
it('test', () => { expect(1).toBe(1); });
|
|
347
|
+
});`);
|
|
348
|
+
const findings = detectMissingTestCleanup([file]);
|
|
349
|
+
expect(findings).toHaveLength(1);
|
|
350
|
+
expect(findings[0].category).toBe('missing-test-cleanup');
|
|
351
|
+
expect(findings[0].title).toContain('beforeEach');
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('passes when both beforeAll and afterAll present', () => {
|
|
355
|
+
const file = analyze(`describe('suite', () => {
|
|
356
|
+
beforeAll(() => { setup(); });
|
|
357
|
+
afterAll(() => { teardown(); });
|
|
358
|
+
it('test', () => { expect(1).toBe(1); });
|
|
359
|
+
});`);
|
|
360
|
+
const findings = detectMissingTestCleanup([file]);
|
|
361
|
+
expect(findings).toHaveLength(0);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it('passes when both beforeEach and afterEach present', () => {
|
|
365
|
+
const file = analyze(`describe('suite', () => {
|
|
366
|
+
beforeEach(() => { setup(); });
|
|
367
|
+
afterEach(() => { teardown(); });
|
|
368
|
+
it('test', () => { expect(1).toBe(1); });
|
|
369
|
+
});`);
|
|
370
|
+
const findings = detectMissingTestCleanup([file]);
|
|
371
|
+
expect(findings).toHaveLength(0);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('skips non-test files', () => {
|
|
375
|
+
const src = parse(`beforeAll(() => { setup(); });`, '/repo/src/feature.ts');
|
|
376
|
+
const entry = analyzeSourceFile(
|
|
377
|
+
src,
|
|
378
|
+
'pkg',
|
|
379
|
+
emptySummary(),
|
|
380
|
+
{ ...DEFAULT_OPTS, root: '/repo' },
|
|
381
|
+
emptyMaps(),
|
|
382
|
+
[],
|
|
383
|
+
emptyProfile
|
|
384
|
+
);
|
|
385
|
+
const findings = detectMissingTestCleanup([entry]);
|
|
386
|
+
expect(findings).toHaveLength(0);
|
|
387
|
+
});
|
|
388
|
+
});
|