Give the instance check a name differing in case alone
Every foreign fixture differed from the mind's name in its bytes, so a check
folding case passed both suites. A slug label is `[A-Za-z0-9_-]{1,64}`:
uppercase is legal, `Yggdrasil` and `yggdrasil` are two names a client may
declare and two minds a host may hold, and a comparison that folds case
answers one of them for the other. Soul found the mutant alive.
`CASED_INSTANCE` stands beside the near and prefixed names in the mind
fixtures and `CASED` beside them in the daemon's, and each test asserts the
relation it relies on before using it: the cased name lowercases to the mind's
and is not equal to it.
`D1L5` folds case against the mind suite and `D1DL2` against the daemon suite,
so both fixture sets are load-bearing rather than only the one.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
731b542354
commit
202e5e3ba6
4 changed files with 39 additions and 6 deletions
|
|
@ -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}");
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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() }),
|
||||
|
|
|
|||
|
|
@ -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.'
|
||||
|
|
|
|||
Loading…
Reference in a new issue