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
4 changes: 1 addition & 3 deletions ci/allow/forks/plex.txt
Original file line number Diff line number Diff line change
@@ -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 `<path>::<item name>` (an attribute on an item), `<path>::<enclosing fn>` (a statement or an inline `cfg!`) or `<path>::<struct>` (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`.
Expand All @@ -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
Expand Down
15 changes: 7 additions & 8 deletions rust-modules/plex/src/plex/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<fn() -> 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);
}
Expand Down
5 changes: 2 additions & 3 deletions rust-modules/src/app/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 0 additions & 5 deletions rust-modules/telemetry/src/telemetry/consent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -212,23 +211,20 @@ struct CanonicalDecision {
extensions: std::collections::BTreeMap<String, serde_json::Value>,
}

#[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 {
errors: u32,
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 {
analytics: Option<String>,
errors: Option<String>,
}

#[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<plx_os::storage::state::ConsentPayload, ()> {
Ok(plx_os::storage::state::ConsentPayload {
Expand All @@ -254,7 +250,6 @@ pub fn split_canonical(consent: &Consent) -> Result<plx_os::storage::state::Cons
})
}

#[cfg(any(all(target_os = "linux", target_arch = "arm", not(feature = "hostsim"), not(any(test, feature = "test-support"))), test, feature = "test-support"))]
pub fn join_canonical(payload: &plx_os::storage::state::ConsentPayload) -> Result<Consent, ()> {
let decision: CanonicalDecision = serde_json::from_value(payload.consent.clone()).map_err(|_| ())?;
let scopes: CanonicalScopes = serde_json::from_value(payload.scopes.clone()).map_err(|_| ())?;
Expand Down
56 changes: 48 additions & 8 deletions rust-modules/telemetry/src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::path::PathBuf>,
) -> 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 ---------------------------------------------
Expand Down Expand Up @@ -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);
}
}
Loading
Loading