fix: add mock OpenAI server for E2E tests#53
Merged
Merged
Conversation
Closes #52 E2E tests were failing in CI because they relied on real API endpoints that returned 404 errors. This adds a local mock OpenAI-compatible server that handles all test scenarios without external API dependencies. Changes: - Add mock-openai-server.ts in packages/ai/__tests__/helpers/ - Add mock-openai-server.ts in packages/agent/__tests__/helpers/ - Update openai-compat.e2e.test.ts to support MOCK=true mode - Update tool-calling.e2e.test.ts to support MOCK=true mode - Update react-loop.e2e.test.ts to support MOCK=true mode - Update e2e.yml workflow to set MOCK=true The mock server handles: - Non-streaming and streaming chat completions - Tool calls (single and multiple) - Tool result summaries (ReAct loop support) - JSON/structured output responses Usage: MOCK=true pnpm test (runs E2E tests against mock server) All 7 E2E tests pass with MOCK=true, no external API needed.
There was a problem hiding this comment.
🤖 AI Code Review
Automated review for PR #53 — informational only, does not block merge.
Checklist
| Item | Notes | |
|---|---|---|
| Type Safety | unsafe as unknown cast detected |
|
| ✅ | Error Handling | No issues detected |
| ✅ | Test Coverage | 3 test file(s) updated |
| ✅ | API Consistency | 4 new export(s) added |
| ✅ | Breaking Changes | No breaking changes detected |
Stats
- 📁 Files changed: 6 (5 TypeScript)
- ➕ Lines added: 1033
- 🧪 Test files updated: 3
1 check(s) need attention.
Powered by openlinkos/agent · AI PR Review workflow
Contributor
Author
🔍 代码审查 — PR #53关联 Issue: #52 — E2E 测试因 OpenAI API 404 导致 CI 失败 方案: 添加本地 mock OpenAI 兼容服务器,E2E 测试在 MOCK=true 模式下无需外部 API ✅ 审查通过优点:
注意事项(不阻塞合并):
CI 状态: Build ✅ | Type check ✅ | AI Review ✅ | Release check ✅ | Test ⏳ 等待中 等待 Test 通过后执行合并。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #52
改动说明
E2E 测试之前依赖真实 API 端点,CI 中 404 报错。本次改动添加了本地 mock OpenAI 兼容服务器,所有测试场景无需外部 API。
新增文件
packages/ai/__tests__/helpers/mock-openai-server.ts— mock 服务器packages/agent/__tests__/helpers/mock-openai-server.ts— agent 包副本(vitest 跨包引用限制)修改文件
packages/ai/__tests__/e2e/openai-compat.e2e.test.ts— 支持 MOCK=truepackages/agent/__tests__/e2e/tool-calling.e2e.test.ts— 支持 MOCK=truepackages/agent/__tests__/e2e/react-loop.e2e.test.ts— 支持 MOCK=true.github/workflows/e2e.yml— 加MOCK: trueMock 服务器能力
验收标准
MOCK=true pnpm test全量 1018 + 7 E2E 测试通过MOCK=true后可跑通