Files
AirPlan-V2/test_dbg.py
AirPlan 6130478c96 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>
2026-06-12 15:56:44 +08:00

159 lines
4.9 KiB
Python
Executable File
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
"""Dbg Mode 功能测试"""
import sys
import os
import tempfile
import json
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent / "lib"))
# 实际的调试步骤
DBG_STEPS = ["confirm_symptoms", "load_context", "reproduce", "locate_root_cause", "fix", "verify_again", "document", "close"]
def test_dbg_evidence_first_gate():
"""测试证据先于修复门控"""
from air_runtime.modes.dbg_mode import EvidenceFirstGate, WorkflowViolation
with tempfile.TemporaryDirectory() as tmpdir:
session_id = "dbg-001"
gate = EvidenceFirstGate(session_id)
# 初始状态:无证据,不能修改代码
assert gate.can_modify_code() == False
# 尝试修改代码应该抛出异常
try:
gate.gate_check()
assert False, "应该抛出 WorkflowViolation"
except WorkflowViolation as e:
assert "取证" in str(e)
# 收集证据后可以修改代码
gate.record_evidence("screenshot", "login.png")
gate.record_evidence("log_analysis", "app.log")
assert gate.can_modify_code() == True
gate.gate_check() # 不应抛异常
print("✓ 证据先于修复门控测试通过")
return True
def test_dbg_start_session():
"""测试启动调试会话"""
from air_runtime.modes.dbg_mode import start_session, get_step
with tempfile.TemporaryDirectory() as tmpdir:
project_root = Path(tmpdir)
# 启动调试会话
result = start_session(project_root, "T-001")
# 检查返回值
assert "sessionId" in result
assert "sessionPath" in result
assert "currentStep" in result
# 检查会话文件存在
session_path = Path(result["sessionPath"])
assert session_path.exists()
# 检查步骤是 confirm_symptoms
step = get_step(session_path)
assert step == "confirm_symptoms", f"初始步骤应为 confirm_symptoms实际: {step}"
print(f"✓ 启动调试会话测试通过,会话: {result['sessionId']}, 步骤: {step}")
return True
def test_dbg_advance_step():
"""测试步骤推进(提供正确证据)"""
from air_runtime.modes.dbg_mode import start_session, advance_step, get_step
with tempfile.TemporaryDirectory() as tmpdir:
project_root = Path(tmpdir)
# 启动会话
result = start_session(project_root, "T-002")
session_path = Path(result["sessionPath"])
# confirm_symptoms 步骤需要 symptom, expected, actual
evidence = {
"symptom": "程序崩溃",
"expected": "正常输出 hello world",
"actual": "段错误 (segmentation fault)"
}
next_step = advance_step(session_path, evidence)
assert next_step == "load_context", f"下一步应为 load_context实际: {next_step}"
print(f"✓ 步骤推进测试通过,下一步: {next_step}")
return True
def test_dbg_snapshot():
"""测试快照功能"""
from air_runtime.modes.dbg_mode import pre_fix_snapshot
with tempfile.TemporaryDirectory() as tmpdir:
project_root = Path(tmpdir)
# 初始化 git 仓库
import subprocess
subprocess.run(["git", "init"], cwd=project_root, capture_output=True)
subprocess.run(["git", "config", "user.email", "test@test.com"], cwd=project_root, capture_output=True)
subprocess.run(["git", "config", "user.name", "Test"], cwd=project_root, capture_output=True)
# 创建源文件
src_dir = project_root / "src"
src_dir.mkdir(parents=True, exist_ok=True)
(src_dir / "main.cpp").write_text("int main() { return 0; }")
# 初始提交
subprocess.run(["git", "add", "."], cwd=project_root, capture_output=True)
subprocess.run(["git", "commit", "-m", "initial"], cwd=project_root, capture_output=True)
# 创建快照
snapshot_id = pre_fix_snapshot(project_root, "T-003")
# 快照 ID 可能是空的(因为没有 filesChanged但函数应该正常执行
print(f"✓ 快照功能测试通过")
return True
def main():
print("=" * 50)
print("Dbg Mode 功能测试")
print("=" * 50)
tests = [
("证据先于修复门控", test_dbg_evidence_first_gate),
("启动调试会话", test_dbg_start_session),
("步骤推进", test_dbg_advance_step),
("快照功能", test_dbg_snapshot),
]
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)