Avoid inheritance expansion during input presence capture
This commit is contained in:
@@ -128,8 +128,13 @@ introduces separate root/collection handling; the current capture logic is share
|
|||||||
|
|
||||||
### 4. Avoid Expanding Inheritance Provenance For Input-Presence Flags
|
### 4. Avoid Expanding Inheritance Provenance For Input-Presence Flags
|
||||||
|
|
||||||
Status: open for consideration. Priority: P3. Implementation stage: 6.
|
Status: complete. Priority: P3. Implementation stage: 6.
|
||||||
Related to finding 3; consider addressing them together.
|
Related to finding 3.
|
||||||
|
|
||||||
|
Completion: presence capture now uses typed values and `Metadata.IsExplicit`,
|
||||||
|
retaining only required-field flags. Removed the unused three-state metadata
|
||||||
|
records and full-origin queries from this phase. Focused race-enabled default,
|
||||||
|
inherited-input, explicit-presence, normalization, and requirements tests passed.
|
||||||
|
|
||||||
Locations: `internal/configuration/load.go:173–178` and `208–216`.
|
Locations: `internal/configuration/load.go:173–178` and `208–216`.
|
||||||
|
|
||||||
|
|||||||
@@ -25,20 +25,10 @@ type promptMessageConfig = settings.PromptMessageSettings
|
|||||||
type cacheControlConfig = settings.PromptCacheControlSettings
|
type cacheControlConfig = settings.PromptCacheControlSettings
|
||||||
type promptOutputConfig = settings.PromptOutputSettings
|
type promptOutputConfig = settings.PromptOutputSettings
|
||||||
|
|
||||||
// fieldState distinguishes omission, an explicit value, and an explicit null.
|
|
||||||
// Inherited values are explicit because ConfigKit has already expanded them.
|
|
||||||
type fieldState uint8
|
|
||||||
|
|
||||||
const (
|
|
||||||
fieldAbsent fieldState = iota
|
|
||||||
fieldValue
|
|
||||||
fieldNull
|
|
||||||
)
|
|
||||||
|
|
||||||
type loaded struct {
|
type loaded struct {
|
||||||
view configkit.Inspection
|
view configkit.Inspection
|
||||||
diagnostics []configkit.Diagnostic
|
diagnostics []configkit.Diagnostic
|
||||||
promptMetadata map[string][]promptInputPresence
|
promptRequired map[string][]bool
|
||||||
prompts map[string]*promptEntry
|
prompts map[string]*promptEntry
|
||||||
registry *backend.Registry
|
registry *backend.Registry
|
||||||
backendRecords map[string]backendConfig
|
backendRecords map[string]backendConfig
|
||||||
@@ -168,19 +158,18 @@ func Validate(config *settings.Settings, validation *configkit.Validation) {
|
|||||||
// Capture builds owned runtime resources from effective settings and native evidence.
|
// Capture builds owned runtime resources from effective settings and native evidence.
|
||||||
func Capture(input *settings.Settings, view configkit.Inspection, diagnostics []configkit.Diagnostic) (*loaded, error) {
|
func Capture(input *settings.Settings, view configkit.Inspection, diagnostics []configkit.Diagnostic) (*loaded, error) {
|
||||||
config := ownSettings(input)
|
config := ownSettings(input)
|
||||||
state := &loaded{view: view, diagnostics: ownDiagnostics(diagnostics), promptMetadata: make(map[string][]promptInputPresence)}
|
state := &loaded{view: view, diagnostics: ownDiagnostics(diagnostics), promptRequired: make(map[string][]bool)}
|
||||||
metadata := view.Metadata()
|
metadata := view.Metadata()
|
||||||
for _, resources := range resourceSets(&config) {
|
for _, resources := range resourceSets(&config) {
|
||||||
for index, entry := range resources.prompts {
|
for index, entry := range resources.prompts {
|
||||||
presence := make([]promptInputPresence, len(entry.Inputs))
|
presence := make([]bool, len(entry.Inputs))
|
||||||
for i := range entry.Inputs {
|
for i := range entry.Inputs {
|
||||||
path := resources.bases.prompts.Index(index).Key("inputs").Index(i)
|
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"))}
|
// Typed values capture defaults; explicitness preserves source false.
|
||||||
if entry.Inputs[i].Required {
|
// IsExplicit avoids projecting inheritance origins for a flag.
|
||||||
presence[i].required = fieldValue
|
presence[i] = entry.Inputs[i].Required || metadata.IsExplicit(path.Key("required"))
|
||||||
}
|
}
|
||||||
}
|
state.promptRequired[indexedResourceID(resources.namespace, entry.ID)] = presence
|
||||||
state.promptMetadata[indexedResourceID(resources.namespace, entry.ID)] = presence
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := state.materializePrompts(&config, metadata); err != nil {
|
if err := state.materializePrompts(&config, metadata); err != nil {
|
||||||
@@ -208,17 +197,6 @@ func Capture(input *settings.Settings, view configkit.Inspection, diagnostics []
|
|||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func finalFieldState(metadata configkit.Metadata, path configkit.Path) fieldState {
|
|
||||||
info, exists := metadata.Lookup(path)
|
|
||||||
if !exists || !info.Explicit {
|
|
||||||
return fieldAbsent
|
|
||||||
}
|
|
||||||
if info.Null {
|
|
||||||
return fieldNull
|
|
||||||
}
|
|
||||||
return fieldValue
|
|
||||||
}
|
|
||||||
|
|
||||||
func ownDiagnostics(values []configkit.Diagnostic) []configkit.Diagnostic {
|
func ownDiagnostics(values []configkit.Diagnostic) []configkit.Diagnostic {
|
||||||
if values == nil {
|
if values == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -249,12 +227,6 @@ func promptNamespaces(prompts []domain.PromptIdentity) []string {
|
|||||||
return resourceNamespaces(ids)
|
return resourceNamespaces(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
type promptInputPresence struct {
|
|
||||||
required fieldState
|
|
||||||
contentType fieldState
|
|
||||||
description fieldState
|
|
||||||
}
|
|
||||||
|
|
||||||
// eligibleResourceList leaves invalid identities to the existing validation
|
// eligibleResourceList leaves invalid identities to the existing validation
|
||||||
// boundaries, without mutating a list that cannot be recorded by identity.
|
// boundaries, without mutating a list that cannot be recorded by identity.
|
||||||
func eligibleResourceList[T any](entries []T, identity func(T) string) bool {
|
func eligibleResourceList[T any](entries []T, identity func(T) string) bool {
|
||||||
|
|||||||
@@ -78,10 +78,10 @@ func (state *loaded) InspectPrompt(ctx context.Context, id string) (*PromptResou
|
|||||||
result := &PromptResource{ID: id, Hash: entry.hash, DefaultProfile: raw.DefaultProfile, Description: raw.Description, SessionID: raw.SessionID}
|
result := &PromptResource{ID: id, Hash: entry.hash, DefaultProfile: raw.DefaultProfile, Description: raw.Description, SessionID: raw.SessionID}
|
||||||
if raw.Inputs != nil {
|
if raw.Inputs != nil {
|
||||||
inputs := make([]PromptInputResource, len(raw.Inputs))
|
inputs := make([]PromptInputResource, len(raw.Inputs))
|
||||||
presence := state.promptMetadata[id]
|
presence := state.promptRequired[id]
|
||||||
for i, input := range raw.Inputs {
|
for i, input := range raw.Inputs {
|
||||||
inputs[i] = PromptInputResource{Name: input.Name, ContentType: input.ContentType, Description: input.Description}
|
inputs[i] = PromptInputResource{Name: input.Name, ContentType: input.ContentType, Description: input.Description}
|
||||||
if presence[i].required == fieldValue {
|
if presence[i] {
|
||||||
required := input.Required
|
required := input.Required
|
||||||
inputs[i].Required = &required
|
inputs[i].Required = &required
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user