Migrate composed PromptKit consumer

This commit is contained in:
2026-11-06 01:01:13 +00:00
parent 1e3879e880
commit 7f327758d8
5 changed files with 79 additions and 29 deletions

View File

@@ -4,16 +4,17 @@ import (
"bytes"
"context"
"errors"
"fmt"
"io"
"reflect"
"strings"
"testing"
configkit "go.maximumdirect.net/configkit"
promptkit "go.maximumdirect.net/promptkit"
"go.maximumdirect.net/ckconfig"
"go.maximumdirect.net/ckprompt"
commandkit "go.maximumdirect.net/commandkit"
configkit "go.maximumdirect.net/configkit"
promptkit "go.maximumdirect.net/promptkit"
"go.yaml.in/yaml/v4"
)
@@ -105,11 +106,41 @@ func TestComposedPromptKitAndDomainCommandsRemainAvailable(t *testing.T) {
if err != nil {
t.Fatal(err)
}
engine, err := loadPromptEngine(context.Background(), ckconfig.Selection{}, &inspectionInput{Campaign: commandkit.Supplied[string]{Value: "spring", Set: true}}, nil)
if err != nil {
t.Fatal(err)
}
inspection, err := engine.InspectConfiguration()
if err != nil {
t.Fatal(err)
}
var effective bytes.Buffer
if err := inspection.WriteEffective(&effective); err != nil {
t.Fatal(err)
}
var config struct {
Profiles []struct {
ID string `yaml:"id"`
} `yaml:"profiles"`
}
if err := yaml.Unmarshal(effective.Bytes(), &config); err != nil {
t.Fatal(err)
}
index := -1
for i, profile := range config.Profiles {
if profile.ID == "spring" {
index = i
break
}
}
if index < 0 {
t.Fatal("selected profile missing from configuration")
}
commands := [][]string{
{"config", "validate", "--scope", "all", "--campaign", "spring", "--limit=0"},
{"config", "show", "--scope", "promptkit", "--campaign", "spring"},
{"config", "sources", "--scope", "promptkit", "--campaign", "spring"},
{"config", "explain", "--scope", "promptkit", "--path", "/profiles/spring/model", "--campaign", "spring"},
{"config", "explain", "--scope", "promptkit", "--path", fmt.Sprintf("/profiles/%d/model", index), "--campaign", "spring"},
{"promptkit", "show", "prompt", "briefing", "--campaign", "spring", "--format", "yaml"},
{"promptkit", "show", "profile", "spring", "--campaign", "spring"},
{"session", "restore", "session-42", "--campaign", "spring"},
@@ -146,12 +177,15 @@ func TestComposedRequirementsDiscoveryUsesSelectedCampaign(t *testing.T) {
if err := yaml.Unmarshal(output.Bytes(), &report); err != nil {
t.Fatalf("decode requirements report %q: %v", output.String(), err)
}
for _, key := range []string{"prompt_id", "version", "profile_id", "complete", "inputs", "variables", "issues"} {
for _, key := range []string{"prompt_id", "profile_id", "complete", "inputs", "variables", "issues"} {
if _, found := report[key]; !found {
t.Errorf("requirements report is missing %q: %#v", key, report)
}
}
if report["prompt_id"] != "briefing" || report["version"] != "1" || report["profile_id"] != "spring" {
if _, exists := report["version"]; exists {
t.Fatalf("unexpected prompt version: %#v", report)
}
if report["prompt_id"] != "briefing" || report["profile_id"] != "spring" {
t.Fatalf("requirements report metadata = %#v", report)
}
})
@@ -267,9 +301,25 @@ func TestPromptKitScopeDiffAndCatalogsUseSelectedCampaign(t *testing.T) {
if outcome.Kind != commandkit.OutcomeSuccess {
t.Fatalf("PromptKit diff outcome = %#v", outcome)
}
value := composedReportValue(t, output.Bytes(), "changes", "profiles", "spring", "model")
if value == nil || value.Value != "spring-model-after" {
t.Fatalf("PromptKit diff spring model = %#v; report %q", value, output.String())
var diff struct {
Changes struct {
Profiles []struct {
ID string `yaml:"id"`
Model string `yaml:"model"`
} `yaml:"profiles"`
} `yaml:"changes"`
}
if err := yaml.Unmarshal(output.Bytes(), &diff); err != nil {
t.Fatal(err)
}
foundChange := false
for _, profile := range diff.Changes.Profiles {
if profile.ID == "spring" && profile.Model == "spring-model-after" {
foundChange = true
}
}
if !foundChange {
t.Fatalf("PromptKit diff missing spring model: %q", output.String())
}
output.Reset()
@@ -283,7 +333,7 @@ func TestPromptKitScopeDiffAndCatalogsUseSelectedCampaign(t *testing.T) {
}
foundPrompt := false
for _, prompt := range prompts {
if prompt["id"] == "briefing" && prompt["version"] == "1" {
if prompt["id"] == "briefing" && len(prompt) == 1 {
foundPrompt = true
break
}