diff --git a/src/GamePort/Application/FidelityObservation.cs b/src/GamePort/Application/FidelityObservation.cs index 305d2fb..0aef836 100644 --- a/src/GamePort/Application/FidelityObservation.cs +++ b/src/GamePort/Application/FidelityObservation.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Numerics; using System.Text; using System.Text.Json; using System.Text.RegularExpressions; @@ -13,6 +14,7 @@ internal sealed class FidelityObservation : IDisposable private static readonly JsonSerializerOptions Json = new() { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower }; private readonly Stopwatch clock = Stopwatch.StartNew(); private readonly string directory, session, caseId, kind; + private readonly string launchId = Guid.NewGuid().ToString("N"); private readonly DateTimeOffset wallStart = DateTimeOffset.UtcNow; private readonly int maxRecords; private const long MaxBytes = 512L * 1024 * 1024; @@ -21,6 +23,8 @@ internal sealed class FidelityObservation : IDisposable private string? failure; private bool completed, disposed, ownsDirectory; private double overhead; + private long? pendingDeparture; + private (string Scene, bool Controlled, string? Owner, bool Playing, string? Dialogue)? control; private FidelityObservation(string directory, string session, string caseId, string kind, int maxRecords) { this.directory = directory; this.session = session; this.caseId = caseId; this.kind = kind; this.maxRecords = maxRecords; } @@ -41,6 +45,7 @@ internal sealed class FidelityObservation : IDisposable var session = Option("--fidelity-session") ?? throw new ArgumentException("--fidelity-session required"); var caseId = Option("--fidelity-case") ?? throw new ArgumentException("--fidelity-case required"); var fixture = args.Any(a => a.StartsWith("--smoke-", StringComparison.Ordinal) + || a.StartsWith("--", StringComparison.Ordinal) && a.EndsWith("-smoke", StringComparison.Ordinal) || a is "--headless" or "--story-time" or "--time" or "--inspect" or "--skip-intro" or "--noclip" or "--debug-menu" or "--debug-page" or "--gadget-menu"); return Create(output, session, caseId, fixture ? "port_fixture" : "native_port", project, originals); @@ -57,9 +62,24 @@ internal sealed class FidelityObservation : IDisposable var path = Path.TrimEndingDirectorySeparator(Path.GetFullPath(output)); static bool Within(string child, string parent) => child.Equals(parent, StringComparison.OrdinalIgnoreCase) || child.StartsWith(Path.TrimEndingDirectorySeparator(parent) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase); - var original = Path.TrimEndingDirectorySeparator(Path.GetFullPath(originals)); - var git = Path.Combine(Path.GetFullPath(project), ".git"); - if (Within(path, original) || Within(original, path) || Within(path, git) || Within(git, path)) + static string ResolvedDirectory(string value) + { + var full = Path.GetFullPath(value); + var current = Path.GetPathRoot(full)!; + foreach (var part in full[current.Length..].Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries)) + { + current = Path.Combine(current, part); + var info = new DirectoryInfo(current); + if (info.LinkTarget != null) + current = info.ResolveLinkTarget(true)?.FullName ?? throw new ArgumentException("Unresolved protected asset link"); + } + return Path.TrimEndingDirectorySeparator(current); + } + var protectedRoots = new List { ResolvedDirectory(originals), Path.Combine(ResolvedDirectory(project), ".git") }; + // A generated --assets copy must not make the checkout's authoritative sibling writable. + foreach (var candidate in new[] { Path.Combine(project, "..", "Original"), Path.Combine(project, "Original"), Path.Combine(project, "assets") }) + if (Directory.Exists(candidate)) protectedRoots.Add(ResolvedDirectory(candidate)); + if (protectedRoots.Any(protectedRoot => Within(path, protectedRoot) || Within(protectedRoot, path))) throw new ArgumentException("Observation output must be separate from original assets and Git metadata"); for (var parent = new DirectoryInfo(path); parent != null; parent = parent.Parent) if (parent.LinkTarget != null) throw new ArgumentException("Observation output cannot traverse symbolic links"); @@ -80,6 +100,7 @@ internal sealed class FidelityObservation : IDisposable observer.WriteSummary(false); observer.writer = sink ?? new StreamWriter(new FileStream(Path.Combine(path, "events.jsonl"), FileMode.CreateNew, FileAccess.Write, FileShare.Read), new UTF8Encoding(false), 65536); + observer.writer.NewLine = "\n"; } catch (Exception error) when (OutputError(error)) { observer.Fail(error.Message); } return observer; @@ -89,8 +110,51 @@ internal sealed class FidelityObservation : IDisposable => Record("input_step", scene, simulationTick, "post_owner_step", new { requested_input = requested, accepts_input = acceptsInput, accepted_input = acceptsInput ? (PlayerInput?)requested : null, - control_owner = controlOwner, - acceptance_scope = "player_binding_input_gate; independent body/fire work is not classified by this boolean" }); + control_owner = controlOwner, control_owner_phase = "post_step", + acceptance_scope = "reported binding gate only; individual command dispatch and independent body/fire work are not classified by this boolean" }); + + public void RecordSceneEntry(string scene, int simulationTick, bool returning, bool retainedPlayer, string entryPath) + { + control = null; + Record("scene_entry", scene, simulationTick, "application_scene_composition", new { + returning, retained_player = retainedPlayer, entry_path = entryPath, departure_sequence = pendingDeparture }); + pendingDeparture = null; + } + + public void RecordTransition(string scene, string destination, int simulationTick, bool returning) + { + Record("scene_departure", scene, simulationTick, "continuation_published", new { destination, returning }); + pendingDeparture = sequence; + } + + public void RecordRawEvent(string scene, int simulationTick, uint eventType, uint? scancode, byte? button, byte? repeat) + => Record("raw_sdl_event", scene, simulationTick, "sdl_poll_before_routing", new { + event_type = eventType, scancode, button, repeat, acceptance = "raw_only; routing may consume or reject this event" }); + + public void RecordControl(string scene, int simulationTick, bool controlled, string? owner, bool playing, string? dialogue, string boundary) + { + var current = (scene, controlled, owner, playing, dialogue); + var previous = control; + if (previous == current && !boundary.StartsWith("skip:", StringComparison.Ordinal)) return; + var data = new { controlled, control_owner = owner, playing, dialogue }; + Record("control_observation", scene, simulationTick, boundary, data); + if (boundary.StartsWith("skip:", StringComparison.Ordinal) && previous is { } before && (before.Playing || !before.Controlled)) + Record("dialogue_skip", scene, simulationTick, boundary, data); + if ((previous == null || previous is { Playing: false }) && playing) + Record("dialogue_start", scene, simulationTick, boundary, data); + if (previous is { Playing: true } && !playing) + Record("dialogue_end", scene, simulationTick, + boundary == "director_step" ? "natural_director_step" : boundary, data); + control = current; + } + + public void RecordState(string scene, int simulationTick, Vector3 root, Vector3 rotation, Vector3 velocity, + bool grounded, int movementMode, bool inputAfterPlayerUpdate, int controllers, int physics, int effects) + => Record("player_state", scene, simulationTick, "post_owner_value_snapshot", new { + actor_root = new[] { root.X, root.Y, root.Z }, euler_degrees = new[] { rotation.X, rotation.Y, rotation.Z }, + velocity = new[] { velocity.X, velocity.Y, velocity.Z }, grounded, movement_mode = movementMode, + input_after_player_update = inputAfterPlayerUpdate, controller_steps = controllers, physics_steps = physics, + effect_steps = effects, interpretation = "copied state only; bank/landing/idle require explicit review" }); private void Record(string name, string scene, int simulationTick, string method, object data) { @@ -100,7 +164,7 @@ internal sealed class FidelityObservation : IDisposable { if (sequence >= maxRecords) throw new IOException("Observation record limit reached"); var line = JsonSerializer.Serialize(new { schema_version = 1, session_id = session, case_id = caseId, - evidence_kind = kind, clock_id = session + ":stopwatch", sequence = sequence + 1, + evidence_kind = kind, launch_id = launchId, clock_id = launchId + ":stopwatch", sequence = sequence + 1, elapsed_seconds = clock.Elapsed.TotalSeconds, simulation_tick = simulationTick, name, scene, method, data }, Json); var length = Encoding.UTF8.GetByteCount(line) + 1; @@ -148,10 +212,11 @@ internal sealed class FidelityObservation : IDisposable var target = Path.Combine(directory, "observation-summary.json"); var temporary = target + "." + Guid.NewGuid().ToString("N") + ".tmp"; var summary = new { schema_version = 1, session_id = session, case_id = caseId, evidence_kind = kind, - clock_id = session + ":stopwatch", wall_start = wallStart, wall_end = DateTimeOffset.UtcNow, + launch_id = launchId, clock_id = launchId + ":stopwatch", wall_start = wallStart, wall_end = DateTimeOffset.UtcNow, elapsed_seconds = clock.Elapsed.TotalSeconds, records = sequence, bytes, incomplete = !success, status = success ? "recorded" : "incomplete", failure, diagnostic = true, observer_seconds = overhead, max_records = maxRecords, max_bytes = MaxBytes, + overhead_scope = "Record serialization/write attempts only; excludes caller snapshots, control comparisons, final flush and summaries", limitations = new[] { "Diagnostic observer adds serialization, buffered disk writes and state-copy overhead; not a clean audiovisual capture.", "Observation is not a receipt or an acceptance decision; fixture and native full-route evidence remain distinct.", "No media clock mapping is inferred. Simulation ticks are scene-local and may reset across continuations.", diff --git a/src/GamePort/Program.cs b/src/GamePort/Program.cs index 3296a96..11a8a1a 100644 --- a/src/GamePort/Program.cs +++ b/src/GamePort/Program.cs @@ -341,6 +341,24 @@ internal static class Program var debugCheckpointFile = toolsSmoke ? Path.GetFullPath("artifacts/debug-expansion/checkpoint.tsk") : Path.Combine(AppContext.BaseDirectory, "debug-checkpoint.tsk"); Vector3 returnRoot = loadedSave?.StoredVector ?? Vector3.Zero; + void ObserveControl(string boundary) + { + if (observation != null && director != null) + observation.RecordControl(level!.Code, simulation?.Steps ?? 0, director.Controlled, + director.ControlledTag, director.Playing, director.CurrentTag, boundary); + } + void SkipObservedDialogue(string source) + { + ObserveControl("before_skip"); + director!.Skip(); + ObserveControl("skip:" + source); + } + void StepObservedDirector(float delta) + { + ObserveControl("before_director_step"); + director?.Step(delta); + ObserveControl("director_step"); + } void RequestTransition(LevelTransition request) { if (transitionRequest != null) return; @@ -593,6 +611,8 @@ internal static class Program var renderer = presentation.LoadScene(mesh, texture, headless, walking ? WalkTitle : animations?.WindowTitle ?? "Jimmy Neutron — scene preview | C camera", width, height, !args.Contains("--no-validation")); + observation?.RecordSceneEntry(level?.Code ?? "preview", simulation?.Steps ?? 0, returning, + carriedPlayer != null, carriedSave != null ? "retained" : loadedSave != null ? "tsk-story" : "fresh-direct-scene"); var window = presentation.Window; ShrinkSoldier? shrinkVictim = null; var shrinkPhaseMask = 0; @@ -668,6 +688,7 @@ internal static class Program sceneAudio.Music(originalStart!.Text("MusicDatabase") ?? "none", originalStart.Integer("MusicIndex", -1)); } director.Begin(originalStart!, activateStartTrigger: !returning); + ObserveControl("scene_begin"); gadgets?.Reset(); baseballs?.Reset(); interactions!.Reset(); @@ -685,7 +706,7 @@ internal static class Program Console.WriteLine($"Practice RETURN: exact saved root={restored}, root={simulation.ActorRoot}, STRT yaw={simulation.Yaw}, intro suppressed={!director.Playing}, companion restored={companionRestored}, retained player input order={simulation.InputAfterPlayerUpdate}, gadget availability={interactions.Inventory.State(0, 3)}."); if (!restored) throw new InvalidOperationException("RETURN did not restore the live departure root without replaying STRT actions"); } - if (args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || scooterSmoke || gadgetWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke || controlPhaseSmoke) { sceneAudio?.StopSpeech(); director.Skip(); } + if (args.Contains("--skip-intro") || jetpackSmoke || shrinkSmoke || invisibleSmoke || bubbleSmoke || baseballSmoke || rocketSmoke || grapplerSmoke || scooterSmoke || gadgetWindowSmoke || debugSmoke || diagnosticsSmoke || toolsSmoke || controlPhaseSmoke) { sceneAudio?.StopSpeech(); SkipObservedDialogue("startup-option-or-fixture"); } if (gadgetWindowSmoke) { interactions!.Inventory.SetState(0,3,1); interactions.Inventory.SelectGadget(3); } if (controlPhaseSmoke) { @@ -710,13 +731,13 @@ internal static class Program { if (interactions!.Inventory.State(0, 3) != 1) throw new InvalidOperationException("VR04 PostLoad tail did not re-enable its owned practice jetpack"); - director.Skip(); + SkipObservedDialogue("fixture-setup"); interactions!.Update(level.Entities.First(e => e.Kind == "LOAD").Position); if (transitionRequest is not { Returning: true }) throw new InvalidOperationException("VR04 exit did not preserve RETURN identity"); } if (args.Contains("--smoke-transition")) { - director.Skip(); + SkipObservedDialogue("fixture-setup"); interactions!.Update(level!.Entities.First(e => e.Kind == "LOAD").Position); if (transitionRequest == null) throw new InvalidOperationException("Original VR01 RETURN contact did not request a transition"); } @@ -729,9 +750,9 @@ internal static class Program if (carlSmoke) LabRouteSmoke.StartCarl(level!, director, interactions!, () => practice.Key(17, Vector2.Zero)); if (objectiveSmoke) { - director.Skip(); + SkipObservedDialogue("fixture-setup"); director.Touch(level!.Player!.Tag!, level.Entities.Single(e => e.Tag == "teleportexplanation").Position); - director.Skip(); + SkipObservedDialogue("fixture-setup"); if (interactions!.CurrentObjective != 1) throw new InvalidOperationException("Original explanation did not assign objective1"); if (objectiveWindowSmoke) objectivePanel!.Step(9); } @@ -739,7 +760,7 @@ internal static class Program || practiceReturnSmoke && level.Code == "LV1B" && !returning) { if ((!headless && !practiceWindowSmoke) || level?.Code != "LV1B") throw new ArgumentException("Practice smoke requires the original lab"); - director.Skip(); + SkipObservedDialogue("fixture-setup"); if (practiceReturnSmoke) { // Move the real player away from STRT so an accidental @@ -748,7 +769,7 @@ internal static class Program director.SyncActor(level.Player!.Tag!, simulation.ActorRoot, simulation.Rotation); } director.Touch(level!.Player!.Tag!, level.Entities.Single(e => e.Tag == "teleportexplanation").Position); - director.Skip(); + SkipObservedDialogue("fixture-setup"); interactions!.Update(director.FindActor("shrinkray")!.Position); if (!practice.Active) throw new InvalidOperationException("Original lab pickup did not open practice modal"); if (args.Contains("--smoke-practice-transition") || practiceReturnSmoke) practice.Key(28, Vector2.Zero); @@ -761,7 +782,7 @@ internal static class Program interactions!.UpdateEnergy(simulation!.Energy); foreach (var patrol in patrols.Values) patrol.Step(FixedStepClock.Step); mechanisms!.Step(FixedStepClock.Step); - director.Step(FixedStepClock.Step); + StepObservedDirector(FixedStepClock.Step); objectivePanel!.Step(FixedStepClock.Step, director.ControlledTag != null, practice.Active); if (animations!.SelectAction(director.FindActor(level!.Player!.Tag!)!.Animation)) initialPoseTime = 0; initialPoseTime += FixedStepClock.Step; @@ -879,6 +900,7 @@ internal static class Program if (simulation == null) { debugMenu.Message = "RESET REQUIRES PLAY MODE"; return; } if (practice.Active) practice.Key(17, Vector2.Zero); playerBinding?.ResetVehicle();simulation.Reset(); poseTime = 0; sceneAudio?.StopSpeech(); director?.Begin(originalStart!); + ObserveControl("reset_begin"); rocketship?.Reset(); if(scooter!=null) { @@ -914,7 +936,7 @@ internal static class Program case DebugAction.Camera: ToggleCamera(); debugMenu.Close(); break; case DebugAction.SkipCutscene: if (director is { Playing: true } or { Blocked: true }||director is{Controlled:false}&&rocketship?.Mounted!=true) - { sceneAudio?.StopSpeech(); director.Skip(); debugMenu.Message = "CUTSCENE SKIPPED"; } + { sceneAudio?.StopSpeech(); SkipObservedDialogue("debug-menu"); debugMenu.Message = "CUTSCENE SKIPPED"; } else debugMenu.Message = "NO ACTIVE CUTSCENE"; break; case DebugAction.RefillEnergy when simulation != null: @@ -1137,6 +1159,10 @@ internal static class Program } while (!headless && Sdl.SDL_PollEvent(out var e)) { + observation?.RecordRawEvent(level?.Code ?? "preview", simulation?.Steps ?? 0, + e.Type, e.Type is Sdl.KeyDown or Sdl.KeyUp ? e.Scancode : null, + e.Type is Sdl.MouseButtonDown or Sdl.MouseButtonUp ? e.MouseButton : null, + e.Type is Sdl.KeyDown or Sdl.KeyUp ? e.Repeat : null); if(scooterSmoke&&e.Type==Sdl.KeyDown) sawScooterKeys|=e.Scancode switch{81=>1,82=>2,80=>4,225=>8,43=>16,60=>32,21=>64,_=>0}; if(grapplerSmoke&&e.Type==Sdl.KeyDown) @@ -1230,7 +1256,7 @@ internal static class Program if (smoke && e.Scancode == 79) sawKey = true; if (e.Scancode is 41 or 44 && e.Repeat == 0 && director is { Controlled: false }&&rocketship?.Mounted!=true && (e.Scancode != 44 || simulation?.Noclip != true)) - { sceneAudio?.StopSpeech(); director.Skip(); keys.Clear(); mouseJump = false; } + { sceneAudio?.StopSpeech(); SkipObservedDialogue("sdl-key-" + e.Scancode); keys.Clear(); mouseJump = false; } else if (e.Scancode == 41) running = false; if (inspecting && e.Repeat == 0 && animations?.Select(e.Scancode) == true) { @@ -1301,6 +1327,10 @@ internal static class Program else { simulation.Step(input); acceptsInput = true; } observation?.RecordInput(level?.Code ?? "preview", simulation.Steps, input, acceptsInput, director?.ControlledTag ?? (playerBinding == null ? "direct-simulation" : "script")); + observation?.RecordState(level?.Code ?? "preview", simulation.Steps, simulation.ActorRoot, + simulation.Rotation, simulation.Velocity, simulation.Grounded, simulation.MovementMode, + simulation.InputAfterPlayerUpdate, simulation.ControllerSteps, simulation.PhysicsSteps, simulation.EffectSteps); + ObserveControl("player_step"); scooterFixture?.Received(input); grapplerFixture?.Received(input); rocketFixture?.Received(input); @@ -1324,7 +1354,7 @@ internal static class Program } mechanisms?.Step(FixedStepClock.Step); foreach (var patrol in patrols.Values) patrol.Step(FixedStepClock.Step); - director?.Step(FixedStepClock.Step); + StepObservedDirector(FixedStepClock.Step); objectivePanel?.Key(keys.Contains(18) && director is { Controlled: true, InventoryEnabled: true }); objectivePanel?.Step(FixedStepClock.Step, director?.ControlledTag != null, practice.Active); var switched = director is { Controlled: false } && !simulation.Noclip @@ -1525,8 +1555,8 @@ internal static class Program && simulation.Energy < 20 && Vector2.Distance(new(simulation.ActorRoot.X, simulation.ActorRoot.Z), new(controlEntry.X, controlEntry.Z)) < .001f; CutsceneIdleSmoke.LandWhileLocked(playerBinding!, director!, simulation!); sceneAudio?.StopSpeech(); - director!.Skip(); - CutsceneIdleSmoke.VerifyReturn(playerBinding!, director, simulation!); + SkipObservedDialogue("control-phase-fixture"); + CutsceneIdleSmoke.VerifyReturn(playerBinding!, director!, simulation!); controlControllers = simulation!.ControllerSteps; } if (controlPhaseSmoke && count == 30) @@ -1873,6 +1903,7 @@ internal static class Program continuation = new(nextArgs.ToArray(), (debugCheckpointToLoad ?? interactions!.Snapshot()) with { StartPoint = transitionRequest.StartPoint, StoredVector = debugCheckpointToLoad?.StoredVector ?? returnRoot }, transitionRequest.Returning, debugCheckpointToLoad == null ? simulation?.CaptureLevelState(interactions!.Inventory.SelectedGadget) : null); + observation?.RecordTransition(level!.Code, transitionRequest.LevelFile, simulation?.Steps ?? 0, transitionRequest.Returning); Console.WriteLine($"Loading original destination: {transitionRequest.LevelFile}, start={transitionRequest.StartPoint}; fade behavior remains unreconstructed."); } if (walkSmoke && !simulation!.SmokePassed) return 2; diff --git a/tests/GamePort.FidelityObservationTests/Program.cs b/tests/GamePort.FidelityObservationTests/Program.cs index 6d7c4c4..4788ca6 100644 --- a/tests/GamePort.FidelityObservationTests/Program.cs +++ b/tests/GamePort.FidelityObservationTests/Program.cs @@ -1,4 +1,6 @@ using System.Text.Json; +using System.Numerics; +using GamePort.Assets; using GamePort.Application; using GamePort.Game; @@ -62,14 +64,51 @@ try Check(continuation.Select(e => e.GetProperty("sequence").GetInt64()).SequenceEqual(Enumerable.Range(1, continuation.Length).Select(i => (long)i)), "ordered transitions share sequence"); Check(continuation.Last().GetProperty("scene").GetString() == "LV1B" && continuation.Last().GetProperty("data").GetProperty("returning").GetBoolean(), "RETURN and arrival remain paired"); Check(continuation.Zip(continuation.Skip(1)).All(p => p.First.GetProperty("elapsed_seconds").GetDouble() <= p.Second.GetProperty("elapsed_seconds").GetDouble()), "clock survives scene tick reset"); - using (var fresh = Open("fresh")) { fresh.RecordSceneEntry("LV1B", 0, false, false, "fresh-direct-scene"); fresh.Complete(0); } - Check(Events("fresh")[0].GetProperty("simulation_tick").GetInt32() == 0 && !Summary("fresh").GetProperty("incomplete").GetBoolean(), "fresh observer owns independent clock from scene ticks"); + using (var fresh = FidelityObservation.Create(Path.Combine(root, "fresh"), "independent-session", "fresh-natural-ordinary", "port_fixture", ".", Path.Combine(root, "Original"))) + { fresh.RecordSceneEntry("LV1B", 0, false, false, "fresh-direct-scene"); fresh.Complete(0); } + Check(Events("fresh")[0].GetProperty("clock_id").GetString() != continuation[0].GetProperty("clock_id").GetString() + && Events("fresh")[0].GetProperty("simulation_tick").GetInt32() == 0 && !Summary("fresh").GetProperty("incomplete").GetBoolean(), "fresh observer owns independent clock from scene ticks"); rejected = false; try { using var invalid = FidelityObservation.Create(Path.Combine(root, "Original", "unsafe"), "safe", "case", "port_fixture", ".", Path.Combine(root, "Original")); } catch (ArgumentException) { rejected = true; } Check(rejected && !Directory.Exists(Path.Combine(root, "Original")), "original overlap rejected before write"); - var writer = new StringWriter(); using (var failedFlush = Open("flush", sink: new FlushFailureWriter())) { failedFlush.RecordInput("LV1B", 1, default, true, "Jimmy"); failedFlush.Complete(0); } Check(Summary("flush").GetProperty("incomplete").GetBoolean(), "flush failure cannot claim success"); + Check(continuation.Where(e => e.GetProperty("name").GetString() == "scene_entry").Skip(1) + .All(e => continuation.Any(d => d.GetProperty("name").GetString() == "scene_departure" + && d.GetProperty("sequence").GetInt64() == e.GetProperty("data").GetProperty("departure_sequence").GetInt64())), "arrival links actual departure sequence"); + if (!OperatingSystem.IsWindows()) + { + Directory.CreateDirectory(Path.Combine(root, "Original")); + Directory.CreateSymbolicLink(Path.Combine(root, "asset-alias"), Path.Combine(root, "Original")); + rejected = false; + try { using var invalid = FidelityObservation.Create(Path.Combine(root, "Original", "unsafe"), "safe", "case", "port_fixture", ".", Path.Combine(root, "asset-alias")); } catch (ArgumentException) { rejected = true; } + Check(rejected && !Directory.Exists(Path.Combine(root, "Original", "unsafe")), "asset aliases cannot bypass original containment"); + rejected = false; + try { using var invalid = FidelityObservation.Create(Path.Combine(root, "asset-alias", "unsafe"), "safe", "case", "port_fixture", ".", Path.Combine(root, "unrelated")); } catch (ArgumentException) { rejected = true; } + Check(rejected, "output cannot traverse symbolic-link ancestors"); + } + var positions = new[] { new Vector3(-100000, 0, -100000), new Vector3(-100000, 0, 100000), new Vector3(100000, 0, 100000), + new Vector3(-100000, 0, -100000), new Vector3(100000, 0, 100000), new Vector3(100000, 0, -100000) }; + var floor = new Mesh(positions.Select(p => new MeshVertex(p, Vector2.Zero, Vector3.One)).ToArray(), [0, 1, 2, 3, 4, 5]); + var standing = new Mesh([new(new(-20, -20, -20), Vector2.Zero, Vector3.One), new(new(20, 80, 20), Vector2.Zero, Vector3.One)], []); + var off = new LabSimulation(new SceneCollision(floor), standing, new Vector3(0, 25, 0), 0f); + var failed = new LabSimulation(new SceneCollision(floor), standing, new Vector3(0, 25, 0), 0f); + using (var observer = Open("failed-simulation", sink: new BrokenWriter())) + { + for (var tick = 0; tick < 120; tick++) + { + var input = new PlayerInput(tick < 80, false, tick > 15 && tick < 45, false, tick < 20); + off.Step(input); failed.Step(input); + observer.RecordInput("fixture-floor", failed.Steps, input, true, "Jimmy"); + observer.RecordState("fixture-floor", failed.Steps, failed.ActorRoot, failed.Rotation, failed.Velocity, + failed.Grounded, failed.MovementMode, failed.InputAfterPlayerUpdate, failed.ControllerSteps, failed.PhysicsSteps, failed.EffectSteps); + } + observer.Complete(0); + } + Check(off.ActorRoot == failed.ActorRoot && off.Rotation == failed.Rotation && off.Velocity == failed.Velocity + && off.Steps == failed.Steps && off.ControllerSteps == failed.ControllerSteps && off.PhysicsSteps == failed.PhysicsSteps + && off.EffectSteps == failed.EffectSteps && Summary("failed-simulation").GetProperty("incomplete").GetBoolean(), + "write failure preserves actual 120-step movement/body/effect state exactly"); Console.WriteLine($"Fidelity observation checks: {checks} passed"); } finally { Directory.Delete(root, true); } diff --git a/tests/test_fidelity_observation.py b/tests/test_fidelity_observation.py index ae11fc0..7d3e304 100644 --- a/tests/test_fidelity_observation.py +++ b/tests/test_fidelity_observation.py @@ -1,6 +1,5 @@ """Actual port-process observation plumbing; fixtures never fill native acceptance.""" import json -import os from pathlib import Path import subprocess import sys @@ -13,9 +12,25 @@ import fidelity_receipts as receipts class FidelityObservation(unittest.TestCase): + @classmethod + def setUpClass(cls): + result = subprocess.run(['bash', '-lc', 'source scripts/env.sh && dotnet build GamePort.csproj --no-restore'], + cwd=ROOT, capture_output=True, text=True, timeout=90) + if result.returncode: + raise RuntimeError(result.stdout + result.stderr) + required = ['level1b/scene.json', 'VR04/scene.json', 'ui/ui.json', 'animations/jimstop/animation.json'] + if not all((ROOT / 'artifacts/extracted' / name).is_file() for name in required): + # The consolidated script runs Python before its preparation step. + # Reuse its local extractor instead of assuming generated fixtures exist. + result = subprocess.run([sys.executable, 'tools/extractors/prepare.py', '--all-scenes', + '--audio', 'sounds', 'musicsecretlab'], cwd=ROOT, + capture_output=True, text=True, timeout=300) + if result.returncode: + raise RuntimeError(result.stdout + result.stderr) + def run_port(self, *args): # Fixed shell source; caller values are positional argv, never shell code. - return subprocess.run(['bash', '-lc', 'source scripts/env.sh && dotnet run --no-build -- "$@"', + return subprocess.run(['bash', '-lc', 'source scripts/env.sh && dotnet bin/Debug/net10.0/GamePort.dll "$@"', 'observer-test', *map(str, args)], cwd=ROOT, text=True, capture_output=True, timeout=90) @@ -103,6 +118,8 @@ class FidelityObservation(unittest.TestCase): self.assertEqual([e['data']['retained_player'] for e in entries], [False, True, True]) departures = [e for e in records if e['name'] == 'scene_departure'] self.assertEqual(len(departures), 2) + self.assertEqual([e['data']['departure_sequence'] for e in entries[1:]], + [e['sequence'] for e in departures]) self.assertEqual(departures[-1]['data']['returning'], True) self.assertEqual({e['session_id'] for e in records}, {'retained-process'}) self.assertEqual({e['evidence_kind'] for e in records}, {'port_fixture'})