feat: add provider abstraction for review backends
This commit is contained in:
@@ -584,3 +584,110 @@ Configure project-local Claude Code discovery via `.claude/settings.local.json`
|
||||
- No secrets or absolute paths in any tracked file ✅
|
||||
|
||||
Status: ✅ Complete
|
||||
|
||||
---
|
||||
|
||||
## Phase 6 — Provider Abstraction
|
||||
|
||||
### Task 6.1 — Provider factory (`src/providers/factory.js`, `test/providers/factory.test.js`)
|
||||
|
||||
Create `createChatProvider(config)` factory that validates and returns configured chat provider.
|
||||
|
||||
**Requirements:**
|
||||
- Whitelist validates against `"openai"` only (currently)
|
||||
- Defaults to `"openai"` for any falsy/unknown value (null, NaN, empty string, numeric)
|
||||
- Throws descriptive error on unrecognized provider names containing both the invalid name and supported providers
|
||||
- No global state — all logic in pure function
|
||||
|
||||
**Tests:** ~30 tests covering default provider, CHATGPT_MCP_PROVIDER env var, whitelist enforcement, case sensitivity, edge cases (null, NaN, whitespace, JSON strings, mutation checks).
|
||||
|
||||
Status: ✅ Complete
|
||||
|
||||
### Task 6.2 — OpenAI provider adapter (`src/providers/openai.js`, `test/providers/openai.test.js`)
|
||||
|
||||
Create `openaiProvider.send(input, config)` thin interface that wraps existing OpenAI modules.
|
||||
|
||||
**Interface:**
|
||||
```js
|
||||
provider.send(input, config) → Promise<{ content: string }>
|
||||
```
|
||||
|
||||
Internally calls:
|
||||
1. `createOpenAIClient(config)` — returns client with API key
|
||||
2. `sendOpenAIResponse(client, { input: [{ role: "system", content }], model, temperature, maxOutputTokens })`
|
||||
|
||||
**Tests:** 27 tests covering parameter passing, call ordering, error propagation, idempotency, edge cases (empty input, unicode, long input, object input).
|
||||
|
||||
Status: ✅ Complete
|
||||
|
||||
---
|
||||
|
||||
## Phase 7 — Integration and Test Updates
|
||||
|
||||
### Task 7.1 — Update all tool handlers to use provider abstraction
|
||||
|
||||
All five handler files updated to use `{ loadConfig, createProvider }` dependency injection instead of `{ loadConfig, createOpenAIClient, sendOpenAIResponse }`.
|
||||
|
||||
| Handler | File | Change |
|
||||
|---------|------|--------|
|
||||
| handleAskChatGpt | `src/tools/ask-chatgpt.js` | deps.createProvider(config) + provider.send() |
|
||||
| handleReviewPlan | `src/tools/review-plan.js` | same |
|
||||
| handleReviewCode | `src/tools/review-code.js` | same |
|
||||
| handleDebugIssue | `src/tools/debug-issue.js` | same |
|
||||
| handleArchitectureReview | `src/tools/architecture-review.js` | same |
|
||||
|
||||
Status: ✅ Complete
|
||||
|
||||
### Task 7.2 — Update handler tests to use provider mock pattern
|
||||
|
||||
All five handler test files rewritten with `{ loadConfig, createProvider }` mock pattern instead of `{ createOpenAIClient, sendOpenAIResponse }`.
|
||||
|
||||
**Key changes in tests:**
|
||||
- `createProvider` mock returns `{ send: sendMock }` instead of direct client mocks
|
||||
- All inputs use baseInputSchema `{ question, context, ... }` fields consistently
|
||||
- 28 tests per handler (success path, validation failure, config failure, budget failure, provider creation/send failure, dependency order, warnings propagation, result shape, short-circuit behavior)
|
||||
|
||||
| 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 | ✅ |
|
||||
|
||||
Status: ✅ Complete
|
||||
|
||||
### Task 7.3 — Config and provider test coverage
|
||||
|
||||
Added tests for `CHATGPT_MCP_PROVIDER` env var in `test/config/env.test.js` and new provider-specific tests.
|
||||
|
||||
- **env.test.js**: Added section testing chatgptMcpProvider defaults to `"openai"` and accepts any string value
|
||||
- **factory.test.js**: ~30 tests covering factory behavior
|
||||
- **openai.test.js**: 27 tests covering send delegation
|
||||
|
||||
Status: ✅ Complete
|
||||
|
||||
### Task 7.4 — Final integration verification
|
||||
|
||||
- All 579 tests pass across 20 test files
|
||||
- No regressions in existing coverage
|
||||
- `npm start` → tools/list shows same 5 tools with unchanged schemas
|
||||
|
||||
Status: ✅ Complete
|
||||
|
||||
---
|
||||
|
||||
## Completion Summary
|
||||
|
||||
| Phase | Description | Status |
|
||||
|-------|-------------|--------|
|
||||
| 0 | Repository Setup | ✅ Complete |
|
||||
| 1 | Core Utilities | ✅ Complete |
|
||||
| 2 | OpenAI Integration | ✅ Complete |
|
||||
| 3 | Tool Inputs and Prompts | ✅ Complete |
|
||||
| 4 | Tool Handlers | ✅ Complete (5 handlers, 139 tests) |
|
||||
| 5 | MCP Server and Registration | ✅ Complete (5 tools registered) |
|
||||
| 6 | Provider Abstraction | ✅ Complete (factory + adapter) |
|
||||
| 7 | Integration and Tests | ✅ Complete (579 tests across 20 files) |
|
||||
|
||||
**Total:** All planned MVP tasks complete. 579 passing tests, zero regressions, all docs updated.
|
||||
|
||||
Reference in New Issue
Block a user