Desk: re-vendor Huginn desk fixtures at b299d6f7 (71 files, CultLib 3a51bbab subdirectory) and CultLib vectors at d3025d3c

Pins name the commits, the exact file list and each sha256; the verifier is proved to fail on a changed byte, an
extra file and a missing file, at both directory levels. The four golden request frames still reproduce. The
synthetic card-viewers and proposed non-decider fragments are gone: both reader views are now CultLib's own entry
bytes served through the door. Huginn's record-whole still has no answerer_count (its README says so), so the
fault test stays true and is re-pointed at it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Heimdall 2026-11-11 19:14:17 +00:00
commit a2c41b1f34
31 changed files with 1336 additions and 137 deletions

View file

@ -23,7 +23,7 @@
<ItemGroup>
<None Include="Fixtures\*.json" CopyToOutputDirectory="PreserveNewest" />
<None Include="Fixtures\*.cjs" CopyToOutputDirectory="PreserveNewest" />
<None Include="Fixtures\desk-feed\*" CopyToOutputDirectory="PreserveNewest" />
<None Include="Fixtures\desk-feed\**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>

View file

@ -2,29 +2,39 @@ using System.Security.Cryptography;
namespace Bifrost.Web.Tests;
// Huginn's desk-feed golden bytes, vendored byte for byte from
// crates/huginn-mind/tests/fixtures/desk-feed/ at Huginn commit 79d954c (docs/desk-feed-door.md is the contract).
// Huginn's desk-feed golden bytes, vendored byte for byte from crates/huginn-mind/tests/fixtures/desk-feed/ at Huginn
// main b299d6f7320cd0879c93d5cc1d1adb0dbed7339b (#58; docs/desk-feed-door.md is the contract): 71 files, the
// subdirectory cultlib-3a51bbab/ (twelve CultLib vectors, unedited) included. The pin is the exact file list and each
// sha256; a changed byte, an extra file or a missing file fails, and the verifier is proved to catch each.
// A silent re-vendor fails here: move the pin on purpose, with the contract and the door's tests.
public sealed class DeskFeedFixturePinTests
{
public const string HuginnCommit = "79d954c";
public const string HuginnCommit = "b299d6f7320cd0879c93d5cc1d1adb0dbed7339b";
public static readonly string Directory = Path.Combine(AppContext.BaseDirectory, "Fixtures", "desk-feed");
private static readonly Dictionary<string, string> Sha256 = new(StringComparer.Ordinal)
public static readonly IReadOnlyDictionary<string, string> Sha256 = new Dictionary<string, string>(StringComparer.Ordinal)
{
[".gitattributes"] = "171872d6445cb1ffef0263b613d1ac318a60398449831d4cc4f772f78a7ebcff",
["README.md"] = "441636e7b122289181ff999f2de51e8ca59fbab5782b7e05e1002bcca9657c48",
["card-viewers-decider.synthetic.payload.hex"] = "13e0d20ed4c07d638417a39237f17d96c5decd659be47b0d022d26712980ec15",
["card-viewers-decider.synthetic.payload.msgpack"] = "c5c2d9b1f4f08b0049227a9cb9deb850bc9a7a74acd7ad6c85b15d2433133dee",
["card-viewers-non-decider.synthetic.payload.hex"] = "e59938dff11230981bf51241d89091df76d2ca36b563f2a65dea58873844bf8c",
["card-viewers-non-decider.synthetic.payload.msgpack"] = "003fe7bb3ac93dc5cdf56fa1eca003f720d423fb1260778882ce5354729a1027",
["cultlib-3a51bbab/answer-counted.msgpack"] = "55d69ae3cc7ebbeeae7d501e8641640e115c3fb5aac399ea760588bca343b9e6",
["cultlib-3a51bbab/answer-refused-stale.msgpack"] = "3183bc9c483f4a625332cda11ef22a9c8560868a7728b77daa63a1960a3cd3d6",
["cultlib-3a51bbab/answer-retraction.msgpack"] = "89156f41ec3ea54f5d47bd3318913ff013785f4727916875be97785935cb7735",
["cultlib-3a51bbab/answer-revision.msgpack"] = "19d7289395ae68cbaf6de1c0a1ef6c843211b2caf9462e1d2268cd0883386315",
["cultlib-3a51bbab/answer-withheld-answerer.msgpack"] = "b66b4f921cdd374be04af3de34c59e254a5e542027ae8c57f196a3ea3406e427",
["cultlib-3a51bbab/card-operator-fork.msgpack"] = "56bfdb65ded60b562001d09d0b8da6e092900f404bf5f68f7084dff29bcc34f5",
["cultlib-3a51bbab/card-raised-at-nil.msgpack"] = "b81bb825790ffe03fabe63c3f8a61c36bd50ca268aa6dff67b5bcfad3957e58c",
["cultlib-3a51bbab/card-withheld-deciders.msgpack"] = "d13b9b77461cfdf78f943ef56c6aeab852ab6b6f0b355e26c5b361f99c79c7f7",
["cultlib-3a51bbab/entry-closed-with-ruling-and-a-refusal.msgpack"] = "f7859c7d04d338d6b1c634308b08ae58ae77b0ff459767859a5e40f0af2f16e5",
["cultlib-3a51bbab/entry-open-counted.msgpack"] = "b51f499e8dd0465cf5df9d68d8fccbe94dd1339fd3157969693dd0d4ecb2549b",
["cultlib-3a51bbab/entry-withheld-closed-with-ruling-and-a-refusal.msgpack"] = "daaa819bfa2612616826ef3217dfcf8d8d8cb71d86547d7106426c779134f827",
["cultlib-3a51bbab/entry-withheld-open-counted.msgpack"] = "62ccad7a9f41262d6e35d0247315d0bb75d1313b3c9dabe8a99d1aa1b844607f",
["cultlib-3a51bbab/README.md"] = "9262509aab2cb3c3dbdbb4994a959669685cac0fff0f927b790da769787cc42b",
["error.response.frame.bin"] = "fa03f44b82d7c4796f45dd36086a54342dc1de7e660a58cf3ddff4ff59d85a4c",
["error.response.frame.hex"] = "21c75b6e1d000ddc1a5455a9cc4d6c5b37bd1640c22e1055e96ff85bdff461bb",
["failure.response.frame.bin"] = "edc2277943334744d3057902800c25bbc913ff8ed336b4612f1a19772ec46dc9",
["failure.response.frame.hex"] = "b3c262ac506b51529e8063b2d38cc8c0047b431b75fe6ede1a91adebefd014d3",
["failure.response.payload.hex"] = "13ca85b5868451892746d2531833d394b66d25b5069cd0208169c5fcc94bf350",
["failure.response.payload.msgpack"] = "4bf7c80eb2d75b9559ab430757a98ebfd424745ed3fc1888d21bc6e41ed99403",
[".gitattributes"] = "171872d6445cb1ffef0263b613d1ac318a60398449831d4cc4f772f78a7ebcff",
["list-counts.request.frame.bin"] = "be338fc06f127f9c20f82952708ffe95f8b6b8de7c5098834eb8cb257893637f",
["list-counts.request.frame.hex"] = "496bbc58292a1d029361bd553eef2ccf786cfa6520b1a3ad97c831893c36cf50",
["list-counts.request.payload.hex"] = "5ec076a5d8006a0290ad269deffb2bfe45ac7ee8b6a11ea2d4968a6ac8603e4b",
@ -53,6 +63,11 @@ public sealed class DeskFeedFixturePinTests
["list-too-large.response.frame.hex"] = "aad762b1e1deea39330223eb9ea7ebd2bb0fdd3326e259383b90846c1310456f",
["list-too-large.response.payload.hex"] = "880ae2c51454a3d6b06d2e827e44b6990365d8cfa304b55e25eb898641117762",
["list-too-large.response.payload.msgpack"] = "710d145c1ded7e7d02343342becd61e4520da979580f13dbebe6f0eda5aabec6",
["README.md"] = "67158e6a566ad03e648c317d751ca59e6ea125daef56f60f5288bef1f8142ca1",
["read.request.frame.bin"] = "3a9bc16ce4ce706e8c839bf4cfe65d3e2fdf759992555e68be6fc7bcc15653ea",
["read.request.frame.hex"] = "3c3d9540c4af789d230b7108f98d5d5f3dd9b291ff618064ddc374eb2a7bb082",
["read.request.payload.hex"] = "48aed263254eac7bc156c1af1f2ee210a08dda2b453a5be2dc17083ab73800b2",
["read.request.payload.msgpack"] = "c5447f462247703af4329e071bc0ac14dce1cb94a63c85517400791d022263ca",
["read-too-large.response.frame.bin"] = "5995c03914851ea95aaff4b75fa3ebaee4f19a2c7ce101eab85b7475515690bd",
["read-too-large.response.frame.hex"] = "b150aa192bf3fa415b5175f8b9f43731c5b73c2a2153c87da2dc3a4b6d986ee2",
["read-too-large.response.payload.hex"] = "18b7ad6c617ee1d9a3aa726a012e9a3af8ca9c14b8af774d082cf17879c85b90",
@ -61,14 +76,8 @@ public sealed class DeskFeedFixturePinTests
["read-unknown.response.frame.hex"] = "97ab11a04a2d62917186b23666ed26ef09df220ffb1c3e188d919985085733e2",
["read-unknown.response.payload.hex"] = "ca8d4d1fa4d40915b6e062767967e62343b360ce669801da96d99509e24787fb",
["read-unknown.response.payload.msgpack"] = "0d4fe47159db88b5048bc1f42a0e72857b568eac48572777a0c896ee94f7c208",
["read.request.frame.bin"] = "3a9bc16ce4ce706e8c839bf4cfe65d3e2fdf759992555e68be6fc7bcc15653ea",
["read.request.frame.hex"] = "3c3d9540c4af789d230b7108f98d5d5f3dd9b291ff618064ddc374eb2a7bb082",
["read.request.payload.hex"] = "48aed263254eac7bc156c1af1f2ee210a08dda2b453a5be2dc17083ab73800b2",
["read.request.payload.msgpack"] = "c5447f462247703af4329e071bc0ac14dce1cb94a63c85517400791d022263ca",
["record-non-decider.proposed.payload.hex"] = "15350e035612b380b55811c90b218afb7444214a2965deae35076aabe78206e5",
["record-non-decider.proposed.payload.msgpack"] = "5095dfb375613a5f80a4471e1d5b68c77890b0732dc03cc11e52d9e769406afc",
["record-whole.payload.hex"] = "f70d1a81a4f1031c04d5e1750f9162afc859a7b4d5b4cacf3e562d60ac00f531",
["record-whole.payload.msgpack"] = "3ad3926b024fb76178cd68cbdab6a28da1ddef9a3aca6b66050488213145d496",
["record-whole.payload.hex"] = "bf2530550ff5d2a7bf5c650e9af9d73dc8bcd4e4328fdc797ae6167b9e3d1a25",
["record-whole.payload.msgpack"] = "07f2687e9e9f169dded3e61c645fcd6d0a766f64a2b9d469eabb7ae98c6e254f",
["refused-unit.response.frame.bin"] = "4f86943a6947dd3c6041ee7d1b52d3f73697604dd224ca5dcf5b66064b0de1f1",
["refused-unit.response.frame.hex"] = "f25f35911d242d6fdb7ac4e1ecb3fe01901aa4b816d957104bde6f21b29a1bed",
["refused-unit.response.payload.hex"] = "858d49c8c66ce1b9c32160e2aecb320a8c00166728c80f5a02d62ec90b4f410d",
@ -79,19 +88,85 @@ public sealed class DeskFeedFixturePinTests
["unavailable.response.payload.msgpack"] = "dfa613abaf5f23e6aff5bcb0a59b3a1784f2fbf6d12cbdfa82f10e80963f0a4e",
};
[Fact]
public void Fixtures_are_huginn_79d954c_byte_for_byte()
// Every way the directory differs from the pin, by relative path (forward slashes).
public static List<string> Problems(string directory)
{
var present = new DirectoryInfo(Directory).GetFiles().Select(f => f.Name).Order(StringComparer.Ordinal).ToArray();
Assert.Equal(Sha256.Keys.Order(StringComparer.Ordinal).ToArray(), present);
foreach (var (name, expected) in Sha256)
var present = new Dictionary<string, string>(StringComparer.Ordinal);
foreach (var file in new DirectoryInfo(directory).EnumerateFiles("*", SearchOption.AllDirectories))
{
var actual = Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(Path.Combine(Directory, name)))).ToLowerInvariant();
Assert.True(
expected == actual,
$"{name} is not Huginn {HuginnCommit}:crates/huginn-mind/tests/fixtures/desk-feed/{name} (sha256 {actual}). " +
"Re-vendor from that commit or move the pin on purpose.");
var name = Path.GetRelativePath(directory, file.FullName).Replace('\\', '/');
present[name] = Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(file.FullName))).ToLowerInvariant();
}
var problems = new List<string>();
problems.AddRange(Sha256.Keys.Except(present.Keys, StringComparer.Ordinal).Order(StringComparer.Ordinal).Select(n => $"missing: {n}"));
problems.AddRange(present.Keys.Except(Sha256.Keys, StringComparer.Ordinal).Order(StringComparer.Ordinal).Select(n => $"extra: {n}"));
problems.AddRange(Sha256.Where(p => present.TryGetValue(p.Key, out var actual) && actual != p.Value).Select(p => $"changed: {p.Key}"));
return problems;
}
[Fact]
public void Fixtures_are_huginn_b299d6f7_byte_for_byte()
{
Assert.Equal(71, Sha256.Count);
Assert.True(Problems(Directory).Count == 0,
$"not Huginn {HuginnCommit}:crates/huginn-mind/tests/fixtures/desk-feed/: {string.Join("; ", Problems(Directory))}. " +
"Re-vendor from that commit or move the pin on purpose.");
}
private static string Copy()
{
var copy = System.IO.Directory.CreateTempSubdirectory("pin").FullName;
foreach (var file in new DirectoryInfo(Directory).EnumerateFiles("*", SearchOption.AllDirectories))
{
var to = Path.Combine(copy, Path.GetRelativePath(Directory, file.FullName));
System.IO.Directory.CreateDirectory(Path.GetDirectoryName(to)!);
file.CopyTo(to);
}
return copy;
}
[Theory]
[InlineData("list-open.request.frame.bin", "changed")]
[InlineData("cultlib-3a51bbab/entry-open-counted.msgpack", "changed")]
[InlineData("README.md", "changed")]
public void A_changed_byte_fails_the_pin(string name, string kind)
{
var copy = Copy();
try
{
var path = Path.Combine(copy, name);
var bytes = File.ReadAllBytes(path);
bytes[^1] ^= 1;
File.WriteAllBytes(path, bytes);
Assert.Equal([$"{kind}: {name}"], Problems(copy));
}
finally
{
System.IO.Directory.Delete(copy, true);
}
}
[Fact]
public void An_extra_or_missing_file_fails_the_pin_at_either_level()
{
var copy = Copy();
try
{
File.WriteAllText(Path.Combine(copy, "extra.hex"), "00\n");
File.WriteAllText(Path.Combine(copy, "cultlib-3a51bbab", "extra.msgpack"), "x");
File.Delete(Path.Combine(copy, "read.request.frame.hex"));
File.Delete(Path.Combine(copy, "cultlib-3a51bbab", "answer-counted.msgpack"));
Assert.Equal(
["missing: cultlib-3a51bbab/answer-counted.msgpack", "missing: read.request.frame.hex", "extra: cultlib-3a51bbab/extra.msgpack", "extra: extra.hex"],
Problems(copy));
}
finally
{
System.IO.Directory.Delete(copy, true);
}
}
}

