feat(01-04): preserve observer identity through control and scene changes

This commit is contained in:
UnixNight committed 2026-11-12 23:20:14 -05:00
1 parent 6bccd47b9b
commit ea4dc9b5df
4 files changed
+177 -25

No files matched your search

@@ -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); }
+19 -2
View File
@@ -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'})