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

Commit a0aee2fe

a0aee2fe6130Merged

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

Description

Replace real codergen calls with mock handlers in tests

Unit and integration tests no longer shell out to the Claude CLI. MockCodergenHandler returns Success with context updates, making tests fast, deterministic, and runnable without API keys.

Details

Commit
a0aee2fe6130
Parent
3c0bb486414f

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

@@ -224,12 +224,62 @@
224224 mod tests {
225225 use super::*;
226226 use crate::graph::PipelineGraph;
227+ use crate::handler::{HandlerRegistry, NodeHandler, StartHandler, ExitHandler, ConditionalHandler};
228+ use async_trait::async_trait;
227229
228230 fn parse_graph(dot: &str) -> PipelineGraph {
229231 let parsed = attractor_dot::parse(dot).unwrap();
230232 PipelineGraph::from_dot(parsed).unwrap()
231233 }
232234
235+ /// A mock codergen handler that returns Success without shelling out to Claude CLI.
236+ struct MockCodergenHandler;
237+
238+ #[async_trait]
239+ impl NodeHandler for MockCodergenHandler {
240+ fn handler_type(&self) -> &str {
241+ "codergen"
242+ }
243+ async fn execute(
244+ &self,
245+ node: &crate::graph::PipelineNode,
246+ _ctx: &Context,
247+ _graph: &PipelineGraph,
248+ ) -> Result<Outcome> {
249+ let mut updates = HashMap::new();
250+ updates.insert(
251+ format!("{}.completed", node.id),
252+ serde_json::Value::Bool(true),
253+ );
254+ updates.insert(
255+ format!("{}.result", node.id),
256+ serde_json::Value::String("mock result".into()),
257+ );
258+ Ok(Outcome {
259+ status: StageStatus::Success,
260+ preferred_label: None,
261+ suggested_next_ids: vec![],
262+ context_updates: updates,
263+ notes: "mock codergen".into(),
264+ failure_reason: None,
265+ })
266+ }
267+ }
268+
269+ /// Build a test registry with mock codergen handler (no real CLI calls).
270+ fn test_registry() -> HandlerRegistry {
271+ let mut reg = HandlerRegistry::new();
272+ reg.register(StartHandler);
273+ reg.register(ExitHandler);
274+ reg.register(ConditionalHandler);
275+ reg.register(MockCodergenHandler);
276+ reg
277+ }
278+
279+ fn test_executor() -> PipelineExecutor {
280+ PipelineExecutor::new(test_registry())
281+ }
282+
233283 // Test 1: Linear pipeline (start -> A -> exit) completes successfully
234284 #[tokio::test]
235285 async fn linear_pipeline_completes() {
@@ -241,7 +291,7 @@
241291 start -> process -> done
242292 }"#,
243293 );
244- let executor = PipelineExecutor::with_default_registry();
294+ let executor = test_executor();
245295 let result = executor.run(&graph).await.unwrap();
246296
247297 assert_eq!(result.completed_nodes, vec!["start", "process", "done"]);
@@ -265,7 +315,7 @@
265315 // Test 2: Branching pipeline routes based on conditions
266316 #[tokio::test]
267317 async fn branching_pipeline_routes_on_condition() {
268- // The codergen handler returns Success, so outcome=success.
318+ // The mock codergen handler returns Success, so outcome=success.
269319 // Edge to "yes_path" has condition="outcome=success", so it should be taken.
270320 let graph = parse_graph(
271321 r#"digraph G {
@@ -281,7 +331,7 @@
281331 no_path -> done
282332 }"#,
283333 );
284- let executor = PipelineExecutor::with_default_registry();
334+ let executor = test_executor();
285335 let result = executor.run(&graph).await.unwrap();
286336
287337 assert!(result.completed_nodes.contains(&"yes_path".to_string()));
@@ -298,7 +348,7 @@
298348 process -> done
299349 }"#,
300350 );
301- let executor = PipelineExecutor::with_default_registry();
351+ let executor = test_executor();
302352 let result = executor.run(&graph).await;
303353
304354 assert!(result.is_err());
@@ -317,7 +367,7 @@
317367 // Test 4: Context updates from one node visible to next (verify via final_context)
318368 #[tokio::test]
319369 async fn context_updates_propagate() {
320- // The codergen handler (Claude Code) sets context_updates with
370+ // The mock codergen handler sets context_updates with
321371 // "<node_id>.completed", "<node_id>.result", etc.
322372 let graph = parse_graph(
323373 r#"digraph G {
@@ -327,15 +377,15 @@
327377 start -> step -> done
328378 }"#,
329379 );
330- let executor = PipelineExecutor::with_default_registry();
380+ let executor = test_executor();
331381 let result = executor.run(&graph).await.unwrap();
332382
333- // The codergen handler marks the node as completed
383+ // The mock handler marks the node as completed
334384 assert_eq!(
335385 result.final_context.get("step.completed"),
336386 Some(&serde_json::Value::Bool(true)),
337387 );
338- // The codergen handler stores the Claude response in "<node_id>.result"
388+ // The mock handler stores a result in "<node_id>.result"
339389 assert!(
340390 result.final_context.contains_key("step.result"),
341391 "Expected step.result in final context, keys: {:?}",
@@ -351,13 +401,8 @@
351401 // Test 5: Goal gate failure with retry target loops back
352402 #[tokio::test]
353403 async fn goal_gate_failure_with_retry_loops_back() {
354- // We cannot easily make a handler fail on first call and succeed on second
355- // with the default registry. Instead, we test that goal gate checking works
356- // by having a goal gate node that succeeds (so no loop occurs) and verifying
357- // the exit is reached.
358- //
359- // For a more thorough test of the retry path, we'd need a custom handler.
360- // Here we at least verify the goal gate path doesn't error when gates are satisfied.
404+ // The mock handler returns success, so goal gate is satisfied and no loop occurs.
405+ // Here we verify the goal gate path doesn't error when gates are satisfied.
361406 let graph = parse_graph(
362407 r#"digraph G {
363408 start [shape="Mdiamond"]
@@ -366,10 +411,10 @@
366411 start -> review -> done
367412 }"#,
368413 );
369- let executor = PipelineExecutor::with_default_registry();
414+ let executor = test_executor();
370415 let result = executor.run(&graph).await.unwrap();
371416
372- // Goal gate is satisfied (codergen returns success), so pipeline completes
417+ // Goal gate is satisfied (mock returns success), so pipeline completes
373418 assert!(result.completed_nodes.contains(&"done".to_string()));
374419 }
375420