2026-10-04 00:56:14 +00:00
|
|
|
package llm
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"reflect"
|
|
|
|
|
"sort"
|
|
|
|
|
"testing"
|
2026-11-10 18:13:12 +00:00
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/config"
|
|
|
|
|
ck "go.maximumdirect.net/configkit"
|
2026-10-04 00:56:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestRuntimeTracksCapturedConfigurationAndInheritedMessageFiles(t *testing.T) {
|
2026-11-10 18:13:12 +00:00
|
|
|
dir := t.TempDir()
|
|
|
|
|
for name, content := range map[string]string{
|
2026-11-10 20:35:35 +00:00
|
|
|
"config.yml": "version: 3\n",
|
|
|
|
|
"prompts.yml": "config:\n imports:\n - path: catalog/arbitrary-name.yaml\n required: true\n",
|
|
|
|
|
"catalog/arbitrary-name.yaml": "prompts:\n - id: source\n messages:\n - role: user\n content_file: instruction.md\n output:\n format: text\n validation_mode: none\n",
|
|
|
|
|
"catalog/instruction.md": "Captured operator message.\n",
|
|
|
|
|
"prompts/nested/override.yaml": "prompts:\n - id: literal-child\n extends: {id: source}\n",
|
|
|
|
|
"prompts/nested/collection.yml": "collections:\n operator:\n prompts:\n - id: local\n messages:\n - role: user\n content_file: ../shared/collection.md\n output:\n format: text\n validation_mode: none\n",
|
|
|
|
|
"prompts/shared/collection.md": "Message in a collection.\n",
|
2026-11-10 18:13:12 +00:00
|
|
|
} {
|
|
|
|
|
file := filepath.Join(dir, name)
|
|
|
|
|
if err := os.MkdirAll(filepath.Dir(file), 0700); err != nil {
|
2026-10-04 00:56:14 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-11-10 18:13:12 +00:00
|
|
|
if err := os.WriteFile(file, []byte(content), 0600); err != nil {
|
2026-10-04 00:56:14 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-10 18:13:12 +00:00
|
|
|
loaded, err := config.Load(ck.Input{Source: ck.File(filepath.Join(dir, "config.yml"))}, "")
|
2026-10-04 00:56:14 +00:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
2026-11-10 18:13:12 +00:00
|
|
|
runtime, err := NewRuntime(context.Background(), loaded, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
2026-10-04 00:56:14 +00:00
|
|
|
}
|
2026-11-10 20:35:35 +00:00
|
|
|
want := []string{
|
|
|
|
|
filepath.Join(dir, "prompts.yml"),
|
|
|
|
|
filepath.Join(dir, "catalog/arbitrary-name.yaml"),
|
|
|
|
|
filepath.Join(dir, "catalog/instruction.md"),
|
|
|
|
|
filepath.Join(dir, "prompts/nested/override.yaml"),
|
|
|
|
|
filepath.Join(dir, "prompts/nested/collection.yml"),
|
|
|
|
|
filepath.Join(dir, "prompts/shared/collection.md"),
|
|
|
|
|
}
|
2026-10-04 00:56:14 +00:00
|
|
|
sort.Strings(want)
|
|
|
|
|
if !reflect.DeepEqual(runtime.SourcePaths, want) {
|
|
|
|
|
t.Fatalf("captured source paths = %#v, want %#v", runtime.SourcePaths, want)
|
|
|
|
|
}
|
|
|
|
|
}
|