Cover PromptKit constructor configuration failures
This commit is contained in:
@@ -73,7 +73,11 @@ in Stage 2.
|
|||||||
|
|
||||||
## Stage 2 — Cover real constructor failures through both integrations
|
## Stage 2 — Cover real constructor failures through both integrations
|
||||||
|
|
||||||
Status — pending.
|
Status — completed. The focused independent-module test
|
||||||
|
`GOWORK=off GOTOOLCHAIN=local go test -count=1 -run '^TestPromptConstructorConfigurationOutcomes$' .`
|
||||||
|
passes with PromptKit v0.23.1. It exercises a real malformed companion through
|
||||||
|
catalog and configuration commands, preserving constructor and typed error
|
||||||
|
identity, diagnostic/source evidence, reports, and diff-side context.
|
||||||
|
|
||||||
1. Read the existing test wiring in ckprompt's `command_test.go`,
|
1. Read the existing test wiring in ckprompt's `command_test.go`,
|
||||||
`configuration_outcomes_test.go`, and
|
`configuration_outcomes_test.go`, and
|
||||||
|
|||||||
75
integrations/ckprompt/constructor_outcomes_test.go
Normal file
75
integrations/ckprompt/constructor_outcomes_test.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package ckprompt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"go.maximumdirect.net/ckconfig"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
"go.maximumdirect.net/configkit"
|
||||||
|
"go.maximumdirect.net/promptkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPromptConstructorConfigurationOutcomes(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
mainPath := filepath.Join(dir, "config.yml")
|
||||||
|
companionPath := filepath.Join(dir, "prompts.yml")
|
||||||
|
for path, data := range map[string]string{mainPath: "companion: prompts.yml\n", companionPath: "profiles: [\n"} {
|
||||||
|
if err := os.WriteFile(path, []byte(data), 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
good := adapterEngine(t)
|
||||||
|
var constructorErr error
|
||||||
|
load := func(_ context.Context, selection ckconfig.Selection, _, _ struct{}) (*promptkit.Engine, error) {
|
||||||
|
if selection.Config.Value == "good" {
|
||||||
|
return good, nil
|
||||||
|
}
|
||||||
|
appConfig, err := configkit.Load[struct {
|
||||||
|
Companion string `yaml:"companion"`
|
||||||
|
}](configkit.File(selection.Config.Value))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
companion := filepath.Join(filepath.Dir(selection.Config.Value), appConfig.Config.Companion)
|
||||||
|
engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{Source: configkit.File(companion)}}}, promptkit.WithBundledOpenRouter(false))
|
||||||
|
constructorErr = err
|
||||||
|
return engine, err
|
||||||
|
}
|
||||||
|
app := newPromptTestApp(t, Command(FromEngine[struct{}, struct{}](load)), ckconfig.Command(ckconfig.Suite[struct{}, struct{}]{Scopes: []ckconfig.Scope[struct{}, struct{}]{ConfigScope(load)}}))
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
report, side string
|
||||||
|
}{
|
||||||
|
{"catalog", []string{"promptkit", "list", "prompts", "--config", mainPath}, "", ""},
|
||||||
|
{"show", []string{"config", "show", "--scope=promptkit", "--config", mainPath}, "", ""},
|
||||||
|
{"sources", []string{"config", "sources", "--format=json", "--scope=promptkit", "--config", mainPath}, `"sources"`, ""},
|
||||||
|
{"validate", []string{"config", "validate", "--details", "--format=json", "--scope=promptkit", "--config", mainPath}, `"code": "yaml.invalid"`, ""},
|
||||||
|
{"explain", []string{"config", "explain", "--list", "--scope=promptkit", "--config", mainPath}, "", ""},
|
||||||
|
{"diff left", []string{"config", "diff", "--scope=promptkit", "--config", mainPath, "--against-config=good"}, "", "left"},
|
||||||
|
{"diff right", []string{"config", "diff", "--scope=promptkit", "--config=good", "--against-config", mainPath}, "", "right"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
constructorErr = nil
|
||||||
|
var out, diag bytes.Buffer
|
||||||
|
result := app.Execute(context.Background(), tc.args, commandkit.Streams{Out: &out, Err: &diag})
|
||||||
|
var actual, expected *configkit.LoadError
|
||||||
|
if constructorErr == nil || !errors.As(constructorErr, &expected) || !errors.As(result.Cause, &actual) || actual != expected || !errors.Is(result.Cause, constructorErr) || !errors.Is(result.Cause, promptkit.ErrInvalidConfig) || result.Kind != commandkit.OutcomeUsage || result.Status != 2 {
|
||||||
|
t.Fatalf("outcome=%#v constructor=%v diagnostic=%q", result, constructorErr, diag.String())
|
||||||
|
}
|
||||||
|
if !strings.Contains(diag.String(), "yaml.invalid") || !strings.Contains(diag.String(), "prompts.yml") || (tc.report != "" && !strings.Contains(out.String(), tc.report)) || (tc.side != "" && !strings.Contains(diag.String(), "("+tc.side+")")) {
|
||||||
|
t.Fatalf("output=%q diagnostics=%q", out.String(), diag.String())
|
||||||
|
}
|
||||||
|
if tc.name == "sources" && !strings.Contains(out.String(), "prompts.yml") {
|
||||||
|
t.Fatalf("source evidence missing companion: %q", out.String())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user