View file

@ -102,7 +102,7 @@ public sealed class DeskReadTests
}
}
Assert.Equal(10, steps);
Assert.Equal(12, steps);
}
[Fact]

View file

@ -5,7 +5,7 @@ using Bifrost.Web.Tests.Support;
namespace Bifrost.Web.Tests;
// CultLib 3a51bbab's reader views, as Bifrost meets them: the 17-key card (raised_at, decider_count) stays opaque,
// CultLib d3025d3c's reader views (append-only on 3a51bbab), as Bifrost meets them: the 17-key card (raised_at, decider_count) stays opaque,
// the record is typed with answerer_count, and answerer is nil in a non-decider's view.
public sealed class DeskReaderViewTests
{
@ -43,6 +43,7 @@ public sealed class DeskReaderViewTests
public void The_options_hash_vectors_are_the_15_and_Bifrost_computes_no_hash()
{
Assert.Equal(15, DeskVectors.Array("optionsHash").Count);
Assert.Equal(9, DeskVectors.Array("bodyDigests").Count);
var directory = new DirectoryInfo(AppContext.BaseDirectory);
while (directory is not null && !Directory.Exists(Path.Combine(directory.FullName, "src", "Bifrost.Web", "Features", "Desk")))
{
@ -62,8 +63,10 @@ public sealed class DeskReaderViewTests
public void Stored_answers_round_trip_and_every_variant_carries_a_nil_answerer_with_the_key_written()
{
var rows = DeskVectors.Rows("deskAnswer", "valid").ToList();
Assert.Equal(6, rows.Count);
Assert.Equal(8, rows.Count);
Assert.Contains(rows, r => (string)r["name"]! == "withheld_answerer");
Assert.Contains(rows, r => (string)r["name"]! == "withheld_answerer_revision" && (string)r["message"]!["outcome"]! == "Revision");
Assert.Contains(rows, r => (string)r["name"]! == "withheld_answerer_retraction" && (string)r["message"]!["outcome"]! == "Retraction");
var outcomes = new HashSet<string>();
foreach (var row in rows)
{
@ -87,7 +90,7 @@ public sealed class DeskReaderViewTests
public void Entries_in_both_views_round_trip_and_the_shape_faults_Bifrost_can_see_are_refused()
{
var valid = DeskVectors.Rows("transport", "entry", "valid").ToList();
Assert.Equal(6, valid.Count);
Assert.Equal(8, valid.Count);
foreach (var row in valid)
{
var message = row["message"]!;

View file

@ -6,8 +6,9 @@ namespace Bifrost.Web.Tests;
public sealed class DeskVectorPinTests
{
[Fact]
public void Vectors_are_cultlib_3a51bbab()
public void Vectors_are_cultlib_d3025d3c()
{
Assert.StartsWith("d3025d3c", DeskVectors.SourceCommit, StringComparison.Ordinal);
var sha = Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(DeskVectors.Path))).ToLowerInvariant();
Assert.True(

View file

@ -35,10 +35,10 @@ lands (see `docs/desk-feed-door.md`).
| `unavailable.response` | Huginn to Bifrost | `Refused` `Unavailable` (Bifrost: 503 for this Mind) |
| `failure.response` | Huginn to Bifrost | operation failure, `payloadSchema` `gamecult.cultnet.operation_failure.v1` (Bifrost: 503) |
| `error.response` | Huginn to Bifrost | CultNet `Error` message, no payload (Bifrost: 503) |
| `record-whole` | fragment | `gamecult.fork.record.v0` with a counted answer and a revision, answerer ids and notes whole: what the door sends today, and a decider's view |
| `record-non-decider.proposed` | fragment | PROPOSED non-decider record: every `answerer` nil, `answerer_count` 2. Needs CultLib change `cultlib-fork-card-reader-counts`; not Huginn output yet |
| `card-viewers-decider.synthetic` | fragment | SYNTHETIC: only `{deciders: [two ids], decider_count: 2}`. Not a card |
| `card-viewers-non-decider.synthetic` | fragment | SYNTHETIC: only `{deciders: [], decider_count: 2}`. Not a card |
| `record-whole` | fragment | `gamecult.fork.record.v0` with all four answer variants (Counted, Revision, Refused, Retraction) by three accounts, answerer ids and notes whole: what the door sends today (5 keys, no `answerer_count`) |
No case carries a card (`gamecult.fork.card.v0`). The card's bytes wait on CultLib's re-pinned card
vectors for `raised_at`, so no entry-bearing list page or read is pinned yet.
The reader-count shapes (`raised_at`, `decider_count`, `answerer_count`, nullable `answerer`) are
CultLib's own bytes, vendored unedited in `cultlib-3a51bbab/` (see its README for the pinned commit and
each vector). They are not Huginn's output: Huginn's types do not carry those shapes yet.
`cut-desk-feed-listing` and `cut-desk-feed-raised-at` replace them with entry-bearing fixtures the
encoders write, after decoding these bytes into the real types.

View file

@ -1 +0,0 @@
82a8646563696465727392d92435663063326231652d386134642d346333622d396537662d316132623363346435653666d92430623964376533612d366332312d346635382d613064342d396538663761366235633464ad646563696465725f636f756e7402

View file

@ -1 +0,0 @@
‚¨deciders’Ù$5f0c2b1e-8a4d-4c3b-9e7f-1a2b3c4d5e6fÙ$0b9d7e3a-6c21-4f58-a0d4-9e8f7a6b5c4d­decider_count

View file

@ -1 +0,0 @@
82a8646563696465727390ad646563696465725f636f756e7402

View file

@ -1 +0,0 @@
‚¨deciders<EFBFBD>­decider_count

View file

@ -0,0 +1,26 @@
# CultLib desk-feed vectors, vendored
Source: `GameCult/CultLib` at commit `3a51bbabad244a56ec4521080530d88744001ce4` (#117, on
`af914253` #115), file `contracts/cultnet/governance/fork-card-vectors.json`. Each `.msgpack` file is
the vector's `messagePackHex` decoded to bytes, nothing else changed. Do not edit them or rewrite them
from Huginn's encoders: Huginn's own types do not carry these shapes yet (see
`docs/desk-feed-door.md`). To re-pin, take the new commit's vectors and update the sha here, in
`docs/desk-feed-door.md` and in `CULTLIB_SHA` in `desk_feed_fixtures.rs`.
| file | upstream vector | what it pins |
|---|---|---|
| `card-operator-fork` | `card.valid` `operator_fork` | 18 keys (`DE 00 12`), `raised_at` a string, a decider's `deciders` and `decider_count` 1 |
| `card-raised-at-nil` | `card.valid` `raised_at_nil` | `raised_at` nil, key kept |
| `card-withheld-deciders` | `card.valid` `withheld_deciders` | empty `deciders`, `decider_count` 2 |
| `answer-counted` | `deskAnswer.valid` `counted` | 16 keys (`DE 00 10`), `answerer` a string |
| `answer-revision` | `deskAnswer.valid` `revision` | a `Revision`, `answerer` a string (no CultLib vector nulls a Revision) |
| `answer-retraction` | `deskAnswer.valid` `retraction` | a `Retraction`, `answerer` a string (no CultLib vector nulls a Retraction) |
| `answer-withheld-answerer` | `deskAnswer.valid` `withheld_answerer` | `answerer` nil |
| `answer-refused-stale` | `deskAnswer.valid` `refused_stale` | a `Refused` answer, `answerer` a string |
| `entry-open-counted` | `transport.entry.valid` `open_counted` | decider view: entry `83`, record `86`, `answerer_count` 1 |
| `entry-withheld-open-counted` | `transport.entry.valid` `withheld_open_counted` | non-decider twin: `deciders` empty, `answerer` nil, count 1 |
| `entry-closed-with-ruling-and-a-refusal` | `transport.entry.valid` `closed_with_ruling_and_a_refusal` | decider view, a refusal among the answers, `answerer_count` 2 |
| `entry-withheld-closed-with-ruling-and-a-refusal` | `transport.entry.valid` `withheld_closed_with_ruling_and_a_refusal` | its non-decider twin, count 2 |
The test `desk_feed_fixtures.rs` checks each file's SHA-256, decodes it with a decoder of its own
(not `rmp_serde`), and then tries Huginn's real types.

View file

@ -1 +0,0 @@
86ad736368656d6156657273696f6eb767616d6563756c742e666f726b2e7265636f72642e7630a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438b1636f756e7465645f616e737765725f6964a26e31ae616e7377657265725f636f756e7402a7616e737765727392de0010ad736368656d6156657273696f6eb767616d6563756c742e6465736b5f616e737765722e7630a9616e737765725f6964a26e31a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479a76f7574636f6d65a7436f756e746564a26f66c0a87265747261637473c0a4636f6465c0ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438a663686f696365ab61736b696e672d6d696e64a46e6f7465be5468652061736b6572206c6973747320686572206f776e20666f726b732eab616e7377657265645f6174b4323032362d31312d31315431373a30303a30305aab72656365697665645f6174b4323032362d31312d31315431373a30303a30305aaf636c61696d5f696e5f667574757265c2a8616e737765726572c0a9617574686f72697479a64d656d626572aa726571756573745f6964d92430303030303030302d303030302d343030302d383030302d303030303030303030303031de0010ad736368656d6156657273696f6eb767616d6563756c742e6465736b5f616e737765722e7630a9616e737765725f6964a26e32a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479a76f7574636f6d65a85265766973696f6ea26f66a26e31a87265747261637473c0a4636f6465c0ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438a663686f696365ab61736b696e672d6d696e64a46e6f7465a74167726565642eab616e7377657265645f6174b4323032362d31312d31315431373a30353a30305aab72656365697665645f6174b4323032362d31312d31315431373a30353a30305aaf636c61696d5f696e5f667574757265c2a8616e737765726572c0a9617574686f72697479a64d656d626572aa726571756573745f6964d92430303030303030302d303030302d343030302d383030302d303030303030303030303032

View file

@ -1 +1 @@
85ad736368656d6156657273696f6eb767616d6563756c742e666f726b2e7265636f72642e7630a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438b1636f756e7465645f616e737765725f6964a26e31a7616e737765727392de0010ad736368656d6156657273696f6eb767616d6563756c742e6465736b5f616e737765722e7630a9616e737765725f6964a26e31a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479a76f7574636f6d65a7436f756e746564a26f66c0a87265747261637473c0a4636f6465c0ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438a663686f696365ab61736b696e672d6d696e64a46e6f7465be5468652061736b6572206c6973747320686572206f776e20666f726b732eab616e7377657265645f6174b4323032362d31312d31315431373a30303a30305aab72656365697665645f6174b4323032362d31312d31315431373a30303a30305aaf636c61696d5f696e5f667574757265c2a8616e737765726572d92435663063326231652d386134642d346333622d396537662d316132623363346435653666a9617574686f72697479a64d656d626572aa726571756573745f6964d92430303030303030302d303030302d343030302d383030302d303030303030303030303031de0010ad736368656d6156657273696f6eb767616d6563756c742e6465736b5f616e737765722e7630a9616e737765725f6964a26e32a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479a76f7574636f6d65a85265766973696f6ea26f66a26e31a87265747261637473c0a4636f6465c0ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438a663686f696365ab61736b696e672d6d696e64a46e6f7465a74167726565642eab616e7377657265645f6174b4323032362d31312d31315431373a30353a30305aab72656365697665645f6174b4323032362d31312d31315431373a30353a30305aaf636c61696d5f696e5f667574757265c2a8616e737765726572d92430623964376533612d366332312d346635382d613064342d396538663761366235633464a9617574686f72697479a64d656d626572aa726571756573745f6964d92430303030303030302d303030302d343030302d383030302d303030303030303030303032
85ad736368656d6156657273696f6eb767616d6563756c742e666f726b2e7265636f72642e7630a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438b1636f756e7465645f616e737765725f6964a26e31a7616e737765727394de0010ad736368656d6156657273696f6eb767616d6563756c742e6465736b5f616e737765722e7630a9616e737765725f6964a26e31a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479a76f7574636f6d65a7436f756e746564a26f66c0a87265747261637473c0a4636f6465c0ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438a663686f696365ab61736b696e672d6d696e64a46e6f7465be5468652061736b6572206c6973747320686572206f776e20666f726b732eab616e7377657265645f6174b4323032362d31312d31315431373a30303a30305aab72656365697665645f6174b4323032362d31312d31315431373a30303a30305aaf636c61696d5f696e5f667574757265c2a8616e737765726572d92435663063326231652d386134642d346333622d396537662d316132623363346435653666a9617574686f72697479a64d656d626572aa726571756573745f6964d92430303030303030302d303030302d343030302d383030302d303030303030303030303031de0010ad736368656d6156657273696f6eb767616d6563756c742e6465736b5f616e737765722e7630a9616e737765725f6964a26e32a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479a76f7574636f6d65a85265766973696f6ea26f66a26e31a87265747261637473c0a4636f6465c0ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438a663686f696365ab61736b696e672d6d696e64a46e6f7465a74167726565642eab616e7377657265645f6174b4323032362d31312d31315431373a30353a30305aab72656365697665645f6174b4323032362d31312d31315431373a30353a30305aaf636c61696d5f696e5f667574757265c2a8616e737765726572d92430623964376533612d366332312d346635382d613064342d396538663761366235633464a9617574686f72697479a64d656d626572aa726571756573745f6964d92430303030303030302d303030302d343030302d383030302d303030303030303030303032de0010ad736368656d6156657273696f6eb767616d6563756c742e6465736b5f616e737765722e7630a9616e737765725f6964a26e33a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479a76f7574636f6d65a752656675736564a26f66c0a87265747261637473c0a4636f6465ad6e6f745f615f64656369646572ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438a663686f696365ab61736b696e672d6d696e64a46e6f7465a74d6520746f6f2eab616e7377657265645f6174b4323032362d31312d31315431373a30363a30305aab72656365697665645f6174b4323032362d31312d31315431373a30363a30305aaf636c61696d5f696e5f667574757265c2a8616e737765726572d92463336131663265342d376236642d346538662d396130622d316332643365346635613662a9617574686f72697479a64d656d626572aa726571756573745f6964d92430303030303030302d303030302d343030302d383030302d303030303030303030303033de0010ad736368656d6156657273696f6eb767616d6563756c742e6465736b5f616e737765722e7630a9616e737765725f6964a26e34a7666f726b5f6964d930657572656b612d7375627374726174653a7175657374696f6e3a6465736b2d6c697374696e672d617574686f72697479a76f7574636f6d65aa52657472616374696f6ea26f66c0a87265747261637473a26e32a4636f6465c0ac6f7074696f6e735f68617368d94037643935666338376435333234323036313166653431356331646566323761333434373631376262363832333566343665336166313330616561333631633438a663686f696365c0a46e6f7465c0ab616e7377657265645f6174b4323032362d31312d31315431373a30373a30305aab72656365697665645f6174b4323032362d31312d31315431373a30373a30305aaf636c61696d5f696e5f667574757265c2a8616e737765726572d92430623964376533612d366332312d346635382d613064342d396538663761366235633464a9617574686f72697479a64d656d626572aa726571756573745f6964d92430303030303030302d303030302d343030302d383030302d303030303030303030303034

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,82 @@
using System.Buffers;
using System.Text.Json;
using System.Text.Json.Nodes;
using Bifrost.Web.Features.Desk;
using MessagePack;
namespace Bifrost.Web.Tests.Support;
// Serves a vector's own wire form (messagePackHex) through the real UnixSocketDeskDoor on a socket double: Huginn's
// externally tagged DeskResponse with the vector's bytes spliced in unchanged as the document.
public static class DeskServe
{
public static byte[] Hex(JsonNode? hex) => Convert.FromHexString((string)hex!);
// {variant: {key: <raw bytes>, ..., "as_of": asOf}}: the raw bytes ride as they are.
public static byte[] Variant(string variant, (string Key, byte[] Raw)[] fields, ulong asOf = 1)
{
var buffer = new ArrayBufferWriter<byte>();
var w = new MessagePackWriter(buffer);
w.WriteMapHeader(1);
w.Write(variant);
w.WriteMapHeader(fields.Length + 1);
foreach (var (key, raw) in fields)
{
w.Write(key);
w.WriteRaw(raw);
}
w.Write("as_of");
w.Write(asOf);
w.Flush();
return buffer.WrittenSpan.ToArray();
}
public static byte[] Str(string? value)
{
var buffer = new ArrayBufferWriter<byte>();
var w = new MessagePackWriter(buffer);
w.Write(value);
w.Flush();
return buffer.WrittenSpan.ToArray();
}
public static byte[] Forks(byte[] list) => Variant("Forks", [("list", list)]);
public static byte[] Fork(byte[] entry) => Variant("Fork", [("entry", entry)]);
public static byte[] Answered(byte[] answer, string? counted = null) =>
Variant("Answered", [("answer", answer), ("counted_answer_id", Str(counted))]);
// A socket that answers every request with these payload bytes, built into a frame from the request's id and operation.
public static FakeHuginnSocket Socket(byte[] payload, string status = "accepted") =>
new(FakeHuginnSocket.Build((id, operation) => DeskWire.ResponseFrame(id, operation, status, payload)));
private static readonly DeskDoorContext Context = new("gamecult-chat", "Member", "5f0c2b1e-8a4d-4c3b-9e7f-1a2b3c4d5e6f", ["5f0c2b1e-8a4d-4c3b-9e7f-1a2b3c4d5e6f"]);
public static async Task<ForkList> ListAsync(byte[] listBytes, string mind = "gamecult-chat")
{
using var huginn = Socket(Forks(listBytes));
var outcome = await new UnixSocketDeskDoor().ListAsync(huginn.Path, Context with { Mind = mind }, new DeskListRequest(mind, "open", null, 50), CancellationToken.None);
return Assert.IsType<DeskListOutcome.Listed>(outcome).List;
}
public static async Task<ForkEntry> ReadAsync(byte[] entryBytes)
{
using var huginn = Socket(Fork(entryBytes));
var outcome = await new UnixSocketDeskDoor().ReadAsync(huginn.Path, Context, "gamecult-chat:question:slot-mark-consent", CancellationToken.None);
return Assert.IsType<DeskReadOutcome.Found>(outcome).Entry;
}
public static async Task<DeskAnswerDocument> AnswerAsync(byte[] answerBytes)
{
using var huginn = Socket(Answered(answerBytes));
var outcome = await new UnixSocketDeskDoor().AnswerAsync(huginn.Path, Context, DeskReplay.AnswerBody(DeskReplay.ChatFork), CancellationToken.None);
return Assert.IsType<DeskAnswerOutcome.Answered>(outcome).Result.Answer;
}
// What leaves the door as JSON text, written the way the edge writes it.
public static string Text<T>(T value) => JsonSerializer.SerializeToNode(value, DeskJson.Options)!.ToJsonString(DeskJson.Options);
public static string Text(JsonNode node) => node.ToJsonString(DeskJson.Options);
}

View file

@ -3,12 +3,13 @@ using System.Text.Json.Nodes;
namespace Bifrost.Web.Tests.Support;
// CultLib's fork-card vectors, vendored at commit 3a51bbabad244a56ec4521080530d88744001ce4 (#117 on af914253 #115, the final card contract).
// CultLib's fork-card vectors, vendored at commit d3025d3c19674803ad32eb2335461b8cbc22bd28 (#118: append-only on 3a51bbab,
// card DE0012 and record 86 unchanged).
public static class DeskVectors
{
public const string SourceCommit = "3a51bbabad244a56ec4521080530d88744001ce4";
public const string SourceCommit = "d3025d3c19674803ad32eb2335461b8cbc22bd28";
public const string FileSha256 = "13afdcba1f45fd09eb433142c222d435b542cc891e0263df2da0c37ff522d39d";
public const string FileSha256 = "c2b215a81e6708855b2424f8383f1dff0f3877b7fc9264102ca61d302b00c24c";
public static string Path => System.IO.Path.Combine(AppContext.BaseDirectory, "Fixtures", "fork-card-vectors.json");

View file

@ -8,7 +8,7 @@ using Bifrost.Web.Tests.Support;
namespace Bifrost.Web.Tests;
// The production door against a real unix socket and Huginn's golden frames (fixtures at Huginn 79d954c).
// The production door against a real unix socket and Huginn's golden frames (fixtures at Huginn b299d6f7, vectors at CultLib d3025d3c).
public sealed class UnixSocketDeskDoorTests
{
private const string Fork = "eureka-substrate:question:desk-listing-authority";
@ -242,134 +242,168 @@ public sealed class UnixSocketDeskDoorTests
// ---- (c2) both reader views through the door and the edge ----
// Huginn's fragments at 79d954c, as JSON. record-whole is the decider's view as Huginn sent it before
// answerer_count existed; record-non-decider.proposed is a PROPOSED mirror type built in Huginn's test (the
// non-decider view, every answerer nil, answerer_count 2); card-viewers-*.synthetic are SYNTHETIC two-key
// fragments, not cards. Bifrost reads none of them as anything but what they are: a record, and two keys a card
// carries.
// What each piece of the fixtures directory is (its two READMEs):
// - record-whole is HUGINN's own encoder output at b299d6f7: gamecult.fork.record.v0 with all four answer variants
// by three accounts, notes and ids whole. It has 5 keys and NO answerer_count: what the door sends today.
// - cultlib-3a51bbab/*.msgpack are CULTLIB's bytes (twelve vectors pinned to 3a51bbab, each a vector's
// messagePackHex decoded), vendored unedited. They are NOT Huginn output; Huginn's types do not carry those
// shapes yet. Bifrost reads them as the contract (vectors file d3025d3c, append-only on 3a51bbab) spells them.
private static JsonObject Fragment(string name) =>
JsonNode.Parse(MessagePackSerializer.ConvertToJson(File.ReadAllBytes(
Path.Combine(DeskFeedFixturePinTests.Directory, name + ".payload.msgpack"))))!.AsObject();
// The decider's view as the CultLib 3a51bbab contract spells it: record-whole with answerer_count (the number of
// distinct ids over its two answers) in the contract's place, after counted_answer_id. Huginn's record-whole does
// not carry it yet.
private static JsonObject DeciderRecord()
private static byte[] CultLib(string name) =>
File.ReadAllBytes(Path.Combine(DeskFeedFixturePinTests.Directory, "cultlib-3a51bbab", name + ".msgpack"));
private static JsonObject CultLibJson(string name) => JsonNode.Parse(MessagePackSerializer.ConvertToJson(CultLib(name)))!.AsObject();
// file, vector section, vector name (the vector whose messagePackHex the file holds)
public static TheoryData<string, string, string> CultLibFiles() => new()
{
var whole = Fragment("record-whole");
var record = new JsonObject();
foreach (var (key, value) in whole.ToList())
{ "card-operator-fork", "card/valid", "operator_fork" },
{ "card-raised-at-nil", "card/valid", "raised_at_nil" },
{ "card-withheld-deciders", "card/valid", "withheld_deciders" },
{ "answer-counted", "deskAnswer/valid", "counted" },
{ "answer-revision", "deskAnswer/valid", "revision" },
{ "answer-retraction", "deskAnswer/valid", "retraction" },
{ "answer-withheld-answerer", "deskAnswer/valid", "withheld_answerer" },
{ "answer-refused-stale", "deskAnswer/valid", "refused_stale" },
{ "entry-open-counted", "transport/entry/valid", "open_counted" },
{ "entry-withheld-open-counted", "transport/entry/valid", "withheld_open_counted" },
{ "entry-closed-with-ruling-and-a-refusal", "transport/entry/valid", "closed_with_ruling_and_a_refusal" },
{ "entry-withheld-closed-with-ruling-and-a-refusal", "transport/entry/valid", "withheld_closed_with_ruling_and_a_refusal" },
};
[Theory]
[MemberData(nameof(CultLibFiles))]
public void Each_CultLib_file_is_its_vectors_wire_bytes_in_the_vendored_vectors_file(string file, string section, string name)
{
var vector = DeskVectors.Rows(section.Split('/')).Single(r => (string)r["name"]! == name);
Assert.Equal((string)vector["messagePackHex"]!, Convert.ToHexString(CultLib(file)), ignoreCase: true);
Assert.True(DeskVectors.SameShape(vector["message"], CultLibJson(file)), file);
}
[Fact]
public void The_CultLib_files_are_the_shapes_their_README_names()
{
// Card: 18 keys (DE 00 12), raised_at a string / nil with the key kept, deciders whole or withheld with the count.
Assert.Equal([0xde, 0x00, 0x12], CultLib("card-operator-fork")[..3]);
Assert.Equal(1, (int)CultLibJson("card-operator-fork")["decider_count"]!);
Assert.NotEmpty(CultLibJson("card-operator-fork")["deciders"]!.AsArray());
Assert.Equal(JsonValueKind.String, CultLibJson("card-operator-fork")["raised_at"]!.GetValueKind());
Assert.True(CultLibJson("card-raised-at-nil").ContainsKey("raised_at"));
Assert.Null(CultLibJson("card-raised-at-nil")["raised_at"]);
Assert.Empty(CultLibJson("card-withheld-deciders")["deciders"]!.AsArray());
Assert.Equal(2, (int)CultLibJson("card-withheld-deciders")["decider_count"]!);
// Answers: 16 keys (DE 00 10), answerer a string except the withheld one.
foreach (var answer in new[] { "answer-counted", "answer-revision", "answer-retraction", "answer-refused-stale", "answer-withheld-answerer" })
{
whole.Remove(key);
record[key] = value;
if (key == "counted_answer_id")
{
record["answerer_count"] = 2;
}
Assert.Equal([0xde, 0x00, 0x10], CultLib(answer)[..3]);
Assert.Equal(answer == "answer-withheld-answerer", CultLibJson(answer)["answerer"] is null);
}
return record;
// Entries: header 83, record header 86 with answerer_count the fifth key; the decider view names every answerer,
// its non-decider twin none, and the count is the same in both.
foreach (var (decider, withheld) in new[] { ("entry-open-counted", "entry-withheld-open-counted"), ("entry-closed-with-ruling-and-a-refusal", "entry-withheld-closed-with-ruling-and-a-refusal") })
{
Assert.Equal(0x83, CultLib(decider)[0]);
var (whole, hidden) = (CultLibJson(decider), CultLibJson(withheld));
Assert.Equal("answerer_count", whole["record"]!.AsObject().ElementAt(4).Key);
Assert.Equal(6, whole["record"]!.AsObject().Count);
Assert.NotEmpty(whole["card"]!["deciders"]!.AsArray());
Assert.All(whole["record"]!["answers"]!.AsArray(), a => Assert.NotNull(a!["answerer"]));
Assert.Empty(hidden["card"]!["deciders"]!.AsArray());
Assert.All(hidden["record"]!["answers"]!.AsArray(), a => Assert.Null(a!["answerer"]));
Assert.Equal((int)whole["record"]!["answerer_count"]!, (int)hidden["record"]!["answerer_count"]!);
Assert.Equal((int)whole["card"]!["decider_count"]!, (int)hidden["card"]!["decider_count"]!);
}
Assert.Equal(1, (int)CultLibJson("entry-open-counted")["record"]!["answerer_count"]!);
Assert.Equal(2, (int)CultLibJson("entry-closed-with-ruling-and-a-refusal")["record"]!["answerer_count"]!);
}
// The vector card with its two reader-view keys replaced by a fragment's, in the card's own key order.
private static string ViewCard(string fragment)
[Fact]
public void Every_account_id_in_record_whole_is_a_lowercase_D_format_uuid_and_the_record_is_what_the_README_says()
{
var card = JsonNode.Parse(DeskVectors.Rows("card", "valid").First(r => (string)r["name"]! == "operator_fork")["message"]!.ToJsonString())!.AsObject();
var view = Fragment(fragment);
card["fork_id"] = Fork;
card["deciders"] = view["deciders"]!.DeepClone();
card["decider_count"] = view["decider_count"]!.DeepClone();
return card.ToJsonString(DeskJson.Options);
var whole = Fragment("record-whole");
// Huginn's own record: 5 keys, no answerer_count (the README says so; the contract wants a sixth).
Assert.Equal(["schemaVersion", "fork_id", "options_hash", "counted_answer_id", "answers"], whole.Select(p => p.Key));
Assert.Equal(["Counted", "Revision", "Refused", "Retraction"], whole["answers"]!.AsArray().Select(a => (string)a!["outcome"]!).Distinct());
var grammar = new System.Text.RegularExpressions.Regex("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$");
var accounts = whole["answers"]!.AsArray().Select(a => (string)a!["answerer"]!).ToList();
Assert.All(accounts, id => Assert.Matches(grammar, id));
Assert.Equal(3, accounts.Distinct().Count());
}
private static string EntryOf(string card, JsonObject record) =>
$$$"""{"schemaVersion":"gamecult.fork.entry.v0","card":{{{card}}},"record":{{{record.ToJsonString(DeskJson.Options)}}}}""";
// A decider's entry and its non-decider twin, each served through the real door as a list page: the card (18 keys,
// raised_at, decider_count) and the record (answerer_count) leave exactly as CultLib wrote them.
[Theory]
[InlineData("entry-open-counted")]
[InlineData("entry-withheld-open-counted")]
[InlineData("entry-closed-with-ruling-and-a-refusal")]
[InlineData("entry-withheld-closed-with-ruling-and-a-refusal")]
public async Task A_CultLib_entry_in_either_view_comes_through_the_door_unchanged(string file)
{
var entry = CultLibJson(file);
using var huginn = new FakeHuginnSocket(FakeHuginnSocket.Answer((_, _) => ListOf(entry.ToJsonString(DeskJson.Options))));
var listed = Assert.IsType<DeskListOutcome.Listed>(await List(new UnixSocketDeskDoor(), huginn.Path));
var got = Assert.Single(listed.List.Forks);
Assert.Equal(DeskServe.Text(entry), DeskServe.Text(got));
var withheld = file.Contains("withheld", StringComparison.Ordinal);
Assert.Equal(withheld, got.Card.GetProperty("deciders").GetArrayLength() == 0);
Assert.All(got.Record.Answers, a => Assert.Equal(withheld, a.Answerer is null));
}
private static string ListOf(string entry, string mind = "eureka") =>
$$$"""{"Forks":{"list":{"schemaVersion":"gamecult.fork.list.v0","mind":"{{{mind}}}","stamp":"s7","open_count":1,"recorded_count":0,"forks":[{{{entry}}}],"next_cursor":null},"as_of":7}}""";
[Fact]
public void Every_account_id_in_the_fixtures_is_a_lowercase_D_format_uuid_and_the_non_decider_fragments_name_none()
public async Task A_decider_entry_keeps_its_ids_and_notes_and_a_non_decider_entry_has_nil_answerers_the_count_and_no_notes_through_the_edge()
{
var grammar = new System.Text.RegularExpressions.Regex("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$");
foreach (var id in Fragment("card-viewers-decider.synthetic")["deciders"]!.AsArray().Select(d => (string)d!)
.Concat(Fragment("record-whole")["answers"]!.AsArray().Select(a => (string)a!["answerer"]!)))
{
Assert.Matches(grammar, id);
}
var nonDeciderCard = Fragment("card-viewers-non-decider.synthetic");
Assert.Empty(nonDeciderCard["deciders"]!.AsArray());
Assert.Equal(2, (int)nonDeciderCard["decider_count"]!);
Assert.All(Fragment("record-non-decider.proposed")["answers"]!.AsArray(), a => Assert.Null(a!["answerer"]));
}
[Theory]
[InlineData("card-viewers-decider.synthetic")]
[InlineData("card-viewers-non-decider.synthetic")]
public async Task A_card_in_either_view_comes_through_the_door_byte_for_byte(string view)
{
var card = ViewCard(view);
var nonDecider = view.Contains("non-decider", StringComparison.Ordinal);
var record = nonDecider ? Fragment("record-non-decider.proposed") : DeciderRecord();
using var huginn = new FakeHuginnSocket(FakeHuginnSocket.Answer((_, _) => ListOf(EntryOf(card, record))));
var listed = Assert.IsType<DeskListOutcome.Listed>(await List(new UnixSocketDeskDoor(), huginn.Path));
var entry = Assert.Single(listed.List.Forks);
// The card is opaque: raised_at (a string), decider_count and the withheld or whole deciders leave as they came.
Assert.Equal(card, JsonSerializer.Serialize(entry.Card, DeskJson.Options));
Assert.Equal(nonDecider, entry.Card.GetProperty("deciders").GetArrayLength() == 0);
Assert.Equal(2, entry.Card.GetProperty("decider_count").GetInt32());
Assert.Equal(JsonValueKind.String, entry.Card.GetProperty("raised_at").ValueKind);
Assert.Equal(2, entry.Record.AnswererCount);
Assert.Equal(record.ToJsonString(DeskJson.Options), JsonSerializer.Serialize(entry.Record, DeskJson.Options));
Assert.All(entry.Record.Answers, a => Assert.Equal(nonDecider, a.Answerer is null));
}
[Fact]
public async Task A_decider_record_keeps_its_ids_and_a_non_decider_record_comes_through_with_nil_answerers_and_the_count()
{
var nonDecider = Fragment("record-non-decider.proposed");
using var huginn = new FakeHuginnSocket(FakeHuginnSocket.Answer((_, _) => ListOf(EntryOf(ViewCard("card-viewers-non-decider.synthetic"), nonDecider), "gamecult-chat")));
var withheld = CultLibJson("entry-withheld-closed-with-ruling-and-a-refusal");
using var huginn = new FakeHuginnSocket(FakeHuginnSocket.Answer((_, _) => ListOf(withheld.ToJsonString(DeskJson.Options), "gamecult-chat")));
using var factory = new DeskWebApplicationFactory(ConfigurationWith(huginn.Path, FakeHuginnSocket.Absent()), fakeDoor: false);
await factory.EnsureAccountAsync(DeskWebApplicationFactory.Member, true);
var reply = await factory.SendAsync("GET", "/api/desk/gamecult-chat/forks", token: factory.Token(DeskWebApplicationFactory.Member, "bifrost-desk", "desk.read"));
// Huginn withheld the ids; Bifrost invents none, and nils the notes (the one thing it strips).
Assert.Equal(200, reply.Status);
var forks = JsonNode.Parse(reply.Text)!["forks"]!.AsArray();
var record = forks[0]!["record"]!;
Assert.Equal(2, (int)record["answerer_count"]!);
Assert.All(record["answers"]!.AsArray(), a =>
var shown = JsonNode.Parse(reply.Text)!["forks"]![0]!;
Assert.Equal(2, (int)shown["record"]!["answerer_count"]!);
Assert.All(shown["record"]!["answers"]!.AsArray(), a =>
{
Assert.True(a!.AsObject().ContainsKey("answerer"));
Assert.Null(a["answerer"]);
Assert.Null(a["note"]);
});
Assert.Empty(forks[0]!["card"]!["deciders"]!.AsArray());
Assert.Equal(2, (int)forks[0]!["card"]!["decider_count"]!);
Assert.DoesNotContain("The asker lists her own forks.", reply.Text);
Assert.Empty(shown["card"]!["deciders"]!.AsArray());
Assert.Equal((int)withheld["card"]!["decider_count"]!, (int)shown["card"]!["decider_count"]!);
// The decider's view, as the contract spells it, keeps every id and every note.
var decider = DeciderRecord();
using var huginn2 = new FakeHuginnSocket(FakeHuginnSocket.Answer((_, _) => ListOf(EntryOf(ViewCard("card-viewers-decider.synthetic"), decider), "gamecult-chat")));
// The decider's view keeps every id and every note.
var decider = CultLibJson("entry-closed-with-ruling-and-a-refusal");
using var huginn2 = new FakeHuginnSocket(FakeHuginnSocket.Answer((_, _) => ListOf(decider.ToJsonString(DeskJson.Options), "gamecult-chat")));
using var factory2 = new DeskWebApplicationFactory(ConfigurationWith(huginn2.Path, FakeHuginnSocket.Absent()), fakeDoor: false);
await factory2.EnsureAccountAsync(DeskWebApplicationFactory.Alice, true);
var own = await factory2.SendAsync("GET", "/api/desk/gamecult-chat/forks", token: factory2.Token(DeskWebApplicationFactory.Alice, "bifrost-desk", "desk.read"));
Assert.Equal(200, own.Status);
var shown = JsonNode.Parse(own.Text)!["forks"]![0]!["record"]!;
Assert.Equal(decider.ToJsonString(DeskJson.Options), shown.ToJsonString(DeskJson.Options));
Assert.Equal(DeskServe.Text(decider), DeskServe.Text(JsonNode.Parse(own.Text)!["forks"]![0]!));
}
// Huginn's record-whole at 79d954c has no answerer_count, which the 3a51bbab contract requires. The door refuses it
// as a reply that does not decode; it does not write the 0 it could have made up. When Huginn's fixture gains the
// key this test is the one to retire.
// Huginn's record-whole at b299d6f7 still has no answerer_count, which the contract requires (the README says "what
// the door sends today"; the real types follow in cut-desk-feed-listing). The door refuses it as a reply that does
// not decode; it does not write the 0 it could have made up. When Huginn's record gains the key this test is the
// one to retire.
[Fact]
public async Task Huginns_record_without_answerer_count_is_a_fault_not_a_zero()
{
var entry = EntryOf(ViewCard("card-viewers-decider.synthetic"), Fragment("record-whole"));
var card = CultLibJson("entry-open-counted")["card"]!;
var entry = $$$"""{"schemaVersion":"gamecult.fork.entry.v0","card":{{{card.ToJsonString(DeskJson.Options)}}},"record":{{{Fragment("record-whole").ToJsonString(DeskJson.Options)}}}}""";
using var huginn = new FakeHuginnSocket(FakeHuginnSocket.Answer((_, _) => ListOf(entry)));
var failure = await Assert.ThrowsAsync<DeskDoorException>(() => List(new UnixSocketDeskDoor(), huginn.Path));