Persona door: tests pin every read at the door and a semantic answer by its hub
Soul C1 F4: the source, chat, chat-window, activity and roots reads are handed to the mind at the persona door (none refused NotThisDoor, each answered the same at both doors); the semantic wire test also runs through the persona door, so a held search answers by the persona hub. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e5d1984dc1
commit
cf27291471
2 changed files with 70 additions and 5 deletions
|
|
@ -1102,6 +1102,47 @@ pub(crate) mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
/// Every read the persona door answers reaches the mind there: none of the
|
||||
/// source, chat, activity and roots reads is refused as `NotThisDoor`.
|
||||
/// What the mind then says (a search, or `Unavailable` with no index or
|
||||
/// forge) is the mind's, the same at either door.
|
||||
#[test]
|
||||
fn the_persona_door_hands_every_other_read_to_the_mind() {
|
||||
use huginn_mind::wire::{ChatWindowQuery, SourceQuery};
|
||||
let (_root, mut daemon) = seeded();
|
||||
let reads = [
|
||||
HuginnMindRequest::SearchSources {
|
||||
instance: slug(INSTANCE),
|
||||
query: SourceQuery { text: Line("reconcile".into()), texts: vec![], top_k: 5, repo: None, front: false },
|
||||
},
|
||||
HuginnMindRequest::SearchChat {
|
||||
instance: slug(INSTANCE),
|
||||
query: ChatQuery { texts: vec![Line("release".into())], rooms: vec![], after_ms: None, before_ms: None, top_k: 5 },
|
||||
},
|
||||
HuginnMindRequest::ChatWindow {
|
||||
instance: slug(INSTANCE),
|
||||
query: ChatWindowQuery { event_id: Short("$a".into()), before: 5, after: 0 },
|
||||
},
|
||||
HuginnMindRequest::StewardedActivity { instance: slug(INSTANCE), repos: vec![], after: None },
|
||||
HuginnMindRequest::RootsTouched { instance: slug(INSTANCE) },
|
||||
];
|
||||
for read in reads {
|
||||
let operation = read.operation();
|
||||
let at_door = daemon.handle_at(Door::Persona, read.clone(), now());
|
||||
assert!(
|
||||
!matches!(at_door, Handled::Answered(HuginnMindResponse::Refused(MindRefusal::NotThisDoor))),
|
||||
"{operation} is refused at the persona door"
|
||||
);
|
||||
if let (Handled::Answered(at_door), Handled::Answered(at_full)) = (at_door, daemon.handle_at(Door::Full, read, now())) {
|
||||
assert_eq!(at_door, at_full, "{operation} answers the same at either door");
|
||||
}
|
||||
}
|
||||
assert!(matches!(
|
||||
daemon.handle_at(Door::Persona, HuginnMindRequest::RootsTouched { instance: slug(INSTANCE) }, now()).answered(),
|
||||
HuginnMindResponse::RootsTouched(_)
|
||||
));
|
||||
}
|
||||
|
||||
/// A declared instance outside `Slug`'s grammar is refused by its own
|
||||
/// name, `InvalidFormat`, on the read path, before the identity
|
||||
/// comparison ever runs: it is not merely a foreign mind, it names no
|
||||
|
|
|
|||
|
|
@ -143,9 +143,10 @@ fn quick() -> Backoff {
|
|||
Backoff { initial: Duration::from_millis(1), max: Duration::from_millis(2), recheck: Duration::from_secs(3600), search_deadline: Duration::from_secs(30) }
|
||||
}
|
||||
|
||||
/// A daemon serving a mind over a real socket, with the ports the test gave it.
|
||||
/// A daemon serving a mind over real sockets, its full door and its persona door, with the ports the test gave it.
|
||||
struct Harness {
|
||||
endpoint: String,
|
||||
persona_endpoint: String,
|
||||
stopping: Arc<AtomicBool>,
|
||||
serving: Option<JoinHandle<Result<()>>>,
|
||||
embedder: FakeEmbedder,
|
||||
|
|
@ -172,19 +173,31 @@ impl Harness {
|
|||
let mut daemon: Daemon<OwnedRedbMessagePackBackingStore, WorkerSink> = Daemon::new(mind, sink);
|
||||
let mut hub = bind("127.0.0.1:0".parse().unwrap(), &daemon.runtime_id()).unwrap();
|
||||
let endpoint = format!("rudp://{}", hub.local_addr().unwrap());
|
||||
let mut door = bind("127.0.0.1:0".parse().unwrap(), &daemon.runtime_id()).unwrap();
|
||||
let persona_endpoint = format!("rudp://{}", door.local_addr().unwrap());
|
||||
let registry = schema_registry().unwrap();
|
||||
let stopping = Arc::new(AtomicBool::new(false));
|
||||
let loop_stopping = Arc::clone(&stopping);
|
||||
let options = ServeOptions::default();
|
||||
let serving = std::thread::spawn(move || run(&mut daemon, &mut hub, None, ®istry, None, &loop_stopping, &options));
|
||||
Self { endpoint, stopping, serving: Some(serving), embedder, index, _root: root }
|
||||
let serving =
|
||||
std::thread::spawn(move || run(&mut daemon, &mut hub, Some(&mut door), ®istry, None, &loop_stopping, &options));
|
||||
Self { endpoint, persona_endpoint, stopping, serving: Some(serving), embedder, index, _root: root }
|
||||
}
|
||||
|
||||
fn client(&self) -> Client {
|
||||
Self::client_at(&self.endpoint)
|
||||
}
|
||||
|
||||
/// A client of the persona door.
|
||||
fn persona_client(&self) -> Client {
|
||||
Self::client_at(&self.persona_endpoint)
|
||||
}
|
||||
|
||||
fn client_at(endpoint: &str) -> Client {
|
||||
let mut client = CultMesh::create_rudp_client_for_endpoint(
|
||||
"semantic-test".to_string(),
|
||||
CULTNET_OPERATION_CONNECTION_ID,
|
||||
&self.endpoint,
|
||||
endpoint,
|
||||
CultMeshRudpSocketOptions::default(),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
@ -272,8 +285,19 @@ fn healthy() -> Harness {
|
|||
/// the members.
|
||||
#[test]
|
||||
fn a_semantic_query_returns_only_documents_the_mind_holds_and_the_selection_admits() {
|
||||
a_semantic_query_returns_only_documents_the_mind_holds_and_the_selection_admits_at(Harness::client);
|
||||
}
|
||||
|
||||
/// The same semantic read asked at the persona door: the search is held while the index works, and its answer leaves by
|
||||
/// the persona door's own hub to the session that asked there.
|
||||
#[test]
|
||||
fn a_semantic_query_at_the_persona_door_is_answered_through_the_persona_door() {
|
||||
a_semantic_query_returns_only_documents_the_mind_holds_and_the_selection_admits_at(Harness::persona_client);
|
||||
}
|
||||
|
||||
fn a_semantic_query_returns_only_documents_the_mind_holds_and_the_selection_admits_at(client_of: fn(&Harness) -> Client) {
|
||||
let harness = healthy();
|
||||
let mut client = harness.client();
|
||||
let mut client = client_of(&harness);
|
||||
until_index(&mut client, "Current", |status| *status == IndexStatus::Current);
|
||||
harness.index.state.lock().unwrap().hits = vec![
|
||||
hit("question", id("question", "Q1"), 0.95),
|
||||
|
|
|
|||
Loading…
Reference in a new issue