Files
AirPlan-V2/test_arc.py
AirLongDian 19a4550830 test: 全模式功能测试覆盖 (12模式 33项测试)
新增 arc/eng/do/dbg/ctx/xdb/sdb/ndb/dep/tst/sec/rvr 全模式功能测试;
fix do_mode UI 检测中文关键词补全;scripts/install.sh 同步更新。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-11 10:10:57 +08:00

143 lines
4.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Arc Mode 功能测试"""
import sys
import os
import tempfile
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent / "lib"))
def test_arc_phase_gate():
"""测试三阶段门控"""
from air_runtime.modes.arc_mode import ArcPhaseGate
with tempfile.TemporaryDirectory() as tmpdir:
state_path = Path(tmpdir) / "state.json"
gate = ArcPhaseGate(state_path)
# 初始阶段应该是 discussing
assert gate.current_phase == "discussing", f"初始阶段应为 discussing实际: {gate.current_phase}"
# 可以前进到 proposing
gate.advance_to("proposing")
assert gate.current_phase == "proposing"
# 不能跳到 confirmed只能逐步前进
gate.advance_to("confirmed")
assert gate.current_phase == "confirmed"
# can_write_plan 只在 confirmed 时返回 True
assert gate.can_write_plan() == True
# 测试确认架构
result = gate.confirm_architecture("好的,确认这个架构")
assert result == True
assert gate.current_phase == "confirmed"
print("✓ ArcPhaseGate 三阶段门控测试通过")
return True
def test_arc_build_graph():
"""测试 DAG 构建"""
from air_runtime.modes.arc_mode import _build_graph_from_todo
from air_runtime.task_graph import TaskGraph
with tempfile.TemporaryDirectory() as tmpdir:
todo_path = Path(tmpdir) / "todo.md"
todo_path.write_text("""
| Task | Status | Files/Dirs | Done When |
|------|--------|------------|-----------|
| [T-001] 任务1 | TODO | src/a/ | 完成 |
| [T-002] 任务2 | TODO | src/b/ | 完成 |
| [T-003] 任务3 | DONE | src/c/ | 完成 |
""")
graph, violations = _build_graph_from_todo(todo_path)
# 检查节点数量
assert len(graph.nodes) >= 3, f"应有至少3个节点实际: {len(graph.nodes)}"
# 检查是否有边界测试任务注入
test_nodes = [n for n in graph.nodes.values() if n.test_required]
assert len(test_nodes) > 0, "应该有边界测试任务"
# 检查 Done When 违规检测
assert len(violations) > 0, "应该有 Done When 不含'测试通过'的违规"
print(f"✓ DAG 构建测试通过,节点数: {len(graph.nodes)}, 测试任务: {len(test_nodes)}, 违规: {len(violations)}")
return True
def test_arc_parallel_review():
"""测试并行审查模式"""
from air_runtime.modes.arc_mode import parallel_review_mode
with tempfile.TemporaryDirectory() as tmpdir:
project_root = Path(tmpdir)
# 创建 AirPlan 目录结构
arc_root = project_root / "AirPlan" / "state" / "airarc"
arc_root.mkdir(parents=True, exist_ok=True)
# 写入 state.json需先有 confirmed 阶段)
import json
(arc_root / "state.json").write_text(json.dumps({"arcPhase": "confirmed"}))
# 创建 todo.md
todo_path = project_root / "AirPlan" / "todo.md"
todo_path.write_text("""
| Task | Status | Files/Dirs | Done When |
|------|--------|------------|-----------|
| [T-001] 任务1 | TODO | src/main.cpp | 编译通过 |
""")
result = parallel_review_mode(project_root, todo_path)
# 检查返回值
assert "execution_plan_json_path" in result
assert result.get("blocked") != True, "不应被阻止"
# 检查 execution-plan.json 是否生成
plan_path = result["execution_plan_json_path"]
assert Path(plan_path).exists(), f"执行计划文件应存在: {plan_path}"
print(f"✓ parallel_review_mode 测试通过")
return True
def main():
print("=" * 50)
print("Arc Mode 功能测试")
print("=" * 50)
tests = [
("三阶段门控", test_arc_phase_gate),
("DAG 构建", test_arc_build_graph),
("并行审查", test_arc_parallel_review),
]
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)