mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-08-28 05:27:41 +00:00
Fail runs that bypass goal gates
This commit is contained in:
parent
d16cd75c56
commit
885bc92122
1 changed files with 21 additions and 9 deletions
|
|
@ -5,7 +5,7 @@ use rand::Rng;
|
|||
|
||||
use crate::condition::evaluate_condition;
|
||||
use crate::context::Context;
|
||||
use crate::outcome::{Outcome, StageOutcome};
|
||||
use crate::outcome::Outcome;
|
||||
|
||||
/// Result of edge selection: the chosen edge and the reason it was selected.
|
||||
pub(crate) struct SelectedGraphEdge<'a> {
|
||||
|
|
@ -99,14 +99,13 @@ pub(crate) fn check_goal_gates(
|
|||
graph: &GvGraph,
|
||||
node_outcomes: &HashMap<String, Outcome>,
|
||||
) -> std::result::Result<(), String> {
|
||||
for (node_id, outcome) in node_outcomes {
|
||||
if let Some(node) = graph.nodes.get(node_id) {
|
||||
if node.goal_gate()
|
||||
&& outcome.status != StageOutcome::Succeeded
|
||||
&& outcome.status != StageOutcome::PartiallySucceeded
|
||||
{
|
||||
return Err(node_id.clone());
|
||||
}
|
||||
for (node_id, node) in &graph.nodes {
|
||||
if node.goal_gate()
|
||||
&& !node_outcomes
|
||||
.get(node_id)
|
||||
.is_some_and(|outcome| outcome.status.is_successful())
|
||||
{
|
||||
return Err(node_id.clone());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -632,6 +631,19 @@ mod tests {
|
|||
assert_eq!(check_goal_gates(&g, &outcomes), Err("work".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn goal_gates_unvisited_returns_node_id() {
|
||||
let mut g = Graph::new("test");
|
||||
let mut n = Node::new("verify");
|
||||
n.attrs
|
||||
.insert("goal_gate".to_string(), AttrValue::Boolean(true));
|
||||
g.nodes.insert("verify".to_string(), n);
|
||||
|
||||
let outcomes = HashMap::new();
|
||||
|
||||
assert_eq!(check_goal_gates(&g, &outcomes), Err("verify".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn goal_gates_non_gate_nodes_ignored() {
|
||||
let mut g = Graph::new("test");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue