Accept ConfigKit integers in module options
This commit is contained in:
@@ -155,7 +155,7 @@ func nonNegativeIntOption(name string, value any) (int, error) {
|
||||
}
|
||||
|
||||
func intOption(name string, value any) (int, error) {
|
||||
got, ok := value.(int)
|
||||
got, ok := pipeline.IntOption(value)
|
||||
if !ok {
|
||||
return 0, chunkerErrorf("%s must be an integer", name)
|
||||
}
|
||||
|
||||
@@ -121,9 +121,19 @@ func TestPlanRejectsInvalidOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeOptionsRejectsNonNativeIntegers(t *testing.T) {
|
||||
func TestDecodeOptionsAcceptsConfigKitIntegers(t *testing.T) {
|
||||
options, err := DecodeOptions(map[string]any{"max_units": int64(2), "overlap_units": int64(1)})
|
||||
if err != nil {
|
||||
t.Fatalf("DecodeOptions() error = %v", err)
|
||||
}
|
||||
if options.MaxUnits != 2 || options.OverlapUnits != 1 {
|
||||
t.Fatalf("DecodeOptions() = %#v", options)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeOptionsRejectsUnsupportedIntegerRepresentations(t *testing.T) {
|
||||
for _, value := range []any{
|
||||
int8(2), int16(2), int32(2), int64(2),
|
||||
int8(2), int16(2), int32(2),
|
||||
uint(2), uint8(2), uint16(2), uint32(2), uint64(2),
|
||||
float32(2), float64(2), json.Number("2"),
|
||||
} {
|
||||
|
||||
@@ -182,7 +182,7 @@ func decodeEvidenceContextPolicy(value any) (pipeline.EvidenceContextPolicy, err
|
||||
}
|
||||
windowUnits := 3
|
||||
if rawWindow, ok := object["window_units"]; ok {
|
||||
value, ok := rawWindow.(int)
|
||||
value, ok := pipeline.IntOption(rawWindow)
|
||||
if !ok {
|
||||
return pipeline.EvidenceContextPolicy{}, encoderErrorf("evidence_context option %q must be an integer", "window_units")
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ func TestDecodeEvidenceContextOptions(t *testing.T) {
|
||||
{name: "disabled", options: map[string]any{"evidence_context": map[string]any{"enabled": false}}},
|
||||
{name: "enabled default window", options: map[string]any{"evidence_context": map[string]any{"enabled": true, "lanes": []any{"npcs"}}}, want: pipeline.EvidenceContextPolicy{Enabled: true, WindowUnits: 3, LaneIDs: []string{"npcs"}}},
|
||||
{name: "explicit zero window and normalized lanes", options: map[string]any{"evidence_context": map[string]any{"enabled": true, "lanes": []any{" spells ", "npcs"}, "window_units": 0}}, want: pipeline.EvidenceContextPolicy{Enabled: true, WindowUnits: 0, LaneIDs: []string{"npcs", "spells"}}},
|
||||
{name: "ConfigKit window integer", options: map[string]any{"evidence_context": map[string]any{"enabled": true, "lanes": []any{"npcs"}, "window_units": int64(2)}}, want: pipeline.EvidenceContextPolicy{Enabled: true, WindowUnits: 2, LaneIDs: []string{"npcs"}}},
|
||||
{name: "duplicate lanes", options: map[string]any{"evidence_context": map[string]any{"enabled": true, "lanes": []any{"npcs", " npcs "}}}, wantErr: "duplicated"},
|
||||
{name: "unknown nested option", options: map[string]any{"evidence_context": map[string]any{"enabled": false, "extra": true}}, wantErr: "unknown option"},
|
||||
{name: "disabled nested fields", options: map[string]any{"evidence_context": map[string]any{"enabled": false, "lanes": []any{"npcs"}}}, wantErr: "not allowed"},
|
||||
|
||||
Reference in New Issue
Block a user