MCPcopy Create free account
hub / github.com/buger/jsonparser / TestFuzzPathMutationSeedsClean

Function TestFuzzPathMutationSeedsClean

path_fuzz_test.go:284–382  ·  view source on GitHub ↗

TestFuzzPathMutationSeedsClean is a regression gate that runs every seed corpus entry through FuzzPathMutation's body once. It catches seed-shape regressions (a seed that newly panics after a code change) without requiring a `-fuzz` run. Uses the same recover-and-record pattern as the fuzz body so p

(t *testing.T)

Source from the content-addressed store, hash-verified

282//
283// Verifies: SYS-REQ-035 [seed cleanliness]
284func TestFuzzPathMutationSeedsClean(t *testing.T) {
285 pathCrashCounter = 0
286 // Re-run the seed corpus through a manual loop (we can't invoke the
287 // testing.F body directly, so we replicate the body). Any seed that
288 // records a crash fails this test.
289 seeds := []struct {
290 data []byte
291 path []byte
292 }{
293 {[]byte(`{"a":1}`), []byte("a")},
294 {[]byte(`[1,2,3]`), []byte("")},
295 {[]byte(`{"a":{"b":1}}`), []byte("a")},
296 {[]byte(`{"a":[{"x":1}]}`), []byte("a")},
297 {[]byte(`{"a":1}`), []byte("[0]")},
298 {[]byte(`{"a":1}`), []byte("[99]")},
299 {[]byte(`{"":1}`), []byte("")},
300 {[]byte(`{"a":[1,2,3]}`), []byte("a/")},
301 {[]byte(`{"a":[{"b":1}]}`), []byte("a/[0]")},
302 {[]byte(`{"a":[{"b":1}]}`), []byte("a/[0]/")},
303 {[]byte(`null`), []byte("a")},
304 {[]byte(``), []byte("a")},
305 {[]byte(`{`), []byte("a")},
306 {[]byte(`[}`), []byte("[0]")},
307 }
308 setVal := []byte(`"v"`)
309 for i, tc := range seeds {
310 components := splitPathComponents(tc.path)
311
312 // json.Valid is only a meaningful post-condition when the input is
313 // itself valid JSON AND the path semantics apply to the input's
314 // container type. For malformed input or shape-mismatched paths
315 // (D6: array-index on object root), the parser's behavior is
316 // undefined; we only assert no-panic there. The D6 corruption is
317 // documented in reference_oracle_test.go's file header.
318 inputValid := json.Valid(tc.data)
319 pathShapeMatches := pathShapeMatchesRoot(tc.data, components)
320
321 // We do NOT soft-skip the D9 panic here: the seeds exercise shapes
322 // known to be safe post-fix, plus the D9 repro shape which IS
323 // expected to record a crash. If a previously-safe seed starts
324 // panicking, that's a regression.
325 ops := []struct {
326 name string
327 fn func()
328 }{
329 {"Get", func() { _, _, _, _ = Get(tc.data, components...) }},
330 {"GetString", func() { _, _ = GetString(tc.data, components...) }},
331 {"GetInt", func() { _, _ = GetInt(tc.data, components...) }},
332 {"GetFloat", func() { _, _ = GetFloat(tc.data, components...) }},
333 {"GetBoolean", func() { _, _ = GetBoolean(tc.data, components...) }},
334 {"ArrayEach", func() {
335 _, _ = ArrayEach(tc.data, func([]byte, ValueType, int, error) {}, components...)
336 }},
337 {"ObjectEach", func() {
338 _ = ObjectEach(tc.data, func([]byte, []byte, ValueType, int) error { return nil }, components...)
339 }},
340 {"EachKey", func() {
341 if len(components) > 0 {

Callers

nothing calls this directly

Calls 13

splitPathComponentsFunction · 0.85
pathShapeMatchesRootFunction · 0.85
GetFunction · 0.85
GetStringFunction · 0.85
GetIntFunction · 0.85
GetFloatFunction · 0.85
GetBooleanFunction · 0.85
ArrayEachFunction · 0.85
ObjectEachFunction · 0.85
EachKeyFunction · 0.85
SetFunction · 0.85
DeleteFunction · 0.85

Tested by

no test coverage detected