Fix batch 4 (R-X, S-4/S-10): the error schema matches the wire, and the validator refuses a keyword it does not implement
CultNetErrorMessage is a MessagePack-CSharp map-mode object, so every declared key is written on the wire, nil included - the same fact R-S already established for the raw document header. cultnet.error.schema.json was missing routingHint entirely and typed code/details as always-present non-null values; Soul's P7 found real bytes failing it on exactly this. routingHint, code and details are now `required`, with nullable types matching CultNetErrorMessage/CultNetErrorDetails. A new test decodes real bytes for all four refusal codes (selection_invalid, cursor_stale, cursor_invalid, reference_outside_target) against the schema. MiniJsonSchemaValidator: - implements minimum, maximum, maxLength and maxItems, which were declared in committed schemas (fieldPredicate's number pattern, selection.limit, ...) but silently never checked; - anchors `pattern` to a full match (Index==0 && Length==value.Length) instead of Regex.IsMatch's "search anywhere", so .NET's `$` (which, unlike ECMA-262's, matches immediately before one trailing newline even without RegexOptions.Multiline) can no longer let e.g. "5\n" pass a schema author wrote as "exactly one digit"; - refuses a schema node that uses a keyword this validator gives no constraint semantics to, instead of silently ignoring it. Running every committed contracts/cultnet/*.schema.json schema through this found 12 such uses, none reached by any existing test: `allOf`/`if`/`then`/`else` in cultnet.database-change-raw.schema.json, and `uniqueItems` (six places) plus one `anyOf` in the cultmesh.verse-catalog-*.schema.json pair. contentEncoding, $schema/$id/$defs/title/description/default and the x-cult-runtime-type vendor extension are treated as metadata with no constraint semantics to implement, not refused. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
b3a8f6d195
commit
b7d77b708d
3 changed files with 135 additions and 16 deletions
|
|
@ -161,5 +161,44 @@ namespace GameCult.Networking.Tests
|
|||
|
||||
Assert.That(errors, Is.Empty, string.Join("; ", errors));
|
||||
}
|
||||
|
||||
// R-X (docs/cultnet-selection-cut.md, fix batch 4): CultNetErrorMessage is a MessagePack-CSharp
|
||||
// map-mode object - routingHint/code/details are always written, nil included, the same as any
|
||||
// other declared key. Soul's P7 found the schema disagreed with the real bytes on exactly this:
|
||||
// routingHint undeclared, additionalProperties:false, and details.asOf/current typed as a plain
|
||||
// integer instead of ["integer","null"]. This decodes real bytes for all four refusal codes.
|
||||
[Test]
|
||||
public void ErrorMessage_SelectionInvalidRealBytes_MatchesItsSchema()
|
||||
{
|
||||
var ex = new CultNetSelectionInvalidException("schemas", null, "selection.schemas must be non-empty.");
|
||||
AssertErrorMatchesSchema(CultNetErrorMessage.ForSelectionInvalid(ex));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ErrorMessage_CursorStaleRealBytes_MatchesItsSchema()
|
||||
{
|
||||
var ex = new CultNetSelectionCursorException("cursor_stale", "stale", asOf: 3, current: 7);
|
||||
AssertErrorMatchesSchema(CultNetErrorMessage.ForCursor(ex));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ErrorMessage_CursorInvalidRealBytes_MatchesItsSchema()
|
||||
{
|
||||
var ex = new CultNetSelectionCursorException("cursor_invalid", "The cursor does not decode.");
|
||||
AssertErrorMatchesSchema(CultNetErrorMessage.ForCursor(ex));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ErrorMessage_ReferenceOutsideTargetRealBytes_MatchesItsSchema()
|
||||
{
|
||||
var ex = new CultNetSelectionReferenceOutsideTargetException("citer-schema", "citer-key", "Design", "outside-schema", "outside-key");
|
||||
AssertErrorMatchesSchema(CultNetErrorMessage.ForReferenceOutsideTarget(ex));
|
||||
}
|
||||
|
||||
private static void AssertErrorMatchesSchema(CultNetErrorMessage message)
|
||||
{
|
||||
var validator = new MiniJsonSchemaValidator(SchemaDir());
|
||||
validator.AssertValid(ToJson(message), "cultnet.error.schema.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue