Update integration fixtures and collection examples
This commit is contained in:
@@ -7,8 +7,11 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
appconfig "gitea.maximumdirect.net/eric/scriptorium/internal/config"
|
||||
)
|
||||
|
||||
func TestConfigCommandsInspectApplicationWithoutEngine(t *testing.T) {
|
||||
@@ -29,13 +32,43 @@ func TestConfigCommandsInspectApplicationWithoutEngine(t *testing.T) {
|
||||
}
|
||||
case "sources":
|
||||
var sources []configurationSource
|
||||
if err := json.Unmarshal([]byte(stdout), &sources); err != nil || len(sources) != 1 || sources[0].Layer != "base" {
|
||||
if err := json.Unmarshal([]byte(stdout), &sources); err != nil || len(sources) != 1 || sources[0].Layer != "main" {
|
||||
t.Fatalf("unexpected source records: %q (%v)", stdout, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectionExampleLoadsAndRenders(t *testing.T) {
|
||||
t.Chdir(filepath.Join("..", "..", ".."))
|
||||
want := []appconfig.SourceSelection{
|
||||
{File: "examples/framework/backends.yml"},
|
||||
{File: "examples/profiles/local-fast.yaml"},
|
||||
{File: "examples/prompts/generic.markdown_summary.yaml"},
|
||||
}
|
||||
for _, overlay := range []string{"", "collection"} {
|
||||
result, err := appconfig.Load(appconfig.LoadOptions{Path: "examples/config.collections.yml", Explicit: true, Overlay: overlay})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := append([]appconfig.SourceSelection{}, want...)
|
||||
if overlay != "" {
|
||||
expected = append(expected, appconfig.SourceSelection{File: "examples/profiles/local-gpu.yml"})
|
||||
}
|
||||
if !reflect.DeepEqual(result.Config.PromptKitSources, expected) {
|
||||
t.Fatalf("overlay %q selectors = %+v, want %+v", overlay, result.Config.PromptKitSources, expected)
|
||||
}
|
||||
args := []string{"--config", "examples/config.collections.yml", "--prompt", "generic.markdown_summary", "--input", "transcript=examples/fixtures/transcript.md", "--input", "glossary=examples/fixtures/glossary.yml"}
|
||||
if overlay != "" {
|
||||
args = append(args, "--config-overlay", overlay)
|
||||
}
|
||||
code, stdout, stderr := runCLICommand(t, renderCommand, args)
|
||||
if code != ExitOK || !strings.Contains(stdout, "generic.markdown_summary") || !strings.Contains(stdout, "local-fast") {
|
||||
t.Fatalf("collection render failed: code=%d stdout=%q stderr=%q", code, stdout, stderr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigCommandsExposeComposedSourcesAndResolvedValues(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(dir, "overlays"), 0o755); err != nil {
|
||||
@@ -43,7 +76,7 @@ func TestConfigCommandsExposeComposedSourcesAndResolvedValues(t *testing.T) {
|
||||
}
|
||||
base := filepath.Join(dir, "config.yml")
|
||||
for path, body := range map[string]string{
|
||||
base: "configkit:\n imports:\n - path: fragment.yml\npromptkit_sources:\n - directory: ' ./before/../prompts '\nschema_dir: ./schemas\n",
|
||||
base: "config:\n imports:\n - path: fragment.yml\n required: true\npromptkit_sources:\n - directory: ' ./before/../prompts '\nschema_dir: ./schemas\n",
|
||||
filepath.Join(dir, "fragment.yml"): "server:\n addr: :8081\n",
|
||||
filepath.Join(dir, "overlays", "local.yml"): "promptkit_sources:\n - directory: ./overlay-prompts\nserver:\n addr: :9090\n",
|
||||
} {
|
||||
@@ -64,7 +97,7 @@ func TestConfigCommandsExposeComposedSourcesAndResolvedValues(t *testing.T) {
|
||||
if err := json.Unmarshal([]byte(stdout), &sources); err != nil || len(sources) != 5 {
|
||||
t.Fatalf("unexpected composed source records: %+v (%v)", sources, err)
|
||||
}
|
||||
for i, layer := range []string{"base", "base", "overlay", "cli", "cli"} {
|
||||
for i, layer := range []string{"main", "main", "overlay", "cli", "cli"} {
|
||||
if string(sources[i].Layer) != layer {
|
||||
t.Fatalf("source %d layer = %q, want %q", i, sources[i].Layer, layer)
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
legacyconfigkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/promptkit"
|
||||
appconfig "gitea.maximumdirect.net/eric/scriptorium/internal/config"
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/defaults"
|
||||
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
||||
"go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestParseMappingsSingleAndRepeated(t *testing.T) {
|
||||
@@ -554,6 +555,26 @@ func TestApplicationDiagnosticWriterFailure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigurationErrorsUseTheirNativeDiagnosticWriters(t *testing.T) {
|
||||
application := writeAppConfigFile(t, "unknown_field: value\n")
|
||||
framework := writeFrameworkFile(t, t.TempDir(), "invalid.yml", "not: [valid\n")
|
||||
frameworkConfig := writeAppConfigFile(t, fmt.Sprintf("promptkit_sources:\n - file: %q\n", framework))
|
||||
for _, path := range []string{application, frameworkConfig} {
|
||||
code, stdout, stderr := runCLICommand(t, renderCommand, []string{"--config", path, "--prompt", "sample"})
|
||||
if code != ExitRuntimeError || stdout != "" || !strings.Contains(stderr, "error [") {
|
||||
t.Fatalf("expected native diagnostics: code=%d stdout=%q stderr=%q", code, stdout, stderr)
|
||||
}
|
||||
if code := renderCommand([]string{"--config", path, "--prompt", "sample"}, io.Discard, failingDiagnosticWriter{}); code != ExitRuntimeError {
|
||||
t.Fatalf("diagnostic write failure returned %d", code)
|
||||
}
|
||||
}
|
||||
_, err := newEngine(engineSettings{promptkitSources: []appconfig.SourceSelection{{File: framework}}})
|
||||
var legacyError *legacyconfigkit.LoadError
|
||||
if !errors.As(err, &legacyError) {
|
||||
t.Fatalf("framework load lost legacy diagnostic identity: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRenderArgsWithExplicitConfigLoadsDirectoriesAndFormat(t *testing.T) {
|
||||
configPath := writeAppConfigFile(t, `
|
||||
promptkit_sources:
|
||||
@@ -1092,9 +1113,10 @@ func TestRenderCommandLoadsImportsAndOverlayWithoutChangingExecutionProfile(t *t
|
||||
t.Fatal(err)
|
||||
}
|
||||
base := filepath.Join(lib.rootDir, "config.yml")
|
||||
framework := writeFrameworkSourceFile(t, lib.rootDir, "framework.yml", "configkit:\n imports:\n - path: prompts/prompt.render.yaml\n")
|
||||
for path, body := range map[string]string{
|
||||
base: "configkit:\n imports:\n - path: fragments/sources.yml\n",
|
||||
filepath.Join(lib.rootDir, "fragments", "sources.yml"): sourceSelectionsYAML(lib.promptDir, lib.profileDir, ""),
|
||||
base: "config:\n imports:\n - path: fragments/sources.yml\n required: true\n",
|
||||
filepath.Join(lib.rootDir, "fragments", "sources.yml"): fmt.Sprintf("promptkit_sources:\n - file: %q\n - directory: %q\n", framework, lib.profileDir),
|
||||
filepath.Join(lib.rootDir, "overlays", "local.yml"): "defaults:\n render_format: json\n",
|
||||
} {
|
||||
if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user