| 1 |
//go:build !no_antithesis_sdk |
| 2 |
|
| 3 |
package assert |
| 4 |
|
| 5 |
import ( |
| 6 |
"sync" |
| 7 |
|
| 8 |
"github.com/antithesishq/antithesis-sdk-go/internal" |
| 9 |
) |
| 10 |
|
| 11 |
// TODO: Someday this tracker should also start deduplicating |
| 12 |
// guidance, but there are some complicated policy questions |
| 13 |
// to settle before we do that. |
| 14 |
type booleanGuidance struct{} |
| 15 |
|
| 16 |
// booleanGuidanceTracker keeps the per-id entries: a grow-only map with |
| 17 |
// stable keys, read on every rich-assert evaluation and written once per |
| 18 |
// guidance id. |
| 19 |
var booleanGuidanceTracker sync.Map // message key -> *booleanGuidance |
| 20 |
|
| 21 |
func getBooleanGuidanceEntry(messageKey string) *booleanGuidance { |
| 22 |
if entry, ok := booleanGuidanceTracker.Load(messageKey); ok { |
| 23 |
return entry.(*booleanGuidance) |
| 24 |
} |
| 25 |
entry, _ := booleanGuidanceTracker.LoadOrStore(messageKey, &booleanGuidance{}) |
| 26 |
return entry.(*booleanGuidance) |
| 27 |
} |
| 28 |
|
| 29 |
func (tI *booleanGuidance) send_value(bgI *booleanGuidanceInfo) { |
| 30 |
if tI == nil { |
| 31 |
return |
| 32 |
} |
| 33 |
|
| 34 |
emitBooleanGuidance(bgI) |
| 35 |
} |
| 36 |
|
| 37 |
func emitBooleanGuidance(bgI *booleanGuidanceInfo) error { |
| 38 |
return internal.Json_data(map[string]any{"antithesis_guidance": bgI}) |
| 39 |
} |