using System.Reflection; using AcDream.App.Composition; using AcDream.App.Rendering; using AcDream.App.Tests.Architecture; namespace AcDream.App.Tests.Rendering; public sealed class RetailPViewPassExecutorTests { [Fact] public void Extracted_contracts_retain_no_window_callbacks_or_visibility_owner() { Assert.DoesNotContain( typeof(RetailPViewFrameInput).GetProperties(), property => typeof(Delegate).IsAssignableFrom(property.PropertyType)); FieldInfo[] fields = typeof(RetailPViewPassExecutor).GetFields( BindingFlags.Instance | BindingFlags.NonPublic); Assert.DoesNotContain(fields, field => field.FieldType == typeof(GameWindow)); Assert.DoesNotContain(fields, field => field.FieldType == typeof(CellVisibility)); Assert.DoesNotContain(fields, field => field.FieldType == typeof(RetailPViewFrameInput)); Assert.DoesNotContain(fields, field => field.FieldType == typeof(RetailPViewFrameResult)); Assert.DoesNotContain(fields, field => field.FieldType == typeof(ClipFrameAssembly)); Assert.DoesNotContain( fields, field => typeof(Delegate).IsAssignableFrom(field.FieldType)); } [Fact] public void Concrete_executor_accumulates_walk_terrain_batch_timing() { // S3 chunk 3 fix round 1 (F3): the walk leaf no longer brackets // itself with Begin()/Complete() (that stopwatch-restart pair would // push one timing SAMPLE per batch, not one per frame) — it times // itself with a raw Stopwatch.GetTimestamp() delta and hands the // elapsed ticks to AccumulateWalkBatch, which only accumulates. MethodInfo landscape = typeof(RetailPViewPassExecutor).GetMethod( "DrawWalkLandCellBatch", BindingFlags.Instance | BindingFlags.NonPublic)!; IReadOnlyList landscapeCalls = CompiledCallGraph.Read(landscape); int terrainDraw = RequiredCallIndex( landscapeCalls, typeof(TerrainModernRenderer), nameof(TerrainModernRenderer.DrawLandCells)); int accumulate = RequiredCallIndex( landscapeCalls, typeof(TerrainDrawDiagnosticsController), nameof(TerrainDrawDiagnosticsController.AccumulateWalkBatch)); Assert.True(terrainDraw < accumulate); Assert.DoesNotContain( landscapeCalls, call => call.Target.DeclaringType == typeof(TerrainDrawDiagnosticsController) && call.Target.Name == nameof(TerrainDrawDiagnosticsController.Begin)); Assert.DoesNotContain( landscapeCalls, call => call.Target.DeclaringType == typeof(TerrainDrawDiagnosticsController) && call.Target.Name == nameof(TerrainDrawDiagnosticsController.Complete)); } [Fact] public void Concrete_executor_pushes_the_walk_terrain_frame_sample_at_replay_end() { // S3 chunk 3 fix round 1 (F3): DrawWalkDrivenStatics is the ONE call // site of driver.Replay in production — CompleteWalkTerrainFrame // must run immediately after it, so the frame's sample is pushed // exactly once, at "the end of the walk replay". MethodInfo drawWalkDrivenStatics = typeof(RetailPViewRenderer).GetMethod( "DrawWalkDrivenStatics", BindingFlags.Instance | BindingFlags.NonPublic)!; IReadOnlyList calls = CompiledCallGraph.Read(drawWalkDrivenStatics); int replay = RequiredCallIndex( calls, typeof(AcDream.App.Rendering.Walk.WalkFrameDriver), nameof(AcDream.App.Rendering.Walk.WalkFrameDriver.Replay)); int completeWalkFrame = RequiredCallIndex( calls, typeof(RetailPViewPassExecutor), nameof(RetailPViewPassExecutor.CompleteWalkTerrainFrame)); Assert.True(replay < completeWalkFrame); } [Fact] public void Frame_composition_constructs_one_walk_executor() { MethodInfo compose = typeof(FrameRootCompositionPhase).GetMethod( "ComposeCore", BindingFlags.Instance | BindingFlags.NonPublic)!; IReadOnlyList calls = CompiledCallGraph.Read(compose); int executor = RequiredCallIndex( calls, typeof(RetailPViewPassExecutor), ".ctor"); int renderer = RequiredCallIndex( calls, typeof(WorldScenePViewRenderer), ".ctor"); Assert.True(executor < renderer); Assert.Single( calls, call => call.Target.DeclaringType == typeof(RetailPViewPassExecutor) && call.Target.Name == ".ctor"); Assert.Single( calls, call => call.Target.DeclaringType == typeof(WorldScenePViewRenderer) && call.Target.Name == ".ctor"); } private static int RequiredCallIndex( IReadOnlyList calls, Type declaringType, string methodName) { int index = CompiledCallGraph.IndexOf(calls, declaringType, methodName); Assert.True( index >= 0, $"Expected call to {declaringType.Name}.{methodName}."); return index; } }