Fix campaign prompt identity resolution
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -803,3 +805,63 @@ func TestComposedStorageScopeAndSharedResult(t *testing.T) {
|
||||
t.Fatalf("failed load: %#v %q", outcome, diagnostics.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestComposedCampaignPromptID(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "campaign.yml")
|
||||
if err := os.WriteFile(path, []byte("campaigns:\n spring:\n prompt_id: custom\n profile_id: spring\n model: spring-model\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
selection := ckconfigSelection(path)
|
||||
cache := &runCache{}
|
||||
input := &inspectionInput{}
|
||||
result, err := loadApplicationConfig(t.Context(), selection, input, cache)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
engine, err := loadPromptEngine(t.Context(), selection, input, cache)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
view, ok := result.InspectSubtree(configkit.Keys("promptkit"))
|
||||
if !ok {
|
||||
t.Fatal("missing application inspection")
|
||||
}
|
||||
inspection, err := engine.InspectConfiguration()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var applicationOutput, engineOutput bytes.Buffer
|
||||
if err := view.WriteEffective(&applicationOutput); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := inspection.WriteEffective(&engineOutput); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
applicationValue, err := commandkit.DecodeYAMLReport(&applicationOutput)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
engineValue, err := commandkit.DecodeYAMLReport(&engineOutput)
|
||||
if err != nil || !reflect.DeepEqual(applicationValue, engineValue) {
|
||||
t.Fatalf("shared inspection mismatch: application=%#v engine=%#v error=%v", applicationValue, engineValue, err)
|
||||
}
|
||||
app, err := newApp()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var output, diagnostics bytes.Buffer
|
||||
outcome := app.Execute(t.Context(), []string{"promptkit", "list", "prompts", "--config=" + path, "--format=json"}, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||
if outcome.Kind != commandkit.OutcomeSuccess {
|
||||
t.Fatalf("catalog failed: %#v, %s", outcome, diagnostics.String())
|
||||
}
|
||||
var prompts []struct{ ID string }
|
||||
if err := json.Unmarshal(output.Bytes(), &prompts); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, prompt := range prompts {
|
||||
if prompt.ID == "custom" {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("catalog lacks selected campaign prompt: %s", output.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user