Fully Automated - 100% Backpressure - Pipeline runner ๐Ÿƒ for AI workflows. ๐Ÿš€

Commit 4ed0ea8a

4ed0ea8a0bf7Merged

Scott Nixon <[email protected]> ยท 9 months ago ยท 5 files ยท ~5 modified

Description

Fix 5 bugs: context condition routing, UTF-8 panic, line numbers, fidelity validation, doc count

  • Fix edge condition resolver to consult pipeline context for arbitrary keys, enabling conditions like deploy_env=prod to actually work
  • Fix potential panic in ToolHandler when truncating non-ASCII output at a multi-byte UTF-8 boundary
  • Fix off-by-one in edit_file line number reporting (was 0-indexed)
  • Fix fidelity validator to accept parenthesized syntax like truncate(5)
  • Correct doc comment from "12 built-in lint rules" to 11

Details

Commit
4ed0ea8a0bf7
Parent
7dec122024ac

crates/attractor-pipeline/src/engine.rsmodifiedView file

@@ -214,12 +214,21 @@
214214 .await;
215215 }
216216
217- // Select next edge
217+ // Select next edge โ€” resolve condition keys from outcome and context
218+ let ctx_snapshot = context.snapshot().await;
218219 let resolve = |key: &str| -> String {
219220 match key {
220221 "outcome" => status_to_string(outcome.status),
221222 "preferred_label" => outcome.preferred_label.clone().unwrap_or_default(),
222- _ => String::new(),
223+ _ => ctx_snapshot
224+ .get(key)
225+ .and_then(|v| match v {
226+ serde_json::Value::String(s) => Some(s.clone()),
227+ serde_json::Value::Bool(b) => Some(b.to_string()),
228+ serde_json::Value::Number(n) => Some(n.to_string()),
229+ _ => Some(v.to_string()),
230+ })
231+ .unwrap_or_default(),
223232 }
224233 };
225234 let next_edge = select_edge(&current_node.id, &outcome, &resolve, graph);
@@ -577,6 +586,79 @@
577586 assert_eq!(call_count.load(Ordering::SeqCst), 2);
578587 }
579588
589+ // Test 8a: Context-based edge conditions are resolved from pipeline context
590+ #[tokio::test]
591+ async fn context_based_conditions_resolve_from_context() {
592+ // A handler that sets a context key and succeeds
593+ struct ContextSettingHandler;
594+
595+ #[async_trait]
596+ impl NodeHandler for ContextSettingHandler {
597+ fn handler_type(&self) -> &str {
598+ "codergen"
599+ }
600+ async fn execute(
601+ &self,
602+ node: &crate::graph::PipelineNode,
603+ _ctx: &Context,
604+ _graph: &PipelineGraph,
605+ ) -> Result<Outcome> {
606+ let mut updates = HashMap::new();
607+ updates.insert(
608+ format!("{}.completed", node.id),
609+ serde_json::Value::Bool(true),
610+ );
611+ updates.insert(
612+ "deploy_env".to_string(),
613+ serde_json::Value::String("prod".to_string()),
614+ );
615+ Ok(Outcome {
616+ status: StageStatus::Success,
617+ preferred_label: None,
618+ suggested_next_ids: vec![],
619+ context_updates: updates,
620+ notes: "set context".into(),
621+ failure_reason: None,
622+ })
623+ }
624+ }
625+
626+ let graph = parse_graph(
627+ r#"digraph G {
628+ start [shape="Mdiamond"]
629+ setup [shape="box", label="Setup", prompt="setup"]
630+ prod_path [shape="box", label="Prod", prompt="prod"]
631+ dev_path [shape="box", label="Dev", prompt="dev"]
632+ done [shape="Msquare"]
633+ start -> setup
634+ setup -> prod_path [condition="deploy_env=prod"]
635+ setup -> dev_path [condition="deploy_env=dev"]
636+ prod_path -> done
637+ dev_path -> done
638+ }"#,
639+ );
640+
641+ let mut registry = HandlerRegistry::new();
642+ registry.register(StartHandler);
643+ registry.register(ExitHandler);
644+ registry.register(ConditionalHandler);
645+ registry.register(ContextSettingHandler);
646+
647+ let executor = PipelineExecutor::new(registry);
648+ let result = executor.run(&graph).await.unwrap();
649+
650+ // The condition "deploy_env=prod" should route to prod_path
651+ assert!(
652+ result.completed_nodes.contains(&"prod_path".to_string()),
653+ "Expected prod_path in completed nodes, got: {:?}",
654+ result.completed_nodes
655+ );
656+ assert!(
657+ !result.completed_nodes.contains(&"dev_path".to_string()),
658+ "dev_path should not be in completed nodes"
659+ );
660+ }
661+
580662 // Test 8: PipelineExecutor::new and with_default_registry
581663 #[test]
582664 fn executor_constructors() {