Thing 2.0 cut 7a h2: every refused activation is a diagnostic in the frame output (silent-refusals)
Steward decision 7 of the h2 fix brief. Kind mismatch, unknown node, blocked while confirming and a refused change answer Code::ActivationRefused from Commands::activate; Core queues what activate and resume say and the next frame's diagnostics carry it out, the channel the host already reads. A Param command cannot reach a tree (resolve refuses the document, tested), so it is the same refusal as a kind mismatch, not a separate branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
110acf5ef3
commit
f5c6ec9048
3 changed files with 96 additions and 21 deletions
|
|
@ -233,8 +233,10 @@ impl Commands {
|
|||
}
|
||||
|
||||
/// The one commit primitive: the user acted on `act.node` of `tree`. Every path calls it. It
|
||||
/// mints one invocation, or nothing: a node that is not a command source, a disabled or busy
|
||||
/// button, an input with nothing to send, or a command waiting on confirmation.
|
||||
/// mints one invocation, or nothing. A refusal (a node that is not a command source for this kind, a
|
||||
/// node nobody laid, a change the input does not take, a command waiting on confirmation) answers with
|
||||
/// a `Code::ActivationRefused` diagnostic. A disabled or busy button is not a refusal: the user sees
|
||||
/// it, so it stays silent.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn activate(
|
||||
&mut self,
|
||||
|
|
@ -246,12 +248,17 @@ impl Commands {
|
|||
port: &mut dyn StatePort,
|
||||
ledger: &mut Ledger,
|
||||
) -> Vec<Diagnostic> {
|
||||
if self.confirming.is_some() {
|
||||
return Vec::new();
|
||||
}
|
||||
let surface = tree.resolved().document().record_key();
|
||||
let Some(located) = tree.locate(&act.node) else { return Vec::new() };
|
||||
let Some(CommandRef::Id(command)) = command_of(located.node, &act.kind) else { return Vec::new() };
|
||||
if self.confirming.is_some() {
|
||||
return vec![refused(&surface, &act.node, "a command is waiting for confirmation")];
|
||||
}
|
||||
let Some(located) = tree.locate(&act.node) else {
|
||||
return vec![refused(&surface, &act.node, "the node is not in the surface")];
|
||||
};
|
||||
// A Param command is the same refusal: resolve leaves none in a tree, so none reaches here.
|
||||
let Some(CommandRef::Id(command)) = command_of(located.node, &act.kind) else {
|
||||
return vec![refused(&surface, &act.node, "the node fires no command for this activation")];
|
||||
};
|
||||
if let ActivationKind::Change(value) = &act.kind {
|
||||
match capture::change(tree, &act.node, located.node, value) {
|
||||
Ok(taken) => drafts.set(&surface, &act.node, taken),
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use std::collections::HashSet;
|
|||
|
||||
use crate::bind::Binder;
|
||||
use crate::command::{Activation, Commands, Confirming, HostEffect, NodeStates, Resume};
|
||||
use crate::diagnostic::Diagnostic;
|
||||
use crate::diagnostic::{Code, Diagnostic};
|
||||
use crate::input::{Drafts, InputEvent};
|
||||
use crate::layout::{LaidTree, LayoutError, LayoutFrame, Measure, Metrics, layout};
|
||||
use crate::port::{Address, Change, IdSource, Interest, Ledger, Lookup, StatePort};
|
||||
|
|
@ -81,6 +81,8 @@ pub struct Core {
|
|||
theme: Theme,
|
||||
commands: Commands,
|
||||
drafts: Drafts,
|
||||
/// What activations said since the last frame; the frame's diagnostics carry it out.
|
||||
notes: Vec<Diagnostic>,
|
||||
/// The surface `show` named, and the one whose interest and trees are held.
|
||||
wanted: Option<Address>,
|
||||
shown: Option<Address>,
|
||||
|
|
@ -100,6 +102,7 @@ impl Core {
|
|||
theme: Theme::std(),
|
||||
commands: Commands::new(config.client, config.invocation_timeout_ms),
|
||||
drafts: Drafts::new(),
|
||||
notes: Vec::new(),
|
||||
wanted: None,
|
||||
shown: None,
|
||||
last: None,
|
||||
|
|
@ -121,7 +124,7 @@ impl Core {
|
|||
}
|
||||
changes.extend(port.drain());
|
||||
|
||||
let mut diagnostics = Vec::new();
|
||||
let mut diagnostics = std::mem::take(&mut self.notes);
|
||||
let mut effects = Vec::new();
|
||||
let mut rebound = false;
|
||||
for change in &changes {
|
||||
|
|
@ -161,33 +164,40 @@ impl Core {
|
|||
}
|
||||
}
|
||||
|
||||
/// The user acted on a node of the shown surface: the one primitive every input path ends in. A
|
||||
/// host or a test calls it directly until the pointer and keyboard routes (which call it from
|
||||
/// `frame`) land. The invocation it mints is in the next frame's `outbound`.
|
||||
pub fn activate(&mut self, act: Activation, now: Timestamp, ports: Ports<'_>) -> Vec<Diagnostic> {
|
||||
/// The host's semantic activation: the user, or an accessibility action or an automation acting for
|
||||
/// them, activated a node of the shown surface. It is the one primitive every input path ends in (pointer and
|
||||
/// keyboard routes arrive here too). The invocation it mints is in the next
|
||||
/// frame's `outbound`; a refusal (see `Commands::activate`) is said in that frame's `diagnostics`.
|
||||
pub fn activate(&mut self, act: Activation, now: Timestamp, ports: Ports<'_>) {
|
||||
let Some(tree) = self.shown.as_ref().and_then(|shown| self.binder.tree(shown.key.as_str())) else {
|
||||
return Vec::new();
|
||||
let node = Some(act.node);
|
||||
self.notes.push(Diagnostic { code: Code::ActivationRefused, surface: String::new(), node, detail: "no surface is shown".into() });
|
||||
return;
|
||||
};
|
||||
self.commands.activate(act, tree, &mut self.drafts, now, ports.ids, ports.state, &mut self.ledger)
|
||||
let said = self.commands.activate(act, tree, &mut self.drafts, now, ports.ids, ports.state, &mut self.ledger);
|
||||
self.notes.extend(said);
|
||||
}
|
||||
|
||||
/// Answer the command waiting on confirmation (`confirming`). Until the confirmation dialog
|
||||
/// lands after keyboard input, a host calls this from its own test or debug path.
|
||||
/// Answer the command waiting on confirmation (`confirming`). The host shows the question and calls
|
||||
/// this with the user's answer; accepting mints with the captures taken at the activation.
|
||||
pub fn confirm(&mut self, accept: bool, now: Timestamp, ports: Ports<'_>) {
|
||||
self.commands.confirm(accept, now, ports.ids, ports.state, &mut self.ledger);
|
||||
}
|
||||
|
||||
/// The command waiting for the user's yes or no, for the host to ask.
|
||||
pub fn confirming(&self) -> Option<&Confirming> {
|
||||
self.commands.confirming()
|
||||
}
|
||||
|
||||
/// Run the command an `OpenExternal` effect named, once the external step has returned. The
|
||||
/// host holds the `Resume` across the navigation.
|
||||
pub fn resume(&mut self, resume: &Resume, now: Timestamp, ports: Ports<'_>) -> Vec<Diagnostic> {
|
||||
/// Run the command an `OpenExternal` effect named, once the external step has returned. The host
|
||||
/// holds the `Resume` across the navigation and hands it back here; the command is minted, or asks
|
||||
/// for confirmation, like an activation. A refusal is said in the next frame's `diagnostics`.
|
||||
pub fn resume(&mut self, resume: &Resume, now: Timestamp, ports: Ports<'_>) {
|
||||
let Some(tree) = self.binder.tree(&resume.surface_key) else {
|
||||
return Vec::new();
|
||||
return;
|
||||
};
|
||||
self.commands.resume(resume, tree, &self.drafts, now, ports.ids, ports.state, &mut self.ledger)
|
||||
let said = self.commands.resume(resume, tree, &self.drafts, now, ports.ids, ports.state, &mut self.ledger);
|
||||
self.notes.extend(said);
|
||||
}
|
||||
|
||||
/// The busy, pending and fault state of the shown surface's nodes, for render and accessibility.
|
||||
|
|
|
|||
|
|
@ -1266,6 +1266,64 @@ fn a_select_change_naming_no_declared_option_is_refused() {
|
|||
assert_eq!(rig.draft(&nid("pick")), Some(choice_value("a")));
|
||||
}
|
||||
|
||||
// ----- a refusal is said -----
|
||||
|
||||
#[test]
|
||||
fn every_refusal_is_a_diagnostic_naming_the_surface_and_node() {
|
||||
let mut confirming = go_surface();
|
||||
confirming.commands[1] = decl("after", &[], Some("sure?"));
|
||||
let mut rig = Rig::new(MemState::new(), &confirming);
|
||||
let mut ids = SeqIds::new();
|
||||
let surface_key = rig.surface.clone();
|
||||
// A kind the node does not take, a value of the wrong kind, a node nobody laid.
|
||||
for (node, kind) in [("go", ActivationKind::Submit), ("name", ActivationKind::Press), ("no-such-node", ActivationKind::Press)] {
|
||||
let refused = rig.act(&nid(node), kind, PINNED_NOW, &mut ids);
|
||||
assert_eq!(codes(&refused), vec![Code::ActivationRefused], "{node}");
|
||||
assert_eq!(refused[0].surface, surface_key);
|
||||
assert_eq!(refused[0].node, Some(nid(node)));
|
||||
}
|
||||
// Waiting on a confirmation blocks every other activation, and says so.
|
||||
assert!(rig.press("after", PINNED_NOW, &mut ids).is_empty());
|
||||
let blocked = rig.press("go", at(1), &mut ids);
|
||||
assert_eq!(codes(&blocked), vec![Code::ActivationRefused]);
|
||||
assert!(rig.commands.take_outbound().is_empty());
|
||||
// A busy button stays silent: it is a state the user sees, not a fault.
|
||||
let mut rig = Rig::new(MemState::new(), &go_surface());
|
||||
rig.press("go", PINNED_NOW, &mut ids);
|
||||
assert!(rig.press("go", at(1), &mut ids).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_command_param_outside_a_composition_leaves_no_tree_to_activate() {
|
||||
let mut document = go_surface();
|
||||
let Node::Box(root) = &mut document.root else { unreachable!() };
|
||||
root.children.push(Node::Button(ButtonNode {
|
||||
common: common("param"),
|
||||
content: vec![],
|
||||
on_activate: CommandRef::Param(param("cmd")),
|
||||
enabled: lit_bool(true),
|
||||
}));
|
||||
let resolution = resolve(&document, &MemState::new(), &Limits::default());
|
||||
assert!(resolution.tree.is_none());
|
||||
assert!(codes(&resolution.diagnostics).contains(&Code::UnboundParam));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_core_says_a_refused_activation_in_the_frame_output() {
|
||||
let provider = ProviderId::new(PROVIDER);
|
||||
let document = go_surface();
|
||||
let mut state = MemState::new();
|
||||
state.put(&provider, &document);
|
||||
let mut core = core();
|
||||
core.show(provider, RecordKey::new(document.record_key()));
|
||||
frame_at(&mut core, &mut state, PINNED_NOW);
|
||||
core.activate(press("no-such-node"), at(1), Ports { state: &mut state, ids: &mut SeqIds::new() });
|
||||
let out = frame_at(&mut core, &mut state, at(2));
|
||||
assert_eq!(codes(&out.diagnostics), vec![Code::ActivationRefused]);
|
||||
// Said once.
|
||||
assert!(frame_at(&mut core, &mut state, at(3)).diagnostics.is_empty());
|
||||
}
|
||||
|
||||
// ----- a resume is an activation of a declared command -----
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue