diff --git a/pkgs/id/src/idset.rs b/pkgs/id/src/idset.rs index 3ee02f0ad4..3fab81bb78 100644 --- a/pkgs/id/src/idset.rs +++ b/pkgs/id/src/idset.rs @@ -759,6 +759,7 @@ mod tests { tag: None, document: None, removes: None, + note: None, }, ) .unwrap(); diff --git a/pkgs/id/src/tags.rs b/pkgs/id/src/tags.rs index 2f48127a2d..54f121f70d 100644 --- a/pkgs/id/src/tags.rs +++ b/pkgs/id/src/tags.rs @@ -584,7 +584,7 @@ fn encode_omega_null_key_prefix(key: &[u8]) -> Vec { /// Handles both `TupleValue::String` and `TupleValue::Bytes` for binary support. fn decode_alpha_key(raw: &[u8]) -> Result<(TagValue, TagValue, Option)> { let fields = decode(raw)?; - if fields.len() < 3 { + if fields.len() != 3 { bail!("α key has {} fields, expected 3", fields.len()); } let subject = tuple_value_to_tag_value(&fields[0]) @@ -608,7 +608,7 @@ fn decode_alpha_key(raw: &[u8]) -> Result<(TagValue, TagValue, Option) /// back to `(subject, key, value?)`. Handles both String and Bytes variants. fn decode_omega_key(raw: &[u8]) -> Result<(TagValue, TagValue, Option)> { let fields = decode(raw)?; - if fields.len() < 3 { + if fields.len() != 3 { bail!("Ω key has {} fields, expected 3", fields.len()); } let value = if fields[0].is_null() { @@ -1942,6 +1942,47 @@ mod tests { assert_eq!(value, Some(TagValue::from("rust"))); } + /// Build a 4-field α-shaped key: a valid tag key plus a trailing field. + /// No writer emits this; it models the phantom key from issue #1832. + fn encode_alpha_key_4_fields() -> Vec { + let mut enc = TupleEncoder::new(); + encode_smart(&mut enc, b"file.txt"); + encode_smart(&mut enc, b"tag"); + encode_smart(&mut enc, b"v1"); + encode_smart(&mut enc, b"extra"); + enc.build() + } + + /// Build a 4-field Ω-shaped key: (value, key, subject) plus a trailing field. + fn encode_omega_key_4_fields() -> Vec { + let mut enc = TupleEncoder::new(); + encode_smart(&mut enc, b"v1"); + encode_smart(&mut enc, b"tag"); + encode_smart(&mut enc, b"file.txt"); + encode_smart(&mut enc, b"extra"); + enc.build() + } + + #[test] + fn test_decode_alpha_key_rejects_four_fields() { + let raw = encode_alpha_key_4_fields(); + let err = decode_alpha_key(&raw).unwrap_err(); + assert!( + err.to_string().contains("expected 3"), + "unexpected error: {err}" + ); + } + + #[test] + fn test_decode_omega_key_rejects_four_fields() { + let raw = encode_omega_key_4_fields(); + let err = decode_omega_key(&raw).unwrap_err(); + assert!( + err.to_string().contains("expected 3"), + "unexpected error: {err}" + ); + } + #[test] fn test_decode_omega_key_null() { let raw = encode_omega_key(b"file.txt", b"pinned", None);