feat: AirPlan V2 — 全专家插件强制路由 + 事件系统规范化

P0-8 扩大: do_mode.py finish_worker 全专家插件强制路由
- GUI→XDB, network→NDB, C/C++→SDB, done→Rvr, blocked/failed→Dbg
- 证据去重: 已有 xdbSessions/ndbSessions/sdbReports/rvrReviewed 则跳过

P1-GAP17: 事件 emit 规范化
- 新增 7 个事件常量 (TASK_ENTERED, TASK_FINISHED, ENGINE_ENTERED 等)
- 全部 emit 调用替换字符串字面量为常量,零残留
- 30 个事件类型常量全部定义且唯一

P1-GAP18: 事件日志原子轮转
- emit 计数器每 128 次检查轮转,避免每次 emit 读文件
- 清除未使用的 _emit_with_completion/_pending_merge_complete
- 原子轮转: tempfile+os.replace 保证不损坏

eng 极端接管: 强制调用全部专家插件 (Dbg/XDB/NDB/SDB/Rvr)
commands/do.md: 更新为全专家插件路由文档

全量测试: 69 通过, 0 失败

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
AirPlan
2026-06-12 15:56:44 +08:00
commit 6130478c96
73 changed files with 10622 additions and 0 deletions

198
test_eng.py Executable file
View File

@@ -0,0 +1,198 @@
#!/usr/bin/env python3
"""Eng Mode 功能测试"""
import sys
import os
import tempfile
import json
from pathlib import Path
import time
sys.path.insert(0, str(Path(__file__).parent / "lib"))
def test_eng_init():
"""测试调度器初始化"""
from air_runtime.modes.eng_mode import enter_engine, _init_state
with tempfile.TemporaryDirectory() as tmpdir:
project_root = Path(tmpdir)
state_path, _ = enter_engine(project_root)
# 检查状态文件存在
assert Path(state_path).exists()
# 检查初始状态
from air_runtime.io import safe_json_load
state = safe_json_load(Path(state_path))
assert state["enabled"] == True
assert state["engineMode"] == "idle"
assert state["nextAction"] == "plan"
print("✓ 调度器初始化测试通过")
return True
def test_eng_build_plan():
"""测试构建执行计划"""
from air_runtime.modes.eng_mode import build_engine_plan
with tempfile.TemporaryDirectory() as tmpdir:
project_root = Path(tmpdir)
# 创建 AirPlan 目录
airplan_dir = project_root / "AirPlan"
airplan_dir.mkdir(parents=True, exist_ok=True)
# 创建 todo.md
todo_path = airplan_dir / "todo.md"
todo_path.write_text("""
| Task | Status | Files/Dirs | Done When |
|------|--------|------------|-----------|
| [T-001] 任务A | TODO | src/a.cpp | 编译通过 |
| [T-002] 任务B | TODO | src/b.cpp | 编译通过 |
""")
result = build_engine_plan(project_root, todo_path)
assert "planPath" in result
assert Path(result["planPath"]).exists()
print(f"✓ 构建执行计划测试通过,任务数: {len(result['selectedTasks'])}")
return True
def test_eng_dispatch():
"""测试任务派发"""
from air_runtime.modes.eng_mode import dispatch_worker_group, enter_engine
with tempfile.TemporaryDirectory() as tmpdir:
project_root = Path(tmpdir)
# 初始化
enter_engine(project_root)
# 创建 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 | 编译通过 |
| [T-002] 任务2 | TODO | src/utils.cpp | 编译通过 |
""")
# 派发
result = dispatch_worker_group(project_root)
# 检查返回值
assert "waveId" in result
assert "taskIds" in result
assert len(result["taskIds"]) > 0, "应有派发的任务"
print(f"✓ 任务派发测试通过,波次: {result['waveId']}, 任务数: {len(result['taskIds'])}")
return True
def test_eng_monitor():
"""测试监控引擎"""
from air_runtime.modes.eng_mode import monitor_engine, enter_engine
with tempfile.TemporaryDirectory() as tmpdir:
project_root = Path(tmpdir)
# 初始化
enter_engine(project_root)
# 监控
result = monitor_engine(project_root)
# 检查返回值
assert "engineMode" in result
assert "activeWorkerCount" in result
assert "nextAction" in result
print(f"✓ 监控引擎测试通过worker数: {result['activeWorkerCount']}")
return True
def test_eng_block_release():
"""测试 block-release 阻止派发"""
from air_runtime.modes.eng_mode import dispatch_worker_group, enter_engine
from air_runtime.io import atomic_json_write
from air_runtime.paths import airplan_root
with tempfile.TemporaryDirectory() as tmpdir:
project_root = Path(tmpdir)
# 初始化
enter_engine(project_root)
# 创建 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 | 编译通过 |
""")
# 模拟一个 block-release 的 review 报告
rvr_root = project_root / "AirPlan" / "state" / "airrvr" / "reports"
rvr_root.mkdir(parents=True, exist_ok=True)
report = {
"taskId": "T-001",
"verdict": "fail",
"highRiskAudit": {
"deliveryVerdict": "block-release",
"overallRisk": "critical"
}
}
atomic_json_write(rvr_root / "T-001.json", report)
# 尝试派发,应该被阻止
result = dispatch_worker_group(project_root)
assert result.get("blocked") == True, "block-release 应该阻止派发"
assert "block-release" in result.get("reason", ""), "阻止原因应包含 block-release"
print(f"✓ block-release 阻止派发测试通过")
return True
def main():
print("=" * 50)
print("Eng Mode 功能测试")
print("=" * 50)
tests = [
("调度器初始化", test_eng_init),
("构建执行计划", test_eng_build_plan),
("任务派发", test_eng_dispatch),
("监控引擎", test_eng_monitor),
("block-release阻止", test_eng_block_release),
]
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)