Remove obsolete prompt version reports
This commit is contained in:
@@ -6,13 +6,12 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
promptkit "go.maximumdirect.net/promptkit"
|
||||
"go.maximumdirect.net/ckconfig"
|
||||
commandkit "go.maximumdirect.net/commandkit"
|
||||
promptkit "go.maximumdirect.net/promptkit"
|
||||
"go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
@@ -347,7 +346,7 @@ func TestDiscoveryCommandsForwardFiltersAndRenderCollections(t *testing.T) {
|
||||
ListPrompts: func(_ context.Context, request CatalogRequest, _, _ struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
providers++
|
||||
promptRequest = request
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "team/briefing", Version: testStringPointer("")}}}, nil
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "team/briefing"}}}, nil
|
||||
},
|
||||
ListProfiles: func(_ context.Context, request CatalogRequest, _, _ struct{}) (commandkit.Acquired[[]string], error) {
|
||||
providers++
|
||||
@@ -387,7 +386,7 @@ func TestDiscoveryCommandsForwardFiltersAndRenderCollections(t *testing.T) {
|
||||
t.Fatalf("prompt list outcome/request = (%#v, %#v), output=%q", outcome, promptRequest, output)
|
||||
}
|
||||
var promptRows []map[string]any
|
||||
if err := yaml.Unmarshal([]byte(output), &promptRows); err != nil || len(promptRows) != 1 || promptRows[0]["id"] != "team/briefing" || promptRows[0]["version"] != "" {
|
||||
if err := yaml.Unmarshal([]byte(output), &promptRows); err != nil || len(promptRows) != 1 || promptRows[0]["id"] != "team/briefing" || len(promptRows[0]) != 1 {
|
||||
t.Fatalf("prompt catalog YAML = %#v, error=%v, output=%q", promptRows, err, output)
|
||||
}
|
||||
|
||||
@@ -456,7 +455,7 @@ func TestCatalogListUsesPreparedInputAndPreflightsFormat(t *testing.T) {
|
||||
ListPrompts: func(_ context.Context, request CatalogRequest, value input, gotState state) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
providerCalls++
|
||||
received, receivedSelection, receivedState = value, request.Selection, gotState
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing", Version: testStringPointer("1")}}}, nil
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing"}}}, nil
|
||||
},
|
||||
}
|
||||
app := newPromptTestApp(t, Command(suite))
|
||||
@@ -594,9 +593,9 @@ func TestCatalogNilFactoriesSupplyZeroValues(t *testing.T) {
|
||||
|
||||
func TestCatalogCommandsRenderNativeValuesAndEmptySequences(t *testing.T) {
|
||||
prompts := []promptkit.PromptIdentity{
|
||||
{ID: "later", Version: testStringPointer("1.10")},
|
||||
{ID: "001", Version: testStringPointer(" 03 ")},
|
||||
{ID: "a: true", Version: testStringPointer("yes")},
|
||||
{ID: "later"},
|
||||
{ID: "001"},
|
||||
{ID: "a: true"},
|
||||
{ID: "without-version"},
|
||||
}
|
||||
profiles := []string{"later", "001", "a: true", "later"}
|
||||
@@ -626,13 +625,8 @@ func TestCatalogCommandsRenderNativeValuesAndEmptySequences(t *testing.T) {
|
||||
if !idOK || id != prompts[index].ID {
|
||||
t.Errorf("prompt entry %d = %#v, want ID %q", index, entry, prompts[index].ID)
|
||||
}
|
||||
version, versionExists := entry["version"]
|
||||
if prompts[index].Version == nil {
|
||||
if versionExists || len(entry) != 1 {
|
||||
t.Errorf("prompt entry %d emitted absent version: %#v", index, entry)
|
||||
}
|
||||
} else if !versionExists || version != *prompts[index].Version || len(entry) != 2 {
|
||||
t.Errorf("prompt entry %d version = %#v, want %q", index, version, *prompts[index].Version)
|
||||
if _, exists := entry["version"]; exists || len(entry) != 1 {
|
||||
t.Errorf("prompt entry %d contains unexpected fields: %#v", index, entry)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,7 +721,7 @@ func TestCatalogFailureReportsWarningAndNativeExplanationSeparately(t *testing.T
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
canceled := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
cancel()
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing", Version: testStringPointer("1")}}, Diagnostics: []commandkit.Diagnostic{diagnostic}}, nil
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing"}}, Diagnostics: []commandkit.Diagnostic{diagnostic}}, nil
|
||||
}}))
|
||||
output.Reset()
|
||||
diagnosticOutput.Reset()
|
||||
@@ -747,7 +741,7 @@ func TestCatalogFailureReportsWarningAndNativeExplanationSeparately(t *testing.T
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
writerApp := newPromptTestApp(t, Command(Suite[struct{}, struct{}]{ListPrompts: func(context.Context, CatalogRequest, struct{}, struct{}) (commandkit.Acquired[[]promptkit.PromptIdentity], error) {
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing", Version: testStringPointer("1")}}, Diagnostics: []commandkit.Diagnostic{diagnostic}}, nil
|
||||
return commandkit.Acquired[[]promptkit.PromptIdentity]{Value: []promptkit.PromptIdentity{{ID: "briefing"}}, Diagnostics: []commandkit.Diagnostic{diagnostic}}, nil
|
||||
}}))
|
||||
outcome := writerApp.Execute(context.Background(), []string{"promptkit", "list", "prompts"}, commandkit.Streams{Out: test.writer, Err: io.Discard})
|
||||
if outcome.Kind != commandkit.OutcomeOperational || !errors.Is(outcome.Presentation.Output.WriteError, test.want) || outcome.Presentation.Output.State != commandkit.DeliveryIncomplete {
|
||||
@@ -948,6 +942,9 @@ func TestDefinitionReportsRetainNativeFieldsAndSafeCredentialReferences(t *testi
|
||||
if err := yaml.Unmarshal(output.Bytes(), &prompt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, exists := prompt["version"]; exists {
|
||||
t.Fatalf("prompt version emitted: %#v", prompt)
|
||||
}
|
||||
inputs := prompt["inputs"].([]any)
|
||||
if len(inputs) != 2 || inputs[0].(map[string]any)["name"] != "topic" || inputs[1].(map[string]any)["name"] != "audience" || prompt["prompt_hash"] == "" {
|
||||
t.Fatalf("prompt fields/order = %#v", prompt)
|
||||
@@ -959,7 +956,7 @@ func TestDefinitionReportsRetainNativeFieldsAndSafeCredentialReferences(t *testi
|
||||
|
||||
output.Reset()
|
||||
outcome = app.Execute(context.Background(), []string{"promptkit", "show", "prompt", "briefing"}, commandkit.Streams{Out: &output, Err: io.Discard})
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || loadCalls != 2 || !strings.Contains(output.String(), "Prompt version: \"1\"") || !strings.Contains(output.String(), `- name: "topic"`) {
|
||||
if outcome.Kind != commandkit.OutcomeSuccess || loadCalls != 2 || strings.Contains(output.String(), "Prompt version:") || !strings.Contains(output.String(), `- name: "topic"`) {
|
||||
t.Fatalf("default text prompt report = (%#v, calls=%d, %s)", outcome, loadCalls, output.String())
|
||||
}
|
||||
|
||||
@@ -1002,72 +999,21 @@ func TestDefinitionReportsRetainNativeFieldsAndSafeCredentialReferences(t *testi
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptionalPromptVersionsPreserveAbsenceAndEmptyValues(t *testing.T) {
|
||||
empty := ""
|
||||
label := "release-1"
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
version *string
|
||||
present bool
|
||||
want string
|
||||
}{
|
||||
{name: "absent"},
|
||||
{name: "present empty", version: &empty, present: true, want: ""},
|
||||
{name: "nonempty", version: &label, present: true, want: "release-1"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
prompt := promptReportFromInspection(&promptkit.PromptInspection{PromptID: "briefing", PromptVersion: test.version})
|
||||
promptBytes, err := encodePromptYAMLBytes(prompt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var promptReport map[string]any
|
||||
if err := yaml.Unmarshal(promptBytes, &promptReport); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertOptionalVersion(t, promptReport, test.present, test.want)
|
||||
text := formatPromptText(prompt)
|
||||
if test.present && !strings.Contains(text, "Prompt version: "+strconv.Quote(test.want)+"\n") {
|
||||
t.Errorf("text omitted present version %q: %q", test.want, text)
|
||||
}
|
||||
if !test.present && strings.Contains(text, "Prompt version:") {
|
||||
t.Errorf("text emitted absent version: %q", text)
|
||||
}
|
||||
|
||||
requirementsBytes, err := encodePromptYAMLBytes(requirementsReportFromInspection(&promptkit.RequirementInspection{PromptID: "briefing", PromptVersion: test.version}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var requirementsReport map[string]any
|
||||
if err := yaml.Unmarshal(requirementsBytes, &requirementsReport); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertOptionalVersion(t, requirementsReport, test.present, test.want)
|
||||
|
||||
catalogBytes, err := encodePromptCatalog([]promptkit.PromptIdentity{{ID: "briefing", Version: test.version}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var catalog []map[string]any
|
||||
if err := yaml.Unmarshal(catalogBytes, &catalog); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(catalog) != 1 || catalog[0]["id"] != "briefing" {
|
||||
t.Fatalf("catalog = %#v", catalog)
|
||||
}
|
||||
assertOptionalVersion(t, catalog[0], test.present, test.want)
|
||||
})
|
||||
func TestPromptReportOmitsRemovedVersion(t *testing.T) {
|
||||
report := promptReportFromInspection(&promptkit.PromptInspection{PromptID: "briefing", PromptHash: "hash"})
|
||||
encoded, err := encodePromptYAMLBytes(report)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func assertOptionalVersion(t *testing.T, report map[string]any, present bool, want string) {
|
||||
t.Helper()
|
||||
version, found := report["version"]
|
||||
if found != present {
|
||||
t.Fatalf("version presence = %t in %#v, want %t", found, report, present)
|
||||
var document map[string]any
|
||||
if err := yaml.Unmarshal(encoded, &document); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if present && version != want {
|
||||
t.Errorf("version = %#v, want %q", version, want)
|
||||
if _, exists := document["version"]; exists || document["prompt_id"] != "briefing" || document["prompt_hash"] != "hash" {
|
||||
t.Fatalf("prompt report = %#v", document)
|
||||
}
|
||||
if text := formatPromptText(report); strings.Contains(text, "Prompt version:") || !strings.Contains(text, `Prompt hash: "hash"`) {
|
||||
t.Fatalf("prompt text = %q", text)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1165,9 +1111,9 @@ func TestProfileTextUsesCredentialNamesAndExplicitEmptyExtraParams(t *testing.T)
|
||||
|
||||
func TestPromptCatalogYAMLPreservesSchemaStringsAndOrder(t *testing.T) {
|
||||
want := []promptkit.PromptIdentity{
|
||||
{ID: " briefing ", Version: testStringPointer(" 03 ")},
|
||||
{ID: "001", Version: testStringPointer("1.10")},
|
||||
{ID: " briefing ", Version: testStringPointer(" 03 ")},
|
||||
{ID: " briefing "},
|
||||
{ID: "001"},
|
||||
{ID: " briefing "},
|
||||
}
|
||||
output, err := encodePromptCatalog(want)
|
||||
if err != nil {
|
||||
@@ -1181,13 +1127,12 @@ func TestPromptCatalogYAMLPreservesSchemaStringsAndOrder(t *testing.T) {
|
||||
t.Fatalf("catalog entry count = %d, want %d: %q", len(decoded), len(want), output)
|
||||
}
|
||||
for index, entry := range decoded {
|
||||
if len(entry) != 2 {
|
||||
t.Errorf("entry %d fields = %#v, want only id and version", index, entry)
|
||||
if len(entry) != 1 {
|
||||
t.Errorf("entry %d fields = %#v, want only id", index, entry)
|
||||
}
|
||||
id, idOK := entry["id"].(string)
|
||||
version, versionOK := entry["version"].(string)
|
||||
if !idOK || !versionOK || id != want[index].ID || want[index].Version == nil || version != *want[index].Version {
|
||||
t.Errorf("entry %d = %#v, want id/version %q/%#v", index, entry, want[index].ID, want[index].Version)
|
||||
if !idOK || id != want[index].ID {
|
||||
t.Errorf("entry %d = %#v, want id %q", index, entry, want[index].ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1272,10 +1217,9 @@ func TestRequirementsReportPreservesNativeFieldsAndMetadata(t *testing.T) {
|
||||
empty := ""
|
||||
contentType := "true"
|
||||
inspection := &promptkit.RequirementInspection{
|
||||
PromptID: "true",
|
||||
PromptVersion: testStringPointer("001"),
|
||||
ProfileID: "null",
|
||||
Complete: true,
|
||||
PromptID: "true",
|
||||
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"},
|
||||
@@ -1303,10 +1247,13 @@ func TestRequirementsReportPreservesNativeFieldsAndMetadata(t *testing.T) {
|
||||
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["version"] != "001" || report["profile_id"] != "null" {
|
||||
if report["complete"] != complete || report["prompt_id"] != "true" || report["profile_id"] != "null" {
|
||||
t.Fatalf("selected context or completeness = %#v", report)
|
||||
}
|
||||
|
||||
if _, exists := report["version"]; exists {
|
||||
t.Fatalf("requirements version emitted: %#v", report)
|
||||
}
|
||||
inputs, ok := report["inputs"].([]any)
|
||||
if !ok || len(inputs) != 2 {
|
||||
t.Fatalf("inputs = %#v", report["inputs"])
|
||||
|
||||
Reference in New Issue
Block a user