Demonstrate requirements discovery in composed example
This commit is contained in:
@@ -121,7 +121,7 @@ func loadPromptEngine(ctx context.Context, selection ckconfig.Selection, input *
|
||||
chosen.PromptVersion: map[string]any{
|
||||
"default_profile": chosen.ProfileID,
|
||||
"inputs": []any{map[string]any{"name": "topic", "required": true, "content_type": "text/plain", "description": "Topic to brief"}},
|
||||
"messages": []any{map[string]any{"role": "user", "content": "Write a concise briefing about {{.topic}}."}},
|
||||
"messages": []any{map[string]any{"role": "user", "content": "Write a concise briefing about {{.topic}}. {{if .mode}}{{input \"notes\"}}{{end}}"}},
|
||||
"output": map[string]any{"format": "text", "validation_mode": "none"},
|
||||
},
|
||||
}},
|
||||
|
||||
@@ -117,6 +117,100 @@ func TestComposedPromptKitAndDomainCommandsRemainAvailable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestComposedRequirementsDiscoveryUsesSelectedCampaign(t *testing.T) {
|
||||
app, err := newApp()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
args []string
|
||||
wantMode bool
|
||||
wantModeIssue bool
|
||||
}{
|
||||
{
|
||||
name: "conditional dependency is unresolved without mode",
|
||||
args: []string{"promptkit", "requirements", "show", "briefing", "--campaign", "spring"},
|
||||
wantModeIssue: true,
|
||||
},
|
||||
{
|
||||
name: "supplied mode discovers conditional notes",
|
||||
args: []string{"promptkit", "requirements", "show", "briefing", "--campaign", "spring", "--var", "mode=full", "--format", "yaml"},
|
||||
wantMode: true,
|
||||
},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var output bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), test.args, commandkit.Streams{Out: &output, Err: io.Discard})
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || outcome.Status != 0 {
|
||||
t.Fatalf("requirements outcome = %#v, report %q", outcome, output.String())
|
||||
}
|
||||
|
||||
var report struct {
|
||||
PromptID string `yaml:"prompt_id"`
|
||||
PromptVersion string `yaml:"prompt_version"`
|
||||
ProfileID string `yaml:"profile_id"`
|
||||
Complete bool `yaml:"complete"`
|
||||
Inputs []struct {
|
||||
Name string `yaml:"name"`
|
||||
Kind string `yaml:"kind"`
|
||||
Declared bool `yaml:"declared"`
|
||||
} `yaml:"inputs"`
|
||||
Variables []struct {
|
||||
Name string `yaml:"name"`
|
||||
Supplied bool `yaml:"supplied"`
|
||||
} `yaml:"variables"`
|
||||
Issues []struct {
|
||||
Code string `yaml:"code"`
|
||||
InputName string `yaml:"input_name"`
|
||||
VariableName string `yaml:"variable_name"`
|
||||
} `yaml:"issues"`
|
||||
}
|
||||
if err := yaml.Unmarshal(output.Bytes(), &report); err != nil {
|
||||
t.Fatalf("decode requirements report %q: %v", output.String(), err)
|
||||
}
|
||||
if report.PromptID != "briefing" || report.PromptVersion != "1" || report.ProfileID != "spring" {
|
||||
t.Fatalf("requirements identity = %#v", report)
|
||||
}
|
||||
|
||||
foundTopic, foundNotes, foundMode := false, false, false
|
||||
for _, input := range report.Inputs {
|
||||
switch input.Name {
|
||||
case "topic":
|
||||
foundTopic = input.Declared && input.Kind == "required"
|
||||
case "notes":
|
||||
foundNotes = true
|
||||
wantKind := "conditional"
|
||||
if test.wantMode {
|
||||
wantKind = "required"
|
||||
}
|
||||
if input.Declared || input.Kind != wantKind {
|
||||
t.Errorf("notes input classification = %#v; want undeclared %s", input, wantKind)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, variable := range report.Variables {
|
||||
if variable.Name == "mode" {
|
||||
foundMode = variable.Supplied == test.wantMode
|
||||
}
|
||||
}
|
||||
if !foundTopic || !foundNotes || !foundMode {
|
||||
t.Fatalf("requirements inventory topic=%t notes=%t mode=%t; report %#v", foundTopic, foundNotes, foundMode, report)
|
||||
}
|
||||
if test.wantModeIssue && (len(report.Issues) != 1 || report.Issues[0].Code != "missing_variable" || report.Issues[0].VariableName != "mode") {
|
||||
t.Fatalf("missing mode issue = %#v", report.Issues)
|
||||
}
|
||||
if !test.wantModeIssue && len(report.Issues) != 0 {
|
||||
t.Fatalf("requirements issues with mode supplied=%t: %#v", test.wantMode, report.Issues)
|
||||
}
|
||||
if report.Complete != test.wantMode {
|
||||
t.Fatalf("requirements completeness = %t with mode supplied=%t; report %#v", report.Complete, test.wantMode, report)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptKitScopeDiffAndCatalogsUseSelectedCampaign(t *testing.T) {
|
||||
app, err := newApp()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user