Remove internal prompt version metadata
This commit is contained in:
@@ -262,7 +262,7 @@ func BenchmarkInspectionSelection(b *testing.B) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
definition, hash, err := result.GetPromptSnapshot(ctx, "inspection")
|
||||
if err != nil || definition.ID != "inspection" || definition.Version == nil || *definition.Version != "1" || hash == "" ||
|
||||
if err != nil || definition.ID != "inspection" || hash == "" ||
|
||||
len(definition.Inputs) != 1 || definition.Inputs[0].Name != "transcript" || !definition.Inputs[0].Required {
|
||||
b.Fatalf("prompt lookup fixture is invalid: definition=%+v hash=%q err=%v", definition, hash, err)
|
||||
}
|
||||
@@ -272,7 +272,7 @@ func BenchmarkInspectionSelection(b *testing.B) {
|
||||
b.Fatalf("profile lookup fixture is invalid: profile=%+v err=%v", profile, err)
|
||||
}
|
||||
inspection, err := result.GetPromptInspection(ctx, "inspection")
|
||||
if err != nil || inspection.PromptID != "inspection" || inspection.PromptVersion == nil || *inspection.PromptVersion != "1" ||
|
||||
if err != nil || inspection.PromptID != "inspection" ||
|
||||
len(inspection.Inputs) != 1 || inspection.Inputs[0].Name != "transcript" {
|
||||
b.Fatalf("prompt inspection fixture is invalid: inspection=%+v err=%v", inspection, err)
|
||||
}
|
||||
|
||||
@@ -77,9 +77,6 @@ func (state *loaded) ListPrompts(ctx context.Context) ([]domain.PromptIdentity,
|
||||
return nil, err
|
||||
}
|
||||
prompts := append([]domain.PromptIdentity(nil), state.promptIDs...)
|
||||
for index := range prompts {
|
||||
prompts[index].Version = stringPointerValue(prompts[index].Version)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ func TestLoadedListsSortedEffectiveIdentities(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantPrompts := []domain.PromptIdentity{
|
||||
{ID: " z/prompt ", Version: stringPointer("v1")},
|
||||
{ID: "a/prompt", Version: stringPointer("v1")},
|
||||
{ID: "z/prompt", Version: stringPointer("v1")},
|
||||
{ID: " z/prompt "},
|
||||
{ID: "a/prompt"},
|
||||
{ID: "z/prompt"},
|
||||
}
|
||||
if !reflect.DeepEqual(prompts, wantPrompts) {
|
||||
t.Fatalf("prompt identities = %#v, want %#v", prompts, wantPrompts)
|
||||
@@ -84,7 +84,6 @@ func TestLoadedListsAreIndependent(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prompts[0].ID = "changed prompt"
|
||||
*prompts[0].Version = "changed version"
|
||||
|
||||
profiles, err = state.ListProfiles(context.Background())
|
||||
if err != nil {
|
||||
@@ -101,7 +100,7 @@ func TestLoadedListsAreIndependent(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantPrompts := []domain.PromptIdentity{{ID: "example", Version: stringPointer("v1")}}
|
||||
wantPrompts := []domain.PromptIdentity{{ID: "example"}}
|
||||
if !reflect.DeepEqual(prompts, wantPrompts) {
|
||||
t.Fatalf("caller mutation changed prompt inventory: %#v", prompts)
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ func load(main configkit.Input, underlays []configkit.Underlay) (*loaded, error)
|
||||
state.backendIDs = sortedKeys(indexedBackends(&result.Config))
|
||||
state.profileIDs = sortedKeys(state.indexedProfiles)
|
||||
for _, id := range sortedKeys(state.prompts) {
|
||||
state.promptIDs = append(state.promptIDs, domain.PromptIdentity{ID: id, Version: stringPointerValue(state.prompts[id].definition.Version)})
|
||||
state.promptIDs = append(state.promptIDs, domain.PromptIdentity{ID: id})
|
||||
}
|
||||
state.namespaces = map[string][]string{
|
||||
"backend": resourceNamespaces(state.backendIDs),
|
||||
|
||||
@@ -171,8 +171,8 @@ func TestLoadComposesLiteralKeysAndEffectivePresence(t *testing.T) {
|
||||
if !exists || collectionProfile.ID != "base/namespaced" || collectionProfile.ResolvedTarget == nil || collectionProfile.ResolvedTarget.BackendID != "base/local.v1" {
|
||||
t.Fatalf("collection profile snapshot = %+v, exists %t", collectionProfile, exists)
|
||||
}
|
||||
if loaded.result.Config.Collections["invoice"].Prompts["summary"].Messages[0].Content == nil || loaded.result.Config.Collections["invoice"].Prompts["summary"].Version == nil || *loaded.result.Config.Collections["invoice"].Prompts["summary"].Version != "v1.0" {
|
||||
t.Fatal("literal prompt ID and version were not decoded")
|
||||
if loaded.result.Config.Collections["invoice"].Prompts["summary"].Messages[0].Content == nil {
|
||||
t.Fatal("literal prompt content was not decoded")
|
||||
}
|
||||
if loaded.result.Config.Version == nil || *loaded.result.Config.Version != "1" ||
|
||||
loaded.result.Config.Collections["base"].ReleaseVersion == nil || *loaded.result.Config.Collections["base"].ReleaseVersion != "" ||
|
||||
|
||||
@@ -297,7 +297,6 @@ func (state *loaded) lookupPromptEntry(id string) (*promptEntry, error) {
|
||||
}
|
||||
|
||||
func ownPromptDefinition(definition domain.PromptDefinition) *domain.PromptDefinition {
|
||||
definition.Version = stringPointerValue(definition.Version)
|
||||
definition.Inputs = append([]domain.PromptInput(nil), definition.Inputs...)
|
||||
definition.Templates = append([]domain.PromptMessageTemplate(nil), definition.Templates...)
|
||||
for index := range definition.Templates {
|
||||
@@ -310,7 +309,6 @@ func ownPromptDefinition(definition domain.PromptDefinition) *domain.PromptDefin
|
||||
}
|
||||
|
||||
func ownPromptInspection(inspection domain.PromptInspection) *domain.PromptInspection {
|
||||
inspection.PromptVersion = stringPointerValue(inspection.PromptVersion)
|
||||
inspection.Inputs = append([]domain.PromptInput(nil), inspection.Inputs...)
|
||||
return &inspection
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ func TestLoadCapturesNativeContentFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadRejectsMalformedStaticSyntaxAndCapturesOptionalVersion(t *testing.T) {
|
||||
func TestLoadRejectsMalformedStaticSyntax(t *testing.T) {
|
||||
_, err := load(mapping("bad-template", map[string]any{"prompts": map[string]any{"example": map[string]any{
|
||||
"messages": []any{map[string]any{"role": "user", "content": "{{if}}"}},
|
||||
"output": map[string]any{"format": "text", "validation_mode": "basic"},
|
||||
@@ -144,119 +144,6 @@ func TestLoadRejectsMalformedStaticSyntaxAndCapturesOptionalVersion(t *testing.T
|
||||
if err == nil || !strings.Contains(err.Error(), "invalid template syntax") {
|
||||
t.Fatalf("expected construction-time syntax error, got %v", err)
|
||||
}
|
||||
state, err := load(mapping("version metadata", map[string]any{"prompts": map[string]any{"example": map[string]any{
|
||||
"version": "release label",
|
||||
"messages": []any{map[string]any{"role": "user", "content": "one"}},
|
||||
"output": map[string]any{"format": "text", "validation_mode": "basic"},
|
||||
}}}), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
definition, inspection, err := state.prompt("example")
|
||||
if err != nil || definition.Version == nil || *definition.Version != "release label" ||
|
||||
inspection.PromptVersion == nil || *inspection.PromptVersion != "release label" {
|
||||
t.Fatalf("optional version metadata was not retained: definition=%+v inspection=%+v err=%v", definition, inspection, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptVersionLabelPresenceAndOwnership(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
version any
|
||||
include bool
|
||||
wantPresent bool
|
||||
wantValue string
|
||||
}{
|
||||
{name: "absent"},
|
||||
{name: "null", include: true},
|
||||
{name: "empty", version: "", include: true, wantPresent: true},
|
||||
{name: "exact text", version: " Release/v1 ", include: true, wantPresent: true, wantValue: " Release/v1 "},
|
||||
}
|
||||
|
||||
hashes := make(map[string]string, len(tests))
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
definition := map[string]any{
|
||||
"messages": []any{map[string]any{"role": "user", "content": "hello"}},
|
||||
"output": map[string]any{"format": "text", "validation_mode": "basic"},
|
||||
}
|
||||
if test.include {
|
||||
definition["version"] = test.version
|
||||
}
|
||||
state, err := load(mapping("prompt version label", map[string]any{
|
||||
"prompts": map[string]any{"example": definition},
|
||||
}), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
captured, inspection, err := state.prompt("example")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
identities, err := state.ListPrompts(context.Background())
|
||||
if err != nil || len(identities) != 1 {
|
||||
t.Fatalf("list prompt labels: %#v, %v", identities, err)
|
||||
}
|
||||
check := func(name string, value *string) {
|
||||
t.Helper()
|
||||
if !test.wantPresent {
|
||||
if value != nil {
|
||||
t.Errorf("%s label = %q, want absent", name, *value)
|
||||
}
|
||||
return
|
||||
}
|
||||
if value == nil || *value != test.wantValue {
|
||||
t.Errorf("%s label = %v, want %q", name, value, test.wantValue)
|
||||
}
|
||||
}
|
||||
check("definition", captured.Version)
|
||||
check("inspection", inspection.PromptVersion)
|
||||
check("listing", identities[0].Version)
|
||||
if captured.Version != nil && (captured.Version == inspection.PromptVersion || captured.Version == identities[0].Version || inspection.PromptVersion == identities[0].Version) {
|
||||
t.Fatal("returned prompt labels share mutable pointers")
|
||||
}
|
||||
hashes[test.name] = inspection.PromptHash
|
||||
|
||||
if captured.Version != nil {
|
||||
*captured.Version = "mutated definition"
|
||||
}
|
||||
if inspection.PromptVersion != nil {
|
||||
*inspection.PromptVersion = "mutated inspection"
|
||||
}
|
||||
if identities[0].Version != nil {
|
||||
*identities[0].Version = "mutated listing"
|
||||
}
|
||||
again, againInspection, err := state.prompt("example")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check("captured definition after mutation", again.Version)
|
||||
check("captured inspection after mutation", againInspection.PromptVersion)
|
||||
})
|
||||
}
|
||||
if hashes["absent"] == hashes["empty"] {
|
||||
t.Fatal("absent and declared-empty labels produced the same definition hash")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptVersionNullClearsInheritedLabel(t *testing.T) {
|
||||
prompt := map[string]any{
|
||||
"version": "base-label",
|
||||
"messages": []any{map[string]any{"role": "user", "content": "hello"}},
|
||||
"output": map[string]any{"format": "text", "validation_mode": "basic"},
|
||||
}
|
||||
state, err := load(
|
||||
mapping("clear inherited label", map[string]any{"prompts": map[string]any{"example": map[string]any{"version": nil}}}),
|
||||
[]configkit.Underlay{{Inputs: []configkit.Input{mapping("base prompt", map[string]any{"prompts": map[string]any{"example": prompt}})}}},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
definition, inspection, err := state.prompt("example")
|
||||
if err != nil || definition.Version != nil || inspection.PromptVersion != nil {
|
||||
t.Fatalf("null overlay retained inherited label: definition=%+v inspection=%+v err=%v", definition, inspection, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptInspectionLookupMatchesSnapshotSelectionAndOwnsInputs(t *testing.T) {
|
||||
@@ -272,7 +159,6 @@ func TestPromptInspectionLookupMatchesSnapshotSelectionAndOwnsInputs(t *testing.
|
||||
}
|
||||
}
|
||||
selectedPrompt := makePrompt("selected")
|
||||
selectedPrompt["version"] = "v2"
|
||||
state, err := load(mapping("prompt inspection lookup", map[string]any{
|
||||
"profiles": map[string]any{"partial": map[string]any{}},
|
||||
"prompts": map[string]any{
|
||||
@@ -292,8 +178,7 @@ func TestPromptInspectionLookupMatchesSnapshotSelectionAndOwnsInputs(t *testing.
|
||||
if err != nil {
|
||||
t.Fatalf("snapshot prompt ID: %v", err)
|
||||
}
|
||||
if inspection.PromptID != definition.ID || inspection.PromptVersion == nil || definition.Version == nil ||
|
||||
*inspection.PromptVersion != *definition.Version ||
|
||||
if inspection.PromptID != definition.ID ||
|
||||
inspection.PromptHash != hash || inspection.DefaultProfileID != "partial" ||
|
||||
len(inspection.Inputs) != 1 || inspection.Inputs[0].Name != "document" ||
|
||||
inspection.Inputs[0].ContentType != "text/plain" || inspection.Inputs[0].Description != "source document" {
|
||||
|
||||
Reference in New Issue
Block a user