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

Function TestOracleSetRoundTrip

reference_oracle_test.go:510–607  ·  view source on GitHub ↗

reqproof:proptest parser.Set Verifies: SYS-REQ-009 [property]

(t *testing.T)

Source from the content-addressed store, hash-verified

508// reqproof:proptest parser.Set
509// Verifies: SYS-REQ-009 [property]
510func TestOracleSetRoundTrip(t *testing.T) {
511 r := oracleNewRNG(oracleSeed + 1)
512 const iterations = 10000
513 knownBugPaths := 0
514 knownBugPanics := 0
515 for i := 0; i < iterations; i++ {
516 raw, v := oracleRandomJSONBytes(r, 3)
517 path := pickAdversarialPath(r, v)
518 setVal := oracleSetValue(r)
519 semanticallyValid := setPathSemanticallyValid(v, path)
520
521 var out []byte
522 var serr error
523 panicked := false
524 func() {
525 defer func() {
526 if rec := recover(); rec != nil {
527 panicked = true
528 if semanticallyValid {
529 t.Fatalf("Set panicked on semantically-valid path: "+
530 "input=%q path=%v val=%q: %v", raw, path, setVal, rec)
531 }
532 // Adversarial path: document the open panic bug.
533 // Known reachable via parser.go:981 (Set's nested
534 // array-of-objects + empty-key path) — see divergence D9.
535 knownBugPanics++
536 t.Logf("D9 known panic — Set on adversarial path panicked "+
537 "(open bug at parser.go:981): input=%q path=%v val=%q: %v",
538 raw, path, setVal, rec)
539 }
540 }()
541 assertInputUnchanged(t, raw, func() {
542 out, serr = Set(raw, setVal, path...)
543 })
544 }()
545
546 if panicked {
547 continue
548 }
549
550 if serr != nil {
551 // Set rejected the operation. The original document MUST still
552 // be valid JSON (Set must not corrupt on rejection).
553 if !json.Valid(raw) {
554 continue // generator invariant violation — skip
555 }
556 continue
557 }
558
559 // THE BUG-CATCHING ASSERTMENT: for semantically-valid paths, the
560 // output MUST be valid JSON AND Get on the same path MUST return
561 // the set value. PR #286's bug was that Set returned `out=[9]`
562 // for `Set([1,2], 9, "[5]")` — Set "succeeded" but the original
563 // [1,2] was silently destroyed.
564 //
565 // For semantically-INVALID paths (D6/D7/D8 — array-index on object
566 // root, nested OOB index, bracket-key on object), we soft-skip
567 // both assertions because the operation is ill-defined; those

Callers

nothing calls this directly

Calls 9

oracleNewRNGFunction · 0.85
oracleRandomJSONBytesFunction · 0.85
pickAdversarialPathFunction · 0.85
oracleSetValueFunction · 0.85
setPathSemanticallyValidFunction · 0.85
assertInputUnchangedFunction · 0.85
SetFunction · 0.85
GetFunction · 0.85
compareGetToOracleFunction · 0.85

Tested by

no test coverage detected