============================================================================= Gate A: NO-PANIC (embedded in every gate via encodingJSONNoPanic) ============================================================================= Gate A is not a standalone function: every json.* call throughout the gates b
(t *testing.T, data []byte)
| 172 | // These two code paths share the same scanner internally but have |
| 173 | // historically diverged on edge cases (trailing data, malformed escapes). |
| 174 | func runValidConsistencyGate(t *testing.T, data []byte) { |
| 175 | t.Helper() |
| 176 | valid := json.Valid(data) |
| 177 | |
| 178 | var v interface{} |
| 179 | var unmarshalErr error |
| 180 | encodingJSONNoPanic(t, "ValidConsistency/Unmarshal", data, func() { |
| 181 | unmarshalErr = json.Unmarshal(data, &v) |
| 182 | }) |
| 183 | |
| 184 | if valid && unmarshalErr != nil { |
| 185 | // json.Unmarshal into interface{} represents numbers as float64, |
| 186 | // which cannot hold values like 1e999 (would be +Inf). This is a |
| 187 | // DOCUMENTED design choice of encoding/json (the docs say "float64, |
| 188 | // for JSON numbers"), NOT a syntactic Valid/Unmarshal divergence — |
| 189 | // it is the same number-range limitation the spec says to document |
| 190 | // rather than flag. Re-verify with json.Number (which has no |
| 191 | // float64-range constraint): if the number-aware decode succeeds, |
| 192 | // this is the float64-range case; only flag if json.Number ALSO |
| 193 | // fails, which would indicate a genuine syntactic inconsistency. |
| 194 | dec := json.NewDecoder(bytes.NewReader(data)) |
| 195 | dec.UseNumber() |
| 196 | var nv interface{} |
| 197 | if dErr := dec.Decode(&nv); dErr == nil { |
| 198 | return // float64-range limitation — documented non-bug. |
| 199 | } |
| 200 | t.Errorf("Gate B: json.Valid==true but Unmarshal failed even under "+ |
| 201 | "UseNumber (genuine consistency bug): err=%v data=%s", |
| 202 | unmarshalErr, truncateForMsg(data)) |
| 203 | } |
| 204 | if !valid && unmarshalErr == nil { |
| 205 | t.Errorf("Gate B: json.Valid==false but Unmarshal succeeded (consistency bug): "+ |
| 206 | "data=%s", truncateForMsg(data)) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // ============================================================================= |
| 211 | // Gate C: Unmarshal → Marshal → Unmarshal round-trip equivalence |
no test coverage detected