brokkr-ctl on MessagePack payloads: reads through cultcache_rs::decode_payload, one MessagePack value per write, tests off JSON
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ef7086971c
commit
0f4ab2d0d9
4 changed files with 30 additions and 6 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
|
@ -47,6 +47,18 @@ dependencies = [
|
|||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brokkr-ctl"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cultcache-rs",
|
||||
"rmp-serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brokkr-daemon"
|
||||
version = "0.1.0"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ publish = false
|
|||
[dependencies]
|
||||
anyhow = "1"
|
||||
cultcache-rs = { workspace = true }
|
||||
rmp-serde = "1.3"
|
||||
serde_json = "1"
|
||||
uuid = { version = "1", features = ["v7"] }
|
||||
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ fn send(options: &Options) -> Result<i32> {
|
|||
store.push(&CultCacheEnvelope {
|
||||
key: format!("{INTENT_PREFIX}{command_id}"),
|
||||
r#type: INTENT_SCHEMA.to_string(),
|
||||
payload: serde_json::to_vec(&intent)?,
|
||||
payload: rmp_serde::to_vec(&intent)?,
|
||||
stored_at: iso_now(),
|
||||
schema_id: Some(INTENT_SCHEMA.to_string()),
|
||||
})?;
|
||||
|
|
@ -343,8 +343,8 @@ fn status(store: &SingleFileMessagePackBackingStore) -> Result<i32> {
|
|||
}
|
||||
|
||||
fn decode(envelope: &CultCacheEnvelope) -> Result<Value> {
|
||||
serde_json::from_slice(&envelope.payload)
|
||||
.with_context(|| format!("{} is not a JSON map payload", envelope.key))
|
||||
cultcache_rs::decode_payload::<Value>(&envelope.payload)
|
||||
.with_context(|| format!("{} is not one MessagePack value", envelope.key))
|
||||
}
|
||||
|
||||
fn print_fields(value: &Value) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ fn envelope(schema: &str, key: &str, payload: &Value) -> CultCacheEnvelope {
|
|||
CultCacheEnvelope {
|
||||
key: key.to_string(),
|
||||
r#type: schema.to_string(),
|
||||
payload: serde_json::to_vec(payload).unwrap(),
|
||||
payload: rmp_serde::to_vec(payload).unwrap(),
|
||||
stored_at: "2026-11-27T00:00:00.000000+00:00".to_string(),
|
||||
schema_id: Some(schema.to_string()),
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ fn send_writes_a_pullable_intent() {
|
|||
.expect("intent key");
|
||||
assert_eq!(intent.r#type, INTENT);
|
||||
assert_eq!(intent.schema_id.as_deref(), Some(INTENT));
|
||||
let payload: Value = serde_json::from_slice(&intent.payload).unwrap();
|
||||
let payload: Value = cultcache_rs::decode_payload(&intent.payload).unwrap();
|
||||
assert_eq!(
|
||||
payload,
|
||||
json!({"schema": INTENT, "commandId": id, "action": "createObject", "requestedBy": "nibu/hands",
|
||||
|
|
@ -202,7 +202,7 @@ fn help_words_as_option_values_do_not_swallow_the_command() {
|
|||
let id = stdout(&output).trim().strip_prefix("commandId: ").unwrap().to_string();
|
||||
let found = SingleFileMessagePackBackingStore::new(&path).pull_all().unwrap();
|
||||
let intent = found.iter().find(|e| e.key == format!("blender/commands/{id}")).unwrap();
|
||||
let payload: Value = serde_json::from_slice(&intent.payload).unwrap();
|
||||
let payload: Value = cultcache_rs::decode_payload(&intent.payload).unwrap();
|
||||
assert_eq!(payload["note"], "-h");
|
||||
assert_eq!(payload["requestedBy"], "nibu/--help");
|
||||
// a real help flag still prints help and sends nothing
|
||||
|
|
@ -320,3 +320,14 @@ fn help_names_every_dispatched_action_and_only_fields_the_addon_mentions() {
|
|||
assert!(source.contains(&format!("\"{field}\"")), "add-on never mentions {field}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_json_payload_is_refused_not_guessed() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = store_with_receipts(dir.path(), &[]);
|
||||
let mut json_receipt = envelope(RECEIPT, "blender/receipts/j", &json!({"commandId": "j", "status": "accepted"}));
|
||||
json_receipt.payload = serde_json::to_vec(&json!({"commandId": "j", "status": "accepted"})).unwrap();
|
||||
push(&path, &[json_receipt]);
|
||||
let output = ctl(&path, &["wait", "j", "--timeout", "1"], None);
|
||||
assert_eq!(output.status.code(), Some(1));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue