fix(domain): shape check sees positional parents, multicast never an own address
This commit is contained in:
1 parent
257a29b09b
commit
1ec9e1bea6
6 files changed
+273
-8
No files matched your search
@@ -121,6 +121,10 @@ fn snapshot_matches(snapshot: &SheetSnapshot, report: &Report) -> bool {
|
||||
/// `ReportArchiveEnvelopeSchema.parse`: the shape of a whole envelope (the snapshot's shape
|
||||
/// only, no caps nor integrity), as the session keeps it.
|
||||
pub fn parse_envelope(data: &Value) -> Result<ReportArchiveEnvelope, serde_json::Error> {
|
||||
// A positional envelope would carry its report past the check unseen.
|
||||
if !data.is_object() {
|
||||
return Err(serde::de::Error::custom("envelope: expected an object"));
|
||||
}
|
||||
let report = data.get("report").unwrap_or(&Value::Null);
|
||||
check_v3_shape(report).map_err(serde::de::Error::custom)?;
|
||||
ReportArchiveEnvelope::deserialize(data)
|
||||
|
||||
@@ -51,8 +51,13 @@ pub fn version_of(data: &Value) -> Option<f64> {
|
||||
|
||||
/// The shapes Zod refused and serde's derives accept (owner go 2026-10-24, RUST.md §11.18):
|
||||
/// `sheet` and `practitioner` written as positional arrays, a `severity` written as a one-key
|
||||
/// map. Checked on the raw value before the typed read; nothing else is widened or narrowed.
|
||||
/// map. Checked on the raw value before the typed read. The report and each observation must
|
||||
/// be objects themselves, or a positional parent would carry those fields past the check
|
||||
/// unseen; nothing else is widened or narrowed.
|
||||
pub fn check_v3_shape(data: &Value) -> Result<(), String> {
|
||||
if !data.is_object() {
|
||||
return Err("report: expected an object".to_owned());
|
||||
}
|
||||
for key in ["sheet", "practitioner"] {
|
||||
if data.get(key).is_some_and(|value| !value.is_object()) {
|
||||
return Err(format!("{key}: expected an object"));
|
||||
@@ -60,11 +65,14 @@ pub fn check_v3_shape(data: &Value) -> Result<(), String> {
|
||||
}
|
||||
let observations = data.get("observations").and_then(Value::as_array);
|
||||
for (index, observation) in observations.into_iter().flatten().enumerate() {
|
||||
let severity = observation.get("severity");
|
||||
if severity.is_some_and(|value| !value.is_string()) {
|
||||
return Err(format!(
|
||||
"observations[{index}].severity: expected a string or null"
|
||||
));
|
||||
if !observation.is_object() {
|
||||
return Err(format!("observations[{index}]: expected an object"));
|
||||
}
|
||||
if observation
|
||||
.get("severity")
|
||||
.is_some_and(|value| !value.is_string())
|
||||
{
|
||||
return Err(format!("observations[{index}].severity: expected a string"));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user