From 74469bdaa1dea67914e5d9fd23780362b320ae3b Mon Sep 17 00:00:00 2001 From: soul Date: Fri, 27 Nov 2026 23:05:04 +0100 Subject: [PATCH] CatalogResaveTests: a fixture written under the old schema, one probe type with the appended member Two same-named probe types in one assembly collide in every registry that scans it. Co-Authored-By: Claude Sonnet 5.5 --- .../CatalogResaveTests.cs | 66 ++++++------------ tests/fixtures/catalog-resave/probe-v1.cc | Bin 0 -> 744 bytes 2 files changed, 22 insertions(+), 44 deletions(-) create mode 100644 tests/fixtures/catalog-resave/probe-v1.cc diff --git a/tests/Aetheria.Shared.Tests/CatalogResaveTests.cs b/tests/Aetheria.Shared.Tests/CatalogResaveTests.cs index eca4524a0..df520f5fa 100644 --- a/tests/Aetheria.Shared.Tests/CatalogResaveTests.cs +++ b/tests/Aetheria.Shared.Tests/CatalogResaveTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using GameCult.Caching; @@ -8,91 +7,70 @@ using MessagePack; using Xunit; // AetherDb catalog resave (follow-up aetherdb-catalog-resave): a record stored under an older schema id is re-saved under the -// current one, a dry run writes nothing, and a second apply writes nothing. The two probe types share one schema name; the -// second appends a member, which is how a real schema change restamps a record. +// current one, a dry run writes nothing, and a second apply writes nothing. The fixture tests/fixtures/catalog-resave/probe-v1.cc +// holds two records of schema aetheria.test.resaveprobe as written by a type with one member; Probe appends a second, which is +// how a real schema change restamps a record. public sealed class CatalogResaveTests : IDisposable { [MessagePackObject] [CultDocument("aetheria.test.resaveprobe", "1")] - public sealed class ProbeV1 - { - [Key(0)] public string Name = ""; - } - - [MessagePackObject] - [CultDocument("aetheria.test.resaveprobe", "1")] - public sealed class ProbeV2 + public sealed class Probe { [Key(0)] public string Name = ""; [Key(1)] public int Appended = 7; } private readonly TempDirectory _directory = new TempDirectory(); - private string Path_ => System.IO.Path.Combine(_directory.Path, "probe.cc"); + private string Stored => System.IO.Path.Combine(_directory.Path, "probe.cc"); + + public CatalogResaveTests() => + File.Copy(System.IO.Path.Combine(RunStartTests.FindRepoRoot(), "tests", "fixtures", "catalog-resave", "probe-v1.cc"), Stored); public void Dispose() => _directory.Dispose(); - private static CultCache Open(string path, Type type) + private CultCache Open() { - var cache = new CultCache(CultDocumentRegistry.ForTypes(new[] { type })); - cache.AddBackingStore(new SingleFileMessagePackBackingStore(path), new[] { type }); + var cache = new CultCache(CultDocumentRegistry.ForTypes(new[] { typeof(Probe) })); + cache.AddBackingStore(new SingleFileMessagePackBackingStore(Stored), new[] { typeof(Probe) }); return cache; } - private void WriteOld() - { - using var cache = Open(Path_, typeof(ProbeV1)); - cache.Commit(batch => - { - batch.Upsert(typeof(ProbeV1), new ProbeV1 { Name = "a" }, new CultRecordKey("a")); - batch.Upsert(typeof(ProbeV1), new ProbeV1 { Name = "b" }, new CultRecordKey("b")); - }); - cache.FlushAsync().Wait(); - } - private string[] StoredIds() => - CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(Path_)).Records.Select(r => r.SchemaId).ToArray(); + CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(Stored)).Records.Select(r => r.SchemaId).ToArray(); [Fact] public void ADryRunListsAndWritesNothing() { - WriteOld(); - var before = File.ReadAllBytes(Path_); - var oldIds = StoredIds(); - using (var cache = Open(Path_, typeof(ProbeV2))) + var before = File.ReadAllBytes(Stored); + using (var cache = Open()) { var output = new StringWriter(); Assert.Equal(0, CatalogResaveCommand.Run(cache, apply: false, output)); Assert.Contains("2 record(s) would be re-saved", output.ToString()); } - Assert.Equal(before, File.ReadAllBytes(Path_)); - Assert.Equal(oldIds, StoredIds()); + Assert.Equal(before, File.ReadAllBytes(Stored)); } [Fact] public void ApplyRestampsEveryRecordAndASecondApplyWritesNothing() { - WriteOld(); var oldIds = StoredIds(); - string[] newIds; - using (var cache = Open(Path_, typeof(ProbeV2))) - { + using (var cache = Open()) Assert.Equal(0, CatalogResaveCommand.Run(cache, apply: true, new StringWriter())); - } - newIds = StoredIds(); + var newIds = StoredIds(); Assert.Equal(2, newIds.Length); Assert.All(newIds, id => Assert.DoesNotContain(id, oldIds)); - var written = File.ReadAllBytes(Path_); + var written = File.ReadAllBytes(Stored); - using (var cache = Open(Path_, typeof(ProbeV2))) + using (var cache = Open()) { - Assert.Equal(new[] { "a", "b" }, cache.GetAll().Select(p => p.Name).OrderBy(n => n)); - Assert.All(cache.GetAll(), p => Assert.Equal(7, p.Appended)); + Assert.Equal(new[] { "a", "b" }, cache.GetAll().Select(p => p.Name).OrderBy(n => n)); + Assert.All(cache.GetAll(), p => Assert.Equal(7, p.Appended)); var output = new StringWriter(); Assert.Equal(0, CatalogResaveCommand.Run(cache, apply: true, output)); Assert.Contains("0 record(s) would be re-saved", output.ToString()); } - Assert.Equal(written, File.ReadAllBytes(Path_)); + Assert.Equal(written, File.ReadAllBytes(Stored)); } // The catalog the game ships is current: resaving it changes nothing. diff --git a/tests/fixtures/catalog-resave/probe-v1.cc b/tests/fixtures/catalog-resave/probe-v1.cc new file mode 100644 index 0000000000000000000000000000000000000000..3c94bd6ada104a183aba6694cfa31c286dd81c50 GIT binary patch literal 744 zcmchUyH3L}6o!#_60%aFV<*04V`5{Vhy^hmJ0~`GCV?}%cs@&fyg-ZF*iup?KT4Cq$KW3I zz8-gRmc?32t&N4G*pHxQ9FhVCN%zirLk^NKIeH}zCq7V{4ntpehjFv^J5*6mor~QH z8&8pj-DG(P*dJ0Deo5CIH%(mZN;=(aYK+#8ihoc4Mmaw?pDy3$x1TV*S-E{>-+fCz zpFhqYFRo_zXP(6x2QD`l+u&-K^8)gMilx~h literal 0 HcmV?d00001