Share application loading in composed example
This commit is contained in:
@@ -294,7 +294,7 @@ func TestComposedPromptKitAndDomainCommandsRemainAvailable(t *testing.T) {
|
||||
{"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", fmt.Sprintf("/profiles/%d/model", index), "--campaign", "spring"},
|
||||
{"config", "explain", "--scope", "promptkit", "--path", fmt.Sprintf("/promptkit/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"},
|
||||
@@ -461,17 +461,19 @@ func TestPromptKitScopeDiffAndCatalogsUseSelectedCampaign(t *testing.T) {
|
||||
}
|
||||
var diff struct {
|
||||
Changes struct {
|
||||
Profiles []struct {
|
||||
ID string `yaml:"id"`
|
||||
Model string `yaml:"model"`
|
||||
} `yaml:"profiles"`
|
||||
PromptKit struct {
|
||||
Profiles []struct {
|
||||
ID string `yaml:"id"`
|
||||
Model string `yaml:"model"`
|
||||
} `yaml:"profiles"`
|
||||
} `yaml:"promptkit"`
|
||||
} `yaml:"changes"`
|
||||
}
|
||||
if err := yaml.Unmarshal(output.Bytes(), &diff); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundChange := false
|
||||
for _, profile := range diff.Changes.Profiles {
|
||||
for _, profile := range diff.Changes.PromptKit.Profiles {
|
||||
if profile.ID == "spring" && profile.Model == "spring-model-after" {
|
||||
foundChange = true
|
||||
}
|
||||
@@ -740,3 +742,64 @@ func composedField(mapping *yaml.Node, name string) *yaml.Node {
|
||||
func ckconfigSelection(path string) ckconfig.Selection {
|
||||
return ckconfig.Selection{Config: commandkit.Supplied[string]{Value: path, Set: true}}
|
||||
}
|
||||
|
||||
func TestComposedStorageScopeAndSharedResult(t *testing.T) {
|
||||
cache := &runCache{}
|
||||
selection := ckconfigSelection("fixtures/before.yml")
|
||||
input := &inspectionInput{Campaign: commandkit.Supplied[string]{Value: "spring", Set: true}}
|
||||
result, err := loadApplicationConfig(context.Background(), selection, input, cache)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
engine, err := loadPromptEngine(context.Background(), selection, input, cache)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(cache.applications) != 1 || cache.applications[0].result != result {
|
||||
t.Fatal("engine did not use the selected application result")
|
||||
}
|
||||
inspection, err := engine.InspectConfiguration()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
appView, ok := result.InspectSubtree(configkit.Keys("promptkit"))
|
||||
if !ok {
|
||||
t.Fatal("missing application inspection")
|
||||
}
|
||||
var appYAML, promptYAML bytes.Buffer
|
||||
if err := appView.WriteEffective(&appYAML); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := inspection.WriteEffective(&promptYAML); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if appYAML.String() != promptYAML.String() {
|
||||
t.Fatal("engine inspection differs from shared application result")
|
||||
}
|
||||
app, err := newApp()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
args []string
|
||||
want string
|
||||
}{
|
||||
{[]string{"config", "show", "--scope=storage", "--config=fixtures/before.yml"}, "./before"},
|
||||
{[]string{"config", "explain", "--scope=storage", "--config=fixtures/before.yml", "--path=/storage/location"}, "/storage/location"},
|
||||
{[]string{"config", "diff", "--scope=storage", "--config=fixtures/before.yml", "--against-config=fixtures/after.yml"}, "./after"},
|
||||
{[]string{"config", "show", "--scope=storage", `--set=/storage/location="custom"`, "--campaign=spring"}, "custom"},
|
||||
{[]string{"config", "show", "--scope=app"}, "promptkit:"},
|
||||
{[]string{"config", "validate", "--scope=all"}, "storage"},
|
||||
} {
|
||||
var output, diagnostics bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), tc.args, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || !strings.Contains(output.String(), tc.want) {
|
||||
t.Errorf("%v: %#v output=%q diagnostics=%q", tc.args, outcome, output.String(), diagnostics.String())
|
||||
}
|
||||
}
|
||||
var diagnostics bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), []string{"config", "show", "--scope=storage", "--config=fixtures/missing.yml"}, commandkit.Streams{Out: io.Discard, Err: &diagnostics})
|
||||
if outcome.Kind != commandkit.OutcomeOperational || !strings.Contains(diagnostics.String(), "missing.yml") {
|
||||
t.Fatalf("failed load: %#v %q", outcome, diagnostics.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user