@nathapp/nax 0.18.1
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/.gitlab-ci.yml +96 -0
- package/BRIEF.md +140 -0
- package/CHANGELOG.md +60 -0
- package/CLAUDE.md +159 -0
- package/README.md +373 -0
- package/US-007-IMPLEMENTATION.md +139 -0
- package/bin/nax.ts +930 -0
- package/biome.json +14 -0
- package/bun.lock +168 -0
- package/bunfig.toml +11 -0
- package/docs/20260216-fix-plan-context-review.md +56 -0
- package/docs/20260216-relentless-vs-ngent-comparison.md +208 -0
- package/docs/20260216-v02-plan.md +136 -0
- package/docs/20260216-v02-review.md +685 -0
- package/docs/20260217-dogfood-findings.md +56 -0
- package/docs/20260217-p2-plus-plan.md +117 -0
- package/docs/20260217-partial-fixes-plan.md +62 -0
- package/docs/20260217-plan-analyze-spec.md +117 -0
- package/docs/20260217-post-impl-review.md +1137 -0
- package/docs/20260217-quick-wins-plan.md +66 -0
- package/docs/20260217-split-runner-plan.md +75 -0
- package/docs/20260217-v03-impl-plan.md +80 -0
- package/docs/20260217-v03-post-impl-review.md +589 -0
- package/docs/20260217-v04-impl-plan.md +86 -0
- package/docs/20260217-v05-post-impl-review.md +850 -0
- package/docs/20260217-v06-post-impl-review.md +817 -0
- package/docs/20260218-adr003-port-plan.md +151 -0
- package/docs/20260218-review-adr003-verification.md +175 -0
- package/docs/20260219-fix-plan-bug16-19.md +79 -0
- package/docs/20260219-fix-plan-bug20-22.md +114 -0
- package/docs/20260219-plan-llm-routing.md +116 -0
- package/docs/20260219-review-bug20-22-fixes.md +135 -0
- package/docs/20260219-routing-baseline-keyword.md +63 -0
- package/docs/20260220-plan-structured-logging-p1.md +80 -0
- package/docs/20260220-plan-structured-logging-p2.md +37 -0
- package/docs/20260220-review-llm-routing.md +180 -0
- package/docs/20260220-review-post-fix-llm-routing.md +70 -0
- package/docs/20260221-fix-plan-relevantfiles-split.md +101 -0
- package/docs/20260221-fix-plan-routing-mode.md +125 -0
- package/docs/20260221-review-v0.9-implementation.md +379 -0
- package/docs/20260222-fix-plan-v091-routing-isolation.md +197 -0
- package/docs/20260223-fix-plan-prompt-audit.md +62 -0
- package/docs/20260224-nax-roadmap-phases.md +189 -0
- package/docs/20260225-phase2-llm-service-layer.md +401 -0
- package/docs/20260225-review-v0.10.1.md +187 -0
- package/docs/20260303-v010-implementation-plan.md +165 -0
- package/docs/CLAUDE.md.bak +191 -0
- package/docs/ROADMAP.md +165 -0
- package/docs/SPEC-rectification.md +0 -0
- package/docs/SPEC.md +324 -0
- package/docs/US-001-plugin-loading-verification.md +152 -0
- package/docs/architecture-analysis.md +1076 -0
- package/docs/bugs/BUG-21-escalation-null-attempts.md +48 -0
- package/docs/bugs-from-dogfood-run-c.md +243 -0
- package/docs/code-review-20260228.md +612 -0
- package/docs/code-review-v0.15.0.md +629 -0
- package/docs/hook-lifecycle-test-plan.md +149 -0
- package/docs/releases/v0.11.0-and-earlier.md +20 -0
- package/docs/releases/v0.12.0.md +15 -0
- package/docs/releases/v0.13.0.md +14 -0
- package/docs/releases/v0.14.0.md +20 -0
- package/docs/releases/v0.14.1.md +36 -0
- package/docs/releases/v0.14.2.md +51 -0
- package/docs/releases/v0.14.3.md +174 -0
- package/docs/releases/v0.14.4.md +94 -0
- package/docs/releases/v0.15.0.md +502 -0
- package/docs/releases/v0.15.1.md +170 -0
- package/docs/releases/v0.15.3.md +193 -0
- package/docs/specs/status-file-v0.10.1.md +812 -0
- package/docs/v0.10-global-config.md +206 -0
- package/docs/v0.10-plugin-system.md +415 -0
- package/docs/v0.10-prompt-optimizer.md +234 -0
- package/docs/v0.3-spec.md +244 -0
- package/docs/v0.4-spec.md +140 -0
- package/docs/v0.5-spec.md +237 -0
- package/docs/v0.6-spec.md +371 -0
- package/docs/v0.7-spec.md +177 -0
- package/docs/v0.8-llm-routing.md +206 -0
- package/docs/v0.8-structured-logging.md +132 -0
- package/docs/v0.9.3-prompt-audit.md +112 -0
- package/examples/plugins/console-reporter/index.test.ts +207 -0
- package/examples/plugins/console-reporter/index.ts +110 -0
- package/nax/config.json +147 -0
- package/nax/features/bugfix-v0171/prd.json +52 -0
- package/nax/features/config-management/prd.json +108 -0
- package/nax/features/config-management/progress.txt +5 -0
- package/nax/features/diagnose/acceptance.test.ts +412 -0
- package/nax/features/diagnose/prd.json +41 -0
- package/nax/features/orchestration-fixes/prd.json +89 -0
- package/nax/features/orchestration-fixes/progress.txt +1 -0
- package/nax/features/plugin-integration/US-007-VERIFICATION.md +259 -0
- package/nax/features/plugin-integration/prd.json +208 -0
- package/nax/features/plugin-integration/progress.txt +5 -0
- package/nax/features/precheck/prd.json +205 -0
- package/nax/features/precheck/progress.txt +15 -0
- package/nax/features/structured-logging/prd.json +199 -0
- package/nax/features/unlock/prd.json +36 -0
- package/package.json +47 -0
- package/src/acceptance/fix-generator.ts +348 -0
- package/src/acceptance/generator.ts +282 -0
- package/src/acceptance/index.ts +30 -0
- package/src/acceptance/types.ts +79 -0
- package/src/agents/claude-decompose.ts +169 -0
- package/src/agents/claude-plan.ts +139 -0
- package/src/agents/claude.ts +324 -0
- package/src/agents/cost.ts +268 -0
- package/src/agents/index.ts +13 -0
- package/src/agents/registry.ts +48 -0
- package/src/agents/types-extended.ts +133 -0
- package/src/agents/types.ts +113 -0
- package/src/agents/validation.ts +69 -0
- package/src/analyze/classifier.ts +305 -0
- package/src/analyze/index.ts +16 -0
- package/src/analyze/scanner.ts +175 -0
- package/src/analyze/types.ts +51 -0
- package/src/cli/accept.ts +108 -0
- package/src/cli/analyze-parser.ts +284 -0
- package/src/cli/analyze.ts +207 -0
- package/src/cli/config.ts +561 -0
- package/src/cli/constitution.ts +109 -0
- package/src/cli/diagnose-analysis.ts +159 -0
- package/src/cli/diagnose-formatter.ts +87 -0
- package/src/cli/diagnose.ts +203 -0
- package/src/cli/generate.ts +127 -0
- package/src/cli/index.ts +37 -0
- package/src/cli/init.ts +188 -0
- package/src/cli/interact.ts +295 -0
- package/src/cli/plan.ts +198 -0
- package/src/cli/plugins.ts +111 -0
- package/src/cli/prompts.ts +295 -0
- package/src/cli/runs.ts +174 -0
- package/src/cli/status-cost.ts +151 -0
- package/src/cli/status-features.ts +338 -0
- package/src/cli/status.ts +13 -0
- package/src/commands/common.ts +171 -0
- package/src/commands/diagnose.ts +17 -0
- package/src/commands/index.ts +8 -0
- package/src/commands/logs.ts +384 -0
- package/src/commands/precheck.ts +86 -0
- package/src/commands/unlock.ts +96 -0
- package/src/config/defaults.ts +160 -0
- package/src/config/index.ts +22 -0
- package/src/config/loader.ts +121 -0
- package/src/config/merger.ts +147 -0
- package/src/config/path-security.ts +121 -0
- package/src/config/paths.ts +27 -0
- package/src/config/schema.ts +56 -0
- package/src/config/schemas.ts +286 -0
- package/src/config/types.ts +423 -0
- package/src/config/validate.ts +103 -0
- package/src/constitution/generator.ts +191 -0
- package/src/constitution/generators/aider.ts +41 -0
- package/src/constitution/generators/claude.ts +35 -0
- package/src/constitution/generators/cursor.ts +36 -0
- package/src/constitution/generators/opencode.ts +38 -0
- package/src/constitution/generators/types.ts +33 -0
- package/src/constitution/generators/windsurf.ts +36 -0
- package/src/constitution/index.ts +10 -0
- package/src/constitution/loader.ts +133 -0
- package/src/constitution/types.ts +31 -0
- package/src/context/auto-detect.ts +227 -0
- package/src/context/builder.ts +246 -0
- package/src/context/elements.ts +83 -0
- package/src/context/formatter.ts +107 -0
- package/src/context/generator.ts +129 -0
- package/src/context/generators/aider.ts +34 -0
- package/src/context/generators/claude.ts +28 -0
- package/src/context/generators/cursor.ts +28 -0
- package/src/context/generators/opencode.ts +30 -0
- package/src/context/generators/windsurf.ts +28 -0
- package/src/context/greenfield.ts +114 -0
- package/src/context/index.ts +33 -0
- package/src/context/injector.ts +279 -0
- package/src/context/test-scanner.ts +370 -0
- package/src/context/types.ts +98 -0
- package/src/errors.ts +67 -0
- package/src/execution/batching.ts +157 -0
- package/src/execution/crash-recovery.ts +373 -0
- package/src/execution/escalation/escalation.ts +44 -0
- package/src/execution/escalation/index.ts +13 -0
- package/src/execution/escalation/tier-escalation.ts +295 -0
- package/src/execution/escalation/tier-outcome.ts +158 -0
- package/src/execution/helpers.ts +38 -0
- package/src/execution/index.ts +45 -0
- package/src/execution/lifecycle/acceptance-loop.ts +272 -0
- package/src/execution/lifecycle/headless-formatter.ts +85 -0
- package/src/execution/lifecycle/index.ts +12 -0
- package/src/execution/lifecycle/parallel-lifecycle.ts +101 -0
- package/src/execution/lifecycle/precheck-runner.ts +140 -0
- package/src/execution/lifecycle/run-cleanup.ts +81 -0
- package/src/execution/lifecycle/run-completion.ts +129 -0
- package/src/execution/lifecycle/run-initialization.ts +141 -0
- package/src/execution/lifecycle/run-lifecycle.ts +312 -0
- package/src/execution/lifecycle/run-setup.ts +204 -0
- package/src/execution/lifecycle/story-hooks.ts +38 -0
- package/src/execution/lifecycle/story-size-prompts.ts +123 -0
- package/src/execution/lock.ts +115 -0
- package/src/execution/parallel-executor.ts +216 -0
- package/src/execution/parallel.ts +400 -0
- package/src/execution/pid-registry.ts +280 -0
- package/src/execution/pipeline-result-handler.ts +388 -0
- package/src/execution/post-verify-rectification.ts +188 -0
- package/src/execution/post-verify.ts +274 -0
- package/src/execution/progress.ts +25 -0
- package/src/execution/prompts.ts +127 -0
- package/src/execution/queue-handler.ts +109 -0
- package/src/execution/rectification.ts +13 -0
- package/src/execution/runner.ts +377 -0
- package/src/execution/sequential-executor.ts +388 -0
- package/src/execution/status-file.ts +264 -0
- package/src/execution/status-writer.ts +139 -0
- package/src/execution/story-context.ts +229 -0
- package/src/execution/test-output-parser.ts +14 -0
- package/src/execution/verification.ts +72 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/runner.ts +286 -0
- package/src/hooks/types.ts +67 -0
- package/src/interaction/chain.ts +154 -0
- package/src/interaction/index.ts +60 -0
- package/src/interaction/init.ts +83 -0
- package/src/interaction/plugins/auto.ts +217 -0
- package/src/interaction/plugins/cli.ts +300 -0
- package/src/interaction/plugins/telegram.ts +384 -0
- package/src/interaction/plugins/webhook.ts +258 -0
- package/src/interaction/state.ts +171 -0
- package/src/interaction/triggers.ts +229 -0
- package/src/interaction/types.ts +163 -0
- package/src/logger/formatters.ts +84 -0
- package/src/logger/index.ts +16 -0
- package/src/logger/logger.ts +298 -0
- package/src/logger/types.ts +48 -0
- package/src/logging/formatter.ts +355 -0
- package/src/logging/index.ts +22 -0
- package/src/logging/types.ts +93 -0
- package/src/metrics/aggregator.ts +190 -0
- package/src/metrics/index.ts +14 -0
- package/src/metrics/tracker.ts +200 -0
- package/src/metrics/types.ts +109 -0
- package/src/optimizer/index.ts +62 -0
- package/src/optimizer/noop.optimizer.ts +24 -0
- package/src/optimizer/rule-based.optimizer.ts +248 -0
- package/src/optimizer/types.ts +53 -0
- package/src/pipeline/events.ts +130 -0
- package/src/pipeline/index.ts +19 -0
- package/src/pipeline/runner.ts +161 -0
- package/src/pipeline/stages/acceptance.ts +197 -0
- package/src/pipeline/stages/completion.ts +99 -0
- package/src/pipeline/stages/constitution.ts +63 -0
- package/src/pipeline/stages/context.ts +117 -0
- package/src/pipeline/stages/execution.ts +194 -0
- package/src/pipeline/stages/index.ts +62 -0
- package/src/pipeline/stages/optimizer.ts +74 -0
- package/src/pipeline/stages/prompt.ts +57 -0
- package/src/pipeline/stages/queue-check.ts +103 -0
- package/src/pipeline/stages/review.ts +181 -0
- package/src/pipeline/stages/routing.ts +81 -0
- package/src/pipeline/stages/verify.ts +100 -0
- package/src/pipeline/types.ts +167 -0
- package/src/plugins/index.ts +31 -0
- package/src/plugins/loader.ts +287 -0
- package/src/plugins/registry.ts +168 -0
- package/src/plugins/types.ts +327 -0
- package/src/plugins/validator.ts +352 -0
- package/src/prd/index.ts +172 -0
- package/src/prd/types.ts +202 -0
- package/src/precheck/checks-blockers.ts +391 -0
- package/src/precheck/checks-warnings.ts +142 -0
- package/src/precheck/checks.ts +30 -0
- package/src/precheck/index.ts +247 -0
- package/src/precheck/story-size-gate.ts +144 -0
- package/src/precheck/types.ts +31 -0
- package/src/queue/index.ts +2 -0
- package/src/queue/manager.ts +254 -0
- package/src/queue/types.ts +54 -0
- package/src/review/index.ts +8 -0
- package/src/review/runner.ts +172 -0
- package/src/review/types.ts +66 -0
- package/src/routing/builder.ts +81 -0
- package/src/routing/chain.ts +74 -0
- package/src/routing/index.ts +16 -0
- package/src/routing/loader.ts +58 -0
- package/src/routing/router.ts +303 -0
- package/src/routing/strategies/adaptive.ts +215 -0
- package/src/routing/strategies/index.ts +8 -0
- package/src/routing/strategies/keyword.ts +163 -0
- package/src/routing/strategies/llm-prompts.ts +209 -0
- package/src/routing/strategies/llm.ts +235 -0
- package/src/routing/strategies/manual.ts +50 -0
- package/src/routing/strategy.ts +99 -0
- package/src/tdd/cleanup.ts +111 -0
- package/src/tdd/index.ts +23 -0
- package/src/tdd/isolation.ts +123 -0
- package/src/tdd/orchestrator.ts +383 -0
- package/src/tdd/prompts.ts +270 -0
- package/src/tdd/rectification-gate.ts +183 -0
- package/src/tdd/session-runner.ts +179 -0
- package/src/tdd/types.ts +81 -0
- package/src/tdd/verdict.ts +271 -0
- package/src/tui/App.tsx +265 -0
- package/src/tui/components/AgentPanel.tsx +75 -0
- package/src/tui/components/CostOverlay.tsx +118 -0
- package/src/tui/components/HelpOverlay.tsx +107 -0
- package/src/tui/components/StatusBar.tsx +63 -0
- package/src/tui/components/StoriesPanel.tsx +177 -0
- package/src/tui/hooks/useKeyboard.ts +142 -0
- package/src/tui/hooks/useLayout.ts +137 -0
- package/src/tui/hooks/usePipelineEvents.ts +183 -0
- package/src/tui/hooks/usePty.ts +194 -0
- package/src/tui/index.tsx +38 -0
- package/src/tui/types.ts +76 -0
- package/src/utils/git.ts +83 -0
- package/src/utils/queue-writer.ts +54 -0
- package/src/verification/executor.ts +235 -0
- package/src/verification/gate.ts +207 -0
- package/src/verification/index.ts +12 -0
- package/src/verification/parser.ts +230 -0
- package/src/verification/rectification.ts +108 -0
- package/src/verification/types.ts +113 -0
- package/src/worktree/dispatcher.ts +65 -0
- package/src/worktree/index.ts +2 -0
- package/src/worktree/manager.ts +187 -0
- package/src/worktree/merge.ts +301 -0
- package/src/worktree/types.ts +4 -0
- package/test/TEST_COVERAGE_US001.md +217 -0
- package/test/TEST_COVERAGE_US003.md +84 -0
- package/test/TEST_COVERAGE_US005.md +86 -0
- package/test/US-002-orchestrator.test.ts +246 -0
- package/test/acceptance/cm-003-default-view.test.ts +194 -0
- package/test/execution/pid-registry.test.ts +240 -0
- package/test/execution/post-verify.test.ts +224 -0
- package/test/helpers/timeout.ts +42 -0
- package/test/integration/US-002-TEST-SUMMARY.md +107 -0
- package/test/integration/US-003-TEST-SUMMARY.md +149 -0
- package/test/integration/US-004-TEST-SUMMARY.md +106 -0
- package/test/integration/US-005-TEST-SUMMARY.md +138 -0
- package/test/integration/US-007-TEST-SUMMARY.md +100 -0
- package/test/integration/agent-validation.test.ts +439 -0
- package/test/integration/analyze-integration.test.ts +261 -0
- package/test/integration/analyze-scanner.test.ts +131 -0
- package/test/integration/cli-config-default-edge-cases.test.ts +222 -0
- package/test/integration/cli-config-default-view.test.ts +229 -0
- package/test/integration/cli-config-diff.test.ts +460 -0
- package/test/integration/cli-config.test.ts +736 -0
- package/test/integration/cli-diagnose.test.ts +592 -0
- package/test/integration/cli-logs.test.ts +314 -0
- package/test/integration/cli-plugins.test.ts +678 -0
- package/test/integration/cli-precheck.test.ts +371 -0
- package/test/integration/cli-run-headless.test.ts +173 -0
- package/test/integration/cli.test.ts +75 -0
- package/test/integration/config/merger.test.ts +465 -0
- package/test/integration/config/paths.test.ts +51 -0
- package/test/integration/config-loader.test.ts +265 -0
- package/test/integration/config.test.ts +444 -0
- package/test/integration/context-integration.test.ts +702 -0
- package/test/integration/context-provider-injection.test.ts +506 -0
- package/test/integration/context-verification-integration.test.ts +295 -0
- package/test/integration/e2e.test.ts +896 -0
- package/test/integration/execution.test.ts +625 -0
- package/test/integration/helpers.test.ts +295 -0
- package/test/integration/hooks.test.ts +361 -0
- package/test/integration/interaction-chain-pipeline.test.ts +464 -0
- package/test/integration/isolation.test.ts +143 -0
- package/test/integration/logger.test.ts +461 -0
- package/test/integration/parallel.test.ts +250 -0
- package/test/integration/path-security.test.ts +173 -0
- package/test/integration/pipeline-acceptance.test.ts +302 -0
- package/test/integration/pipeline-events.test.ts +475 -0
- package/test/integration/pipeline.test.ts +658 -0
- package/test/integration/plan.test.ts +157 -0
- package/test/integration/plugin-routing.test.ts +921 -0
- package/test/integration/plugins/config-integration.test.ts +172 -0
- package/test/integration/plugins/config-resolution.test.ts +522 -0
- package/test/integration/plugins/loader.test.ts +641 -0
- package/test/integration/plugins/registry.test.ts +746 -0
- package/test/integration/plugins/validator.test.ts +563 -0
- package/test/integration/prd-pause.test.ts +205 -0
- package/test/integration/prd-resolvers.test.ts +185 -0
- package/test/integration/precheck-integration.test.ts +468 -0
- package/test/integration/precheck.test.ts +805 -0
- package/test/integration/progress.test.ts +34 -0
- package/test/integration/rectification-flow.test.ts +512 -0
- package/test/integration/reporter-lifecycle.test.ts +860 -0
- package/test/integration/review-config-commands.test.ts +319 -0
- package/test/integration/review-config-schema.test.ts +116 -0
- package/test/integration/review-plugin-integration.test.ts +722 -0
- package/test/integration/review.test.ts +149 -0
- package/test/integration/routing-stage-bug-021.test.ts +274 -0
- package/test/integration/routing-stage-greenfield.test.ts +286 -0
- package/test/integration/runner-config-plugins.test.ts +461 -0
- package/test/integration/runner-fixes.test.ts +399 -0
- package/test/integration/runner-plugin-integration.test.ts +543 -0
- package/test/integration/runner.test.ts +1679 -0
- package/test/integration/s5-greenfield-fallback.test.ts +297 -0
- package/test/integration/status-file-integration.test.ts +325 -0
- package/test/integration/status-file.test.ts +379 -0
- package/test/integration/status-writer.test.ts +345 -0
- package/test/integration/story-id-in-events.test.ts +273 -0
- package/test/integration/tdd-cleanup.test.ts +246 -0
- package/test/integration/tdd-orchestrator.test.ts +1762 -0
- package/test/integration/test-scanner.test.ts +403 -0
- package/test/integration/verification-asset-check.test.ts +142 -0
- package/test/integration/verify-stage.test.ts +275 -0
- package/test/integration/worktree/manager.test.ts +218 -0
- package/test/integration/worktree/merge.test.ts +341 -0
- package/test/manual/logging-formatter-demo.ts +158 -0
- package/test/ui/tui-agent-panel.test.tsx +99 -0
- package/test/ui/tui-controls.test.ts +334 -0
- package/test/ui/tui-cost-and-pty.test.ts +189 -0
- package/test/ui/tui-layout.test.ts +378 -0
- package/test/ui/tui-pty-integration.test.tsx +159 -0
- package/test/ui/tui-stories.test.ts +332 -0
- package/test/unit/acceptance.test.ts +186 -0
- package/test/unit/agent-stderr-capture.test.ts +146 -0
- package/test/unit/analyze-classifier.test.ts +215 -0
- package/test/unit/analyze.test.ts +224 -0
- package/test/unit/auto-detect.test.ts +249 -0
- package/test/unit/cli-status.test.ts +417 -0
- package/test/unit/commands/common.test.ts +320 -0
- package/test/unit/commands/logs.test.ts +416 -0
- package/test/unit/commands/unlock.test.ts +319 -0
- package/test/unit/constitution-generators.test.ts +160 -0
- package/test/unit/constitution.test.ts +209 -0
- package/test/unit/context.test.ts +1722 -0
- package/test/unit/cost.test.ts +231 -0
- package/test/unit/crash-recovery.test.ts +308 -0
- package/test/unit/escalation.test.ts +126 -0
- package/test/unit/execution-logging-stderr.test.ts +156 -0
- package/test/unit/execution-stage.test.ts +122 -0
- package/test/unit/fix-generator.test.ts +275 -0
- package/test/unit/formatters.test.ts +469 -0
- package/test/unit/greenfield.test.ts +179 -0
- package/test/unit/helpers.test.ts +317 -0
- package/test/unit/interaction/human-review-trigger.test.ts +164 -0
- package/test/unit/interaction-network-failures.test.ts +389 -0
- package/test/unit/interaction-plugins.test.ts +164 -0
- package/test/unit/isolation.test.ts +134 -0
- package/test/unit/logging/formatter.test.ts +455 -0
- package/test/unit/merge.test.ts +268 -0
- package/test/unit/metrics.test.ts +276 -0
- package/test/unit/optimizer/noop.optimizer.test.ts +125 -0
- package/test/unit/optimizer/rule-based.optimizer.test.ts +358 -0
- package/test/unit/prd-auto-default.test.ts +290 -0
- package/test/unit/prd-failure-category.test.ts +176 -0
- package/test/unit/prd-get-next-story.test.ts +186 -0
- package/test/unit/precheck-checks.test.ts +840 -0
- package/test/unit/precheck-story-size-gate.test.ts +287 -0
- package/test/unit/precheck-types.test.ts +142 -0
- package/test/unit/prompts.test.ts +475 -0
- package/test/unit/queue.test.ts +237 -0
- package/test/unit/rectification.test.ts +284 -0
- package/test/unit/registry.test.ts +287 -0
- package/test/unit/routing.test.ts +937 -0
- package/test/unit/run-lifecycle.test.ts +140 -0
- package/test/unit/storyid-events.test.ts +224 -0
- package/test/unit/tdd-verdict.test.ts +492 -0
- package/test/unit/test-output-parser.test.ts +377 -0
- package/test/unit/verdict.test.ts +324 -0
- package/test/unit/worktree-manager.test.ts +158 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# US-005: Plugin Routing Integration - Test Summary
|
|
2
|
+
|
|
3
|
+
**Story:** Plugin routing strategies integrate into router chain
|
|
4
|
+
|
|
5
|
+
**Test File:** `test/integration/plugin-routing.test.ts`
|
|
6
|
+
|
|
7
|
+
**Status:** ✅ Tests written and failing (as expected)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Test Coverage
|
|
12
|
+
|
|
13
|
+
### AC1: Plugin routers are tried before the built-in routing strategy
|
|
14
|
+
|
|
15
|
+
**Tests (4):**
|
|
16
|
+
- ✅ Plugin routers execute before built-in keyword strategy
|
|
17
|
+
- ✅ Multiple plugin routers maintain load order
|
|
18
|
+
- ✅ Plugin routers are inserted before manual strategy
|
|
19
|
+
- ✅ Plugin routers are inserted before llm strategy
|
|
20
|
+
|
|
21
|
+
**Coverage:** Validates that plugin routers are prepended to the strategy chain and execute in load order before any built-in strategies.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
### AC2: First plugin router that returns a non-null result wins
|
|
26
|
+
|
|
27
|
+
**Tests (5):**
|
|
28
|
+
- ✅ First plugin router decision is used
|
|
29
|
+
- ✅ Second plugin router is used when first returns null
|
|
30
|
+
- ✅ Plugin router overrides built-in keyword strategy
|
|
31
|
+
- ✅ Third plugin router is used when first two return null
|
|
32
|
+
- ✅ Plugin router can delegate based on conditional logic (integration test)
|
|
33
|
+
|
|
34
|
+
**Coverage:** Validates the chain precedence rules where the first non-null decision wins, and tests realistic scenarios where plugins selectively handle certain stories.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
### AC3: If all plugin routers return null, built-in strategy is used as fallback
|
|
39
|
+
|
|
40
|
+
**Tests (4):**
|
|
41
|
+
- ✅ Keyword strategy is used when all plugin routers return null
|
|
42
|
+
- ✅ Keyword strategy handles complex story when plugins return null
|
|
43
|
+
- ✅ Manual strategy is used as fallback when plugins return null
|
|
44
|
+
- ✅ Empty plugin registry falls back to keyword strategy
|
|
45
|
+
|
|
46
|
+
**Coverage:** Validates that the chain properly falls through to built-in strategies (keyword, manual) when all plugin routers return null or when no plugins are loaded.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### AC4: Plugin routers receive the same story context as built-in routers
|
|
51
|
+
|
|
52
|
+
**Tests (5):**
|
|
53
|
+
- ✅ Plugin router receives story object
|
|
54
|
+
- ✅ Plugin router receives routing context with config
|
|
55
|
+
- ✅ Plugin router receives codebase context when available
|
|
56
|
+
- ✅ Plugin router receives metrics when available
|
|
57
|
+
- ✅ Multiple plugin routers receive same context
|
|
58
|
+
|
|
59
|
+
**Coverage:** Validates that plugin routers receive the complete `UserStory` and `RoutingContext` objects, including optional fields like `codebaseContext` and `metrics`.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### AC5: Router errors are caught and logged; fallback to next router in chain
|
|
64
|
+
|
|
65
|
+
**Tests (6):**
|
|
66
|
+
- ❌ Error in plugin router is caught and next router is tried
|
|
67
|
+
- ❌ Error in plugin router is logged
|
|
68
|
+
- ❌ Multiple router errors are caught and keyword fallback succeeds
|
|
69
|
+
- ❌ Async error in plugin router is caught
|
|
70
|
+
- ❌ Error in last plugin router falls back to keyword strategy
|
|
71
|
+
- ❌ Error message includes plugin name for debugging
|
|
72
|
+
|
|
73
|
+
**Coverage:** Validates that errors thrown by plugin routers don't crash the routing system and that proper error logging occurs with router names for debugging.
|
|
74
|
+
|
|
75
|
+
**Status:** Currently failing (expected) - error handling not yet implemented in `StrategyChain.route()`
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Integration Tests
|
|
80
|
+
|
|
81
|
+
**Real-world scenarios (6):**
|
|
82
|
+
- ✅ Premium plugin forces security stories to expert tier
|
|
83
|
+
- ✅ Cost-optimization plugin downgrades simple docs to fast tier
|
|
84
|
+
- ✅ Domain-specific plugin routes database migrations to expert tier
|
|
85
|
+
- ✅ Multiple plugins: first matching plugin wins
|
|
86
|
+
- ✅ Plugin router can delegate based on conditional logic (duplicate coverage)
|
|
87
|
+
|
|
88
|
+
**Coverage:** Tests realistic plugin use cases that demonstrate the value of the plugin router system.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Test Results
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
22 pass
|
|
96
|
+
6 fail
|
|
97
|
+
54 expect() calls
|
|
98
|
+
Ran 28 tests across 1 file.
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Passing Tests (22):** Plugin router chain integration, precedence, fallback, and context passing all work correctly with the current implementation.
|
|
102
|
+
|
|
103
|
+
**Failing Tests (6):** All failures are in AC5 (error handling). The errors are propagating instead of being caught, logged, and triggering fallback to the next router.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Implementation Gaps
|
|
108
|
+
|
|
109
|
+
The tests reveal that the following needs to be implemented:
|
|
110
|
+
|
|
111
|
+
1. **Error handling in `StrategyChain.route()`** (`src/routing/chain.ts:38-44`)
|
|
112
|
+
- Wrap each `strategy.route()` call in try-catch
|
|
113
|
+
- Log errors with strategy name
|
|
114
|
+
- Continue to next strategy on error
|
|
115
|
+
|
|
116
|
+
2. **Error logging with plugin context**
|
|
117
|
+
- Include plugin router name in error logs
|
|
118
|
+
- Use `getSafeLogger()` to log routing errors
|
|
119
|
+
- Log at error level with category "routing"
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Next Steps for Implementer
|
|
124
|
+
|
|
125
|
+
1. Modify `src/routing/chain.ts` to wrap `strategy.route()` in try-catch
|
|
126
|
+
2. Add error logging that includes strategy name
|
|
127
|
+
3. Continue chain iteration on error (same as null return)
|
|
128
|
+
4. Run tests: `bun test ./test/integration/plugin-routing.test.ts`
|
|
129
|
+
5. All 28 tests should pass after implementation
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Notes
|
|
134
|
+
|
|
135
|
+
- Tests use mock plugins with custom routing logic
|
|
136
|
+
- Tests verify both sync and async router error handling
|
|
137
|
+
- Tests validate error log messages include router names for debugging
|
|
138
|
+
- Integration tests demonstrate realistic plugin use cases (security enforcement, cost optimization, domain-specific routing)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# US-007 Test Coverage Summary
|
|
2
|
+
|
|
3
|
+
## Story
|
|
4
|
+
Read plugin config entries from nax config.json
|
|
5
|
+
|
|
6
|
+
## Acceptance Criteria Coverage
|
|
7
|
+
|
|
8
|
+
### AC1: plugins[] from config.json are passed to loadPlugins() as configPlugins parameter
|
|
9
|
+
**Tests:**
|
|
10
|
+
- `test/integration/runner-config-plugins.test.ts`: "config.plugins[] entries are passed to loadPlugins() when runner initializes"
|
|
11
|
+
- Verifies config.plugins is loaded via loadConfig()
|
|
12
|
+
- Verifies config.plugins is passed to loadPlugins() with correct projectRoot
|
|
13
|
+
- Verifies plugin is initialized with correct config
|
|
14
|
+
|
|
15
|
+
### AC2: Relative module paths in plugins[].module are resolved relative to project root
|
|
16
|
+
**Tests:**
|
|
17
|
+
- `test/integration/runner-config-plugins.test.ts`: "relative plugin paths in config.plugins[] are resolved relative to project root"
|
|
18
|
+
- Tests `./lib/plugins/plugin.ts` resolves correctly from project root
|
|
19
|
+
- Verifies plugin is loaded and initialized successfully
|
|
20
|
+
|
|
21
|
+
### AC3: Absolute module paths and npm package names work as-is
|
|
22
|
+
**Tests:**
|
|
23
|
+
- `test/integration/runner-config-plugins.test.ts`: "absolute plugin paths in config.plugins[] work without project root resolution"
|
|
24
|
+
- Tests absolute paths are passed through without modification
|
|
25
|
+
- Verifies plugin is loaded correctly
|
|
26
|
+
|
|
27
|
+
### AC4: If a plugin module cannot be found, a clear error message is logged with the path tried
|
|
28
|
+
**Tests:**
|
|
29
|
+
- `test/integration/runner-config-plugins.test.ts`: "missing plugin module from config.plugins[] logs clear error (does not crash runner)"
|
|
30
|
+
- Verifies error message contains original path
|
|
31
|
+
- Verifies error message contains attempted resolved path
|
|
32
|
+
- Verifies runner doesn't crash (returns empty registry)
|
|
33
|
+
|
|
34
|
+
### AC5: Plugin-specific config (plugins[].config) is passed to the plugin's setup() function
|
|
35
|
+
**Tests:**
|
|
36
|
+
- `test/integration/runner-config-plugins.test.ts`: "config.plugins[] entries are passed to loadPlugins() when runner initializes"
|
|
37
|
+
- Verifies config object is passed to plugin's setup()
|
|
38
|
+
- Verifies config values match what was in config.json
|
|
39
|
+
|
|
40
|
+
## Additional Test Coverage
|
|
41
|
+
|
|
42
|
+
### Edge Cases
|
|
43
|
+
1. **Empty plugins[] array**: Verifies no plugins loaded
|
|
44
|
+
2. **Undefined plugins field**: Verifies runner's `config.plugins || []` fallback works
|
|
45
|
+
3. **Plugin name collision**: Verifies config plugins override auto-discovered plugins
|
|
46
|
+
|
|
47
|
+
## Test Files
|
|
48
|
+
|
|
49
|
+
### New Test File
|
|
50
|
+
- `test/integration/runner-config-plugins.test.ts` (7 tests, 32 assertions)
|
|
51
|
+
- Focuses on integration between loadConfig() and loadPlugins()
|
|
52
|
+
- Simulates runner.ts initialization flow
|
|
53
|
+
- All tests passing
|
|
54
|
+
|
|
55
|
+
### Existing Test Files (Already Exist)
|
|
56
|
+
- `test/integration/config-loader.test.ts` (8 tests for plugin config loading)
|
|
57
|
+
- Tests schema validation
|
|
58
|
+
- Tests config merging (global + project)
|
|
59
|
+
- `test/integration/plugins/config-resolution.test.ts` (20+ tests)
|
|
60
|
+
- Comprehensive AC coverage at plugin loader level
|
|
61
|
+
- `test/integration/plugins/config-integration.test.ts` (1 E2E test)
|
|
62
|
+
- Realistic scenario with relative paths
|
|
63
|
+
|
|
64
|
+
## Test Strategy
|
|
65
|
+
|
|
66
|
+
1. **Unit level**: Plugin loader path resolution logic (existing tests)
|
|
67
|
+
2. **Integration level**: Config loader + plugin loader (NEW tests in runner-config-plugins.test.ts)
|
|
68
|
+
3. **E2E level**: Full runner initialization flow (existing test in config-integration.test.ts)
|
|
69
|
+
|
|
70
|
+
## Coverage Summary
|
|
71
|
+
|
|
72
|
+
- ✅ All 5 acceptance criteria covered with multiple test cases
|
|
73
|
+
- ✅ Edge cases covered (empty array, undefined, collisions)
|
|
74
|
+
- ✅ Error handling verified (missing modules, invalid paths)
|
|
75
|
+
- ✅ Integration verified (config → runner → plugins)
|
|
76
|
+
|
|
77
|
+
## Running Tests
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Run new integration tests only
|
|
81
|
+
bun test ./test/integration/runner-config-plugins.test.ts
|
|
82
|
+
|
|
83
|
+
# Run all plugin-related tests
|
|
84
|
+
bun test ./test/integration/plugins/
|
|
85
|
+
|
|
86
|
+
# Run all config-related tests
|
|
87
|
+
bun test ./test/integration/config-loader.test.ts
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Implementation Status
|
|
91
|
+
|
|
92
|
+
**Status**: Tests written and passing ✅
|
|
93
|
+
|
|
94
|
+
The implementation already exists in:
|
|
95
|
+
- `src/config/loader.ts`: Loads plugins[] from config.json
|
|
96
|
+
- `src/config/schema.ts`: Validates plugin config entries
|
|
97
|
+
- `src/plugins/loader.ts`: Resolves paths and loads plugins
|
|
98
|
+
- `src/execution/runner.ts:201-202`: Passes config.plugins to loadPlugins()
|
|
99
|
+
|
|
100
|
+
These tests verify the integration works correctly end-to-end.
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import type { AgentAdapter, AgentRunOptions } from "../../src/agents";
|
|
3
|
+
import { ClaudeCodeAdapter } from "../../src/agents/claude";
|
|
4
|
+
import { describeAgentCapabilities, validateAgentFeature, validateAgentForTier } from "../../src/agents/validation";
|
|
5
|
+
|
|
6
|
+
describe("Agent Validation and Retry Logic", () => {
|
|
7
|
+
describe("ClaudeCodeAdapter.isInstalled", () => {
|
|
8
|
+
test("returns true when binary exists in PATH", async () => {
|
|
9
|
+
const adapter = new ClaudeCodeAdapter();
|
|
10
|
+
// Mock successful which command
|
|
11
|
+
const originalSpawn = Bun.spawn;
|
|
12
|
+
(Bun as any).spawn = mock((cmd: string[]) => {
|
|
13
|
+
if (cmd[0] === "which" && cmd[1] === "claude") {
|
|
14
|
+
return {
|
|
15
|
+
exited: Promise.resolve(0),
|
|
16
|
+
stdout: { getReader: () => ({ read: () => Promise.resolve({ done: true }) }) },
|
|
17
|
+
stderr: { getReader: () => ({ read: () => Promise.resolve({ done: true }) }) },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return originalSpawn(cmd);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const installed = await adapter.isInstalled();
|
|
24
|
+
expect(installed).toBe(true);
|
|
25
|
+
|
|
26
|
+
Bun.spawn = originalSpawn;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("returns false when binary does not exist", async () => {
|
|
30
|
+
const adapter = new ClaudeCodeAdapter();
|
|
31
|
+
// Mock failed which command
|
|
32
|
+
const originalSpawn = Bun.spawn;
|
|
33
|
+
(Bun as any).spawn = mock((cmd: string[]) => {
|
|
34
|
+
if (cmd[0] === "which" && cmd[1] === "claude") {
|
|
35
|
+
return {
|
|
36
|
+
exited: Promise.resolve(1),
|
|
37
|
+
stdout: { getReader: () => ({ read: () => Promise.resolve({ done: true }) }) },
|
|
38
|
+
stderr: { getReader: () => ({ read: () => Promise.resolve({ done: true }) }) },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return originalSpawn(cmd);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const installed = await adapter.isInstalled();
|
|
45
|
+
expect(installed).toBe(false);
|
|
46
|
+
|
|
47
|
+
Bun.spawn = originalSpawn;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("returns false on exception", async () => {
|
|
51
|
+
const adapter = new ClaudeCodeAdapter();
|
|
52
|
+
const originalSpawn = Bun.spawn;
|
|
53
|
+
(Bun as any).spawn = mock(() => {
|
|
54
|
+
throw new Error("Command not found");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const installed = await adapter.isInstalled();
|
|
58
|
+
expect(installed).toBe(false);
|
|
59
|
+
|
|
60
|
+
Bun.spawn = originalSpawn;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("ClaudeCodeAdapter timeout handling", () => {
|
|
65
|
+
test("distinguishes timeout from normal failure", async () => {
|
|
66
|
+
const adapter = new ClaudeCodeAdapter();
|
|
67
|
+
const originalSpawn = Bun.spawn;
|
|
68
|
+
|
|
69
|
+
// Mock process that times out
|
|
70
|
+
(Bun as any).spawn = mock(() => {
|
|
71
|
+
let killed = false;
|
|
72
|
+
return {
|
|
73
|
+
exited: new Promise((resolve) => {
|
|
74
|
+
setTimeout(() => resolve(killed ? 143 : 0), 100);
|
|
75
|
+
}),
|
|
76
|
+
kill: (signal: string) => {
|
|
77
|
+
if (signal === "SIGTERM") killed = true;
|
|
78
|
+
},
|
|
79
|
+
stdout: new Response("").body,
|
|
80
|
+
stderr: new Response("").body,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const options: AgentRunOptions = {
|
|
85
|
+
prompt: "test",
|
|
86
|
+
workdir: "/tmp",
|
|
87
|
+
modelTier: "balanced",
|
|
88
|
+
modelDef: { provider: "anthropic", model: "claude-sonnet-4.5", env: {} },
|
|
89
|
+
timeoutSeconds: 0.05, // 50ms timeout
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const result = await adapter.run(options);
|
|
93
|
+
|
|
94
|
+
// Should be marked as timeout (exit code 124)
|
|
95
|
+
expect(result.exitCode).toBe(124);
|
|
96
|
+
expect(result.success).toBe(false);
|
|
97
|
+
|
|
98
|
+
Bun.spawn = originalSpawn;
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("ClaudeCodeAdapter retry logic", () => {
|
|
103
|
+
test(
|
|
104
|
+
"retries on rate limit with exponential backoff",
|
|
105
|
+
async () => {
|
|
106
|
+
const adapter = new ClaudeCodeAdapter();
|
|
107
|
+
const originalSpawn = Bun.spawn;
|
|
108
|
+
let attemptCount = 0;
|
|
109
|
+
|
|
110
|
+
// Mock rate-limited response that succeeds on 3rd try
|
|
111
|
+
(Bun as any).spawn = mock(() => {
|
|
112
|
+
attemptCount++;
|
|
113
|
+
const isRateLimited = attemptCount < 3;
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
exited: Promise.resolve(isRateLimited ? 1 : 0),
|
|
117
|
+
kill: () => {},
|
|
118
|
+
stdout: new Response(isRateLimited ? "" : "success").body,
|
|
119
|
+
stderr: new Response(isRateLimited ? "rate limit exceeded" : "").body,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const options: AgentRunOptions = {
|
|
124
|
+
prompt: "test",
|
|
125
|
+
workdir: "/tmp",
|
|
126
|
+
modelTier: "balanced",
|
|
127
|
+
modelDef: { provider: "anthropic", model: "claude-sonnet-4.5", env: {} },
|
|
128
|
+
timeoutSeconds: 60,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const startTime = Date.now();
|
|
132
|
+
const result = await adapter.run(options);
|
|
133
|
+
const duration = Date.now() - startTime;
|
|
134
|
+
|
|
135
|
+
// Should succeed after retries
|
|
136
|
+
expect(result.success).toBe(true);
|
|
137
|
+
expect(attemptCount).toBe(3);
|
|
138
|
+
|
|
139
|
+
// Should have backoff delays (2s + 4s = 6s, but we'll check for at least 3s)
|
|
140
|
+
// Note: In real implementation, backoff is 2^attempt * 1000 = 2s, 4s
|
|
141
|
+
expect(duration).toBeGreaterThanOrEqual(3000);
|
|
142
|
+
|
|
143
|
+
Bun.spawn = originalSpawn;
|
|
144
|
+
},
|
|
145
|
+
{ timeout: 15000 },
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
test(
|
|
149
|
+
"fails immediately on agent execution errors (no retry)",
|
|
150
|
+
async () => {
|
|
151
|
+
const adapter = new ClaudeCodeAdapter();
|
|
152
|
+
const originalSpawn = Bun.spawn;
|
|
153
|
+
let attemptCount = 0;
|
|
154
|
+
|
|
155
|
+
// Mock agent execution failure (exit code 1)
|
|
156
|
+
// These are not retried because they're likely legitimate agent failures
|
|
157
|
+
(Bun as any).spawn = mock(() => {
|
|
158
|
+
attemptCount++;
|
|
159
|
+
return {
|
|
160
|
+
exited: Promise.resolve(1),
|
|
161
|
+
kill: () => {},
|
|
162
|
+
stdout: new Response("").body,
|
|
163
|
+
stderr: new Response("agent error").body,
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const options: AgentRunOptions = {
|
|
168
|
+
prompt: "test",
|
|
169
|
+
workdir: "/tmp",
|
|
170
|
+
modelTier: "balanced",
|
|
171
|
+
modelDef: { provider: "anthropic", model: "claude-sonnet-4.5", env: {} },
|
|
172
|
+
timeoutSeconds: 60,
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const result = await adapter.run(options);
|
|
176
|
+
|
|
177
|
+
// Should fail after 1 attempt (no retry for agent errors)
|
|
178
|
+
expect(result.success).toBe(false);
|
|
179
|
+
expect(attemptCount).toBe(1);
|
|
180
|
+
|
|
181
|
+
Bun.spawn = originalSpawn;
|
|
182
|
+
},
|
|
183
|
+
{ timeout: 15000 },
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
test("succeeds immediately on first attempt if no error", async () => {
|
|
187
|
+
const adapter = new ClaudeCodeAdapter();
|
|
188
|
+
const originalSpawn = Bun.spawn;
|
|
189
|
+
let attemptCount = 0;
|
|
190
|
+
|
|
191
|
+
// Mock successful execution
|
|
192
|
+
(Bun as any).spawn = mock(() => {
|
|
193
|
+
attemptCount++;
|
|
194
|
+
return {
|
|
195
|
+
exited: Promise.resolve(0),
|
|
196
|
+
kill: () => {},
|
|
197
|
+
stdout: new Response("success").body,
|
|
198
|
+
stderr: new Response("").body,
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const options: AgentRunOptions = {
|
|
203
|
+
prompt: "test",
|
|
204
|
+
workdir: "/tmp",
|
|
205
|
+
modelTier: "balanced",
|
|
206
|
+
modelDef: { provider: "anthropic", model: "claude-sonnet-4.5", env: {} },
|
|
207
|
+
timeoutSeconds: 60,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const result = await adapter.run(options);
|
|
211
|
+
|
|
212
|
+
// Should succeed on first try
|
|
213
|
+
expect(result.success).toBe(true);
|
|
214
|
+
expect(attemptCount).toBe(1);
|
|
215
|
+
|
|
216
|
+
Bun.spawn = originalSpawn;
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test("does not retry on timeout (exit code 124)", async () => {
|
|
220
|
+
const adapter = new ClaudeCodeAdapter();
|
|
221
|
+
const originalSpawn = Bun.spawn;
|
|
222
|
+
let attemptCount = 0;
|
|
223
|
+
|
|
224
|
+
// Mock timeout
|
|
225
|
+
(Bun as any).spawn = mock(() => {
|
|
226
|
+
attemptCount++;
|
|
227
|
+
let killed = false;
|
|
228
|
+
return {
|
|
229
|
+
exited: new Promise((resolve) => {
|
|
230
|
+
setTimeout(() => resolve(killed ? 143 : 0), 100);
|
|
231
|
+
}),
|
|
232
|
+
kill: (signal: string) => {
|
|
233
|
+
if (signal === "SIGTERM") killed = true;
|
|
234
|
+
},
|
|
235
|
+
stdout: new Response("").body,
|
|
236
|
+
stderr: new Response("").body,
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const options: AgentRunOptions = {
|
|
241
|
+
prompt: "test",
|
|
242
|
+
workdir: "/tmp",
|
|
243
|
+
modelTier: "balanced",
|
|
244
|
+
modelDef: { provider: "anthropic", model: "claude-sonnet-4.5", env: {} },
|
|
245
|
+
timeoutSeconds: 0.05, // 50ms timeout
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const result = await adapter.run(options);
|
|
249
|
+
|
|
250
|
+
// Should not retry on timeout
|
|
251
|
+
expect(result.exitCode).toBe(124);
|
|
252
|
+
expect(attemptCount).toBe(1);
|
|
253
|
+
|
|
254
|
+
Bun.spawn = originalSpawn;
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe("ClaudeCodeAdapter command building", () => {
|
|
259
|
+
test("builds correct command with model and prompt", () => {
|
|
260
|
+
const adapter = new ClaudeCodeAdapter();
|
|
261
|
+
const options: AgentRunOptions = {
|
|
262
|
+
prompt: "test prompt",
|
|
263
|
+
workdir: "/tmp",
|
|
264
|
+
modelTier: "balanced",
|
|
265
|
+
modelDef: { provider: "anthropic", model: "claude-sonnet-4.5", env: {} },
|
|
266
|
+
timeoutSeconds: 60,
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const cmd = adapter.buildCommand(options);
|
|
270
|
+
|
|
271
|
+
expect(cmd).toEqual([
|
|
272
|
+
"claude",
|
|
273
|
+
"--model",
|
|
274
|
+
"claude-sonnet-4.5",
|
|
275
|
+
"--dangerously-skip-permissions",
|
|
276
|
+
"-p",
|
|
277
|
+
"test prompt",
|
|
278
|
+
]);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe("Agent Capability Metadata", () => {
|
|
283
|
+
const claudeAdapter = new ClaudeCodeAdapter();
|
|
284
|
+
|
|
285
|
+
describe("ClaudeCodeAdapter capabilities", () => {
|
|
286
|
+
test("declares all expected tiers", () => {
|
|
287
|
+
const caps = claudeAdapter.capabilities;
|
|
288
|
+
expect(caps.supportedTiers).toContain("fast");
|
|
289
|
+
expect(caps.supportedTiers).toContain("balanced");
|
|
290
|
+
expect(caps.supportedTiers).toContain("powerful");
|
|
291
|
+
expect(caps.supportedTiers.length).toBe(3);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test("declares all expected features", () => {
|
|
295
|
+
const caps = claudeAdapter.capabilities;
|
|
296
|
+
expect(caps.features.has("tdd")).toBe(true);
|
|
297
|
+
expect(caps.features.has("review")).toBe(true);
|
|
298
|
+
expect(caps.features.has("refactor")).toBe(true);
|
|
299
|
+
expect(caps.features.has("batch")).toBe(true);
|
|
300
|
+
expect(caps.features.size).toBe(4);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("declares 200k token context window", () => {
|
|
304
|
+
expect(claudeAdapter.capabilities.maxContextTokens).toBe(200_000);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe("validateAgentForTier", () => {
|
|
309
|
+
test("returns true for supported tiers", () => {
|
|
310
|
+
expect(validateAgentForTier(claudeAdapter, "fast")).toBe(true);
|
|
311
|
+
expect(validateAgentForTier(claudeAdapter, "balanced")).toBe(true);
|
|
312
|
+
expect(validateAgentForTier(claudeAdapter, "powerful")).toBe(true);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test("returns false for unsupported tiers (custom agent)", () => {
|
|
316
|
+
// Create a mock agent that only supports fast tier
|
|
317
|
+
const limitedAgent: AgentAdapter = {
|
|
318
|
+
name: "limited",
|
|
319
|
+
displayName: "Limited Agent",
|
|
320
|
+
binary: "limited",
|
|
321
|
+
capabilities: {
|
|
322
|
+
supportedTiers: ["fast"],
|
|
323
|
+
maxContextTokens: 50_000,
|
|
324
|
+
features: new Set(["review"]),
|
|
325
|
+
},
|
|
326
|
+
async isInstalled() {
|
|
327
|
+
return true;
|
|
328
|
+
},
|
|
329
|
+
async run() {
|
|
330
|
+
return {
|
|
331
|
+
success: true,
|
|
332
|
+
exitCode: 0,
|
|
333
|
+
output: "",
|
|
334
|
+
rateLimited: false,
|
|
335
|
+
durationMs: 1000,
|
|
336
|
+
estimatedCost: 0.01,
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
buildCommand() {
|
|
340
|
+
return ["limited"];
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
expect(validateAgentForTier(limitedAgent, "fast")).toBe(true);
|
|
345
|
+
expect(validateAgentForTier(limitedAgent, "balanced")).toBe(false);
|
|
346
|
+
expect(validateAgentForTier(limitedAgent, "powerful")).toBe(false);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
describe("validateAgentFeature", () => {
|
|
351
|
+
test("returns true for supported features", () => {
|
|
352
|
+
expect(validateAgentFeature(claudeAdapter, "tdd")).toBe(true);
|
|
353
|
+
expect(validateAgentFeature(claudeAdapter, "review")).toBe(true);
|
|
354
|
+
expect(validateAgentFeature(claudeAdapter, "refactor")).toBe(true);
|
|
355
|
+
expect(validateAgentFeature(claudeAdapter, "batch")).toBe(true);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test("returns false for unsupported features (custom agent)", () => {
|
|
359
|
+
const reviewOnlyAgent: AgentAdapter = {
|
|
360
|
+
name: "reviewer",
|
|
361
|
+
displayName: "Review Agent",
|
|
362
|
+
binary: "reviewer",
|
|
363
|
+
capabilities: {
|
|
364
|
+
supportedTiers: ["fast", "balanced"],
|
|
365
|
+
maxContextTokens: 100_000,
|
|
366
|
+
features: new Set(["review"]),
|
|
367
|
+
},
|
|
368
|
+
async isInstalled() {
|
|
369
|
+
return true;
|
|
370
|
+
},
|
|
371
|
+
async run() {
|
|
372
|
+
return {
|
|
373
|
+
success: true,
|
|
374
|
+
exitCode: 0,
|
|
375
|
+
output: "",
|
|
376
|
+
rateLimited: false,
|
|
377
|
+
durationMs: 1000,
|
|
378
|
+
estimatedCost: 0.01,
|
|
379
|
+
};
|
|
380
|
+
},
|
|
381
|
+
buildCommand() {
|
|
382
|
+
return ["reviewer"];
|
|
383
|
+
},
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
expect(validateAgentFeature(reviewOnlyAgent, "review")).toBe(true);
|
|
387
|
+
expect(validateAgentFeature(reviewOnlyAgent, "tdd")).toBe(false);
|
|
388
|
+
expect(validateAgentFeature(reviewOnlyAgent, "refactor")).toBe(false);
|
|
389
|
+
expect(validateAgentFeature(reviewOnlyAgent, "batch")).toBe(false);
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
describe("describeAgentCapabilities", () => {
|
|
394
|
+
test("formats Claude Code capabilities correctly", () => {
|
|
395
|
+
const description = describeAgentCapabilities(claudeAdapter);
|
|
396
|
+
expect(description).toContain("claude:");
|
|
397
|
+
expect(description).toContain("tiers=[fast,balanced,powerful]");
|
|
398
|
+
expect(description).toContain("maxTokens=200000");
|
|
399
|
+
expect(description).toContain("features=");
|
|
400
|
+
expect(description).toContain("tdd");
|
|
401
|
+
expect(description).toContain("review");
|
|
402
|
+
expect(description).toContain("refactor");
|
|
403
|
+
expect(description).toContain("batch");
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test("formats limited agent capabilities correctly", () => {
|
|
407
|
+
const limitedAgent: AgentAdapter = {
|
|
408
|
+
name: "tiny",
|
|
409
|
+
displayName: "Tiny Agent",
|
|
410
|
+
binary: "tiny",
|
|
411
|
+
capabilities: {
|
|
412
|
+
supportedTiers: ["fast"],
|
|
413
|
+
maxContextTokens: 10_000,
|
|
414
|
+
features: new Set(["review"]),
|
|
415
|
+
},
|
|
416
|
+
async isInstalled() {
|
|
417
|
+
return true;
|
|
418
|
+
},
|
|
419
|
+
async run() {
|
|
420
|
+
return {
|
|
421
|
+
success: true,
|
|
422
|
+
exitCode: 0,
|
|
423
|
+
output: "",
|
|
424
|
+
rateLimited: false,
|
|
425
|
+
durationMs: 1000,
|
|
426
|
+
estimatedCost: 0.01,
|
|
427
|
+
};
|
|
428
|
+
},
|
|
429
|
+
buildCommand() {
|
|
430
|
+
return ["tiny"];
|
|
431
|
+
},
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const description = describeAgentCapabilities(limitedAgent);
|
|
435
|
+
expect(description).toBe("tiny: tiers=[fast], maxTokens=10000, features=[review]");
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
});
|