@@ -17,7 +17,9 @@ use value_capture::{capture_call_arguments, record_return_value, record_visible_
1717use std:: collections:: { hash_map:: Entry , HashMap , HashSet } ;
1818use std:: fs;
1919use std:: path:: { Path , PathBuf } ;
20+ #[ cfg( feature = "integration-test" ) ]
2021use std:: sync:: atomic:: { AtomicBool , Ordering } ;
22+ #[ cfg( feature = "integration-test" ) ]
2123use std:: sync:: OnceLock ;
2224
2325use pyo3:: prelude:: * ;
@@ -89,15 +91,20 @@ impl FailureStage {
8991 }
9092}
9193
94+ // Failure injection helpers are only compiled for integration tests.
95+ #[ cfg_attr( not( feature = "integration-test" ) , allow( dead_code) ) ]
9296#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
9397enum FailureMode {
9498 Stage ( FailureStage ) ,
9599 SuppressEvents ,
96100}
97101
102+ #[ cfg( feature = "integration-test" ) ]
98103static FAILURE_MODE : OnceLock < Option < FailureMode > > = OnceLock :: new ( ) ;
104+ #[ cfg( feature = "integration-test" ) ]
99105static FAILURE_TRIGGERED : AtomicBool = AtomicBool :: new ( false ) ;
100106
107+ #[ cfg( feature = "integration-test" ) ]
101108fn configured_failure_mode ( ) -> Option < FailureMode > {
102109 * FAILURE_MODE . get_or_init ( || {
103110 let raw = std:: env:: var ( "CODETRACER_TEST_INJECT_FAILURE" ) . ok ( ) ;
@@ -114,6 +121,7 @@ fn configured_failure_mode() -> Option<FailureMode> {
114121 } )
115122}
116123
124+ #[ cfg( feature = "integration-test" ) ]
117125fn should_inject_failure ( stage : FailureStage ) -> bool {
118126 match configured_failure_mode ( ) {
119127 Some ( FailureMode :: Stage ( mode) ) if mode == stage => {
@@ -123,10 +131,22 @@ fn should_inject_failure(stage: FailureStage) -> bool {
123131 }
124132}
125133
134+ #[ cfg( not( feature = "integration-test" ) ) ]
135+ fn should_inject_failure ( _stage : FailureStage ) -> bool {
136+ false
137+ }
138+
139+ #[ cfg( feature = "integration-test" ) ]
126140fn suppress_events ( ) -> bool {
127141 matches ! ( configured_failure_mode( ) , Some ( FailureMode :: SuppressEvents ) )
128142}
129143
144+ #[ cfg( not( feature = "integration-test" ) ) ]
145+ fn suppress_events ( ) -> bool {
146+ false
147+ }
148+
149+ #[ cfg( feature = "integration-test" ) ]
130150fn injected_failure_err ( stage : FailureStage ) -> PyErr {
131151 let err = bug ! (
132152 ErrorCode :: TraceIncomplete ,
@@ -137,6 +157,17 @@ fn injected_failure_err(stage: FailureStage) -> PyErr {
137157 ffi:: map_recorder_error ( err)
138158}
139159
160+ #[ cfg( not( feature = "integration-test" ) ) ]
161+ fn injected_failure_err ( stage : FailureStage ) -> PyErr {
162+ let err = bug ! (
163+ ErrorCode :: TraceIncomplete ,
164+ "failure injection requested at {} without fail-injection feature" ,
165+ stage. as_str( )
166+ )
167+ . with_context ( "injection_stage" , stage. as_str ( ) . to_string ( ) ) ;
168+ ffi:: map_recorder_error ( err)
169+ }
170+
140171fn is_real_filename ( filename : & str ) -> bool {
141172 let trimmed = filename. trim ( ) ;
142173 !( trimmed. starts_with ( '<' ) && trimmed. ends_with ( '>' ) )
0 commit comments