Watch
0
0
Fork
You've already forked hyperhive
0

archetype flows behave like the built-ins: switch off per archetype or per agent, board cards, duplicate

The document's disabled list takes archetype:<archetype>/<flow> (off for every member) and the same with @<agent> (off for one member); a key naming nothing is ignored. GET /api/notify/flows lists the archetype flows with their members, the board draws a card for each with a switch, a checkbox per agent and duplicate, and the dry run counts their hits. The flows keep following the archetype.
This commit is contained in:
atlas 2026-11-11 19:08:19 +01:00 • committed by mara
commit 68c24643f6

View file

@ -12,12 +12,18 @@ use swarm_wire::notify_flows::Flow;
use swarm_wire::router_api::{DryRun, FlowHits, NodeHits};
use crate::event::{Delivery, Snapshot, fields};
use crate::flow::ArchetypeFlow;
use crate::{flow, route};
/// `flows` over `events`, oldest first, each a forge event type and body.
/// An event that names no issue or PR is not counted.
pub fn run(flows: &[Flow], events: &[(String, Vec<u8>)]) -> DryRun {
let mut hits: Vec<BTreeMap<&str, u64>> = flows
/// `flows` and the archetypes' `archetype` flows over `events`, oldest first,
/// each a forge event type and body. An event that names no issue or PR is not
/// counted.
pub fn run(flows: &[Flow], archetype: &[ArchetypeFlow], events: &[(String, Vec<u8>)]) -> DryRun {
let all: Vec<&Flow> = flows
.iter()
.chain(archetype.iter().map(|a| &a.flow))
.collect();
let mut hits: Vec<BTreeMap<&str, u64>> = all
.iter()
.map(|f| f.nodes.iter().map(|n| (n.id.as_str(), 0)).collect())
.collect();
@ -31,19 +37,19 @@ pub fn run(flows: &[Flow], events: &[(String, Vec<u8>)]) -> DryRun {
let key = delivery.state_key();
let before = snapshots.remove(&key).unwrap_or_default();
let event_fields = fields(event_type, &delivery, &before);
for (flow, counts) in flows.iter().zip(&mut hits) {
for (flow, counts) in all.iter().zip(&mut hits) {
for id in flow::reached(flow, event_type, &event_fields) {
if let Some(count) = counts.get_mut(id) {
*count += 1;
}
}
}
let routed = route::route(event_type, &delivery, &before, flows, &[], |_| true);
let routed = route::route(event_type, &delivery, &before, flows, archetype, |_| true);
snapshots.insert(key, routed.next);
}
DryRun {
events: run,
flows: flows
flows: all
.iter()
.zip(hits)
.map(|(flow, counts)| FlowHits {
@ -102,7 +108,7 @@ mod tests {
("issues".to_owned(), body("closed", 5, &[])),
("issues".to_owned(), b"not json".to_vec()),
];
let r = run(&flows, &events);
let r = run(&flows, &[], &events);
assert_eq!(r.events, 4);
// The source sees all three assign events, the match and the sink both
// assigned ones, though the second adds nobody.
@ -160,7 +166,7 @@ mod tests {
edges: vec![edge("source", "atlas")],
};
let assign = ("issue_assign".to_owned(), body("assigned", 5, &["atlas"]));
let r = run(&[flow], &[assign.clone(), assign]);
let r = run(&[flow], &[], &[assign.clone(), assign]);
assert_eq!(count(&r, "added", "source"), 2);
assert_eq!(count(&r, "added", "atlas"), 1);
}
@ -173,11 +179,43 @@ mod tests {
..Document::default()
};
let (flows, _) = doc.active();
let r = run(&flows, &[]);
let r = run(&flows, &[], &[]);
assert_eq!(r.events, 0);
let listed: Vec<&str> = r.flows.iter().map(|f| f.flow.as_str()).collect();
assert!(!listed.contains(&"closed"));
assert!(listed.contains(&"assigned"));
assert_eq!(listed.len(), builtins().len() - 1);
}
/// An archetype's flow is counted next to the document's, under its key.
#[test]
fn an_archetype_flow_is_counted_under_its_key() {
let (flows, _) = Document::default().active();
let mut flow = builtins().remove(0);
flow.id = "archetype:triage/new".to_owned();
flow.nodes[2].kind =
swarm_wire::notify_flows::NodeKind::Todo(swarm_wire::notify_flows::TodoSink {
to: swarm_wire::notify_flows::Recipients::Members,
op: swarm_wire::router_todo::Op::Upsert,
key: "forge:{{ repo }}#{{ number }}:triage".to_owned(),
prefix: false,
text: "triage".to_owned(),
});
let archetype = [ArchetypeFlow {
flow,
members: vec!["alice".to_owned()],
}];
let events = vec![("issue_assign".to_owned(), body("assigned", 5, &["atlas"]))];
let r = run(&flows, &archetype, &events);
assert_eq!(count(&r, "archetype:triage/new", "source"), 1);
assert_eq!(count(&r, "archetype:triage/new", "sink"), 1);
assert_eq!(count(&r, "assigned", "sink"), 1, "the document's flow too");
// Control: with no archetype flow it has no entry.
assert!(
run(&flows, &[], &events)
.flows
.iter()
.all(|f| f.flow != "archetype:triage/new")
);
}
}