Brokkr C#: snapshot lists as whole values; C# pin to CultLib 9fc4bdda; snapshots reach disk again #18
8 changed files with 110 additions and 27 deletions
|
|
@ -2,8 +2,8 @@
|
|||
<PropertyGroup>
|
||||
<CultLibRoot Condition="'$(CultLibRoot)' == '' and '$(CULTLIB_ROOT)' != ''">$(CULTLIB_ROOT)</CultLibRoot>
|
||||
<CultLibRoot Condition="'$(CultLibRoot)' == ''">$(MSBuildThisFileDirectory)..\CultLib</CultLibRoot>
|
||||
<!-- CultLib 2.0.0: tag cultlib-unity-v2.0.0. -->
|
||||
<CultLibRevision>42dce3611a81adc5c5fac54cadbaa5637d6022d3</CultLibRevision>
|
||||
<!-- CultLib 9fc4bdda: MessagePack default payload, element ids. -->
|
||||
<CultLibRevision>9fc4bdda6a8620f846b58e89ddf476f4676d3e89</CultLibRevision>
|
||||
<GitExecutable Condition="'$(GitExecutable)' == '' and Exists('C:\Program Files\Git\cmd\git.exe')">C:\Program Files\Git\cmd\git.exe</GitExecutable>
|
||||
<GitExecutable Condition="'$(GitExecutable)' == ''">git</GitExecutable>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<Project>
|
||||
<!-- Builds consume CultLib at one admitted revision. Point CultLibRoot (or CULTLIB_ROOT) at a clean
|
||||
worktree of that revision: git worktree add <path> cultlib-unity-v2.0.0 (detached) (in CultLib). -->
|
||||
worktree of that revision: git worktree add <path> <revision>, detached (in CultLib). -->
|
||||
<Target Name="VerifyCultLibRevision"
|
||||
BeforeTargets="ResolveProjectReferences"
|
||||
Condition="'$(SkipCultLibRevisionCheck)' != 'true'">
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
<Output TaskParameter="ConsoleOutput" PropertyName="ActualCultLibRevision" />
|
||||
</Exec>
|
||||
<Error Condition="'@(_CultLibReference)' != '' and '$([System.String]::Copy($(ActualCultLibRevision)).Trim())' != '$(CultLibRevision)'"
|
||||
Text="CultLib must be revision $(CultLibRevision) (cultlib-unity-v2.0.0); found $([System.String]::Copy($(ActualCultLibRevision)).Trim()). Set CultLibRoot to a clean worktree of that tag." />
|
||||
Text="CultLib must be revision $(CultLibRevision); found $([System.String]::Copy($(ActualCultLibRevision)).Trim()). Set CultLibRoot to a clean worktree of that revision." />
|
||||
<Exec Condition="'@(_CultLibReference)' != ''"
|
||||
Command=""$(GitExecutable)" -C "$(CultLibRoot)" status --porcelain --untracked-files=normal"
|
||||
ConsoleToMSBuild="true"
|
||||
|
|
|
|||
|
|
@ -176,8 +176,12 @@ internal static class Cli
|
|||
$"Timed out waiting for Brokkr receipt '{receiptKey.Value}'; the intent is still in the store: a running editor with the sink on will run it, but if the operator enables the sink after now it expires unrun.{why}");
|
||||
}
|
||||
|
||||
private static BrokkrHostSnapshot? ReadHostSnapshot(CultCache cache) =>
|
||||
cache.TryGet(new CultRecordKey("unity/host/current"), out BrokkrHostSnapshot? host) ? host : null;
|
||||
private static BrokkrHostSnapshot? ReadHostSnapshot(CultCache cache)
|
||||
{
|
||||
if (!cache.TryGet(new CultRecordKey("unity/host/current"), out BrokkrHostSnapshot? host)) return null;
|
||||
host.RefuseDefaultLists();
|
||||
return host;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> Parse(string[] args)
|
||||
{
|
||||
|
|
|
|||
60
brokkr-contracts.Tests/BrokkrHostSnapshotTests.cs
Normal file
60
brokkr-contracts.Tests/BrokkrHostSnapshotTests.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System.Collections.Immutable;
|
||||
using GameCult.Brokkr;
|
||||
using MessagePack;
|
||||
|
||||
namespace Brokkr.Contracts.Tests;
|
||||
|
||||
public sealed class BrokkrHostSnapshotTests
|
||||
{
|
||||
// Captured before the lists became ImmutableArray holders: the record payload must not change.
|
||||
private const string PayloadHex =
|
||||
"DC0013D92567616D6563756C742E62726F6B6B722E746F6F6C5F686F73745F736E617073686F742E7630B362726F6B6B722E756E6974795F656469746F72AC756E6974792D656469746F72A170A174A0A0A000900090919EA16FA0A0A0C2A00000A09195A163A0A0C29195A178A0A0A131C2A0A0A0909196A161A0A0C2C2A0C2C2C2C2C2";
|
||||
|
||||
private static BrokkrHostSnapshot Populated() => new()
|
||||
{
|
||||
projectPath = "p",
|
||||
observedAt = "t",
|
||||
sceneObjects = ImmutableArray.Create(new BrokkrGameObjectSnapshot
|
||||
{
|
||||
objectId = "o",
|
||||
components = ImmutableArray.Create(new BrokkrComponentSnapshot
|
||||
{
|
||||
componentId = "c",
|
||||
properties = ImmutableArray.Create(new BrokkrSerializedPropertySnapshot { path = "x", value = "1" })
|
||||
})
|
||||
}),
|
||||
assets = ImmutableArray.Create(new BrokkrAssetSnapshot { path = "a" })
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void ListsAreWholeValuesWithTheSameBytesAsArrays() =>
|
||||
Assert.Equal(PayloadHex, Convert.ToHexString(MessagePackSerializer.Serialize(Populated())));
|
||||
|
||||
[Fact]
|
||||
public void PopulatedSnapshotIsAccepted() => Populated().RefuseDefaultLists();
|
||||
|
||||
[Theory]
|
||||
[InlineData(12)]
|
||||
[InlineData(13)]
|
||||
public void NilListsDecodeToDefaultAndAreRefused(int key)
|
||||
{
|
||||
var fields = MessagePackSerializer.Deserialize<object?[]>(MessagePackSerializer.Serialize(Populated()));
|
||||
fields[key] = null;
|
||||
var snapshot = MessagePackSerializer.Deserialize<BrokkrHostSnapshot>(MessagePackSerializer.Serialize(fields));
|
||||
|
||||
var error = Assert.Throws<InvalidOperationException>(snapshot.RefuseDefaultLists);
|
||||
Assert.Contains("default", error.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultNestedListsAreRefused()
|
||||
{
|
||||
var snapshot = Populated();
|
||||
snapshot.sceneObjects[0].components = default;
|
||||
Assert.Throws<InvalidOperationException>(snapshot.RefuseDefaultLists);
|
||||
|
||||
snapshot = Populated();
|
||||
snapshot.sceneObjects[0].components[0].properties = default;
|
||||
Assert.Throws<InvalidOperationException>(snapshot.RefuseDefaultLists);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ namespace Brokkr.Contracts.Tests;
|
|||
// The scenario harness: an editor without Unity. It opens the store exactly as BrokkrCultMeshMirror does (a CultMesh
|
||||
// node with StartServer=false over a directory store, no shard log) and runs one service tick in the
|
||||
// service order: pull, drain pending intents through BrokkrCommandDrain (the same class the service uses), host
|
||||
// snapshot, soft flush. "Executing" an intent only records it, so the scenarios measure delivery and once-only
|
||||
// snapshot, flush. "Executing" an intent only records it, so the scenarios measure delivery and once-only
|
||||
// execution, not Unity. It is also a thin IBrokkrCommandStore in front of the real BrokkrCommandStore, with knobs to
|
||||
// make writes fail and to land a writer between the enable's pull and its commit.
|
||||
internal sealed class EditorProbe : IDisposable, IBrokkrCommandStore
|
||||
|
|
@ -132,7 +132,7 @@ internal sealed class EditorProbe : IDisposable, IBrokkrCommandStore
|
|||
projectPath = "probe",
|
||||
agentCommandsEnabled = AgentCommandsEnabled
|
||||
});
|
||||
await node.FlushAsync(soft: true);
|
||||
await node.FlushAsync();
|
||||
return handled;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,8 +77,9 @@ namespace GameCult.Brokkr.Editor
|
|||
internal async Task PublishSnapshotAsync(BrokkrHostSnapshot snapshot)
|
||||
{
|
||||
RequireRunning();
|
||||
snapshot.RefuseDefaultLists();
|
||||
await node.Database.PutAsync(new CultRecordKey("unity/host/current"), snapshot);
|
||||
await node.FlushAsync(soft: true);
|
||||
await node.FlushAsync();
|
||||
}
|
||||
|
||||
// Command ids are single-use: a caller with no id gets a fresh one, and reusing an answered id is a defect.
|
||||
|
|
@ -91,42 +92,42 @@ namespace GameCult.Brokkr.Editor
|
|||
}
|
||||
|
||||
await node.Database.PutAsync(BrokkrCommandLedger.CommandKey(command.commandId), command);
|
||||
await node.FlushAsync(soft: true);
|
||||
await node.FlushAsync();
|
||||
}
|
||||
|
||||
internal async Task PublishQuestRouteAsync(BrokkrQuestRoute route)
|
||||
{
|
||||
RequireRunning();
|
||||
await node.Database.PutAsync(new CultRecordKey($"unity/quest-routes/{route.id}"), route);
|
||||
await node.FlushAsync(soft: true);
|
||||
await node.FlushAsync();
|
||||
}
|
||||
|
||||
internal async Task PublishSyncSessionAsync(BrokkrSyncSession session)
|
||||
{
|
||||
RequireRunning();
|
||||
await node.Database.PutAsync(new CultRecordKey($"sync/sessions/{session.sessionId}"), session);
|
||||
await node.FlushAsync(soft: true);
|
||||
await node.FlushAsync();
|
||||
}
|
||||
|
||||
internal async Task PublishSyncObjectBindingAsync(BrokkrSyncObjectBinding binding)
|
||||
{
|
||||
RequireRunning();
|
||||
await node.Database.PutAsync(new CultRecordKey($"sync/bindings/objects/{binding.bindingId}"), binding);
|
||||
await node.FlushAsync(soft: true);
|
||||
await node.FlushAsync();
|
||||
}
|
||||
|
||||
internal async Task PublishSyncVarAsync(BrokkrSyncVar syncVar)
|
||||
{
|
||||
RequireRunning();
|
||||
await node.Database.PutAsync(new CultRecordKey($"sync/vars/{syncVar.syncVarId}"), syncVar);
|
||||
await node.FlushAsync(soft: true);
|
||||
await node.FlushAsync();
|
||||
}
|
||||
|
||||
internal async Task PublishTimelineBindingAsync(BrokkrSyncTimelineBinding binding)
|
||||
{
|
||||
RequireRunning();
|
||||
await node.Database.PutAsync(new CultRecordKey($"sync/bindings/timelines/{binding.bindingId}"), binding);
|
||||
await node.FlushAsync(soft: true);
|
||||
await node.FlushAsync();
|
||||
}
|
||||
|
||||
internal bool TryDequeueSyncReceipt(out BrokkrSyncReceipt receipt)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
|
@ -55,7 +56,7 @@ namespace GameCult.Brokkr.Editor
|
|||
};
|
||||
}
|
||||
|
||||
private static BrokkrGameObjectSnapshot[] CaptureSceneObjects()
|
||||
private static ImmutableArray<BrokkrGameObjectSnapshot> CaptureSceneObjects()
|
||||
{
|
||||
var objects = new List<BrokkrGameObjectSnapshot>();
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ namespace GameCult.Brokkr.Editor
|
|||
}
|
||||
}
|
||||
|
||||
return objects.ToArray();
|
||||
return objects.ToImmutableArray();
|
||||
}
|
||||
|
||||
private static void CaptureGameObject(
|
||||
|
|
@ -109,7 +110,7 @@ namespace GameCult.Brokkr.Editor
|
|||
}
|
||||
}
|
||||
|
||||
private static BrokkrComponentSnapshot[] CaptureComponents(GameObject gameObject)
|
||||
private static ImmutableArray<BrokkrComponentSnapshot> CaptureComponents(GameObject gameObject)
|
||||
{
|
||||
return gameObject.GetComponents<Component>()
|
||||
.Where(component => component != null)
|
||||
|
|
@ -121,7 +122,7 @@ namespace GameCult.Brokkr.Editor
|
|||
enabled = ReadEnabled(component),
|
||||
properties = CaptureProperties(component)
|
||||
})
|
||||
.ToArray();
|
||||
.ToImmutableArray();
|
||||
}
|
||||
|
||||
private static string[] CaptureMaterialNames(GameObject gameObject)
|
||||
|
|
@ -135,7 +136,7 @@ namespace GameCult.Brokkr.Editor
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
private static BrokkrSerializedPropertySnapshot[] CaptureProperties(UnityEngine.Object target)
|
||||
private static ImmutableArray<BrokkrSerializedPropertySnapshot> CaptureProperties(UnityEngine.Object target)
|
||||
{
|
||||
var properties = new List<BrokkrSerializedPropertySnapshot>();
|
||||
using var serializedObject = new SerializedObject(target);
|
||||
|
|
@ -165,10 +166,10 @@ namespace GameCult.Brokkr.Editor
|
|||
}
|
||||
}
|
||||
|
||||
return properties.ToArray();
|
||||
return properties.ToImmutableArray();
|
||||
}
|
||||
|
||||
private static BrokkrAssetSnapshot[] CaptureAssets()
|
||||
private static ImmutableArray<BrokkrAssetSnapshot> CaptureAssets()
|
||||
{
|
||||
return AssetDatabase.GetAllAssetPaths()
|
||||
.Where(path => path.StartsWith("Assets/", StringComparison.Ordinal))
|
||||
|
|
@ -185,7 +186,7 @@ namespace GameCult.Brokkr.Editor
|
|||
name = System.IO.Path.GetFileNameWithoutExtension(path)
|
||||
};
|
||||
})
|
||||
.ToArray();
|
||||
.ToImmutableArray();
|
||||
}
|
||||
|
||||
internal static string GetObjectId(UnityEngine.Object target)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using GameCult.Caching;
|
||||
using MessagePack;
|
||||
|
||||
|
|
@ -21,14 +22,30 @@ namespace GameCult.Brokkr
|
|||
[Key(9)] public string[] selectedObjectNames = Array.Empty<string>();
|
||||
[Key(10)] public int assetCount;
|
||||
[Key(11)] public string[] capabilities = Array.Empty<string>();
|
||||
[Key(12)] public BrokkrGameObjectSnapshot[] sceneObjects = Array.Empty<BrokkrGameObjectSnapshot>();
|
||||
[Key(13)] public BrokkrAssetSnapshot[] assets = Array.Empty<BrokkrAssetSnapshot>();
|
||||
[Key(12)] public ImmutableArray<BrokkrGameObjectSnapshot> sceneObjects = ImmutableArray<BrokkrGameObjectSnapshot>.Empty;
|
||||
[Key(13)] public ImmutableArray<BrokkrAssetSnapshot> assets = ImmutableArray<BrokkrAssetSnapshot>.Empty;
|
||||
[Key(14)] public bool isPlaying;
|
||||
[Key(15)] public bool isPaused;
|
||||
[Key(16)] public bool isCompiling;
|
||||
[Key(17)] public bool isUpdating;
|
||||
// False means the editor executes no agent commands: the operator has not enabled the sink.
|
||||
[Key(18)] public bool agentCommandsEnabled;
|
||||
|
||||
// The snapshot lists are whole values (ImmutableArray, no element ids): a store row from a writer that left
|
||||
// one nil decodes to a default array, which this refuses instead of letting a reader throw later.
|
||||
public void RefuseDefaultLists()
|
||||
{
|
||||
if (sceneObjects.IsDefault) throw new InvalidOperationException("Brokkr host snapshot sceneObjects is default, not a list.");
|
||||
if (assets.IsDefault) throw new InvalidOperationException("Brokkr host snapshot assets is default, not a list.");
|
||||
foreach (var sceneObject in sceneObjects)
|
||||
{
|
||||
if (sceneObject.components.IsDefault)
|
||||
throw new InvalidOperationException($"Brokkr host snapshot object '{sceneObject.path}' components is default, not a list.");
|
||||
foreach (var component in sceneObject.components)
|
||||
if (component.properties.IsDefault)
|
||||
throw new InvalidOperationException($"Brokkr host snapshot component '{component.typeName}' properties is default, not a list.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Written by the editor, into the store, when the operator enables the command sink. The token is also kept in
|
||||
|
|
@ -73,7 +90,7 @@ namespace GameCult.Brokkr
|
|||
[Key(6)] public int layer;
|
||||
[Key(7)] public int childCount;
|
||||
[Key(8)] public string parentId = "";
|
||||
[Key(9)] public BrokkrComponentSnapshot[] components = Array.Empty<BrokkrComponentSnapshot>();
|
||||
[Key(9)] public ImmutableArray<BrokkrComponentSnapshot> components = ImmutableArray<BrokkrComponentSnapshot>.Empty;
|
||||
[Key(10)] public string localPosition = "";
|
||||
[Key(11)] public string localEulerAngles = "";
|
||||
[Key(12)] public string localScale = "";
|
||||
|
|
@ -88,7 +105,7 @@ namespace GameCult.Brokkr
|
|||
[Key(1)] public string typeName = "";
|
||||
[Key(2)] public string assemblyQualifiedName = "";
|
||||
[Key(3)] public bool enabled;
|
||||
[Key(4)] public BrokkrSerializedPropertySnapshot[] properties = Array.Empty<BrokkrSerializedPropertySnapshot>();
|
||||
[Key(4)] public ImmutableArray<BrokkrSerializedPropertySnapshot> properties = ImmutableArray<BrokkrSerializedPropertySnapshot>.Empty;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
|
|||
Loading…
Reference in a new issue