From bf7dcfe235754587a68ce56e3a9fce22f63e04de Mon Sep 17 00:00:00 2001 From: Heimdall Date: Wed, 11 Nov 2026 17:35:16 +0000 Subject: [PATCH] Desk: the card is an opaque JsonElement, not a typed ForkCard CultLib is still changing gamecult.fork.card.v0 (raised_at). Bifrost reads and edits nothing in it, so it passes through with every key, number and key order. Co-Authored-By: Claude Sonnet 5.5 --- .../Features/Desk/DeskDocuments.cs | 34 +++---------------- tests/Bifrost.Web.Tests/DeskDocumentTests.cs | 21 +++++++++++- tests/Bifrost.Web.Tests/DeskScenarioTests.cs | 6 ++-- tests/Bifrost.Web.Tests/Support/DeskReplay.cs | 8 ++--- 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/Bifrost.Web/Features/Desk/DeskDocuments.cs b/src/Bifrost.Web/Features/Desk/DeskDocuments.cs index 915b3e4..3a8965d 100644 --- a/src/Bifrost.Web/Features/Desk/DeskDocuments.cs +++ b/src/Bifrost.Web/Features/Desk/DeskDocuments.cs @@ -6,7 +6,9 @@ namespace Bifrost.Web.Features.Desk; // The fork-desk documents Bifrost reads or writes, spelled as CultLib's contracts/cultnet/governance/fork-card.md // (commit de8a062a) spells them: snake_case keys, every key written (nil where absent), declared in the // contract's key order. Bifrost authors only DeskRefusal and DeskUnavailable. AnswerRequest is the client's body; -// ForkCard, DeskAnswerDocument and AnswerResult are Huginn's documents, typed here so they pass through unchanged. +// DeskAnswerDocument, ForkList and AnswerResult are Huginn's documents, typed here so they pass through unchanged. +// The card (gamecult.fork.card.v0) is deliberately NOT typed: its shape is still moving in CultLib (raised_at), and +// Bifrost neither reads nor edits it, so it is an opaque JsonElement that keeps every key, number and key order. public static class DeskSchemas { @@ -53,32 +55,6 @@ public sealed record DeskUnavailable( [property: JsonPropertyName("error")] string Error, [property: JsonPropertyName("retryAfterSeconds")] int? RetryAfterSeconds); -public sealed record ForkOption( - [property: JsonPropertyName("id")] string Id, - [property: JsonPropertyName("text")] string Text); - -public sealed record ForkRef( - [property: JsonPropertyName("kind")] string Kind, - [property: JsonPropertyName("id")] string Id); - -public sealed record ForkCard( - [property: JsonPropertyName("schemaVersion")] string SchemaVersion, - [property: JsonPropertyName("fork_id")] string ForkId, - [property: JsonPropertyName("title")] string Title, - [property: JsonPropertyName("context")] string Context, - [property: JsonPropertyName("options")] ForkOption[] Options, - [property: JsonPropertyName("recommendation")] string Recommendation, - [property: JsonPropertyName("depends")] string[] Depends, - [property: JsonPropertyName("leans")] string? Leans, - [property: JsonPropertyName("flag")] string? Flag, - [property: JsonPropertyName("raised_in")] ForkRef? RaisedIn, - [property: JsonPropertyName("deciders")] string[] Deciders, - [property: JsonPropertyName("status")] string Status, - [property: JsonPropertyName("ruling")] string? Ruling, - [property: JsonPropertyName("ruled_from")] string[] RuledFrom, - [property: JsonPropertyName("order")] long Order, - [property: JsonPropertyName("options_hash")] string OptionsHash); - // One stored answer: Counted, Revision, Retraction or Refused, told apart by Outcome and Code. public sealed record DeskAnswerDocument( [property: JsonPropertyName("schemaVersion")] string SchemaVersion, @@ -107,7 +83,7 @@ public sealed record ForkRecord( public sealed record ForkEntry( [property: JsonPropertyName("schemaVersion")] string SchemaVersion, - [property: JsonPropertyName("card")] ForkCard Card, + [property: JsonPropertyName("card")] JsonElement Card, [property: JsonPropertyName("record")] ForkRecord Record); public sealed record ForkList( @@ -122,7 +98,7 @@ public sealed record ForkList( public sealed record AnswerResult( [property: JsonPropertyName("schemaVersion")] string SchemaVersion, [property: JsonPropertyName("answer")] DeskAnswerDocument Answer, - [property: JsonPropertyName("card")] ForkCard? Card, + [property: JsonPropertyName("card")] JsonElement? Card, [property: JsonPropertyName("counted_answer_id")] string? CountedAnswerId); // The refusal codes Bifrost itself writes, each with its one status and message (vectors doorRefusals). diff --git a/tests/Bifrost.Web.Tests/DeskDocumentTests.cs b/tests/Bifrost.Web.Tests/DeskDocumentTests.cs index f97e3f6..da5f709 100644 --- a/tests/Bifrost.Web.Tests/DeskDocumentTests.cs +++ b/tests/Bifrost.Web.Tests/DeskDocumentTests.cs @@ -68,8 +68,27 @@ public sealed class DeskDocumentTests foreach (var row in rows) { var message = row["message"]!; - var card = message.Deserialize(DeskJson.Options)!; + var card = message.Deserialize(DeskJson.Options); Assert.True(DeskVectors.SameShape(message, Write(card)), (string)row["name"]!); } } + + // The card is opaque: whatever keys, in whatever order, with whatever numbers, leave as they came. + [Fact] + public void An_unknown_card_passes_through_byte_for_byte() + { + const string card = + "{\"order\":7,\"raised_at\":\"2026-11-11T09:00:00Z\",\"title\":\"It's \u00e9\",\"fork_id\":\"x:question:y\"," + + "\"future\":{\"z\":1.50,\"a\":[3,null,1e2],\"big\":12345678901234567890},\"options_hash\":\"ab\",\"leans\":null}"; + var entryJson = + "{\"schemaVersion\":\"gamecult.fork.entry.v0\",\"card\":" + card + + ",\"record\":{\"schemaVersion\":\"gamecult.fork.record.v0\",\"fork_id\":\"x:question:y\",\"options_hash\":\"ab\",\"counted_answer_id\":null,\"answers\":[]}}"; + + var entry = JsonSerializer.Deserialize(entryJson, DeskJson.Options)!; + var written = JsonSerializer.Serialize(entry, DeskJson.Options); + Assert.Equal(entryJson, written); + + var result = new AnswerResult(DeskSchemas.AnswerResult, null!, entry.Card, null); + Assert.Contains("\"card\":" + card + ",", JsonSerializer.Serialize(result, DeskJson.Options)); + } } diff --git a/tests/Bifrost.Web.Tests/DeskScenarioTests.cs b/tests/Bifrost.Web.Tests/DeskScenarioTests.cs index 9955bdb..dca4862 100644 --- a/tests/Bifrost.Web.Tests/DeskScenarioTests.cs +++ b/tests/Bifrost.Web.Tests/DeskScenarioTests.cs @@ -22,7 +22,7 @@ public sealed class DeskScenarioTests { using var factory = new DeskWebApplicationFactory(); var door = factory.Door; - door.Forks[(Socket, DeskReplay.ChatFork)] = DeskReplay.Entry(scenario["card"]!.Deserialize(DeskJson.Options)!); + door.Forks[(Socket, DeskReplay.ChatFork)] = DeskReplay.Entry(scenario["card"]!.Deserialize(DeskJson.Options)); var scenarioName = (string)scenario["name"]!; foreach (var step in scenario["steps"]!.AsArray().Select(s => s!.AsObject())) @@ -36,7 +36,7 @@ public sealed class DeskScenarioTests if (kind == "card") { - door.Forks[(Socket, DeskReplay.ChatFork)] = DeskReplay.Entry(step["card"]!.Deserialize(DeskJson.Options)!); + door.Forks[(Socket, DeskReplay.ChatFork)] = DeskReplay.Entry(step["card"]!.Deserialize(DeskJson.Options)); continue; } @@ -155,7 +155,7 @@ public sealed class DeskScenarioTests var answer = message["answer"]!.Deserialize(DeskJson.Options)!; var result = message.Deserialize(DeskJson.Options)!; factory.Door.Forks[(Socket, answer.ForkId)] = DeskReplay.Entry( - message["card"] is { } card ? card.Deserialize(DeskJson.Options)! : DeskReplay.Card(answer.ForkId)); + message["card"] is { } card ? card.Deserialize(DeskJson.Options) : DeskReplay.Card(answer.ForkId)); factory.Door.AnswerScript = (_, _, _) => new DeskAnswerOutcome.Answered(result with { Card = null }); await factory.EnsureAccountAsync(DeskWebApplicationFactory.Alice, true); diff --git a/tests/Bifrost.Web.Tests/Support/DeskReplay.cs b/tests/Bifrost.Web.Tests/Support/DeskReplay.cs index 92eba39..2d478e3 100644 --- a/tests/Bifrost.Web.Tests/Support/DeskReplay.cs +++ b/tests/Bifrost.Web.Tests/Support/DeskReplay.cs @@ -11,18 +11,18 @@ public static class DeskReplay private static JsonNode BaseCard => DeskVectors.Root["scenarios"]![0]!["card"]!; - public static ForkCard Card(string forkId, string title = "Slot mark consent") + public static JsonElement Card(string forkId, string title = "Slot mark consent") { var card = JsonNode.Parse(BaseCard.ToJsonString())!.AsObject(); card["fork_id"] = forkId; card["title"] = title; - return card.Deserialize(DeskJson.Options)!; + return card.Deserialize(DeskJson.Options); } - public static ForkEntry Entry(ForkCard card) => new( + public static ForkEntry Entry(JsonElement card) => new( "gamecult.fork.entry.v0", card, - new ForkRecord("gamecult.fork.record.v0", card.ForkId, card.OptionsHash, null, [])); + new ForkRecord("gamecult.fork.record.v0", card.GetProperty("fork_id").GetString()!, card.GetProperty("options_hash").GetString()!, null, [])); // Every fork the vectors say each Mind holds, on that Mind's socket. public static void HoldVectorForks(FakeDeskDoor door)