@@ -77,13 +77,10 @@ async fn run_single_assertion(
7777 }
7878}
7979
80- /// Reorder `actual` arrays to align with `expected`'s element ordering .
80+ /// Reorder `actual` arrays to match `expected`'s element order for cleaner diffs .
8181///
82- /// When a test fails, the raw diff can be misleading if array elements appear
83- /// in a different order — every line shows as changed even if only one field
84- /// differs. This function reorders `actual` so that elements are paired with
85- /// their closest match in `expected`, producing a diff that highlights only
86- /// real value differences.
82+ /// Without this, out-of-order elements show every field as changed even when
83+ /// only one field differs.
8784pub ( super ) fn align_for_diff (
8885 expected : & serde_json:: Value ,
8986 actual : & serde_json:: Value ,
@@ -132,12 +129,8 @@ pub(super) fn align_for_diff(
132129 }
133130}
134131
135- /// Score how similar two JSON values are for use in [`align_for_diff`].
136- ///
137- /// For objects, counts the number of fields whose values are equal in both.
138- /// A matching `"id"` field is weighted heavily (+100) since it is the
139- /// strongest signal that two objects represent the same entity.
140- /// For all other value types, returns 1 if equal, 0 otherwise.
132+ /// Score JSON similarity for [`align_for_diff`].
133+ /// Objects: matching `"id"` = 100, other equal fields = 1. Non-objects: 0 or 1.
141134fn json_similarity ( a : & serde_json:: Value , b : & serde_json:: Value ) -> usize {
142135 match ( a, b) {
143136 ( serde_json:: Value :: Object ( a_obj) , serde_json:: Value :: Object ( b_obj) ) => {
@@ -162,13 +155,9 @@ fn json_similarity(a: &serde_json::Value, b: &serde_json::Value) -> usize {
162155 }
163156}
164157
165- /// Compare two JSON values for equality ( ignoring key ordering in objects) .
158+ /// Compare JSON values for equality, ignoring object key ordering.
166159///
167- /// Also handles string-vs-number coercion: GraphQL returns `BigInt` and
168- /// `BigDecimal` fields as JSON strings (e.g., `"1000000000000000000"`),
169- /// but test authors may write them as JSON numbers. This function treats
170- /// `String("123")` and `Number(123)` as equal when they represent the
171- /// same value.
160+ /// Coerces string/number: `"123"` == `123` to handle GraphQL `BigInt`/`BigDecimal`.
172161fn json_equal ( a : & serde_json:: Value , b : & serde_json:: Value ) -> bool {
173162 match ( a, b) {
174163 ( serde_json:: Value :: Null , serde_json:: Value :: Null ) => true ,
0 commit comments