Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091// Package property runs rapid properties under the repository's seed and// budget convention (robot-docs/testing.md#seeds-and-budgets).//// ALBEDO_PROPERTY_SEED unset runs the gate's fixed seed, "random" a fresh one,// and a number that seed. ALBEDO_PROPERTY_CASES sets the checks per property.// rapid's own -rapid.seed and -rapid.checks flags win when given. rapid prints// the failing seed and the shrunk counterexample itself. Fail files are off:// a counterexample is committed as a named example test instead.//// Import it only from _test files, so rapid stays out of the shipped binary.package property
import ( "flag" "fmt" "os" "strconv" "sync" "testing"
"pgregory.net/rapid")
// GateSeed is the seed every property runs with when ALBEDO_PROPERTY_SEED is// unset, so the gate replays the same cases on every run.const GateSeed uint64 = 1
var configure = sync.OnceValue(func() error { given := map[string]bool{} flag.Visit(func(f *flag.Flag) { given[f.Name] = true }) seed, err := Seed(os.Getenv("ALBEDO_PROPERTY_SEED")) if err != nil { return err } if !given["rapid.seed"] { if err := flag.Set("rapid.seed", strconv.FormatUint(seed, 10)); err != nil { return err } } if cases := os.Getenv("ALBEDO_PROPERTY_CASES"); cases != "" && !given["rapid.checks"] { if err := flag.Set("rapid.checks", cases); err != nil { return fmt.Errorf("ALBEDO_PROPERTY_CASES: %w", err) } } if !given["rapid.nofailfile"] { return flag.Set("rapid.nofailfile", "true") } return nil})
// Seed maps ALBEDO_PROPERTY_SEED to rapid's seed, where 0 asks for a random one.func Seed(value string) (uint64, error) { switch value { case "": return GateSeed, nil case "random": return 0, nil } seed, err := strconv.ParseUint(value, 10, 64) if err != nil || seed == 0 { return 0, fmt.Errorf("ALBEDO_PROPERTY_SEED must be unset, \"random\", or a positive integer, not %q", value) } return seed, nil}
// Check runs prop with rapid.Check under the convention.func Check(t *testing.T, prop func(*rapid.T)) { t.Helper() if err := configure(); err != nil { t.Fatal(err) } rapid.Check(t, prop)}
// AtGate reports whether properties run as the gate runs them: the gate's// seed and at least rapid's default budget. A coverage check that a model's// generator reached the interactions it is about is tuned to that run, and// holds only there; another seed that misses an event has found no defect.func AtGate() bool { if configure() != nil { return false } seed, checks := flag.Lookup("rapid.seed"), flag.Lookup("rapid.checks") if seed == nil || checks == nil || seed.Value.String() != strconv.FormatUint(GateSeed, 10) { return false } budget, err := strconv.Atoi(checks.Value.String()) least, defaultErr := strconv.Atoi(checks.DefValue) return err == nil && defaultErr == nil && budget >= least}