test_env_rebuild.py•2.48 kB
#!/usr/bin/env python3
"""
MemOS环境重建测试脚本
验证依赖锁定和环境一致性
"""
import subprocess
import sys
import os
from pathlib import Path
def run_command(cmd, description):
"""运行命令并检查结果"""
print(f"🔄 {description}...")
try:
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, check=True)
print(f"✅ {description} - 成功")
return True
except subprocess.CalledProcessError as e:
print(f"❌ {description} - 失败: {e.stderr}")
return False
def test_environment_rebuild():
"""测试环境重建流程"""
print("🧪 MemOS环境重建测试")
print("=" * 40)
# 检查必需文件
required_files = [
"requirements.txt",
"pyproject.toml",
"setup_env.sh",
"mvp_memory.py"
]
print("📋 检查必需文件...")
for file in required_files:
if Path(file).exists():
print(f"✅ {file} - 存在")
else:
print(f"❌ {file} - 缺失")
return False
# 检查虚拟环境
if Path("memos_venv").exists():
print("✅ 虚拟环境目录存在")
else:
print("❌ 虚拟环境目录不存在")
return False
# 测试依赖导入
print("\n🔍 测试关键依赖...")
test_imports = [
"import schedule",
"import prometheus_client",
"import watchdog",
"import psutil",
"import requests",
"import openai",
"import qdrant_client"
]
for import_stmt in test_imports:
cmd = f"memos_venv/bin/python -c '{import_stmt}; print(\"✅ {import_stmt.split()[1]} - 可导入\")'"
if not run_command(cmd, f"测试 {import_stmt.split()[1]}"):
return False
# 测试MVP管理器
print("\n🧪 测试MVP管理器...")
mvp_test_cmd = """memos_venv/bin/python -c "
from mvp_memory import create_mvp_memory_manager
try:
m = create_mvp_memory_manager()
result = m.test_connection()
print(f'✅ MVP管理器测试通过: {result}')
except Exception as e:
print(f'❌ MVP管理器测试失败: {e}')
exit(1)
" """
if not run_command(mvp_test_cmd, "MVP管理器功能测试"):
return False
print("\n🎉 环境重建测试全部通过!")
return True
if __name__ == "__main__":
success = test_environment_rebuild()
sys.exit(0 if success else 1)