Files
erp-ass/backend/tests/test_prompts.py
dazhuang acd73431ae feat: implement ERP AI Assistant Phase 1
Backend (FastAPI + SQLAlchemy + Claude API + RAG):
- Config management with Pydantic v2
- Database engine with connection pooling and SQL injection prevention
- AI engine with Claude API integration (support custom base URL)
- RAG engine with ChromaDB and sentence-transformers
- Requirement analysis service
- Config generation service
- Executor engine with SQL validation
- REST API endpoints: /analyze, /generate, /execute

Frontend (Vue 3 + Element Plus + Pinia):
- Complete 3-step workflow: analyze → generate → execute
- Step indicator with progress visualization
- Analysis result display with field table
- SQL preview with monospace font
- Execute confirmation dialog with safety warning
- Execution result display
- State management with Pinia
- API service integration

Security:
- SQL injection prevention with parameterized queries
- Dangerous SQL operation blocking
- Database password URL encoding
- Transaction auto-rollback
- Pydantic config validation

Features:
- Natural language requirement analysis
- Automated SQL configuration generation
- Safe execution with human review
- LAN access support
- Custom Claude API endpoint support

Documentation:
- README with quick start guide
- Quick start guide
- LAN access configuration
- Dependency fixes guide
- Claude API configuration
- Git operation guide
- Implementation report

Dependencies fixed:
- numpy<2.0.0 for chromadb compatibility
- sentence-transformers==2.7.0 for huggingface_hub compatibility

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 14:23:20 +00:00

37 lines
1.1 KiB
Python

"""Tests for prompt templates."""
from app.core.prompts import SYSTEM_PROMPT, ANALYZE_PROMPT_TEMPLATE, GENERATE_PROMPT_TEMPLATE
def test_system_prompt_exists():
"""测试系统 Prompt 存在"""
assert SYSTEM_PROMPT is not None
assert len(SYSTEM_PROMPT) > 100
# Test for stable characteristics rather than exact wording
assert "ERP" in SYSTEM_PROMPT
assert "配置" in SYSTEM_PROMPT
def test_analyze_prompt_template():
"""测试需求解析模板"""
rendered = ANALYZE_PROMPT_TEMPLATE.format(
user_input="创建销售订单",
knowledge_context="测试知识",
existing_tables="测试表"
)
assert "创建销售订单" in rendered
assert "测试知识" in rendered
assert "测试表" in rendered
def test_generate_prompt_template():
"""测试配置生成模板"""
rendered = GENERATE_PROMPT_TEMPLATE.format(
requirements="需求分析结果",
platform_rules="平台规则",
similar_cases="类似案例"
)
assert "需求分析结果" in rendered
assert "平台规则" in rendered
assert "类似案例" in rendered