build/generate-extended-cases: Fix testcase loader to use json.Number. (#8429)

The testcase generator had a bug where very large numbers would be
parsed incorrectly, truncating the lower bits off their values.

This was discovered to be caused by the YAML library defaulting
to parsing all numeric values into floating point numbers, which
lose precision at larger sizes.

The fix was to provide the YAML unmarshaling function with the
appropriate equivalent of `(*json.Decoder).UseNumber()` at the
callsite. This causes the YAML library to use `json.Number`
types by default, just as we expect almost everywhere else in
Rego.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
This commit is contained in:
Philip Conrad
2026-03-19 05:35:03 -04:00
committed by GitHub
parent c8b8772475
commit 2165d44ad6
@@ -2,6 +2,7 @@ package cases
import (
"context"
"encoding/json"
"errors"
"fmt"
"io/fs"
@@ -135,7 +136,11 @@ func LoadIrExtendedTestCasesFiltered(filters ...Filters) ([]ExtendedSet, error)
}
var x ExtendedSet
if err := yaml.Unmarshal(f, &x); err != nil {
useNumber := yaml.JSONOpt(func(d *json.Decoder) *json.Decoder {
d.UseNumber()
return d
})
if err := yaml.Unmarshal(f, &x, useNumber); err != nil {
return fmt.Errorf("%s: %w", path, err)
}