test(ai): 补测经 AiStateFragments 的跨模块状态撞名,State() 补引导注释

This commit is contained in:
2026-07-29 12:11:07 +08:00
parent 80fdc36762
commit 894ae99984
2 changed files with 26 additions and 0 deletions
@@ -114,5 +114,27 @@ namespace BaseGames.Tests.EditMode.AI
var b = new BrainBuilder();
Assert.Throws<System.ArgumentException>(() => AiStateFragments.AbilityOnce(b, "S", null));
}
[Test]
public void Fragments_Throw_WhenTwoModulesDeclareSameState()
{
// 守卫存在的真正理由:两个独立模块取了同名状态时,
// 后者的回调会静默覆盖前者。经原语声明必须直接报错。
var b = new BrainBuilder();
AiStateFragments.Locomotion(b, "Idle", LocomotionMode.Idle);
var ex = Assert.Throws<System.InvalidOperationException>(
() => AiStateFragments.Locomotion(b, "Idle", LocomotionMode.Patrol));
StringAssert.Contains("Idle", ex.Message);
}
[Test]
public void Fragments_Throw_WhenDifferentFragmentKindsCollide()
{
// 跨层撞名同样要挡:未发现层的 Locomotion 态与死亡层的 Ability 态重名。
var b = new BrainBuilder();
AiStateFragments.Locomotion(b, "Shared", LocomotionMode.Patrol);
Assert.Throws<System.InvalidOperationException>(
() => AiStateFragments.Ability(b, "Shared", "atk"));
}
}
}