octocode-cli 1.2.5 → 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 +86 -109
- package/out/octocode-cli.js +7027 -7014
- 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,469 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for response builder utilities.
|
|
3
|
+
*
|
|
4
|
+
* @module tests/unit/responseBuilder
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
8
|
+
import { ResearchResponse, detectLanguageFromPath } from '../../utils/responseBuilder.js';
|
|
9
|
+
|
|
10
|
+
// Mock octocode-mcp public module
|
|
11
|
+
vi.mock('octocode-mcp/public', () => ({
|
|
12
|
+
createRoleBasedResult: vi.fn((opts) => ({
|
|
13
|
+
content: [
|
|
14
|
+
{ type: 'text', text: opts.assistant?.summary || '' },
|
|
15
|
+
],
|
|
16
|
+
structuredContent: opts.data,
|
|
17
|
+
isError: opts.isError || false,
|
|
18
|
+
})),
|
|
19
|
+
QuickResult: {
|
|
20
|
+
success: vi.fn((summary, data, hints) => ({
|
|
21
|
+
content: [{ type: 'text', text: summary }],
|
|
22
|
+
structuredContent: data,
|
|
23
|
+
hints,
|
|
24
|
+
isError: false,
|
|
25
|
+
})),
|
|
26
|
+
empty: vi.fn((summary, hints) => ({
|
|
27
|
+
content: [{ type: 'text', text: summary }],
|
|
28
|
+
hints,
|
|
29
|
+
isEmpty: true,
|
|
30
|
+
})),
|
|
31
|
+
paginated: vi.fn((summary, data, pagination, hints) => ({
|
|
32
|
+
content: [{ type: 'text', text: summary }],
|
|
33
|
+
structuredContent: data,
|
|
34
|
+
pagination,
|
|
35
|
+
hints,
|
|
36
|
+
})),
|
|
37
|
+
},
|
|
38
|
+
StatusEmoji: {
|
|
39
|
+
success: '✅',
|
|
40
|
+
error: '❌',
|
|
41
|
+
empty: '📭',
|
|
42
|
+
file: '📄',
|
|
43
|
+
folder: '📁',
|
|
44
|
+
definition: '📍',
|
|
45
|
+
reference: '🔗',
|
|
46
|
+
call: '📞',
|
|
47
|
+
info: 'ℹ️',
|
|
48
|
+
partial: '⚠️',
|
|
49
|
+
},
|
|
50
|
+
ContentBuilder: vi.fn(),
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
describe('detectLanguageFromPath', () => {
|
|
54
|
+
it('detects TypeScript files', () => {
|
|
55
|
+
expect(detectLanguageFromPath('src/utils.ts')).toBe('typescript');
|
|
56
|
+
expect(detectLanguageFromPath('components/App.tsx')).toBe('typescript');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('detects JavaScript files', () => {
|
|
60
|
+
expect(detectLanguageFromPath('index.js')).toBe('javascript');
|
|
61
|
+
expect(detectLanguageFromPath('components/Button.jsx')).toBe('javascript');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('detects Python files', () => {
|
|
65
|
+
expect(detectLanguageFromPath('main.py')).toBe('python');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('detects Go files', () => {
|
|
69
|
+
expect(detectLanguageFromPath('main.go')).toBe('go');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('detects Rust files', () => {
|
|
73
|
+
expect(detectLanguageFromPath('lib.rs')).toBe('rust');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('detects Java files', () => {
|
|
77
|
+
expect(detectLanguageFromPath('Main.java')).toBe('java');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('detects Ruby files', () => {
|
|
81
|
+
expect(detectLanguageFromPath('app.rb')).toBe('ruby');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('detects shell scripts', () => {
|
|
85
|
+
expect(detectLanguageFromPath('install.sh')).toBe('bash');
|
|
86
|
+
expect(detectLanguageFromPath('run.bash')).toBe('bash');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('detects config files', () => {
|
|
90
|
+
expect(detectLanguageFromPath('config.yml')).toBe('yaml');
|
|
91
|
+
expect(detectLanguageFromPath('config.yaml')).toBe('yaml');
|
|
92
|
+
expect(detectLanguageFromPath('package.json')).toBe('json');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('detects web files', () => {
|
|
96
|
+
expect(detectLanguageFromPath('index.html')).toBe('html');
|
|
97
|
+
expect(detectLanguageFromPath('styles.css')).toBe('css');
|
|
98
|
+
expect(detectLanguageFromPath('styles.scss')).toBe('scss');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('returns empty string for unknown extensions', () => {
|
|
102
|
+
expect(detectLanguageFromPath('data.xyz')).toBe('');
|
|
103
|
+
expect(detectLanguageFromPath('README')).toBe('');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('handles nested paths', () => {
|
|
107
|
+
expect(detectLanguageFromPath('/Users/dev/project/src/index.ts')).toBe('typescript');
|
|
108
|
+
expect(detectLanguageFromPath('a/b/c/d/e.py')).toBe('python');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('handles uppercase extensions', () => {
|
|
112
|
+
expect(detectLanguageFromPath('file.TS')).toBe('typescript');
|
|
113
|
+
expect(detectLanguageFromPath('file.PY')).toBe('python');
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('ResearchResponse.searchResults', () => {
|
|
118
|
+
it('formats results with files', () => {
|
|
119
|
+
const result = ResearchResponse.searchResults({
|
|
120
|
+
files: [
|
|
121
|
+
{ path: 'src/utils.ts', matches: 3, line: 10 },
|
|
122
|
+
{ path: 'src/index.ts', matches: 1, line: 5 },
|
|
123
|
+
],
|
|
124
|
+
totalMatches: 4,
|
|
125
|
+
searchPattern: 'function',
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
expect(result.content[0].text).toContain('Found 4 matches');
|
|
129
|
+
expect(result.content[0].text).toContain('function');
|
|
130
|
+
expect(result.content[0].text).toContain('src/utils.ts');
|
|
131
|
+
expect(result.content[0].text).toContain('src/index.ts');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('handles empty results', () => {
|
|
135
|
+
const result = ResearchResponse.searchResults({
|
|
136
|
+
files: [],
|
|
137
|
+
totalMatches: 0,
|
|
138
|
+
searchPattern: 'nonexistent',
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
expect(result.content[0].text).toContain('No matches found');
|
|
142
|
+
expect(result.content[0].text).toContain('nonexistent');
|
|
143
|
+
expect(result.isEmpty).toBe(true);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('truncates file list at 10 files', () => {
|
|
147
|
+
const files = Array.from({ length: 15 }, (_, i) => ({
|
|
148
|
+
path: `file${i}.ts`,
|
|
149
|
+
matches: 1,
|
|
150
|
+
}));
|
|
151
|
+
|
|
152
|
+
const result = ResearchResponse.searchResults({
|
|
153
|
+
files,
|
|
154
|
+
totalMatches: 15,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
expect(result.content[0].text).toContain('and 5 more files');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('includes preview text when available', () => {
|
|
161
|
+
const result = ResearchResponse.searchResults({
|
|
162
|
+
files: [
|
|
163
|
+
{ path: 'src/utils.ts', matches: 1, preview: 'export function helper() {' },
|
|
164
|
+
],
|
|
165
|
+
totalMatches: 1,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
expect(result.content[0].text).toContain('export function helper()');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('handles non-string preview gracefully (no crash)', () => {
|
|
172
|
+
// preview could be a number or other non-string type from malformed data
|
|
173
|
+
const result = ResearchResponse.searchResults({
|
|
174
|
+
files: [
|
|
175
|
+
{ path: 'src/utils.ts', matches: 1, preview: 42 as unknown as string },
|
|
176
|
+
],
|
|
177
|
+
totalMatches: 1,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Should not crash and should not include garbled output
|
|
181
|
+
expect(result.content[0].text).toContain('src/utils.ts');
|
|
182
|
+
expect(result.content[0].text).not.toContain('.slice');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('handles undefined preview gracefully', () => {
|
|
186
|
+
const result = ResearchResponse.searchResults({
|
|
187
|
+
files: [
|
|
188
|
+
{ path: 'src/utils.ts', matches: 1 },
|
|
189
|
+
],
|
|
190
|
+
totalMatches: 1,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(result.content[0].text).toContain('src/utils.ts');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('includes repo info for GitHub results', () => {
|
|
197
|
+
const result = ResearchResponse.searchResults({
|
|
198
|
+
files: [
|
|
199
|
+
{ path: 'src/index.ts', repo: 'anthropic/claude', matches: 1 },
|
|
200
|
+
],
|
|
201
|
+
totalMatches: 1,
|
|
202
|
+
isLocal: false,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
expect(result.content[0].text).toContain('anthropic/claude');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('adds pagination hints when hasMore', () => {
|
|
209
|
+
const result = ResearchResponse.searchResults({
|
|
210
|
+
files: [{ path: 'file.ts', matches: 1 }],
|
|
211
|
+
totalMatches: 100,
|
|
212
|
+
pagination: { page: 1, total: 10, hasMore: true },
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
expect(result.hints).toContain('Next page: page=2');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('passes through MCP hints', () => {
|
|
219
|
+
const result = ResearchResponse.searchResults({
|
|
220
|
+
files: [{ path: 'file.ts', matches: 1 }],
|
|
221
|
+
totalMatches: 1,
|
|
222
|
+
mcpHints: ['Use localGetFileContent to read full file'],
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
expect(result.hints).toContain('Use localGetFileContent to read full file');
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe('ResearchResponse.fileContent', () => {
|
|
230
|
+
it('formats content with code fence', () => {
|
|
231
|
+
const result = ResearchResponse.fileContent({
|
|
232
|
+
path: 'src/utils.ts',
|
|
233
|
+
content: 'export function helper() {}',
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expect(result.content[0].text).toContain('📄 src/utils.ts');
|
|
237
|
+
expect(result.content[0].text).toContain('```typescript');
|
|
238
|
+
expect(result.content[0].text).toContain('export function helper()');
|
|
239
|
+
expect(result.content[0].text).toContain('```');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('includes line range info', () => {
|
|
243
|
+
const result = ResearchResponse.fileContent({
|
|
244
|
+
path: 'src/utils.ts',
|
|
245
|
+
content: 'line 10 content',
|
|
246
|
+
lines: { start: 10, end: 20 },
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
expect(result.content[0].text).toContain('lines 10-20');
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('uses explicit language when provided', () => {
|
|
253
|
+
const result = ResearchResponse.fileContent({
|
|
254
|
+
path: 'Dockerfile',
|
|
255
|
+
content: 'FROM node:18',
|
|
256
|
+
language: 'dockerfile',
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
expect(result.content[0].text).toContain('```dockerfile');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('adds hints for partial content', () => {
|
|
263
|
+
const result = ResearchResponse.fileContent({
|
|
264
|
+
path: 'src/large.ts',
|
|
265
|
+
content: 'partial...',
|
|
266
|
+
isPartial: true,
|
|
267
|
+
totalLines: 1000,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
expect(result.structuredContent.isPartial).toBe(true);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
describe('ResearchResponse.lspResult', () => {
|
|
275
|
+
it('formats definition results', () => {
|
|
276
|
+
const result = ResearchResponse.lspResult({
|
|
277
|
+
symbol: 'myFunction',
|
|
278
|
+
locations: [
|
|
279
|
+
{ uri: 'file:///src/utils.ts', line: 10, preview: 'function myFunction() {' },
|
|
280
|
+
],
|
|
281
|
+
type: 'definition',
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
expect(result.content[0].text).toContain('Definition for "myFunction"');
|
|
285
|
+
expect(result.content[0].text).toContain('utils.ts:10');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('formats reference results', () => {
|
|
289
|
+
const result = ResearchResponse.lspResult({
|
|
290
|
+
symbol: 'myFunction',
|
|
291
|
+
locations: [
|
|
292
|
+
{ uri: 'file:///src/index.ts', line: 5 },
|
|
293
|
+
{ uri: 'file:///src/app.ts', line: 20 },
|
|
294
|
+
],
|
|
295
|
+
type: 'references',
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
expect(result.content[0].text).toContain('References for "myFunction"');
|
|
299
|
+
expect(result.content[0].text).toContain('index.ts:5');
|
|
300
|
+
expect(result.content[0].text).toContain('app.ts:20');
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('handles empty locations', () => {
|
|
304
|
+
const result = ResearchResponse.lspResult({
|
|
305
|
+
symbol: 'unknownSymbol',
|
|
306
|
+
locations: [],
|
|
307
|
+
type: 'definition',
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
expect(result.content[0].text).toContain('No definition found');
|
|
311
|
+
expect(result.content[0].text).toContain('unknownSymbol');
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('adds appropriate follow-up hints', () => {
|
|
315
|
+
const result = ResearchResponse.lspResult({
|
|
316
|
+
symbol: 'fn',
|
|
317
|
+
locations: [{ uri: 'file:///src/utils.ts', line: 1 }],
|
|
318
|
+
type: 'definition',
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
expect(result.structuredContent.type).toBe('definition');
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
describe('ResearchResponse.repoStructure', () => {
|
|
326
|
+
it('formats directory structure', () => {
|
|
327
|
+
const result = ResearchResponse.repoStructure({
|
|
328
|
+
path: '/src',
|
|
329
|
+
structure: {
|
|
330
|
+
files: ['index.ts', 'utils.ts'],
|
|
331
|
+
folders: ['components', 'hooks'],
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
expect(result.content[0].text).toContain('📁 /src');
|
|
336
|
+
expect(result.content[0].text).toContain('📁 components');
|
|
337
|
+
expect(result.content[0].text).toContain('📄 index.ts');
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('includes owner/repo for GitHub repos', () => {
|
|
341
|
+
const result = ResearchResponse.repoStructure({
|
|
342
|
+
path: '',
|
|
343
|
+
structure: { files: ['README.md'], folders: ['src'] },
|
|
344
|
+
owner: 'anthropic',
|
|
345
|
+
repo: 'claude',
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
expect(result.content[0].text).toContain('anthropic/claude');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('truncates long lists', () => {
|
|
352
|
+
const files = Array.from({ length: 25 }, (_, i) => `file${i}.ts`);
|
|
353
|
+
const result = ResearchResponse.repoStructure({
|
|
354
|
+
path: '/',
|
|
355
|
+
structure: { files, folders: [] },
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// Only first 20 files shown
|
|
359
|
+
expect(result.content[0].text).not.toContain('file24.ts');
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
describe('ResearchResponse.packageSearch', () => {
|
|
364
|
+
it('formats npm package results', () => {
|
|
365
|
+
const result = ResearchResponse.packageSearch({
|
|
366
|
+
packages: [
|
|
367
|
+
{ name: 'express', version: '4.18.2', description: 'Fast web framework' },
|
|
368
|
+
{ name: 'koa', version: '2.14.1', description: 'Expressive middleware' },
|
|
369
|
+
],
|
|
370
|
+
registry: 'npm',
|
|
371
|
+
query: 'web framework',
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
expect(result.content[0].text).toContain('Found 2 packages');
|
|
375
|
+
expect(result.content[0].text).toContain('NPM');
|
|
376
|
+
expect(result.content[0].text).toContain('express@4.18.2');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('handles empty results', () => {
|
|
380
|
+
const result = ResearchResponse.packageSearch({
|
|
381
|
+
packages: [],
|
|
382
|
+
registry: 'pypi',
|
|
383
|
+
query: 'nonexistent-package',
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
expect(result.content[0].text).toContain('No packages found');
|
|
387
|
+
expect(result.isEmpty).toBe(true);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it('handles non-string description gracefully', () => {
|
|
391
|
+
const result = ResearchResponse.packageSearch({
|
|
392
|
+
packages: [
|
|
393
|
+
{ name: 'test-pkg', version: '1.0.0', description: undefined },
|
|
394
|
+
],
|
|
395
|
+
registry: 'npm',
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
expect(result.content[0].text).toContain('No description');
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('handles numeric description gracefully', () => {
|
|
402
|
+
const result = ResearchResponse.packageSearch({
|
|
403
|
+
packages: [
|
|
404
|
+
{ name: 'test-pkg', version: '1.0.0', description: 123 as unknown as string },
|
|
405
|
+
],
|
|
406
|
+
registry: 'npm',
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
// Should use 'No description' fallback for non-string
|
|
410
|
+
expect(result.content[0].text).toContain('No description');
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
describe('ResearchResponse.bulkResult', () => {
|
|
415
|
+
it('formats bulk operation summary', () => {
|
|
416
|
+
const result = ResearchResponse.bulkResult({
|
|
417
|
+
results: [
|
|
418
|
+
{ status: 'success', data: {} },
|
|
419
|
+
{ status: 'success', data: {} },
|
|
420
|
+
{ status: 'error', error: 'Failed' },
|
|
421
|
+
],
|
|
422
|
+
operation: 'search',
|
|
423
|
+
totalQueries: 3,
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
expect(result.content[0].text).toContain('Bulk search completed');
|
|
427
|
+
expect(result.content[0].text).toContain('Success: 2/3');
|
|
428
|
+
expect(result.content[0].text).toContain('Failed: 1/3');
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it('handles all success', () => {
|
|
432
|
+
const result = ResearchResponse.bulkResult({
|
|
433
|
+
results: [
|
|
434
|
+
{ status: 'success', data: {} },
|
|
435
|
+
{ status: 'success', data: {} },
|
|
436
|
+
],
|
|
437
|
+
operation: 'fetch',
|
|
438
|
+
totalQueries: 2,
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
expect(result.isError).toBe(false);
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it('marks as error when all fail', () => {
|
|
445
|
+
const result = ResearchResponse.bulkResult({
|
|
446
|
+
results: [
|
|
447
|
+
{ status: 'error', error: 'Failed' },
|
|
448
|
+
{ status: 'error', error: 'Failed' },
|
|
449
|
+
],
|
|
450
|
+
operation: 'search',
|
|
451
|
+
totalQueries: 2,
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
expect(result.isError).toBe(true);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('includes empty count when present', () => {
|
|
458
|
+
const result = ResearchResponse.bulkResult({
|
|
459
|
+
results: [
|
|
460
|
+
{ status: 'success', data: {} },
|
|
461
|
+
{ status: 'empty' },
|
|
462
|
+
],
|
|
463
|
+
operation: 'search',
|
|
464
|
+
totalQueries: 2,
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
expect(result.content[0].text).toContain('Empty: 1/2');
|
|
468
|
+
});
|
|
469
|
+
});
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for retry utilities.
|
|
3
|
+
*
|
|
4
|
+
* @module tests/unit/retry
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
8
|
+
import { withRetry, RETRY_CONFIGS } from '../../utils/retry.js';
|
|
9
|
+
|
|
10
|
+
describe('withRetry', () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
vi.useFakeTimers();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
vi.useRealTimers();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('returns immediately on success', async () => {
|
|
20
|
+
const operation = vi.fn().mockResolvedValue('success');
|
|
21
|
+
|
|
22
|
+
const resultPromise = withRetry(operation, RETRY_CONFIGS.local);
|
|
23
|
+
const result = await resultPromise;
|
|
24
|
+
|
|
25
|
+
expect(result).toBe('success');
|
|
26
|
+
expect(operation).toHaveBeenCalledTimes(1);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('retries on retryable error', async () => {
|
|
30
|
+
const operation = vi
|
|
31
|
+
.fn()
|
|
32
|
+
.mockRejectedValueOnce({ code: 'EBUSY' })
|
|
33
|
+
.mockResolvedValue('success');
|
|
34
|
+
|
|
35
|
+
const resultPromise = withRetry(operation, RETRY_CONFIGS.local);
|
|
36
|
+
|
|
37
|
+
// First call fails immediately
|
|
38
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
39
|
+
|
|
40
|
+
// Wait for delay and retry
|
|
41
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
42
|
+
|
|
43
|
+
const result = await resultPromise;
|
|
44
|
+
|
|
45
|
+
expect(result).toBe('success');
|
|
46
|
+
expect(operation).toHaveBeenCalledTimes(2);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('throws on non-retryable error', async () => {
|
|
50
|
+
const operation = vi.fn().mockRejectedValue({ code: 'ENOENT' });
|
|
51
|
+
|
|
52
|
+
await expect(withRetry(operation, RETRY_CONFIGS.local)).rejects.toEqual({
|
|
53
|
+
code: 'ENOENT',
|
|
54
|
+
});
|
|
55
|
+
expect(operation).toHaveBeenCalledTimes(1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('applies exponential backoff', async () => {
|
|
59
|
+
const operation = vi
|
|
60
|
+
.fn()
|
|
61
|
+
.mockRejectedValueOnce({ code: 'ETIMEDOUT' })
|
|
62
|
+
.mockRejectedValueOnce({ code: 'ETIMEDOUT' })
|
|
63
|
+
.mockResolvedValue('success');
|
|
64
|
+
|
|
65
|
+
const config = {
|
|
66
|
+
maxAttempts: 3,
|
|
67
|
+
initialDelayMs: 100,
|
|
68
|
+
maxDelayMs: 1000,
|
|
69
|
+
backoffMultiplier: 2,
|
|
70
|
+
retryOn: (err: unknown) => (err as { code?: string })?.code === 'ETIMEDOUT',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const resultPromise = withRetry(operation, config);
|
|
74
|
+
|
|
75
|
+
// First attempt fails
|
|
76
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
77
|
+
|
|
78
|
+
// First retry after 100ms
|
|
79
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
80
|
+
expect(operation).toHaveBeenCalledTimes(2);
|
|
81
|
+
|
|
82
|
+
// Second retry after 200ms (100 * 2)
|
|
83
|
+
await vi.advanceTimersByTimeAsync(200);
|
|
84
|
+
|
|
85
|
+
const result = await resultPromise;
|
|
86
|
+
expect(result).toBe('success');
|
|
87
|
+
expect(operation).toHaveBeenCalledTimes(3);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('caps delay at maxDelayMs', async () => {
|
|
91
|
+
const operation = vi
|
|
92
|
+
.fn()
|
|
93
|
+
.mockRejectedValueOnce({ code: 'ETIMEDOUT' })
|
|
94
|
+
.mockRejectedValueOnce({ code: 'ETIMEDOUT' })
|
|
95
|
+
.mockResolvedValue('success');
|
|
96
|
+
|
|
97
|
+
const config = {
|
|
98
|
+
maxAttempts: 3,
|
|
99
|
+
initialDelayMs: 500,
|
|
100
|
+
maxDelayMs: 600, // Cap at 600ms
|
|
101
|
+
backoffMultiplier: 2,
|
|
102
|
+
retryOn: (err: unknown) => (err as { code?: string })?.code === 'ETIMEDOUT',
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const resultPromise = withRetry(operation, config);
|
|
106
|
+
|
|
107
|
+
// First attempt fails
|
|
108
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
109
|
+
|
|
110
|
+
// First retry after 500ms
|
|
111
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
112
|
+
|
|
113
|
+
// Second retry should be capped at 600ms (not 1000ms)
|
|
114
|
+
await vi.advanceTimersByTimeAsync(600);
|
|
115
|
+
|
|
116
|
+
const result = await resultPromise;
|
|
117
|
+
expect(result).toBe('success');
|
|
118
|
+
expect(operation).toHaveBeenCalledTimes(3);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('throws last error after all retries exhausted', async () => {
|
|
122
|
+
const finalError = new Error('Operation failed');
|
|
123
|
+
const operation = vi.fn().mockRejectedValue(finalError);
|
|
124
|
+
|
|
125
|
+
const config = {
|
|
126
|
+
maxAttempts: 2,
|
|
127
|
+
initialDelayMs: 50,
|
|
128
|
+
maxDelayMs: 100,
|
|
129
|
+
backoffMultiplier: 2,
|
|
130
|
+
retryOn: () => true,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Start the operation and immediately handle the promise
|
|
134
|
+
const resultPromise = withRetry(operation, config).catch((e) => e);
|
|
135
|
+
|
|
136
|
+
// Run all timers to completion
|
|
137
|
+
await vi.runAllTimersAsync();
|
|
138
|
+
|
|
139
|
+
// Now check the result
|
|
140
|
+
const result = await resultPromise;
|
|
141
|
+
expect(result).toBe(finalError);
|
|
142
|
+
expect(operation).toHaveBeenCalledTimes(2);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('RETRY_CONFIGS', () => {
|
|
147
|
+
describe('lsp config', () => {
|
|
148
|
+
it('retries on LSP not ready errors', () => {
|
|
149
|
+
const config = RETRY_CONFIGS.lsp;
|
|
150
|
+
|
|
151
|
+
expect(config.retryOn({ code: 'LSP_NOT_READY' })).toBe(true);
|
|
152
|
+
expect(config.retryOn({ message: 'server not started' })).toBe(true);
|
|
153
|
+
expect(config.retryOn({ message: 'not initialized' })).toBe(true);
|
|
154
|
+
expect(config.retryOn({ code: 'ECONNREFUSED' })).toBe(true);
|
|
155
|
+
expect(config.retryOn({ code: 'ETIMEDOUT' })).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('does not retry on unrelated errors', () => {
|
|
159
|
+
const config = RETRY_CONFIGS.lsp;
|
|
160
|
+
|
|
161
|
+
expect(config.retryOn({ code: 'ENOENT' })).toBe(false);
|
|
162
|
+
expect(config.retryOn({ message: 'Symbol not found' })).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('github config', () => {
|
|
167
|
+
it('retries on rate limit errors', () => {
|
|
168
|
+
const config = RETRY_CONFIGS.github;
|
|
169
|
+
|
|
170
|
+
expect(config.retryOn({ status: 429 })).toBe(true);
|
|
171
|
+
expect(config.retryOn({ status: 403 })).toBe(true);
|
|
172
|
+
expect(config.retryOn({ message: 'rate limit exceeded' })).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('retries on server errors', () => {
|
|
176
|
+
const config = RETRY_CONFIGS.github;
|
|
177
|
+
|
|
178
|
+
expect(config.retryOn({ status: 500 })).toBe(true);
|
|
179
|
+
expect(config.retryOn({ status: 502 })).toBe(true);
|
|
180
|
+
expect(config.retryOn({ status: 503 })).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('does not retry on client errors', () => {
|
|
184
|
+
const config = RETRY_CONFIGS.github;
|
|
185
|
+
|
|
186
|
+
expect(config.retryOn({ status: 400 })).toBe(false);
|
|
187
|
+
expect(config.retryOn({ status: 404 })).toBe(false);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('local config', () => {
|
|
192
|
+
it('retries on file busy errors', () => {
|
|
193
|
+
const config = RETRY_CONFIGS.local;
|
|
194
|
+
|
|
195
|
+
expect(config.retryOn({ code: 'EBUSY' })).toBe(true);
|
|
196
|
+
expect(config.retryOn({ code: 'EAGAIN' })).toBe(true);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('retries on timeout', () => {
|
|
200
|
+
const config = RETRY_CONFIGS.local;
|
|
201
|
+
|
|
202
|
+
expect(config.retryOn({ code: 'ETIMEDOUT' })).toBe(true);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|