From 641ba143a583dd359ea1701efa2466e6f6925251 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 15:59:41 +0300 Subject: [PATCH 1/3] The platform states where the account's records live: tv::Services.storage The session, the install's preferences and the consent record live in the LS2/DB8 storage helper on a webOS television and in files everywhere else. The persistence layers chose between the two with `all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support")))`, which is "32-bit ARM Linux", not "a television": a Tizen ARM build would select the helper with none behind it. `tv::Services` gains a fifth group, `storage: StorageHooks { authority }`, in the new `os/src/tv/authority.rs`. `Authority::Helper` is webOS (`port.rs`); `Authority::Files` is the desktop platform, `Services::HOST_TEST` and any platform with no helper (`StorageHooks::NONE`). `tv::authority::authority()` reads the installed table, and an uninstalled process reads `Files` like every other group's host-test answer. There is deliberately no test override: the layers that read it take the authority as a parameter, so a test passes whichever one it grades. Nothing reads the value yet; the plex and telemetry lanes re-key their fences to it next. Tests pin the host-test answer in the destructuring test of `tv.rs`, the webOS and desktop tables, and the order `run_application` installs the services before it enters the application: an uninstalled television would read `Files` and write a plaintext session file. Co-Authored-By: Claude --- docs/module-layers.md | 2 +- docs/platform-ports.md | 4 ++ rust-modules/os/src/tv.rs | 10 ++++- rust-modules/os/src/tv/authority.rs | 65 ++++++++++++++++++++++++++++ rust-modules/src/platform_desktop.rs | 12 ++++- rust-modules/src/port.rs | 44 ++++++++++++++++++- 6 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 rust-modules/os/src/tv/authority.rs diff --git a/docs/module-layers.md b/docs/module-layers.md index 06df7a3e2..714e30989 100644 --- a/docs/module-layers.md +++ b/docs/module-layers.md @@ -350,7 +350,7 @@ L15's 44 entries, 205 references of which 95 were in production code. The port's their layers, so none of this held up the split. L15 moved every one of those references behind an interface in `os`'s new `tv` module that -the port fills at boot. `tv::Services` is a table of function pointers in four groups (`identity`, `secure`, `system` and `legacy_webos_media`), installed once by `app::run_application` (from the `Platform` its entry hands it) before anything +the port fills at boot. `tv::Services` is a table of function pointers and stated values in five groups (`identity`, `secure`, `system`, `storage` and `legacy_webos_media`), installed once by `app::run_application` (from the `Platform` its entry hands it) before anything that reads it. With nothing installed (host unit tests, where nothing calls `plex_run`) `tv::Services::HOST_TEST` answers what the host arms answered before; a shipping build that reaches it logs `tv: port not installed - using the no-port defaults` once. diff --git a/docs/platform-ports.md b/docs/platform-ports.md index 45f9329ff..477fa0d54 100644 --- a/docs/platform-ports.md +++ b/docs/platform-ports.md @@ -848,6 +848,10 @@ split by who reads it (critic M4): `devcaps` parses through, `Files::NONE` for a platform with none); - `secure { seal, open, remove, mode }` (Target shape 4; until W2 `mode` is W3a's own once-set value); - `system { go_home, poll_home, deliver_toast }`; + - `storage { authority }` (W8a): `Authority::Helper` (webOS: the LS2/DB8 storage helper owns the session, the + install's preferences and the consent record) or `Authority::Files` (desktop, Tizen, a host test), read through + `tv::authority::authority()`. It replaces the `target_os = "linux"` + `target_arch = "arm"` fence the persistence + layers chose their store by; the helper's wake-up (`storage::client::install_activator`) joins it after W7b; - `legacy_webos_media { sink, display_sink, uri_media }`: the Starfish, ACB and `com.webos.media` verbs (F31), named for what they are (critic M3). Every hook is required (Decision 2, C): a platform states each field, a named `NONE` being a statement and a `Default`-filled gap not allowed. The one exemption is this group: diff --git a/rust-modules/os/src/tv.rs b/rust-modules/os/src/tv.rs index 4d372c779..4a2264b99 100644 --- a/rust-modules/os/src/tv.rs +++ b/rust-modules/os/src/tv.rs @@ -1,4 +1,5 @@ //! The television, as everything outside the port sees it (step L15, docs/module-layers.md). +pub mod authority; pub mod device; pub mod home; pub mod launch; @@ -10,13 +11,15 @@ pub mod sound; pub mod toast; pub mod uri; +pub use authority::StorageHooks; + use std::sync::OnceLock; /// What the platform's settings service said about the locale. i18n owns the parse and the log lines. #[cfg_attr(any(feature = "hostsim", test, feature = "test-support"), allow(dead_code))] // Reply/Unavailable: TV arm only pub enum LocaleReply { NoPlatform, Unavailable, Reply(String) } -/// What the lower layers read from the platform, in four groups. Installed once ([`install`]) before +/// What the lower layers read from the platform, in five groups. Installed once ([`install`]) before /// anything reads it, and read only by `tv`'s own modules, so no other module can issue a verb the /// interfaces below do not offer. The window, the bus pump and the frame probe are NOT here: only /// the loop reads them, so they belong to the application's own `Platform`. @@ -28,6 +31,7 @@ pub struct Services { pub identity: IdentityHooks, pub secure: SecureHooks, pub system: SystemHooks, + pub storage: StorageHooks, pub legacy_webos_media: LegacyWebosMedia, } @@ -117,6 +121,7 @@ impl Services { identity: IdentityHooks::NONE, secure: SecureHooks::NONE, system: SystemHooks::NONE, + storage: StorageHooks::NONE, legacy_webos_media: LegacyWebosMedia::NONE, }; } @@ -159,6 +164,7 @@ mod tests { identity: IdentityHooks { probe_device, start_capability_probe, repair_native_video, device_files, system_locale, sound_output }, secure: SecureHooks { seal, open, remove, mode }, system: SystemHooks { go_home, poll_home, deliver_toast }, + storage: StorageHooks { authority }, legacy_webos_media: LegacyWebosMedia { sink, display_sink, uri_media }, } = Services::HOST_TEST; @@ -193,6 +199,8 @@ mod tests { toast::Sent { reply: None, outcome: toast::Outcome::NoBus } ); + assert_eq!(authority, authority::Authority::Files, "no storage helper: the app keeps its records in files"); + assert!(!sink.feed_abi_is_cow(), "the refusing sink, not a native one"); assert_eq!(display_sink.window_mode(), sink::VP_NONE); assert_eq!(display_sink.window_id(), c""); diff --git a/rust-modules/os/src/tv/authority.rs b/rust-modules/os/src/tv/authority.rs new file mode 100644 index 000000000..85d8dd6a2 --- /dev/null +++ b/rust-modules/os/src/tv/authority.rs @@ -0,0 +1,65 @@ +//! Where the account's canonical state lives: the platform's storage helper, or plain files. +//! +//! The session record, the install's preferences and the consent record each have two homes. On a +//! webOS television the LS2/DB8 storage helper owns them ([`Authority::Helper`]): the app never +//! reads or writes a file of its own for them. Everywhere else the app keeps them in files under its +//! persistent state root ([`Authority::Files`]): the desktop simulator, a host test, and a platform +//! with no helper at all (Tizen). The layers that persist these records (`plex::session`, +//! `telemetry`) choose their store from this value, once per operation, instead of from the build's +//! CPU and OS, which is what picked it before: a 32-bit ARM Linux binary is not necessarily a +//! television. +//! +//! The platform states it once, as the `authority` of its [`StorageHooks`](super::StorageHooks), and +//! [`authority`] reads it. A process that installed no platform (a host test) reads +//! [`StorageHooks::NONE`], which is `Files`, like every other group's host-test answer. A shipping +//! process must install its services before anything persists: an uninstalled television would read +//! `Files` and write a plaintext session file, which is why `run_application` installs them first +//! (`port::tests` pins the order). +//! +//! This group is the home of the platform's other storage statements as well. The helper's wake-up +//! (`storage::client::install_activator`, which `port::plex_main` installs for webOS today) belongs +//! here as a later member and moves with the os lane after W7b; it is not moved yet. + +/// Where the account's canonical state lives. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum Authority { + /// The platform's storage helper (webOS: the LS2/DB8 service). No file of the app's own holds + /// the record, and a helper that cannot answer is never papered over with one. + Helper, + /// Files under the app's persistent state root, written by the app itself. + #[default] + Files, +} + +/// The storage group of [`Services`](super::Services): what a platform states about where the app's +/// own records live. +pub struct StorageHooks { + pub authority: Authority, +} + +impl StorageHooks { + /// A platform with no storage helper: the app keeps its records in files. + pub const NONE: Self = Self { authority: Authority::Files }; +} + +/// The installed platform's [`Authority`], or `Files` when nothing is installed. +pub fn authority() -> Authority { + super::services().storage.authority +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_default_authority_is_files() { + assert_eq!(Authority::default(), Authority::Files); + assert_eq!(StorageHooks::NONE.authority, Authority::Files, "a platform with no helper keeps files"); + } + + /// Nothing is installed in a test process, so the reader answers the host-test group's `Files`. + #[test] + fn an_uninstalled_process_reads_files() { + assert_eq!(authority(), Authority::Files); + } +} diff --git a/rust-modules/src/platform_desktop.rs b/rust-modules/src/platform_desktop.rs index b4cb8f580..3a412fb05 100644 --- a/rust-modules/src/platform_desktop.rs +++ b/rust-modules/src/platform_desktop.rs @@ -18,6 +18,8 @@ //! no compositor to hint and no bus to pump. The secure store is `SecureHooks::NONE`: nothing seals, //! so a session is the 0600 plaintext file the session layer writes itself, which the simulator's //! harnesses plant and read. +//! The storage group is `StorageHooks::NONE`: there is no storage helper, so the account's records +//! live in files under the persistent state root. //! //! This module never names `port`, `system`, `webos` or `keymanager`, so a desktop executable //! references none of the television's code. It still COMPILES it (the television arms of those @@ -28,7 +30,7 @@ use crate::app::platform::{FrameProbe, Platform, Shell}; use plx_os::devcaps::dv::{self, DvCapability, DvProbe, ProbeSource}; use plx_os::tv::toast::{Identity, Outcome, Sent}; -use plx_os::tv::{IdentityHooks, LegacyWebosMedia, SecureHooks, Services, SystemHooks}; +use plx_os::tv::{IdentityHooks, LegacyWebosMedia, SecureHooks, Services, StorageHooks, SystemHooks}; use std::ffi::CStr; use std::os::raw::{c_int, c_void}; @@ -56,6 +58,7 @@ static SERVICES: Services = Services { }, secure: SecureHooks::NONE, system: SystemHooks { go_home, poll_home: SystemHooks::NONE.poll_home, deliver_toast }, + storage: StorageHooks::NONE, legacy_webos_media: LegacyWebosMedia { sink: SINK, display_sink: DISPLAY, @@ -141,6 +144,13 @@ pub fn run(pms_host: &CStr, pms_port: u16) -> c_int { mod tests { use super::*; + /// A desktop has no storage helper: the session, the install's preferences and the consent record + /// are files. The same value a host test reads from `Services::HOST_TEST`. + #[test] + fn the_desktop_table_keeps_the_account_in_files() { + assert_eq!(SERVICES.storage.authority, plx_os::tv::authority::Authority::Files); + } + /// The app's plane boot resolves the display through `display_installed()` (this table's /// `display_sink`), where media's old `acb_init` resolved it through `player::display()`. In /// the simulator both must be the host sink, never `NoSink`: a boot that read `NoSink` would diff --git a/rust-modules/src/port.rs b/rust-modules/src/port.rs index 7f717ca52..800c426a8 100644 --- a/rust-modules/src/port.rs +++ b/rust-modules/src/port.rs @@ -20,8 +20,8 @@ const DISPLAY: &dyn plx_os::tv::sink::DisplaySink = &plx_os::webos::video_sink:: #[cfg(test)] const DISPLAY: &dyn plx_os::tv::sink::DisplaySink = SINK; -/// What the lower layers read: the webOS identity, key manager, Home key and toast, and the native -/// playback seam. The window, the bus pump and the frame probe are the loop's own, in [`PLATFORM`]. +/// What the lower layers read: the webOS identity, key manager, Home key and toast, the storage helper +/// and the native playback seam. The window, the bus pump and the frame probe are the loop's own, in [`PLATFORM`]. static SERVICES: plx_os::tv::Services = plx_os::tv::Services { identity: plx_os::tv::IdentityHooks { probe_device: plx_os::webos::probe, @@ -42,6 +42,7 @@ static SERVICES: plx_os::tv::Services = plx_os::tv::Services { poll_home: plx_os::webos::poll_home, deliver_toast: plx_os::webos::toast::deliver, }, + storage: plx_os::tv::StorageHooks { authority: plx_os::tv::authority::Authority::Helper }, legacy_webos_media: plx_os::tv::LegacyWebosMedia { sink: SINK, display_sink: DISPLAY, @@ -148,3 +149,42 @@ pub unsafe extern "C" fn plx_launch_args(json: *const c_char) { let raw = unsafe { std::ffi::CStr::from_ptr(json) }.to_string_lossy(); plx_os::tv::launch::offer(&raw); } + +#[cfg(test)] +mod tests { + use super::SERVICES; + use plx_os::tv::authority::Authority; + + /// The webOS table states the storage helper as the home of the session, the install's preferences + /// and the consent record. The persistence layers choose their store from this value, so a table + /// that stated anything else would move a television's account out of DB8. + #[test] + fn the_webos_table_states_the_storage_helper_as_the_authority() { + assert_eq!(SERVICES.storage.authority, Authority::Helper); + assert_eq!(SERVICES.secure.mode, plx_os::tv::secure::StoreMode::Durable); + } + + /// `run_application` installs the services before anything else runs. The authority is read by + /// whatever persists first, and an uninstalled television reads `Files` and would write a + /// plaintext session file, so the install has to come before `exit::entry` runs `enter_application`. + /// Reads the source, like `app::boot`'s `seam_order_tests`, because no host test can run the entry. + #[test] + fn the_services_are_installed_before_the_application_enters() { + let source = include_str!("app/mod.rs"); + let body = source + .split_once("fn run_application(") + .expect("run_application") + .1 + .split_once("\n}\n") + .expect("end of run_application") + .0; + let install = body.find("platform.install_services();").expect("run_application installs the services"); + let enter = body.find("exit::entry(").expect("run_application enters through exit::entry"); + assert!(install < enter, "install_services must run before exit::entry"); + assert_eq!( + source.matches("install_services()").count(), + 1, + "one production install; a second would be refused by tv and could hide a missing first" + ); + } +} From 645bc357c7ba541ec2f2b4a807c9fcc2924bf41a Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 16:20:25 +0300 Subject: [PATCH 2/3] Telemetry's consent store follows the platform's storage authority, not the build's CPU Where consent lives was picked by `all(target_os = "linux", target_arch = "arm", not(hostsim), not(any(test, test-support)))`: a 32-bit ARM Linux binary was assumed to be a webOS television with the LS2/DB8 storage helper. The platform now states it (`plx_os::tv::authority::authority()`), and `load`, `record_at` and `forget_at` read it once per operation and hand it to `load_with`, `record_with` and `forget_with`: `Helper` runs the helper arm, `Files` the files arm. Both arms' bodies are unchanged; only the selection moved. The helper arm's items (the DB8 commit, the legacy import, the canonical-consent helpers) and the canonical-consent codec in `consent.rs` compile on every target, so the 29 gated lines in persistence.rs, consent.rs and mod.rs are gone. `cleanup_after_account_clear` is unconditional: under `Helper` it sweeps the legacy candidates the helper arm of `forget_at` deferred, under `Files` it answers true because `forget_at` already removed them inline. A Tizen build takes `Files`, with no third authority value. Its install in `app::boot::install_plex_seams` loses its cfg in this same change, which needs plex's installer and its static ungated too (two cfg lines and one sentence in plex/session.rs, the two stale lines deleted from ci/allow/forks/plex.txt). Tests pass the authority as a parameter through the `*_with` forms, so no process-global override is added: one test per operation grades both stores (the files arm never reaches the helper's transport; the helper arm leaves the state root's consent file alone), and one grades the account-clear sweep. `telemetry/native.rs` (Sentry Native, 9 arm and 9 linux sites) is left for the Tizen retail work. Co-Authored-By: Claude Sonnet 5.5 --- ci/allow/forks/plex.txt | 4 +- rust-modules/plex/src/plex/session.rs | 15 +- rust-modules/src/app/boot.rs | 5 +- .../telemetry/src/telemetry/consent.rs | 5 - rust-modules/telemetry/src/telemetry/mod.rs | 56 ++++- .../telemetry/src/telemetry/persistence.rs | 201 ++++++++++++------ 6 files changed, 192 insertions(+), 94 deletions(-) diff --git a/ci/allow/forks/plex.txt b/ci/allow/forks/plex.txt index ef9ce4bba..00a5ca7ee 100644 --- a/ci/allow/forks/plex.txt +++ b/ci/allow/forks/plex.txt @@ -1,4 +1,4 @@ -# count: 33 +# count: 31 # Test/production forks (docs/sans-io.md), area `plex`: one line per production-visible `#[cfg(..)]` / `cfg!(..)` whose predicate reads `test` or `feature = "test-support"` # (`not(test)`, `not(any(test, feature = "test-support"))`, ...) in every machine crate (data/, plex/, media/, session/, screens/, ui/, appkit/ and machine/), keyed `::` (an attribute on an item), `::` (a statement or an inline `cfg!`) or `::` (a field). # Logic is one thing in production and tests deliver it events: there is no cfg(test) fork. Spec: ci/check-deps.sh `forks`. @@ -8,12 +8,10 @@ rust-modules/plex/src/plex/identity.rs::version rust-modules/plex/src/plex/origin.rs::latched_flag! rust-modules/plex/src/plex/origin.rs::store_policy_forced rust-modules/plex/src/plex/servers.rs::register_captured_origin_with_connection -rust-modules/plex/src/plex/session.rs::ACCOUNT_CLEAR_CLEANUP rust-modules/plex/src/plex/session.rs::auth_paths rust-modules/plex/src/plex/session.rs::clear_for_erase rust-modules/plex/src/plex/session.rs::clear_for_erase rust-modules/plex/src/plex/session.rs::clear_for_erase -rust-modules/plex/src/plex/session.rs::install_account_clear_cleanup rust-modules/plex/src/plex/session.rs::publish rust-modules/plex/src/plex/session.rs::read_into_cache_locked rust-modules/plex/src/plex/session.rs::read_into_cache_locked diff --git a/rust-modules/plex/src/plex/session.rs b/rust-modules/plex/src/plex/session.rs index 698d864e2..320bfdbc2 100644 --- a/rust-modules/plex/src/plex/session.rs +++ b/rust-modules/plex/src/plex/session.rs @@ -4282,17 +4282,16 @@ fn auto_quality_ready() -> bool { } /// **The telemetry/consent legacy-file sweep that follows a durable canonical clear** -/// ([`clear_for_erase`]'s ARM arm): `telemetry` owns the files and sits above `plex`, so the app -/// installs its `cleanup_after_account_clear` as a hook ([`install_account_clear_cleanup`]; -/// `app::boot::install_plex_seams`). It answers whether every candidate was retired. Unset there is -/// nothing registered to retire, which reads as retired, so the "could not be retired" branch is -/// never taken without a sweep that failed. Compiled where the sweep is: ARM, not the simulator, -/// not a test build. -#[cfg(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))))] +/// ([`clear_for_erase`] where the storage helper is canonical): `telemetry` owns the files and sits +/// above `plex`, so the app installs its `cleanup_after_account_clear` as a hook +/// ([`install_account_clear_cleanup`]; `app::boot::install_plex_seams`). It answers whether every +/// candidate was retired. Unset there is nothing registered to retire, which reads as retired, so +/// the "could not be retired" branch is never taken without a sweep that failed. The sweep runs +/// only where the platform states [`Authority::Helper`]; elsewhere the files it retires are not +/// deferred to a sign-out, so an installed hook is never asked. static ACCOUNT_CLEAR_CLEANUP: std::sync::OnceLock bool> = std::sync::OnceLock::new(); /// Install the sweep [`ACCOUNT_CLEAR_CLEANUP`] runs. Once; later calls are ignored. -#[cfg(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))))] pub fn install_account_clear_cleanup(sweep: fn() -> bool) { let _ = ACCOUNT_CLEAR_CLEANUP.set(sweep); } diff --git a/rust-modules/src/app/boot.rs b/rust-modules/src/app/boot.rs index 1645c2d47..a24fa1d82 100644 --- a/rust-modules/src/app/boot.rs +++ b/rust-modules/src/app/boot.rs @@ -434,11 +434,10 @@ mod panic_log_tests { /// * `plex::session::install_auto_quality_ready` — `route::auto_quality_ready`, the gate a fresh /// session record's default quality is seeded from (unset, `plex` reads `true`, the gate's value); /// * `plex::session::install_account_clear_cleanup` — `telemetry::cleanup_after_account_clear`, the -/// telemetry/consent legacy-file sweep a durable sign-out runs. It exists only where the sweep does -/// (ARM, not the simulator, not a test build); unset, `plex` reads it as already retired. +/// telemetry/consent legacy-file sweep a durable sign-out runs. It is installed on every platform: +/// the sweep retires files only where the storage helper owns them; unset, `plex` reads it as retired. pub(crate) fn install_plex_seams() { plx_plex::plex::session::install_auto_quality_ready(plx_media::route::auto_quality_ready); - #[cfg(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(test)))] plx_plex::plex::session::install_account_clear_cleanup(plx_telemetry::telemetry::cleanup_after_account_clear); } diff --git a/rust-modules/telemetry/src/telemetry/consent.rs b/rust-modules/telemetry/src/telemetry/consent.rs index 15765389a..1e35364b0 100644 --- a/rust-modules/telemetry/src/telemetry/consent.rs +++ b/rust-modules/telemetry/src/telemetry/consent.rs @@ -200,7 +200,6 @@ pub fn migrate_loaded(mut c: Consent) -> Consent { c } -#[cfg(any(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), test, feature = "test-support"))] #[derive(serde::Serialize, serde::Deserialize)] #[serde(deny_unknown_fields)] struct CanonicalDecision { @@ -212,7 +211,6 @@ struct CanonicalDecision { extensions: std::collections::BTreeMap, } -#[cfg(any(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), test, feature = "test-support"))] #[derive(serde::Serialize, serde::Deserialize)] #[serde(deny_unknown_fields)] struct CanonicalScopes { @@ -220,7 +218,6 @@ struct CanonicalScopes { usage: u32, } -#[cfg(any(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), test, feature = "test-support"))] #[derive(serde::Serialize, serde::Deserialize)] #[serde(deny_unknown_fields)] struct CanonicalIds { @@ -228,7 +225,6 @@ struct CanonicalIds { errors: Option, } -#[cfg(any(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), test, feature = "test-support"))] /// Split consent into the three DB8-public slots the canonical state clears atomically on logout. pub fn split_canonical(consent: &Consent) -> Result { Ok(plx_os::storage::state::ConsentPayload { @@ -254,7 +250,6 @@ pub fn split_canonical(consent: &Consent) -> Result Result { let decision: CanonicalDecision = serde_json::from_value(payload.consent.clone()).map_err(|_| ())?; let scopes: CanonicalScopes = serde_json::from_value(payload.scopes.clone()).map_err(|_| ())?; diff --git a/rust-modules/telemetry/src/telemetry/mod.rs b/rust-modules/telemetry/src/telemetry/mod.rs index d8ab2adf2..b0f134268 100644 --- a/rust-modules/telemetry/src/telemetry/mod.rs +++ b/rust-modules/telemetry/src/telemetry/mod.rs @@ -234,15 +234,31 @@ pub fn forget() { } /// Called after the shared account tombstone (`plex::session::clear`'s canonical commit) is -/// confirmed durable. On ARM, `persistence::forget_at` deliberately leaves telemetry/consent's own -/// legacy files in place when a decision is cleared, relying on this sweep to run once the ONE -/// atomic DB8 revocation for both domains — session and telemetry/consent — is confirmed rather -/// than merely queued. Ported from `release/v0.6`'s `telemetry::cleanup_after_account_clear` / -/// `persistence::cleanup_after_combined_clear`, which the 0.7 forward-port dropped along with -/// their only caller (Copilot review on PR #105, finding 7). -#[cfg(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))))] +/// confirmed durable. Where the platform's storage authority is the helper +/// ([`plx_os::tv::authority::Authority::Helper`], a webOS television), `persistence::forget_at` +/// deliberately leaves telemetry/consent's own legacy files in place when a decision is cleared, +/// relying on this sweep to run once the ONE atomic DB8 revocation for both domains — session and +/// telemetry/consent — is confirmed rather than merely queued. With files +/// ([`plx_os::tv::authority::Authority::Files`]) `forget_at` already removed them inline, so there is +/// nothing left to retire and this answers `true`. Ported from `release/v0.6`'s +/// `telemetry::cleanup_after_account_clear` / `persistence::cleanup_after_combined_clear`, which the +/// 0.7 forward-port dropped along with their only caller (Copilot review on PR #105, finding 7). pub fn cleanup_after_account_clear() -> bool { - persistence::cleanup_after_combined_clear(&candidates()) != persistence::CleanupResult::Failed + account_clear_sweep(plx_os::tv::authority::authority(), candidates) +} + +/// [`cleanup_after_account_clear`] with the platform's authority handed in. `legacy` is called only +/// by the helper arm, so the files arm reads no path. +fn account_clear_sweep( + authority: plx_os::tv::authority::Authority, + legacy: impl FnOnce() -> Vec, +) -> bool { + match authority { + plx_os::tv::authority::Authority::Helper => { + persistence::cleanup_after_combined_clear(&legacy()) != persistence::CleanupResult::Failed + } + plx_os::tv::authority::Authority::Files => true, + } } // ---- the spool, and the one worker that drains it --------------------------------------------- @@ -794,4 +810,28 @@ mod tests { .expect("a file with more fields still parses"); assert!(newer.usage); } + + /// The sweep after a durable account clear belongs to the helper authority alone: it retires + /// every legacy candidate there, and with files it answers `true` without reading a path, because + /// `forget_at` already removed them inline. The webOS answer and the one Tizen gets, side by side. + #[test] + fn the_account_clear_sweep_retires_legacy_files_only_where_the_helper_defers_it() { + use plx_os::tv::authority::Authority; + let dir = std::env::temp_dir().join(format!("plxnative-account-clear-sweep-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let candidate = dir.join("telemetry.json"); + std::fs::write(&candidate, b"{}").unwrap(); + + assert!( + account_clear_sweep(Authority::Files, || panic!("the files authority reads no candidate")), + "files: nothing deferred, nothing to retire" + ); + assert!(candidate.exists(), "files: the sweep touched nothing"); + + assert!(account_clear_sweep(Authority::Helper, || vec![candidate.clone()])); + assert!(!candidate.exists(), "helper: the deferred legacy candidate is retired"); + + let _ = std::fs::remove_dir_all(&dir); + } } diff --git a/rust-modules/telemetry/src/telemetry/persistence.rs b/rust-modules/telemetry/src/telemetry/persistence.rs index ede6ec41b..e503c128a 100644 --- a/rust-modules/telemetry/src/telemetry/persistence.rs +++ b/rust-modules/telemetry/src/telemetry/persistence.rs @@ -3,17 +3,19 @@ //! The record backend owns framing and filesystem durability. This adapter owns the consent JSON //! payload, revision choice, and the rule that a present canonical record is terminal: legacy //! files are consulted only when `consent.json` is genuinely absent. +//! +//! Where the canonical record lives is the platform's statement +//! ([`plx_os::tv::authority::authority`]): the storage helper ([`Authority::Helper`], a webOS +//! television) or files under the persistent state root ([`Authority::Files`]). [`load`], +//! [`record_at`] and [`forget_at`] read it once per operation and hand it, with the helper's +//! transport, to their `*_with` form, which is what a test calls to grade either store. use super::consent::Consent; use plx_os::storage::{Record, RecordKey, RecordState, RecordStore}; -#[cfg(not(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support")))))] use plx_os::storage::StoreError; +use plx_os::tv::authority::Authority; use std::path::{Path, PathBuf}; -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] use plx_os::storage::{ client::{self, Load as HelperLoad}, state::{self, Generation, MigrationProgress}, @@ -21,7 +23,6 @@ use plx_os::storage::{ }; #[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[allow(dead_code)] // `Delegated` is produced only by the shipping webOS adapter. pub enum PersistResult { NotAttempted, /// Durability belongs to the immediately-following atomic Session `ClearTenure` operation. @@ -108,17 +109,14 @@ pub fn forget() -> PersistOutcome { forget_at(&super::resource_candidates(), root()) } -#[cfg(not(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support")))))] fn store() -> Result { plx_os::storage::open(root()) } -#[cfg(not(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support")))))] fn store_at(root: PathBuf) -> Result { plx_os::storage::open(root) } -#[cfg(not(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support")))))] fn cleanup_canonical(store: &impl RecordStore) -> CleanupResult { if store.cleanup(RecordKey::Consent).is_ok() { CleanupResult::Complete @@ -140,11 +138,10 @@ fn log_cleanup_failure(stage: &str, path: &Path, error: &std::io::Error) { } /// Sweep telemetry/consent's own legacy candidates once the shared account ClearTenure DB8 -/// mutation has been confirmed durable. [`forget_at`]'s ARM branch defers exactly this cleanup -/// here rather than doing it inline, because the immediately-following session ClearTenure is the -/// one atomic DB8 revocation for both domains and legacy sources must survive until THAT commit is -/// confirmed, not merely queued. -#[cfg(any(test, feature = "test-support", all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"))))] +/// mutation has been confirmed durable. [`forget_at`]'s helper branch ([`Authority::Helper`]) defers +/// exactly this cleanup here rather than doing it inline, because the immediately-following session +/// ClearTenure is the one atomic DB8 revocation for both domains and legacy sources must survive +/// until THAT commit is confirmed, not merely queued. pub fn cleanup_after_combined_clear(legacy: &[PathBuf]) -> CleanupResult { remove_legacy_sources(legacy.iter().cloned()) } @@ -181,11 +178,14 @@ fn remove_legacy_sources(paths: impl IntoIterator) -> CleanupRes /// Load canonical consent, falling back to trusted legacy candidates only when canonical is /// absent. A malformed, inaccessible, future, or otherwise present canonical record is terminal. pub fn load(legacy: &[PathBuf]) -> Consent { - #[cfg(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))))] - { - return load_helper(&mut client::NativeTransport, legacy); + load_with(plx_os::tv::authority::authority(), &mut client::NativeTransport, legacy) +} + +/// [`load`] with the platform's authority and the helper's transport handed in. +fn load_with(authority: Authority, transport: &mut dyn client::Transport, legacy: &[PathBuf]) -> Consent { + if authority == Authority::Helper { + return load_helper(transport, legacy); } - #[cfg(not(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support")))))] { #[cfg(not(any(test, feature = "test-support")))] if plx_base::paths::ensure_persistent_state_root().is_err() { @@ -268,18 +268,10 @@ pub fn load(legacy: &[PathBuf]) -> Consent { } } -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] fn helper_expected(snapshot: &client::Snapshot) -> Option<(&str, state::Expected)> { Some((&snapshot.db_rev, snapshot.state.expected())) } -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] #[derive(Clone, Copy)] struct HelperCommit { result: PersistResult, @@ -288,10 +280,6 @@ struct HelperCommit { conflict: bool, } -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] fn helper_commit( transport: &mut dyn client::Transport, loaded: &HelperLoad, @@ -359,10 +347,6 @@ fn helper_commit( } } -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] fn legacy_consent(legacy: &[PathBuf]) -> Result)>, ()> { let mut found: Option<(Consent, Vec)> = None; for path in legacy { @@ -387,10 +371,6 @@ fn legacy_consent(legacy: &[PathBuf]) -> Result)>, Ok(found) } -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] enum PreviousCanonical { Missing, Data(Consent), @@ -400,18 +380,10 @@ enum PreviousCanonical { /// Decode the complete `plxnative-record` wrapper used by the JSON canonical store that preceded /// DB8. A corrupt/future record is terminal and is never treated like an absent legacy source. -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] fn previous_canonical_consent() -> PreviousCanonical { previous_canonical_consent_at(root()) } -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] fn previous_canonical_consent_at(root: PathBuf) -> PreviousCanonical { match std::fs::symlink_metadata(&root) { Err(error) if error.kind() == std::io::ErrorKind::NotFound => PreviousCanonical::Missing, @@ -440,10 +412,6 @@ fn previous_canonical_consent_at(root: PathBuf) -> PreviousCanonical { } } -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] fn load_helper(transport: &mut dyn client::Transport, legacy: &[PathBuf]) -> Consent { let loaded = match client::load_with(transport) { Ok(loaded) => loaded, @@ -615,7 +583,6 @@ fn read_legacy(path: &Path) -> LegacyRead { } } -#[cfg(not(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support")))))] fn load_legacy_and_migrate(store: &impl RecordStore, legacy: &[PathBuf]) -> Consent { let mut found: Option<(Consent, Vec<(PathBuf, Vec)>)> = None; for path in legacy { @@ -727,12 +694,21 @@ pub(super) fn record_at( legacy: &[PathBuf], canonical_root: PathBuf, ) -> PersistOutcome { - #[cfg(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))))] - { + record_with(plx_os::tv::authority::authority(), &mut client::NativeTransport, consent, legacy, canonical_root) +} + +/// [`record_at`] with the platform's authority and the helper's transport handed in. +fn record_with( + authority: Authority, + transport: &mut dyn client::Transport, + consent: &Consent, + legacy: &[PathBuf], + canonical_root: PathBuf, +) -> PersistOutcome { + if authority == Authority::Helper { let _ = canonical_root; - return record_helper(&mut client::NativeTransport, consent, legacy); + return record_helper(transport, consent, legacy); } - #[cfg(not(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support")))))] { let store = match store_at(canonical_root) { Ok(store) => store, @@ -827,10 +803,6 @@ pub(super) fn record_at( } } -#[cfg(any( - all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), - test -))] fn record_helper( transport: &mut dyn client::Transport, consent: &Consent, @@ -906,8 +878,13 @@ fn record_helper( /// Write a canonical cleared tombstone, then remove stale legacy copies best-effort. pub(super) fn forget_at(legacy: &[PathBuf], canonical_root: PathBuf) -> PersistOutcome { - #[cfg(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))))] - { + forget_with(plx_os::tv::authority::authority(), legacy, canonical_root) +} + +/// [`forget_at`] with the platform's authority handed in. The helper arm touches nothing itself, so +/// it takes no transport. +fn forget_with(authority: Authority, legacy: &[PathBuf], canonical_root: PathBuf) -> PersistOutcome { + if authority == Authority::Helper { let _ = canonical_root; // Session's immediately-following ClearTenure is the one atomic DB8 revocation for both // domains. Consent has already been unpublished before this worker job runs. Legacy @@ -920,7 +897,6 @@ pub(super) fn forget_at(legacy: &[PathBuf], canonical_root: PathBuf) -> PersistO publish(outcome); return outcome; } - #[cfg(not(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support")))))] { let store = match store_at(canonical_root) { Ok(store) => store, @@ -1038,12 +1014,13 @@ mod tests { /// Copilot review on PR #105, finding 7. `release/v0.6` swept telemetry/consent's own legacy /// files (`telemetry::cleanup_after_account_clear` / `persistence::cleanup_after_combined_clear`) /// once the shared account ClearTenure DB8 mutation was confirmed durable on ARM sign-out; the - /// 0.7 forward-port dropped both the function and its only caller entirely (`forget_at`'s ARM + /// 0.7 forward-port dropped both the function and its only caller entirely (`forget_at`'s helper /// branch still says it relies on this sweep, but nothing performed it — confirmed absent by - /// grep against this tree before this fix). ARM's `forget_at` is compiled out on host - /// (`not(all(target_os = "linux", target_arch = "arm", ...))`), so the real defect cannot be - /// observed red on this platform; this test pins the restored sweep function directly rather - /// than through the ARM-only call site. `cleanup_after_combined_clear` did not exist before + /// grep against this tree before this fix). That branch ran only where the build was a 32-bit ARM + /// Linux binary, so the real defect could not be observed red on a host; this test pins the + /// restored sweep function directly rather than through that call site (the dispatch itself is + /// graded by `upgrade_tests::the_platform_authority_picks_the_store_for_forget`). + /// `cleanup_after_combined_clear` did not exist before /// this fix, so the red here is simulated (a compile failure against the old tree), not an /// observed runtime failure. #[test] @@ -1587,4 +1564,94 @@ mod upgrade_tests { assert!(!after.any() && !after.answered() && after.errors_id.is_none()); assert!(!source.exists(), "a stale source is retired, never imported, after sign-out"); } + + /// A transport that counts its calls and answers none: the files arm must never reach it. + fn silent(asked: &std::cell::Cell) -> impl FnMut(Request) -> Result + '_ { + move |_| { + asked.set(asked.get() + 1); + Err(plx_os::storage::client::ClientError::Unavailable) + } + } + + /// The platform's [`Authority`], not the build's CPU and OS, picks where consent is read from: + /// `Files` migrates a legacy source into the state root's own file and never asks the helper; + /// `Helper` imports it into the helper and never creates the state root's consent file. + #[test] + fn the_platform_authority_picks_the_store_for_load() { + let _g = plx_base::testlock::serial(); + { + let dir = Dir::new("authority-load-files"); + let source = dir.legacy(GENERATED_DECLINE_065); + let asked = std::cell::Cell::new(0); + let mut transport = silent(&asked); + let loaded = load_with(Authority::Files, &mut transport, std::slice::from_ref(&source)); + assert_eq!(asked.get(), 0, "the files arm never reaches the storage helper"); + assert_preserved("files authority", &loaded, GENERATED_DECLINE_065); + assert!(dir.0.join("state/consent.json").exists(), "the files arm keeps its own record"); + assert!(!source.exists(), "the legacy source is retired once the file is durable"); + } + { + let dir = Dir::new("authority-load-helper"); + let source = dir.legacy(GENERATED_DECLINE_065); + let mut b = backend(None); + let mut transport = |request: Request| Ok(b.dispatch(request)); + let loaded = load_with(Authority::Helper, &mut transport, std::slice::from_ref(&source)); + assert_preserved("helper authority", &loaded, GENERATED_DECLINE_065); + assert!(b.rpc.puts >= 1, "the helper arm commits the import to the helper"); + assert!(!dir.0.join("state/consent.json").exists(), "the helper arm never creates the state root's consent file"); + assert!(!source.exists(), "the legacy source is retired once the helper holds it"); + } + } + + /// The same split for a write: `Files` writes the state root's file and never asks the helper; + /// `Helper` commits to the helper, whatever root it was handed, and creates no consent file there. + #[test] + fn the_platform_authority_picks_the_store_for_record() { + let _g = plx_base::testlock::serial(); + let consent = super::super::consent::apply(&Consent::default(), true, true, || Some("f".repeat(32))); + { + let dir = Dir::new("authority-record-files"); + let asked = std::cell::Cell::new(0); + let mut transport = silent(&asked); + let outcome = record_with(Authority::Files, &mut transport, &consent, &[], dir.0.join("state")); + assert_eq!(outcome.write, PersistResult::Durable); + assert_eq!(asked.get(), 0, "the files arm never reaches the storage helper"); + assert!(dir.0.join("state/consent.json").exists(), "the files arm keeps its own record"); + } + { + let dir = Dir::new("authority-record-helper"); + let elsewhere = dir.0.join("elsewhere"); + let mut b = backend(Some(db8_066())); + let mut transport = |request: Request| Ok(b.dispatch(request)); + let outcome = record_with(Authority::Helper, &mut transport, &consent, &[], elsewhere.clone()); + assert_eq!(outcome.write, PersistResult::Durable); + assert!(b.rpc.puts >= 1, "the helper arm commits to the helper"); + assert!(!dir.0.join("state/consent.json").exists() && !elsewhere.exists(), "no consent file under the state root"); + assert_eq!(helper_load(&mut b, &[]), consent, "the helper holds the decision"); + } + } + + /// And for a sign-out: `Files` writes the cleared tombstone and retires the legacy source itself; + /// `Helper` delegates both to the session's ClearTenure and touches neither. + #[test] + fn the_platform_authority_picks_the_store_for_forget() { + let _g = plx_base::testlock::serial(); + { + let dir = Dir::new("authority-forget-files"); + let source = dir.legacy(GENERATED_DECLINE_065); + let outcome = forget_with(Authority::Files, std::slice::from_ref(&source), dir.0.join("state")); + assert_eq!(outcome.write, PersistResult::Durable); + assert!(!source.exists(), "the files arm retires the legacy source itself"); + assert!(dir.0.join("state/consent.json").exists(), "the files arm writes its own tombstone"); + } + { + let dir = Dir::new("authority-forget-helper"); + let source = dir.legacy(GENERATED_DECLINE_065); + let outcome = forget_with(Authority::Helper, std::slice::from_ref(&source), dir.0.join("state")); + assert_eq!(outcome.write, PersistResult::Delegated); + assert_eq!(outcome.cleanup, CleanupResult::NotAttempted); + assert!(source.exists(), "the legacy source waits for the confirmed ClearTenure"); + assert!(!dir.0.join("state/consent.json").exists(), "the helper arm never creates the state root's consent file"); + } + } } From 9914c2dec10506e551959d6469cc837d9f395aed Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 16:30:00 +0300 Subject: [PATCH 3/3] The storage authority's docs say what the helper and the files are on a television, and the order pin is exact Review of the foundation found three things the first commit got wrong or left weak. On webOS the helper is the canonical store, but the app's own files are not absent there: the session layer writes a marked fallback (`save_legacy_fallback_locked`) whenever a commit to the helper is not durable, serves it as transient state while the helper cannot answer (`read_legacy_filtered_locked`), and the legacy files an older build left are migration inputs. `tv::authority`'s module doc and the `Helper` variant said no file is ever written and a helper outage is never papered over; they now say what the code does. The platform-ports bullet follows. The order pin in `port.rs` asserted only that the install precedes `exit::entry`. It now asserts that `platform.install_services();` is `run_application`'s first non-comment statement, counts the call and `tv::install(` across every source file of the application crate (not just `app/mod.rs`), and fails when a statement is inserted above the install, when a second call is added, and when `tv::install` is called a second time. Each of those three mutations was run and fails for its own assertion. `authority.rs` and the `port.rs` test docs spoke as if a reader of the value already existed. They now state what the value says and what it is for. Co-Authored-By: Claude --- docs/platform-ports.md | 6 ++- rust-modules/os/src/tv/authority.rs | 37 +++++++++------- rust-modules/src/port.rs | 67 +++++++++++++++++++++-------- 3 files changed, 76 insertions(+), 34 deletions(-) diff --git a/docs/platform-ports.md b/docs/platform-ports.md index 477fa0d54..49fe3eb59 100644 --- a/docs/platform-ports.md +++ b/docs/platform-ports.md @@ -848,8 +848,10 @@ split by who reads it (critic M4): `devcaps` parses through, `Files::NONE` for a platform with none); - `secure { seal, open, remove, mode }` (Target shape 4; until W2 `mode` is W3a's own once-set value); - `system { go_home, poll_home, deliver_toast }`; - - `storage { authority }` (W8a): `Authority::Helper` (webOS: the LS2/DB8 storage helper owns the session, the - install's preferences and the consent record) or `Authority::Files` (desktop, Tizen, a host test), read through + - `storage { authority }` (W8a): `Authority::Helper` (webOS: the LS2/DB8 storage helper is the canonical store of + the session, the install's preferences and the consent record; the app's own files there are the legacy + migration inputs and the marked fallback of a helper outage) or `Authority::Files` (desktop, Tizen, a host + test: the app's own record files are the store), read through `tv::authority::authority()`. It replaces the `target_os = "linux"` + `target_arch = "arm"` fence the persistence layers chose their store by; the helper's wake-up (`storage::client::install_activator`) joins it after W7b; - `legacy_webos_media { sink, display_sink, uri_media }`: the Starfish, ACB and `com.webos.media` verbs (F31), diff --git a/rust-modules/os/src/tv/authority.rs b/rust-modules/os/src/tv/authority.rs index 85d8dd6a2..629a19410 100644 --- a/rust-modules/os/src/tv/authority.rs +++ b/rust-modules/os/src/tv/authority.rs @@ -1,21 +1,27 @@ //! Where the account's canonical state lives: the platform's storage helper, or plain files. //! -//! The session record, the install's preferences and the consent record each have two homes. On a -//! webOS television the LS2/DB8 storage helper owns them ([`Authority::Helper`]): the app never -//! reads or writes a file of its own for them. Everywhere else the app keeps them in files under its -//! persistent state root ([`Authority::Files`]): the desktop simulator, a host test, and a platform -//! with no helper at all (Tizen). The layers that persist these records (`plex::session`, -//! `telemetry`) choose their store from this value, once per operation, instead of from the build's -//! CPU and OS, which is what picked it before: a 32-bit ARM Linux binary is not necessarily a -//! television. +//! The session record, the install's preferences and the consent record each have one canonical +//! store, and the platform states which. On a webOS television it is the LS2/DB8 storage helper +//! ([`Authority::Helper`]). Everywhere else it is the app's own record files under its persistent +//! state root ([`Authority::Files`]): the desktop simulator, a host test, and a platform with no +//! helper at all (Tizen). //! -//! The platform states it once, as the `authority` of its [`StorageHooks`](super::StorageHooks), and -//! [`authority`] reads it. A process that installed no platform (a host test) reads +//! Under `Helper` the app's own files are not the store. They are the legacy migration inputs an +//! older build left, and the marked fallback the session layer writes when a commit to the helper is +//! not durable (a helper outage): while the helper cannot answer, that file is served as transient +//! state, and it never replaces the helper's record. +//! +//! The platform states the value once, as the `authority` of its [`StorageHooks`](super::StorageHooks), +//! and [`authority`] reads it. A process that installed no platform (a host test) reads //! [`StorageHooks::NONE`], which is `Files`, like every other group's host-test answer. A shipping -//! process must install its services before anything persists: an uninstalled television would read -//! `Files` and write a plaintext session file, which is why `run_application` installs them first +//! process has to install its services before anything persists, because an uninstalled television +//! would be told it has no helper; `run_application` installs them as its first statement //! (`port::tests` pins the order). //! +//! The value exists so that the layers that persist these records can choose their canonical store +//! from what the platform states, not from the build's CPU and OS (a 32-bit ARM Linux binary is not +//! necessarily a television). +//! //! This group is the home of the platform's other storage statements as well. The helper's wake-up //! (`storage::client::install_activator`, which `port::plex_main` installs for webOS today) belongs //! here as a later member and moves with the os lane after W7b; it is not moved yet. @@ -23,10 +29,11 @@ /// Where the account's canonical state lives. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub enum Authority { - /// The platform's storage helper (webOS: the LS2/DB8 service). No file of the app's own holds - /// the record, and a helper that cannot answer is never papered over with one. + /// The platform's storage helper (webOS: the LS2/DB8 service) is the canonical store. The app's + /// own files are only the legacy migration inputs and the session layer's marked fallback, which + /// is written during a helper outage and is never the record. Helper, - /// Files under the app's persistent state root, written by the app itself. + /// The app's own record files under its persistent state root are the canonical store. #[default] Files, } diff --git a/rust-modules/src/port.rs b/rust-modules/src/port.rs index 800c426a8..ec914547a 100644 --- a/rust-modules/src/port.rs +++ b/rust-modules/src/port.rs @@ -155,36 +155,69 @@ mod tests { use super::SERVICES; use plx_os::tv::authority::Authority; - /// The webOS table states the storage helper as the home of the session, the install's preferences - /// and the consent record. The persistence layers choose their store from this value, so a table - /// that stated anything else would move a television's account out of DB8. + /// The webOS table states the storage helper as the canonical home of the session, the install's + /// preferences and the consent record: on a television that is DB8, and a table that stated + /// `Files` would say the app's own files are. #[test] fn the_webos_table_states_the_storage_helper_as_the_authority() { assert_eq!(SERVICES.storage.authority, Authority::Helper); assert_eq!(SERVICES.secure.mode, plx_os::tv::secure::StoreMode::Durable); } - /// `run_application` installs the services before anything else runs. The authority is read by - /// whatever persists first, and an uninstalled television reads `Files` and would write a - /// plaintext session file, so the install has to come before `exit::entry` runs `enter_application`. - /// Reads the source, like `app::boot`'s `seam_order_tests`, because no host test can run the entry. + /// Every `.rs` file under the application crate's `src`, as text. + fn crate_sources() -> Vec { + fn walk(dir: &std::path::Path, out: &mut Vec) { + for entry in std::fs::read_dir(dir).expect("read a source directory") { + let path = entry.expect("a directory entry").path(); + if path.is_dir() { + walk(&path, out); + } else if path.extension().is_some_and(|ext| ext == "rs") { + out.push(std::fs::read_to_string(&path).expect("read a source file")); + } + } + } + let mut out = Vec::new(); + walk(&std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src"), &mut out); + out + } + + /// `run_application` installs the services as its first statement, before anything can read + /// them: a process that has installed none reads the host-test answers, which for the storage + /// group is `Files`, so a television that persisted ahead of its install would be told it has no + /// helper. One production install, and the only caller of `tv::install` is the `Platform` method + /// it goes through. Reads the source, like `app::boot`'s `seam_order_tests`, because no host test + /// can run the entry. #[test] - fn the_services_are_installed_before_the_application_enters() { - let source = include_str!("app/mod.rs"); - let body = source + fn the_services_are_installed_first_and_only_there() { + let body = include_str!("app/mod.rs") .split_once("fn run_application(") .expect("run_application") .1 - .split_once("\n}\n") - .expect("end of run_application") - .0; - let install = body.find("platform.install_services();").expect("run_application installs the services"); - let enter = body.find("exit::entry(").expect("run_application enters through exit::entry"); - assert!(install < enter, "install_services must run before exit::entry"); + .split_once('{') + .expect("run_application's body") + .1; + let first = body + .lines() + .map(str::trim) + .find(|line| !line.is_empty() && !line.starts_with("//")) + .expect("a first statement"); + let first = first.split_once("//").map_or(first, |(code, _)| code).trim(); + assert_eq!( + first, + concat!("platform.install_", "services();"), + "the install must be run_application's first statement" + ); + let sources = crate_sources(); + let count = |needle: &str| sources.iter().map(|text| text.matches(needle).count()).sum::(); assert_eq!( - source.matches("install_services()").count(), + count(concat!(".install_", "services()")), 1, "one production install; a second would be refused by tv and could hide a missing first" ); + assert_eq!( + count(concat!("tv::", "install(")), + 1, + "`tv::install` is called by `Platform::install_services` and nowhere else" + ); } }