Share immutable backend defaults during profile capture
This commit is contained in:
@@ -138,7 +138,9 @@ ConfigKit resolves profile inheritance before the handoff. Within a collection,
|
|||||||
`extends: {id: parent}` names a sibling local ID; it is not a cross-collection reference.
|
`extends: {id: parent}` names a sibling local ID; it is not a cross-collection reference.
|
||||||
The configuration adapter validates final effective resource references and
|
The configuration adapter validates final effective resource references and
|
||||||
field values, then captures backend definitions and profile target snapshots
|
field values, then captures backend definitions and profile target snapshots
|
||||||
with backend defaults and outbound-control presence. Null profile endpoint,
|
with backend defaults and outbound-control presence. Profiles without provider
|
||||||
|
overrides share capture-owned immutable backend parameter maps; target lookups
|
||||||
|
still detach mutable values before runtime use. Null profile endpoint,
|
||||||
credential source, and whole provider map permit backend fallback after
|
credential source, and whole provider map permit backend fallback after
|
||||||
composition, subject to the required-credential rule. A profile can remain
|
composition, subject to the required-credential rule. A profile can remain
|
||||||
partial until runtime overrides complete it. Resource inspection selects indexed
|
partial until runtime overrides complete it. Resource inspection selects indexed
|
||||||
|
|||||||
@@ -173,7 +173,13 @@ real-world benchmark is needed to establish that algorithmic change.
|
|||||||
|
|
||||||
### 5. Share Immutable Backend Defaults Across Profiles Without Overrides
|
### 5. Share Immutable Backend Defaults Across Profiles Without Overrides
|
||||||
|
|
||||||
Status: open for consideration. Priority: P3. Implementation stage: 6.
|
Status: complete. Priority: P3. Implementation stage: 6.
|
||||||
|
|
||||||
|
Completion: profile construction now reads capture-owned backend definitions
|
||||||
|
directly and shares immutable provider maps when no overlay is needed. Registry
|
||||||
|
and runtime lookups remain defensive, and overlays still copy before merging.
|
||||||
|
Added lookup/overlay isolation coverage and updated internal documentation.
|
||||||
|
The full `go test -race ./...` suite and `go vet ./...` passed with Go 1.27.4.
|
||||||
|
|
||||||
Locations: `internal/configuration/targets.go:27–29` and `68–78`,
|
Locations: `internal/configuration/targets.go:27–29` and `68–78`,
|
||||||
`internal/backend/registry.go:39–48`, and
|
`internal/backend/registry.go:39–48`, and
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (state *loaded) buildExecutionProfiles(config *settings.Settings) error {
|
|||||||
state.indexedProfiles = make(map[string]domain.ExecutionProfile, len(profileConfigs))
|
state.indexedProfiles = make(map[string]domain.ExecutionProfile, len(profileConfigs))
|
||||||
for _, id := range sortedKeys(profileConfigs) {
|
for _, id := range sortedKeys(profileConfigs) {
|
||||||
config := profileConfigs[id]
|
config := profileConfigs[id]
|
||||||
profile, err := captureExecutionProfile(id, config, state.registry)
|
profile, err := captureExecutionProfile(id, config, definitions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -65,12 +65,14 @@ func captureBackend(id string, config backendConfig) domain.Backend {
|
|||||||
return definition
|
return definition
|
||||||
}
|
}
|
||||||
|
|
||||||
func captureExecutionProfile(id string, config profileConfig, registry *backend.Registry) (domain.ExecutionProfile, error) {
|
func captureExecutionProfile(id string, config profileConfig, backends map[string]domain.Backend) (domain.ExecutionProfile, error) {
|
||||||
target := defaults.ExecutionTargetDefault()
|
target := defaults.ExecutionTargetDefault()
|
||||||
if config.Backend != nil && *config.Backend != "" {
|
if config.Backend != nil && *config.Backend != "" {
|
||||||
selected, err := registry.GetBackend(*config.Backend)
|
// These defaults are capture-owned and immutable. Public and runtime
|
||||||
if err != nil {
|
// lookups still detach mutable values; profile overlays copy before merging.
|
||||||
return domain.ExecutionProfile{}, fmt.Errorf("profile %q backend: %w", id, err)
|
selected, found := backends[*config.Backend]
|
||||||
|
if !found {
|
||||||
|
return domain.ExecutionProfile{}, fmt.Errorf("profile %q backend: %w: %q", id, backend.ErrBackendNotFound, *config.Backend)
|
||||||
}
|
}
|
||||||
target.BackendID = selected.ID
|
target.BackendID = selected.ID
|
||||||
target.Endpoint = selected.Endpoint
|
target.Endpoint = selected.Endpoint
|
||||||
|
|||||||
@@ -64,6 +64,45 @@ func TestOverlayProviderMapOwnsInputsAndReplacesValues(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProfilesWithSharedDefaultsRemainIsolatedAtLookup(t *testing.T) {
|
||||||
|
state, err := load(mapping("shared defaults", map[string]any{
|
||||||
|
"backends": []any{map[string]any{"id": "backend", "endpoint": "https://example.test/v1",
|
||||||
|
"extra_params": map[string]any{"nested": map[string]any{"value": "backend"}}}},
|
||||||
|
"profiles": []any{
|
||||||
|
map[string]any{"id": "first", "backend": "backend"},
|
||||||
|
map[string]any{"id": "second", "backend": "backend"},
|
||||||
|
map[string]any{"id": "overlay", "backend": "backend", "extra_params": map[string]any{"nested": map[string]any{"value": "profile"}}},
|
||||||
|
},
|
||||||
|
}), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
for _, id := range []string{"first", "second", "overlay"} {
|
||||||
|
profile, err := state.GetProfile(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
want := "backend"
|
||||||
|
if id == "overlay" {
|
||||||
|
want = "profile"
|
||||||
|
}
|
||||||
|
if profile.ResolvedTarget.ExtraParams["nested"].(map[string]any)["value"] != want {
|
||||||
|
t.Fatalf("%s defaults changed: %+v", id, profile)
|
||||||
|
}
|
||||||
|
profile.ResolvedTarget.ExtraParams["nested"].(map[string]any)["value"] = "caller mutation"
|
||||||
|
}
|
||||||
|
backend, err := state.GetBackend("backend")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
backend.ExtraParams["nested"].(map[string]any)["value"] = "backend caller mutation"
|
||||||
|
profile, err := state.GetProfile(ctx, "first")
|
||||||
|
if err != nil || profile.ResolvedTarget.ExtraParams["nested"].(map[string]any)["value"] != "backend" {
|
||||||
|
t.Fatalf("lookup mutation changed retained defaults: %+v, %v", profile, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRequestCompletesLoadedPartialProfile(t *testing.T) {
|
func TestRequestCompletesLoadedPartialProfile(t *testing.T) {
|
||||||
state, err := load(mapping("partial profile", map[string]any{
|
state, err := load(mapping("partial profile", map[string]any{
|
||||||
"profiles": []any{map[string]any{"id": "partial"}},
|
"profiles": []any{map[string]any{"id": "partial"}},
|
||||||
|
|||||||
Reference in New Issue
Block a user