From 53a2f8cbad9283107b947beae8de77e38ae7e062 Mon Sep 17 00:00:00 2001 From: Libby Date: Wed, 11 Nov 2026 23:17:17 +0000 Subject: [PATCH] Key-identity vector: row-11 key read from the refusal as a delimited token, memory same-type row, only schema conflicts count as refusals Co-Authored-By: Claude Sonnet 5.5 --- docs/write-ownership-map.md | 2 +- .../KeyIdentityVectorTests.cs | 29 ++++++++++++++---- tests/vectors/key-identity/README.md | 12 +++++--- tests/vectors/key-identity/catalog-store.cc | Bin 638 -> 639 bytes tests/vectors/key-identity/rows.msgpack | 2 +- tests/vectors/key-identity/run-store.cc | Bin 634 -> 635 bytes 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/docs/write-ownership-map.md b/docs/write-ownership-map.md index 6e3f0efc..e1f046cf 100644 --- a/docs/write-ownership-map.md +++ b/docs/write-ownership-map.md @@ -40,7 +40,7 @@ Probes: scratch tests in this worktree, removed. C# filtered runs on Starfire (o | P5 cache {A,B}: remove, then add in a second commit | C | n/a | n/a | n/a | | P6 N2 over an N1 record (undeclared name drift), cache {N2} / cacheless reg {N2} | C restamped / C restamped | not probed | not probed | C (cache) | -The C#-written probe the leaves are held to is `tests/vectors/key-identity` (11 rows: retype, foreign carry, key in two stores), walked by +The C#-written probe the leaves are held to is `tests/vectors/key-identity` (12 rows: retype, foreign carry, key in two stores), walked by `KeyIdentityVectorTests`; each leaf cut corrects its own column above. What this establishes: diff --git a/tests/GameCult.Caching.Tests/KeyIdentityVectorTests.cs b/tests/GameCult.Caching.Tests/KeyIdentityVectorTests.cs index a4153b9e..da5eeb3b 100644 --- a/tests/GameCult.Caching.Tests/KeyIdentityVectorTests.cs +++ b/tests/GameCult.Caching.Tests/KeyIdentityVectorTests.cs @@ -4,6 +4,7 @@ using System.Buffers; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using GameCult.Caching; using GameCult.Caching.MessagePack; using MessagePack; @@ -58,14 +59,15 @@ namespace GameCult.Caching.Tests new("foreign-key-delete-refused", A, new[] { Open("foreign-store.cc"), Delete("alpha", "k") }), new("foreign-claimed-by-a-later-registration", new[] { "alpha", "gamma" }, new[] { Open("foreign-store.cc") }), new("key-in-two-stores-refused", AB, new[] { Open("memory"), Attach("catalog-store.cc", "alpha"), Attach("run-store.cc", "beta") }), + new("same-type-replaces-memory-cache", A, new[] { Open("memory"), Put("alpha", "k", "a"), Put("alpha", "k", "b") }), }; // The stores C# writes: [file name, registered types, (type, key, text) records]. Never typed by a runtime. private static readonly (string File, string[] Registered, (string Type, string Key, string Text)[] Records)[] Stores = { ("foreign-store.cc", new[] { "alpha", "gamma" }, new[] { ("alpha", "j", "a"), ("gamma", "k", "g") }), - ("catalog-store.cc", new[] { "alpha" }, new[] { ("alpha", "k", "a") }), - ("run-store.cc", new[] { "beta" }, new[] { ("beta", "k", "b") }), + ("catalog-store.cc", new[] { "alpha" }, new[] { ("alpha", "qx", "a") }), + ("run-store.cc", new[] { "beta" }, new[] { ("beta", "qx", "b") }), }; private static CultDocumentRegistry RegistryOf(IEnumerable names) => CultDocumentRegistry.ForTypes(names.Select(name => Types[name]).ToArray()); @@ -102,6 +104,9 @@ namespace GameCult.Caching.Tests private static string Short(string schemaName) => Types.Single(pair => pair.Key == schemaName.Replace("tests.ki_", "")).Key; + // The key as a delimited token: not a piece of a longer word, schema name or path. + private static bool Delimited(string message, string key) => Regex.IsMatch(message, $@"(? $"{record.SchemaId}|{record.StoredAt}|{Convert.ToBase64String(record.Payload)}"; // Runs the ops and returns what the reference answers. Every op but the last must succeed; the last may refuse. @@ -154,7 +159,6 @@ namespace GameCult.Caching.Tests } catch (InvalidOperationException) when (shared.Length == 1) { - refusedKey = shared[0]; Assert.That(File.ReadAllBytes(attached), Is.EqualTo(VectorFiles.Committed(Vector, op.File!)), "a refused attach leaves the store as it was"); throw; } @@ -171,7 +175,8 @@ namespace GameCult.Caching.Tests throw new InvalidOperationException(op.Kind); } } - catch (Exception failure) when (i == row.Ops.Length - 1 && (failure is CultSchemaConflictException || failure is InvalidOperationException)) + catch (Exception failure) when (i == row.Ops.Length - 1 && + (failure is CultSchemaConflictException || (op.Kind == "attach" && failure is InvalidOperationException))) { refusal = failure; } @@ -183,8 +188,20 @@ namespace GameCult.Caching.Tests Assert.That(row.Ops[^1].Key, Is.EqualTo(conflict.RecordKey), $"{row.Label}: the refusal names the key written or removed"); } + if (refusal is InvalidOperationException && refusal is not CultSchemaConflictException) + { + // The key is read out of the refusal's own text, not taken from the row: the second-store refusal opens "Record is held by". + var named = Regex.Match(refusal.Message, @"^Record (\S+) is held by"); + Assert.That(named.Success, Is.True, $"{row.Label}: the refusal opens by naming a key: {refusal.Message}"); + refusedKey = named.Groups[1].Value; + var shared = Snapshot(VectorFiles.Committed(Vector, "run-store.cc")).Records.Select(record => record.Key).ToArray(); + Assert.That(shared, Does.Contain(refusedKey), $"{row.Label}: the key the refusal names is the shared one"); + Assert.That(Regex.Matches(refusal.Message, Regex.Escape(refusedKey)).Count, Is.EqualTo(Regex.Matches(refusal.Message, $@"(? new[] { Short(stored.Descriptor.SchemaName), stored.Key.Value, (string)EmittedDocumentTypes.Read(stored.Document, "Text")! }) @@ -348,7 +365,7 @@ namespace GameCult.Caching.Tests } Assert.That(failed, Is.Empty); - Assert.That(walked, Is.EqualTo(11), "rows walked"); + Assert.That(walked, Is.EqualTo(12), "rows walked"); } } } diff --git a/tests/vectors/key-identity/README.md b/tests/vectors/key-identity/README.md index f10e1fdb..a7d3ea53 100644 --- a/tests/vectors/key-identity/README.md +++ b/tests/vectors/key-identity/README.md @@ -20,16 +20,18 @@ Registering a type that declares its schema id claims it at the next load. - `tests.ki_beta`: `sha256:dee4b727cf2ee04e61ab635ff0c5f3dca7345a411dc5f1018e583ab16009cf94` - `tests.ki_gamma`: `sha256:fbc26e351e00c9e7185e8de171c7486aba707c229c949f0aae6b889288af5f6d` - `foreign-store.cc`: a single-file store, alpha `a` at key `j`, gamma `g` at key `k`, stored-at pinned to - `2026-01-01T00:00:00Z`. `catalog-store.cc`: alpha `a` at `k`. `run-store.cc`: beta `b` at `k` (row 11). + `2026-01-01T00:00:00Z`. `catalog-store.cc`: alpha `a` at `qx`. `run-store.cc`: beta `b` at `qx` (row 11). The row-11 key is `qx` because it must + occur in the refusal's message only as the key, never inside a schema name (`k` is inside `ki_alpha`). - `rows.msgpack`: an array of `[label, registered, ops, expect]`. - `registered`: the types the cache registers, a subset of `[alpha, beta, gamma]`. - `ops`, in order: `[open, file-or-nil-or-memory]` (a cache on a fresh copy of the vector file; nil is a fresh path with no file; the string `memory` is a cache with no store), `[attach, file, [home types]]` (route one more store, a fresh copy of the vector file, to those home types, and pull every store), `[reopen]` (dispose, then a new cache on the same path), `[put, type, key, text]`, `[delete, type, key]` (each one commit). - - `expect` is `[refusal, held, file, foreign, kept]`. Every op but the last succeeds; the last succeeds or refuses. + - `expect` is `[refusal, held, file, foreign, kept]`. Every op but the last succeeds; the last succeeds or refuses, and in the generator only a schema conflict (or, for an attach, an invalid-operation refusal) counts as a refusal: any other exception fails the run. `refusal` is nil or `[key]`: a typed schema-conflict refusal naming the key for a put or a delete (rows 1, 3, 5, 8, 9), - and for row 11 any refusal whose message names the key, the store file it was refused from left byte-identical. + and for row 11 any refusal (an invalid-operation error, not a schema conflict) whose message opens `Record is held by` and + contains the key only as a delimited token (not inside a schema name or other word); the key in `expect` is read out of that message, the store file it was refused from left byte-identical. `held` is the cache's records, sorted by type then key, as `[type, key, text]`. `file` is the store file's records after the ops, sorted by key, as `[key, schema name]`, nil for a cache with no store. `foreign` is the keys the cache lists as foreign, sorted. `kept` is the foreign keys whose stored record (schema id, stored-at, payload) after the ops equals the @@ -40,7 +42,7 @@ Registering a type that declares its schema id claims it at the next load. 1 retype-refused-held-in-file, 2 retype-by-remove-then-add, 3 retype-refused-memory-cache, 4 same-type-replaces, 5 retype-refused-after-reload, 6 foreign-loads, 7 foreign-kept-by-a-write, 8 foreign-key-write-refused, 9 foreign-key-delete-refused, 10 foreign-claimed-by-a-later-registration (registered `[alpha, gamma]`: row 6's store loads -with nothing foreign), 11 key-in-two-stores-refused. +with nothing foreign), 11 key-in-two-stores-refused, 12 same-type-replaces-memory-cache (a cache with no store replaces a same-type record: admitted). -Every runtime walks 11 rows and asserts the count; none is exempt (every row is single-record ops). A leaf never registers +Every runtime walks 12 rows and asserts the count; none is exempt (every row is single-record ops). A leaf never registers gamma in rows 6 and 8; only row 10 does. diff --git a/tests/vectors/key-identity/catalog-store.cc b/tests/vectors/key-identity/catalog-store.cc index 01c7dd2d3f0a947688dfbed6876360dac319db7c..4821af2580ae4409e3ac86cdd0466f93aafaa780 100644 GIT binary patch delta 15 Wcmeyz@}Fe`Hxu)s!ivefOoae2$OU8o delta 14 Vcmey*@{eT$Hxtvs?8$sgg#apX1myq# diff --git a/tests/vectors/key-identity/rows.msgpack b/tests/vectors/key-identity/rows.msgpack index 76363e86..056a9bac 100644 --- a/tests/vectors/key-identity/rows.msgpack +++ b/tests/vectors/key-identity/rows.msgpack @@ -1 +1 @@ -›”»retype-refused-held-in-file’¥alpha¤beta“’¤openÀ”£put¥alpha¡k¡a”£put¤beta¡k¡b•‘¡k‘“¥alpha¡k¡a‘’¡k®tests.ki_alpha��”¹retype-by-remove-then-add’¥alpha¤beta”’¤openÀ”£put¥alpha¡k¡a“¦delete¥alpha¡k”£put¤beta¡k¡b•À‘“¤beta¡k¡b‘’¡k­tests.ki_beta��”»retype-refused-memory-cache’¥alpha¤beta“’¤open¦memory”£put¥alpha¡k¡a”£put¤beta¡k¡b•‘¡k‘“¥alpha¡k¡aÀ��”²same-type-replaces‘¥alpha“’¤openÀ”£put¥alpha¡k¡a”£put¥alpha¡k¡b•À‘“¥alpha¡k¡b‘’¡k®tests.ki_alpha��”»retype-refused-after-reload’¥alpha¤beta”’¤openÀ”£put¥alpha¡k¡a‘¦reopen”£put¤beta¡k¡b•‘¡k‘“¥alpha¡k¡a‘’¡k®tests.ki_alpha��”­foreign-loads‘¥alpha‘’¤open°foreign-store.cc•À‘“¥alpha¡j¡a’’¡j®tests.ki_alpha’¡k®tests.ki_gamma‘¡k‘¡k”·foreign-kept-by-a-write‘¥alpha’’¤open°foreign-store.cc”£put¥alpha¡m¡m•À’“¥alpha¡j¡a“¥alpha¡m¡m“’¡j®tests.ki_alpha’¡k®tests.ki_gamma’¡m®tests.ki_alpha‘¡k‘¡k”¹foreign-key-write-refused‘¥alpha’’¤open°foreign-store.cc”£put¥alpha¡k¡x•‘¡k‘“¥alpha¡j¡a’’¡j®tests.ki_alpha’¡k®tests.ki_gamma‘¡k‘¡k”ºforeign-key-delete-refused‘¥alpha’’¤open°foreign-store.cc“¦delete¥alpha¡k•‘¡k‘“¥alpha¡j¡a’’¡j®tests.ki_alpha’¡k®tests.ki_gamma‘¡k‘¡k”Ù'foreign-claimed-by-a-later-registration’¥alpha¥gamma‘’¤open°foreign-store.cc•À’“¥alpha¡j¡a“¥gamma¡k¡g’’¡j®tests.ki_alpha’¡k®tests.ki_gamma��”¹key-in-two-stores-refused’¥alpha¤beta“’¤open¦memory“¦attach°catalog-store.cc‘¥alpha“¦attach¬run-store.cc‘¤beta•‘¡k‘“¥alpha¡k¡aÀ�� \ No newline at end of file +œ”»retype-refused-held-in-file’¥alpha¤beta“’¤openÀ”£put¥alpha¡k¡a”£put¤beta¡k¡b•‘¡k‘“¥alpha¡k¡a‘’¡k®tests.ki_alpha��”¹retype-by-remove-then-add’¥alpha¤beta”’¤openÀ”£put¥alpha¡k¡a“¦delete¥alpha¡k”£put¤beta¡k¡b•À‘“¤beta¡k¡b‘’¡k­tests.ki_beta��”»retype-refused-memory-cache’¥alpha¤beta“’¤open¦memory”£put¥alpha¡k¡a”£put¤beta¡k¡b•‘¡k‘“¥alpha¡k¡aÀ��”²same-type-replaces‘¥alpha“’¤openÀ”£put¥alpha¡k¡a”£put¥alpha¡k¡b•À‘“¥alpha¡k¡b‘’¡k®tests.ki_alpha��”»retype-refused-after-reload’¥alpha¤beta”’¤openÀ”£put¥alpha¡k¡a‘¦reopen”£put¤beta¡k¡b•‘¡k‘“¥alpha¡k¡a‘’¡k®tests.ki_alpha��”­foreign-loads‘¥alpha‘’¤open°foreign-store.cc•À‘“¥alpha¡j¡a’’¡j®tests.ki_alpha’¡k®tests.ki_gamma‘¡k‘¡k”·foreign-kept-by-a-write‘¥alpha’’¤open°foreign-store.cc”£put¥alpha¡m¡m•À’“¥alpha¡j¡a“¥alpha¡m¡m“’¡j®tests.ki_alpha’¡k®tests.ki_gamma’¡m®tests.ki_alpha‘¡k‘¡k”¹foreign-key-write-refused‘¥alpha’’¤open°foreign-store.cc”£put¥alpha¡k¡x•‘¡k‘“¥alpha¡j¡a’’¡j®tests.ki_alpha’¡k®tests.ki_gamma‘¡k‘¡k”ºforeign-key-delete-refused‘¥alpha’’¤open°foreign-store.cc“¦delete¥alpha¡k•‘¡k‘“¥alpha¡j¡a’’¡j®tests.ki_alpha’¡k®tests.ki_gamma‘¡k‘¡k”Ù'foreign-claimed-by-a-later-registration’¥alpha¥gamma‘’¤open°foreign-store.cc•À’“¥alpha¡j¡a“¥gamma¡k¡g’’¡j®tests.ki_alpha’¡k®tests.ki_gamma��”¹key-in-two-stores-refused’¥alpha¤beta“’¤open¦memory“¦attach°catalog-store.cc‘¥alpha“¦attach¬run-store.cc‘¤beta•‘¢qx‘“¥alpha¢qx¡aÀ��”¿same-type-replaces-memory-cache‘¥alpha“’¤open¦memory”£put¥alpha¡k¡a”£put¥alpha¡k¡b•À‘“¥alpha¡k¡bÀ�� \ No newline at end of file diff --git a/tests/vectors/key-identity/run-store.cc b/tests/vectors/key-identity/run-store.cc index 4f07ad6670043f3da1abba0f24323e26886fceac..9166ed095f3323f5c07993271aa166da070ef6f6 100644 GIT binary patch delta 19 bcmeyx@|$G?I}`Jw!ivcY89gTlF=+q*OgskC delta 18 acmey(@{45yI}_8w?8yrmJtqe