Compose application assets in one strict group
This commit is contained in:
@@ -1,54 +1,53 @@
|
||||
package llm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
)
|
||||
|
||||
func TestPromptKitConfigurationSourcesKeepsNativeFilesystemGroups(t *testing.T) {
|
||||
registry := NewAssetRegistry()
|
||||
for index, name := range []string{"first", "second"} {
|
||||
files := fstest.MapFS{
|
||||
"prompts/prompt.yaml": {Data: []byte("prompts: {}\n")},
|
||||
}
|
||||
if err := registry.RegisterPromptFS(files, "."); err != nil {
|
||||
t.Fatalf("register prompt source %d (%s): %v", index, name, err)
|
||||
}
|
||||
}
|
||||
fallbackProfiles := fstest.MapFS{
|
||||
"profiles.yaml": {Data: []byte("profiles: {}\n")},
|
||||
}
|
||||
if err := registry.RegisterFallbackProfileFS(fallbackProfiles, "."); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
schemas := fstest.MapFS{"schema.json": {Data: []byte(`{"type":"object"}`)}}
|
||||
if err := registry.RegisterSchemaFS(schemas, "."); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sources, options, err := registry.PromptKitConfigurationSources()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if sources.Main != nil {
|
||||
t.Fatalf("maintained sources unexpectedly set a main input: %+v", sources.Main)
|
||||
}
|
||||
if len(sources.Underlays) != 3 {
|
||||
t.Fatalf("underlays = %d, want two prompt groups and one profile group", len(sources.Underlays))
|
||||
}
|
||||
for index, underlay := range sources.Underlays {
|
||||
if len(underlay.Inputs) != 1 {
|
||||
t.Fatalf("underlay %d has %d inputs, want 1", index, len(underlay.Inputs))
|
||||
}
|
||||
input := underlay.Inputs[0]
|
||||
if input.Imports {
|
||||
t.Fatalf("maintained input %d unexpectedly enables imports", index)
|
||||
}
|
||||
if input.Filesystem == nil || input.Filesystem.FS == nil {
|
||||
t.Fatalf("maintained input %d has no native filesystem context", index)
|
||||
}
|
||||
}
|
||||
if len(options) != 1 {
|
||||
t.Fatalf("runtime options = %d, want one schema option", len(options))
|
||||
func TestApplicationAssetsComposeStrictlyBeforeOperatorOverlay(t *testing.T) {
|
||||
for _, conflict := range []bool{false, true} {
|
||||
t.Run(fmt.Sprint("conflict=", conflict), func(t *testing.T) {
|
||||
registry := NewAssetRegistry()
|
||||
for _, id := range []string{"first", "second"} {
|
||||
if conflict {
|
||||
id = "first"
|
||||
}
|
||||
files := fstest.MapFS{"profiles.yaml": {Data: []byte(fmt.Sprintf("profiles:\n %s:\n backend: openrouter\n model: openai/gpt-5.6-luna\n", id))}}
|
||||
if err := registry.RegisterFallbackProfileFS(files, "."); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
operator := filepath.Join(t.TempDir(), "operator.yml")
|
||||
if err := os.WriteFile(operator, []byte("profiles:\n first:\n api_key_required: false\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inspector, err := NewPromptKitProfileInspector(PromptKitProfileInspectorConfig{Assets: registry, Source: PromptKitProfileSourceConfig{ProfileFile: operator}})
|
||||
if conflict {
|
||||
if err == nil {
|
||||
t.Fatal("conflicting application profiles were silently overlaid")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, id := range []string{"first", "second"} {
|
||||
profile, err := inspector.InspectProfile(context.Background(), id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if profile.Model != "openai/gpt-5.6-luna" || profile.BackendID != "openrouter" {
|
||||
t.Fatalf("profile = %#v", profile)
|
||||
}
|
||||
if id == "first" && profile.CredentialRequired {
|
||||
t.Fatal("operator overlay was not applied")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user