Share one native application configuration load and captured engine
This commit is contained in:
57
internal/cli/native_schema_load_test.go
Normal file
57
internal/cli/native_schema_load_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func TestNativeLoadPreparesOperatorSchemaSelections(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, test := range []struct {
|
||||
name, schema, root string
|
||||
missing bool
|
||||
}{
|
||||
{"inline", "schema: {type: object}", "", false},
|
||||
{"source file", "schema_file: response.json", "", false},
|
||||
{"external root", "schema_path: response.json", "schema_root: external-schemas", false},
|
||||
{"replaced root missing embedded schema", "schema_path: dnd/scenes/schemas/dnd_scenes_llm.v1.json", "schema_root: external-schemas", true},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
main := filepath.Join(dir, "config.yml")
|
||||
writeConfigKitFile(t, main, "version: 6\n")
|
||||
writeConfigKitFile(t, filepath.Join(dir, "response.json"), `{"type":"object"}`)
|
||||
writeConfigKitFile(t, filepath.Join(dir, "external-schemas", "response.json"), `{"type":"object"}`)
|
||||
writeConfigKitFile(t, filepath.Join(dir, "prompts.yml"), "collections:\n notarius:\n "+test.root+"\n prompts:\n - id: dnd.scenes\n default_profile: notarius/dnd-extraction\n messages: [{role: user, content: operator-message}]\n output:\n format: json\n validation_mode: json_schema\n "+test.schema+"\n")
|
||||
loaders := &nativeLoaders{}
|
||||
engine, err := loaders.engine(context.Background(), nativeSelection(main))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request := promptkit.RunRequest{PromptID: "notarius/dnd.scenes", APIKey: "fixture"}
|
||||
prepared, err := engine.PrepareExecution(context.Background(), request)
|
||||
if test.missing {
|
||||
if err == nil {
|
||||
prepared.Discard()
|
||||
t.Fatal("root replacement silently retained embedded schema root")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer prepared.Discard()
|
||||
details := prepared.Details()
|
||||
if len(details.Messages) != 1 || details.Messages[0].Content != "operator-message" || details.StructuredOutput == nil {
|
||||
t.Fatalf("replacement contract = %#v", details)
|
||||
}
|
||||
// Replacing one identified prompt must not discard unrelated embedded prompts.
|
||||
if _, err := engine.InspectPrompt(context.Background(), "notarius/dnd.spells"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user