From 54d5f0adac62fe11e567548b6d5271c5b0b1392c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 27 Nov 2026 21:51:30 +0100 Subject: [PATCH] Thing contract, Rust: Node::Slot(SlotNode { param: ParamName }) at arm 13; unknown-arm golden moves to 14 Co-Authored-By: Claude Sonnet 5.5 --- crates/thing-contract/src/node.rs | 17 +++++++++++++++-- crates/thing-contract/tests/goldens.rs | 12 ++++++++---- crates/thing-contract/tests/goldens/README.md | 6 +++--- .../tests/goldens/composition-all-params.bin | Bin 812 -> 821 bytes .../tests/goldens/nil-positions.tsv | 11 ++++++++--- .../tests/goldens/node-unknown-arm.bin | 2 +- .../thing-contract/tests/goldens/surface.cc | Bin 7699 -> 7708 bytes 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/crates/thing-contract/src/node.rs b/crates/thing-contract/src/node.rs index 622e171..7a0d169 100644 --- a/crates/thing-contract/src/node.rs +++ b/crates/thing-contract/src/node.rs @@ -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, } +/// 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)] diff --git a/crates/thing-contract/tests/goldens.rs b/crates/thing-contract/tests/goldens.rs index d1891b7..0f49762 100644 --- a/crates/thing-contract/tests/goldens.rs +++ b/crates/thing-contract/tests/goldens.rs @@ -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") })], + ), } } @@ -518,10 +521,11 @@ fn refusal_payloads() -> Vec<(&'static str, Vec)> { 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 +592,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::(&bytes).unwrap_err().to_string() diff --git a/crates/thing-contract/tests/goldens/README.md b/crates/thing-contract/tests/goldens/README.md index 4d66e7d..f9e9f74 100644 --- a/crates/thing-contract/tests/goldens/README.md +++ b/crates/thing-contract/tests/goldens/README.md @@ -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 | diff --git a/crates/thing-contract/tests/goldens/composition-all-params.bin b/crates/thing-contract/tests/goldens/composition-all-params.bin index a93e57a6f8245435e9d054e1ce5e4896e849dcbe..aeea9ede810d860f8446070856d77a14a37ebeaa 100644 GIT binary patch delta 24 gcmZ3(wv}yz10&<)&5n$(8968MPMo+TDLw?la!%r%IB`i*eoEzL5AM@K0M`NxVE_OC delta 26 icmbPZGudW?GzX*3W*H6#M#f2-V>w?lZVu!=Ed&5