commit 0ecda3d80cb128fd88dc12a4a79e694d7972e220
parent 0027232cff1f9b7cd59e2fb25751df8d7846c703
Author: triesap <tyson@radroots.org>
Date: Sun, 21 Jun 2026 20:37:56 +0000
events-codec: expand farm file decode coverage
- Cover farm file parsed wrapper error propagation and source tag decoding with dimension-only and URL-only thumbnail forms.
- Exercise height-zero dimensions validation and private encode-error mapper arms that are unreachable through valid decode flow.
- Validate filtered farm_file tests, full radroots_events_codec tests, crate check, diff check, and refreshed coverage run.
Diffstat:
2 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/crates/events_codec/src/farm_file/decode.rs b/crates/events_codec/src/farm_file/decode.rs
@@ -289,3 +289,24 @@ fn encode_error_to_parse_error(error: crate::error::EventEncodeError) -> EventPa
crate::error::EventEncodeError::Json => EventParseError::InvalidTag("content"),
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::error::EventEncodeError;
+
+ #[test]
+ fn encode_error_mapper_covers_unreachable_decode_edges() {
+ let err = encode_error_to_parse_error(EventEncodeError::InvalidKind(99));
+ assert!(matches!(
+ err,
+ EventParseError::InvalidKind {
+ expected: "1063",
+ got: 99
+ }
+ ));
+
+ let err = encode_error_to_parse_error(EventEncodeError::Json);
+ assert!(matches!(err, EventParseError::InvalidTag("content")));
+ }
+}
diff --git a/crates/events_codec/src/farm_file/mod.rs b/crates/events_codec/src/farm_file/mod.rs
@@ -171,6 +171,24 @@ mod tests {
assert_eq!(data.kind, KIND_FARM_FILE_METADATA);
assert_eq!(data.data, metadata);
+ let err = parsed_from_event(
+ "event-id".to_string(),
+ "author-pubkey".to_string(),
+ 42,
+ KIND_POST,
+ parts.content.clone(),
+ parts.tags.clone(),
+ "sig".to_string(),
+ )
+ .unwrap_err();
+ assert!(matches!(
+ err,
+ EventParseError::InvalidKind {
+ expected: "1063",
+ got: KIND_POST
+ }
+ ));
+
let parsed = parsed_from_event(
"event-id".to_string(),
"author-pubkey".to_string(),
@@ -254,6 +272,7 @@ mod tests {
("size", "not-a-number", "size"),
("dim", "bad", "dim"),
("dim", "0x12", "dim"),
+ ("dim", "12x0", "dim"),
("thumb", "", "thumb"),
("thumb", " ", "thumb"),
] {
@@ -291,6 +310,41 @@ mod tests {
assert!(matches!(err, EventParseError::InvalidTag("thumb")));
}
+ let tags = replace_tag(
+ &parts.tags,
+ "thumb",
+ vec![
+ "thumb".to_string(),
+ "https://media.example.invalid/thumb/sha256".to_string(),
+ "320x240".to_string(),
+ ],
+ );
+ let decoded =
+ farm_file_metadata_from_event(parts.kind, &tags, &parts.content).expect("metadata");
+ assert_eq!(
+ decoded
+ .thumb
+ .as_ref()
+ .and_then(|source| source.mime_type.as_deref()),
+ None
+ );
+ assert_eq!(
+ decoded.thumb.and_then(|source| source.dimensions),
+ Some(RadrootsFarmFileDimensions { w: 320, h: 240 })
+ );
+
+ let tags = replace_tag(
+ &parts.tags,
+ "thumb",
+ vec![
+ "thumb".to_string(),
+ "https://media.example.invalid/thumb/sha256".to_string(),
+ ],
+ );
+ let decoded =
+ farm_file_metadata_from_event(parts.kind, &tags, &parts.content).expect("metadata");
+ assert_eq!(decoded.thumb.and_then(|source| source.dimensions), None);
+
let err = farm_file_metadata_from_event(parts.kind, &parts.tags, " ").unwrap_err();
assert!(matches!(err, EventParseError::InvalidTag("caption")));
}