62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package llm
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"sort"
|
|
"testing"
|
|
)
|
|
|
|
func TestRuntimeTracksCapturedConfigurationAndInheritedMessageFiles(t *testing.T) {
|
|
cfg, main := runtimeAssemblyFixture(t, " proposal_profile: proposal\n validation_profile: validation\n", map[string]string{
|
|
"selected.yml": "profiles:\n proposal:\n backend: offline\n model: proposal\n validation:\n backend: offline\n model: validation\n",
|
|
})
|
|
profiles := filepath.Join(filepath.Dir(main), cfg.ProfilesDir)
|
|
parentDir := filepath.Join(profiles, "catalog")
|
|
childDir := filepath.Join(profiles, "nested", "child")
|
|
for _, directory := range []string{parentDir, childDir} {
|
|
if err := os.MkdirAll(directory, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
parent := filepath.Join(parentDir, "arbitrary-name.yaml")
|
|
child := filepath.Join(childDir, "override.yaml")
|
|
resource := filepath.Join(parentDir, "instruction.md")
|
|
parentDocument := "prompts:\n source:\n release/1~draft:\n messages:\n - role: user\n content_file: ./instruction.md\n output:\n format: text\n validation_mode: basic\n"
|
|
childDocument := "prompts:\n literal/~child:\n extends: source\n"
|
|
for path, content := range map[string]string{
|
|
parent: parentDocument,
|
|
child: childDocument,
|
|
resource: "Captured operator message.\n",
|
|
} {
|
|
if err := os.WriteFile(path, []byte(content), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
runtime, err := NewRuntime(context.Background(), cfg, main, &http.Client{Transport: rejectingTransport{}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := []string{
|
|
filepath.Join(profiles, "nested", "child", "override.yaml"),
|
|
filepath.Join(profiles, "catalog", "arbitrary-name.yaml"),
|
|
filepath.Join(profiles, "selected.yml"),
|
|
resource,
|
|
}
|
|
// Runtime paths are canonical paths from PromptKit's captured sources.
|
|
for i := range want {
|
|
want[i], err = filepath.EvalSymlinks(want[i])
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
sort.Strings(want)
|
|
if !reflect.DeepEqual(runtime.SourcePaths, want) {
|
|
t.Fatalf("captured source paths = %#v, want %#v", runtime.SourcePaths, want)
|
|
}
|
|
}
|