Aetheria/tests/Aetheria.Shared.Tests/CapabilityEventsTests.cs
Meta Vens 5aa989abbf Pickup is a capability: PickupData/Pickup run a timed grab through Zone's hold API and TryPickUp (group A, sim)
GrabEvent carries a FloatingBodyId; Zone gains TryHold/SetHeldProgress/Free and places a held item instead of
integrating it; Entity.TractorPower is derived from Pickup.Power and TractorCommand is the pilot's input
(ActionGameManager writes it undamped, the Time.deltaTime ramp is deleted). Binder and FieldTester change the
delegate type only. PickupTests and a save round-trip pin for the player's zone index.

Group A builds; no beam is on any generated ship until group B.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 05:00:22 +02:00

50 lines
2 KiB
C#

using System.Collections.Generic;
using CultMath;
using UniRx;
using Xunit;
using static CultMath.math;
// Pins the routing invariant of CapabilityEvents (Assets/Scripts/ServerShared/CapabilityEvents.cs,
// docs/headless-playground-cut.md fork L): a publish of one capability event kind reaches only the
// subscribers of that kind. A subscriber to Absorb must never see a Grab (or Melee, or Thrust) event,
// and vice versa for every other kind.
public sealed class CapabilityEventsTests
{
[Fact]
public void EachEventKindReachesOnlyItsOwnSubscribers()
{
var events = new CapabilityEvents();
var absorbed = new List<AbsorbEvent>();
var grabbed = new List<GrabEvent>();
var meleed = new List<MeleeEvent>();
var thrust = new List<ThrustEvent>();
events.Absorb.Subscribe(absorbed.Add);
events.Grab.Subscribe(grabbed.Add);
events.Melee.Subscribe(meleed.Add);
events.Thrust.Subscribe(thrust.Add);
var absorbEvent = new AbsorbEvent(float3(1, 2, 3), float3(0, 0, 1), 5f, DamageType.Corrosive, AbsorbLayer.Hull);
var grabEvent = new GrabEvent(new FloatingBodyId(7), GrabPhase.Started, float3(1, 0, 0), 1.5f);
var meleeEvent = new MeleeEvent(float3(0, 0, 1), 10f, 90f, 0.5f);
var thrustEvent = new ThrustEvent(float2(1, 0), 0.5f, float2(0.2f, -0.2f));
events.PublishAbsorb(absorbEvent);
events.PublishGrab(grabEvent);
events.PublishMelee(meleeEvent);
events.PublishThrust(thrustEvent);
// Each stream received exactly one event: its own.
Assert.Equal(new[] { absorbEvent }, absorbed);
Assert.Equal(new[] { grabEvent }, grabbed);
Assert.Equal(new[] { meleeEvent }, meleed);
Assert.Equal(new[] { thrustEvent }, thrust);
// And nothing extra leaked across kinds: every list has exactly one entry, not more.
Assert.Single(absorbed);
Assert.Single(grabbed);
Assert.Single(meleed);
Assert.Single(thrust);
}
}