Add PromptKit requirements YAML report
This commit is contained in:
@@ -748,3 +748,110 @@ func TestProfileCatalogYAMLPreservesStringValuesAndOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequirementsReportRendersEmptyInventoriesAndFalseValues(t *testing.T) {
|
||||
output, err := encodePromptYAMLBytes(requirementsReportFromInspection(&promptkit.RequirementInspection{}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var report map[string]any
|
||||
if err := yaml.Unmarshal(output, &report); err != nil {
|
||||
t.Fatalf("decode requirements report %q: %v", output, err)
|
||||
}
|
||||
for _, key := range []string{"prompt_id", "prompt_version", "profile_id", "complete", "inputs", "variables", "issues"} {
|
||||
if _, ok := report[key]; !ok {
|
||||
t.Errorf("requirements report is missing %q: %q", key, output)
|
||||
}
|
||||
}
|
||||
if report["complete"] != false {
|
||||
t.Errorf("complete = %#v, want false", report["complete"])
|
||||
}
|
||||
for _, key := range []string{"inputs", "variables", "issues"} {
|
||||
items, ok := report[key].([]any)
|
||||
if !ok || len(items) != 0 {
|
||||
t.Errorf("%s = %#v, want an empty sequence", key, report[key])
|
||||
}
|
||||
}
|
||||
for _, key := range []string{"prompt_id", "prompt_version", "profile_id"} {
|
||||
if report[key] != "" {
|
||||
t.Errorf("%s = %#v, want an explicitly present empty string", key, report[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequirementsReportPreservesNativeFieldsAndMetadata(t *testing.T) {
|
||||
empty := ""
|
||||
contentType := "true"
|
||||
inspection := &promptkit.RequirementInspection{
|
||||
PromptID: "true",
|
||||
PromptVersion: "001",
|
||||
ProfileID: "null",
|
||||
Complete: true,
|
||||
Inputs: []promptkit.InputRequirement{
|
||||
{Name: "true", Kind: promptkit.RequirementKind("123"), Declared: false, Description: &empty},
|
||||
{Name: "001", Kind: promptkit.RequirementKind("future_kind"), Declared: true, ContentType: &contentType, Explanation: "false"},
|
||||
},
|
||||
Variables: []promptkit.VariableRequirement{
|
||||
{Name: "false", Kind: promptkit.RequirementKind("on"), Supplied: false},
|
||||
{Name: "001", Kind: promptkit.RequirementKind("future_kind"), Supplied: true, Explanation: "true"},
|
||||
},
|
||||
Issues: []promptkit.RequirementIssue{{
|
||||
Code: promptkit.RequirementIssueCode("123"),
|
||||
InputName: "",
|
||||
VariableName: "false",
|
||||
Description: "",
|
||||
}},
|
||||
}
|
||||
|
||||
for _, complete := range []bool{true, false} {
|
||||
t.Run(map[bool]string{true: "complete", false: "partial"}[complete], func(t *testing.T) {
|
||||
inspection.Complete = complete
|
||||
output, err := encodePromptYAMLBytes(requirementsReportFromInspection(inspection))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var report map[string]any
|
||||
if err := yaml.Unmarshal(output, &report); err != nil {
|
||||
t.Fatalf("decode requirements report %q: %v", output, err)
|
||||
}
|
||||
if report["complete"] != complete || report["prompt_id"] != "true" || report["prompt_version"] != "001" || report["profile_id"] != "null" {
|
||||
t.Fatalf("selected context or completeness = %#v", report)
|
||||
}
|
||||
|
||||
inputs, ok := report["inputs"].([]any)
|
||||
if !ok || len(inputs) != 2 {
|
||||
t.Fatalf("inputs = %#v", report["inputs"])
|
||||
}
|
||||
firstInput, ok := inputs[0].(map[string]any)
|
||||
if !ok || len(firstInput) != 6 || firstInput["name"] != "true" || firstInput["kind"] != "123" || firstInput["declared"] != false || firstInput["content_type"] != nil || firstInput["description"] != "" || firstInput["explanation"] != "" {
|
||||
t.Fatalf("first input = %#v", inputs[0])
|
||||
}
|
||||
secondInput, ok := inputs[1].(map[string]any)
|
||||
if !ok || len(secondInput) != 6 || secondInput["name"] != "001" || secondInput["kind"] != "future_kind" || secondInput["declared"] != true || secondInput["content_type"] != "true" || secondInput["description"] != nil || secondInput["explanation"] != "false" {
|
||||
t.Fatalf("second input = %#v", inputs[1])
|
||||
}
|
||||
|
||||
variables, ok := report["variables"].([]any)
|
||||
if !ok || len(variables) != 2 {
|
||||
t.Fatalf("variables = %#v", report["variables"])
|
||||
}
|
||||
firstVariable, ok := variables[0].(map[string]any)
|
||||
if !ok || len(firstVariable) != 4 || firstVariable["name"] != "false" || firstVariable["kind"] != "on" || firstVariable["supplied"] != false || firstVariable["explanation"] != "" {
|
||||
t.Fatalf("first variable = %#v", variables[0])
|
||||
}
|
||||
secondVariable, ok := variables[1].(map[string]any)
|
||||
if !ok || len(secondVariable) != 4 || secondVariable["name"] != "001" || secondVariable["kind"] != "future_kind" || secondVariable["supplied"] != true || secondVariable["explanation"] != "true" {
|
||||
t.Fatalf("second variable = %#v", variables[1])
|
||||
}
|
||||
|
||||
issues, ok := report["issues"].([]any)
|
||||
if !ok || len(issues) != 1 {
|
||||
t.Fatalf("issues = %#v", report["issues"])
|
||||
}
|
||||
issue, ok := issues[0].(map[string]any)
|
||||
if !ok || len(issue) != 4 || issue["code"] != "123" || issue["input_name"] != "" || issue["variable_name"] != "false" || issue["description"] != "" {
|
||||
t.Fatalf("issue = %#v", issues[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user