Bound JSON-compatible value copying
This commit is contained in:
@@ -2202,6 +2202,7 @@ func TestWithProfilesRejectsInvalidExtraParams(t *testing.T) {
|
||||
{name: "nan", extraParams: map[string]any{"bad": math.NaN()}},
|
||||
{name: "positive infinity", extraParams: map[string]any{"bad": math.Inf(1)}},
|
||||
{name: "negative infinity", extraParams: map[string]any{"bad": math.Inf(-1)}},
|
||||
{name: "excessively large value", extraParams: map[string]any{"bad": excessivelyLargeJSONValue()}},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
@@ -2466,6 +2467,7 @@ func TestRunRejectsInvalidExtraParams(t *testing.T) {
|
||||
{name: "cyclic slice", extraParams: map[string]any{"cycle": cyclicSlice}},
|
||||
{name: "malformed JSON number", extraParams: map[string]any{"value": json.Number("+1")}},
|
||||
{name: "empty nested key", extraParams: map[string]any{"nested": map[string]any{"": true}}},
|
||||
{name: "excessively deep value", extraParams: map[string]any{"nested": excessivelyDeepJSONValue()}},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
@@ -2490,6 +2492,29 @@ func TestRunRejectsInvalidExtraParams(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func excessivelyDeepJSONValue() any {
|
||||
const clearlyUnsafeContainerDepth = 1_000
|
||||
var value any = true
|
||||
for level := 0; level < clearlyUnsafeContainerDepth; level++ {
|
||||
if level%2 == 0 {
|
||||
value = map[string]any{"child": value}
|
||||
} else {
|
||||
value = []any{value}
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func excessivelyLargeJSONValue() any {
|
||||
const clearlyUnsafeSharedOccurrences = 60_000
|
||||
shared := []any{true}
|
||||
values := make([]any, clearlyUnsafeSharedOccurrences)
|
||||
for i := range values {
|
||||
values[i] = shared
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func TestWithLLMClientRejectsNilClient(t *testing.T) {
|
||||
_, err := promptkit.NewEngine(contractConfig(frameworkSchemaDir), promptkit.WithLLMClient(nil))
|
||||
if !errors.Is(err, promptkit.ErrInvalidConfig) {
|
||||
|
||||
Reference in New Issue
Block a user