Thing contract: Slot node, arm 13, in Rust, C# and TypeScript (thing2:ruling:composition-slot-node) (#9)
All checks were successful
Portable Eve contracts and browser lowering / ubuntu-latest eve-browser-lowering (push) Successful in 2m37s
Portable Eve contracts and browser lowering / ubuntu-latest eve-contracts (push) Successful in 2m13s

This commit is contained in:
Eureka 2026-11-27 22:27:17 +00:00
commit e16a8eb917
23 changed files with 152 additions and 26 deletions

View file

@ -1,12 +1,14 @@
//! Thing Script: the closed node union, the surface document that holds a tree of nodes, and the
//! composition document that names a reusable subtree. Arm keys are fixed for v1.
//! composition document that names a reusable subtree. Arm keys are fixed: Slot (13) is the arm
//! added after the first twelve, and a decoder from before it refuses a record holding one
//! (CultCache's unknown-arm rule).
use cultcache_rs::{CultSlots, CultUnion, DatabaseEntry};
use crate::domain::{Count, Segment, Version};
use crate::command::{CommandDecl, CommandRef};
use crate::keys::{NodeId, ProviderId, composition_key, surface_key};
use crate::source::{Bind, BoolSource, CollectionSource, MemberPath, NumberSource, TextSource};
use crate::source::{Bind, BoolSource, CollectionSource, MemberPath, NumberSource, ParamName, TextSource};
use crate::style::{BoxStyle, Paint, Role};
/// What every node carries.
@ -48,6 +50,8 @@ pub enum Node {
Embed(EmbedNode),
#[cultcache(key = 12)]
Use(UseNode),
#[cultcache(key = 13)]
Slot(SlotNode),
}
#[derive(Clone, Debug, PartialEq, CultSlots)]
@ -321,6 +325,15 @@ pub struct UseNode {
pub args: Vec<Arg>,
}
/// Where a composition body places the nodes passed for its Slot parameter `param`. Only a child
/// list of a composition body holds one, and resolve refuses it elsewhere. It carries no
/// `NodeCommon`: the argument's nodes, keeping their caller-scope ids, replace it.
#[derive(Clone, Debug, PartialEq, CultSlots)]
pub struct SlotNode {
#[cultcache(key = 0)]
pub param: ParamName,
}
#[derive(Clone, Debug, PartialEq, CultSlots)]
pub struct Arg {
#[cultcache(key = 0)]

View file

@ -366,7 +366,10 @@ fn full_composition() -> CompositionDocument {
.into_iter()
.map(|(name, kind)| ParamDecl { name: name.into(), kind })
.collect(),
body: boxed("panel-root", vec![text("panel-title", "t"), inner_use]),
body: boxed(
"panel-root",
vec![text("panel-title", "t"), inner_use, Node::Slot(SlotNode { param: param("body") })],
),
}
}
@ -440,6 +443,14 @@ fn envelope<T: DatabaseEntry>(key: &str, payload: Vec<u8>) -> CultCacheEnvelope
}
}
#[test]
fn slot_arm_bytes() {
let slot = Node::Slot(SlotNode { param: param("body") });
let bytes = rmp_serde::to_vec(&slot).unwrap();
assert_eq!(bytes, [0x92, 0x0D, 0x91, 0x91, 0xA4, 0x62, 0x6F, 0x64, 0x79]);
assert_eq!(rmp_serde::from_slice::<Node>(&bytes).unwrap(), slot);
}
#[test]
fn goldens_match() {
let mut names = BTreeSet::new();
@ -518,10 +529,11 @@ fn refusal_payloads() -> Vec<(&'static str, Vec<u8>)> {
let root = text("root", "x");
vec![
("result-thing1-flat", rmp_serde::to_vec_named(&flat).unwrap()),
// A surface whose root is an arm key the Node union does not declare.
// A surface whose root is an arm key the Node union does not declare: 14 is the first key
// Node does not declare (Slot is 13).
(
"node-unknown-arm",
rmp_serde::to_vec(&("provider.a", "main", 1i64, CANARY, (13i32, (CANARY,)), unit)).unwrap(),
rmp_serde::to_vec(&("provider.a", "main", 1i64, CANARY, (14i32, (CANARY,)), unit)).unwrap(),
),
// A result whose outcome is an arm key the Outcome union does not declare.
("outcome-unknown-arm", rmp_serde::to_vec(&("inv-1", 1i32, (4i32, (CANARY,)))).unwrap()),
@ -588,7 +600,7 @@ fn refusal_cases() {
}
// Decoded directly, the refusal names the union and the arm key, and never the payload.
for (name, union, key) in [("node-unknown-arm", "Node", "13"), ("outcome-unknown-arm", "Outcome", "4")] {
for (name, union, key) in [("node-unknown-arm", "Node", "14"), ("outcome-unknown-arm", "Outcome", "4")] {
let bytes = committed(name);
let message = if union == "Node" {
rmp_serde::from_slice::<SurfaceDocument>(&bytes).unwrap_err().to_string()

View file

@ -12,8 +12,8 @@ when absent. Arm keys are fixed for v1.
| File | Kind | Decodes to |
|---|---|---|
| `surface-all-arms.bin` | `gamecult.thing.surface.v1` | One surface with all 13 node arms (Box 0, Text 1, Image 2, Button 3, Toggle 4, Slider 5, TextInput 6 as both input kinds, Text 0 and Number 1, Select 7, Repeat 8, Overlay 9, Plot 10, Embed 11, Use 12), a Box chain four levels deep, every text, number and bool source arm, every Format arm, both state sources, both member steps, every dimension and colour arm, and two declared commands |
| `composition-all-params.bin` | `gamecult.thing.composition.v1` | A composition with one parameter of each of the 7 kinds, whose body uses a composition with one argument of each of the 7 argument arms |
| `surface-all-arms.bin` | `gamecult.thing.surface.v1` | One surface with 13 of the 14 node arms (Box 0, Text 1, Image 2, Button 3, Toggle 4, Slider 5, TextInput 6 as both input kinds, Text 0 and Number 1, Select 7, Repeat 8, Overlay 9, Plot 10, Embed 11, Use 12; Slot 13 is in `composition-all-params`, a body being where a slot stands), a Box chain four levels deep, every text, number and bool source arm, every Format arm, both state sources, both member steps, every dimension and colour arm, and two declared commands |
| `composition-all-params.bin` | `gamecult.thing.composition.v1` | A composition with one parameter of each of the 7 kinds, whose body uses a composition with one argument of each of the 7 argument arms and places the body slot (Slot 13) last in its root's children |
| `invocation-all-inputs.bin` | `gamecult.thing.command_invocation.v1` | An invocation with a payload record of bin bytes and one captured input of each of the 4 input arms |
| `result-pending.bin` | `gamecult.thing.command_result.v1` | Outcome Pending, seq 1 |
| `result-completed.bin` | same | Outcome Completed with source version 8, drafts cleared, no effect |
@ -30,7 +30,7 @@ when absent. Arm keys are fixed for v1.
| File | Payload | Expected |
|---|---|---|
| `result-thing1-flat.bin` | a MessagePack map with named members, the shape a Thing 1 provider wrote for a command result | refused when stored as a command result; the error names the kind and the record key and never a value |
| `node-unknown-arm.bin` | a surface whose root node has arm key 13, which Node does not declare | refused; the error names the kind and the record key, and decoded directly it names the union Node and the key 13, and never a value |
| `node-unknown-arm.bin` | a surface whose root node has arm key 14, which Node does not declare | refused; the error names the kind and the record key, and decoded directly it names the union Node and the key 14, and never a value |
| `outcome-unknown-arm.bin` | a result whose outcome has arm key 4, which Outcome does not declare | refused in the same way, naming the union Outcome and the key 4 |
| `result-extra-slot.bin` | a Pending result with a fourth slot past the last one declared | read: it decodes to the Pending result with seq 1 (CultLib's extra-trailing-slots ruling: read, never written back) |
| `result-seq-zero.bin` | a result whose seq slot is 0 | refused; the error names the kind and the record key, decoded directly it names Seq, and never a value |

View file

@ -2384,9 +2384,9 @@ composition-all-params 3.6.0 76 81 REFUSE
composition-all-params 3.6.1 81 84 REFUSE
composition-all-params 3.6.1.0 82 83 REFUSE
composition-all-params 3.6.1.1 83 84 REFUSE
composition-all-params 4 84 812 REFUSE
composition-all-params 4 84 821 REFUSE
composition-all-params 4.0 85 86 REFUSE
composition-all-params 4.1 86 812 REFUSE
composition-all-params 4.1 86 821 REFUSE
composition-all-params 4.1.0 87 104 REFUSE
composition-all-params 4.1.0.0 88 99 REFUSE
composition-all-params 4.1.0.1 99 103 REFUSE
@ -2512,7 +2512,7 @@ composition-all-params 4.1.2.2 308 317 REFUSE
composition-all-params 4.1.3 317 320 REFUSE
composition-all-params 4.1.3.0 318 319 REFUSE
composition-all-params 4.1.3.1 319 320 REFUSE
composition-all-params 4.1.4 320 812 REFUSE
composition-all-params 4.1.4 320 821 REFUSE
composition-all-params 4.1.4.0 321 355 REFUSE
composition-all-params 4.1.4.0.0 322 323 REFUSE
composition-all-params 4.1.4.0.1 323 355 REFUSE
@ -2753,6 +2753,11 @@ composition-all-params 4.1.4.1.1.2.6.1.1.0.1.1.3 808 811 REFUSE
composition-all-params 4.1.4.1.1.2.6.1.1.0.1.1.3.0 809 810 REFUSE
composition-all-params 4.1.4.1.1.2.6.1.1.0.1.1.3.1 810 811 REFUSE
composition-all-params 4.1.4.1.1.2.6.1.1.0.1.1.4 811 812 REFUSE
composition-all-params 4.1.4.2 812 821 REFUSE
composition-all-params 4.1.4.2.0 813 814 REFUSE
composition-all-params 4.1.4.2.1 814 821 REFUSE
composition-all-params 4.1.4.2.1.0 815 821 REFUSE
composition-all-params 4.1.4.2.1.0.0 816 821 REFUSE
invocation-all-inputs 0 1 39 REFUSE
invocation-all-inputs 1 39 69 REFUSE
invocation-all-inputs 2 69 70 REFUSE

1 surface-all-arms 0 1 12 REFUSE
2384 composition-all-params 3.6.1 81 84 REFUSE
2385 composition-all-params 3.6.1.0 82 83 REFUSE
2386 composition-all-params 3.6.1.1 83 84 REFUSE
2387 composition-all-params 4 84 812 821 REFUSE
2388 composition-all-params 4.0 85 86 REFUSE
2389 composition-all-params 4.1 86 812 821 REFUSE
2390 composition-all-params 4.1.0 87 104 REFUSE
2391 composition-all-params 4.1.0.0 88 99 REFUSE
2392 composition-all-params 4.1.0.1 99 103 REFUSE
2512 composition-all-params 4.1.3 317 320 REFUSE
2513 composition-all-params 4.1.3.0 318 319 REFUSE
2514 composition-all-params 4.1.3.1 319 320 REFUSE
2515 composition-all-params 4.1.4 320 812 821 REFUSE
2516 composition-all-params 4.1.4.0 321 355 REFUSE
2517 composition-all-params 4.1.4.0.0 322 323 REFUSE
2518 composition-all-params 4.1.4.0.1 323 355 REFUSE
2753 composition-all-params 4.1.4.1.1.2.6.1.1.0.1.1.3.0 809 810 REFUSE
2754 composition-all-params 4.1.4.1.1.2.6.1.1.0.1.1.3.1 810 811 REFUSE
2755 composition-all-params 4.1.4.1.1.2.6.1.1.0.1.1.4 811 812 REFUSE
2756 composition-all-params 4.1.4.2 812 821 REFUSE
2757 composition-all-params 4.1.4.2.0 813 814 REFUSE
2758 composition-all-params 4.1.4.2.1 814 821 REFUSE
2759 composition-all-params 4.1.4.2.1.0 815 821 REFUSE
2760 composition-all-params 4.1.4.2.1.0.0 816 821 REFUSE
2761 invocation-all-inputs 0 1 39 REFUSE
2762 invocation-all-inputs 1 39 69 REFUSE
2763 invocation-all-inputs 2 69 70 REFUSE

View file

@ -1 +1 @@
–ªprovider.a¤main¯CANARY-7f3a91c2’ ‘¯CANARY-7f3a91c2<63>
–ªprovider.a¤main¯CANARY-7f3a91c2’‘¯CANARY-7f3a91c2<63>

View file

@ -222,9 +222,12 @@ fn arm(node: &Node) -> &'static str {
Node::Plot(_) => "Plot",
Node::Embed(_) => "Embed",
Node::Use(_) => "Use",
Node::Slot(_) => "Slot",
}
}
// The thirteen arms the fixtures place. Slot (arm 13) is not among them: a Slot stands only in a composition body,
// and placing one in f09 is resolve's cut, not the fixtures'.
const ALL_ARMS: [&str; 13] = [
"Box", "Button", "Embed", "Image", "Overlay", "Plot", "Repeat", "Select", "Slider", "Text", "TextInput", "Toggle",
"Use",

View file

@ -17,6 +17,7 @@ namespace GameCult.Thing.Contract;
[Union(10, typeof(PlotNode))]
[Union(11, typeof(EmbedNode))]
[Union(12, typeof(UseNode))]
[Union(13, typeof(SlotNode))]
public abstract class Node
{
internal Node() { }
@ -265,6 +266,22 @@ public sealed class UseNode : Node
}
}
/// <summary>
/// Where a composition body places the nodes passed for its Slot parameter <c>Param</c>. Only a child
/// list of a composition body holds one, and resolve refuses it elsewhere. It carries no
/// <see cref="NodeCommon"/>: the argument's nodes, keeping their caller-scope ids, replace it.
/// </summary>
[MessagePackObject]
public sealed class SlotNode : Node
{
[Key(0)] public ParamName Param { get; }
public SlotNode(ParamName param)
{
Param = ThingDomain.Present(param, "Param");
}
}
[Union(0, typeof(ImageFitContain))]
[Union(1, typeof(ImageFitCover))]
[Union(2, typeof(ImageFitFill))]

View file

@ -4,6 +4,21 @@ using MessagePack;
namespace GameCult.Thing.Contract;
/// <summary>
/// A parameter named, where Rust's ParamName is a field (<see cref="SlotNode.Param"/>). Where it is an
/// arm payload, the arm class (TextSourceParam and the rest) carries Name itself.
/// </summary>
[MessagePackObject]
public sealed class ParamName
{
[Key(0)] public string Name { get; }
public ParamName(string name)
{
Name = ThingDomain.Present(name, "Name");
}
}
[Union(0, typeof(TextLiteral))]
[Union(1, typeof(TextSourceBound))]
[Union(2, typeof(TextSourceParam))]

View file

@ -40,6 +40,7 @@ const readOnlyList = <TItem>(item: Codec<TItem>): Codec<TItem[]> => {
};
// source.rs
export const paramName = present(codecs.slots<T.ParamName>({ 0: ["name", text] }, named("ParamName")));
export const textSourceParam = present(codecs.slots<T.ParamName>({ 0: ["name", text] }, named("TextSourceParam")));
export const numberSourceParam = present(codecs.slots<T.ParamName>({ 0: ["name", text] }, named("NumberSourceParam")));
export const boolSourceParam = present(codecs.slots<T.ParamName>({ 0: ["name", text] }, named("BoolSourceParam")));
@ -461,6 +462,8 @@ export const useNode = present(codecs.slots<T.UseNode>(
named("UseNode"),
));
export const slotNode = present(codecs.slots<T.SlotNode>({ 0: ["param", paramName] }, named("SlotNode")));
const nodeUnion = present(
codecs.union<T.Node>(
"Node",
@ -478,6 +481,7 @@ const nodeUnion = present(
10: ["Plot", plotNode],
11: ["Embed", embedNode],
12: ["Use", useNode],
13: ["Slot", slotNode],
},
named("Node"),
),

View file

@ -198,7 +198,16 @@ export type Node =
| Arm<"Overlay", OverlayNode>
| Arm<"Plot", PlotNode>
| Arm<"Embed", EmbedNode>
| Arm<"Use", UseNode>;
| Arm<"Use", UseNode>
| Arm<"Slot", SlotNode>;
/**
* Where a composition body places the nodes passed for its Slot parameter `param`. Only a child list of a composition
* body holds one, and resolve refuses it elsewhere. It carries no NodeCommon: the argument's nodes, keeping their
* caller-scope ids, replace it.
*/
export interface SlotNode {
readonly param: ParamName;
}
export interface BoxNode {
readonly common: NodeCommon;
readonly style: BoxStyle;

View file

@ -450,7 +450,7 @@ export function fullComposition(): CompositionDocument {
{ name: "act", kind: { kind: "Command" } },
{ name: "body", kind: { kind: "Slot" } },
],
body: boxed("panel-root", [text("panel-title", "t"), innerUse]),
body: boxed("panel-root", [text("panel-title", "t"), innerUse, { kind: "Slot", param: { name: "body" } }]),
};
}

View file

@ -4,16 +4,17 @@ import assert from "node:assert/strict";
import { join } from "node:path";
import test from "node:test";
import { codecs } from "@gamecult/thing-contract";
import { decodeDocumentPayload, documentPayloadFromBytes } from "@gamecult/cultcache-ts";
import { codecs, compositionDocument, type Node } from "@gamecult/thing-contract";
import { nonEmptyLines, parityDir } from "./builders.js";
import { golden, nonEmptyLines, parityDir } from "./builders.js";
const entries = Object.entries(codecs) as [string, { typeName?: string; decode(raw: unknown): unknown }][];
const rustName = (key: string) => key[0].toUpperCase() + key.slice(1);
const names = new Set(nonEmptyLines(join(parityDir, "type-names.txt")));
test("the package exports one hundred and one codecs", () => {
assert.equal(entries.length, 101);
test("the package exports one hundred and three codecs", () => {
assert.equal(entries.length, 103);
});
test("every codec's type name is a type of the C# package", () => {
@ -40,3 +41,16 @@ test("every union refuses an unknown arm by its own name, and the twenty-nine un
}
assert.equal(unions.length, 29);
});
test("slot: a Slot is arm 13 holding a nested ParamName, and the composition golden places it last in the body root's children", () => {
const slot: Node = { kind: "Slot", param: { name: "body" } };
assert.deepEqual(codecs.node.encode(slot), [13, [["body"]]]);
assert.deepStrictEqual(codecs.node.decode([13, [["body"]]]), slot);
assert.throws(() => codecs.node.decode([13, ["body"]]));
assert.throws(() => codecs.node.decode([13, [[null]]]));
const decoded = decodeDocumentPayload(compositionDocument, documentPayloadFromBytes(golden("composition-all-params.bin")));
assert.equal(decoded.body.kind, "Box");
if (decoded.body.kind !== "Box") return;
assert.deepStrictEqual(decoded.body.children.at(-1), slot);
});

View file

@ -13,10 +13,12 @@ const NS = "GameCult.Thing.Contract.";
const names = new Set(nonEmptyLines(join(parityDir, "type-names.txt")));
const entries = Object.entries(codecs) as [string, { typeName?: string; members?: readonly { typeName: string }[] }][];
test("ParamName and Scalar are Rust names the C# package does not have; each arm has its own codec", () => {
assert.equal(names.has(`${NS}ParamName`), false);
test("Scalar is a Rust name the C# package does not have; ParamName is its type for a slot; each Param arm has its own codec", () => {
assert.equal(names.has(`${NS}Scalar`), false);
for (const [key, codec] of entries) assert.doesNotMatch(codec.typeName ?? "", /\.(ParamName|Scalar)$/u, key);
for (const [key, codec] of entries) assert.doesNotMatch(codec.typeName ?? "", /.Scalar$/u, key);
assert.ok(names.has(`${NS}ParamName`));
assert.equal(codecs.paramName.typeName, `${NS}ParamName`);
assert.equal(codecs.slotNode.typeName, `${NS}SlotNode`);
const arms = {
textSourceParam: "TextSourceParam",
numberSourceParam: "NumberSourceParam",

View file

@ -45,7 +45,7 @@ test("a Thing 1 flat map is not a command result", () => {
});
test("an unknown Node arm is refused naming the union and the key", () => {
assert.match(refusal(read(surfaceDocument, "node-unknown-arm.bin")), /Union Node: unknown arm key 13/);
assert.match(refusal(read(surfaceDocument, "node-unknown-arm.bin")), /Union Node: unknown arm key 14/);
});
test("an unknown Outcome arm is refused naming the union and the key", () => {

View file

@ -263,7 +263,7 @@ internal static class Builders
new("act", new ParamKindCommand()),
new("body", new ParamKindSlot()),
},
Boxed("panel-root", Text("panel-title", "t"), innerUse));
Boxed("panel-root", Text("panel-title", "t"), innerUse, new SlotNode(new ParamName("body"))));
}
public static List<(string Name, CommandResult Result)> Results(CommandInvocation invocation) => new()

View file

@ -62,7 +62,7 @@ public sealed class GoldenTests
[Test]
public void Thing1FlatMapIsRefused() => Refused(typeof(CommandResult), "result-thing1-flat");
[TestCase("node-unknown-arm", typeof(SurfaceDocument), "Node", "13")]
[TestCase("node-unknown-arm", typeof(SurfaceDocument), "Node", "14")]
[TestCase("outcome-unknown-arm", typeof(CommandResult), "Outcome", "4")]
public void UnknownArmsAreRefusedNamingUnionAndKey(string golden, Type type, string union, string key)
{

View file

@ -0,0 +1,30 @@
using MessagePack;
namespace GameCult.Thing.Contract.Tests;
/// <summary>
/// thing2:ruling:composition-slot-node: a Slot is union key 13 of Node, one nested slot holding the parameter name, and a
/// composition body places it last in the root's children.
/// </summary>
public sealed class SlotNodeTests
{
[Test]
public void SlotIsArm13WithANestedParamName()
{
Node slot = new SlotNode(new ParamName("body"));
var bytes = MessagePackSerializer.Serialize(typeof(Node), slot, Wire.Options);
Assert.That(bytes, Is.EqualTo(new byte[] { 0x92, 0x0D, 0x91, 0x91, 0xA4, 0x62, 0x6F, 0x64, 0x79 }));
var read = (SlotNode)MessagePackSerializer.Deserialize(typeof(Node), bytes, Wire.Options);
Assert.That(read.Param.Name, Is.EqualTo("body"));
}
[Test]
public void TheCompositionGoldenHoldsTheSlotLastInTheRootsChildren()
{
var composition = (CompositionDocument)Wire.Read(typeof(CompositionDocument), Wire.Golden("composition-all-params.bin"));
var root = (BoxNode)composition.Body;
var slot = (SlotNode)root.Children[^1];
Assert.That(slot.Param.Name, Is.EqualTo("body"));
Assert.That(root.Children, Has.Count.EqualTo(3));
}
}

View file

@ -1,6 +1,6 @@
# thing-contract-parity
The names the C# package `GameCult.Thing.Contract` gives its types. The C# package owns them because CultLib's C# reference compares catalog type names when a store reopens, and every runtime package is held to the C# names.
The names the C# package `GameCult.Thing.Contract` gives its types. The C# package owns them because CultLib's C# reference compares catalog type names when a store reopens, and every runtime package is held to the C# names. `ParamName` is in the set as `SlotNode.Param`'s type; the Param arms fold it into their own classes.
| File | Rows |
|---|---|

View file

@ -118,6 +118,7 @@ GameCult.Thing.Contract.ParamKindCommand
GameCult.Thing.Contract.ParamKindNumber
GameCult.Thing.Contract.ParamKindSlot
GameCult.Thing.Contract.ParamKindText
GameCult.Thing.Contract.ParamName
GameCult.Thing.Contract.PendingOutcome
GameCult.Thing.Contract.PlotMark
GameCult.Thing.Contract.PlotMarkArea
@ -144,6 +145,7 @@ GameCult.Thing.Contract.SelectOption
GameCult.Thing.Contract.Size2
GameCult.Thing.Contract.SliderNode
GameCult.Thing.Contract.SlotArg
GameCult.Thing.Contract.SlotNode
GameCult.Thing.Contract.StateRef
GameCult.Thing.Contract.StateSource
GameCult.Thing.Contract.StateSourceItem