From 02f8aa37f1a7c626f1f161249d0a5d9a2e56a34b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 13:04:51 +0000 Subject: [PATCH 1/3] dir-sim: licences as DR64 planes over a version's users license::LicensePlanes builds, from ogar-az's decoded licence and subscribedSkus pages, at most 64 licence-state codes per tenant (sku, direct|group, state), each one bit plane over the version's user ordinals, plus a read plane. Holder and state queries are Quack filters over those resident planes. Not read (absent, null, or not on a page) stays apart from read-none; two paths to one SKU are one holder; a 65th code is refused (TooManyStates), never merged; unknown or repeated users and repeated SKUs are refused; capacity is held as the decoded exact i64 counts beside the planes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF --- crates/lance-graph-dir-sim/src/lib.rs | 1 + crates/lance-graph-dir-sim/src/license.rs | 268 ++++++++++++++++++ .../tests/license_planes.rs | 204 +++++++++++++ 3 files changed, 473 insertions(+) create mode 100644 crates/lance-graph-dir-sim/src/license.rs create mode 100644 crates/lance-graph-dir-sim/tests/license_planes.rs diff --git a/crates/lance-graph-dir-sim/src/lib.rs b/crates/lance-graph-dir-sim/src/lib.rs index 711c3ebc9..609eef664 100644 --- a/crates/lance-graph-dir-sim/src/lib.rs +++ b/crates/lance-graph-dir-sim/src/lib.rs @@ -43,6 +43,7 @@ mod exec; pub mod groups; pub mod image; pub mod ldap; +pub mod license; pub mod log; pub mod observe; pub mod proxy; diff --git a/crates/lance-graph-dir-sim/src/license.rs b/crates/lance-graph-dir-sim/src/license.rs new file mode 100644 index 000000000..7f160e037 --- /dev/null +++ b/crates/lance-graph-dir-sim/src/license.rs @@ -0,0 +1,268 @@ +//! Licences as DR64 planes over a version's users. +//! +//! The Graph licence pages that `ogar_az::license` decodes become, per tenant, +//! at most [`MAX_LICENSE_STATES`] licence-state codes. A code is one +//! `(sku, via, state)` triple: the SKU, whether the path is direct or through a +//! group, and the reported state. Each code is one bit plane over the version's +//! user ordinals, so one DR64 tile holds every licence state of a tenant, and a +//! licence question is a Quack `Filter` over resident planes, like every other +//! population query here. +//! +//! What the planes keep apart, by construction: +//! +//! * **Not read is not none.** [`LicensePlanes`] has a read plane. A user whose +//! `licenseAssignmentStates` was absent or `null`, or who is on no licence +//! page at all, is not read; a user read with an empty list is read and +//! holds no code. Every holder query is gated by the read plane. +//! * **A path is not a seat.** A user who holds one SKU directly and through a +//! group sets two codes and is one holder of that SKU. +//! * **Overflow is refused.** A 65th distinct code is +//! [`LicenseError::TooManyStates`], never a dropped or merged state. +//! * **Capacity stays exact.** Purchased and consumed units are the decoded +//! `i64` counts, held beside the planes; they are not lane values. +//! +//! The assigning group's identity is not part of a code (that would multiply +//! codes by groups); several group paths to one SKU in one state set one bit. + +use lance_graph_mask_risc::{words_for, Foreign, Planes}; +use lance_graph_quack::{Agg, Filter, Mask}; +use ogar_az::license::{LicensesPage, PathState, SkuCapacity, SkuPage}; +use ogar_dir_core::Guid128; + +use crate::exec::{self, Kept}; +use crate::snapshot::ones; +use crate::View; + +/// Licence-state codes per tenant: one DR64 tile. +pub const MAX_LICENSE_STATES: usize = 64; + +/// How a licence reaches a user. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum Via { + /// Assigned to the user directly. + Direct, + /// Inherited from a group. + Group, +} + +/// One licence-state code: a SKU, how it is assigned, and its reported state. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct LicenseState { + /// The SKU. + pub sku: Guid128, + /// Direct or through a group. + pub via: Via, + /// The reported state, as decoded. + pub state: PathState, +} + +/// Why licence planes were not built. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum LicenseError { + /// More distinct licence-state codes than one DR64 tile holds. + TooManyStates { + /// Distinct codes seen before the limit was passed. + found: usize, + /// [`MAX_LICENSE_STATES`]. + limit: usize, + }, + /// A licence page names a user the version does not have. + UnknownUser(Guid128), + /// A user appears on more than one licence page entry. + DuplicateUser(Guid128), + /// A SKU appears more than once in the capacity pages. + DuplicateSku(Guid128), +} + +/// A tenant's licences over one version's users. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct LicensePlanes { + n_users: usize, + read: Vec, + states: Vec, + planes: Vec>, + capacity: Vec, +} + +impl LicensePlanes { + /// Build the planes from decoded licence and capacity pages. + /// + /// # Errors + /// + /// [`LicenseError`]: too many codes, a user the version does not know, a + /// user listed twice, or a SKU listed twice in the capacity pages. + pub fn build( + v: &View<'_>, + licenses: &[LicensesPage], + skus: &[SkuPage], + ) -> Result { + let n_users = v.users_len(); + let words = words_for(n_users); + let mut read = vec![0u64; words]; + let mut states: Vec = Vec::new(); + let mut planes: Vec> = Vec::new(); + for u in licenses.iter().flat_map(|p| &p.users) { + let o = v + .user_ordinal(&u.user) + .ok_or(LicenseError::UnknownUser(u.user))?; + let row = usize::from(o.0); + if read[row / 64] & (1 << (row % 64)) != 0 { + return Err(LicenseError::DuplicateUser(u.user)); + } + let Some(paths) = &u.paths else { + continue; + }; + read[row / 64] |= 1 << (row % 64); + for p in paths { + let code = LicenseState { + sku: p.sku, + via: if p.assigned_by_group.is_some() { + Via::Group + } else { + Via::Direct + }, + state: p.state.clone(), + }; + let i = match states.iter().position(|s| *s == code) { + Some(i) => i, + None => { + if states.len() == MAX_LICENSE_STATES { + return Err(LicenseError::TooManyStates { + found: states.len() + 1, + limit: MAX_LICENSE_STATES, + }); + } + states.push(code); + planes.push(vec![0u64; words]); + states.len() - 1 + } + }; + planes[i][row / 64] |= 1 << (row % 64); + } + } + let mut capacity: Vec = Vec::new(); + for s in skus.iter().flat_map(|p| &p.skus) { + if capacity.iter().any(|c| c.sku == s.sku) { + return Err(LicenseError::DuplicateSku(s.sku)); + } + capacity.push(s.clone()); + } + Ok(Self { + n_users, + read, + states, + planes, + capacity, + }) + } + + /// The licence-state codes, in first-seen order; the index is the plane. + pub fn states(&self) -> &[LicenseState] { + &self.states + } + + /// The decoded capacity of `sku`, if its capacity was read. + pub fn capacity(&self, sku: &Guid128) -> Option<&SkuCapacity> { + self.capacity.iter().find(|c| c.sku == *sku) + } + + /// Users whose licences were read (an empty list included). + pub fn read(&self) -> Kept { + self.run(Filter::plane(Mask(0))) + } + + /// Users whose licences were not read. + pub fn not_read(&self) -> Kept { + self.run(Filter::and([ + Filter::plane(Mask(1)), + Filter::negate(Filter::plane(Mask(0))), + ])) + } + + /// Read users holding `sku` by any path in any state. Each holder is one + /// row however many paths it has. + pub fn holders(&self, sku: &Guid128) -> Kept { + self.run(self.holders_filter(sku)) + } + + /// How many read users hold `sku` by any path in any state. + pub fn holder_count(&self, sku: &Guid128) -> usize { + let all = ones(self.n_users); + exec::count( + self.holders_filter(sku), + &self.planes_with(&all).planes(), + &Foreign::NONE, + ) + } + + /// Read users holding licence-state code `code` (an index into + /// [`Self::states`]); `None` for an index past the codes. + pub fn with_state(&self, code: usize) -> Option { + (code < self.states.len()).then(|| { + self.run(Filter::and([ + Filter::plane(Mask(0)), + Filter::plane(Mask(Self::plane_mask(code))), + ])) + }) + } + + /// Plane 0 is the read plane, plane 1 every user, then one per code. + fn plane_mask(code: usize) -> u16 { + u16::try_from(code + 2).expect("at most 64 codes") + } + + fn holders_filter(&self, sku: &Guid128) -> Filter { + let held: Vec = self + .states + .iter() + .enumerate() + .filter(|(_, s)| s.sku == *sku) + .map(|(i, _)| Filter::plane(Mask(Self::plane_mask(i)))) + .collect(); + if held.is_empty() { + // No code names the SKU: no row holds it. + return Filter::and([ + Filter::plane(Mask(0)), + Filter::negate(Filter::plane(Mask(0))), + ]); + } + Filter::and([Filter::plane(Mask(0)), Filter::or(held)]) + } + + fn planes_with<'a>(&'a self, all: &'a [u64]) -> PlaneSet<'a> { + let mut masks: Vec<&'a [u64]> = Vec::with_capacity(self.planes.len() + 2); + masks.push(&self.read); + masks.push(all); + masks.extend(self.planes.iter().map(Vec::as_slice)); + PlaneSet { + n_rows: self.n_users, + masks, + } + } + + fn run(&self, filter: Filter) -> Kept { + let all = ones(self.n_users); + let set = self.planes_with(&all); + exec::keep( + &exec::program(filter, Agg::Rows), + &set.planes(), + &Foreign::NONE, + ) + } +} + +/// The resident planes one licence query reads. +struct PlaneSet<'a> { + n_rows: usize, + masks: Vec<&'a [u64]>, +} + +impl PlaneSet<'_> { + fn planes(&self) -> Planes<'_> { + Planes { + n_rows: self.n_rows, + masks: &self.masks, + lanes: &[], + } + } +} diff --git a/crates/lance-graph-dir-sim/tests/license_planes.rs b/crates/lance-graph-dir-sim/tests/license_planes.rs new file mode 100644 index 000000000..b4dc51d64 --- /dev/null +++ b/crates/lance-graph-dir-sim/tests/license_planes.rs @@ -0,0 +1,204 @@ +//! Licences as DR64 planes over a version's users (`license::LicensePlanes`). + +use lance_graph_dir_sim::license::{LicenseError, LicensePlanes, Via, MAX_LICENSE_STATES}; +use lance_graph_dir_sim::{Observation, ObservedNode, VersionStore}; +use ogar_az::license::{ingest_licenses_page, ingest_skus_page, LicensesPage, PathState}; +use ogar_dir_core::{DirectoryScope, Guid128}; + +const SCOPE: DirectoryScope = DirectoryScope(Guid128([0x5C; 16])); +const SKU: &str = "c7df2760-2c81-4ef7-b578-5b5392b571df"; +const SKU2: &str = "4b9405b0-7788-4568-add1-99614e613b69"; +const GROUP: &str = "3f2504e0-4f89-11d3-9a0c-0305e82c3301"; + +fn user(u: u8) -> Guid128 { + let mut b = [0u8; 16]; + b[0] = 1; + b[1] = u; + Guid128(b) +} + +fn store(users: u8) -> VersionStore { + let mut o = Observation { + scope: SCOPE, + nodes: Vec::new(), + members: Vec::new(), + }; + for u in 0..users { + let mail = format!("u{u}@example.test"); + o.nodes.push((user(u), ObservedNode::user(&mail, &mail))); + } + let mut st = VersionStore::new(); + st.observe("ad", 0, o).unwrap(); + st +} + +fn g(s: &str) -> Guid128 { + Guid128::parse(s).unwrap() +} + +fn page(entries: &[String]) -> LicensesPage { + ingest_licenses_page(&format!(r#"{{"value":[{}]}}"#, entries.join(","))).unwrap() +} + +fn path(sku: &str, state: &str, group: Option<&str>) -> String { + match group { + Some(gr) => format!(r#"{{"skuId":"{sku}","state":"{state}","assignedByGroup":"{gr}"}}"#), + None => format!(r#"{{"skuId":"{sku}","state":"{state}"}}"#), + } +} + +fn entry(u: u8, paths: Option<&[String]>) -> String { + match paths { + Some(p) => format!( + r#"{{"id":"{}","licenseAssignmentStates":[{}]}}"#, + user(u), + p.join(",") + ), + None => format!(r#"{{"id":"{}"}}"#, user(u)), + } +} + +fn build(users: u8, entries: &[String]) -> Result { + let st = store(users); + let v = st.view(st.tag("observed").unwrap()).unwrap(); + LicensePlanes::build(&v, &[page(entries)], &[]) +} + +/// Falsifier: a not-read user counted as read (or as holding nothing that was +/// read) moves a row between the two sets. +#[test] +fn not_read_is_not_none() { + // u0 read with none, u1 property absent, u2 not on the page, u3 holds SKU. + let p = build( + 4, + &[ + entry(0, Some(&[])), + entry(1, None), + entry(3, Some(&[path(SKU, "Active", None)])), + ], + ) + .unwrap(); + assert_eq!(p.read().rows(), vec![0, 3]); + assert_eq!(p.not_read().rows(), vec![1, 2]); + assert_eq!(p.holders(&g(SKU)).rows(), vec![3]); + assert_eq!(p.holder_count(&g(SKU)), 1); + // A SKU no code names has no holder, and is not an error. + assert!(p.holders(&g(SKU2)).rows().is_empty()); + assert_eq!(p.holder_count(&g(SKU2)), 0); +} + +/// Falsifier: counting paths as holders makes u0 count twice. +#[test] +fn two_paths_are_one_holder() { + let p = build( + 2, + &[ + entry( + 0, + Some(&[path(SKU, "Active", None), path(SKU, "Active", Some(GROUP))]), + ), + entry(1, Some(&[path(SKU, "Active", Some(GROUP))])), + ], + ) + .unwrap(); + assert_eq!(p.states().len(), 2, "direct and group are two codes"); + assert_eq!(p.states()[0].via, Via::Direct); + assert_eq!(p.states()[1].via, Via::Group); + assert_eq!(p.holders(&g(SKU)).rows(), vec![0, 1]); + assert_eq!(p.holder_count(&g(SKU)), 2); + assert_eq!(p.with_state(0).unwrap().rows(), vec![0]); + assert_eq!(p.with_state(1).unwrap().rows(), vec![0, 1]); + assert!(p.with_state(2).is_none()); +} + +/// Falsifier: merging states (or coercing unknown text to Active) collapses +/// the three codes. +#[test] +fn states_stay_apart_and_unknown_text_is_kept() { + let p = build( + 3, + &[ + entry(0, Some(&[path(SKU, "Active", None)])), + entry(1, Some(&[path(SKU, "Disabled", None)])), + entry(2, Some(&[path(SKU, "ActiveWithError", None)])), + ], + ) + .unwrap(); + let states: Vec<&PathState> = p.states().iter().map(|s| &s.state).collect(); + assert_eq!( + states, + [ + &PathState::Active, + &PathState::Disabled, + &PathState::Other("ActiveWithError".into()) + ] + ); + // A disabled path is still a held SKU: the planes do not decide entitlement. + assert_eq!(p.holders(&g(SKU)).rows(), vec![0, 1, 2]); +} + +fn sku(i: usize) -> String { + format!("00000000-0000-4000-8000-{i:012x}") +} + +/// Falsifier: silently dropping or merging the 65th code builds planes. +#[test] +fn a_65th_state_is_refused_and_64_fit() { + let fits: Vec = (0..MAX_LICENSE_STATES) + .map(|i| path(&sku(i), "Active", None)) + .collect(); + let p = build(1, &[entry(0, Some(&fits))]).unwrap(); + assert_eq!(p.states().len(), 64); + assert_eq!(p.holder_count(&g(&sku(63))), 1); + + let over: Vec = (0..=MAX_LICENSE_STATES) + .map(|i| path(&sku(i), "Active", None)) + .collect(); + assert_eq!( + build(1, &[entry(0, Some(&over))]), + Err(LicenseError::TooManyStates { + found: 65, + limit: 64 + }) + ); +} + +#[test] +fn unknown_or_repeated_entries_are_refused() { + assert_eq!( + build(1, &[entry(5, Some(&[]))]), + Err(LicenseError::UnknownUser(user(5))) + ); + assert_eq!( + build(1, &[entry(0, Some(&[])), entry(0, Some(&[]))]), + Err(LicenseError::DuplicateUser(user(0))) + ); + let st = store(1); + let v = st.view(st.tag("observed").unwrap()).unwrap(); + let skus = ingest_skus_page(&format!( + r#"{{"value":[ + {{"skuId":"{SKU}","consumedUnits":1,"prepaidUnits":{{"enabled":1,"suspended":0,"warning":0}}}}, + {{"skuId":"{SKU}","consumedUnits":1,"prepaidUnits":{{"enabled":1,"suspended":0,"warning":0}}}}]}}"# + )) + .unwrap(); + assert_eq!( + LicensePlanes::build(&v, &[], &[skus]), + Err(LicenseError::DuplicateSku(g(SKU))) + ); +} + +#[test] +fn capacity_is_held_exact_beside_the_planes() { + let st = store(1); + let v = st.view(st.tag("observed").unwrap()).unwrap(); + let skus = ingest_skus_page(&format!( + r#"{{"value":[{{"skuId":"{SKU}","consumedUnits":1200,"prepaidUnits":{{"enabled":1000,"suspended":0,"warning":0}}}}]}}"# + )) + .unwrap(); + let p = LicensePlanes::build(&v, &[], &[skus]).unwrap(); + let c = p.capacity(&g(SKU)).unwrap(); + assert_eq!((c.enabled, c.consumed, c.free()), (1000, 1200, -200)); + assert!(p.capacity(&g(SKU2)).is_none()); + // Capacity read, licences not: every user is not read. + assert_eq!(p.not_read().rows(), vec![0]); +} From 00e1ecb7367337fb1a98bfe07220073ada4a14cf Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 13:05:18 +0000 Subject: [PATCH 2/3] board: D-DIRSIM-LICENSE-DR64 row Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF --- .claude/board/STATUS_BOARD.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.claude/board/STATUS_BOARD.md b/.claude/board/STATUS_BOARD.md index fd3633011..b757c142c 100644 --- a/.claude/board/STATUS_BOARD.md +++ b/.claude/board/STATUS_BOARD.md @@ -7,6 +7,7 @@ Plan `.claude/plans/xlog-knowledge-spine-v1.md` (charter, DOCS ONLY); harvest `x | D-XLOG-KNOWLEDGE-0 | Charter: three IR routes kept separate, donor roles, gates G0..G8, STOP conditions | In PR (#2093), docs only | | D-XLOG-KNOWLEDGE-G0 | xlog.md + fork source harvest, page/claim/source manifest; 2.80x Scallop claim marked CONFLICT | Partial: 12 pages read, `/llms.txt` 404; manifest not built | | D-XLOG-KNOWLEDGE-G1 | Reproduce the coverage census at pinned SHAs; add Datafrog as an independent comparator; falsifiers | Shipped (#2095): census reproduced byte-identical (lance-graph `bdee050`, xlog `beac406` = tree of `656def9`). Datafrog arm (`datafrog_arm.rs`, AdaWorldAPI fork `edd7cfc`): agrees on 85/87 oracle-agrees rules, 2 not applicable (integer constant), 0 disagree; rungs unchanged. 4 disable runs red; broken join -> 68 disagreements in the census, 0 rung changes. Entry `2026-11-15-d-xlog-knowledge-g1-datafrog.md` | +| D-DIRSIM-LICENSE-DR64 | Licences from ogar-az (OGAR #380) as DR64 planes over a dir-sim version: <=64 (sku, via, state) codes per tenant, read plane, exact capacity | In PR: `license::LicensePlanes`; 6 tests, 3 disable runs red (not-read->read, no 65th-code cap, no code dedupe). Next: DT64 `LaneSource` binding over the planes. DR512 reserved for users per OU per group (operator) | | D-DIRSIM-LINEAR-RESTORE | `VersionStore::restore` continues the previous overlay along a linear history | In PR: replay+restore 1.19 ms at 1 024 re-reads (was 50 ms), 0.45 ms at 128; 64-step chain applies exactly 64 changes (old fold 2 080); branch re-folds from root; disable red. Closes the quadratic-replay open point of `2026-11-16-d-dirsim-delta-read-1.md` | | D-DIRSIM-DELTA-READ-1 | Read what changed between observations from the stored deltas; history cost probe | In PR: `VersionStore::history` (34-47 ns, 0 alloc at 1..1024 re-reads); `view`/`diff` linear in lineage; replay quadratic (50 ms cold at 1024) - linear restore proposed. Entry `2026-11-16-d-dirsim-delta-read-1.md` | | D-DIRSIM-REOBSERVE | dir-sim stores a re-read as its verified changes; plan intent from the nearest observation | In PR: `VersionStore::reobserve`; one membership change = 1 change, 125 B log batch vs 11 094 B for a second root; 3 disable runs red. Entry `2026-11-16-d-dirsim-reobserve.md` | From 69d3b5f3d4f8ec9b32bc438e197281178ae97c9b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 13:55:34 +0000 Subject: [PATCH 3/3] fix(dir-sim): licence planes exclude deleted slots; duplicate users caught in either order --- crates/lance-graph-dir-sim/src/license.rs | 28 +++++++--- .../tests/license_planes.rs | 55 +++++++++++++++++++ 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/crates/lance-graph-dir-sim/src/license.rs b/crates/lance-graph-dir-sim/src/license.rs index 7f160e037..7ef2183cd 100644 --- a/crates/lance-graph-dir-sim/src/license.rs +++ b/crates/lance-graph-dir-sim/src/license.rs @@ -30,8 +30,7 @@ use ogar_az::license::{LicensesPage, PathState, SkuCapacity, SkuPage}; use ogar_dir_core::Guid128; use crate::exec::{self, Kept}; -use crate::snapshot::ones; -use crate::View; +use crate::{UserOrdinal, View}; /// Licence-state codes per tenant: one DR64 tile. pub const MAX_LICENSE_STATES: usize = 64; @@ -78,6 +77,9 @@ pub enum LicenseError { #[derive(Clone, Debug, PartialEq, Eq)] pub struct LicensePlanes { n_users: usize, + /// The users that exist in this version; a deleted user keeps its slot + /// but is not here. + live: Vec, read: Vec, states: Vec, planes: Vec>, @@ -99,6 +101,15 @@ impl LicensePlanes { let n_users = v.users_len(); let words = words_for(n_users); let mut read = vec![0u64; words]; + // A user listed on a page, whether or not its licences were read. + let mut seen = vec![0u64; words]; + let mut live = vec![0u64; words]; + for row in 0..n_users { + let o = UserOrdinal(u16::try_from(row).expect("user ordinals are u16")); + if v.user_guid(o).is_some() { + live[row / 64] |= 1 << (row % 64); + } + } let mut states: Vec = Vec::new(); let mut planes: Vec> = Vec::new(); for u in licenses.iter().flat_map(|p| &p.users) { @@ -106,9 +117,10 @@ impl LicensePlanes { .user_ordinal(&u.user) .ok_or(LicenseError::UnknownUser(u.user))?; let row = usize::from(o.0); - if read[row / 64] & (1 << (row % 64)) != 0 { + if seen[row / 64] & (1 << (row % 64)) != 0 { return Err(LicenseError::DuplicateUser(u.user)); } + seen[row / 64] |= 1 << (row % 64); let Some(paths) = &u.paths else { continue; }; @@ -149,6 +161,7 @@ impl LicensePlanes { } Ok(Self { n_users, + live, read, states, planes, @@ -187,10 +200,9 @@ impl LicensePlanes { /// How many read users hold `sku` by any path in any state. pub fn holder_count(&self, sku: &Guid128) -> usize { - let all = ones(self.n_users); exec::count( self.holders_filter(sku), - &self.planes_with(&all).planes(), + &self.planes_with(&self.live).planes(), &Foreign::NONE, ) } @@ -206,7 +218,8 @@ impl LicensePlanes { }) } - /// Plane 0 is the read plane, plane 1 every user, then one per code. + /// Plane 0 is the read plane, plane 1 the version's existing users, then + /// one per code. fn plane_mask(code: usize) -> u16 { u16::try_from(code + 2).expect("at most 64 codes") } @@ -241,8 +254,7 @@ impl LicensePlanes { } fn run(&self, filter: Filter) -> Kept { - let all = ones(self.n_users); - let set = self.planes_with(&all); + let set = self.planes_with(&self.live); exec::keep( &exec::program(filter, Agg::Rows), &set.planes(), diff --git a/crates/lance-graph-dir-sim/tests/license_planes.rs b/crates/lance-graph-dir-sim/tests/license_planes.rs index b4dc51d64..3e5e89d8e 100644 --- a/crates/lance-graph-dir-sim/tests/license_planes.rs +++ b/crates/lance-graph-dir-sim/tests/license_planes.rs @@ -202,3 +202,58 @@ fn capacity_is_held_exact_beside_the_planes() { // Capacity read, licences not: every user is not read. assert_eq!(p.not_read().rows(), vec![0]); } + +/// A user deleted in the version keeps its slot but is not a user: it is +/// neither read nor unread. Falsifier: the unread set taken against every +/// slot instead of the version's existing users. +#[test] +fn a_deleted_user_is_not_unread() { + let mut st = store(3); + let mut o = Observation { + scope: SCOPE, + nodes: Vec::new(), + members: Vec::new(), + }; + for u in [0u8, 2] { + let mail = format!("u{u}@example.test"); + o.nodes.push((user(u), ObservedNode::user(&mail, &mail))); + } + let gone = st + .view(st.tag("observed").unwrap()) + .unwrap() + .user_ordinal(&user(1)) + .unwrap(); + let v1 = st.reobserve("ad", 1, o).unwrap(); + let v = st.view(v1).unwrap(); + assert_eq!(v.users_len(), 3, "the deleted user keeps its slot"); + assert_eq!(v.user_guid(gone), None, "and is not a user of this version"); + let p = LicensePlanes::build(&v, &[page(&[entry(0, Some(&[]))])], &[]).unwrap(); + assert_eq!(p.read().rows(), vec![0], "u0 read"); + assert_eq!( + p.not_read().rows(), + vec![2], + "u2 unread; the deleted slot is in neither set" + ); +} + +/// A user listed twice is refused in either order, whether or not its +/// licences were read the first time. Falsifier: duplicates tracked by the +/// read plane, which an unread first entry leaves clear. +#[test] +fn a_repeated_user_is_refused_in_either_order() { + let read = entry(0, Some(&[path(SKU, "Active", None)])); + let unread = entry(0, None); + for entries in [ + [unread.clone(), read.clone()], + [read.clone(), unread.clone()], + [unread.clone(), unread.clone()], + ] { + assert_eq!( + build(2, &entries).err(), + Some(LicenseError::DuplicateUser(user(0))), + "{entries:?}" + ); + } + // Silence half: one entry per user is admitted. + assert!(build(2, &[unread, entry(1, None)]).is_ok()); +}