Thing 2.0 cut 7a: commands (activate, Drafts, minted invocations, lifecycle, effects as data) #25

Merged
eureka merged 13 commits from hands/thing2-commands-dispatch into main 2026-11-29 00:35:40 +00:00
Showing only changes of commit bf7534859b - Show all commits

Thing 2.0 cut 7a: tests for each command source kind and the wrong-key result
All checks were successful
Portable Eve contracts and browser lowering / ubuntu-latest eve-browser-lowering (pull_request) Successful in 4m16s
Portable Eve contracts and browser lowering / ubuntu-latest eve-contracts (pull_request) Successful in 3m4s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Meta Vens 2026-11-28 22:00:56 +01:00

View file

@ -949,3 +949,59 @@ fn stranger() -> CommandInvocation {
invocation.invocation_id = "33333333-3333-4333-8333-333333333333".into();
invocation
}
#[test]
fn every_command_source_kind_fires_its_command_and_captures_its_own_draft_kind() {
let slider = Node::Slider(SliderNode { common: common("vol"), min: 0.0, max: 1.0, step: 0.1, value: lit_number(0.2), commit: command("go") });
let select = Node::Select(SelectNode {
common: common("pick"),
options: OptionList::Literal(LiteralOptions { options: vec![SelectOption { value: "a".into(), label: "A".into() }] }),
value: record_bind(path(&["Theme"]), None),
on_change: command("go"),
});
let overlay = Node::Overlay(OverlayNode {
common: common("dialog"),
anchor: Anchor::Viewport,
modal: true,
dismiss: command("go"),
children: vec![],
});
let number = input("num", InputKind::Number, "1", "go");
let document = surface(
PROVIDER,
boxed("root", vec![slider, select, overlay, number, input("txt", InputKind::Text, "t", "go")]),
vec![decl("go", &["vol", "pick", "num"], None)],
);
let mut rig = Rig::new(MemState::new(), &document);
// Drafts of each kind are what the captures send.
rig.set_draft(&nid("vol"), InputValue::Number(NumberValue { value: 0.9 }));
rig.set_draft(&nid("pick"), InputValue::Choice(ChoiceValue { value: "a".into() }));
rig.set_draft(&nid("num"), InputValue::Number(NumberValue { value: 7.0 }));
let mut ids = SeqIds::new();
rig.act(&nid("dialog"), ActivationKind::Press, PINNED_NOW, &mut ids);
rig.act(&nid("txt"), ActivationKind::Submit, PINNED_NOW, &mut ids);
let minted = rig.commands.take_outbound();
assert_eq!(minted.len(), 2);
assert_eq!(minted[0].source, nid("dialog"));
assert_eq!(minted[0].captured[0].value, InputValue::Number(NumberValue { value: 0.9 }));
assert_eq!(minted[0].captured[1].value, InputValue::Choice(ChoiceValue { value: "a".into() }));
assert_eq!(minted[0].captured[2].value, InputValue::Number(NumberValue { value: 7.0 }));
assert_eq!(minted[1].source, nid("txt"));
rig.act(&nid("vol"), ActivationKind::Change(InputValue::Number(NumberValue { value: 0.4 })), PINNED_NOW, &mut ids);
rig.act(&nid("pick"), ActivationKind::Change(InputValue::Choice(ChoiceValue { value: "a".into() })), PINNED_NOW, &mut ids);
let changed = rig.commands.take_outbound();
assert_eq!(changed.len(), 2);
assert_eq!(changed[0].source, nid("vol"));
assert_eq!(changed[0].captured[0].value, InputValue::Number(NumberValue { value: 0.4 }));
assert_eq!(changed[1].source, nid("pick"));
}
#[test]
fn a_result_filed_under_the_wrong_key_says_so() {
let mut rig = Rig::new(MemState::new(), &go_surface());
let mine = rig.mint("go", PINNED_NOW);
let body = CommandResult::pending(&mine, seq(1), "x");
let address = rig.result_address(&CommandResult::pending(&mine, seq(2), "").record_key());
let answered = rig.apply(&Change::Upsert(Entry { address, record: Record::Result(body) }), at(1));
assert_eq!(answered.diagnostics[0].detail, "the result is not the one its key names");
}