Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/id/src/idset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ mod tests {
tag: None,
document: None,
removes: None,
note: None,
},
)
.unwrap();
Expand Down
45 changes: 43 additions & 2 deletions pkgs/id/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ fn encode_omega_null_key_prefix(key: &[u8]) -> Vec<u8> {
/// Handles both `TupleValue::String` and `TupleValue::Bytes` for binary support.
fn decode_alpha_key(raw: &[u8]) -> Result<(TagValue, TagValue, Option<TagValue>)> {
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])
Expand All @@ -608,7 +608,7 @@ fn decode_alpha_key(raw: &[u8]) -> Result<(TagValue, TagValue, Option<TagValue>)
/// back to `(subject, key, value?)`. Handles both String and Bytes variants.
fn decode_omega_key(raw: &[u8]) -> Result<(TagValue, TagValue, Option<TagValue>)> {
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() {
Expand Down Expand Up @@ -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<u8> {
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<u8> {
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);
Expand Down