diff --git a/tests/GameCult.Caching.Tests/UniqueIndexVectorTests.cs b/tests/GameCult.Caching.Tests/UniqueIndexVectorTests.cs index cf47bfbe..3e499f0f 100644 --- a/tests/GameCult.Caching.Tests/UniqueIndexVectorTests.cs +++ b/tests/GameCult.Caching.Tests/UniqueIndexVectorTests.cs @@ -310,6 +310,12 @@ namespace GameCult.Caching.Tests EmittedDocumentTypes.Emit("UqVecPairIndex", "tests.uq_pair", "tests.uq_pair.v1", new EmittedDocumentTypes.Field[] { new("Sku", typeof(string), 0, Index: "Sku"), new("Alt", typeof(string), 1, Index: "Alt") }), "Alt"), + new("tests.uq_alias", + EmittedDocumentTypes.Emit("UqVecAliasRole", "tests.uq_alias", "tests.uq_alias.v1", + new EmittedDocumentTypes.Field[] { new("Sku", typeof(string), 0, Role: "Sku"), new("Alt", typeof(string), 1, Role: "alt") }), + EmittedDocumentTypes.Emit("UqVecAliasIndex", "tests.uq_alias", "tests.uq_alias.v1", + new EmittedDocumentTypes.Field[] { new("Sku", typeof(string), 0, Index: "Sku"), new("Alt", typeof(string), 1, Index: "alt") }), + "Alt"), Plain("Alpha", "tests.uq_alpha"), Plain("Beta", "tests.uq_beta"), }; @@ -326,6 +332,7 @@ namespace GameCult.Caching.Tests private const string Item = "tests.unique_item"; private const string Pair = "tests.uq_pair"; + private const string Alias = "tests.uq_alias"; private const string Alpha = "tests.uq_alpha"; private const string Beta = "tests.uq_beta"; @@ -340,18 +347,20 @@ namespace GameCult.Caching.Tests { new("b:1", Alpha, "P"), new("a:1", Beta, "P"), new("b:2", Alpha, "P"), new("a:2", Beta, "P") }; + private static readonly Rec[] AliasRecords = { new("item:a", Alias, "S", "X"), new("item:b", Alias, "S", "Y"), new("item:c", Alias, "T", "Y") }; private static readonly Rec[] RepullBefore = Items_(("item:a1", "A"), ("item:b1", "C")); private static readonly Rec[] RepullAfter = Items_(("item:a1", "A"), ("item:b1", "B"), ("item:b2", "B"), ("item:c1", "A")); private static readonly (string File, Rec[] Records)[] RefusalStores = { ("pair-store.cc", PairRecords), ("surrogate-store.cc", SurrogateRecords), ("types-store.cc", TypeRecords), - ("repull-before.cc", RepullBefore), ("repull-after.cc", RepullAfter), + ("repull-before.cc", RepullBefore), ("repull-after.cc", RepullAfter), ("alias-store.cc", AliasRecords), }; private static readonly Refusal SurrogateRefusal = new("k\U0001F600", "k\uE000", Item, "Sku"); private static readonly Refusal TypesRefusal = new("a:1", "a:2", Beta, "Sku"); private static readonly Refusal PairRefusal = new("item:b", "item:c", Pair, "Alt"); + private static readonly Refusal AliasRefusal = new("item:a", "item:b", Alias, "Sku"); private static readonly Refusal RepullRefusal = new("item:a1", "item:c1", Item, "Sku"); private static readonly Case[] Cases = @@ -373,6 +382,17 @@ namespace GameCult.Caching.Tests new("load-repull-after", new[] { Open("repull-after.cc") }, RepullRefusal), new("commit-onto-a-loaded-holder", new[] { Open("repull-before.cc"), Commit(Items_(("item:z", "A"))) }, new Refusal("item:a1", "item:z", Item, "Sku")), + // Rows 14-19 extend the spec's floor of 13: orderings a code-point, case-insensitive or culture compare would flip. + new("batch-key-case", new[] { Open(), Commit(Items_(("a", "S"), ("z", "S"), ("B", "T"), ("C", "T"))) }, + new Refusal("B", "C", Item, "Sku")), + new("batch-key-punctuation", new[] { Open(), Commit(Items_(("_", "S"), ("a", "S"), ("Z", "T"), ("b", "T"))) }, + new Refusal("Z", "b", Item, "Sku")), + new("batch-key-case-in-a-group", new[] { Open(), Commit(Items_(("a", "S"), ("B", "S"))) }, + new Refusal("B", "a", Item, "Sku")), + new("batch-surrogate-groups", new[] { Open(), Commit(Items_(("\uE000", "S"), ("\uE000b", "S"), ("\U0001F600", "T"), ("\U0001F600b", "T"))) }, + new Refusal("\U0001F600", "\U0001F600b", Item, "Sku")), + new("batch-alias-case", new[] { Open(), Commit(AliasRecords) }, AliasRefusal), + new("load-alias-case", new[] { Open("alias-store.cc") }, AliasRefusal), }; private static byte[] RefusalStoreBytes(Rec[] records) @@ -560,23 +580,7 @@ namespace GameCult.Caching.Tests } } - Assert.That(walked, Is.EqualTo(13)); - } - - // Not a vector row (the cross-runtime rows are fixed by the spec): keys order by code unit, so "B" precedes "a". - [Test] - public void RefusalOrdersKeysByCodeUnitNotByCase() - { - using var cache = CultCacheMessagePack.Create( - Path.Combine(Path.GetTempPath(), $"cultlib-uidxc-{Guid.NewGuid():N}.cc"), - new CultCacheOpenOptions { Registry = CultDocumentRegistry.ForTypes(new[] { ItemIndex }) }); - var refused = Assert.Throws(() => cache.Commit(batch => - { - foreach (var (key, sku) in new[] { ("a", "S"), ("z", "S"), ("B", "T"), ("C", "T") }) - batch.Upsert(ItemIndex, EmittedDocumentTypes.New(ItemIndex, ("Sku", sku), ("Category", "")), new CultRecordKey(key)); - }))!; - Assert.That(refused.Message, Is.EqualTo( - "Records B and C (tests.unique_item) both hold unique index 'Sku'; an index value names one record.")); + Assert.That(walked, Is.EqualTo(19)); } } } diff --git a/tests/vectors/unique-index/README.md b/tests/vectors/unique-index/README.md index 3717067c..8c706de2 100644 --- a/tests/vectors/unique-index/README.md +++ b/tests/vectors/unique-index/README.md @@ -18,10 +18,11 @@ reviewed commit. Other runtimes are held to the same canonical text and the same stored-at pinned to `2026-01-01T00:00:00Z`. Records `item:a` and `item:b` both hold Sku `S-1`; `item:c` holds Sku `" "` and `item:d` holds Sku `U+0085`. Written through a role Sku. - `blank-store.cc`: the same, only `item:c` and `item:d`. -- `pair-store.cc`, `surrogate-store.cc`, `types-store.cc`, `repull-before.cc`, `repull-after.cc`: single-file stores +- `pair-store.cc`, `surrogate-store.cc`, `types-store.cc`, `repull-before.cc`, `repull-after.cc`, `alias-store.cc`: single-file stores written like `duplicate-store.cc`, through roles, for the rows of `refusals.msgpack` that open or pull them. Schemas - `tests.unique_item`, `tests.uq_pair` (Sku and Alt both unique), `tests.uq_alpha` and `tests.uq_beta`, each slots - `[0: Sku string, 1: second string]`. + `tests.unique_item`, `tests.uq_pair` (Sku and Alt both unique), `tests.uq_alias` (Sku and `alt` both unique), + `tests.uq_alpha` and `tests.uq_beta`, each slots `[0: Sku string, 1: second string]`; schema ids are the schema name + plus `.v1` (`tests.unique_item.v1`, `tests.uq_pair.v1`, `tests.uq_alias.v1`, `tests.uq_alpha.v1`, `tests.uq_beta.v1`). - `outcomes.msgpack`: rows `[file, unique alias or nil, open|refused, k1 or nil, k2 or nil]`. Opening `file` with that alias a unique index (nil: a role, no unique alias) yields the verdict. A refusal reads, byte for byte, `Records and (tests.unique_item) both hold unique index ''; an index value names one record.` @@ -44,6 +45,17 @@ last succeeds and the last refuses with exactly the RULE text built from those f byte-identical. Schemas are those of the store files above; `second` is `Category` (plain) except in `tests.uq_pair`, where it is `Alt` (unique). -A runtime performs every row its API can perform and asserts the count it walked: C# and Rust 13; Python 12 (not -`batch-interleaved-types`: `put_envelopes` takes one type); TypeScript 7 (`held-then-landing` and the five load and -re-pull rows 8-13: no batch commit, `variants:idea:unique-index-runtimes.ts-batch-commit`). +The 13 rows of the spec are a floor; rows 14-19 extend it with orderings that a code-point, case-insensitive or +culture compare would flip. Rows, in file order: 1 batch-later-value-staged-first, 2 batch-surrogate-keys, 3 +batch-interleaved-types, 4 batch-two-aliases, 5 held-then-landing, 6 held-in-the-least-group, 7 swap-off-a-held-value, +8 load-two-aliases, 9 load-surrogate-keys, 10 load-interleaved-types, 11 repull-held-pair, 12 load-repull-after, 13 +commit-onto-a-loaded-holder, 14 batch-key-case (`B` before `a`), 15 batch-key-punctuation (`Z` before `_` before `a`), +16 batch-key-case-in-a-group, 17 batch-surrogate-groups (U+1F600 before U+E000, the reverse of code-point order), 18 +batch-alias-case (alias `Sku` before `alt`), 19 load-alias-case. + +A runtime performs every row its API can perform and asserts the count it walked: + +- C# and Rust: all 19. +- Python: 18, every row but 3 (`put_envelopes` takes one type). +- TypeScript: 8, rows 5, 8, 9, 10, 11, 12, 13 and 19 (no batch commit, so no row 1-4, 6, 7 or 14-18; + `variants:idea:unique-index-runtimes.ts-batch-commit`). diff --git a/tests/vectors/unique-index/alias-store.cc b/tests/vectors/unique-index/alias-store.cc new file mode 100644 index 00000000..3ea51ef5 Binary files /dev/null and b/tests/vectors/unique-index/alias-store.cc differ diff --git a/tests/vectors/unique-index/refusals.msgpack b/tests/vectors/unique-index/refusals.msgpack index 674664bc..6820a694 100644 Binary files a/tests/vectors/unique-index/refusals.msgpack and b/tests/vectors/unique-index/refusals.msgpack differ