test: replace input and physics source freezes

This commit is contained in:
Erik 2026-08-18 15:31:57 +02:00
parent 0ad2ee1cdf
commit caa5eb8b2b
6 changed files with 313 additions and 238 deletions

View file

@ -1,4 +1,9 @@
using System.Text.RegularExpressions;
using System.Reflection;
using AcDream.App.Net;
using AcDream.App.Physics;
using AcDream.App.Tests.Architecture;
using AcDream.Core.Physics;
using AcDream.Runtime.Gameplay;
namespace AcDream.App.Tests.Physics;
@ -13,77 +18,98 @@ public sealed class Issue270ProductionWiringTests
// the factory's deleted ApplyMovementStats body into
// LiveMovementStatsApplier, which routes through the Runtime
// movement owner's typed seam instead of touching the controller.
string applier = ReadSource("Net", "LiveMovementStatsApplier.cs");
string factory = ReadSource("Net", "LiveSessionRuntimeFactory.cs");
_ = Assert.Single(
typeof(LiveMovementStatsApplier).GetFields(
BindingFlags.Instance | BindingFlags.NonPublic),
field => field.FieldType == typeof(StaminaExhaustionEdgeTracker));
Assert.Contains(
"_staminaExhaustion.Observe(snapshot.CurrentStamina)",
applier,
StringComparison.Ordinal);
IReadOnlyList<CompiledCall> applierCalls =
CompiledCallGraph.ReadDeclared(typeof(LiveMovementStatsApplier));
Assert.Single(
Regex.Matches(
applier,
@"_movement\.ReportExhaustion\(\);")
.Cast<Match>());
Assert.Contains(
"_staminaExhaustion.Reset();",
applier,
StringComparison.Ordinal);
Assert.Contains(
"_movementStats.Reset();",
factory,
StringComparison.Ordinal);
applierCalls,
call =>
call.Target.DeclaringType == typeof(StaminaExhaustionEdgeTracker)
&& call.Target.Name == nameof(StaminaExhaustionEdgeTracker.Observe));
Assert.Single(
applierCalls,
call =>
call.Target.DeclaringType
== typeof(RuntimeLocalPlayerMovementState)
&& call.Target.Name == nameof(
RuntimeLocalPlayerMovementState.ReportExhaustion));
Assert.Single(
applierCalls,
call =>
call.Target.DeclaringType == typeof(StaminaExhaustionEdgeTracker)
&& call.Target.Name == nameof(StaminaExhaustionEdgeTracker.Reset));
IReadOnlyList<CompiledCall> factoryCalls =
CompiledCallGraph.ReadDeclared(typeof(LiveSessionRuntimeFactory));
Assert.Single(
factoryCalls,
call =>
call.Target.DeclaringType == typeof(LiveMovementStatsApplier)
&& call.Target.Name == nameof(LiveMovementStatsApplier.Reset));
// The factory keeps zero direct controller mutations: both stat
// callbacks route through the applier's seam.
Assert.Equal(
2,
Regex.Matches(factory, @"_movementStats\.Apply\(").Count);
factoryCalls.Count(call =>
call.Target.DeclaringType == typeof(LiveMovementStatsApplier)
&& call.Target.Name == nameof(LiveMovementStatsApplier.Apply)));
Assert.DoesNotContain(
"Motion.ReportExhaustion",
factory,
StringComparison.Ordinal);
factoryCalls,
call => call.Target.DeclaringType == typeof(MotionInterpreter)
&& call.Target.Name == nameof(MotionInterpreter.ReportExhaustion));
}
[Fact]
public void RemoteSpawnSettle_IsRetriedAndCoversBothCreationRoutes()
{
string source = ReadSource(
"Physics",
"LiveEntityNetworkUpdateController.cs");
const BindingFlags flags = BindingFlags.Instance
| BindingFlags.Static
| BindingFlags.Public
| BindingFlags.NonPublic
| BindingFlags.DeclaredOnly;
MethodInfo[] callers = typeof(LiveEntityNetworkUpdateController)
.GetMethods(flags)
.Where(method => method.GetMethodBody() is not null)
.Where(method => CompiledCallGraph.Read(method).Any(call =>
call.Target.DeclaringType
== typeof(LiveEntityNetworkUpdateController)
&& call.Target.Name == "SeedRemoteSpawnPlacement"))
.ToArray();
Assert.Contains(
"if (!remote.Body.InContact)",
source,
StringComparison.Ordinal);
Assert.Equal(2, callers.Length);
Assert.Equal(
3,
Regex.Matches(source, @"SeedRemoteSpawnPlacement\(").Count);
["DispatchRemoteInboundMotion", "OnPosition"],
callers.Select(method => method.Name).Order().ToArray());
MethodInfo retryingInboundRoute = Assert.Single(
callers,
method => method.Name == "DispatchRemoteInboundMotion");
IReadOnlyList<CompiledCall> retryCalls =
CompiledCallGraph.Read(retryingInboundRoute);
int contact = CompiledCallGraph.IndexOf(
retryCalls,
typeof(PhysicsBody),
"get_InContact");
int settle = CompiledCallGraph.IndexOf(
retryCalls,
typeof(LiveEntityNetworkUpdateController),
"SeedRemoteSpawnPlacement");
Assert.True(contact >= 0 && settle > contact);
// C3c-F5: the settle helper moved to Core (SpawnPlacementSettler) so
// the local player's Runtime first-entry activation shares the same
// tested compressed-first-gravity-frame sweep.
MethodInfo seed = typeof(LiveEntityNetworkUpdateController).GetMethod(
"SeedRemoteSpawnPlacement",
flags)
?? throw new MissingMethodException(
typeof(LiveEntityNetworkUpdateController).FullName,
"SeedRemoteSpawnPlacement");
Assert.Contains(
"SpawnPlacementSettler.TrySettle(",
source,
StringComparison.Ordinal);
}
private static string ReadSource(params string[] relativePath)
{
DirectoryInfo? directory = new(AppContext.BaseDirectory);
while (directory is not null)
{
if (File.Exists(Path.Combine(directory.FullName, "AcDream.slnx")))
{
return File.ReadAllText(Path.Combine(
directory.FullName,
"src",
"AcDream.App",
Path.Combine(relativePath)));
}
directory = directory.Parent;
}
throw new DirectoryNotFoundException("Could not find AcDream.slnx.");
CompiledCallGraph.Read(seed),
call => call.Target.DeclaringType == typeof(SpawnPlacementSettler)
&& call.Target.Name == nameof(SpawnPlacementSettler.TrySettle));
}
}