diff --git a/apps/origin-src/src/annotations/mod.rs b/apps/origin-src/src/annotations/mod.rs index c21fd7e5..73cbe22b 100644 --- a/apps/origin-src/src/annotations/mod.rs +++ b/apps/origin-src/src/annotations/mod.rs @@ -16,6 +16,7 @@ mod retention; use std::collections::HashSet; use origin_platform::{Native, Platform}; +use origin_shared::api::Annotation; use origin_shared::{ ChangeId, EncodedObject, Kind, Principal, Record, RecordId, RevisionId, Statement, StatementId, }; @@ -33,17 +34,6 @@ pub struct Annotations<'a, P = Native> { index: Index, } -/// A statement, and whether its issuer superseded it. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct Annotation { - /// The statement's id. - pub id: StatementId, - /// The statement. - pub statement: Statement, - /// The first statement from the same issuer that supersedes it. - pub superseded_by: Option, -} - impl<'a, P: Platform> Annotations<'a, P> { /// The statements of `store`, as `index` knows them. pub fn new(store: &'a Store

, index: Index) -> Self { @@ -190,12 +180,31 @@ impl<'a, P: Platform> Annotations<'a, P> { Ok(None) } - /// The statements about `subject`, in arrival order. + /// The statements about `subject`, in arrival order, each saying + /// whether its claim holds, as [`Annotations::claims`] finds: so readers + /// such as CI runners count results as the landing queue does. /// /// # Errors /// - /// Fails if a statement cannot be read. + /// Fails if a statement, or a record or tree claims read, cannot be + /// read. pub fn about(&self, subject: RecordId) -> Result, StoreError> { + let mut listed = self.listed(subject)?; + let holding: HashSet = + self.claims_of(&listed)?.iter().map(Claim::id).collect(); + for annotation in &mut listed { + annotation.holds = holding.contains(&annotation.id); + } + Ok(listed) + } + + /// The statements about `subject`, in arrival order, without finding + /// which hold. + /// + /// # Errors + /// + /// Fails if a statement cannot be read. + fn listed(&self, subject: RecordId) -> Result, StoreError> { self.index .statements(subject) .iter() @@ -205,6 +214,7 @@ impl<'a, P: Platform> Annotations<'a, P> { id, superseded_by: self.superseded_by(id, &statement)?, statement, + holds: false, }) }) .collect() @@ -223,7 +233,7 @@ impl<'a, P: Platform> Annotations<'a, P> { issuer: &Principal, ) -> Result, StoreError> { Ok(self - .about(subject)? + .listed(subject)? .into_iter() .rev() .find(|annotation| { diff --git a/apps/origin-src/src/annotations/promotion.rs b/apps/origin-src/src/annotations/promotion.rs index d8b0d80c..fec5d6fb 100644 --- a/apps/origin-src/src/annotations/promotion.rs +++ b/apps/origin-src/src/annotations/promotion.rs @@ -17,6 +17,7 @@ use std::collections::HashSet; use origin_platform::Platform; +use origin_shared::api::Annotation; use origin_shared::{Principal, Record, RecordId, Statement, StatementId, TreeId}; use super::Annotations; @@ -77,12 +78,25 @@ impl Annotations<'_, P> { /// /// Fails if a record or a tree cannot be read. pub fn claims(&self, subject: RecordId) -> Result, StoreError> { + self.claims_of(&self.listed(subject)?) + } + + /// The claims that hold of `listed`, the statements about one record, + /// as [`Annotations::claims`] finds them. + /// + /// # Errors + /// + /// Fails if a record or a tree cannot be read. + pub(super) fn claims_of(&self, listed: &[Annotation]) -> Result, StoreError> { let mut claims = Vec::new(); - for annotation in self.about(subject)? { + for annotation in listed { if annotation.superseded_by.is_some() { continue; } - let claim = match self.store.claim(annotation.id, annotation.statement) { + let claim = match self + .store + .claim(annotation.id, annotation.statement.clone()) + { Ok(Ok(claim)) => claim, // A clone may lack the trees a promotion is checked with. Ok(Err(_)) | Err(StoreError::NotFound(_)) => continue, @@ -592,6 +606,11 @@ mod tests { ); let annotations = Annotations::open(&store).unwrap(); assert_eq!(annotations.claims(RecordId::Revision(second)).unwrap(), []); + let about = annotations.about(RecordId::Revision(second)).unwrap(); + assert!( + about.iter().all(|annotation| !annotation.holds), + "{about:?}" + ); assert_eq!(promote(&store, second), [("lint".to_owned(), Some(rerun))]); } }