diff --git a/crates/huginn-daemon/src/daemon.rs b/crates/huginn-daemon/src/daemon.rs index 5a15212..fcbce14 100644 --- a/crates/huginn-daemon/src/daemon.rs +++ b/crates/huginn-daemon/src/daemon.rs @@ -123,6 +123,8 @@ pub(crate) mod tests { pub(crate) const NEAR: &str = "yggdrasix"; /// `INSTANCE` whole, with more after it. pub(crate) const PREFIXED: &str = "yggdrasil-two"; + /// `INSTANCE` in another case, which a slug label permits. + pub(crate) const CASED: &str = "Yggdrasil"; pub(crate) const CAMPAIGN: &str = "eureka-state"; pub(crate) fn slug(value: &str) -> Slug { @@ -455,14 +457,17 @@ pub(crate) mod tests { let history = HuginnMindRequest::History { instance: slug(OTHER), scope }; assert_eq!(daemon.handle(history, now()), HuginnMindResponse::Refused(foreign)); - // Two names a comparison could mistake for this mind's. `NEAR` is + // Three names a comparison could mistake for this mind's. `NEAR` is // `INSTANCE`'s own length and differs in its last byte, so a check // reading lengths, first bytes, or running only when the declared name // is longer admits it; `PREFIXED` carries `INSTANCE` whole, so a prefix - // test admits it. Both are refused on the read side and the write side. + // test admits it; `CASED` is `INSTANCE` in another case, which a slug + // label permits, so a check folding case admits it. Each is refused on + // the read side and the write side. assert_eq!(NEAR.len(), INSTANCE.len()); assert!(PREFIXED.starts_with(INSTANCE)); - for declared in [NEAR, PREFIXED] { + assert_eq!(CASED.to_ascii_lowercase(), INSTANCE); + for declared in [NEAR, PREFIXED, CASED] { let refusal = MindRefusal::ForeignInstance { declared: declared.into(), mind: INSTANCE.into() }; let query = HuginnMindRequest::Query { instance: slug(declared), query: PipelineQuery::default() }; assert_eq!(daemon.handle(query, now()), HuginnMindResponse::Refused(refusal.clone()), "{declared}"); diff --git a/crates/huginn-mind/src/fixtures.rs b/crates/huginn-mind/src/fixtures.rs index 5797fe0..3c84a09 100644 --- a/crates/huginn-mind/src/fixtures.rs +++ b/crates/huginn-mind/src/fixtures.rs @@ -30,6 +30,11 @@ pub(crate) const NEAR_INSTANCE: &str = "yggdrasix"; /// A foreign instance carrying `INSTANCE` whole as its prefix, so a prefix /// test admits it. pub(crate) const PREFIXED_INSTANCE: &str = "yggdrasil-two"; +/// A foreign instance differing from `INSTANCE` in case alone. A slug label is +/// `[A-Za-z0-9_-]{1,64}`, so this is a name a client may declare and a mind +/// may hold: two minds whose names differ only in case are two minds, and a +/// comparison that folds case answers one of them for the other. +pub(crate) const CASED_INSTANCE: &str = "Yggdrasil"; pub(crate) const CAMPAIGN: &str = "eureka-state"; pub(crate) const REPO: &str = "GameCult/Epiphany"; pub(crate) const OTHER_REPO: &str = "GameCult/Huginn"; diff --git a/crates/huginn-mind/src/mind.rs b/crates/huginn-mind/src/mind.rs index 78b54c8..94dc6cb 100644 --- a/crates/huginn-mind/src/mind.rs +++ b/crates/huginn-mind/src/mind.rs @@ -411,10 +411,14 @@ mod tests { /// its last byte, so a check reading only the lengths, only the first byte, /// or running only when the declared name is longer lets it through; /// `PREFIXED_INSTANCE` has the mind's whole name as its prefix, so a check - /// asking whether one starts with the other lets that one through. + /// asking whether one starts with the other lets that one through; and + /// `CASED_INSTANCE` differs in case alone, which a slug label permits, so a + /// check folding case answers for a mind that is not this one. #[test] fn require_instance_is_the_one_check_admission_and_the_daemon_share() { - use crate::fixtures::{NEAR_INSTANCE, OTHER_INSTANCE, PREFIXED_INSTANCE, now, provenance, seeded}; + use crate::fixtures::{ + CASED_INSTANCE, NEAR_INSTANCE, OTHER_INSTANCE, PREFIXED_INSTANCE, now, provenance, seeded, + }; use crate::receipt::Faculty; let mut mind = seeded(); @@ -425,7 +429,9 @@ mod tests { assert_eq!(NEAR_INSTANCE.len(), INSTANCE.len(), "the near name is the mind's own length"); assert_eq!(NEAR_INSTANCE[..INSTANCE.len() - 1], INSTANCE[..INSTANCE.len() - 1], "and differs in one byte"); assert!(PREFIXED_INSTANCE.starts_with(INSTANCE), "the prefixed name carries the mind's whole name"); - for declared in [NEAR_INSTANCE, PREFIXED_INSTANCE] { + assert_eq!(CASED_INSTANCE.to_ascii_lowercase(), INSTANCE, "the cased name differs in case alone"); + assert_ne!(CASED_INSTANCE, INSTANCE); + for declared in [NEAR_INSTANCE, PREFIXED_INSTANCE, CASED_INSTANCE] { assert_eq!( mind.require_instance(&slug(declared)).err(), Some(MindRefusal::ForeignInstance { declared: declared.into(), mind: INSTANCE.into() }), diff --git a/tools/eureka-cut10-mutations.psd1 b/tools/eureka-cut10-mutations.psd1 index 65776ad..a086c3c 100644 --- a/tools/eureka-cut10-mutations.psd1 +++ b/tools/eureka-cut10-mutations.psd1 @@ -90,6 +90,15 @@ Old = ' if declared != self.instance() {' New = ' if !declared.0.starts_with(&self.instance().0) {' } + @{ + Id = 'D1L5' + Rule = 'It compares the names as written: a slug may carry uppercase, so two names differing in case are two minds.' + Test = 'mind::tests::require_instance_is_the_one_check_admission_and_the_daemon_share' + Command = 'cargo test -p huginn-mind --lib' + File = 'crates/huginn-mind/src/mind.rs' + Old = ' if declared != self.instance() {' + New = ' if !declared.0.eq_ignore_ascii_case(&self.instance().0) {' + } @{ Id = 'D1N' Rule = 'The refusal names which mind refused, so an agent can act on the field rather than guess.' @@ -126,6 +135,14 @@ Old = ' if declared != self.instance() {' New = ' if declared.0.len() != self.instance().0.len() {' } + @{ + Id = 'D1DL2' + Rule = 'And case, the daemon''s way: the daemon''s own fixtures carry a name differing from the mind''s in case alone.' + Test = 'daemon::tests::a_read_or_a_write_naming_another_instance_is_refused_by_the_mind_and_writes_nothing' + File = 'crates/huginn-mind/src/mind.rs' + Old = ' if declared != self.instance() {' + New = ' if !declared.0.eq_ignore_ascii_case(&self.instance().0) {' + } @{ Id = 'D2' Rule = 'Rulings 14 and 18 on the wire: the daemon passes the declared instance to the mind as the client sent it.'