Watch
0
0
Fork
You've already forked hyperhive
0

an agent gets one todo when its pr starts conflicting with the target branch

This commit is contained in:
atlas 2026-11-11 04:36:28 +01:00 • committed by mara
commit 11eb7dac9c

View file

@ -5,7 +5,7 @@ use std::collections::BTreeSet;
use swarm_wire::router_todo::Op;
use crate::event::{Delivery, Snapshot, fields, is_assign};
use crate::event::{Delivery, Snapshot, conflicting_after, fields, is_assign};
use swarm_wire::notify_flows::Flow;
use crate::flow::{Action, ReviewRequest, evaluate, requests};
@ -67,6 +67,7 @@ pub fn route(
if !is_run && delivery.is_pull && !delivery.head.is_empty() {
next.head = Some(delivery.head.clone());
}
next.conflicting = conflicting_after(event_type, &delivery.action, snapshot);
if is_assign(event_type) {
// A skipped assignee is left out of the snapshot, so the next assign
// event counts it as added again: an agent assigned before it is in
@ -204,6 +205,110 @@ mod tests {
d
}
/// A PR starts conflicting: its author gets one todo, a second finding of
/// the same changes nothing, and the PR merging again clears it. Closing
/// the PR clears it too and forgets the state, so a reopened PR that
/// still conflicts is told again.
#[test]
fn a_pull_request_that_starts_conflicting_tells_the_author_once() {
let flows = builtins();
let is_agent = |a: &str| a == "atlas";
let found = |action: &str, snapshot: &Snapshot| {
route(
"pull_request_mergeability",
&pull_by("atlas", action),
snapshot,
&flows,
is_agent,
)
};
let first = found("conflicting", &Snapshot::default());
assert_eq!(agents(&first), [("atlas", Op::Upsert)]);
assert_eq!(first.actions[0].op.key, "forge:o/r#9:conflict");
assert_eq!(first.actions[0].flow, "conflict");
assert!(
first.actions[0]
.op
.summary
.starts_with("PR o/r#9 no longer merges into its target branch")
);
assert_eq!(first.next.conflicting, Some(true));
assert_eq!(first.next.holders, BTreeSet::from(["atlas".to_owned()]));
let again = found("conflicting", &first.next);
assert!(again.actions.is_empty(), "no todo for a repeat: {again:?}");
assert_eq!(again.next.conflicting, Some(true));
let merges = found("mergeable", &again.next);
assert_eq!(agents(&merges), [("atlas", Op::Clear)]);
assert_eq!(merges.actions[0].op.key, "forge:o/r#9:conflict");
assert!(!merges.actions[0].op.prefix);
assert_eq!(merges.next.conflicting, Some(false));
let later = found("conflicting", &merges.next);
assert_eq!(
agents(&later),
[("atlas", Op::Upsert)],
"a PR that conflicts again after merging is told again"
);
let closed = route(
"pull_request",
&pull_by("atlas", "closed"),
&later.next,
&flows,
is_agent,
);
assert!(
closed
.actions
.iter()
.any(|a| a.op.op == Op::Clear && a.op.prefix && a.op.key == "forge:o/r#9:"),
"the close clears every todo for the PR, the conflict one included"
);
assert_eq!(closed.next.conflicting, None);
assert_eq!(
agents(&found("conflicting", &closed.next)),
[("atlas", Op::Upsert)]
);
}
/// A PR that merges and never conflicted has nothing to clear, and the
/// mergeability events leave the other state alone.
#[test]
fn a_mergeable_finding_on_a_pull_request_that_never_conflicted_does_nothing() {
let flows = builtins();
for before in [None, Some(false)] {
let snapshot = Snapshot {
conflicting: before,
..Snapshot::default()
};
let r = route(
"pull_request_mergeability",
&pull_by("atlas", "mergeable"),
&snapshot,
&flows,
|_| true,
);
assert!(r.actions.is_empty(), "{before:?}: {:?}", r.actions);
assert_eq!(r.next.conflicting, Some(false));
}
// Control: the same finding on a conflicting PR does clear.
let conflicting = Snapshot {
conflicting: Some(true),
..Snapshot::default()
};
let r = route(
"pull_request_mergeability",
&pull_by("atlas", "mergeable"),
&conflicting,
&flows,
|_| true,
);
assert_eq!(agents(&r), [("atlas", Op::Clear)]);
}
/// The push that clears the CI todo also cancels the runs before it, and
/// one of them can report in after the clear. It began at the old head, so
/// it must not bring the todo back.