Reuse complete glossary selections across matching stages
This commit is contained in:
@@ -367,6 +367,11 @@ while still receiving definitions specific to their revisions.
|
|||||||
|
|
||||||
### R11 — Reuse Glossary Selections Before Building Their Views (P3)
|
### 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.
|
**Affected plan:** Stage 11, item 2.
|
||||||
|
|
||||||
**Evidence:** [Spec resolution](../../internal/framework/contracts/contracts.go#L115)
|
**Evidence:** [Spec resolution](../../internal/framework/contracts/contracts.go#L115)
|
||||||
|
|||||||
@@ -111,20 +111,47 @@ type ProposalResult struct {
|
|||||||
Operations []outcomes.Operation `json:"operations,omitempty"`
|
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 {
|
func ResolveModuleRunSpecs(cfg *config.Config) []ModuleRunSpec {
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
specs := make([]ModuleRunSpec, len(cfg.Pipeline.Stages))
|
specs := make([]ModuleRunSpec, len(cfg.Pipeline.Stages))
|
||||||
|
selections := make(map[GlossarySelectionKey]int)
|
||||||
for i, item := range cfg.Pipeline.Stages {
|
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)
|
selected := glossary.Select(cfg.GlossaryCollections, item.Glossaries)
|
||||||
protected := glossary.Select(cfg.GlossaryCollections, item.ProtectedTerms)
|
protected := glossary.Select(cfg.GlossaryCollections, item.ProtectedTerms)
|
||||||
var excluded []glossary.Entry
|
var excluded []glossary.Entry
|
||||||
if item.Module == modulecatalog.KeyGlossary {
|
if key.exempt {
|
||||||
excluded = selected
|
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
|
return specs
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,21 +150,13 @@ func ProcessingPlan(ctx context.Context, cfg *config.Config, inspectProfile func
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
specs := contracts.ResolveModuleRunSpecs(cfg)
|
specs := contracts.ResolveModuleRunSpecs(cfg)
|
||||||
type glossarySelection struct {
|
glossaryViews := make(map[contracts.GlossarySelectionKey]int)
|
||||||
context, protected string
|
|
||||||
exempt bool
|
|
||||||
}
|
|
||||||
glossaryViews := make(map[glossarySelection]int)
|
|
||||||
for i := range specs {
|
for i := range specs {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
spec := &specs[i]
|
spec := &specs[i]
|
||||||
key := glossarySelection{
|
key := contracts.GlossarySelection(spec.Settings)
|
||||||
context: fmt.Sprintf("%q", spec.Settings.Glossaries),
|
|
||||||
protected: fmt.Sprintf("%q", spec.Settings.ProtectedTerms),
|
|
||||||
exempt: spec.ModuleKey == modulecatalog.KeyGlossary,
|
|
||||||
}
|
|
||||||
if prior, ok := glossaryViews[key]; ok {
|
if prior, ok := glossaryViews[key]; ok {
|
||||||
spec.GlossaryVariables = specs[prior].GlossaryVariables
|
spec.GlossaryVariables = specs[prior].GlossaryVariables
|
||||||
spec.GlossaryView = specs[prior].GlossaryView
|
spec.GlossaryView = specs[prior].GlossaryView
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ func TestProcessingPlanReusesOnlyMatchingGlossaryViews(t *testing.T) {
|
|||||||
if err != nil || len(plan) != 4 || !slices.Equal(inspected, []string{profile}) {
|
if err != nil || len(plan) != 4 || !slices.Equal(inspected, []string{profile}) {
|
||||||
t.Fatalf("plan=%+v inspections=%v error=%v", plan, inspected, err)
|
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[0].GlossaryView == plan[2].GlossaryView || plan[0].GlossaryView == plan[3].GlossaryView ||
|
||||||
plan[2].Glossary[0].ID != "b" || plan[3].GlossaryVariables.ProtectionJSON != "[]" {
|
plan[2].Glossary[0].ID != "b" || plan[3].GlossaryVariables.ProtectionJSON != "[]" {
|
||||||
t.Fatalf("incorrect glossary reuse or exemptions: %+v", plan)
|
t.Fatalf("incorrect glossary reuse or exemptions: %+v", plan)
|
||||||
|
|||||||
Reference in New Issue
Block a user