DetectJSONDrift compares a recorded request body against the live one and returns the "body."-prefixed field paths that drifted and are NOT already covered by known noise (root-relative: global/user ∪ already-learned, prefix stripped). isRecordedNoise, when non-nil, drops fields whose recorded value
(recordedBody, liveBody []byte, known map[string][]string, isRecordedNoise func(string) bool)
| 233 | // real, non-learnable mismatch. This is the single JSON-diff kernel behind both |
| 234 | // the HTTP and Pulsar schema-noise paths. |
| 235 | func DetectJSONDrift(recordedBody, liveBody []byte, known map[string][]string, isRecordedNoise func(string) bool) (drift map[string][]string, comparable bool) { |
| 236 | if !json.Valid(recordedBody) || !json.Valid(liveBody) { |
| 237 | return nil, false |
| 238 | } |
| 239 | paths := matcher.ChangedJSONFieldPaths(string(recordedBody), string(liveBody), known, isRecordedNoise) |
| 240 | if len(paths) == 0 { |
| 241 | return nil, true |
| 242 | } |
| 243 | out := make(map[string][]string, len(paths)) |
| 244 | for _, p := range paths { |
| 245 | // Empty regex list == "ignore this whole field", the same semantics as |
| 246 | // HTTPReq.ReqBodyNoise and TestCase.Noise. |
| 247 | out["body."+p] = []string{} |
| 248 | } |
| 249 | return out, true |
| 250 | } |
| 251 | |
| 252 | // MergeLearned returns a fresh map combining already-recorded noise with newly |
| 253 | // detected noise. Existing entries win on key collision (learned noise is |