Make codec shape authority compile-time and fixed

This commit is contained in:
ms2k 2026-07-19 04:33:43 +09:00
commit 54cc167f81
3 changed files with 322 additions and 52 deletions

View file

@ -68,6 +68,10 @@ enum RuntimeSupervisorHandoff {
V1(RuntimeSupervisorHandoffV1),
}
impl lazaret_core::records::SchemaType for RuntimeSupervisorHandoff {
const NAME: &'static str = "RuntimeSupervisorHandoff";
}
fn descriptor(
number: i32,
kind: RuntimeDescriptorKindV1,

View file

@ -543,7 +543,10 @@ fn lifetime_lost() -> io::Result<bool> {
.intersects(PollFlags::IN | PollFlags::HUP | PollFlags::ERR))
}
fn send_message<T: Serialize>(descriptor: impl AsFd, message: &T) -> io::Result<()> {
fn send_message<T: lazaret_core::records::SchemaType + Serialize>(
descriptor: impl AsFd,
message: &T,
) -> io::Result<()> {
let encoded = encode(message).map_err(|error| io::Error::other(error.to_string()))?;
if encoded.len() > MAX_CONTROL_MESSAGE {
return Err(io::Error::other("runtime control message is oversized"));
@ -557,7 +560,7 @@ fn send_message<T: Serialize>(descriptor: impl AsFd, message: &T) -> io::Result<
fn receive_message<T>(descriptor: impl AsFd) -> io::Result<T>
where
T: serde::de::DeserializeOwned + Serialize,
T: lazaret_core::records::SchemaType + serde::de::DeserializeOwned + Serialize,
{
let mut length = [0_u8; 4];
receive_exact(descriptor.as_fd(), &mut length)?;

View file

@ -7,9 +7,51 @@ mod tests {
use lazaret_linux::ipc::private_seqpacket_pair;
use lazaret_linux::process::ChildStandardIoPolicy;
use rustix::pipe::{PipeFlags, pipe_with};
use sha2::{Digest, Sha256};
use super::*;
#[test]
fn private_control_record_vectors_are_stable() {
let namespace = NamespaceIdentity {
device: lazaret_core::identity::DeviceId::new(1),
inode: lazaret_core::identity::InodeId::new(2),
};
let mount = MountIdentity {
mount_id: lazaret_core::identity::MountId::new(3),
device: lazaret_core::identity::DeviceId::new(4),
inode: lazaret_core::identity::InodeId::new(5),
};
let records = [
encode(&AttachedRunscSignal::Continue).unwrap(),
encode(&SupervisorEvent::StateAnchorAbsenceObserved {
user_namespace: namespace,
mount_namespace: namespace,
mount,
observed: mount,
})
.unwrap(),
encode(&CoordinatorMessage::ObserveStateAnchorAbsence {
user_namespace: namespace,
mount_namespace: namespace,
mount,
})
.unwrap(),
];
let mut corpus = Sha256::new();
for record in records {
corpus.update(record.len().to_be_bytes());
corpus.update(record);
}
assert_eq!(
corpus.finalize().as_slice(),
[
59, 166, 131, 49, 39, 47, 193, 4, 70, 106, 107, 188, 204, 94, 145, 7, 250,
164, 101, 22, 121, 174, 24, 13, 138, 108, 62, 97, 17, 162, 129, 89,
]
);
}
#[test]
fn private_stream_framing_round_trips_typed_events() {
let (coordinator, supervisor) = private_seqpacket_pair().unwrap();