A resolver that hands out MessagePack's own [Key] formatter exempts nothing: contract, CHANGELOG, README, test

Soul s3 exemption-bullet-overstates-resolver. AnExtraSlotPastTheWrittenCountStillMarks pins it:
RelayResolver hands out StandardResolver's formatter for Relayed, and its extra slot marks 2/1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Libby 2026-11-12 01:51:03 +00:00
commit b4d9a38d3d
5 changed files with 37 additions and 6 deletions

View file

@ -11,6 +11,7 @@ using MessagePack.Formatters;
[assembly: CultCacheFormatterResolver(typeof(UnionArmGuardTests.ListClaimResolver))]
[assembly: CultCacheFormatterResolver(typeof(UnionArmGuardTests.FbLaterClaimResolver))]
[assembly: CultCacheFormatterResolver(typeof(SlotReadOnlyTests.ResolvedBagResolver))]
[assembly: CultCacheFormatterResolver(typeof(SlotReadOnlyTests.RelayResolver))]
namespace GameCult.Caching.Tests
{

View file

@ -404,6 +404,21 @@ namespace GameCult.Caching.Tests
}
}
// A type an assembly resolver claims by handing out MessagePack's own [Key]-layout formatter: still measured.
[MessagePackObject]
public sealed class Relayed
{
[Key(0)] public string A = string.Empty;
}
public sealed class RelayResolver : IFormatterResolver
{
public static readonly IFormatterResolver Instance = new RelayResolver();
public IMessagePackFormatter<T>? GetFormatter<T>() =>
typeof(T) == typeof(Relayed) ? global::MessagePack.Resolvers.StandardResolver.Instance.GetFormatter<T>() : null;
}
// A [MessagePackObject] collection: MessagePack writes it as its items, not by [Key].
[MessagePackObject]
public class TagList : List<string> { }
@ -419,6 +434,7 @@ namespace GameCult.Caching.Tests
[Key(4)] public Bag? Bag;
[Key(5)] public ResolvedBag? Resolved;
[Key(6)] public TagList? Tags;
[Key(7)] public Relayed? Relayed;
}
private static readonly CultDocumentRegistry MeasuredRegistry = CultDocumentRegistry.ForTypes(new[] { typeof(MeasuredDoc) });
@ -483,6 +499,17 @@ namespace GameCult.Caching.Tests
path = Seed(MeasuredRegistry, typeof(MeasuredDoc), () => new MeasuredDoc { Name = "c" }, countedPayload, "counted.cc");
using (var cache = Open(path, MeasuredRegistry))
AssertSlotRefusal(() => cache.Commit(batch => batch.Remove(Marked)), "measured through its constructor", nameof(Counted), 2, 1);
// A resolver that hands out MessagePack's own [Key] formatter exempts nothing.
var relayedPayload = Emit((ref MessagePackWriter w) =>
{
w.WriteArrayHeader(8); w.Write("r");
for (var i = 0; i < 6; i++) w.WriteNil();
w.WriteArrayHeader(2); w.Write("a"); w.Write(Extra);
});
path = Seed(MeasuredRegistry, typeof(MeasuredDoc), () => new MeasuredDoc { Name = "c" }, relayedPayload, "relayed.cc");
using (var cache = Open(path, MeasuredRegistry))
AssertSlotRefusal(() => cache.Commit(batch => batch.Remove(Marked)), "relayed by a consumer resolver", nameof(Relayed), 2, 1);
}
// ---- a flatten writes its base chain's decoded view: refused when a record on the chain is not owned ----

View file

@ -59,8 +59,9 @@ An object's declared slots are the slots its type's own formatter writes for one
the highest key plus one); a reader derives them from the layout it writes, never from a list of public members.
Only a type the runtime writes by its own positional `[Key]` layout is checked. Exempt, as in the C# reference
(`cultlib-gaps:ruling:leaf-acceptance-follows-reference`): a type the runtime formats some other way (a
user codec or formatter, a hand-written serializer, a resolver ahead of the runtime's own, a collection type
written as its items), and a type no instance of which the runtime can write for measuring
user codec or formatter, a hand-written serializer, a resolver ahead of the runtime's own that supplies a layout
of its own, a collection type written as its items; a resolver that hands out the runtime's own positional
layout exempts nothing), and a type no instance of which the runtime can write for measuring
(`cultlib-gaps:ruling:slot-unmeasurable-type`). Neither is ever marked. No vector carries an exempt type: each
runtime pins its own exemption with its own fixture.
Only an array longer than that marks: a short array