From 46ed99246b2791abe1f738530d780abdcad87383 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 10 Jul 2026 07:14:44 +0100 Subject: [PATCH] Emit portable Unity gameplay witnesses --- .../PlayMode/GenericWorldCaptureTests.cs | 80 ++++++++++++++++++- scripts/run-aetheria-daemon-world-witness.ps1 | 65 ++++++++++++++- 2 files changed, 142 insertions(+), 3 deletions(-) diff --git a/TestProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs b/TestProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs index 5cfc17e..f80ccd1 100644 --- a/TestProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs +++ b/TestProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs @@ -183,6 +183,11 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests EveUnityCultMeshLiveProviderTransport transport = null; EveUnitySceneLiveProviderBridge bridge = null; EveUnityPlayableWorldRuntime runtime = null; + WitnessReceipt movementReceipt = null; + WitnessReceipt focusReceipt = null; + WitnessReceipt actionReceipt = null; + long initialVersion = 0; + float movementDistance = 0f; try { @@ -223,7 +228,7 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests Is.GreaterThan(1), "The generic client substituted its primitive fallback instead of the provider-authored AssetBundle prefab."); var initialPosition = marker.transform.position; - var initialVersion = runtime.ActiveVersion; + initialVersion = runtime.ActiveVersion; var request = runtime.SubmitMoveVectorIntent(playerId, 1f, 0f, 1f); var deadline = Time.realtimeSinceStartup + 12f; @@ -243,7 +248,9 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests runtime.LastReceipt.Message); Assert.That(runtime.LastReceipt.SourceVersion, Is.GreaterThan(initialVersion)); Assert.That(runtime.ActiveVersion, Is.GreaterThan(initialVersion)); - Assert.That(Vector3.Distance(FindMarker(root, playerId).transform.position, initialPosition), Is.GreaterThan(0.01f)); + movementDistance = Vector3.Distance(FindMarker(root, playerId).transform.position, initialPosition); + Assert.That(movementDistance, Is.GreaterThan(0.01f)); + movementReceipt = WitnessReceipt.From("movement", runtime.LastReceipt); var movementVersion = runtime.ActiveVersion; var focus = runtime.SubmitFocusIntent(playerId); @@ -259,6 +266,7 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests Assert.That(runtime.LastReceipt.CommandId, Is.EqualTo(focus.CommandId)); Assert.That(runtime.LastReceipt.State, Is.EqualTo("accepted").Or.EqualTo("reconciled")); Assert.That(runtime.LastReceipt.SourceVersion, Is.GreaterThan(movementVersion)); + focusReceipt = WitnessReceipt.From("targeting", runtime.LastReceipt); var focusVersion = runtime.ActiveVersion; var action = runtime.SubmitActionIntent(playerId, "0"); @@ -278,6 +286,7 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests runtime.LastReceipt.Message); Assert.That(runtime.LastReceipt.SourceVersion, Is.GreaterThan(focusVersion)); Assert.That(runtime.ActiveVersion, Is.GreaterThanOrEqualTo(runtime.LastReceipt.SourceVersion)); + actionReceipt = WitnessReceipt.From("action", runtime.LastReceipt); var light = lightObject.AddComponent(); light.type = LightType.Directional; @@ -320,6 +329,13 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(capturePath))); File.WriteAllBytes(capturePath, pixels.EncodeToPNG()); Assert.That(new FileInfo(capturePath).Length, Is.GreaterThan(1024)); + WriteWitnessFacts( + initialVersion, + runtime.ActiveVersion, + movementDistance, + movementReceipt, + focusReceipt, + actionReceipt); } finally { @@ -337,6 +353,66 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests } } + private static void WriteWitnessFacts( + long initialVersion, + long finalVersion, + float movementDistance, + WitnessReceipt movement, + WitnessReceipt targeting, + WitnessReceipt action) + { + var path = Environment.GetEnvironmentVariable("EVEUNITY_WITNESS_FACTS_PATH"); + if (string.IsNullOrWhiteSpace(path)) return; + var document = new WitnessFacts + { + providerAdvertisement = true, + providerAssets = true, + movement = movement != null, + targeting = targeting != null, + action = action != null, + initialVersion = initialVersion, + finalVersion = finalVersion, + movementDistance = movementDistance, + receipts = new[] { movement, targeting, action } + }; + Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))); + File.WriteAllText(path, JsonUtility.ToJson(document, true)); + } + + [Serializable] + private sealed class WitnessFacts + { + public bool providerAdvertisement; + public bool providerAssets; + public bool movement; + public bool targeting; + public bool action; + public long initialVersion; + public long finalVersion; + public float movementDistance; + public WitnessReceipt[] receipts; + } + + [Serializable] + private sealed class WitnessReceipt + { + public string commandKind; + public string commandId; + public string state; + public long sourceVersion; + + public static WitnessReceipt From(string commandKind, EveUnitySceneCommandReceipt receipt) + { + return new WitnessReceipt + { + commandKind = commandKind, + commandId = receipt.CommandId, + state = receipt.State, + sourceVersion = receipt.SourceVersion + }; + } + } + private static EveUnityPlayableWorldEntityMarker FindMarker(GameObject root, string entityId) { foreach (var marker in root.GetComponentsInChildren()) diff --git a/scripts/run-aetheria-daemon-world-witness.ps1 b/scripts/run-aetheria-daemon-world-witness.ps1 index 90bb7fc..36aa890 100644 --- a/scripts/run-aetheria-daemon-world-witness.ps1 +++ b/scripts/run-aetheria-daemon-world-witness.ps1 @@ -4,6 +4,8 @@ param( [string] $CultLibRoot = "E:\Projects\CultLib", [int] $Port = 3076, [string] $OutputDirectory = "artifacts\aetheria-daemon", + [ValidateSet("auto", "cold", "warm")] + [string] $CacheState = "auto", [switch] $SkipAssetBundleBuild ) @@ -16,6 +18,8 @@ $unityLogPath = Join-Path $outputRoot "unity.log" $bundleBuildLogPath = Join-Path $outputRoot "asset-bundle-build.log" $daemonLogPath = Join-Path $outputRoot "aetheria-daemon.log" $capturePath = Join-Path $outputRoot "aetheria-daemon-world.png" +$factsPath = Join-Path $outputRoot "witness-facts.json" +$witnessPath = Join-Path $outputRoot "runtime-witness.json" $replicaPath = Join-Path $outputRoot "eve-unity-replica.cc" $assetCachePath = Join-Path $outputRoot "asset-cache" $statePath = Join-Path $outputRoot "aetheria-witness-state.cc" @@ -26,6 +30,15 @@ foreach ($required in @($UnityExe, $projectRoot, $daemonProject, (Join-Path $Cul } New-Item -ItemType Directory -Force -Path $outputRoot | Out-Null +if ($CacheState -eq "cold" -and (Test-Path -LiteralPath $assetCachePath)) { + Remove-Item -LiteralPath $assetCachePath -Recurse -Force +} +$cacheWasWarm = @(Get-ChildItem -LiteralPath $assetCachePath -Filter *.bundle -File -ErrorAction SilentlyContinue).Count -gt 0 +if ($CacheState -eq "warm" -and -not $cacheWasWarm) { + throw "Warm witness requested without an existing verified bundle cache at $assetCachePath" +} +$observedCacheState = if ($cacheWasWarm) { "warm" } else { "cold" } +$witnessStartedAt = [DateTimeOffset]::UtcNow foreach ($ephemeralPath in @( $replicaPath, "$replicaPath.records", @@ -96,6 +109,7 @@ try { $env:EVEUNITY_REPLICA_PATH = $replicaPath $env:EVEUNITY_AETHERIA_CAPTURE_PATH = $capturePath $env:EVEUNITY_ASSET_CACHE_PATH = $assetCachePath + $env:EVEUNITY_WITNESS_FACTS_PATH = $factsPath $arguments = @( "-batchmode", "-projectPath", $projectRoot, "-runTests", "-testPlatform", "PlayMode", @@ -113,11 +127,60 @@ try { $run = $results.SelectSingleNode("//test-run") if ($null -eq $run -or [int]$run.passed -ne 1 -or [int]$run.failed -ne 0) { throw "Live world witness did not pass: $resultsPath" } if (-not (Test-Path $capturePath) -or (Get-Item $capturePath).Length -lt 1024) { throw "Live world capture is missing: $capturePath" } + if (-not (Test-Path $factsPath)) { throw "Live world witness facts are missing: $factsPath" } + $facts = Get-Content -LiteralPath $factsPath -Raw | ConvertFrom-Json + $capture = Get-Item -LiteralPath $capturePath + $resultsArtifact = Get-Item -LiteralPath $resultsPath + $durationMs = [Math]::Round(([DateTimeOffset]::UtcNow - $witnessStartedAt).TotalMilliseconds, 3) + $testDurationMs = [Math]::Round(([double]$run.duration) * 1000, 3) + $witness = [ordered]@{ + schema = "gamecult.eve.runtime_witness.v1" + witnessId = "eveunity.aetheria.game.$observedCacheState" + runtimeId = "unity-scene" + runtimeOwnerRepo = "EveUnity" + providerId = "aetheria.daemon" + surfaceId = "aetheria.game" + projectionKind = "provider-authored-world-surface" + status = "pass" + generatedAtUtc = [DateTimeOffset]::UtcNow.ToString("O") + execution = [ordered]@{ + cacheState = $observedCacheState + durationMs = $durationMs + testDurationMs = $testDurationMs + } + assertions = $facts + receipts = @($facts.receipts) + screenshotMetrics = [ordered]@{ + width = 640 + height = 360 + encodedSizeBytes = $capture.Length + sha256 = (Get-FileHash -LiteralPath $capture.FullName -Algorithm SHA256).Hash.ToLowerInvariant() + } + artifacts = @( + [ordered]@{ + kind = "unity-frame-png" + path = $capture.Name + sha256 = (Get-FileHash -LiteralPath $capture.FullName -Algorithm SHA256).Hash.ToLowerInvariant() + sizeBytes = $capture.Length + width = 640 + height = 360 + }, + [ordered]@{ + kind = "unity-test-results" + path = $resultsArtifact.Name + sha256 = (Get-FileHash -LiteralPath $resultsArtifact.FullName -Algorithm SHA256).Hash.ToLowerInvariant() + sizeBytes = $resultsArtifact.Length + } + ) + authority = "runtime-observes-provider-advertisement-assets-command-receipts-and-republished-surface-versions" + } + $witness | ConvertTo-Json -Depth 12 | Set-Content -LiteralPath $witnessPath -Encoding UTF8 Write-Host "Aetheria daemon world witness: passed" Write-Host "Capture: $capturePath" + Write-Host "Runtime witness: $witnessPath" } finally { if ($null -ne $daemon -and -not $daemon.HasExited) { Stop-Process -Id $daemon.Id -Force } - Remove-Item Env:EVEUNITY_PROVIDER_ENDPOINT, Env:EVEUNITY_PROVIDER_ID, Env:EVEUNITY_SURFACE_ID, Env:EVEUNITY_REPLICA_PATH, Env:EVEUNITY_AETHERIA_CAPTURE_PATH, Env:EVEUNITY_ASSET_CACHE_PATH -ErrorAction SilentlyContinue + Remove-Item Env:EVEUNITY_PROVIDER_ENDPOINT, Env:EVEUNITY_PROVIDER_ID, Env:EVEUNITY_SURFACE_ID, Env:EVEUNITY_REPLICA_PATH, Env:EVEUNITY_AETHERIA_CAPTURE_PATH, Env:EVEUNITY_ASSET_CACHE_PATH, Env:EVEUNITY_WITNESS_FACTS_PATH -ErrorAction SilentlyContinue Remove-Item Env:AETHERIA_TRACE_EVE_SNAPSHOTS -ErrorAction SilentlyContinue }