From 84cb567197993608adf43292e088da547627e0e8 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 18 Nov 2026 00:37:56 -0600 Subject: [PATCH] Add pinned and tracking program update channels --- .../id/crates/id-worlds/src/program_bundle.rs | 54 +++++++++++++++++++ pkgs/id/crates/id-worlds/src/world/mod.rs | 29 +++++++++- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/pkgs/id/crates/id-worlds/src/program_bundle.rs b/pkgs/id/crates/id-worlds/src/program_bundle.rs index 1fec7fe362..a9189d7e10 100644 --- a/pkgs/id/crates/id-worlds/src/program_bundle.rs +++ b/pkgs/id/crates/id-worlds/src/program_bundle.rs @@ -97,6 +97,15 @@ pub struct ProgramIdentity { pub content_hash: String, } +impl ProgramIdentity { + /// The update channel is the author's program name; version and content + /// hash identify a particular release, not a different channel. + #[must_use] + pub fn same_channel(&self, other: &Self) -> bool { + self.author == other.author && self.name == other.name + } +} + /// The F12.7 guest ABI a payload targets. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] @@ -721,6 +730,51 @@ mod tests { export(PAYLOAD.to_vec(), spec("chess", 3), &alice()).unwrap() } + #[test] + fn install_policy_defaults_to_pinned_and_pinned_does_not_track() { + let provenance = original().provenance(); + assert_eq!(provenance.policy, crate::world::InstallPolicy::Pinned); + let mut later = provenance.program.clone(); + later.version += 1; + later.content_hash = "later-hash".to_owned(); + assert!(!provenance.tracks(&later)); + } + + #[test] + fn tracking_is_scoped_to_the_exact_author_name_line_not_fork_lineage() { + let mut provenance = original().provenance(); + provenance.policy = crate::world::InstallPolicy::Tracking; + + let mut later_release = provenance.program.clone(); + later_release.version += 1; + later_release.content_hash = "later-hash".to_owned(); + assert!(provenance.tracks(&later_release)); + + let mut other_author = later_release.clone(); + other_author.author = "different-author".to_owned(); + assert!(!provenance.tracks(&other_author)); + + let mut fork = later_release; + fork.name = "chess-fork".to_owned(); + assert!(!provenance.tracks(&fork)); + + let mut fork_provenance = provenance.clone(); + fork_provenance.program = fork.clone(); + assert!(!fork_provenance.tracks(&provenance.program)); + let mut later_fork_release = fork; + later_fork_release.version += 1; + assert!(fork_provenance.tracks(&later_fork_release)); + } + + #[test] + fn missing_policy_in_older_install_records_defaults_to_pinned() { + let provenance = original().provenance(); + let mut value = serde_json::to_value(provenance).unwrap(); + value.as_object_mut().unwrap().remove("policy"); + let restored: crate::world::BundleProvenance = serde_json::from_value(value).unwrap(); + assert_eq!(restored.policy, crate::world::InstallPolicy::Pinned); + } + /// Offsets of the manifest and payload inside an encoded bundle. fn layout(bytes: &[u8]) -> (std::ops::Range, usize) { let start = BUNDLE_MAGIC.len() + 4; diff --git a/pkgs/id/crates/id-worlds/src/world/mod.rs b/pkgs/id/crates/id-worlds/src/world/mod.rs index c25caf36bb..245236fa91 100644 --- a/pkgs/id/crates/id-worlds/src/world/mod.rs +++ b/pkgs/id/crates/id-worlds/src/world/mod.rs @@ -356,14 +356,29 @@ impl ModuleProvenance { } } -/// How a bundle install follows later versions of its program (D4). Only -/// pinned exists today: an update is a new install decision. +/// How a bundle install follows later versions of its program (D4). #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum InstallPolicy { /// Exactly this content hash; nothing changes without a new install. #[default] Pinned, + /// Discover later versions on this install's exact (author, name) line. + Tracking, +} + +impl InstallPolicy { + /// Whether this install opts into update discovery for `candidate`. + /// This does not authorize applying an update; that remains a separate + /// owner decision/flow. + #[must_use] + pub fn tracks( + self, + installed: &crate::program_bundle::ProgramIdentity, + candidate: &crate::program_bundle::ProgramIdentity, + ) -> bool { + self == Self::Tracking && installed.same_channel(candidate) + } } /// The install record of a sideloaded program bundle (#8280). @@ -387,9 +402,19 @@ pub struct BundleProvenance { /// The verified bundle signature, lower-case hex. pub bundle_signature: String, /// How this install follows later versions. + #[serde(default)] pub policy: InstallPolicy, } +impl BundleProvenance { + /// Whether a candidate belongs to this install's opted-in update channel. + /// Fork lineage is deliberately not part of channel identity. + #[must_use] + pub fn tracks(&self, candidate: &crate::program_bundle::ProgramIdentity) -> bool { + self.policy.tracks(&self.program, candidate) + } +} + /// Provenance recorded when one world is forked from another (F12.2). It /// names the source world and module so a fork can trace its origin, and /// whether the fork was marked reusable as a template.