Fix batch 3: R-N wire refusal codes, R-P one authorizer id, R-T removal/cites gaps
R-N: cultnet.error.v0 gains additive code/details fields (contracts/cultnet). CultNetErrorMessage grows ForSelectionInvalid/ForCursor/ForReferenceOutsideTarget factories; both C# servers (CultNetDatabaseServer for snapshot+live, CultNetDatabaseSubscriptionServer) use them at every existing catch site, plus two sites that previously let the exception escape uncaught instead of reaching the peer (CultNetDatabaseServer's v1 subscribe snapshot branch, CultNetDatabaseSubscriptionServer's Subscribe around CreateProjectedSnapshot). CultNetSelectionCursorException now carries AsOf/Current for cursor_stale. R-P: CultNetDatabaseSubscriptionServer.CreateMatchedRecord (the live fast path) authorized against descriptor.SchemaId; the snapshot path (CreateProjectedSnapshot) already authorized against the wire id. Both now call the same CultNetDocumentRegistry.WireSchemaId (made internal, was private) so one id reaches the authorizer on the snapshot, live and reconcile paths alike. R-T(a): CultNetSelectionEvaluator.MatchesSchemaKeysFields no longer reads a Removed change's (always-null) document against Fields - it matches on keys/schemas alone and treats a field predicate as unknown instead of throwing TryGetIndexValue(null). R-T(b): EnsureWithinDeclaredTarget no longer skips the out-of-target check when TargetType is null; it checks against every registered leaf (unconstrained is a real, checked target set, not a bypass). CultCache's ResolveReferenceTarget also now infers the target from a many reference's CultRecordRef<T> element when no explicit [CultReference(typeof(...))] is declared, which was the one remaining source of a null TargetType reaching that check on a real, testable path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
c606eb38f2
commit
66b5e60b43
7 changed files with 191 additions and 18 deletions
|
|
@ -91,6 +91,12 @@ namespace GameCult.Networking
|
|||
return false;
|
||||
if (selection.Fields == null)
|
||||
return true;
|
||||
// R-T(a): a removed change is evaluated without reading a document (there is none to read -
|
||||
// the row is gone). It matches on the selection's keys and schemas alone; a field predicate
|
||||
// cannot be tested against a value that no longer exists, so it counts as unknown rather
|
||||
// than excluding the row (or throwing TryGetIndexValue(null)).
|
||||
if (document == null)
|
||||
return true;
|
||||
|
||||
foreach (var field in selection.Fields)
|
||||
{
|
||||
|
|
@ -239,7 +245,11 @@ namespace GameCult.Networking
|
|||
if (cursor.Digest != CultNetSelectionCursor.ComputeDigest(selection))
|
||||
throw new CultNetSelectionCursorException("cursor_invalid", "The cursor's selection digest does not match this selection.");
|
||||
if (cursor.AsOf != asOf)
|
||||
throw new CultNetSelectionCursorException("cursor_stale", $"The cursor was minted at asOf {cursor.AsOf}; this server answers as of {asOf}.");
|
||||
throw new CultNetSelectionCursorException(
|
||||
"cursor_stale",
|
||||
$"The cursor was minted at asOf {cursor.AsOf}; this server answers as of {asOf}.",
|
||||
asOf: cursor.AsOf,
|
||||
current: asOf);
|
||||
startIndex = FindCursorPosition(ordered, cursor, selection.Descending);
|
||||
}
|
||||
|
||||
|
|
@ -305,10 +315,14 @@ namespace GameCult.Networking
|
|||
|
||||
// D9: a reference's target set is every registered leaf assignable to its declared target type.
|
||||
// A stored edge naming a row whose schema is outside that set refuses the selection (S18).
|
||||
// R-T(b): this runs for every edge, including one whose member carries no declared target type
|
||||
// (CultDocumentRegistry.PersistedMember.TargetType is null only for a shape the cache could not
|
||||
// infer a target from - it no longer special-cases that away here without checking anything;
|
||||
// typeof(object) is every registered leaf, which is the correct target set for a genuinely
|
||||
// unconstrained reference and keeps this the one path, not a skip plus a duplicate path.
|
||||
private static void EnsureWithinDeclaredTarget(CultDocumentRegistry registry, Type? targetType, Row from, string role, Row to)
|
||||
{
|
||||
if (targetType == null) return;
|
||||
var leaves = registry.ResolveTargetLeaves(targetType);
|
||||
var leaves = registry.ResolveTargetLeaves(targetType ?? typeof(object));
|
||||
if (leaves.Any(leaf => leaf.SchemaId == to.Descriptor.SchemaId)) return;
|
||||
throw new CultNetSelectionReferenceOutsideTargetException(from.Descriptor.SchemaId, from.Key.Value, role, to.Descriptor.SchemaId, to.Key.Value);
|
||||
}
|
||||
|
|
@ -407,12 +421,21 @@ namespace GameCult.Networking
|
|||
/// <summary>The typed refusal for a cursor the server cannot answer (<c>cursor_stale</c>/<c>cursor_invalid</c>).</summary>
|
||||
public sealed class CultNetSelectionCursorException : Exception
|
||||
{
|
||||
public CultNetSelectionCursorException(string code, string message) : base(message)
|
||||
public CultNetSelectionCursorException(string code, string message, ulong? asOf = null, ulong? current = null)
|
||||
: base(message)
|
||||
{
|
||||
Code = code;
|
||||
AsOf = asOf;
|
||||
Current = current;
|
||||
}
|
||||
|
||||
public string Code { get; }
|
||||
|
||||
/// <summary>The cursor's own minted <c>asOf</c>. Carried on the wire only for <c>cursor_stale</c> (R-N).</summary>
|
||||
public ulong? AsOf { get; }
|
||||
|
||||
/// <summary>The answering server's current <c>asOf</c>. Carried on the wire only for <c>cursor_stale</c> (R-N).</summary>
|
||||
public ulong? Current { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue