Fork card transport: the Mind id rides in the path; V14 asserted on every scenario
Routes are GET /api/desk/{mind}/forks, GET /api/desk/{mind}/forks/{fork_id}
and POST /api/desk/{mind}/answers with fork_id still in the body (Heimdall's
file 4.2 and 4.3a). Spec: the {mind} segment rules M1 to M5 (fixed configured
list, never joined into a path, unknown Mind is the unknown-fork refusal with
the same bytes, the route's Mind must hold the fork_id, scopes not per Mind,
the decider list is Bifrost-to-Huginn only, marked Bifrost/Huginn work).
Schema: read_request carries `mind`. Vectors: transport.mindRoutes (47 cases,
sameResponse pairs, the socket a judge would open), scenarios for a body that
names `mind` or `deciders` (body_unknown_field), read_request with the Mind.
Both judges replay them; both also assert on every scenario that a request id
bound by another account never returns that account's answer id or document
(V14), with `of` allowed to name the counted answer. Open choice 11: an
unreachable known Mind answers unavailable, an unknown one fork_unknown.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
acb4757f38
commit
c1c970a84b
6 changed files with 1204 additions and 17 deletions
|
|
@ -395,6 +395,30 @@ namespace GameCult.Networking.Tests
|
|||
return (responses, record);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ForkCard_ARequestIdBelongsToItsAccount_AnotherAccountsIdenticalBodyGetsItsOwnAnswerNeverTheFirstOutcome()
|
||||
{
|
||||
var crossed = 0;
|
||||
foreach (var sc in Fork["scenarios"]!.AsArray())
|
||||
{
|
||||
var first = new Dictionary<string, (string Answerer, JsonNode Result)>(); // request_id -> the account that first got a stored result and what it got
|
||||
foreach (var step in sc!["steps"]!.AsArray())
|
||||
{
|
||||
if (S(step!["kind"]) != "answer" || step["response"]?["answer"] is null) continue;
|
||||
var who = S(step["server"]!["answerer"]);
|
||||
var result = step["response"]!;
|
||||
Assert.That(S(result["answer"]!["answerer"]), Is.EqualTo(who), $"{S(sc["name"])}: a result is stamped with the account that asked");
|
||||
var rid = S(step["body"]!["request_id"]);
|
||||
if (!first.TryGetValue(rid, out var prior)) { first[rid] = (who, result); continue; }
|
||||
if (prior.Answerer == who) continue;
|
||||
crossed++;
|
||||
Assert.That(S(result["answer"]!["answer_id"]), Is.Not.EqualTo(S(prior.Result["answer"]!["answer_id"])), $"{S(sc["name"])}: its own answer id");
|
||||
Assert.That(JsonNode.DeepEquals(result, prior.Result), Is.False, $"{S(sc["name"])}: the first account's outcome is never returned");
|
||||
}
|
||||
}
|
||||
Assert.That(crossed, Is.GreaterThanOrEqualTo(3), "the vectors carry the cross-account cases");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ForkCard_EveryScenario_ReplaysToTheVectorsResponsesAndRecord_BytesIncluded()
|
||||
{
|
||||
|
|
@ -500,6 +524,50 @@ namespace GameCult.Networking.Tests
|
|||
return huginnDown ? "unavailable" : "ok";
|
||||
}
|
||||
|
||||
// The {mind} segment is decoded once and compared, ordinally, only with the configured list; nothing is opened from it (fork-card.md, "The {mind} segment").
|
||||
private static (string Code, string? Opened, string? StoredIn) MindRoute(JsonNode config, string route, string segment, string? fork, JsonNode? token)
|
||||
{
|
||||
var auth = AuthJudge(route, token, false);
|
||||
if (auth != "ok") return (auth, null, null);
|
||||
string mind;
|
||||
try { mind = Uri.UnescapeDataString(segment); } catch (UriFormatException) { return ("fork_unknown", null, null); }
|
||||
var minds = config["minds"]!.AsObject();
|
||||
if (!minds.TryGetPropertyValue(mind, out var socket)) return ("fork_unknown", null, null);
|
||||
if (route != "list" && !config["forks"]![mind]!.AsArray().Any(f => S(f) == fork)) return ("fork_unknown", S(socket), null);
|
||||
return ("ok", S(socket), route == "answer" ? mind : null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ForkTransport_MindSegment_IsOnlyComparedWithTheConfiguredList_AnUnknownMindIsTheUnknownForkRefusal()
|
||||
{
|
||||
var config = Fork["transport"]!["mindRoutes"]!;
|
||||
var refusals = Fork["doorRefusals"]!.AsArray().ToDictionary(r => S(r!["name"]), r => r!);
|
||||
var byName = new Dictionary<string, (string Code, string? Opened, string? StoredIn)>();
|
||||
foreach (var c in config["cases"]!.AsArray())
|
||||
{
|
||||
var got = MindRoute(config, S(c!["route"]), S(c["mind"]), c["fork_id"] is null ? null : S(c["fork_id"]), c["token"]);
|
||||
byName[S(c["name"])] = got;
|
||||
Assert.That(got.Code, Is.EqualTo(S(c["expect"])), S(c["name"]));
|
||||
Assert.That(got.Opened, Is.EqualTo(c["opened"] is null ? null : S(c["opened"])), $"{S(c["name"])}: the socket opened");
|
||||
Assert.That(got.StoredIn, Is.EqualTo(c["stored_in"] is null ? null : S(c["stored_in"])), $"{S(c["name"])}: where an answer was stored");
|
||||
Assert.That(c["httpStatus"]!.GetValue<int>(), Is.EqualTo(got.Code == "ok" ? 200 : refusals[got.Code]["httpStatus"]!.GetValue<int>()), S(c["name"]));
|
||||
if (got.Code == "fork_unknown")
|
||||
{
|
||||
var error = S(refusals["fork_unknown"]["message"]!["error"]);
|
||||
Assert.That(error.Contains(S(c["mind"])), Is.False, $"{S(c["name"])}: the refusal does not name the Mind");
|
||||
Assert.That(c["fork_id"] is not null && error.Contains(S(c["fork_id"])), Is.False, $"{S(c["name"])}: the refusal does not name the fork");
|
||||
}
|
||||
}
|
||||
foreach (var pair in config["sameResponse"]!.AsArray())
|
||||
{
|
||||
var a = byName[S(pair![0])]; var b = byName[S(pair[1])];
|
||||
Assert.That(a.Code, Is.EqualTo(b.Code));
|
||||
Assert.That(S(refusals[a.Code]["messagePackHex"]), Is.EqualTo(S(refusals[b.Code]["messagePackHex"])), $"{S(pair[0])} and {S(pair[1])} answer with the same bytes");
|
||||
}
|
||||
Assert.That(byName.Values.Count(v => v.Code == "fork_unknown" && v.Opened is null), Is.GreaterThanOrEqualTo(27), "every bad segment opens nothing");
|
||||
Assert.That(byName.Values.Where(v => v.StoredIn is not null).Select(v => v.StoredIn).Distinct().Count(), Is.EqualTo(2), "an answer is stored in the route's Mind only, and both Minds take one");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ForkTransport_RequestsAndEntriesValidateEncodeToTheVectorBytes_AndEveryNegativeIsRefused()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue