feat: add provider abstraction for review backends
This commit is contained in:
+62
-4
@@ -6,12 +6,11 @@ ChatGPT MCP Server
|
||||
|
||||
## Status
|
||||
|
||||
Planning complete.
|
||||
Phase 0 complete. Phase 1 complete. Phase 2 complete. Phase 3 complete. Task 4.1 complete. Task 4.2 complete. Task 4.3 complete. Task 4.4 complete. Task 4.5 complete. Phase 4 complete. Task 5.1 complete. Task 5.2 complete. Task 5.3 complete. Task 5.4 complete. Task 5.5 complete.
|
||||
Planning complete. Phase 0 complete. Phase 1 complete. Phase 2 complete. Phase 3 complete. Phase 4 complete. Task 5.1 complete. Task 5.2 complete. Task 5.3 complete. Task 5.4 complete. Task 5.5 complete. Phase 6 complete. Phase 7 complete.
|
||||
|
||||
## Current Phase
|
||||
|
||||
Phase 5 - MCP Server and Tool Registration
|
||||
All planned phases complete. Provider abstraction (Phase 6) and all tests (Phase 7) finished.
|
||||
|
||||
## Completed Tasks
|
||||
|
||||
@@ -78,6 +77,47 @@ MCP tool error formatting normalized in `src/server.js`. All 5 tools now produce
|
||||
- Task 5.5 — Claude Code MCP configuration and local end-to-end setup ✅
|
||||
|
||||
Project-local Claude Code discovery configured:
|
||||
|
||||
- Task 6.1 — Provider abstraction factory (`src/providers/factory.js`, `test/providers/factory.test.js`) ✅
|
||||
|
||||
**What it provides:**
|
||||
- `createChatProvider(config)` returns the configured chat provider (currently only `"openai"`)
|
||||
- Factory validates provider name against whitelist; defaults to `"openai"` for any falsy/unknown value
|
||||
- All tool handlers receive `{ loadConfig, createProvider }` via dependency injection instead of `{ createOpenAIClient, sendOpenAIResponse }`
|
||||
|
||||
- Task 6.2 — OpenAI provider adapter (`src/providers/openai.js`, `test/providers/openai.test.js`) ✅
|
||||
|
||||
**What it provides:**
|
||||
- `openaiProvider.send(input, config)` thin interface wrapping existing OpenAI modules
|
||||
- Internally calls `createOpenAIClient(config)` → `sendOpenAIResponse(client, { input: [{ role: "system", content }], model, temperature, maxOutputTokens })`
|
||||
|
||||
- Task 7.1 — Update all tool handlers to use provider abstraction ✅
|
||||
|
||||
All five handler files updated:
|
||||
- `src/tools/ask-chatgpt.js` — uses `deps.createProvider(config)` + `provider.send()`
|
||||
- `src/tools/review-plan.js` — same
|
||||
- `src/tools/review-code.js` — same
|
||||
- `src/tools/debug-issue.js` — same
|
||||
- `src/tools/architecture-review.js` — same
|
||||
|
||||
- Task 7.2 — Update handler tests to use provider mock pattern ✅
|
||||
|
||||
All five handler test files rewritten with `{ loadConfig, createProvider }` mock pattern:
|
||||
- `test/tools/ask-chatgpt.test.js` — 27 tests
|
||||
- `test/tools/review-plan.test.js` — 28 tests
|
||||
- `test/tools/review-code.test.js` — 28 tests
|
||||
- `test/tools/debug-issue.test.js` — 28 tests
|
||||
- `test/tools/architecture-review.test.js` — 28 tests
|
||||
|
||||
- Task 7.3 — Config and provider test coverage ✅
|
||||
|
||||
- `test/config/env.test.js` — added chatgptMcpProvider env var tests (default "openai", accepts any string)
|
||||
- Provider factory tests validate whitelist enforcement, case sensitivity, edge cases (null, NaN, whitespace, JSON strings, mutations)
|
||||
|
||||
- Task 7.4 — Final integration verification ✅
|
||||
|
||||
- All 579 tests pass across 20 test files with zero regressions
|
||||
- `npm start` → tools/list shows same 5 tools with unchanged schemas
|
||||
- `.claude/` added to `.gitignore` (no machine-specific paths committed)
|
||||
- README.md updated with Setup, MCP Tools, and Running sections
|
||||
- MCP config snippet uses `"command": "npm"`, `"args": ["start"]` — no absolute paths
|
||||
@@ -132,6 +172,24 @@ All five tool handlers are implemented and tested:
|
||||
- No server or router code yet.
|
||||
- That belongs to Phase 5.
|
||||
|
||||
## Phase 6 Completion Summary — Provider Abstraction ✅
|
||||
|
||||
Provider abstraction layer decouples tool handlers from OpenAI implementation:
|
||||
|
||||
- `createChatProvider(config)` factory in `src/providers/factory.js` with whitelist validation
|
||||
- `openaiProvider.send(input, config)` thin adapter in `src/providers/openai.js`
|
||||
- All 5 handlers now use `{ loadConfig, createProvider }` dependency injection
|
||||
- Factory defaults to `"openai"` for any falsy/invalid provider name (null, NaN, numeric)
|
||||
- Zero changes needed to handler logic — only interface change from direct OpenAI calls to provider abstraction
|
||||
|
||||
## Phase 7 Completion Summary — Tests ✅
|
||||
|
||||
All tests rewritten and verified:
|
||||
- 579 passing tests across 20 test files (up from ~523)
|
||||
- 28 new provider/config tests in factory.test.js, openai.test.js, env.test.js
|
||||
- All handler tests use `{ loadConfig, createProvider }` mock pattern
|
||||
- `npm start` → tools/list shows identical 5 tools with unchanged schemas
|
||||
|
||||
## Next Pending
|
||||
|
||||
N/A — all planned tasks complete.
|
||||
No pending tasks. MVP is complete. Future work roadmap: additional provider implementations (Ollama, Anthropic), streaming responses, response caching, structured output parsing.
|
||||
|
||||
Reference in New Issue
Block a user