Add schema selection values and ownership
This commit is contained in:
@@ -104,3 +104,40 @@ func TestNilTypedPromptSourceSuppliesEmptySequence(t *testing.T) {
|
||||
t.Fatalf("empty source = %v, %v", prompts, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypedPromptSourceSchemaValues(t *testing.T) {
|
||||
var absent map[string]any
|
||||
object := map[string]any{"type": "object"}
|
||||
file := "schema.json"
|
||||
source := promptkit.PromptSource("schemas", []promptkit.PromptConfig{
|
||||
{ID: "false", Output: &promptkit.PromptOutputConfig{Schema: false}},
|
||||
{ID: "true", Output: &promptkit.PromptOutputConfig{Schema: true}},
|
||||
{ID: "empty", Output: &promptkit.PromptOutputConfig{Schema: map[string]any{}}},
|
||||
{ID: "absent", Output: &promptkit.PromptOutputConfig{Schema: absent}},
|
||||
{ID: "object", Output: &promptkit.PromptOutputConfig{Schema: object, SchemaFile: &file}},
|
||||
})
|
||||
object["type"] = "changed"
|
||||
type document struct {
|
||||
Prompts []struct {
|
||||
ID string `yaml:"id"`
|
||||
Output map[string]any `yaml:"output"`
|
||||
} `yaml:"prompts"`
|
||||
}
|
||||
result, err := configkit.LoadLayered(configkit.Input{Source: source}, configkit.LayeredOptions[document]{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
values := result.Config.Prompts
|
||||
if values[0].Output["schema"] != false || values[1].Output["schema"] != true {
|
||||
t.Fatalf("boolean schemas: %#v", values)
|
||||
}
|
||||
if empty, ok := values[2].Output["schema"].(map[string]any); !ok || len(empty) != 0 {
|
||||
t.Fatalf("empty schema: %#v", values[2])
|
||||
}
|
||||
if _, ok := values[3].Output["schema"]; ok {
|
||||
t.Fatalf("nil schema emitted: %#v", values[3])
|
||||
}
|
||||
if captured, ok := values[4].Output["schema"].(map[string]any); !ok || captured["type"] != "object" || values[4].Output["schema_file"] != file {
|
||||
t.Fatalf("captured schema: %#v", values[4])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user