Files
lobehub__lobehub/e2e/docs/llm-mock.md
Arvin Xu e3f0f46436 ✅ test: add more user journey (#11072)
* ✅ test(e2e): add Agent conversation E2E test with LLM mock

- Add LLM mock framework to intercept /webapi/chat/openai requests
- Create Agent conversation journey test (AGENT-CHAT-001)
- Add data-testid="chat-input" to Desktop ChatInput for E2E testing
- Mock returns SSE streaming responses matching LobeChat's actual format

Test scenario: Enter Lobe AI → Send "hello" → Verify AI response

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* 📝 docs(e2e): add experience-driven E2E testing strategy

Add comprehensive testing strategy from LOBE-2417:
- Core philosophy: user experience baseline for refactoring safety
- Product architecture coverage with priority levels
- Tag system (@journey, @P0/@P1/@P2, module tags)
- Execution strategies for CI, Nightly, and Release
- Updated directory structure with full journey coverage plan

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

📝 docs(e2e): add E2E testing guide for Claude

Document key learnings from implementing Agent conversation test:
- LLM Mock SSE format and usage
- Desktop/Mobile dual component handling with boundingBox
- contenteditable input handling
- Debugging tips and common issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* 📝 docs(e2e): add experience-driven E2E testing strategy

Add comprehensive testing strategy from LOBE-2417:
- Core philosophy: user experience baseline for refactoring safety
- Product architecture coverage with priority levels
- Tag system (@journey, @P0/@P1/@P2, module tags)
- Execution strategies for CI, Nightly, and Release
- Updated directory structure with full journey coverage plan

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

📝 docs(e2e): add E2E testing guide for Claude

Document key learnings from implementing Agent conversation test:
- LLM Mock SSE format and usage
- Desktop/Mobile dual component handling with boundingBox
- contenteditable input handling
- Debugging tips and common issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* update sop

* update sop

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 23:53:25 +08:00

1.3 KiB
Raw Permalink Blame History

LLM Mock 实现

核心原理

LLM Mock 通过 Playwright 的 page.route() 拦截对 /webapi/chat/openai 的请求,返回预设的 SSE 流式响应。

SSE 响应格式

LobeHub 使用特定的 SSE 格式,必须严格匹配:

// 1. 初始 data 事件
id: msg_xxx
event: data
data: {"id":"msg_xxx","model":"gpt-4o-mini","role":"assistant","type":"message",...}

// 2. 文本内容分块(text 事件)
id: msg_xxx
event: text
data: "Hello"

id: msg_xxx
event: text
data: "! I am"

// 3. 停止事件
id: msg_xxx
event: stop
data: "end_turn"

// 4. 使用量统计
id: msg_xxx
event: usage
data: {"totalTokens":100,...}

// 5. 最终停止
id: msg_xxx
event: stop
data: "message_stop"

使用示例

import { llmMockManager, presetResponses } from '../../mocks/llm';

// 在测试步骤中设置 mock
llmMockManager.setResponse('hello', presetResponses.greeting);
await llmMockManager.setup(this.page);

添加自定义响应

// 为特定用户消息设置响应
llmMockManager.setResponse('你好', '你好!我是 Lobe AI,有什么可以帮助你的?');

// 清除所有自定义响应
llmMockManager.clearResponses();

常见问题

LLM Mock 未生效

原因: 路由拦截设置在页面导航之后

解决: 确保在 page.goto() 之前调用 llmMockManager.setup(page)