test: add unit/integration/E2E test suites, fix create_session bug, update docs

- Unit tests: test_session.py (27), test_error_kb.py (24), test_agent.py hardened
- Integration tests: test_api_integration.py (25) with FastAPI TestClient
- E2E tests: main-flows.spec.ts (8) with Playwright + API mocking
- Bug fix: backend/session.py create_session() missing session_id parameter
- Config: frontend/playwright.config.ts, npm run test:e2e
- Docs: update CLAUDE.md v9, .gitignore for test artifacts/eval reports
This commit is contained in:
2026-05-23 08:38:29 +08:00
parent b444303055
commit 1952d75f13
11 changed files with 1029 additions and 12 deletions
+33
View File
@@ -327,3 +327,36 @@ validation_service/ (FastAPI, 端口 8001) — 不变
- `prompts/refine_layout.md` — 1 处
Python 将 `{{` 输出为字面量 `{`LLM 看到的内容不变。
## 更新 (v9 — 2026-05-22)
### 测试基础设施全面补齐
**单元测试** (76 测试):
- `tests/test_session.py` — 27 测试:会话 CRUD、原子写入、唯一 ID、损坏 JSON 跳过
- `tests/test_error_kb.py` — 24 测试:指纹去重、关键词提取(中/英/JRXML)、ErrorKB CRUD、搜索、统计
- `tests/test_agent.py` — 5 个软断言强化为严格断言(`status`/`current_jrxml` 存在性检查)
- 已有测试:`test_ocr_extraction.py`49)、`test_layered_generation.py`19)、`test_validation.py`6)、`test_file_parser_formats.py`4)、`test_annotation_detector.py`7)、`test_e2e_ocr.py`3
**集成测试** (25 测试, `tests/test_api_integration.py`):
- FastAPI TestClient 全覆盖:健康检查、配置、会话 CRUD、文件上传、下载、Chat SSE、安全边界(路径穿越/非法 JSON/大 payload
- Mock LangGraph graph 避免真实 LLM 调用
**E2E 测试** (8 测试, `frontend/tests/e2e/main-flows.spec.ts`):
- Playwright 浏览器自动化:页面加载、侧边栏、会话管理、聊天流程、输入 UX
- 全量 API Mock`page.route`)无需后端运行
- 配置: `frontend/playwright.config.ts`, `npm run test:e2e`
**运行测试**:
```bash
# 全部单元+集成测试
cd D:\Idea Project\jaspersoft && python -m pytest tests/ -v
# 仅 E2E(需要前端 dev server
cd frontend && npx playwright test
```
### Bug 修复: create_session 参数缺失
`backend/session.py``create_session()` 新增可选参数 `session_id: Optional[str] = None`
`api_server.py:507` 调用 `create_session(session_id=session_id)` 时之前会抛出 `TypeError`