Files
scriptorium/internal/adapter/cli/discovery_test.go

83 lines
2.7 KiB
Go
Raw Normal View History

package cli
import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
)
func TestCollectionCheckoutDiscoveryAcrossInvocations(t *testing.T) {
fixture, err := filepath.Abs(filepath.Join("..", "..", "..", "examples", "discovery"))
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
name string
first string
second string
}{
{name: "yml then yaml", first: "support-repo", second: "review-repo"},
{name: "yaml then yml", first: "review-repo", second: "support-repo"},
} {
t.Run(tc.name, func(t *testing.T) {
root := t.TempDir()
framework, err := os.ReadFile(filepath.Join(fixture, "framework.yml"))
if err != nil {
t.Fatal(err)
}
frameworkPath := filepath.Join(root, "framework.yml")
if err := os.WriteFile(frameworkPath, framework, 0o644); err != nil {
t.Fatal(err)
}
collections := filepath.Join(root, "collections")
if err := os.MkdirAll(collections, 0o755); err != nil {
t.Fatal(err)
}
install := func(name string) {
t.Helper()
if err := os.CopyFS(filepath.Join(collections, name), os.DirFS(filepath.Join(fixture, "collections", name))); err != nil {
t.Fatal(err)
}
}
config := writeAppConfigFile(t, fmt.Sprintf("promptkit_sources:\n - file: %q\n", frameworkPath))
input := filepath.Join(root, "transcript.md")
if err := os.WriteFile(input, []byte("synthetic discovery transcript"), 0o644); err != nil {
t.Fatal(err)
}
args := func(name string) []string {
if name == "support-repo" {
return []string{"--config", config, "--prompt", "support/answer", "--profile", "support/fast", "--input", "transcript=" + input}
}
return []string{"--config", config, "--prompt", "review/answer", "--profile", "review/base"}
}
check := func(name string) {
t.Helper()
code, out, stderr := runCLICommand(t, renderCommand, args(name))
if code != ExitOK {
t.Fatalf("render %s: code=%d stderr=%s", name, code, stderr)
}
if name == "support-repo" {
for _, want := range []string{"prompt: support/answer", "selected_profile_id: support/fast", "model: support-example", "max_tokens: 256", "Answer the support request", "synthetic discovery transcript"} {
if !strings.Contains(out, want) {
t.Fatalf("missing %q: %s", want, out)
}
}
} else if !strings.Contains(out, "prompt: review/answer") || !strings.Contains(out, "model: review-example") || !strings.Contains(out, "Review this material") {
t.Fatalf("unexpected review render: %s", out)
}
}
install(tc.first)
check(tc.first)
code, _, _ := runCLICommand(t, renderCommand, args(tc.second))
if code != ExitRuntimeError {
t.Fatal("uninstalled collection unexpectedly selected")
}
install(tc.second)
check(tc.first)
check(tc.second)
})
}
}