Compose application assets in one strict group
This commit is contained in:
@@ -101,21 +101,25 @@ func (r *AssetRegistry) FallbackProfileDigest() (string, error) {
|
||||
}
|
||||
|
||||
// PromptKitConfigurationSources returns the registered prompt and fallback
|
||||
// profile assets as native PromptKit underlay groups. Schema assets remain a
|
||||
// profile assets in one strict native PromptKit underlay. Schema assets remain a
|
||||
// separate PromptKit option because they are runtime validation resources.
|
||||
func (r *AssetRegistry) PromptKitConfigurationSources() (promptkit.ConfigurationSources, []promptkit.Option, error) {
|
||||
if r == nil {
|
||||
return promptkit.ConfigurationSources{}, nil, fmt.Errorf("asset registry must not be nil")
|
||||
}
|
||||
underlays, err := promptKitFilesystemUnderlays(r.prompts, "notarius-prompts")
|
||||
inputs, err := promptKitFilesystemInputs(r.prompts, "notarius-prompts")
|
||||
if err != nil {
|
||||
return promptkit.ConfigurationSources{}, nil, fmt.Errorf("prepare prompt configuration sources: %w", err)
|
||||
}
|
||||
profiles, err := promptKitFilesystemUnderlays(r.fallbackProfiles, "notarius-fallback-profiles")
|
||||
profiles, err := promptKitFilesystemInputs(r.fallbackProfiles, "notarius-fallback-profiles")
|
||||
if err != nil {
|
||||
return promptkit.ConfigurationSources{}, nil, fmt.Errorf("prepare fallback profile configuration sources: %w", err)
|
||||
}
|
||||
underlays = append(underlays, profiles...)
|
||||
inputs = append(inputs, profiles...)
|
||||
var underlays []configkit.Underlay
|
||||
if len(inputs) != 0 {
|
||||
underlays = []configkit.Underlay{{Inputs: inputs}}
|
||||
}
|
||||
schemaFS, err := r.SchemaFS()
|
||||
if err != nil {
|
||||
return promptkit.ConfigurationSources{}, nil, fmt.Errorf("prepare schema assets: %w", err)
|
||||
@@ -125,18 +129,16 @@ func (r *AssetRegistry) PromptKitConfigurationSources() (promptkit.Configuration
|
||||
}, nil
|
||||
}
|
||||
|
||||
func promptKitFilesystemUnderlays(sources []AssetSource, label string) ([]configkit.Underlay, error) {
|
||||
underlays := make([]configkit.Underlay, 0, len(sources))
|
||||
func promptKitFilesystemInputs(sources []AssetSource, label string) ([]configkit.Input, error) {
|
||||
var selected []configkit.Input
|
||||
for index, source := range sources {
|
||||
inputs, err := promptkit.FilesystemInputs(fmt.Sprintf("%s-%d", label, index), source.FS, source.Root)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("select filesystem inputs: %w", err)
|
||||
}
|
||||
if len(inputs) != 0 {
|
||||
underlays = append(underlays, configkit.Underlay{Inputs: inputs})
|
||||
}
|
||||
selected = append(selected, inputs...)
|
||||
}
|
||||
return underlays, nil
|
||||
return selected, nil
|
||||
}
|
||||
|
||||
func (r *AssetRegistry) fallbackProfileAssets() (fs.FS, string, bool, error) {
|
||||
|
||||
@@ -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