feat(workflows): polish conditions and fix listing

Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
Taylor Ho
2026-08-13 14:12:34 -07:00
parent 75c6336818
commit 20073b3a9d
9 changed files with 862 additions and 60 deletions
+21 -13
View File
@@ -105,11 +105,13 @@ pub async fn get_channel_workflows(
///
/// The Workflows overview screen previously issued one `get_channel_workflows`
/// query per member channel (`Promise.all` fanout in `WorkflowsView`), i.e. N
/// relay POSTs. A nostr `#h` filter matches ANY of its listed values, so one
/// query with all channel ids returns the same set. Each `WorkflowWire` carries
/// its own `channel_id` (from the event's `h` tag), so the frontend can still
/// group results by channel. Neither this nor the per-channel command sets a
/// `limit`, so batching does not change result completeness.
/// relay POSTs. This sends N single-channel filters in one query request. Using
/// one multi-value `#h` filter would be equivalent under NIP-01, but older
/// relays incorrectly narrowed that shape to its first channel. Each
/// `WorkflowWire` carries its own `channel_id` (from the event's `h` tag), so
/// the frontend can still group results by channel. Neither this nor the
/// per-channel command sets a `limit`, so batching does not change result
/// completeness.
#[tauri::command]
pub async fn get_channels_workflows(
channel_ids: Vec<String>,
@@ -119,18 +121,24 @@ pub async fn get_channels_workflows(
return Ok(Vec::new());
}
let events = query_relay(
&state,
&[serde_json::json!({
"kinds": [30620],
"#h": channel_ids,
})],
)
.await?;
let filters = channel_workflow_filters(channel_ids);
let events = query_relay(&state, &filters).await?;
Ok(events.iter().map(workflow_from_event).collect())
}
fn channel_workflow_filters(channel_ids: Vec<String>) -> Vec<Value> {
channel_ids
.into_iter()
.map(|channel_id| {
serde_json::json!({
"kinds": [30620],
"#h": [channel_id],
})
})
.collect()
}
#[tauri::command]
pub async fn get_workflow(
workflow_id: String,
@@ -188,6 +188,28 @@ fn workflow_wire_serializes_with_snake_case_keys() {
}
}
#[test]
fn multi_channel_workflow_query_uses_one_filter_per_channel() {
let other_channel = "33333333-3333-3333-3333-333333333333";
let filters = channel_workflow_filters(vec![CHAN.to_string(), other_channel.to_string()]);
assert_eq!(filters.len(), 2);
assert_eq!(
filters[0],
serde_json::json!({
"kinds": [30620],
"#h": [CHAN],
})
);
assert_eq!(
filters[1],
serde_json::json!({
"kinds": [30620],
"#h": [other_channel],
})
);
}
#[test]
fn trigger_response_uses_persisted_run_id_contract() {
let wire = trigger_wire_from_message(