mirror of
https://github.com/block/buzz.git
synced 2026-11-29 20:52:25 +00:00
fix(cli): preserve signatures in event reads (#6884)
## Summary
- preserve string Nostr `sig` values in normal `messages get`, `messages
thread`, `messages search`, and `feed get` output
- omit absent or non-string signatures instead of fabricating empty
values
- keep compact output at exactly `{id, content, created_at}` and update
CLI/managed-agent contract docs
## Validation
- `cargo test -p buzz-cli --lib` (367 passed at final head
`a2498faa0e07f90efc0ab0165606ba3b048327c7`)
- release candidate live-relay matrix: 49/49 normal events independently
recomputed to their NIP-01 IDs and passed BIP-340 verification; all four
compact commands preserved exact three-key output and ordering
- `git diff origin/main...HEAD --check`
- independent adversarial review: clear, no findings
## Compatibility
The normal JSON change is additive for valid relay events. In-repo
consumers use tolerant field lookup. Compact output is unchanged and
locked by regressions for both message and feed formatting.
Generated by Carl, an automated contributor working with Wes.
---------
Signed-off-by: Carl <9d00794d3df50972eb8b615511783cab12a77a8fd5dd5edd58073ec73b54bd8b@buzz.block.builderlab.xyz>
Co-authored-by: Carl <9d00794d3df50972eb8b615511783cab12a77a8fd5dd5edd58073ec73b54bd8b@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -5,6 +5,27 @@ use crate::error::CliError;
|
||||
|
||||
const VALID_FEED_TYPES: &[&str] = &["mentions", "needs_action", "activity", "agent_activity"];
|
||||
|
||||
fn format_events(normalized: &str, format: &crate::OutputFormat) -> String {
|
||||
match format {
|
||||
crate::OutputFormat::Compact => {
|
||||
let events: Vec<serde_json::Value> =
|
||||
serde_json::from_str(normalized).unwrap_or_default();
|
||||
let compact: Vec<serde_json::Value> = events
|
||||
.iter()
|
||||
.map(|e| {
|
||||
serde_json::json!({
|
||||
"id": e.get("id").cloned().unwrap_or_default(),
|
||||
"content": e.get("content").cloned().unwrap_or_default(),
|
||||
"created_at": e.get("created_at").cloned().unwrap_or_default(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
serde_json::to_string(&compact).unwrap_or_default()
|
||||
}
|
||||
crate::OutputFormat::Json => normalized.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get activity feed — query events mentioning our pubkey (via p-tag).
|
||||
pub async fn cmd_get_feed(
|
||||
client: &BuzzClient,
|
||||
@@ -42,25 +63,7 @@ pub async fn cmd_get_feed(
|
||||
let mut events: Vec<serde_json::Value> = serde_json::from_str(&resp).unwrap_or_default();
|
||||
events.sort_by_key(|e| Reverse(e.get("created_at").and_then(|v| v.as_u64()).unwrap_or(0)));
|
||||
let normalized = normalize_events(&events);
|
||||
let output = match format {
|
||||
crate::OutputFormat::Compact => {
|
||||
let evts: Vec<serde_json::Value> =
|
||||
serde_json::from_str(&normalized).unwrap_or_default();
|
||||
let compact: Vec<serde_json::Value> = evts
|
||||
.iter()
|
||||
.map(|e| {
|
||||
serde_json::json!({
|
||||
"id": e.get("id").cloned().unwrap_or_default(),
|
||||
"content": e.get("content").cloned().unwrap_or_default(),
|
||||
"created_at": e.get("created_at").cloned().unwrap_or_default(),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
serde_json::to_string(&compact).unwrap_or_default()
|
||||
}
|
||||
crate::OutputFormat::Json => normalized,
|
||||
};
|
||||
println!("{output}");
|
||||
println!("{}", format_events(&normalized, format));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -78,3 +81,35 @@ pub async fn dispatch(
|
||||
} => cmd_get_feed(client, since, limit, types.as_deref(), format).await,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::format_events;
|
||||
|
||||
#[test]
|
||||
fn compact_event_format_remains_the_three_key_contract() {
|
||||
let normalized = serde_json::json!([{
|
||||
"id": "a".repeat(64),
|
||||
"pubkey": "b".repeat(64),
|
||||
"kind": 9,
|
||||
"content": "compact content",
|
||||
"created_at": 1_787_754_972_u64,
|
||||
"tags": [["p", "c".repeat(64)]],
|
||||
"sig": "d".repeat(128),
|
||||
}])
|
||||
.to_string();
|
||||
|
||||
let output: Vec<serde_json::Value> =
|
||||
serde_json::from_str(&format_events(&normalized, &crate::OutputFormat::Compact))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
output[0],
|
||||
serde_json::json!({
|
||||
"id": "a".repeat(64),
|
||||
"content": "compact content",
|
||||
"created_at": 1_787_754_972_u64,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1057,7 +1057,7 @@ pub async fn dispatch(
|
||||
mod tests {
|
||||
use super::{
|
||||
channel_id_from_event, cmd_get_thread, event_mention_pubkeys, find_root_from_tags,
|
||||
match_profiles_by_name, merge_message_mentions, missing_members,
|
||||
format_events, match_profiles_by_name, merge_message_mentions, missing_members,
|
||||
normalize_explicit_mentions, parse_member_pubkeys, resolve_names_to_pubkeys,
|
||||
resolve_thread_target, thread_ref_from_event, thread_ref_from_parent_tags, BuzzClient,
|
||||
CliError, Uuid,
|
||||
@@ -1078,6 +1078,33 @@ mod tests {
|
||||
const PK_VALID_B: &str = "c6237ef84fa537c78dcee78efd2d4e59f728859c7f194da42ac51ededfa0be05";
|
||||
const PK_VALID_C: &str = "f4a42a97e594b77bdbd8ee35191c8b28a94a4cb871d96f32921558275421fb68";
|
||||
|
||||
#[test]
|
||||
fn compact_event_format_remains_the_three_key_contract() {
|
||||
let normalized = serde_json::json!([{
|
||||
"id": ID_A,
|
||||
"pubkey": PUBKEY,
|
||||
"kind": 9,
|
||||
"content": "compact content",
|
||||
"created_at": 1_787_754_972_u64,
|
||||
"tags": [["h", "channel-id"]],
|
||||
"sig": "d".repeat(128),
|
||||
}])
|
||||
.to_string();
|
||||
|
||||
let output: Vec<serde_json::Value> =
|
||||
serde_json::from_str(&format_events(&normalized, &crate::OutputFormat::Compact))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
output[0],
|
||||
serde_json::json!({
|
||||
"id": ID_A,
|
||||
"content": "compact content",
|
||||
"created_at": 1_787_754_972_u64,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn malformed_channel_is_rejected_before_thread_fetch() {
|
||||
let client =
|
||||
|
||||
Reference in New Issue
Block a user