feat: add provider abstraction for review backends

This commit is contained in:
2026-06-12 19:23:45 +01:00
parent 1b8edb7eba
commit 732d6edd38
22 changed files with 1432 additions and 882 deletions
+54 -2
View File
@@ -55,6 +55,58 @@ Total: 139 orchestration-only tests, all passing.
**All five MCP tools registered:** ask_chatgpt, review_plan, review_code, debug_issue, architecture_review.
## Completed (Phase 6) — Provider Abstraction ✅
Decoupled tool handlers from OpenAI implementation via a provider abstraction layer:
### src/providers/factory.js
- `createChatProvider(config)` validates `chatgptMcpProvider` against whitelist
- Defaults to `"openai"` for any falsy/unknown value (null, NaN, numeric)
- Throws with descriptive message on unrecognized provider names
### src/providers/openai.js
- `openaiProvider.send(input, config)` — thin adapter wrapping OpenAI modules
- Internally calls `createOpenAIClient(config)` then `sendOpenAIResponse(client, params)`
- Params include: input as system messages array, model, temperature, maxOutputTokens from config
### Handler changes (all 5)
- Old interface: `{ loadConfig, createOpenAIClient, sendOpenAIResponse }`
- New interface: `{ loadConfig, createProvider }`
- Each handler calls `provider = deps.createProvider(config)` then `provider.send(budget.input, config)`
- Handler logic unchanged — only dependency injection changed
### CHATGPT_MCP_PROVIDER env var
- Defaults to `"openai"` when not set
- Accepts any string at loadConfig time; validation happens in factory at provider creation
- Currently only `"openai"` is whitelisted; others throw at createChatProvider() time
## Completed (Phase 7) — Tests ✅
### Handler tests updated (5 files, all using `{ loadConfig, createProvider }` mock pattern)
| File | Tests | Status |
|------|-------|--------|
| test/tools/ask-chatgpt.test.js | 27 | ✅ |
| test/tools/review-plan.test.js | 28 | ✅ |
| test/tools/review-code.test.js | 28 | ✅ |
| test/tools/debug-issue.test.js | 28 | ✅ |
| test/tools/architecture-review.test.js | 28 | ✅ |
### New provider/config tests (3 files)
| File | Tests | Status |
|------|-------|--------|
| test/providers/factory.test.js | ~30 | ✅ covers default, whitelist, edge cases |
| test/providers/openai.test.js | 27 | ✅ covers all send delegation paths |
| test/config/env.test.js | +4 (added section) | ✅ covers chatgptMcpProvider env var |
### Final verification
- All 579 tests pass across 20 test files (up from ~523)
- `npm start` → tools/list shows same 5 tools, unchanged schemas
- Zero regression in existing test coverage
## Completed (Phase 5)
**All five MCP tools registered:** ask_chatgpt, review_plan, review_code, debug_issue, architecture_review.
### Task 5.1 - MCP server skeleton ✅
Minimal MCP stdio server in `src/server.js`. MCP initialize handshake succeeds. No tools registered yet.
@@ -65,7 +117,7 @@ Minimal MCP stdio server in `src/server.js`. MCP initialize handshake succeeds.
**Registration details:**
- Uses shared `baseInputSchema` (question required + context, constraints, expectedOutput, projectSummary, taskSummary, relevantFiles, logs optional).
- All 3 external deps injected: `loadConfig`, `createOpenAIClient`, `sendOpenAIResponse`.
- External deps injected via dependency injection: `{ loadConfig, createProvider }` — provider abstraction (Phase 6).
- Returns structured MCP tool result: `{ content: [{ type: "text", text }], isError, warnings }`.
**Smoke test results (all passing):**
@@ -126,7 +178,7 @@ Project-local Claude Code discovery configured:
## Next Pending
N/A — all planned tasks complete.
No pending tasks. MVP complete. Future work: additional providers (Ollama, Anthropic), streaming responses, cost tracking, Dockerfile, CI pipeline, safe project summary generation.
## General Rules