diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 5cade85..e19831f 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -367,6 +367,11 @@ while still receiving definitions specific to their revisions. ### R11 — Reuse Glossary Selections Before Building Their Views (P3) +**Complete.** Stage resolution shares read-only selected entries and +protection terms before preparing the views. Both use the same ordered +selection key. Preflight and runner tests cover repeated selections, +ordering, glossary-stage exemptions, and stage-specific execution. + **Affected plan:** Stage 11, item 2. **Evidence:** [Spec resolution](../../internal/framework/contracts/contracts.go#L115) diff --git a/internal/framework/contracts/contracts.go b/internal/framework/contracts/contracts.go index c9b3143..9016834 100644 --- a/internal/framework/contracts/contracts.go +++ b/internal/framework/contracts/contracts.go @@ -111,20 +111,47 @@ type ProposalResult struct { Operations []outcomes.Operation `json:"operations,omitempty"` } -// ResolveModuleRunSpecs derives isolated consumer views from resolved settings. +// GlossarySelectionKey identifies read-only glossary data shared by stages. +// The ordered collection lists and active glossary exemptions affect the data. +type GlossarySelectionKey struct { + context, protected string + exempt bool +} + +func GlossarySelection(stage config.Stage) GlossarySelectionKey { + return GlossarySelectionKey{ + context: fmt.Sprintf("%q", stage.Glossaries), + protected: fmt.Sprintf("%q", stage.ProtectedTerms), + exempt: stage.Module == modulecatalog.KeyGlossary, + } +} + +// ResolveModuleRunSpecs derives consumer views from resolved settings. +// Equal glossary selections share read-only entries and protection terms. func ResolveModuleRunSpecs(cfg *config.Config) []ModuleRunSpec { if cfg == nil { return nil } specs := make([]ModuleRunSpec, len(cfg.Pipeline.Stages)) + selections := make(map[GlossarySelectionKey]int) for i, item := range cfg.Pipeline.Stages { + spec := &specs[i] + *spec = ModuleRunSpec{ModuleKey: item.Module, InstanceName: fmt.Sprintf("%s_%d", item.Module, i+1), Index: i, ID: item.ID, Settings: item} + key := GlossarySelection(item) + if prior, ok := selections[key]; ok { + spec.Glossary = specs[prior].Glossary + spec.ProtectedTerms = specs[prior].ProtectedTerms + continue + } selected := glossary.Select(cfg.GlossaryCollections, item.Glossaries) protected := glossary.Select(cfg.GlossaryCollections, item.ProtectedTerms) var excluded []glossary.Entry - if item.Module == modulecatalog.KeyGlossary { + if key.exempt { excluded = selected } - specs[i] = ModuleRunSpec{ModuleKey: item.Module, InstanceName: fmt.Sprintf("%s_%d", item.Module, i+1), Index: i, ID: item.ID, Settings: item, Glossary: selected, ProtectedTerms: glossary.Vocabulary(protected, excluded)} + spec.Glossary = selected + spec.ProtectedTerms = glossary.Vocabulary(protected, excluded) + selections[key] = i } return specs } diff --git a/internal/framework/preflight/preflight.go b/internal/framework/preflight/preflight.go index 92b74eb..abc9a21 100644 --- a/internal/framework/preflight/preflight.go +++ b/internal/framework/preflight/preflight.go @@ -150,21 +150,13 @@ func ProcessingPlan(ctx context.Context, cfg *config.Config, inspectProfile func } } specs := contracts.ResolveModuleRunSpecs(cfg) - type glossarySelection struct { - context, protected string - exempt bool - } - glossaryViews := make(map[glossarySelection]int) + glossaryViews := make(map[contracts.GlossarySelectionKey]int) for i := range specs { if err := ctx.Err(); err != nil { return nil, err } spec := &specs[i] - key := glossarySelection{ - context: fmt.Sprintf("%q", spec.Settings.Glossaries), - protected: fmt.Sprintf("%q", spec.Settings.ProtectedTerms), - exempt: spec.ModuleKey == modulecatalog.KeyGlossary, - } + key := contracts.GlossarySelection(spec.Settings) if prior, ok := glossaryViews[key]; ok { spec.GlossaryVariables = specs[prior].GlossaryVariables spec.GlossaryView = specs[prior].GlossaryView diff --git a/internal/framework/preflight/readiness_test.go b/internal/framework/preflight/readiness_test.go index c005268..99825c6 100644 --- a/internal/framework/preflight/readiness_test.go +++ b/internal/framework/preflight/readiness_test.go @@ -87,7 +87,8 @@ func TestProcessingPlanReusesOnlyMatchingGlossaryViews(t *testing.T) { if err != nil || len(plan) != 4 || !slices.Equal(inspected, []string{profile}) { t.Fatalf("plan=%+v inspections=%v error=%v", plan, inspected, err) } - if plan[0].GlossaryView != plan[1].GlossaryView || plan[0].GlossaryVariables != plan[1].GlossaryVariables || + if &plan[0].Glossary[0] != &plan[1].Glossary[0] || &plan[0].ProtectedTerms[0] != &plan[1].ProtectedTerms[0] || + plan[0].GlossaryView != plan[1].GlossaryView || plan[0].GlossaryVariables != plan[1].GlossaryVariables || plan[0].GlossaryView == plan[2].GlossaryView || plan[0].GlossaryView == plan[3].GlossaryView || plan[2].Glossary[0].ID != "b" || plan[3].GlossaryVariables.ProtectionJSON != "[]" { t.Fatalf("incorrect glossary reuse or exemptions: %+v", plan)