Migrate configuration tests to captured resources
This commit is contained in:
@@ -51,26 +51,18 @@ func TestLoadCapturesInheritedImportedContent(t *testing.T) {
|
||||
if message.Role != "user" || message.CacheControl == nil || message.CacheControl.Type != "ephemeral" || message.CacheControl.TTL != "1h" {
|
||||
t.Fatalf("message metadata was not normalized: %+v", message)
|
||||
}
|
||||
childIndex := -1
|
||||
for index, item := range state.result.Config.Collections["docs"].Prompts {
|
||||
if item.ID == "child" {
|
||||
childIndex = index
|
||||
}
|
||||
}
|
||||
if childIndex < 0 {
|
||||
t.Fatal("inherited prompt missing from effective list")
|
||||
}
|
||||
composed := state.result.Config.Collections["docs"].Prompts[childIndex]
|
||||
childIndex := 1
|
||||
composed := state.prompts["docs/child"].resource
|
||||
if *composed.Description != "description" || *composed.SessionID != "session" || composed.Inputs[0].Name != "document" ||
|
||||
*composed.Inputs[0].ContentType != "text/plain" || *composed.Inputs[0].Description != "document source" {
|
||||
t.Fatalf("resolved metadata was not normalized: %+v", composed)
|
||||
}
|
||||
field, ok := state.result.Metadata().Lookup(configkit.Keys("collections", "docs", "prompts").Index(childIndex).Key("messages").Index(0).Key("content_file"))
|
||||
field, ok := state.inspection.Metadata().Lookup(configkit.Keys("promptkit", "collections", "docs", "prompts").Index(childIndex).Key("messages").Index(0).Key("content_file"))
|
||||
if !ok || len(field.Origin.Locations) != 1 {
|
||||
t.Fatalf("content origin was lost during normalization: %+v", field)
|
||||
}
|
||||
var originPath string
|
||||
for _, source := range state.result.Sources() {
|
||||
for _, source := range state.inspection.Sources() {
|
||||
if source.ID == field.Origin.Locations[0].SourceID {
|
||||
originPath = source.Path
|
||||
}
|
||||
@@ -172,11 +164,8 @@ func TestConfiguredRepairBudgets(t *testing.T) {
|
||||
if err != nil || report.Output.RepairAttempts != tc.want {
|
||||
t.Fatalf("inspection: %+v, %v", report, err)
|
||||
}
|
||||
if got := state.result.Config.Prompts[0].Output.RepairAttempts; got == nil || *got != tc.want {
|
||||
t.Fatalf("effective budget = %v", got)
|
||||
}
|
||||
var effective strings.Builder
|
||||
if err := state.result.WriteEffective(&effective); err != nil || !strings.Contains(effective.String(), fmt.Sprintf("repair_attempts: %d", tc.want)) {
|
||||
if err := state.inspection.WriteEffective(&effective); err != nil || !strings.Contains(effective.String(), fmt.Sprintf("repair_attempts: %d", tc.want)) {
|
||||
t.Fatalf("effective inspection = %q, %v", effective.String(), err)
|
||||
}
|
||||
})
|
||||
@@ -243,7 +232,7 @@ func TestLoadUsesExplicitMappingContextAndClosesContent(t *testing.T) {
|
||||
t.Fatalf("mapping context or handle ownership failed: %+v, opens=%d closes=%d, %v", definition, filesystem.contentOpened, filesystem.contentClosed, err)
|
||||
}
|
||||
_, err = load(mapping("contextless", promptWithFile("body.md")), nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "/prompts/0/messages/0/content_file") {
|
||||
if err == nil || !strings.Contains(err.Error(), "/promptkit/prompts/0/messages/0/content_file") {
|
||||
t.Fatalf("expected semantic path for contextless resource, got %v", err)
|
||||
}
|
||||
}
|
||||
@@ -378,8 +367,12 @@ func TestLoadAcceptsEmptyInlineContentAndRejectsInvalidPromptFields(t *testing.T
|
||||
"id": "example", "messages": []any{map[string]any{"role": "user", "content": "ok"}},
|
||||
"output": map[string]any{"format": "text", "validation_mode": "basic"},
|
||||
}}}), nil)
|
||||
if err != nil || extended.result.Config.Prompts[0].Application["version"] != "v1" {
|
||||
t.Fatalf("application field not retained: %+v, %v", extended, err)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var effective strings.Builder
|
||||
if err := extended.inspection.WriteEffective(&effective); err != nil || !strings.Contains(effective.String(), "version: v1") {
|
||||
t.Fatalf("application field not retained: %q, %v", effective.String(), err)
|
||||
}
|
||||
_, err = load(mapping("null-prompt", map[string]any{"prompts": []any{nil}}), nil)
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user