mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
refactor: split protocol endpoint into focused modules
This commit is contained in:
@@ -81,16 +81,11 @@ fn header_and_call_validation_reject_invalid_combinations() {
|
||||
#[test]
|
||||
fn procedure_validation_accepts_introspection_and_rejects_bad_shapes() {
|
||||
assert_eq!(validate_procedure_id(""), Ok(()));
|
||||
assert_eq!(validate_procedure_id("unshell.echo.v01.alpha.invoke"), Ok(()));
|
||||
assert_eq!(
|
||||
validate_procedure_id("unshell.echo.v01.alpha.invoke"),
|
||||
validate_procedure_id("contains spaces"),
|
||||
Err(ValidationError::ProcedureId(
|
||||
"version segment must be v followed by a positive decimal integer"
|
||||
))
|
||||
);
|
||||
assert_eq!(
|
||||
validate_procedure_id("too.short.v1"),
|
||||
Err(ValidationError::ProcedureId(
|
||||
"must contain exactly 5 segments"
|
||||
"procedure identifier should use alphanumeric characters, dots, and underscores"
|
||||
))
|
||||
);
|
||||
}
|
||||
@@ -105,7 +100,7 @@ fn truncated_frames_are_rejected() {
|
||||
hook_id: Some(9),
|
||||
};
|
||||
let message = FaultMessage {
|
||||
fault: ProtocolFault::InternalError,
|
||||
fault: ProtocolFault::INTERNAL_ERROR,
|
||||
};
|
||||
|
||||
let frame = encode_packet(&header, &message).expect("frame should encode");
|
||||
|
||||
+10
-10
@@ -6,7 +6,7 @@ use crate::protocol::tree::{
|
||||
};
|
||||
use crate::protocol::{
|
||||
DataMessage, EndpointIntrospection, FaultMessage, PacketHeader, PacketType, ProtocolFault,
|
||||
decode_frame, deserialize_archived_bytes, encode_packet,
|
||||
deserialize_archived_bytes, encode_packet,
|
||||
};
|
||||
|
||||
fn path(parts: &[&str]) -> Vec<String> {
|
||||
@@ -77,16 +77,16 @@ fn protocol_endpoint_introspection_returns_leaf_summary() {
|
||||
.receive(&Ingress::Local, frame)
|
||||
.expect("endpoint should handle introspection");
|
||||
|
||||
assert!(outcome.events.is_empty());
|
||||
assert_eq!(outcome.forwards.len(), 1);
|
||||
assert_eq!(outcome.forwards[0].0, RouteDecision::Parent);
|
||||
assert!(outcome.forwards.is_empty());
|
||||
assert_eq!(outcome.events.len(), 1);
|
||||
|
||||
let parsed = decode_frame(&outcome.forwards[0].1).expect("response should decode");
|
||||
let response = parsed
|
||||
.deserialize_data()
|
||||
.expect("response data should deserialize");
|
||||
let LocalEvent::Data { header, message: response } = &outcome.events[0] else {
|
||||
panic!("expected local data event");
|
||||
};
|
||||
assert_eq!(header.packet_type, PacketType::Data);
|
||||
assert_eq!(header.dst_path, path(&["root"]));
|
||||
let introspection = deserialize_archived_bytes::<
|
||||
rkyv::Archived<EndpointIntrospection>,
|
||||
crate::protocol::introspection::ArchivedEndpointIntrospection,
|
||||
EndpointIntrospection,
|
||||
>(&response.data)
|
||||
.expect("introspection payload should deserialize");
|
||||
@@ -146,7 +146,7 @@ fn invalid_hook_peer_emits_local_fault_event() {
|
||||
assert_eq!(
|
||||
message,
|
||||
&FaultMessage {
|
||||
fault: ProtocolFault::InvalidHookPeer,
|
||||
fault: ProtocolFault::INVALID_HOOK_PEER,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user