Detach schemas without provider value limits

This commit is contained in:
2026-11-05 20:06:37 +00:00
parent 9463c9463a
commit 6c015a17fa
6 changed files with 66 additions and 81 deletions

View File

@@ -80,6 +80,39 @@ func TestSchemaFilePreparationAndNativeSubmission(t *testing.T) {
}
}
func TestSchemaFilePreparationDetachesLargeAnnotation(t *testing.T) {
// Annotation values are not constraints; this array exceeds the former
// provider-value copier node limit without requiring a large fixture file.
const entries = 100_001
path := filepath.Join(t.TempDir(), "schema.json")
schema := `{"type":"string","examples":[` + strings.Repeat(`0,`, entries-1) + `0]}`
if err := os.WriteFile(path, []byte(schema), 0o600); err != nil {
t.Fatal(err)
}
input := configkit.Input{Source: configkit.Mapping("schema test", map[string]any{
"profiles": []any{map[string]any{"id": "profile", "endpoint": "https://example.invalid/v1", "model": "model"}},
"prompts": []any{map[string]any{"id": "prompt", "default_profile": "profile", "messages": []any{map[string]any{"role": "user", "content": "hello"}}, "output": map[string]any{"format": "json", "validation_mode": "json_schema", "schema_path": "schema.json"}}},
})}
engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &input}}, promptkit.WithSchemaFile(path))
if err != nil {
t.Fatal(err)
}
prepared, err := engine.PrepareExecution(context.Background(), promptkit.RunRequest{PromptID: "prompt"})
if err != nil {
t.Fatalf("prepare large schema: %v", err)
}
first := prepared.Details().StructuredOutput.JSONSchema.Schema.(map[string]any)
examples := first["examples"].([]any)
if len(examples) != entries {
t.Fatalf("examples = %d, want %d", len(examples), entries)
}
examples[0] = "changed"
second := prepared.Details().StructuredOutput.JSONSchema.Schema.(map[string]any)
if _, ok := second["examples"].([]any)[0].(json.Number); !ok {
t.Fatal("schema details share mutable annotation values")
}
}
func TestSchemaFileRejectsInvalidSourcesAndExternalReferences(t *testing.T) {
dir := t.TempDir()
for _, name := range []string{filepath.Join(dir, "missing.json"), dir} {