@@ -76,9 +76,9 @@ def _measure_once(label: str, fn: Callable[[Any], Any], payload: Any) -> float:
7676 return elapsed_ms
7777
7878
79- def _run_with_rust_masking_enabled (enabled : bool , fn : Callable [[ Any ] , Any ], payload : Any ) -> Any :
79+ def _run_with_rust_masking_enabled (enabled : bool , fn : Callable [... , Any ], * args : Any ) -> Any :
8080 with _rust_masking_enabled (enabled ):
81- return fn (payload )
81+ return fn (* args )
8282
8383
8484def _measure_with_rust_masking_enabled (enabled : bool , label : str , fn : Callable [[Any ], Any ], payload : Any , iterations : int ) -> tuple [float , float ]:
@@ -94,6 +94,14 @@ def _assert_parity(python_fn: Callable[[Any], Any], rust_fn: Callable[[Any], Any
9494 raise AssertionError (f"Parity mismatch for payload { payload !r} : python={ python_result !r} rust={ rust_result !r} " )
9595
9696
97+ def _assert_depth_parity (python_fn : Callable [[Any , int ], Any ], rust_fn : Callable [[Any , int ], Any ], cases : list [tuple [Any , int ]]) -> None :
98+ for payload , max_depth in cases :
99+ python_result = python_fn (payload , max_depth )
100+ rust_result = rust_fn (payload , max_depth )
101+ if python_result != rust_result :
102+ raise AssertionError (f"Depth parity mismatch for payload { payload !r} at max_depth={ max_depth } : " f"python={ python_result !r} rust={ rust_result !r} " )
103+
104+
97105def main () -> None :
98106 sidecar = _ensure_sidecar_installed ()
99107 request_logging_middleware ._RUST_REQUEST_LOGGING_MODULE = sidecar
@@ -104,6 +112,12 @@ def python_data(payload: Any) -> Any:
104112 def rust_data (payload : Any ) -> Any :
105113 return mask_sensitive_data (payload , 12 )
106114
115+ def python_data_with_depth (payload : Any , max_depth : int ) -> Any :
116+ return mask_sensitive_data (payload , max_depth )
117+
118+ def rust_data_with_depth (payload : Any , max_depth : int ) -> Any :
119+ return mask_sensitive_data (payload , max_depth )
120+
107121 def python_headers (payload : Any ) -> Any :
108122 return mask_sensitive_headers (payload )
109123
@@ -121,6 +135,17 @@ def rust_headers(payload: Any) -> Any:
121135 {"password" : "secret" , "nested" : {"authToken" : "abc" , "ok" : "value" }},
122136 {"token_count" : 3 , "tokenizer" : "ok" , "privateKey" : "secret" },
123137 [{"jwt_token" : "abc" }, {"normal" : "value" }],
138+ {"outer" : [{1 : "numeric-key" , "authToken" : "abc" }, {"nested" : {("tuple" , 2 ): "tuple-key" , "clientSecret" : "hidden" }}]}, # pragma: allowlist secret
139+ {"outer" : [{"leaf" : "value" }, {"nested" : ["safe" , {"secret" : "x" }]}]},
140+ ],
141+ )
142+ _assert_depth_parity (
143+ lambda payload , max_depth : _run_with_rust_masking_enabled (False , python_data_with_depth , payload , max_depth ),
144+ lambda payload , max_depth : _run_with_rust_masking_enabled (True , rust_data_with_depth , payload , max_depth ),
145+ [
146+ ({"level" : "x" }, 1 ),
147+ ([{"leaf" : "x" }], 1 ),
148+ ({"outer" : [{"leaf" : "value" }, {"nested" : ["safe" , {"secret" : "x" }]}]}, 2 ),
124149 ],
125150 )
126151 _assert_parity (
0 commit comments