2026-11-18 19:20:55 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
2026-11-20 05:08:40 +00:00
|
|
|
"encoding/json"
|
2026-11-18 19:20:55 +00:00
|
|
|
"fmt"
|
2026-11-20 05:08:40 +00:00
|
|
|
"go.maximumdirect.net/promptkit"
|
2026-11-18 19:20:55 +00:00
|
|
|
"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)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-20 05:08:40 +00:00
|
|
|
config := filepath.Join(root, "app.yml")
|
|
|
|
|
writeNativeFile(t, config, fmt.Sprintf("promptkit:\n configuration: %q\n", frameworkPath))
|
2026-11-18 19:20:55 +00:00
|
|
|
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" {
|
2026-11-20 05:08:40 +00:00
|
|
|
return []string{"support/answer", "--config", config, "--profile", "support/fast", "--input-file", "transcript=" + input}
|
2026-11-18 19:20:55 +00:00
|
|
|
}
|
2026-11-20 05:08:40 +00:00
|
|
|
return []string{"review/answer", "--config", config, "--profile", "review/base"}
|
2026-11-18 19:20:55 +00:00
|
|
|
}
|
|
|
|
|
check := func(name string) {
|
|
|
|
|
t.Helper()
|
2026-11-20 05:08:40 +00:00
|
|
|
command := append([]string{"promptkit", "show", "prepared"}, args(name)...)
|
|
|
|
|
outcome, out, stderr := executeNative(t, append(command, "--format=json")...)
|
|
|
|
|
if outcome.Status != 0 {
|
|
|
|
|
t.Fatalf("prepare %s: outcome=%+v stderr=%s", name, outcome, stderr)
|
|
|
|
|
}
|
|
|
|
|
var prepared promptkit.PreparedRun
|
|
|
|
|
if err := json.Unmarshal([]byte(out), &prepared); err != nil {
|
|
|
|
|
t.Fatal(err)
|
2026-11-18 19:20:55 +00:00
|
|
|
}
|
|
|
|
|
if name == "support-repo" {
|
2026-11-20 05:08:40 +00:00
|
|
|
for _, want := range []string{"support/answer", "support/fast", "support-example", "Answer the support request", "synthetic discovery transcript"} {
|
2026-11-18 19:20:55 +00:00
|
|
|
if !strings.Contains(out, want) {
|
|
|
|
|
t.Fatalf("missing %q: %s", want, out)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-20 05:08:40 +00:00
|
|
|
if prepared.EffectiveModelParams.MaxTokens != 256 {
|
|
|
|
|
t.Fatalf("inherited profile setting missing: %+v", prepared)
|
|
|
|
|
}
|
|
|
|
|
} else if !strings.Contains(out, "review/answer") || !strings.Contains(out, "review-example") || !strings.Contains(out, "Review this material") {
|
2026-11-18 19:20:55 +00:00
|
|
|
t.Fatalf("unexpected review render: %s", out)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
install(tc.first)
|
|
|
|
|
check(tc.first)
|
2026-11-20 05:08:40 +00:00
|
|
|
outcome, _, _ := executeNative(t, append([]string{"promptkit", "show", "prepared"}, args(tc.second)...)...)
|
|
|
|
|
if outcome.Status != 1 {
|
2026-11-18 19:20:55 +00:00
|
|
|
t.Fatal("uninstalled collection unexpectedly selected")
|
|
|
|
|
}
|
|
|
|
|
install(tc.second)
|
|
|
|
|
check(tc.first)
|
|
|
|
|
check(tc.second)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|