Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions rust-modules/src/app/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,18 @@ pub(crate) fn content_requests(app: &mut App, fr: &mut Frame) {
bridge.metadata_view(), bridge.marker_preferences());
}

/// **May the page `entry`'s command run now?** Only the page that holds input acts: a page a
/// surface still covers, or a page beneath another, is refused (a command it queued before it was
/// covered must not navigate for it). A surface whose own `Dismiss` is already parked counts as
/// closed. The FIFO runner executes a head in the drain, ahead of NAV COMMIT, so a picker that
/// closes on its pick and reports to its page (*Play Version*, *Also available*) has only PARKED its
/// dismissal when the page's command for that pick arrives. Before the runner (#1392) these gates ran
/// after the frame's commit and never saw the closing surface; asked of the container alone they
/// refused the pick (#1424). One answer for the five page-command families below.
fn holds_input(pages: &plx_ui::dispatch::Dispatcher<bridge::AppHost>, entry: EntryId) -> bool {
pages.input_owner_after_dismissals() == Some(InputOwner::Entry(entry))
}

fn halt_screen_preview(app: &mut ScreenCommandApp<'_, '_>) {
halt_preview_now(&mut app.player.session, &mut app.adapters.player);
}
Expand All @@ -590,7 +602,7 @@ fn content_command(app: &mut ScreenCommandApp<'_, '_>, source: MachineId, reques
let _ = now;
let MachineId::Instance(instance) = source else { return AppCommandOutcome::Refused };
let Some(entry) = app.pages.nav.entry_of_instance(instance) else { return AppCommandOutcome::RetiredSender };
if app.pages.nav.input_owner() != Some(InputOwner::Entry(entry)) { return AppCommandOutcome::Refused; }
if !holds_input(app.pages, entry) { return AppCommandOutcome::Refused; }
match request {
ContentReq::Push(arg) => {
halt_screen_preview(app);
Expand Down Expand Up @@ -742,7 +754,7 @@ fn home_command(app: &mut ScreenCommandApp<'_, '_>, source: MachineId, request:
use plx_machine::machine::AppCommandOutcome;
let MachineId::Instance(instance) = source else { return AppCommandOutcome::Refused };
let Some(entry) = app.pages.nav.entry_of_instance(instance) else { return AppCommandOutcome::RetiredSender };
if app.pages.nav.input_owner() != Some(InputOwner::Entry(entry)) || app.route() != AppArg::Home {
if !holds_input(app.pages, entry) || app.route() != AppArg::Home {
return AppCommandOutcome::Refused;
}
match request {
Expand Down Expand Up @@ -813,8 +825,7 @@ pub(crate) fn execute_search_command(
use plx_screens::registry::SearchReq;
let MachineId::Instance(instance) = source else { return AppCommandOutcome::Refused };
let Some(entry) = pages.nav.entry_of_instance(instance) else { return AppCommandOutcome::RetiredSender };
if pages.top_arg() != Some(&AppArg::Search)
|| pages.nav.input_owner() != Some(InputOwner::Entry(entry)) { return AppCommandOutcome::Refused; }
if pages.top_arg() != Some(&AppArg::Search) || !holds_input(pages, entry) { return AppCommandOutcome::Refused; }
match &request {
SearchReq::Back => bridge::nav_tab(pages, rig, HomeTab::Home, None, Some(ret)),
SearchReq::Tab(tab) => {
Expand Down Expand Up @@ -863,8 +874,7 @@ pub(crate) fn execute_watchlist_command(
let Some(entry) = pages.nav.entry_of_instance(instance) else { return AppCommandOutcome::RetiredSender };
// Options come from a surface over the page, so its live sender need not be the page.
if !matches!(request, WatchlistOut::SetOptions(_))
&& (pages.top_arg() != Some(&AppArg::Watchlist)
|| pages.nav.input_owner() != Some(InputOwner::Entry(entry))) {
&& (pages.top_arg() != Some(&AppArg::Watchlist) || !holds_input(pages, entry)) {
return AppCommandOutcome::Refused;
}
watchlist_request(pages, rig, entry, request, ret);
Expand Down Expand Up @@ -987,7 +997,7 @@ fn library_command(app: &mut ScreenCommandApp<'_, '_>, source: MachineId,
library_publish_shelves(app.pages, app.bridge, entry, target, hidden_page, at_head);
return AppCommandOutcome::Completed;
}
if app.pages.nav.input_owner() != Some(InputOwner::Entry(entry)) || !app.route().is_library_family() {
if !holds_input(app.pages, entry) || !app.route().is_library_family() {
return AppCommandOutcome::Refused;
}
if let Some(ret) = library_navigation(app.pages, app.bridge, &request, ret) {
Expand Down
237 changes: 237 additions & 0 deletions rust-modules/src/app/detail_panel_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,240 @@ fn an_alt_sources_anchor_travels_on_its_arg() {
"and the same anchor is the same state"
);
}


// ---- a pick that closes its panel (#1424) ----------------------------------------------------
//
// *Play Version* and *Also available* are surfaces that close on a pick and REPORT the row to the
// Detail page that opened them (`Fx::Nav(Dismiss)`, then a delivery to the page). The page answers
// with an app command, and the FIFO runner (#1392) gates every page command on "the sender holds
// input". The surface's own dismissal is only parked until NAV COMMIT, so that gate saw the closing
// surface still holding input and refused the page: the panel closed and nothing played, or opened.

/// What each app command asked and how the runner ended it, read off the dispatcher's own tap: the
/// runner's terminal outcome, not a copy of it. A command's `Fx::App` effect is tapped as it leaves
/// the FIFO, and the runner holds exactly one command at a time, so the next `command_done` is that
/// command's.
#[derive(Default)]
struct PickTap {
last: Option<Asked>,
/// `(what was asked, who asked, how it ended)`, in the order the runner finished them.
commands: Vec<(Asked, MachineId, plx_machine::machine::AppCommandOutcome)>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
enum Asked {
Play(Option<plx_plex::plex::MediaId>),
Present(plx_plex::plex::ServerId, String),
/// Any other app command, named by family: not what these tests grade, but a failure prints it.
/// (The Play Version page also asks for a hero `PreviewStart` while the panel covers it; that one
/// IS refused, rightly, before and after the fix: a covered page starts nothing.)
Other(&'static str),
}

impl plx_ui::dispatch::Tap<AppHost> for PickTap {
fn effect(&mut self, _: u64, stamped: &plx_machine::machine::Stamped<AppHost>) {
use plx_screens::registry::{AppFx, ContentArg, ContentReq, PlayIntent};
if let Fx::App(app) = &stamped.fx {
self.last = Some(match app {
AppFx::Content(ContentReq::Play { play, .. }) => Asked::Play(match play {
PlayIntent::Item { version, .. } | PlayIntent::Movie { version, .. } => *version,
}),
AppFx::Content(ContentReq::Present(ContentArg::Detail { sid, rk })) => Asked::Present(*sid, rk.clone()),
AppFx::Content(ContentReq::PreviewStart { .. }) => Asked::Other("content:PreviewStart"),
AppFx::Content(_) => Asked::Other("content"),
AppFx::Store(..) => Asked::Other("store"),
_ => Asked::Other("app"),
});
}
}
fn command_done(&mut self, _: u64, _: plx_machine::machine::AppCommandId, from: MachineId,
outcome: plx_machine::machine::AppCommandOutcome) {
let asked = self.last.take().unwrap_or(Asked::Other("none"));
self.commands.push((asked, from, outcome));
}
}

impl PickTap {
/// How the commands `host` asked that equal `asked` ended, in order.
fn ended(&self, host: InstanceId, asked: &Asked) -> Vec<plx_machine::machine::AppCommandOutcome> {
self.commands.iter()
.filter(|(what, from, _)| what == asked && *from == MachineId::Instance(host))
.map(|(_, _, outcome)| *outcome)
.collect()
}

/// Every command of the run, for a failure message.
fn account(&self) -> String {
format!("{:?}", self.commands)
}
}

/// One key (both edges) and the frames after it, through the product frame with `tap` watching.
/// No `goto`: a pick that enters the player must not be walked back to the page by the driver.
fn pick_key(d: &mut Dispatcher<AppHost>, rig: &mut Bridge, t: &mut u32, key: Key, tap: &mut PickTap) {
*t += 1;
let at = tick(*t);
super::frame_with_tap(d, rig, at, script_key(key, at), tap);
pick_frames(d, rig, t, 28, tap);
}

fn pick_frames(d: &mut Dispatcher<AppHost>, rig: &mut Bridge, t: &mut u32, n: u32, tap: &mut PickTap) {
for _ in 0..n {
*t += 1;
super::frame_with_tap(d, rig, tick(*t), vec![], tap);
}
}

fn page_instance(d: &Dispatcher<AppHost>) -> InstanceId {
d.nav.top_page().and_then(|e| e.inst.as_ref()).expect("the page mounted").id
}

/// **Play Version, the reporter's case (#1424):** a title with two versions, the panel open, the
/// second row picked. The page's play command for THAT version is executed and the Player is
/// entered.
///
/// Red first on `origin/main` (`3878e4f55`): the page asked for the second version and the runner
/// answered `Refused` (`content_command`'s input-owner gate, run before the panel's `Dismiss`
/// committed), so no Player was ever pushed.
#[test]
fn a_picked_version_plays_that_version_though_its_panel_is_still_closing() {
use plx_machine::machine::AppCommandOutcome;
let versions = plx_appkit::version_list::sample();
let pick = versions[1].id;
let mut w = World::detail_page("play-version-pick", plx_data::metadata::Detail {
sid: plx_plex::plex::ServerId::UNSET,
rk: "movie".into(),
kind: "movie".into(),
title: "Movie".into(),
part: "/library/parts/movie".into(),
versions,
..Default::default()
});
let host = page_instance(&w.d);
open_content_panel(
&mut w.d,
host,
Some((plx_plex::plex::ServerId::UNSET, "movie")),
plx_screens::registry::ContentPanel::Versions { anchor: [300.0f32, 800.0, 300.0, 60.0].map(f32::to_bits) },
);
w.frames(40);
assert_eq!(w.d.nav.modals.surfaces.len(), 1, "premise: the Play Version panel is up");
let mut tap = PickTap::default();
let mut t = w.frame;
let mut bridge = w.bridge.bridge();
pick_key(&mut w.d, &mut bridge, &mut t, Key::Down, &mut tap);
pick_key(&mut w.d, &mut bridge, &mut t, Key::Ok, &mut tap);
assert_eq!(
tap.ended(host, &Asked::Play(Some(pick))), [AppCommandOutcome::Completed],
"the page asked to play the SECOND version, once, and the runner executed it: {}", tap.account());
assert!(w.d.nav.modals.surfaces.is_empty(), "the panel closed");
assert!(matches!(w.d.top_arg(), Some(AppArg::Player)), "the pick entered the player");
}

/// The two-copy *Also available* rig of `a_detail_panel_parks_across_a_push_and_returns_with_the_same_instance`:
/// the page on `m1` of server `here`, the picker up over it, its cursor on the first copy.
struct AltRig {
d: Dispatcher<AppHost>,
owner: crate::app::runtime_owners::Harness,
t: u32,
host: InstanceId,
other: plx_plex::plex::ServerId,
}

impl AltRig {
fn open() -> Self {
let here = plx_plex::plex::register_for_test("alt-pick-here", "127.0.0.1", 1, "t", "c1");
let other = plx_plex::plex::register_for_test("alt-pick-other", "127.0.0.2", 2, "t", "c2");
let mut d = Dispatcher::<AppHost>::new();
let mut owner = crate::app::runtime_owners::Harness::new(|| 0);
let mut t = 0u32;
let host = {
let mut rig = owner.bridge();
rig.metadata_run(plx_data::stores::metadata::MetadataCmd::AltInstall {
sid: here,
rk: "m1".into(),
copies: vec![
plx_data::metadata::AltCopy { sid: here, rk: "m1".into(), library: "Movies".into(), ..Default::default() },
plx_data::metadata::AltCopy { sid: other, rk: "copy".into(), library: "Shared".into(), ..Default::default() },
],
});
for _ in 0..4 {
t += 1;
frame(&mut d, &mut rig, detail_arg("m1"), tick(t), vec![]);
}
let host = page_instance(&d);
open_content_panel(
&mut d,
host,
Some((here, "m1")),
plx_screens::registry::ContentPanel::AltSources { anchor: [300.0f32, 800.0, 300.0, 60.0].map(f32::to_bits) },
);
for _ in 0..40 {
t += 1;
frame(&mut d, &mut rig, detail_arg("m1"), tick(t), vec![]);
}
host
};
assert_eq!(d.nav.modals.surfaces.len(), 1, "premise: the picker is up");
Self { d, owner, t, host, other }
}
}

struct ResetServers;
impl Drop for ResetServers {
fn drop(&mut self) {
plx_plex::plex::reset_servers_for_test();
}
}

/// **Also available, the same shape (#1424):** picking the other copy closes the picker and the
/// page presents that copy's own page. The page's `ContentReq::Present` met the same gate.
///
/// Red first on `origin/main`: the page asked to present the other copy and the runner answered
/// `Refused`, so the picker closed and the page stayed where it was.
#[test]
fn a_picked_alternative_source_opens_that_copy_though_its_picker_is_still_closing() {
use plx_machine::machine::AppCommandOutcome;
let _guard = plx_base::testlock::serial();
let _reset = ResetServers;
plx_plex::plex::reset_servers_for_test();
let mut s = AltRig::open();
let mut tap = PickTap::default();
let mut rig = s.owner.bridge();
pick_key(&mut s.d, &mut rig, &mut s.t, Key::Down, &mut tap);
pick_key(&mut s.d, &mut rig, &mut s.t, Key::Ok, &mut tap);
assert_eq!(
tap.ended(s.host, &Asked::Present(s.other, "copy".into())), [AppCommandOutcome::Completed],
"the page asked to present the other copy, once, and the runner executed it: {}", tap.account());
let copy = AppArg::Content(plx_screens::registry::ContentArg::Detail { sid: s.other, rk: "copy".into() });
assert!(
s.d.nav.modals.surfaces.iter().any(|surface| surface.entry.arg == copy && surface.phase != Phase::Closing),
"the other copy's page is up over the first"
);
}

/// **The gate still refuses a page that a SURFACE COVERS (#1424's negative control).** The same
/// report, delivered to the page while the picker is open and nothing has dismissed it: the page
/// does not hold input, so its command is still refused. Only a surface whose own `Dismiss` is
/// already parked counts as closed.
#[test]
fn a_page_under_a_picker_that_stays_open_is_still_refused() {
use plx_machine::machine::AppCommandOutcome;
use plx_screens::registry::AppMsg;
let _guard = plx_base::testlock::serial();
let _reset = ResetServers;
plx_plex::plex::reset_servers_for_test();
let mut s = AltRig::open();
let mut tap = PickTap::default();
let mut rig = s.owner.bridge();
s.d.emit(MachineId::Nav, Fx::Deliver(
MachineId::Instance(s.host),
Delivery::Screen(ScreenEvent::App(AppMsg::AltSourceOpen(
plx_screens::registry::ContentArg::Detail { sid: s.other, rk: "copy".into() })))));
pick_frames(&mut s.d, &mut rig, &mut s.t, 4, &mut tap);
assert_eq!(
tap.ended(s.host, &Asked::Present(s.other, "copy".into())), [AppCommandOutcome::Refused],
"the page asked, and a covered page is refused: {}", tap.account());
assert_eq!(s.d.nav.modals.surfaces.len(), 1, "the picker is still up, and nothing was presented over it");
}
8 changes: 7 additions & 1 deletion rust-modules/ui/src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,14 @@ impl<H: Host> Navigation<H> {

/// The input owner (§2.2): the shared modal stack first, then the top page.
pub fn input_owner(&self) -> Option<InputOwner> {
self.input_owner_unless(|_| false)
}

/// [`input_owner`](Self::input_owner) with every surface `dismissed` names counted as already
/// closed: who holds input once those dismissals commit. Page ops are never read.
pub fn input_owner_unless(&self, dismissed: impl Fn(EntryId) -> bool) -> Option<InputOwner> {
self.modals
.input_owner()
.input_owner_unless(dismissed)
.or_else(|| self.top_page().map(|e| InputOwner::Entry(e.id)))
}

Expand Down
8 changes: 7 additions & 1 deletion rust-modules/ui/src/containers/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,16 @@ impl<H: Host> ModalStack<H> {

/// The topmost Opening|Open surface owns input.
pub fn input_owner(&self) -> Option<InputOwner> {
self.input_owner_unless(|_| false)
}

/// [`input_owner`](Self::input_owner) with every surface `dismissed` names counted as already
/// closed: the owner a parked `Dismiss` is about to leave behind.
pub fn input_owner_unless(&self, dismissed: impl Fn(EntryId) -> bool) -> Option<InputOwner> {
self.surfaces
.iter()
.rev()
.find(|s| matches!(s.phase, Phase::Opening | Phase::Open))
.find(|s| matches!(s.phase, Phase::Opening | Phase::Open) && !dismissed(s.entry.id))
.map(|s| InputOwner::Entry(s.entry.id))
}

Expand Down
26 changes: 26 additions & 0 deletions rust-modules/ui/src/containers/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2742,3 +2742,29 @@ fn a_page_opened_over_a_closing_surface_returns_to_a_live_host() {
let last = |name: &str| ev.rfind(&format!("\"{name}\""));
assert!(last("uncover") > last("cover"), "the host ends uncovered: {ev}");
}

/// **`input_owner_after_dismissals`: who holds input once the dismissals already parked commit
/// (#1424).** A surface that closes on a pick parks its own `Dismiss` and reports the pick to the
/// page, whose command reaches the FIFO head before NAV COMMIT: `input_owner` still names the
/// closing surface there, this names the page. Nothing parked, or only a `Dismiss` of another entry,
/// changes nothing; after the commit the two agree.
#[test]
fn the_owner_after_dismissals_is_the_page_once_the_surfaces_dismiss_is_parked() {
let (mut d, mut rig, _) = booted();
let home = d.nav.top_page().unwrap().id;
let menu = open_modal(&mut d, &mut rig, Style::Compact, 16);
assert_eq!(d.nav.input_owner(), Some(InputOwner::Entry(menu)), "premise: the surface holds input");
assert_eq!(d.input_owner_after_dismissals(), Some(InputOwner::Entry(menu)), "nothing parked: the same owner");

d.request(MachineId::Nav, NavOp::Dismiss(EntryId(menu.0 + 100)));
assert_eq!(d.input_owner_after_dismissals(), Some(InputOwner::Entry(menu)), "another entry's dismissal is not this surface's");

d.request(MachineId::Nav, NavOp::Dismiss(menu));
assert_eq!(d.nav.input_owner(), Some(InputOwner::Entry(menu)), "parked, not committed: the container still says the surface");
assert_eq!(d.input_owner_after_dismissals(), Some(InputOwner::Entry(home)), "the page, once the dismissal commits");

d.frame(&mut rig, tick(32), vec![], vec![], &mut NoTap);
assert_eq!(d.nav.modals.surface(menu).map(|s| s.phase), Some(Phase::Closing), "committed");
assert_eq!(d.nav.input_owner(), Some(InputOwner::Entry(home)));
assert_eq!(d.input_owner_after_dismissals(), d.nav.input_owner(), "after the commit the two agree");
}
Loading
Loading