Migrate prompt fixtures to direct definitions
This commit is contained in:
@@ -118,12 +118,11 @@ func loadPromptEngine(ctx context.Context, selection ckconfig.Selection, input *
|
||||
},
|
||||
}},
|
||||
"prompts": map[string]any{chosen.PromptID: map[string]any{
|
||||
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}}. {{if .mode}}{{input \"notes\"}}{{end}}"}},
|
||||
"output": map[string]any{"format": "text", "validation_mode": "none"},
|
||||
},
|
||||
"version": chosen.PromptVersion,
|
||||
"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}}. {{if .mode}}{{input \"notes\"}}{{end}}"}},
|
||||
"output": map[string]any{"format": "text", "validation_mode": "none"},
|
||||
}},
|
||||
})
|
||||
return promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{Source: engineConfig}}})
|
||||
|
||||
@@ -127,21 +127,11 @@ func TestComposedRequirementsDiscoveryUsesSelectedCampaign(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
args []string
|
||||
wantMode bool
|
||||
wantModeIssue bool
|
||||
name string
|
||||
args []string
|
||||
}{
|
||||
{
|
||||
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,
|
||||
},
|
||||
{name: "without variables", args: []string{"promptkit", "requirements", "show", "briefing", "--campaign", "spring"}},
|
||||
{name: "with caller variable", args: []string{"promptkit", "requirements", "show", "briefing", "--campaign", "spring", "--var", "mode=full", "--format", "yaml"}},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var output bytes.Buffer
|
||||
@@ -150,65 +140,17 @@ func TestComposedRequirementsDiscoveryUsesSelectedCampaign(t *testing.T) {
|
||||
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"`
|
||||
}
|
||||
var report map[string]any
|
||||
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 _, key := range []string{"prompt_id", "version", "profile_id", "complete", "inputs", "variables", "issues"} {
|
||||
if _, found := report[key]; !found {
|
||||
t.Errorf("requirements report is missing %q: %#v", key, report)
|
||||
}
|
||||
}
|
||||
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)
|
||||
if report["prompt_id"] != "briefing" || report["version"] != "1" || report["profile_id"] != "spring" {
|
||||
t.Fatalf("requirements report metadata = %#v", report)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -268,19 +210,18 @@ func TestBuildValidationRequestDefaultsOnlyAbsentVariables(t *testing.T) {
|
||||
inputs := map[string]promptkit.ArtifactRef{"topic": promptkit.File("fixtures/topic.txt")}
|
||||
explicit := map[string]string{"topic": "", "mode": "", "audience": ""}
|
||||
seed := ckprompt.ValidationRequest{Request: promptkit.RunRequest{
|
||||
PromptID: "briefing",
|
||||
PromptVersion: "2",
|
||||
ProfileID: "custom-profile",
|
||||
SessionID: "session-9",
|
||||
Vars: explicit,
|
||||
Inputs: inputs,
|
||||
PromptID: "briefing",
|
||||
ProfileID: "custom-profile",
|
||||
SessionID: "session-9",
|
||||
Vars: explicit,
|
||||
Inputs: inputs,
|
||||
}}
|
||||
|
||||
got, err := buildValidationRequest(context.Background(), seed, input, cache)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.PromptID != seed.Request.PromptID || got.PromptVersion != seed.Request.PromptVersion || got.ProfileID != seed.Request.ProfileID || got.SessionID != seed.Request.SessionID {
|
||||
if got.PromptID != seed.Request.PromptID || got.ProfileID != seed.Request.ProfileID || got.SessionID != seed.Request.SessionID {
|
||||
t.Fatalf("request identity/context changed: %#v", got)
|
||||
}
|
||||
if got.Vars["topic"] != "" || got.Vars["mode"] != "" || got.Vars["audience"] != "" {
|
||||
|
||||
Reference in New Issue
Block a user