diff --git a/application_input_defaults_test.go b/application_input_defaults_test.go new file mode 100644 index 0000000..d860fa7 --- /dev/null +++ b/application_input_defaults_test.go @@ -0,0 +1,90 @@ +package promptkit_test + +import ( + "context" + "errors" + "testing" + + "go.maximumdirect.net/configkit" + "go.maximumdirect.net/promptkit" +) + +func TestApplicationDefaultInputInspection(t *testing.T) { + for _, derived := range []bool{false, true} { + name := "Go defaults" + if derived { + name = "derived collection defaults" + } + t.Run(name, func(t *testing.T) { + settings := promptkit.Settings{ + Profiles: []promptkit.ProfileSettings{{ID: "profile", Endpoint: new("https://example.test/v1"), Model: new("model")}}, + Prompts: []promptkit.PromptSettings{{ID: "prompt", DefaultProfile: new("profile"), + Inputs: []promptkit.PromptInputSettings{{Name: "doc", Required: true, ContentType: new("text/plain"), Description: new("")}}, + Messages: []promptkit.PromptMessageSettings{{Role: new("user"), Content: new("hello")}}, + Output: &promptkit.PromptOutputSettings{Format: new("text"), ValidationMode: new("none")}, + }}, + } + definition := configkit.Definition[handoffApplication]{Defaults: func() handoffApplication { return handoffApplication{PromptKit: settings} }} + source := configkit.NoSource() + id := "prompt" + if derived { + definition.Defaults = nil + source = configkit.Bytes("derived inputs", []byte(`promptkit: + profiles: [{id: profile, endpoint: https://example.test/v1, model: model}] + collections: + team: + prompts: + - id: prompt + default_profile: profile + inputs: [{name: doc}] + messages: [{role: user, content: hello}] + output: {format: text, validation_mode: none} +`)) + id = "team/prompt" + definition.Resolve = func(value *handoffApplication, resolution *configkit.Resolution) error { + input := &value.PromptKit.Collections["team"].Prompts[0].Inputs[0] + input.Required, input.ContentType, input.Description = true, new("text/plain"), new("") + base := configkit.Keys("promptkit", "collections", "team", "prompts").Index(0).Key("inputs").Index(0) + for _, field := range []string{"required", "content_type", "description"} { + resolution.RecordDerivedDefault(base.Key(field), "Application input default", base.Key("name")) + } + return nil + } + } + definition = promptkit.Configure(definition, func(value *handoffApplication) *promptkit.Settings { return &value.PromptKit }) + result, err := configkit.Load(source, configkit.Options[handoffApplication]{Definition: definition}) + if err != nil { + t.Fatal(err) + } + engine, err := promptkit.NewFromConfig(result, promptkit.RuntimeConfig{}) + if err != nil { + t.Fatal(err) + } + ctx := context.Background() + resource, err := engine.InspectPrompt(ctx, id) + if err != nil { + t.Fatal(err) + } + input := (*resource.Inputs)[0] + if input.Required == nil || !*input.Required || input.ContentType == nil || *input.ContentType != "text/plain" || input.Description == nil || *input.Description != "" { + t.Fatalf("resource input = %+v", input) + } + requirements, err := engine.InspectRequirements(ctx, promptkit.RequirementInspectionRequest{PromptID: id}) + if err != nil { + t.Fatal(err) + } + required := requirements.Inputs[0] + if required.Kind != promptkit.RequirementRequired || required.ContentType == nil || *required.ContentType != "text/plain" || required.Description == nil || *required.Description != "" { + t.Fatalf("requirement = %+v", required) + } + request := promptkit.RunRequest{PromptID: id} + if err := engine.ValidateRequest(ctx, request); !errors.Is(err, promptkit.ErrPromptRender) { + t.Fatalf("missing input: %v", err) + } + request.Inputs = map[string]promptkit.ArtifactRef{"doc": promptkit.Inline("document")} + if err := engine.ValidateRequest(ctx, request); err != nil { + t.Fatal(err) + } + }) + } +} diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 79a164c..7cb3133 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -69,7 +69,12 @@ coverage. No change to execution or redaction implementation is needed. ### 3. Preserve Effective Input Metadata Supplied By Application Defaults -Status: open. Priority: P2. Implementation stages: 5–6 and 13. +Status: complete. Priority: P2. Implementation stages: 5–6 and 13. + +Completion: capture reports effective required=true and preserves nullable input +metadata from typed values. Public regressions for Go defaults and recorded +collection defaults failed before the fix and pass afterward, alongside focused +race-enabled presence/normalization tests and offline preflight checks. Locations: `internal/configuration/load.go:208–216`, `internal/configuration/prompts.go:174–180`, and diff --git a/internal/configuration/load.go b/internal/configuration/load.go index cfeb9aa..5b8a612 100644 --- a/internal/configuration/load.go +++ b/internal/configuration/load.go @@ -176,6 +176,9 @@ func Capture(input *settings.Settings, view configkit.Inspection, diagnostics [] for i := range entry.Inputs { path := resources.bases.prompts.Index(index).Key("inputs").Index(i) presence[i] = promptInputPresence{required: finalFieldState(metadata, path.Key("required")), contentType: finalFieldState(metadata, path.Key("content_type")), description: finalFieldState(metadata, path.Key("description"))} + if entry.Inputs[i].Required { + presence[i].required = fieldValue + } } state.promptMetadata[indexedResourceID(resources.namespace, entry.ID)] = presence } diff --git a/internal/configuration/prompts.go b/internal/configuration/prompts.go index 4f98f9d..76ccb76 100644 --- a/internal/configuration/prompts.go +++ b/internal/configuration/prompts.go @@ -171,12 +171,11 @@ func (state *loaded) capturePromptInputs(id string, rawInputs []promptInputConfi inputs = append(inputs, domain.PromptInput{ Name: input.Name, Required: input.Required, ContentType: contentType, Description: description, }) - presence := state.promptMetadata[id][index] item := prompt.InputMetadata{Name: input.Name, Required: input.Required} - if presence.contentType == fieldValue { + if input.ContentType != nil { item.ContentType = stringPointer(contentType) } - if presence.description == fieldValue { + if input.Description != nil { item.Description = stringPointer(description) } metadata = append(metadata, item)