1+ #![ allow( clippy:: too_many_arguments) ]
2+
13/*
24 * SPDX-License-Identifier: MIT
35 * Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
@@ -22,7 +24,6 @@ fn test_evaluate_subgraph_from_cause_with_relay_to_simple() {
2224 |_effect : & PropagatingEffect | -> Result < PropagatingEffect , CausalityError > {
2325 Ok ( PropagatingEffect :: RelayTo (
2426 3 ,
25- //
2627 Box :: new ( PropagatingEffect :: Deterministic ( false ) ) ,
2728 ) )
2829 } ;
@@ -189,3 +190,48 @@ fn test_evaluate_shortest_path_between_causes_with_relay_at_end() {
189190 PropagatingEffect :: RelayTo ( 0 , Box :: new( PropagatingEffect :: Numerical ( 50.0 ) ) )
190191 ) ;
191192}
193+
194+ #[ test]
195+ fn test_evaluate_subgraph_from_cause_relay_to_non_existent_node ( ) {
196+ // Graph: Root (0) -> A (1)
197+ // A will relay to a non-existent node (e.g., index 99)
198+ let mut g = CausaloidGraph :: new ( 0 ) ;
199+
200+ let root_causaloid = test_utils:: get_test_causaloid_deterministic_true ( ) ;
201+ let root_index = g. add_root_causaloid ( root_causaloid) . unwrap ( ) ;
202+
203+ // Causaloid A: Relays to a non-existent node (index 99)
204+ let non_existent_target_index = 124 ;
205+ let causaloid_a_id = 14 ;
206+ let causaloid_a_description = format ! (
207+ "Causaloid A relays to non-existent node {}" ,
208+ non_existent_target_index
209+ ) ;
210+ let causaloid_a_fn =
211+ |_effect : & PropagatingEffect | -> Result < PropagatingEffect , CausalityError > {
212+ Ok ( PropagatingEffect :: RelayTo (
213+ 124 , // non_existent_target_index
214+ Box :: new ( PropagatingEffect :: Numerical ( 1.0 ) ) ,
215+ ) )
216+ } ;
217+
218+ let causaloid_a = Causaloid :: new ( causaloid_a_id, causaloid_a_fn, & causaloid_a_description) ;
219+ let idx_a = g. add_causaloid ( causaloid_a) . unwrap ( ) ;
220+
221+ // Link the graph: Root -> A
222+ g. add_edge ( root_index, idx_a) . unwrap ( ) ;
223+
224+ g. freeze ( ) ;
225+
226+ let initial_effect = PropagatingEffect :: Deterministic ( true ) ;
227+ let res = g. evaluate_subgraph_from_cause ( root_index, & initial_effect) ;
228+
229+ assert ! ( res. is_err( ) ) ;
230+ assert_eq ! (
231+ res. unwrap_err( ) . to_string( ) ,
232+ format!(
233+ "CausalityError: RelayTo target causaloid with index {} not found in graph." ,
234+ non_existent_target_index
235+ )
236+ ) ;
237+ }
0 commit comments