From 8ca1bab380fbee2d81347d75080d52fbd1c30ac9 Mon Sep 17 00:00:00 2001 From: Eureka Date: Sat, 28 Nov 2026 09:47:34 +0000 Subject: [PATCH] Thing contract: an invocation names its source node and Repeat key chain (#22) --- crates/thing-contract/src/command.rs | 8 +++++++ crates/thing-contract/tests/goldens/README.md | 2 +- .../tests/goldens/invocation-all-inputs.bin | Bin 211 -> 234 bytes .../tests/goldens/nil-positions.tsv | 4 ++++ crates/thing-testkit/fixtures/README.md | 4 ++-- .../fixtures/f02-login-effect.surface.cc | Bin 5555 -> 5997 bytes .../fixtures/f04-form.surface.cc | Bin 5580 -> 6015 bytes crates/thing-testkit/src/build.rs | 2 ++ crates/thing-testkit/src/fixture.rs | 6 +++++- packages/GameCult.Thing.Contract/Command.cs | 8 ++++++- packages/thing-contract/src/codecs.ts | 2 ++ packages/thing-contract/src/types.ts | 8 +++++++ packages/thing-contract/test/builders.ts | 2 ++ packages/thing-contract/test/names.test.ts | 2 +- .../GameCult.Thing.Contract.Tests/Builders.cs | 6 ++++-- .../DomainTests.cs | 2 +- .../ReadOnlyListTests.cs | 2 +- .../thing-contract-parity/catalog-members.tsv | 20 ++++++++++-------- tests/thing-contract-parity/written-by-cs.cc | Bin 13957 -> 14406 bytes tests/thing-contract-parity/written-by-rs.cc | Bin 13003 -> 13452 bytes tests/thing-contract-parity/written-by-ts.cc | Bin 13023 -> 13472 bytes 21 files changed, 59 insertions(+), 19 deletions(-) diff --git a/crates/thing-contract/src/command.rs b/crates/thing-contract/src/command.rs index 9daf1c3..29bc9d2 100644 --- a/crates/thing-contract/src/command.rs +++ b/crates/thing-contract/src/command.rs @@ -115,6 +115,14 @@ pub struct CommandInvocation { pub issued_at: String, #[cultcache(key = 8)] pub delegation: Option, + /// The activating node's declared id in the resolved tree. For a node inside a Repeat it is + /// the template's id, never an instance id. A confirmed invocation names the node confirmed; + /// a resumed one carries the source and items of the invocation whose result carried the effect. + #[cultcache(key = 9)] + pub source: NodeId, + /// The key of each Repeat instance enclosing the source, outermost first; empty outside any Repeat. + #[cultcache(key = 10, type_name = "System.Collections.Immutable.ImmutableArray")] + pub items: Vec, } impl CommandInvocation { diff --git a/crates/thing-contract/tests/goldens/README.md b/crates/thing-contract/tests/goldens/README.md index 711f3d0..6e2ed8e 100644 --- a/crates/thing-contract/tests/goldens/README.md +++ b/crates/thing-contract/tests/goldens/README.md @@ -14,7 +14,7 @@ when absent. Arm keys are fixed for v1. |---|---|---| | `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 | +| `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, source `go-button` and items `[outer, inner]` | | `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 | | `result-completed-open-surface.bin` | same | Completed with no source version and the OpenSurface effect | diff --git a/crates/thing-contract/tests/goldens/invocation-all-inputs.bin b/crates/thing-contract/tests/goldens/invocation-all-inputs.bin index 52c059074e5875e980e06a2c1b1f1b27c93d9cbf..5eb52d79dbcac9d1dc153115249feccfdcf65557 100644 GIT binary patch delta 33 pcmcc2_==Hn_C&@@;w#hhb(2a{S)41Kl#`k= KVKcYTL1qA3fI~z8 delta 45 zcmV+|0Mh^eF3c;CrUC`ov8dMtlf(xm0hyDG3?#D;2vPyF#t9V(0@<09-4fWdz7xR% DxHl58 diff --git a/crates/thing-testkit/src/build.rs b/crates/thing-testkit/src/build.rs index f042d9f..4e02889 100644 --- a/crates/thing-testkit/src/build.rs +++ b/crates/thing-testkit/src/build.rs @@ -140,5 +140,7 @@ pub fn invocation() -> CommandInvocation { client: "renderer.web".into(), issued_at: "2026-01-01T00:00:00Z".into(), delegation: Some("delegate-1".into()), + source: nid("go-button"), + items: vec!["outer".into(), "inner".into()], } } diff --git a/crates/thing-testkit/src/fixture.rs b/crates/thing-testkit/src/fixture.rs index ded1572..d2a59d8 100644 --- a/crates/thing-testkit/src/fixture.rs +++ b/crates/thing-testkit/src/fixture.rs @@ -470,7 +470,7 @@ fn surface(provider: &str, label: &str, root: Node, commands: Vec) } /// An invocation of `command` on `surface`, issued at the pinned clock. -fn invoke(surface: &SurfaceDocument, id: &str, command: &str, captured: Vec) -> CommandInvocation { +fn invoke(surface: &SurfaceDocument, id: &str, command: &str, source: &str, captured: Vec) -> CommandInvocation { CommandInvocation { invocation_id: id.into(), surface_key: surface.record_key(), @@ -485,6 +485,8 @@ fn invoke(surface: &SurfaceDocument, id: &str, command: &str, captured: Vec FixtureSet { &login, "6d1c0f52-7a0e-4b53-8f3d-2a9e4c7b1d10", "sign-in", + "sign-in-button", vec![captured("username", InputValue::Text(TextValue { value: "ada".into() }))], ); // The answer arrives in two steps: Pending, then Completed, whose effect sends the user to @@ -641,6 +644,7 @@ fn form() -> FixtureSet { &form, "0b7e44aa-31c9-4e0d-a6f2-95d8c3e1b277", "save", + "enabled", vec![ captured("enabled", InputValue::Bool(BoolValue { value: true })), captured("volume", InputValue::Number(NumberValue { value: 0.75 })), diff --git a/packages/GameCult.Thing.Contract/Command.cs b/packages/GameCult.Thing.Contract/Command.cs index eae7dbc..2951bfb 100644 --- a/packages/GameCult.Thing.Contract/Command.cs +++ b/packages/GameCult.Thing.Contract/Command.cs @@ -160,8 +160,12 @@ public sealed class CommandInvocation [Key(6)] public string Client { get; } [Key(7)] public string IssuedAt { get; } [Key(8)] public string? Delegation { get; } + /// The activating node's declared id in the resolved tree. For a node inside a Repeat it is the template's id, never an instance id. A confirmed invocation names the node confirmed; a resumed one carries the source and items of the invocation whose result carried the effect. + [Key(9)] public string Source { get; } + /// The key of each Repeat instance enclosing the source, outermost first; empty outside any Repeat. + [Key(10)] public ImmutableArray Items { get; } - public CommandInvocation(string invocationId, string surfaceKey, long surfaceVersion, string command, RecordPayload payload, IReadOnlyList captured, string client, string issuedAt, string? delegation) + public CommandInvocation(string invocationId, string surfaceKey, long surfaceVersion, string command, RecordPayload payload, IReadOnlyList captured, string client, string issuedAt, string? delegation, string source, IReadOnlyList items) { InvocationId = ThingDomain.Present(invocationId, "InvocationId"); SurfaceKey = ThingDomain.Present(surfaceKey, "SurfaceKey"); @@ -172,6 +176,8 @@ public sealed class CommandInvocation Client = ThingDomain.Present(client, "Client"); IssuedAt = ThingDomain.Present(issuedAt, "IssuedAt"); Delegation = delegation; + Source = ThingDomain.Present(source, "Source"); + Items = ThingDomain.Items(items, "Items"); } [IgnoreMember] public string RecordKey => ThingKeys.InvocationKey(InvocationId); diff --git a/packages/thing-contract/src/codecs.ts b/packages/thing-contract/src/codecs.ts index c8dfc1c..e2030c6 100644 --- a/packages/thing-contract/src/codecs.ts +++ b/packages/thing-contract/src/codecs.ts @@ -273,6 +273,8 @@ export const commandInvocation = codecs.slots( 6: ["client", text], 7: ["issuedAt", text], 8: ["delegation", nullable(string)], + 9: ["source", text], + 10: ["items", readOnlyList(string)], }, named("CommandInvocation"), ); diff --git a/packages/thing-contract/src/types.ts b/packages/thing-contract/src/types.ts index 40155a9..688dadc 100644 --- a/packages/thing-contract/src/types.ts +++ b/packages/thing-contract/src/types.ts @@ -155,6 +155,14 @@ export interface CommandInvocation { readonly client: string; readonly issuedAt: string; readonly delegation: string | null; + /** + * The activating node's declared id in the resolved tree. For a node inside a Repeat it is the template's + * id, never an instance id. A confirmed invocation names the node confirmed; a resumed one carries the + * source and items of the invocation whose result carried the effect. + */ + readonly source: NodeId; + /** The key of each Repeat instance enclosing the source, outermost first; empty outside any Repeat. */ + readonly items: readonly string[]; } // result.rs diff --git a/packages/thing-contract/test/builders.ts b/packages/thing-contract/test/builders.ts index f343de4..94bdf9a 100644 --- a/packages/thing-contract/test/builders.ts +++ b/packages/thing-contract/test/builders.ts @@ -139,6 +139,8 @@ export function invocation(): CommandInvocation { client: "renderer.web", issuedAt: PINNED_CLOCK, delegation: "delegate-1", + source: "go-button", + items: ["outer", "inner"], }; } diff --git a/packages/thing-contract/test/names.test.ts b/packages/thing-contract/test/names.test.ts index 3af9083..e9f832c 100644 --- a/packages/thing-contract/test/names.test.ts +++ b/packages/thing-contract/test/names.test.ts @@ -46,7 +46,7 @@ test("a list slot is named ImmutableArray, never List, and the element is a type assert.ok(element[1] === "System.String" || names.has(element[1]), `${key}: ${member.typeName}`); } } - assert.equal(lists, 14); + assert.equal(lists, 15); }); test("TextInputNode's slot 2 is inputKind, and the name set holds no Kind-only spelling", () => { diff --git a/tests/GameCult.Thing.Contract.Tests/Builders.cs b/tests/GameCult.Thing.Contract.Tests/Builders.cs index 6a6ce2d..5e606f3 100644 --- a/tests/GameCult.Thing.Contract.Tests/Builders.cs +++ b/tests/GameCult.Thing.Contract.Tests/Builders.cs @@ -100,12 +100,14 @@ internal static class Builders }, "renderer.web", "2026-01-01T00:00:00Z", - "delegate-1"); + "delegate-1", + "go-button", + new List { "outer", "inner" }); public static CommandInvocation InvocationNamed(string id) => new( id, "thing:surface:provider.a.main", 7, "go", new RecordPayload("gamecult.thing.test.go.v1", new byte[] { 0x91, 0x01, 0xff, 0x00 }), - new List(), "renderer.web", "2026-01-01T00:00:00Z", null); + new List(), "renderer.web", "2026-01-01T00:00:00Z", null, "go-button", new List()); public static List BindAllFormats() { diff --git a/tests/GameCult.Thing.Contract.Tests/DomainTests.cs b/tests/GameCult.Thing.Contract.Tests/DomainTests.cs index 85e94af..0917784 100644 --- a/tests/GameCult.Thing.Contract.Tests/DomainTests.cs +++ b/tests/GameCult.Thing.Contract.Tests/DomainTests.cs @@ -19,7 +19,7 @@ public sealed class DomainTests yield return Case("CompletedOutcome.SourceVersion", "Version must be at least 0", () => new CompletedOutcome(-1, false, null)); yield return Case("CommandResult.Completed source version", "Version must be at least 0", () => CommandResult.Completed(Inv(), 1, -1, false, null)); yield return Case("CommandInvocation.SurfaceVersion", "Version must be at least 0", - () => new CommandInvocation("i", "k", -1, "go", new RecordPayload("s", Array.Empty()), new List(), "c", "t", null)); + () => new CommandInvocation("i", "k", -1, "go", new RecordPayload("s", Array.Empty()), new List(), "c", "t", null, "s", new List())); yield return Case("SurfaceDocument.Label empty", "Segment must be non-empty", () => SurfaceOf("p", "")); yield return Case("SurfaceDocument.Label dotted", "Segment must be free of '.'", () => SurfaceOf("p", "a.b")); yield return Case("SurfaceDocument.Version", "Version must be at least 0", () => new SurfaceDocument("p", "l", -1, "t", Boxed("r"), new List())); diff --git a/tests/GameCult.Thing.Contract.Tests/ReadOnlyListTests.cs b/tests/GameCult.Thing.Contract.Tests/ReadOnlyListTests.cs index cd79648..24b5907 100644 --- a/tests/GameCult.Thing.Contract.Tests/ReadOnlyListTests.cs +++ b/tests/GameCult.Thing.Contract.Tests/ReadOnlyListTests.cs @@ -227,7 +227,7 @@ public sealed class ReadOnlyListTests { Assert.Throws(() => MessagePackSerializer.Deserialize(new byte[] { 0x92, 0xA1, (byte)'s', 0xC0 }, Wire.Options)); - var empty = new CommandInvocation("i", "k", 1, "go", new RecordPayload("s", Array.Empty()), new List(), "c", "t", null); + var empty = new CommandInvocation("i", "k", 1, "go", new RecordPayload("s", Array.Empty()), new List(), "c", "t", null, "s", new List()); var decoded = (CommandInvocation)Wire.Read(typeof(CommandInvocation), Wire.Write(empty)); Assert.That(decoded.Payload.Bytes.IsEmpty, Is.True); Assert.That(Wire.Write(decoded), Is.EqualTo(Wire.Write(empty))); diff --git a/tests/thing-contract-parity/catalog-members.tsv b/tests/thing-contract-parity/catalog-members.tsv index aaed98b..5184938 100644 --- a/tests/thing-contract-parity/catalog-members.tsv +++ b/tests/thing-contract-parity/catalog-members.tsv @@ -2,21 +2,23 @@ sha256:054253624267f9b37445b05f7fcf5c4de6f40ad16fa1427eb596c56e5471383e 0 Provid sha256:054253624267f9b37445b05f7fcf5c4de6f40ad16fa1427eb596c56e5471383e 1 CatalogId System.String sha256:054253624267f9b37445b05f7fcf5c4de6f40ad16fa1427eb596c56e5471383e 2 Version System.Int64 sha256:054253624267f9b37445b05f7fcf5c4de6f40ad16fa1427eb596c56e5471383e 3 Assets System.Collections.Immutable.ImmutableArray +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 0 InvocationId System.String +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 1 SurfaceKey System.String +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 2 SurfaceVersion System.Int64 +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 3 Command System.String +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 4 Payload GameCult.Thing.Contract.RecordPayload +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 5 Captured System.Collections.Immutable.ImmutableArray +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 6 Client System.String +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 7 IssuedAt System.String +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 8 Delegation System.String +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 9 Source System.String +sha256:6436a504076d804b7baf681621164dbed8ccb8ff7222f280e6ffcbb36df2d2b0 10 Items System.Collections.Immutable.ImmutableArray sha256:9611b1313cb4cd285ba02e4170f5204c1fb009c52a058c864c0382abd26202bc 0 ProviderId System.String sha256:9611b1313cb4cd285ba02e4170f5204c1fb009c52a058c864c0382abd26202bc 1 Label System.String sha256:9611b1313cb4cd285ba02e4170f5204c1fb009c52a058c864c0382abd26202bc 2 Version System.Int64 sha256:9611b1313cb4cd285ba02e4170f5204c1fb009c52a058c864c0382abd26202bc 3 Title System.String sha256:9611b1313cb4cd285ba02e4170f5204c1fb009c52a058c864c0382abd26202bc 4 Root GameCult.Thing.Contract.Node sha256:9611b1313cb4cd285ba02e4170f5204c1fb009c52a058c864c0382abd26202bc 5 Commands System.Collections.Immutable.ImmutableArray -sha256:9749a22fe62c6de13e396697af2ac2dafb713eb21e30c3ed0eda21ba68085647 0 InvocationId System.String -sha256:9749a22fe62c6de13e396697af2ac2dafb713eb21e30c3ed0eda21ba68085647 1 SurfaceKey System.String -sha256:9749a22fe62c6de13e396697af2ac2dafb713eb21e30c3ed0eda21ba68085647 2 SurfaceVersion System.Int64 -sha256:9749a22fe62c6de13e396697af2ac2dafb713eb21e30c3ed0eda21ba68085647 3 Command System.String -sha256:9749a22fe62c6de13e396697af2ac2dafb713eb21e30c3ed0eda21ba68085647 4 Payload GameCult.Thing.Contract.RecordPayload -sha256:9749a22fe62c6de13e396697af2ac2dafb713eb21e30c3ed0eda21ba68085647 5 Captured System.Collections.Immutable.ImmutableArray -sha256:9749a22fe62c6de13e396697af2ac2dafb713eb21e30c3ed0eda21ba68085647 6 Client System.String -sha256:9749a22fe62c6de13e396697af2ac2dafb713eb21e30c3ed0eda21ba68085647 7 IssuedAt System.String -sha256:9749a22fe62c6de13e396697af2ac2dafb713eb21e30c3ed0eda21ba68085647 8 Delegation System.String sha256:bcc1513ee682d1d58746836d4d2e98df086eb62c3fd9a797a2e72e561437393e 0 Publisher System.String sha256:bcc1513ee682d1d58746836d4d2e98df086eb62c3fd9a797a2e72e561437393e 1 Name System.String sha256:bcc1513ee682d1d58746836d4d2e98df086eb62c3fd9a797a2e72e561437393e 2 Version System.Int64 diff --git a/tests/thing-contract-parity/written-by-cs.cc b/tests/thing-contract-parity/written-by-cs.cc index e8dbd2b60b44f70ba98ae21a62c7f1d8a781fdd2..f7a9abb066f276e15d1526472594887a91c79d9d 100644 GIT binary patch delta 560 zcmbu5J1+!L7>2{z$Y9wZ(YR!nj^)g`emjM06k4lQ%(;nTXJyS63ZbD>a2kn5A}i66 z`3s`Z(a2Kj#19Y+3Xx2$eVXTa--GJi*7ZxrBBz9h3{fPw21KQhq2=In?E9Q*X*4J$ z!CHYawiuA%)+#9p*A{CmQLEtQvjsPsoms+y10zD0wZ_y+tSA^-Mw$?xDUA`?ri{a zm7VR_RHrL(eKXo{``)^{&-5((chs3X&QByC-K%ZhsdxDsaGoFZx|%=Y>UJw|W0|Sm zlzcW>&RzEPK|okQ$TX!45ODW7{F-KrCGR798T;SHR^jJSUh@4ChBcJZaz2SrfY9yR vnR_Ta4qa{3O0p5hwdkZ-Ys9AB+>9bqcNfK@berIAZu}Qid3nY`I6YMRlw6ifFY$XL+aLTt-Y#!0=HDwP){u3GDKa)3qEt~?W@}tR*I;nTo6bDSsGw0X zKnxD0cU(iQnM_;dBT?l;v3F_|DWl2MK&ZNOv@Q{1hz)eAlVNSTlEBKdOV(?$NEEaT z(IIK~CE79 sMTgr80eK?j1nYC?%@XW%0Py-T%U9d)IgIZ5A2i&LpZg@Kyo_&$|DoP`lK=n! diff --git a/tests/thing-contract-parity/written-by-rs.cc b/tests/thing-contract-parity/written-by-rs.cc index a0f7d1b20565c262229b184e24fdba30ba1cdb9d..7373ed71ee3b898eb7172f5a9f859b73926dafc0 100644 GIT binary patch delta 169 zcmX?|+LO8A9t#t@+~x-?*I6eCaq?U0DCH&QrYcz}1?QI*B~KEpC0SqxpF delta 58 zcmV-A0LA}|Y0G7>-UI>#*|XpT*9DXO3nl@Xlf)1tvqub40Ror3lK~7DvlkAL4g%Ae Qlm8tilh7Qjvy&b97Q+b_tpET3 diff --git a/tests/thing-contract-parity/written-by-ts.cc b/tests/thing-contract-parity/written-by-ts.cc index ccfb6390f066eb411bf5ebb77e26078b824685e8..74d6b7a022ae929604f31f44955fdc7f8c5f1451 100644 GIT binary patch delta 251 zcmcbgx*&7IJr*W*xy=t)uCq=O;^eo~QOZlqO;xf|3eGPrN}eQG%Wr4^7xOGh&7Hi5 z$(%R1vKYwJ3oa?j%uAn~AdxV67nd^Q?9KPM${0Cka4rLDPMxgCBf`nG6r`*8rqyIY z2^~HZjdq*;d2aA>Sy&mHSs5DX8JbTvl-j@z=NcPsej~MznIA4-VjOkk)$Galoz9nA?=NnjVuM03YEg@&Et;