diff --git a/pkgs/id/Cargo.lock b/pkgs/id/Cargo.lock index 9c6146670f..2e8e6babf7 100644 --- a/pkgs/id/Cargo.lock +++ b/pkgs/id/Cargo.lock @@ -3907,6 +3907,7 @@ dependencies = [ "id-groups", "id-store", "id-sync", + "id-worlds", "iroh", "iroh-base", "iroh-blobs", @@ -4124,6 +4125,24 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "id-worlds" +version = "0.1.0" +dependencies = [ + "anyhow", + "blake3", + "id-events", + "id-groups", + "iroh-base", + "iroh-blobs", + "libc", + "p2panda-core", + "proptest", + "serde", + "serde_json", + "tempfile", +] + [[package]] name = "identity-hash" version = "0.1.0" diff --git a/pkgs/id/Cargo.toml b/pkgs/id/Cargo.toml index 05a155e142..db00bca275 100644 --- a/pkgs/id/Cargo.toml +++ b/pkgs/id/Cargo.toml @@ -16,14 +16,14 @@ categories = ["command-line-utilities", "network-programming"] # id-core sub-crate under crates/; this package is the workspace root. [workspace] -members = ["crates/id-core", "crates/id-caps", "crates/id-store", "crates/id-events", "crates/id-groups", "crates/id-sync", "crates/id-native-shell"] +members = ["crates/id-core", "crates/id-caps", "crates/id-store", "crates/id-events", "crates/id-groups", "crates/id-sync", "crates/id-worlds", "crates/id-native-shell"] # The vendored crates stay OUT of the workspace: as path dependencies inside # this directory Cargo would otherwise treat them as members, and a member's # feature graph joins the lock resolve — p2panda-sync's `test_utils` feature # forwards to `p2panda-store/test_utils`, whose `sqlite` feature pulls sqlx # into Cargo.lock even though no build here enables it (see vendor/README.md). exclude = ["vendor/p2panda-sync", "vendor/p2panda-encryption"] -default-members = [".", "crates/id-core", "crates/id-caps", "crates/id-store", "crates/id-events", "crates/id-groups", "crates/id-sync"] +default-members = [".", "crates/id-core", "crates/id-caps", "crates/id-store", "crates/id-events", "crates/id-groups", "crates/id-sync", "crates/id-worlds"] # ============================================================================= # Features @@ -83,6 +83,9 @@ id-sync = { path = "crates/id-sync", default-features = false } # Groups-family modules extracted in step 4 of the crate split (#4407). # Re-exported at their historical crate:: paths in src/lib.rs. id-groups = { path = "crates/id-groups", default-features = false } +# Worlds-family modules extracted in step 5 of the crate split (#4408). +# Re-exported at their historical crate:: paths in src/lib.rs. +id-worlds = { path = "crates/id-worlds", default-features = false } anyhow = "1" cbor-core = { version = "=0.10.1", features = ["serde"] } # Calendar arithmetic and the IANA time-zone database for the did-it tracker's diff --git a/pkgs/id/crates/id-groups/src/groups/mod.rs b/pkgs/id/crates/id-groups/src/groups/mod.rs index 4d2afdd048..ba9959ae25 100644 --- a/pkgs/id/crates/id-groups/src/groups/mod.rs +++ b/pkgs/id/crates/id-groups/src/groups/mod.rs @@ -9,7 +9,7 @@ //! re-exports them at the paths the facade has always presented. //! What lives here is the remainder over that projection: //! [`actions`], [`log`] and [`warnings`]. The cross-world bridge -//! (`worlds`) stays in the facade until step 5 extracts `id-worlds`. +//! (`worlds`) lives in `id-worlds` since step 5 (seam 6). //! //! A group changes only by events. [`fold`] computes its state from //! the whole set of events, so the result does not depend on the order diff --git a/pkgs/id/crates/id-worlds/Cargo.toml b/pkgs/id/crates/id-worlds/Cargo.toml new file mode 100644 index 0000000000..cc5c7d5639 --- /dev/null +++ b/pkgs/id/crates/id-worlds/Cargo.toml @@ -0,0 +1,110 @@ +[package] +name = "id-worlds" +version = "0.1.0" +edition = "2024" +rust-version = "1.96" +description = "Worlds layer of the id crate: the world runtime, sessions, sandbox and cross-world authority (pkgs/id crate split step 5, #4408)" +license = "MIT OR Apache-2.0" + +# Step 5 of the pkgs/id crate split (#3447 umbrella, #4408): the world +# family lives here. Dependencies per the design map: id-core, id-caps, +# id-store, id-events, id-groups, id-sync. This first step-5 PR brings +# the leaves that name nothing above them (the compiled-world cache, +# the line/terminal helpers), seam 6's cross-world bridge +# (`groups::worlds` — the consumer side of the groups/worlds +# relationship, per the design), and the blob gate's `FoldedWorlds` +# adapter over that bridge (parked in the facade by step 4 to move +# together with the bridge). The world core, sessions and the rest of +# the family follow in later step-5 PRs. + +[features] +default = [] + +[dependencies] +anyhow = "1" +blake3 = "1" +id-events = { path = "../id-events", default-features = false } +id-groups = { path = "../id-groups", default-features = false } +iroh-base = "1" +iroh-blobs = "0.103" +libc = "0.2" +serde = { version = "1", features = ["derive"] } +serde_json = "1" + +[dev-dependencies] +p2panda-core = { git = "https://github.com/p2panda/p2panda", rev = "da80c05b95269926bf58121cf6a2d3dd5ca41dfc" } +proptest = "1.12" +tempfile = "3" + +[lints.rust] +unsafe_code = "warn" +rust_2018_idioms = { level = "warn", priority = -1 } +rust_2024_compatibility = { level = "warn", priority = -1 } +missing_debug_implementations = "warn" +missing_docs = "warn" +trivial_casts = "warn" +trivial_numeric_casts = "warn" +unused_lifetimes = "warn" +unused_qualifications = "warn" + +[lints.clippy] +all = { level = "warn", priority = -1 } +pedantic = { level = "warn", priority = -1 } +nursery = { level = "warn", priority = -1 } +cargo = { level = "warn", priority = -1 } +unwrap_used = "deny" +expect_used = "deny" +panic = "deny" +unimplemented = "deny" +todo = "deny" +dbg_macro = "deny" +print_stdout = "allow" +print_stderr = "allow" +clone_on_ref_ptr = "warn" +create_dir = "warn" +deref_by_slicing = "warn" +empty_structs_with_brackets = "warn" +filetype_is_file = "warn" +float_cmp_const = "warn" +fn_to_numeric_cast_any = "warn" +format_push_string = "warn" +get_unwrap = "warn" +if_then_some_else_none = "warn" +lossy_float_literal = "warn" +map_err_ignore = "warn" +mem_forget = "warn" +mixed_read_write_in_expression = "warn" +mutex_atomic = "warn" +rc_buffer = "warn" +rc_mutex = "warn" +redundant_type_annotations = "warn" +rest_pat_in_fully_bound_structs = "warn" +same_name_method = "warn" +self_named_module_files = "warn" +str_to_string = "warn" +string_add = "warn" +suspicious_xor_used_as_pow = "warn" +try_err = "warn" +undocumented_unsafe_blocks = "warn" +unnecessary_safety_comment = "warn" +unnecessary_safety_doc = "warn" +unnecessary_self_imports = "warn" +unneeded_field_pattern = "warn" +verbose_file_reads = "warn" +module_name_repetitions = "allow" +must_use_candidate = "allow" +missing_errors_doc = "allow" +missing_panics_doc = "allow" +redundant_pub_crate = "allow" +significant_drop_tightening = "allow" +option_if_let_else = "allow" +multiple_crate_versions = "allow" +cargo_common_metadata = "allow" +too_many_lines = "allow" +too_many_arguments = "allow" +fn_params_excessive_bools = "allow" +struct_excessive_bools = "allow" +cognitive_complexity = "allow" +future_not_send = "allow" +assert_is_empty = "allow" +chunks_exact_to_as_chunks = "allow" diff --git a/pkgs/id/crates/id-worlds/src/blob_gate.rs b/pkgs/id/crates/id-worlds/src/blob_gate.rs new file mode 100644 index 0000000000..85b2aaa6f8 --- /dev/null +++ b/pkgs/id/crates/id-worlds/src/blob_gate.rs @@ -0,0 +1,175 @@ +//! The blob gate's folded-worlds adapter. +//! +//! Step 4 of the pkgs/id crate split (#4407) extracted the gate +//! itself — policy, verdicts and provider wiring — into +//! `id_groups::blob_gate`, over the [`WorldAccess`] trait the events +//! layer owns. What stayed in the facade was [`FoldedWorlds`], the +//! `WorldAccess` implementation over the folded worlds, because it +//! folds through [`crate::groups::worlds::Worlds`]: seam 6's bridge +//! file, which the design sends to the worlds crate. Step 5 moves +//! the adapter together with the bridge, here. (`FoldedWorlds` +//! cannot live in `id-groups`: that crate is below this one and +//! must not name world types.) + +use std::collections::{BTreeSet, HashMap}; + +use iroh_base::EndpointId; +use iroh_blobs::Hash; + +use id_events::world_access::WorldAccess; + +use crate::groups::{Role, worlds::Worlds}; + +/// [`WorldAccess`] over the folded worlds. +/// +/// Membership is the world's own authority, as [`Worlds::holds_here`] gives it: a member of its +/// group, or a grant in its own chains. A crossing from another world does not count. +/// +/// The reference index maps a blob hash to the worlds that name it. Nothing in the store writes +/// it yet. Artifacts carry SHA-256 hashes, not BLAKE3 blob hashes, and only WASM modules are +/// pinned, without a record of their world. So the index is passed in, and a hash it does not +/// hold is unreferenced, which refuses it to every requester. +#[derive(Debug)] +pub struct FoldedWorlds { + worlds: Worlds, + references: HashMap>, +} + +impl FoldedWorlds { + /// Pairs the folded worlds with a reference index. + pub const fn new(worlds: Worlds, references: HashMap>) -> Self { + Self { worlds, references } + } +} + +impl WorldAccess for FoldedWorlds { + fn is_current_member(&self, world: &str, requester: &EndpointId) -> bool { + self.worlds + .holds_here(world, *requester.as_bytes(), Role::Pull) + } + + fn worlds_referencing(&self, hash: &Hash) -> Vec { + self.references + .get(hash) + .map(|worlds| worlds.iter().cloned().collect()) + .unwrap_or_default() + } +} + +#[cfg(test)] +#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] +mod tests { + use std::collections::{BTreeMap, HashMap}; + + use iroh_base::SecretKey; + + use super::*; + use crate::groups::policy::Policy; + use crate::groups::{Body, Create, Event, MemberOp, Template}; + use id_groups::blob_gate::{BlobPolicy, Request, decide}; + + fn id(n: u8) -> EndpointId { + SecretKey::from_bytes(&[n; 32]).public() + } + + fn blob(n: u8) -> Hash { + Hash::from_bytes([n; 32]) + } + + /// The world `docs`, founded by `founder`, which adds `member` as a reader and, when + /// `removed`, removes them again. Folded as the store folds a world. + fn folded(founder: EndpointId, member: EndpointId, removed: bool) -> Worlds { + let (founder, member) = (*founder.as_bytes(), *member.as_bytes()); + let create = p2panda_core::Hash::digest(b"create"); + let add = p2panda_core::Hash::digest(b"add"); + let remove = p2panda_core::Hash::digest(b"remove"); + let mut events = vec![ + Event { + id: create, + author: founder, + after: Vec::new(), + group: None, + body: Body::Create(Create { + template: Template::Custom, + policy: Policy::default(), + members: Vec::new(), + admins_on_create: false, + }), + }, + Event { + id: add, + author: founder, + after: vec![create], + group: Some(create), + body: Body::Member(MemberOp::Add { + member, + role: Role::Read, + }), + }, + ]; + if removed { + events.push(Event { + id: remove, + author: founder, + after: vec![add], + group: Some(create), + body: Body::Member(MemberOp::Remove { + member, + mode: crate::groups::RemoveMode::Revoke, + }), + }); + } + let worlds = BTreeMap::from([("docs".to_owned(), events)]); + Worlds::fold(&worlds, BTreeMap::new()).unwrap() + } + + /// The folded `docs` world, with `hash` indexed as named by `docs`. + fn gate(worlds: Worlds, hash: Hash) -> FoldedWorlds { + let refs = HashMap::from([(hash, BTreeSet::from(["docs".to_owned()]))]); + FoldedWorlds::new(worlds, refs) + } + + #[test] + fn folded_membership_admits_a_member_and_refuses_a_stranger() { + let g = gate(folded(id(1), id(2), false), blob(9)); + let p = BlobPolicy::default(); + assert!(decide(&g, &p, &id(2), &blob(9), Request::Fetch)); + // The founder is Admin, so is a member too. + assert!(decide(&g, &p, &id(1), &blob(9), Request::Fetch)); + assert!(!decide(&g, &p, &id(3), &blob(9), Request::Fetch)); + } + + #[test] + fn a_removed_member_loses_fetch_on_the_folded_world() { + let g = gate(folded(id(1), id(2), true), blob(9)); + assert!(!decide( + &g, + &BlobPolicy::default(), + &id(2), + &blob(9), + Request::Fetch + )); + } + + #[test] + fn an_unindexed_blob_is_refused_even_to_a_member() { + let g = gate(folded(id(1), id(2), false), blob(9)); + let p = BlobPolicy::default().with_observe(); + assert!(!decide(&g, &p, &id(2), &blob(5), Request::Fetch)); + assert!(!decide(&g, &p, &id(2), &blob(5), Request::Observe)); + } + + #[test] + fn observe_over_the_folded_world_follows_the_policy() { + let g = gate(folded(id(1), id(2), false), blob(9)); + assert!(!decide( + &g, + &BlobPolicy::default(), + &id(2), + &blob(9), + Request::Observe + )); + let p = BlobPolicy::default().with_observe(); + assert!(decide(&g, &p, &id(2), &blob(9), Request::Observe)); + } +} diff --git a/pkgs/id/crates/id-worlds/src/groups/mod.rs b/pkgs/id/crates/id-worlds/src/groups/mod.rs new file mode 100644 index 0000000000..1198708a34 --- /dev/null +++ b/pkgs/id/crates/id-worlds/src/groups/mod.rs @@ -0,0 +1,26 @@ +//! Groups, as the worlds layer sees them. +//! +//! The group model types and [`fold`] are group-projection +//! vocabulary owned by the events layer (step 2b, #4405), so the +//! model, `policy`, `event`, `fold`, `friendship` and the private +//! `delegation` module live in `id_events::groups`, and this module +//! re-exports them at the paths the facade has always presented — +//! the same re-exports `id_groups::groups` carries. What lives here +//! is [`worlds`]: seam 6 of the crate-split design sends the +//! groups→worlds bridge to the worlds crate, because the bridge is +//! the consumer side of the relationship (the group layer must not +//! know worlds exist). + +pub mod worlds; + +pub use id_events::groups::{ + Body, Create, DEVICE_ADD_KIND, DEVICE_REVOKE_KIND, Delegate, DeviceOp, Event, Grant, Key, + MemberOp, Role, +}; +pub use id_events::groups::{ + Delegation, History, Join, OnMemberRemoved, Policy, Removal, RemoveMode, RemoveModeKind, + RemovePolicy, RemoveSuccessor, RoleRules, Scheme, SuccessorKind, Template, TransferOpts, +}; +pub use id_events::groups::{DeviceGrant, FoldError, GroupView, Outcome, Projection, Refusal}; +pub use id_events::groups::{Pair, friendship_id}; +pub use id_events::groups::{event, fold, friendship, policy}; diff --git a/pkgs/id/src/groups/worlds.rs b/pkgs/id/crates/id-worlds/src/groups/worlds.rs similarity index 100% rename from pkgs/id/src/groups/worlds.rs rename to pkgs/id/crates/id-worlds/src/groups/worlds.rs diff --git a/pkgs/id/crates/id-worlds/src/lib.rs b/pkgs/id/crates/id-worlds/src/lib.rs new file mode 100644 index 0000000000..33c2e3a5a2 --- /dev/null +++ b/pkgs/id/crates/id-worlds/src/lib.rs @@ -0,0 +1,27 @@ +//! Worlds layer of the `id` crate. +//! +//! Step 5 of the pkgs/id crate split (#3447 umbrella, #4408): the +//! world family lives here, over `id-core`, `id-caps`, `id-store`, +//! `id-events`, `id-groups` and `id-sync`. +//! +//! This first step-5 PR brings: +//! +//! - [`blob_gate`]: the blob gate's folded-worlds adapter +//! ([`blob_gate::FoldedWorlds`]), parked in the facade by step 4 so +//! it could move together with the cross-world bridge it folds. +//! - [`groups::worlds`]: seam 6 of the design — the groups→worlds +//! bridge is the consumer side of the relationship, so it lives in +//! the worlds crate, over the group model in `id-events`. +//! - [`world_cache`], [`world_line`], [`world_terminal`]: the family +//! leaves that name nothing above them. +//! +//! The world core, sessions, sandbox and the rest of the family +//! follow in later step-5 PRs. The facade re-exports each module at +//! its historical `id::` path, so no call site outside the moved +//! modules changed. + +pub mod blob_gate; +pub mod groups; +pub mod world_cache; +pub mod world_line; +pub mod world_terminal; diff --git a/pkgs/id/src/world_cache.rs b/pkgs/id/crates/id-worlds/src/world_cache.rs similarity index 100% rename from pkgs/id/src/world_cache.rs rename to pkgs/id/crates/id-worlds/src/world_cache.rs diff --git a/pkgs/id/src/world_line.rs b/pkgs/id/crates/id-worlds/src/world_line.rs similarity index 100% rename from pkgs/id/src/world_line.rs rename to pkgs/id/crates/id-worlds/src/world_line.rs diff --git a/pkgs/id/src/world_terminal.rs b/pkgs/id/crates/id-worlds/src/world_terminal.rs similarity index 99% rename from pkgs/id/src/world_terminal.rs rename to pkgs/id/crates/id-worlds/src/world_terminal.rs index 38d8323882..87f46f2238 100644 --- a/pkgs/id/src/world_terminal.rs +++ b/pkgs/id/crates/id-worlds/src/world_terminal.rs @@ -79,11 +79,11 @@ pub(crate) enum PresentationTier { /// Profile plus input bytes that were not complete matching query replies. #[derive(Clone, Debug, Default, Eq, PartialEq)] -pub(crate) struct ProbeOutcome { +pub struct ProbeOutcome { /// Locally selected terminal profile. pub(crate) profile: TerminalProfile, /// Unmatched or incomplete bytes, preserved byte-for-byte for key input. - pub(crate) replay: Vec, + pub replay: Vec, /// At least one capability received contradictory complete reports. pub(crate) conflicted: bool, } @@ -181,7 +181,7 @@ impl ProbeDemux { /// switched to the non-canonical mode needed to read replies. Only the Tier 3 /// fallback presenter consumes this result in the current slice. #[cfg(unix)] -pub(crate) fn probe_local_tty() -> Option { +pub fn probe_local_tty() -> Option { use std::io::IsTerminal; if !std::io::stdin().is_terminal() || !std::io::stdout().is_terminal() { @@ -194,7 +194,7 @@ pub(crate) fn probe_local_tty() -> Option { /// Non-Unix builds have no TTY probe; callers keep the piped behavior. #[cfg(not(unix))] -pub(crate) fn probe_local_tty() -> Option { +pub fn probe_local_tty() -> Option { None } diff --git a/pkgs/id/src/blob_gate.rs b/pkgs/id/src/blob_gate.rs index 0262322de3..a7e20ee624 100644 --- a/pkgs/id/src/blob_gate.rs +++ b/pkgs/id/src/blob_gate.rs @@ -1,17 +1,17 @@ //! Who may fetch or observe a blob (P3.4, decision 5) — facade shim -//! over `id-groups`, plus the folded-worlds adapter. +//! over `id-groups` and `id-worlds`. //! //! Step 4 of the pkgs/id crate split (#4407): the gate itself — //! [`BlobPolicy`], [`Request`], [`decide`], [`decide_with_blocks`] and //! the provider wiring in [`blob_events`] — lives in //! `id_groups::blob_gate`, over the [`WorldAccess`] trait the events -//! layer owns (step 2b). What stays here is [`FoldedWorlds`], the -//! `WorldAccess` implementation over the folded worlds: it folds -//! through [`crate::groups::worlds::Worlds`], which is seam 6's -//! bridge file and leaves for `id-worlds` in step 5, so the adapter -//! stays in the facade with it (the same split step 2a used for the -//! store traits: trait and gate below, world-folding adapter above). -//! Step 5 moves `FoldedWorlds` together with `worlds.rs`. +//! layer owns (step 2b). Step 5 (#4408) moved [`FoldedWorlds`], the +//! `WorldAccess` implementation over the folded worlds, into +//! `id_worlds::blob_gate` together with seam 6's bridge file +//! (`groups::worlds`), which it folds through. It cannot live in +//! `id-groups`: that crate is below `id-worlds` and must not name +//! world types. This facade module now holds nothing but the +//! re-exports, so every historical `id::blob_gate` path is unchanged. //! //! The gate's own documentation, in `id_groups::blob_gate`: a fetch //! is allowed only to a current member of a world that references @@ -20,13 +20,6 @@ //! whether the hash is unreferenced or the requester may not reach //! it; and an unknown requester is refused. -use std::collections::{BTreeSet, HashMap}; - -use iroh_base::EndpointId; -use iroh_blobs::Hash; - -use crate::groups::{Role, worlds::Worlds}; - pub use id_groups::blob_gate::{ BlobPolicy, Request, blob_events, blob_events_with_blocks, decide, decide_with_blocks, }; @@ -35,155 +28,6 @@ pub use id_groups::blob_gate::{ /// its historical path (the trait itself is `id_events::world_access`). pub use id_events::world_access::WorldAccess; -/// [`WorldAccess`] over the folded worlds. -/// -/// Membership is the world's own authority, as [`Worlds::holds_here`] gives it: a member of its -/// group, or a grant in its own chains. A crossing from another world does not count. -/// -/// The reference index maps a blob hash to the worlds that name it. Nothing in the store writes -/// it yet. Artifacts carry SHA-256 hashes, not BLAKE3 blob hashes, and only WASM modules are -/// pinned, without a record of their world. So the index is passed in, and a hash it does not -/// hold is unreferenced, which refuses it to every requester. -#[derive(Debug)] -pub struct FoldedWorlds { - worlds: Worlds, - references: HashMap>, -} - -impl FoldedWorlds { - /// Pairs the folded worlds with a reference index. - pub const fn new(worlds: Worlds, references: HashMap>) -> Self { - Self { worlds, references } - } -} - -impl WorldAccess for FoldedWorlds { - fn is_current_member(&self, world: &str, requester: &EndpointId) -> bool { - self.worlds - .holds_here(world, *requester.as_bytes(), Role::Pull) - } - - fn worlds_referencing(&self, hash: &Hash) -> Vec { - self.references - .get(hash) - .map(|worlds| worlds.iter().cloned().collect()) - .unwrap_or_default() - } -} - -#[cfg(test)] -#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] -mod tests { - use std::collections::{BTreeMap, HashMap}; - - use iroh_base::SecretKey; - - use super::*; - use crate::groups::policy::Policy; - use crate::groups::{Body, Create, Event, MemberOp, Template}; - - fn id(n: u8) -> EndpointId { - SecretKey::from_bytes(&[n; 32]).public() - } - - fn blob(n: u8) -> Hash { - Hash::from_bytes([n; 32]) - } - - /// The world `docs`, founded by `founder`, which adds `member` as a reader and, when - /// `removed`, removes them again. Folded as the store folds a world. - fn folded(founder: EndpointId, member: EndpointId, removed: bool) -> Worlds { - let (founder, member) = (*founder.as_bytes(), *member.as_bytes()); - let create = p2panda_core::Hash::digest(b"create"); - let add = p2panda_core::Hash::digest(b"add"); - let remove = p2panda_core::Hash::digest(b"remove"); - let mut events = vec![ - Event { - id: create, - author: founder, - after: Vec::new(), - group: None, - body: Body::Create(Create { - template: Template::Custom, - policy: Policy::default(), - members: Vec::new(), - admins_on_create: false, - }), - }, - Event { - id: add, - author: founder, - after: vec![create], - group: Some(create), - body: Body::Member(MemberOp::Add { - member, - role: Role::Read, - }), - }, - ]; - if removed { - events.push(Event { - id: remove, - author: founder, - after: vec![add], - group: Some(create), - body: Body::Member(MemberOp::Remove { - member, - mode: crate::groups::RemoveMode::Revoke, - }), - }); - } - let worlds = BTreeMap::from([("docs".to_owned(), events)]); - Worlds::fold(&worlds, BTreeMap::new()).unwrap() - } - - /// The folded `docs` world, with `hash` indexed as named by `docs`. - fn gate(worlds: Worlds, hash: Hash) -> FoldedWorlds { - let refs = HashMap::from([(hash, BTreeSet::from(["docs".to_owned()]))]); - FoldedWorlds::new(worlds, refs) - } - - #[test] - fn folded_membership_admits_a_member_and_refuses_a_stranger() { - let g = gate(folded(id(1), id(2), false), blob(9)); - let p = BlobPolicy::default(); - assert!(decide(&g, &p, &id(2), &blob(9), Request::Fetch)); - // The founder is Admin, so is a member too. - assert!(decide(&g, &p, &id(1), &blob(9), Request::Fetch)); - assert!(!decide(&g, &p, &id(3), &blob(9), Request::Fetch)); - } - - #[test] - fn a_removed_member_loses_fetch_on_the_folded_world() { - let g = gate(folded(id(1), id(2), true), blob(9)); - assert!(!decide( - &g, - &BlobPolicy::default(), - &id(2), - &blob(9), - Request::Fetch - )); - } - - #[test] - fn an_unindexed_blob_is_refused_even_to_a_member() { - let g = gate(folded(id(1), id(2), false), blob(9)); - let p = BlobPolicy::default().with_observe(); - assert!(!decide(&g, &p, &id(2), &blob(5), Request::Fetch)); - assert!(!decide(&g, &p, &id(2), &blob(5), Request::Observe)); - } - - #[test] - fn observe_over_the_folded_world_follows_the_policy() { - let g = gate(folded(id(1), id(2), false), blob(9)); - assert!(!decide( - &g, - &BlobPolicy::default(), - &id(2), - &blob(9), - Request::Observe - )); - let p = BlobPolicy::default().with_observe(); - assert!(decide(&g, &p, &id(2), &blob(9), Request::Observe)); - } -} +/// [`WorldAccess`] over the folded worlds; the implementation lives +/// in `id_worlds::blob_gate`. +pub use id_worlds::blob_gate::FoldedWorlds; diff --git a/pkgs/id/src/groups/mod.rs b/pkgs/id/src/groups/mod.rs index 0fadb36eaa..6384428f95 100644 --- a/pkgs/id/src/groups/mod.rs +++ b/pkgs/id/src/groups/mod.rs @@ -8,9 +8,9 @@ //! their historical paths. Step 4 (#4407) extracted the //! policy/enforcement remainder — [`actions`], [`log`], [`warnings`] — //! into `id-groups` over `id-events`, re-exported here likewise. -//! [`worlds`] alone stays in the facade: seam 6 of the design sends -//! the cross-world bridge to `id-worlds` in step 5, and it is the -//! only submodule still defined in this directory. +//! [`worlds`] was the last submodule defined in this directory: +//! seam 6 of the design sends the cross-world bridge to `id-worlds` +//! (step 5, #4408), and this module re-exports it from there. //! //! A group changes only by events. [`fold`] computes its state from //! the whole set of events, so the result does not depend on the order @@ -26,7 +26,7 @@ //! Authority and the cap are checked against the events that come before each event in the //! canonical order. See [`fold`]. -pub mod worlds; +pub use id_worlds::groups::worlds; pub use id_groups::groups::{actions, log, warnings}; diff --git a/pkgs/id/src/lib.rs b/pkgs/id/src/lib.rs index 8378bdf829..f168420b54 100644 --- a/pkgs/id/src/lib.rs +++ b/pkgs/id/src/lib.rs @@ -260,7 +260,7 @@ pub mod world; #[cfg(feature = "world")] pub use id_caps::world_caps; #[cfg(feature = "world")] -pub mod world_cache; +pub use id_worlds::world_cache; pub mod world_compile; #[cfg(feature = "world")] pub mod world_doctor; @@ -272,7 +272,7 @@ mod session_host; pub mod world_hub; #[cfg(feature = "world")] pub use id_caps::world_limits; -pub(crate) mod world_line; +pub(crate) use id_worlds::world_line; #[cfg(feature = "world")] pub use id_caps::world_manifest; #[cfg(feature = "world")] @@ -292,7 +292,7 @@ pub mod world_ssh; #[cfg(feature = "world")] pub mod world_store; #[cfg(feature = "world")] -pub(crate) mod world_terminal; +pub(crate) use id_worlds::world_terminal; #[cfg(feature = "web")] pub use id_core::qr;