#!/usr/bin/env python3 """Dep/Tst/Sec/Rvr Mode 功能测试""" import sys import os import tempfile import json from pathlib import Path sys.path.insert(0, str(Path(__file__).parent / "lib")) def test_dep_main(): """测试部署器 CLI""" import argparse from air_runtime.modes.dep_mode import main as dep_main with tempfile.TemporaryDirectory() as tmpdir: args = argparse.Namespace(project=tmpdir, sub="status", task_id="", host="", binary="") try: dep_main(args) except SystemExit: pass print("✓ Dep CLI 测试通过") return True def test_tst_main(): """测试测试运行器 CLI""" import argparse from air_runtime.modes.tst_mode import main as tst_main with tempfile.TemporaryDirectory() as tmpdir: args = argparse.Namespace(project=tmpdir, sub="status", task_id="", framework="") try: tst_main(args) except SystemExit: pass print("✓ Tst CLI 测试通过") return True def test_tst_framework_detection(): """测试测试框架检测""" from air_runtime.test_runtime import TestRunner runner = TestRunner() assert "pytest" in runner.FRAMEWORKS assert "googletest" in runner.FRAMEWORKS assert "go" in runner.FRAMEWORKS assert "cargo" in runner.FRAMEWORKS print("✓ 测试框架检测测试通过") return True def test_sec_main(): """测试安全扫描器 CLI""" import argparse from air_runtime.modes.sec_mode import main as sec_main with tempfile.TemporaryDirectory() as tmpdir: args = argparse.Namespace(project=tmpdir, sub="status", task_id="", scan_path="", sec_mode="blocking") try: sec_main(args) except SystemExit: pass print("✓ Sec CLI 测试通过") return True def test_sec_rules(): """测试安全规则""" from air_runtime.sec_runtime import scan_file # scan_file 函数存在即可 assert callable(scan_file) print("✓ 安全规则测试通过") return True def test_rvr_main(): """测试需求审查器 CLI""" import argparse from air_runtime.modes.rvr_mode import main as rvr_main with tempfile.TemporaryDirectory() as tmpdir: args = argparse.Namespace(project=tmpdir, sub="status", task_id="") try: rvr_main(args) except SystemExit: pass print("✓ Rvr CLI 测试通过") return True def test_rvr_report(): """测试审查报告生成""" from air_runtime.review_runtime import ReviewRuntime, ReviewReport, RequirementCoverage with tempfile.TemporaryDirectory() as tmpdir: project_root = Path(tmpdir) rvr = ReviewRuntime(project_root) report = ReviewReport( task_id="T-001", verdict="pass", coverage=[ RequirementCoverage(requirement="功能完整", status="covered"), ], ) report_path = rvr.save_report(report) assert report_path.exists() verdict = rvr.get_integration_verdict(report) assert verdict == "pass" print("✓ 审查报告生成测试通过") return True def main(): print("=" * 50) print("Dep/Tst/Sec/Rvr Mode 功能测试") print("=" * 50) tests = [ ("Dep CLI", test_dep_main), ("Tst CLI", test_tst_main), ("测试框架检测", test_tst_framework_detection), ("Sec CLI", test_sec_main), ("安全规则", test_sec_rules), ("Rvr CLI", test_rvr_main), ("审查报告生成", test_rvr_report), ] passed = 0 failed = 0 for name, test_fn in tests: try: test_fn() passed += 1 except Exception as e: print(f"✗ {name} 失败: {e}") import traceback traceback.print_exc() failed += 1 print("=" * 50) print(f"测试结果: {passed} 通过, {failed} 失败") print("=" * 50) return failed == 0 if __name__ == "__main__": success = main() sys.exit(0 if success else 1)