- Renamed `check_environment` to `check_api_key_configured` for clarity, simplifying the API key validation logic. - Removed the blocking behavior of the API key check during application startup, allowing the app to run while providing a prompt for configuration. - Updated `LocalAgentApp` to accept an `api_configured` parameter, enabling conditional messaging for API key setup. - Enhanced the `SandboxRunner` to support backup management and improved execution result handling with detailed metrics. - Integrated data governance strategies into the `HistoryManager`, ensuring compliance and improved data management. - Added privacy settings and metrics tracking across various components to enhance user experience and application safety.
192 lines
5.5 KiB
Python
192 lines
5.5 KiB
Python
"""
|
|
快速验证脚本
|
|
验证新增测试的基本功能
|
|
"""
|
|
|
|
import sys
|
|
import io
|
|
from pathlib import Path
|
|
|
|
# 设置标准输出编码为UTF-8
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
|
|
|
# 添加项目根目录到路径
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
def test_imports():
|
|
"""测试所有测试模块是否可以正常导入"""
|
|
print("=" * 70)
|
|
print("测试模块导入验证")
|
|
print("=" * 70)
|
|
|
|
modules = [
|
|
'tests.test_e2e_integration',
|
|
'tests.test_security_regression',
|
|
'tests.test_runner',
|
|
]
|
|
|
|
success_count = 0
|
|
failed_modules = []
|
|
|
|
for module_name in modules:
|
|
try:
|
|
__import__(module_name)
|
|
print(f"✅ {module_name} - 导入成功")
|
|
success_count += 1
|
|
except Exception as e:
|
|
print(f"❌ {module_name} - 导入失败: {e}")
|
|
failed_modules.append((module_name, str(e)))
|
|
|
|
print(f"\n导入结果: {success_count}/{len(modules)} 成功")
|
|
|
|
if failed_modules:
|
|
print("\n失败详情:")
|
|
for module, error in failed_modules:
|
|
print(f" - {module}: {error}")
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
def test_test_classes():
|
|
"""测试关键测试类是否存在"""
|
|
print("\n" + "=" * 70)
|
|
print("测试类验证")
|
|
print("=" * 70)
|
|
|
|
test_classes = [
|
|
('tests.test_e2e_integration', 'TestCodeReuseSecurityRegression'),
|
|
('tests.test_e2e_integration', 'TestConfigHotReloadRegression'),
|
|
('tests.test_e2e_integration', 'TestExecutionResultThreeStateRegression'),
|
|
('tests.test_security_regression', 'TestSecurityRegressionMatrix'),
|
|
('tests.test_security_regression', 'TestLLMReviewerRegression'),
|
|
('tests.test_security_regression', 'TestCriticalPathCoverage'),
|
|
]
|
|
|
|
success_count = 0
|
|
|
|
for module_name, class_name in test_classes:
|
|
try:
|
|
module = __import__(module_name, fromlist=[class_name])
|
|
test_class = getattr(module, class_name)
|
|
print(f"✅ {module_name}.{class_name} - 存在")
|
|
success_count += 1
|
|
except Exception as e:
|
|
print(f"❌ {module_name}.{class_name} - 不存在: {e}")
|
|
|
|
print(f"\n验证结果: {success_count}/{len(test_classes)} 成功")
|
|
|
|
return success_count == len(test_classes)
|
|
|
|
|
|
def test_runner_functionality():
|
|
"""测试测试运行器的基本功能"""
|
|
print("\n" + "=" * 70)
|
|
print("测试运行器功能验证")
|
|
print("=" * 70)
|
|
|
|
try:
|
|
from tests.test_runner import TestMetricsCollector
|
|
|
|
# 创建指标收集器
|
|
collector = TestMetricsCollector()
|
|
print("✅ TestMetricsCollector 创建成功")
|
|
|
|
# 测试摘要生成
|
|
summary = collector.get_summary()
|
|
print("✅ 摘要生成功能正常")
|
|
|
|
# 验证摘要字段
|
|
required_fields = ['total_tests', 'passed', 'failed', 'errors', 'skipped', 'success_rate']
|
|
for field in required_fields:
|
|
if field in summary:
|
|
print(f" ✅ 摘要包含字段: {field}")
|
|
else:
|
|
print(f" ❌ 摘要缺少字段: {field}")
|
|
return False
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ 测试运行器验证失败: {e}")
|
|
return False
|
|
|
|
|
|
def count_test_methods():
|
|
"""统计测试方法数量"""
|
|
print("\n" + "=" * 70)
|
|
print("测试方法统计")
|
|
print("=" * 70)
|
|
|
|
import unittest
|
|
|
|
modules = [
|
|
'tests.test_e2e_integration',
|
|
'tests.test_security_regression',
|
|
]
|
|
|
|
total_tests = 0
|
|
|
|
for module_name in modules:
|
|
try:
|
|
module = __import__(module_name, fromlist=[''])
|
|
loader = unittest.TestLoader()
|
|
suite = loader.loadTestsFromModule(module)
|
|
count = suite.countTestCases()
|
|
print(f"📊 {module_name}: {count} 个测试方法")
|
|
total_tests += count
|
|
except Exception as e:
|
|
print(f"❌ {module_name}: 统计失败 - {e}")
|
|
|
|
print(f"\n总计: {total_tests} 个测试方法")
|
|
return total_tests
|
|
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("\n" + "=" * 70)
|
|
print("LocalAgent 测试验证工具")
|
|
print("=" * 70 + "\n")
|
|
|
|
results = []
|
|
|
|
# 1. 测试导入
|
|
results.append(("模块导入", test_imports()))
|
|
|
|
# 2. 测试类验证
|
|
results.append(("测试类验证", test_test_classes()))
|
|
|
|
# 3. 测试运行器功能
|
|
results.append(("测试运行器", test_runner_functionality()))
|
|
|
|
# 4. 统计测试方法
|
|
test_count = count_test_methods()
|
|
|
|
# 总结
|
|
print("\n" + "=" * 70)
|
|
print("验证总结")
|
|
print("=" * 70)
|
|
|
|
for name, result in results:
|
|
status = "✅ 通过" if result else "❌ 失败"
|
|
print(f"{name}: {status}")
|
|
|
|
all_passed = all(result for _, result in results)
|
|
|
|
if all_passed:
|
|
print(f"\n🎉 所有验证通过!共 {test_count} 个测试方法可用。")
|
|
print("\n下一步:")
|
|
print(" 1. 运行关键路径测试: python tests/test_runner.py --mode critical")
|
|
print(" 2. 运行所有测试: python tests/test_runner.py --mode all")
|
|
print(" 3. 使用批处理脚本: run_tests.bat")
|
|
return 0
|
|
else:
|
|
print("\n⚠️ 部分验证失败,请检查错误信息。")
|
|
return 1
|
|
|
|
|
|
if __name__ == '__main__':
|
|
exit_code = main()
|
|
sys.exit(exit_code)
|
|
|