octocode-cli 1.2.6 → 1.2.7
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 +7026 -6945
- 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,257 @@
|
|
|
1
|
+
import { dependencyProfileToRecord } from './dependencies.js';
|
|
2
|
+
import { isTestFile } from '../common/utils.js';
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
AnalysisOptions,
|
|
6
|
+
CriticalPath,
|
|
7
|
+
Cycle,
|
|
8
|
+
DependencyState,
|
|
9
|
+
DependencySummary,
|
|
10
|
+
FileCriticality,
|
|
11
|
+
ModuleCount,
|
|
12
|
+
WalkResult,
|
|
13
|
+
} from '../types/index.js';
|
|
14
|
+
|
|
15
|
+
export function buildDependencySummary(
|
|
16
|
+
dependencyState: DependencyState,
|
|
17
|
+
fileCriticalityByPath: Map<string, FileCriticality>,
|
|
18
|
+
options: AnalysisOptions
|
|
19
|
+
): DependencySummary {
|
|
20
|
+
const allFiles = [...dependencyState.files].sort();
|
|
21
|
+
let totalEdges = 0;
|
|
22
|
+
let unresolvedEdgeCount = 0;
|
|
23
|
+
const outgoingCounts: ModuleCount[] = [];
|
|
24
|
+
const inboundCounts: ModuleCount[] = [];
|
|
25
|
+
|
|
26
|
+
for (const file of allFiles) {
|
|
27
|
+
totalEdges += dependencyState.outgoing.get(file)?.size || 0;
|
|
28
|
+
const record = dependencyProfileToRecord(file, dependencyState);
|
|
29
|
+
const crit = fileCriticalityByPath.get(file) || { score: 1 };
|
|
30
|
+
outgoingCounts.push({
|
|
31
|
+
file,
|
|
32
|
+
count: record.outboundCount,
|
|
33
|
+
score: crit.score,
|
|
34
|
+
});
|
|
35
|
+
inboundCounts.push({ file, count: record.inboundCount, score: crit.score });
|
|
36
|
+
unresolvedEdgeCount += record.unresolvedDependencyCount;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const roots = allFiles.filter(file => {
|
|
40
|
+
const inCount = (dependencyState.incoming.get(file) || new Set()).size;
|
|
41
|
+
return inCount === 0;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const leaves = allFiles.filter(file => {
|
|
45
|
+
const outCount = (dependencyState.outgoing.get(file) || new Set()).size;
|
|
46
|
+
return outCount === 0;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const testOnlyModules = allFiles
|
|
50
|
+
.filter(file => !isTestFile(file))
|
|
51
|
+
.filter(file => {
|
|
52
|
+
const prodIn = dependencyState.incomingFromProduction.get(file);
|
|
53
|
+
const testIn = dependencyState.incomingFromTests.get(file);
|
|
54
|
+
return (!prodIn || prodIn.size === 0) && testIn && testIn.size > 0;
|
|
55
|
+
})
|
|
56
|
+
.map(file => ({
|
|
57
|
+
...dependencyProfileToRecord(file, dependencyState),
|
|
58
|
+
}))
|
|
59
|
+
.sort((a, b) => a.file.localeCompare(b.file));
|
|
60
|
+
|
|
61
|
+
const criticalNodes = allFiles
|
|
62
|
+
.map(file => ({
|
|
63
|
+
...dependencyProfileToRecord(file, dependencyState),
|
|
64
|
+
...(fileCriticalityByPath.get(file) || ({} as Partial<FileCriticality>)),
|
|
65
|
+
}))
|
|
66
|
+
.filter(
|
|
67
|
+
node =>
|
|
68
|
+
(node.score || 0) > 12 ||
|
|
69
|
+
node.outboundCount > 5 ||
|
|
70
|
+
node.inboundCount > 8
|
|
71
|
+
)
|
|
72
|
+
.sort(
|
|
73
|
+
(a, b) =>
|
|
74
|
+
(b.score || 0) +
|
|
75
|
+
b.inboundCount * 0.8 +
|
|
76
|
+
b.outboundCount * 0.4 -
|
|
77
|
+
((a.score || 0) + a.inboundCount * 0.8 + a.outboundCount * 0.4)
|
|
78
|
+
)
|
|
79
|
+
.slice(0, 150)
|
|
80
|
+
.map(node => ({
|
|
81
|
+
...node,
|
|
82
|
+
score: Math.round(node.score || 0),
|
|
83
|
+
riskBand:
|
|
84
|
+
(node.score || 0) >= 60
|
|
85
|
+
? 'high'
|
|
86
|
+
: (node.score || 0) >= 30
|
|
87
|
+
? 'medium'
|
|
88
|
+
: 'low',
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
const cycles = computeDependencyCycles(dependencyState);
|
|
92
|
+
const criticalPaths = computeDependencyCriticalPaths(
|
|
93
|
+
dependencyState,
|
|
94
|
+
fileCriticalityByPath,
|
|
95
|
+
options
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
totalModules: allFiles.length,
|
|
100
|
+
totalEdges,
|
|
101
|
+
unresolvedEdgeCount,
|
|
102
|
+
externalDependencyFiles: [...dependencyState.externalCounts.keys()].length,
|
|
103
|
+
rootsCount: roots.length,
|
|
104
|
+
leavesCount: leaves.length,
|
|
105
|
+
roots: roots.slice(0, 20),
|
|
106
|
+
leaves: leaves.slice(0, 20),
|
|
107
|
+
criticalModules: criticalNodes.slice(
|
|
108
|
+
0,
|
|
109
|
+
20
|
|
110
|
+
) as import('../types/index.js').CriticalModule[],
|
|
111
|
+
testOnlyModules: testOnlyModules.slice(0, 50),
|
|
112
|
+
unresolvedSample:
|
|
113
|
+
unresolvedEdgeCount > 0
|
|
114
|
+
? [...dependencyState.unresolvedCounts.keys()].slice(0, 40)
|
|
115
|
+
: [],
|
|
116
|
+
outgoingTop: outgoingCounts.sort((a, b) => b.count - a.count).slice(0, 20),
|
|
117
|
+
inboundTop: inboundCounts.sort((a, b) => b.count - a.count).slice(0, 20),
|
|
118
|
+
cycles: cycles.slice(0, 20),
|
|
119
|
+
criticalPaths: criticalPaths.slice(0, Math.max(1, options.deepLinkTopN)),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function computeDependencyCycles(
|
|
124
|
+
dependencyState: DependencyState
|
|
125
|
+
): Cycle[] {
|
|
126
|
+
const cycles: Cycle[] = [];
|
|
127
|
+
const visited = new Set<string>();
|
|
128
|
+
const visiting = new Set<string>();
|
|
129
|
+
const activeStack: string[] = [];
|
|
130
|
+
const seenCycles = new Set<string>();
|
|
131
|
+
|
|
132
|
+
const canonicalizeCycle = (cyclePath: string[]): string => {
|
|
133
|
+
const rotated = [...cyclePath];
|
|
134
|
+
let best = rotated.slice();
|
|
135
|
+
for (let i = 1; i < rotated.length; i++) {
|
|
136
|
+
const candidate = [...rotated.slice(i), ...rotated.slice(0, i)];
|
|
137
|
+
if (candidate.join(' => ') < best.join(' => ')) {
|
|
138
|
+
best = candidate;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return best.join(' => ');
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const visit = (node: string): void => {
|
|
145
|
+
if (visited.has(node)) return;
|
|
146
|
+
if (visiting.has(node)) return;
|
|
147
|
+
|
|
148
|
+
visiting.add(node);
|
|
149
|
+
activeStack.push(node);
|
|
150
|
+
|
|
151
|
+
const outgoing = dependencyState.outgoing.get(node) || new Set();
|
|
152
|
+
for (const dep of outgoing) {
|
|
153
|
+
const idx = activeStack.indexOf(dep);
|
|
154
|
+
if (idx !== -1) {
|
|
155
|
+
const rawCycle = [...activeStack.slice(idx), dep];
|
|
156
|
+
const normalized = canonicalizeCycle(rawCycle);
|
|
157
|
+
if (!seenCycles.has(normalized)) {
|
|
158
|
+
seenCycles.add(normalized);
|
|
159
|
+
cycles.push({
|
|
160
|
+
path: rawCycle,
|
|
161
|
+
nodeCount: rawCycle.length - 1,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (dependencyState.files.has(dep)) {
|
|
168
|
+
visit(dep);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
activeStack.pop();
|
|
173
|
+
visiting.delete(node);
|
|
174
|
+
visited.add(node);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
for (const node of dependencyState.files) {
|
|
178
|
+
visit(node);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return cycles.sort((a, b) => b.nodeCount - a.nodeCount);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function computeDependencyCriticalPaths(
|
|
185
|
+
dependencyState: DependencyState,
|
|
186
|
+
fileCriticalityByPath: Map<string, FileCriticality>,
|
|
187
|
+
options: AnalysisOptions
|
|
188
|
+
): CriticalPath[] {
|
|
189
|
+
const memo = new Map<string, WalkResult>();
|
|
190
|
+
const visiting = new Set<string>();
|
|
191
|
+
|
|
192
|
+
const nodeScore = (file: string): number => {
|
|
193
|
+
const entry = fileCriticalityByPath.get(file);
|
|
194
|
+
return entry ? entry.score : 1;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const walk = (file: string): WalkResult => {
|
|
198
|
+
if (memo.has(file)) return memo.get(file)!;
|
|
199
|
+
if (visiting.has(file)) {
|
|
200
|
+
return {
|
|
201
|
+
path: [file],
|
|
202
|
+
score: nodeScore(file) * 0.5,
|
|
203
|
+
containsCycle: true,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
visiting.add(file);
|
|
208
|
+
const edges = dependencyState.outgoing.get(file) || new Set();
|
|
209
|
+
let bestPath: WalkResult = {
|
|
210
|
+
path: [file],
|
|
211
|
+
score: nodeScore(file),
|
|
212
|
+
containsCycle: false,
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
for (const dep of edges) {
|
|
216
|
+
if (!dependencyState.files.has(dep)) continue;
|
|
217
|
+
const candidate = walk(dep);
|
|
218
|
+
const candidateScore = nodeScore(file) + candidate.score;
|
|
219
|
+
if (
|
|
220
|
+
candidateScore > bestPath.score ||
|
|
221
|
+
(candidateScore === bestPath.score &&
|
|
222
|
+
candidate.path.length > bestPath.path.length)
|
|
223
|
+
) {
|
|
224
|
+
bestPath = {
|
|
225
|
+
path: [file, ...candidate.path],
|
|
226
|
+
score: candidateScore,
|
|
227
|
+
containsCycle: candidate.containsCycle,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
visiting.delete(file);
|
|
233
|
+
memo.set(file, bestPath);
|
|
234
|
+
return bestPath;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const all: CriticalPath[] = [];
|
|
238
|
+
for (const file of dependencyState.files) {
|
|
239
|
+
const pathEntry = walk(file);
|
|
240
|
+
all.push({
|
|
241
|
+
start: file,
|
|
242
|
+
path: pathEntry.path,
|
|
243
|
+
score: Math.round(pathEntry.score),
|
|
244
|
+
length: pathEntry.path.length,
|
|
245
|
+
containsCycle: pathEntry.containsCycle,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return all
|
|
250
|
+
.filter(item => item.length > 1)
|
|
251
|
+
.sort((a, b) => {
|
|
252
|
+
const byScore = b.score - a.score;
|
|
253
|
+
if (byScore !== 0) return byScore;
|
|
254
|
+
return b.length - a.length;
|
|
255
|
+
})
|
|
256
|
+
.slice(0, Math.max(1, options.deepLinkTopN));
|
|
257
|
+
}
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
collectFiles,
|
|
9
|
+
fileSummaryWithFindings,
|
|
10
|
+
listWorkspacePackages,
|
|
11
|
+
safeRead,
|
|
12
|
+
} from './discovery.js';
|
|
13
|
+
import { DEFAULT_OPTS } from '../types/index.js';
|
|
14
|
+
|
|
15
|
+
import type { AnalysisOptions, FileEntry } from '../types/index.js';
|
|
16
|
+
|
|
17
|
+
describe('discovery', () => {
|
|
18
|
+
describe('collectFiles', () => {
|
|
19
|
+
let tmpDir: string;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'discovery-collect-'));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('collects .ts, .tsx, .js, .jsx, .mjs, .cjs files', () => {
|
|
30
|
+
fs.writeFileSync(path.join(tmpDir, 'a.ts'), '', 'utf8');
|
|
31
|
+
fs.writeFileSync(path.join(tmpDir, 'b.tsx'), '', 'utf8');
|
|
32
|
+
fs.writeFileSync(path.join(tmpDir, 'c.js'), '', 'utf8');
|
|
33
|
+
fs.writeFileSync(path.join(tmpDir, 'd.jsx'), '', 'utf8');
|
|
34
|
+
fs.writeFileSync(path.join(tmpDir, 'e.mjs'), '', 'utf8');
|
|
35
|
+
fs.writeFileSync(path.join(tmpDir, 'f.cjs'), '', 'utf8');
|
|
36
|
+
|
|
37
|
+
const opts: AnalysisOptions = { ...DEFAULT_OPTS, root: tmpDir };
|
|
38
|
+
const files = collectFiles(tmpDir, opts);
|
|
39
|
+
|
|
40
|
+
expect(files).toHaveLength(6);
|
|
41
|
+
expect(files.some(f => f.endsWith('a.ts'))).toBe(true);
|
|
42
|
+
expect(files.some(f => f.endsWith('b.tsx'))).toBe(true);
|
|
43
|
+
expect(files.some(f => f.endsWith('c.js'))).toBe(true);
|
|
44
|
+
expect(files.some(f => f.endsWith('d.jsx'))).toBe(true);
|
|
45
|
+
expect(files.some(f => f.endsWith('e.mjs'))).toBe(true);
|
|
46
|
+
expect(files.some(f => f.endsWith('f.cjs'))).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('skips .d.ts files', () => {
|
|
50
|
+
fs.writeFileSync(path.join(tmpDir, 'types.d.ts'), '', 'utf8');
|
|
51
|
+
fs.writeFileSync(path.join(tmpDir, 'index.ts'), '', 'utf8');
|
|
52
|
+
|
|
53
|
+
const opts: AnalysisOptions = { ...DEFAULT_OPTS, root: tmpDir };
|
|
54
|
+
const files = collectFiles(tmpDir, opts);
|
|
55
|
+
|
|
56
|
+
expect(files).toHaveLength(1);
|
|
57
|
+
expect(files.some(f => f.endsWith('index.ts'))).toBe(true);
|
|
58
|
+
expect(files.some(f => f.endsWith('types.d.ts'))).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('skips symlinks', () => {
|
|
62
|
+
const realFile = path.join(tmpDir, 'real.ts');
|
|
63
|
+
fs.writeFileSync(realFile, '', 'utf8');
|
|
64
|
+
fs.symlinkSync(realFile, path.join(tmpDir, 'link.ts'));
|
|
65
|
+
|
|
66
|
+
const opts: AnalysisOptions = { ...DEFAULT_OPTS, root: tmpDir };
|
|
67
|
+
const files = collectFiles(tmpDir, opts);
|
|
68
|
+
|
|
69
|
+
expect(files).toHaveLength(1);
|
|
70
|
+
expect(files.some(f => f.endsWith('real.ts'))).toBe(true);
|
|
71
|
+
expect(files.some(f => f.endsWith('link.ts'))).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('skips directories in ignoreDirs', () => {
|
|
75
|
+
const skipDir = path.join(tmpDir, 'skipme');
|
|
76
|
+
fs.mkdirSync(skipDir, { recursive: true });
|
|
77
|
+
fs.writeFileSync(path.join(skipDir, 'nested.ts'), '', 'utf8');
|
|
78
|
+
fs.writeFileSync(path.join(tmpDir, 'root.ts'), '', 'utf8');
|
|
79
|
+
|
|
80
|
+
const opts: AnalysisOptions = {
|
|
81
|
+
...DEFAULT_OPTS,
|
|
82
|
+
root: tmpDir,
|
|
83
|
+
ignoreDirs: new Set(['skipme']),
|
|
84
|
+
};
|
|
85
|
+
const files = collectFiles(tmpDir, opts);
|
|
86
|
+
|
|
87
|
+
expect(files).toHaveLength(1);
|
|
88
|
+
expect(files.some(f => f.endsWith('root.ts'))).toBe(true);
|
|
89
|
+
expect(files.some(f => f.includes('skipme'))).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('excludes test files when includeTests is false', () => {
|
|
93
|
+
fs.writeFileSync(path.join(tmpDir, 'foo.ts'), '', 'utf8');
|
|
94
|
+
fs.writeFileSync(path.join(tmpDir, 'foo.test.ts'), '', 'utf8');
|
|
95
|
+
fs.writeFileSync(path.join(tmpDir, 'foo.spec.ts'), '', 'utf8');
|
|
96
|
+
fs.mkdirSync(path.join(tmpDir, '__tests__'), { recursive: true });
|
|
97
|
+
fs.writeFileSync(path.join(tmpDir, '__tests__', 'bar.ts'), '', 'utf8');
|
|
98
|
+
|
|
99
|
+
const opts: AnalysisOptions = {
|
|
100
|
+
...DEFAULT_OPTS,
|
|
101
|
+
root: tmpDir,
|
|
102
|
+
includeTests: false,
|
|
103
|
+
};
|
|
104
|
+
const files = collectFiles(tmpDir, opts);
|
|
105
|
+
|
|
106
|
+
expect(files).toHaveLength(1);
|
|
107
|
+
expect(files.some(f => f.endsWith('foo.ts'))).toBe(true);
|
|
108
|
+
expect(files.some(f => f.endsWith('foo.test.ts'))).toBe(false);
|
|
109
|
+
expect(files.some(f => f.endsWith('foo.spec.ts'))).toBe(false);
|
|
110
|
+
expect(files.some(f => f.includes('__tests__'))).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('includes test files when includeTests is true', () => {
|
|
114
|
+
fs.writeFileSync(path.join(tmpDir, 'foo.ts'), '', 'utf8');
|
|
115
|
+
fs.writeFileSync(path.join(tmpDir, 'foo.test.ts'), '', 'utf8');
|
|
116
|
+
fs.writeFileSync(path.join(tmpDir, 'foo.spec.ts'), '', 'utf8');
|
|
117
|
+
fs.mkdirSync(path.join(tmpDir, '__tests__'), { recursive: true });
|
|
118
|
+
fs.writeFileSync(path.join(tmpDir, '__tests__', 'bar.ts'), '', 'utf8');
|
|
119
|
+
|
|
120
|
+
const opts: AnalysisOptions = {
|
|
121
|
+
...DEFAULT_OPTS,
|
|
122
|
+
root: tmpDir,
|
|
123
|
+
includeTests: true,
|
|
124
|
+
};
|
|
125
|
+
const files = collectFiles(tmpDir, opts);
|
|
126
|
+
|
|
127
|
+
expect(files).toHaveLength(4);
|
|
128
|
+
expect(files.some(f => f.endsWith('foo.ts'))).toBe(true);
|
|
129
|
+
expect(files.some(f => f.endsWith('foo.test.ts'))).toBe(true);
|
|
130
|
+
expect(files.some(f => f.endsWith('foo.spec.ts'))).toBe(true);
|
|
131
|
+
expect(
|
|
132
|
+
files.some(f => f.includes('__tests__') && f.endsWith('bar.ts'))
|
|
133
|
+
).toBe(true);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('walks nested directories', () => {
|
|
137
|
+
fs.mkdirSync(path.join(tmpDir, 'src', 'utils'), { recursive: true });
|
|
138
|
+
fs.writeFileSync(path.join(tmpDir, 'index.ts'), '', 'utf8');
|
|
139
|
+
fs.writeFileSync(path.join(tmpDir, 'src', 'app.ts'), '', 'utf8');
|
|
140
|
+
fs.writeFileSync(
|
|
141
|
+
path.join(tmpDir, 'src', 'utils', 'helper.ts'),
|
|
142
|
+
'',
|
|
143
|
+
'utf8'
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const opts: AnalysisOptions = { ...DEFAULT_OPTS, root: tmpDir };
|
|
147
|
+
const files = collectFiles(tmpDir, opts);
|
|
148
|
+
|
|
149
|
+
expect(files).toHaveLength(3);
|
|
150
|
+
expect(files.some(f => f.endsWith('index.ts'))).toBe(true);
|
|
151
|
+
expect(files.some(f => f.endsWith('app.ts'))).toBe(true);
|
|
152
|
+
expect(files.some(f => f.endsWith('helper.ts'))).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('skips non-allowed extensions', () => {
|
|
156
|
+
fs.writeFileSync(path.join(tmpDir, 'a.ts'), '', 'utf8');
|
|
157
|
+
fs.writeFileSync(path.join(tmpDir, 'b.txt'), '', 'utf8');
|
|
158
|
+
fs.writeFileSync(path.join(tmpDir, 'c.json'), '', 'utf8');
|
|
159
|
+
fs.writeFileSync(path.join(tmpDir, 'd.css'), '', 'utf8');
|
|
160
|
+
|
|
161
|
+
const opts: AnalysisOptions = { ...DEFAULT_OPTS, root: tmpDir };
|
|
162
|
+
const files = collectFiles(tmpDir, opts);
|
|
163
|
+
|
|
164
|
+
expect(files).toHaveLength(1);
|
|
165
|
+
expect(files.some(f => f.endsWith('a.ts'))).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('handles empty directories', () => {
|
|
169
|
+
fs.mkdirSync(path.join(tmpDir, 'empty'), { recursive: true });
|
|
170
|
+
fs.writeFileSync(path.join(tmpDir, 'only.ts'), '', 'utf8');
|
|
171
|
+
|
|
172
|
+
const opts: AnalysisOptions = { ...DEFAULT_OPTS, root: tmpDir };
|
|
173
|
+
const files = collectFiles(tmpDir, opts);
|
|
174
|
+
|
|
175
|
+
expect(files).toHaveLength(1);
|
|
176
|
+
expect(files.some(f => f.endsWith('only.ts'))).toBe(true);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('returns sorted file paths', () => {
|
|
180
|
+
fs.writeFileSync(path.join(tmpDir, 'z.ts'), '', 'utf8');
|
|
181
|
+
fs.writeFileSync(path.join(tmpDir, 'a.ts'), '', 'utf8');
|
|
182
|
+
fs.writeFileSync(path.join(tmpDir, 'm.ts'), '', 'utf8');
|
|
183
|
+
|
|
184
|
+
const opts: AnalysisOptions = { ...DEFAULT_OPTS, root: tmpDir };
|
|
185
|
+
const files = collectFiles(tmpDir, opts);
|
|
186
|
+
|
|
187
|
+
expect(files).toHaveLength(3);
|
|
188
|
+
const basenames = files.map(f => path.basename(f));
|
|
189
|
+
expect(basenames).toEqual(
|
|
190
|
+
[...basenames].sort((a, b) => a.localeCompare(b))
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe('safeRead', () => {
|
|
196
|
+
let tmpDir: string;
|
|
197
|
+
|
|
198
|
+
beforeEach(() => {
|
|
199
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'discovery-saferead-'));
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
afterEach(() => {
|
|
203
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('reads existing file content', () => {
|
|
207
|
+
const filePath = path.join(tmpDir, 'hello.ts');
|
|
208
|
+
const content = 'const x = 1;\nconsole.log(x);';
|
|
209
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
210
|
+
|
|
211
|
+
expect(safeRead(filePath)).toBe(content);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('returns null for non-existent file', () => {
|
|
215
|
+
const filePath = path.join(tmpDir, 'does-not-exist.ts');
|
|
216
|
+
expect(safeRead(filePath)).toBeNull();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('returns null when given a directory path', () => {
|
|
220
|
+
const dirPath = path.join(tmpDir, 'adir');
|
|
221
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
222
|
+
|
|
223
|
+
expect(safeRead(dirPath)).toBeNull();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('listWorkspacePackages', () => {
|
|
228
|
+
let tmpDir: string;
|
|
229
|
+
let packagesDir: string;
|
|
230
|
+
|
|
231
|
+
beforeEach(() => {
|
|
232
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'discovery-packages-'));
|
|
233
|
+
packagesDir = path.join(tmpDir, 'packages');
|
|
234
|
+
fs.mkdirSync(packagesDir, { recursive: true });
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
afterEach(() => {
|
|
238
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('lists packages with valid package.json', () => {
|
|
242
|
+
fs.mkdirSync(path.join(packagesDir, 'pkg-a'), { recursive: true });
|
|
243
|
+
fs.mkdirSync(path.join(packagesDir, 'pkg-b'), { recursive: true });
|
|
244
|
+
fs.writeFileSync(
|
|
245
|
+
path.join(packagesDir, 'pkg-a', 'package.json'),
|
|
246
|
+
JSON.stringify({ name: 'pkg-a' }),
|
|
247
|
+
'utf8'
|
|
248
|
+
);
|
|
249
|
+
fs.writeFileSync(
|
|
250
|
+
path.join(packagesDir, 'pkg-b', 'package.json'),
|
|
251
|
+
JSON.stringify({ name: 'pkg-b' }),
|
|
252
|
+
'utf8'
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
const packages = listWorkspacePackages(tmpDir, packagesDir);
|
|
256
|
+
|
|
257
|
+
expect(packages).toHaveLength(2);
|
|
258
|
+
expect(packages.map(p => p.name)).toContain('pkg-a');
|
|
259
|
+
expect(packages.map(p => p.name)).toContain('pkg-b');
|
|
260
|
+
expect(packages.map(p => p.folder)).toContain('pkg-a');
|
|
261
|
+
expect(packages.map(p => p.folder)).toContain('pkg-b');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('skips directories without package.json', () => {
|
|
265
|
+
fs.mkdirSync(path.join(packagesDir, 'has-pkg'), { recursive: true });
|
|
266
|
+
fs.mkdirSync(path.join(packagesDir, 'no-pkg'), { recursive: true });
|
|
267
|
+
fs.writeFileSync(
|
|
268
|
+
path.join(packagesDir, 'has-pkg', 'package.json'),
|
|
269
|
+
JSON.stringify({ name: 'has-pkg' }),
|
|
270
|
+
'utf8'
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
const packages = listWorkspacePackages(tmpDir, packagesDir);
|
|
274
|
+
|
|
275
|
+
expect(packages).toHaveLength(1);
|
|
276
|
+
expect(packages[0].name).toBe('has-pkg');
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('skips invalid JSON in package.json', () => {
|
|
280
|
+
fs.mkdirSync(path.join(packagesDir, 'valid'), { recursive: true });
|
|
281
|
+
fs.mkdirSync(path.join(packagesDir, 'invalid'), { recursive: true });
|
|
282
|
+
fs.writeFileSync(
|
|
283
|
+
path.join(packagesDir, 'valid', 'package.json'),
|
|
284
|
+
JSON.stringify({ name: 'valid' }),
|
|
285
|
+
'utf8'
|
|
286
|
+
);
|
|
287
|
+
fs.writeFileSync(
|
|
288
|
+
path.join(packagesDir, 'invalid', 'package.json'),
|
|
289
|
+
'{ invalid json }',
|
|
290
|
+
'utf8'
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
const packages = listWorkspacePackages(tmpDir, packagesDir);
|
|
294
|
+
|
|
295
|
+
expect(packages).toHaveLength(1);
|
|
296
|
+
expect(packages[0].name).toBe('valid');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('skips package.json without name field', () => {
|
|
300
|
+
fs.mkdirSync(path.join(packagesDir, 'no-name'), { recursive: true });
|
|
301
|
+
fs.writeFileSync(
|
|
302
|
+
path.join(packagesDir, 'no-name', 'package.json'),
|
|
303
|
+
JSON.stringify({ version: '1.0.0' }),
|
|
304
|
+
'utf8'
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
const packages = listWorkspacePackages(tmpDir, packagesDir);
|
|
308
|
+
|
|
309
|
+
expect(packages).toHaveLength(0);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('returns sorted results by folder name', () => {
|
|
313
|
+
fs.mkdirSync(path.join(packagesDir, 'pkg-z'), { recursive: true });
|
|
314
|
+
fs.mkdirSync(path.join(packagesDir, 'pkg-a'), { recursive: true });
|
|
315
|
+
fs.mkdirSync(path.join(packagesDir, 'pkg-m'), { recursive: true });
|
|
316
|
+
fs.writeFileSync(
|
|
317
|
+
path.join(packagesDir, 'pkg-z', 'package.json'),
|
|
318
|
+
JSON.stringify({ name: 'pkg-z' }),
|
|
319
|
+
'utf8'
|
|
320
|
+
);
|
|
321
|
+
fs.writeFileSync(
|
|
322
|
+
path.join(packagesDir, 'pkg-a', 'package.json'),
|
|
323
|
+
JSON.stringify({ name: 'pkg-a' }),
|
|
324
|
+
'utf8'
|
|
325
|
+
);
|
|
326
|
+
fs.writeFileSync(
|
|
327
|
+
path.join(packagesDir, 'pkg-m', 'package.json'),
|
|
328
|
+
JSON.stringify({ name: 'pkg-m' }),
|
|
329
|
+
'utf8'
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
const packages = listWorkspacePackages(tmpDir, packagesDir);
|
|
333
|
+
|
|
334
|
+
expect(packages).toHaveLength(3);
|
|
335
|
+
expect(packages.map(p => p.folder)).toEqual(['pkg-a', 'pkg-m', 'pkg-z']);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('returns empty array when packageRoot does not exist', () => {
|
|
339
|
+
const packages = listWorkspacePackages(
|
|
340
|
+
tmpDir,
|
|
341
|
+
path.join(tmpDir, 'nonexistent')
|
|
342
|
+
);
|
|
343
|
+
expect(packages).toEqual([]);
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
describe('fileSummaryWithFindings', () => {
|
|
348
|
+
function makeFileEntry(override: Partial<FileEntry> = {}): FileEntry {
|
|
349
|
+
return {
|
|
350
|
+
package: 'pkg',
|
|
351
|
+
file: 'src/file.ts',
|
|
352
|
+
parseEngine: 'typescript',
|
|
353
|
+
nodeCount: 1,
|
|
354
|
+
kindCounts: {},
|
|
355
|
+
functions: [],
|
|
356
|
+
flows: [],
|
|
357
|
+
dependencyProfile: {
|
|
358
|
+
internalDependencies: [],
|
|
359
|
+
externalDependencies: [],
|
|
360
|
+
unresolvedDependencies: [],
|
|
361
|
+
declaredExports: [],
|
|
362
|
+
importedSymbols: [],
|
|
363
|
+
reExports: [],
|
|
364
|
+
},
|
|
365
|
+
...override,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
it('merges issueIds into entries', () => {
|
|
370
|
+
const entries: FileEntry[] = [
|
|
371
|
+
makeFileEntry({ file: 'src/a.ts' }),
|
|
372
|
+
makeFileEntry({ file: 'src/b.ts' }),
|
|
373
|
+
];
|
|
374
|
+
const byFile = new Map<string, string[]>([
|
|
375
|
+
['src/a.ts', ['issue-1', 'issue-2']],
|
|
376
|
+
['src/b.ts', ['issue-3']],
|
|
377
|
+
]);
|
|
378
|
+
|
|
379
|
+
const result = fileSummaryWithFindings(entries, byFile);
|
|
380
|
+
|
|
381
|
+
expect(result).toHaveLength(2);
|
|
382
|
+
expect(result[0].file).toBe('src/a.ts');
|
|
383
|
+
expect(result[0].issueIds).toEqual(['issue-1', 'issue-2']);
|
|
384
|
+
expect(result[1].file).toBe('src/b.ts');
|
|
385
|
+
expect(result[1].issueIds).toEqual(['issue-3']);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('returns empty issueIds for entries without findings', () => {
|
|
389
|
+
const entries: FileEntry[] = [
|
|
390
|
+
makeFileEntry({ file: 'src/a.ts' }),
|
|
391
|
+
makeFileEntry({ file: 'src/b.ts' }),
|
|
392
|
+
];
|
|
393
|
+
const byFile = new Map<string, string[]>([['src/a.ts', ['issue-1']]]);
|
|
394
|
+
|
|
395
|
+
const result = fileSummaryWithFindings(entries, byFile);
|
|
396
|
+
|
|
397
|
+
expect(result).toHaveLength(2);
|
|
398
|
+
expect(result[0].issueIds).toEqual(['issue-1']);
|
|
399
|
+
expect(result[1].issueIds).toEqual([]);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('handles empty byFile map', () => {
|
|
403
|
+
const entries: FileEntry[] = [makeFileEntry({ file: 'src/a.ts' })];
|
|
404
|
+
const byFile = new Map<string, string[]>();
|
|
405
|
+
|
|
406
|
+
const result = fileSummaryWithFindings(entries, byFile);
|
|
407
|
+
|
|
408
|
+
expect(result).toHaveLength(1);
|
|
409
|
+
expect(result[0].issueIds).toEqual([]);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('handles empty entries array', () => {
|
|
413
|
+
const byFile = new Map<string, string[]>([['src/a.ts', ['issue-1']]]);
|
|
414
|
+
|
|
415
|
+
const result = fileSummaryWithFindings([], byFile);
|
|
416
|
+
|
|
417
|
+
expect(result).toEqual([]);
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
});
|