Share pipeline module and reference target selection
This commit is contained in:
@@ -58,6 +58,10 @@ names or defaults; decoding and resolution perform their own normalization.
|
|||||||
[LayoutPipeline](../../internal/framework/pipeline/layout.go) interprets the
|
[LayoutPipeline](../../internal/framework/pipeline/layout.go) interprets the
|
||||||
catalog-independent step and lane identities and ordering. It retains empty
|
catalog-independent step and lane identities and ordering. It retains empty
|
||||||
composable steps; complete resolution requires selected steps to contain lanes.
|
composable steps; complete resolution requires selected steps to contain lanes.
|
||||||
|
[SelectPipelineTargets](../../internal/framework/pipeline/selection.go) selects
|
||||||
|
chunk and lane module specifications, artifact kinds, and declared slots before
|
||||||
|
reference values are required. Complete resolution owns binding validation,
|
||||||
|
type/codec checks, capabilities, validators, and digest construction.
|
||||||
Offline known-resource [preflight](../../internal/preflight/preflight.go) is
|
Offline known-resource [preflight](../../internal/preflight/preflight.go) is
|
||||||
a separate composition check, not request execution or module construction.
|
a separate composition check, not request execution or module construction.
|
||||||
|
|
||||||
|
|||||||
@@ -690,6 +690,13 @@ Update config/pipeline phase documentation.
|
|||||||
|
|
||||||
## Stage 24 — Centralize Module And Reference-Slot Selection
|
## Stage 24 — Centralize Module And Reference-Slot Selection
|
||||||
|
|
||||||
|
**Completed.** A shared target inventory selects chunk and lane bindings,
|
||||||
|
artifact-kind variants, and declared slots without requiring reference values or
|
||||||
|
constructing modules. Resolution consumes the selected specs and preserves
|
||||||
|
configured-lane eligibility for reference defaults. Tests cover kind variants,
|
||||||
|
defaults, subsets, missing selections, explicit restrictions, and unselected
|
||||||
|
default targets; pipeline and preflight suites pass. CLI adoption follows next.
|
||||||
|
|
||||||
**Coverage:** CAT-014 selection. **Prerequisites:** Stage 23.
|
**Coverage:** CAT-014 selection. **Prerequisites:** Stage 23.
|
||||||
|
|
||||||
Implement target inventory with existing spec lookups, selecting defaults/kind
|
Implement target inventory with existing spec lookups, selecting defaults/kind
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
type PipelineLayout struct {
|
type PipelineLayout struct {
|
||||||
ID string
|
ID string
|
||||||
ExplicitSteps bool
|
ExplicitSteps bool
|
||||||
|
Profile PipelineProfile
|
||||||
Steps []PipelineLayoutStep
|
Steps []PipelineLayoutStep
|
||||||
ConfiguredLaneIDs []string
|
ConfiguredLaneIDs []string
|
||||||
}
|
}
|
||||||
@@ -41,7 +42,7 @@ func LayoutPipeline(profile PipelineProfile) (PipelineLayout, error) {
|
|||||||
if explicit && len(steps) == 0 {
|
if explicit && len(steps) == 0 {
|
||||||
return PipelineLayout{}, fmt.Errorf("pipeline %q must declare at least one ordered step", id)
|
return PipelineLayout{}, fmt.Errorf("pipeline %q must declare at least one ordered step", id)
|
||||||
}
|
}
|
||||||
layout := PipelineLayout{ID: id, ExplicitSteps: explicit}
|
layout := PipelineLayout{ID: id, ExplicitSteps: explicit, Profile: profile}
|
||||||
seenSteps := make(map[string]struct{}, len(steps))
|
seenSteps := make(map[string]struct{}, len(steps))
|
||||||
seenLanes := make(map[string]string)
|
seenLanes := make(map[string]string)
|
||||||
for index, step := range steps {
|
for index, step := range steps {
|
||||||
|
|||||||
@@ -348,11 +348,7 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return ResolvedPipeline{}, err
|
return ResolvedPipeline{}, err
|
||||||
}
|
}
|
||||||
pipelineID, explicitSteps := layout.ID, layout.ExplicitSteps
|
pipelineID := layout.ID
|
||||||
if explicitSteps && len(options.Only) > 0 {
|
|
||||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q lane selection is not supported for explicit ordered steps", pipelineID)
|
|
||||||
}
|
|
||||||
steps := layout.Steps
|
|
||||||
configuredLaneIDs := layout.ConfiguredLaneIDs
|
configuredLaneIDs := layout.ConfiguredLaneIDs
|
||||||
|
|
||||||
input, err := resolveBinding(profile.Input, "", fmt.Sprintf("pipeline %q input reference slot", pipelineID))
|
input, err := resolveBinding(profile.Input, "", fmt.Sprintf("pipeline %q input reference slot", pipelineID))
|
||||||
@@ -373,33 +369,26 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
|||||||
}
|
}
|
||||||
capabilities.add(inputModuleSpec.Provides...)
|
capabilities.add(inputModuleSpec.Provides...)
|
||||||
|
|
||||||
chunk, err := resolveBinding(profile.Chunk, DefaultChunkModule, fmt.Sprintf("pipeline %q chunk reference slot", pipelineID))
|
targets, err := SelectPipelineTargets(layout, options.Only, catalog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResolvedPipeline{}, err
|
return ResolvedPipeline{}, err
|
||||||
}
|
}
|
||||||
chunkSpec, err := chunkerSpec(catalog, chunk.Module)
|
chunk, err := resolveBinding(targets.Chunk, DefaultChunkModule, fmt.Sprintf("pipeline %q chunk reference slot", pipelineID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResolvedPipeline{}, moduleLookupError(pipelineID, "", StageChunk, chunk.Module, err)
|
return ResolvedPipeline{}, err
|
||||||
}
|
}
|
||||||
|
chunkSpec := targets.ChunkSpec
|
||||||
if missing, ok := capabilities.missing(chunkSpec.Requires); ok {
|
if missing, ok := capabilities.missing(chunkSpec.Requires); ok {
|
||||||
return ResolvedPipeline{}, capabilityError(pipelineID, "", StageChunk, chunk.Module, missing)
|
return ResolvedPipeline{}, capabilityError(pipelineID, "", StageChunk, chunk.Module, missing)
|
||||||
}
|
}
|
||||||
capabilities.add(chunkSpec.Provides...)
|
capabilities.add(chunkSpec.Provides...)
|
||||||
|
|
||||||
if !explicitSteps {
|
var allLanes []PipelineTargetLane
|
||||||
if err := validatePipelineReferenceDefaults(pipelineID, profile.References, chunkSpec, profile.Artifacts, catalog); err != nil {
|
for _, step := range targets.Steps {
|
||||||
return ResolvedPipeline{}, err
|
allLanes = append(allLanes, step.Lanes...)
|
||||||
}
|
}
|
||||||
} else {
|
if err := validatePipelineReferenceDefaults(pipelineID, profile.References, chunkSpec, allLanes); err != nil {
|
||||||
allLanes := make(map[string]ArtifactLaneProfile)
|
return ResolvedPipeline{}, err
|
||||||
for _, step := range layout.Steps {
|
|
||||||
for laneID, lane := range step.Artifacts {
|
|
||||||
allLanes[laneID] = lane
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := validatePipelineReferenceDefaults(pipelineID, profile.References, chunkSpec, allLanes, catalog); err != nil {
|
|
||||||
return ResolvedPipeline{}, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for _, source := range profile.References {
|
for _, source := range profile.References {
|
||||||
if source.Artifact != nil {
|
if source.Artifact != nil {
|
||||||
@@ -439,31 +428,21 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
|||||||
}
|
}
|
||||||
resolved.ValidatorChains = append(resolved.ValidatorChains, chunkValidatorChain)
|
resolved.ValidatorChains = append(resolved.ValidatorChains, chunkValidatorChain)
|
||||||
outputCapabilities := capabilities.clone()
|
outputCapabilities := capabilities.clone()
|
||||||
for _, step := range steps {
|
for _, step := range targets.Steps {
|
||||||
stepID := step.ID
|
stepID := step.ID
|
||||||
laneOptions := ResolveOptions{}
|
|
||||||
if !explicitSteps {
|
|
||||||
laneOptions = options
|
|
||||||
}
|
|
||||||
lanesByID := step.Artifacts
|
|
||||||
selectedLaneIDs, err := selectedLayoutLaneIDs(pipelineID, step, laneOptions)
|
|
||||||
if err != nil {
|
|
||||||
return ResolvedPipeline{}, err
|
|
||||||
}
|
|
||||||
if len(selectedLaneIDs) == 0 {
|
|
||||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q step %q must declare at least one artifact lane", pipelineID, stepID)
|
|
||||||
}
|
|
||||||
if referenceSourceMapsConflict(profile.References, step.References) {
|
if referenceSourceMapsConflict(profile.References, step.References) {
|
||||||
return ResolvedPipeline{}, fmt.Errorf("pipeline %q step %q has a generated and external reference collision", pipelineID, stepID)
|
return ResolvedPipeline{}, fmt.Errorf("pipeline %q step %q has a generated and external reference collision", pipelineID, stepID)
|
||||||
}
|
}
|
||||||
if err := validatePipelineReferenceDefaults(pipelineID, step.References, chunkSpec, lanesByID, catalog); err != nil {
|
if err := validatePipelineReferenceDefaults(pipelineID, step.References, chunkSpec, step.Lanes); err != nil {
|
||||||
return ResolvedPipeline{}, err
|
return ResolvedPipeline{}, err
|
||||||
}
|
}
|
||||||
stepReferences := mergeReferenceMaps(profile.References, step.References)
|
stepReferences := mergeReferenceMaps(profile.References, step.References)
|
||||||
resolvedStep := ResolvedPipelineStep{ID: stepID}
|
resolvedStep := ResolvedPipelineStep{ID: stepID}
|
||||||
for _, laneID := range selectedLaneIDs {
|
for _, selected := range step.Lanes {
|
||||||
laneProfile := lanesByID[laneID]
|
if !selected.Selected {
|
||||||
lane, validatorChains, laneCapabilities, err := resolveArtifactLane(pipelineID, stepID, laneID, laneProfile, stepReferences, options, capabilities, catalog)
|
continue
|
||||||
|
}
|
||||||
|
lane, validatorChains, laneCapabilities, err := resolveArtifactLane(pipelineID, stepID, selected, stepReferences, options, capabilities, catalog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResolvedPipeline{}, err
|
return ResolvedPipeline{}, err
|
||||||
}
|
}
|
||||||
@@ -506,22 +485,22 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
|
|||||||
func resolveArtifactLane(
|
func resolveArtifactLane(
|
||||||
pipelineID string,
|
pipelineID string,
|
||||||
stepID string,
|
stepID string,
|
||||||
laneID string,
|
selected PipelineTargetLane,
|
||||||
profile ArtifactLaneProfile,
|
|
||||||
pipelineReferences map[string]ReferenceSource,
|
pipelineReferences map[string]ReferenceSource,
|
||||||
options ResolveOptions,
|
options ResolveOptions,
|
||||||
inherited capabilitySet,
|
inherited capabilitySet,
|
||||||
catalog ModuleCatalog,
|
catalog ModuleCatalog,
|
||||||
) (ResolvedArtifactLane, []ResolvedValidatorChain, capabilitySet, error) {
|
) (ResolvedArtifactLane, []ResolvedValidatorChain, capabilitySet, error) {
|
||||||
extract, err := resolveBinding(profile.Extract, "", fmt.Sprintf("pipeline %q step %q lane %q extract reference slot", pipelineID, stepID, laneID))
|
laneID, profile := selected.ID, selected.Profile
|
||||||
|
extract, err := resolveBinding(selected.Extract, "", fmt.Sprintf("pipeline %q step %q lane %q extract reference slot", pipelineID, stepID, laneID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResolvedArtifactLane{}, nil, nil, err
|
return ResolvedArtifactLane{}, nil, nil, err
|
||||||
}
|
}
|
||||||
merge, err := resolveBinding(profile.Merge, DefaultMergeModule, fmt.Sprintf("pipeline %q step %q lane %q merge reference slot", pipelineID, stepID, laneID))
|
merge, err := resolveBinding(selected.Merge, DefaultMergeModule, fmt.Sprintf("pipeline %q step %q lane %q merge reference slot", pipelineID, stepID, laneID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResolvedArtifactLane{}, nil, nil, err
|
return ResolvedArtifactLane{}, nil, nil, err
|
||||||
}
|
}
|
||||||
normalize, err := resolveBinding(profile.Normalize, DefaultNormalizeModule, fmt.Sprintf("pipeline %q step %q lane %q normalize reference slot", pipelineID, stepID, laneID))
|
normalize, err := resolveBinding(selected.Normalize, DefaultNormalizeModule, fmt.Sprintf("pipeline %q step %q lane %q normalize reference slot", pipelineID, stepID, laneID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ResolvedArtifactLane{}, nil, nil, err
|
return ResolvedArtifactLane{}, nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -543,10 +522,7 @@ func resolveArtifactLane(
|
|||||||
|
|
||||||
capabilities := inherited.clone()
|
capabilities := inherited.clone()
|
||||||
|
|
||||||
extractSpec, err := extractorSpec(catalog, lane.Extract.Module)
|
extractSpec := selected.ExtractSpec
|
||||||
if err != nil {
|
|
||||||
return ResolvedArtifactLane{}, nil, nil, moduleLookupError(pipelineID, laneID, StageExtract, lane.Extract.Module, err)
|
|
||||||
}
|
|
||||||
if missing, ok := capabilities.missing(extractSpec.Requires); ok {
|
if missing, ok := capabilities.missing(extractSpec.Requires); ok {
|
||||||
return ResolvedArtifactLane{}, nil, nil, capabilityError(pipelineID, laneID, StageExtract, lane.Extract.Module, missing)
|
return ResolvedArtifactLane{}, nil, nil, capabilityError(pipelineID, laneID, StageExtract, lane.Extract.Module, missing)
|
||||||
}
|
}
|
||||||
@@ -578,9 +554,9 @@ func resolveArtifactLane(
|
|||||||
lane.ExtractPrompts = append([]string(nil), extractSpec.Prompts...)
|
lane.ExtractPrompts = append([]string(nil), extractSpec.Prompts...)
|
||||||
capabilities.add(extractSpec.Provides...)
|
capabilities.add(extractSpec.Provides...)
|
||||||
|
|
||||||
mergeSpec, err := mergerSpecForArtifact(catalog, lane.Merge.Module, lane.ArtifactKind, artifactType)
|
mergeSpec := selected.MergeSpec
|
||||||
if err != nil {
|
if selected.mergeType != artifactType {
|
||||||
return ResolvedArtifactLane{}, nil, nil, moduleLookupError(pipelineID, laneID, StageMerge, lane.Merge.Module, err)
|
return ResolvedArtifactLane{}, nil, nil, moduleLookupError(pipelineID, laneID, StageMerge, lane.Merge.Module, fmt.Errorf("artifact kind %q requires Go type %s, but merger %q variant uses %s", lane.ArtifactKind, typeName(artifactType), lane.Merge.Module, typeName(selected.mergeType)))
|
||||||
}
|
}
|
||||||
if missing, ok := capabilities.missing(mergeSpec.Requires); ok {
|
if missing, ok := capabilities.missing(mergeSpec.Requires); ok {
|
||||||
return ResolvedArtifactLane{}, nil, nil, capabilityError(pipelineID, laneID, StageMerge, lane.Merge.Module, missing)
|
return ResolvedArtifactLane{}, nil, nil, capabilityError(pipelineID, laneID, StageMerge, lane.Merge.Module, missing)
|
||||||
@@ -605,9 +581,9 @@ func resolveArtifactLane(
|
|||||||
lane.MergePrompts = append([]string(nil), mergeSpec.Prompts...)
|
lane.MergePrompts = append([]string(nil), mergeSpec.Prompts...)
|
||||||
capabilities.add(mergeSpec.Provides...)
|
capabilities.add(mergeSpec.Provides...)
|
||||||
|
|
||||||
normalizeSpec, err := normalizerSpecForArtifact(catalog, lane.Normalize.Module, lane.ArtifactKind, artifactType)
|
normalizeSpec := selected.NormalizeSpec
|
||||||
if err != nil {
|
if selected.normalizeType != artifactType {
|
||||||
return ResolvedArtifactLane{}, nil, nil, moduleLookupError(pipelineID, laneID, StageNormalize, lane.Normalize.Module, err)
|
return ResolvedArtifactLane{}, nil, nil, moduleLookupError(pipelineID, laneID, StageNormalize, lane.Normalize.Module, fmt.Errorf("artifact kind %q requires Go type %s, but normalizer %q variant uses %s", lane.ArtifactKind, typeName(artifactType), lane.Normalize.Module, typeName(selected.normalizeType)))
|
||||||
}
|
}
|
||||||
if missing, ok := capabilities.missing(normalizeSpec.Requires); ok {
|
if missing, ok := capabilities.missing(normalizeSpec.Requires); ok {
|
||||||
return ResolvedArtifactLane{}, nil, nil, capabilityError(pipelineID, laneID, StageNormalize, lane.Normalize.Module, missing)
|
return ResolvedArtifactLane{}, nil, nil, capabilityError(pipelineID, laneID, StageNormalize, lane.Normalize.Module, missing)
|
||||||
@@ -767,40 +743,6 @@ func resolveArtifactIdentity(pipelineID, laneID string, lane *ResolvedArtifactLa
|
|||||||
return codecType, nil
|
return codecType, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergerSpecForArtifact(catalog ModuleCatalog, key string, kind contracts.ArtifactKind, expectedType reflect.Type) (ModuleSpec, error) {
|
|
||||||
if kind == "" {
|
|
||||||
return ModuleSpec{}, fmt.Errorf("merger %q cannot be resolved without an artifact kind", key)
|
|
||||||
}
|
|
||||||
if catalog.Mergers == nil {
|
|
||||||
return ModuleSpec{}, fmt.Errorf("module %q is not registered", key)
|
|
||||||
}
|
|
||||||
entry, ok := catalog.Mergers.typedEntry(key, kind)
|
|
||||||
if !ok {
|
|
||||||
return ModuleSpec{}, missingArtifactVariantError("merger", key, kind, catalog.Mergers.registeredKinds(key))
|
|
||||||
}
|
|
||||||
if entry.valueType != expectedType {
|
|
||||||
return ModuleSpec{}, fmt.Errorf("artifact kind %q requires Go type %s, but merger %q variant uses %s", kind, typeName(expectedType), key, typeName(entry.valueType))
|
|
||||||
}
|
|
||||||
return cloneModuleSpec(entry.spec), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func normalizerSpecForArtifact(catalog ModuleCatalog, key string, kind contracts.ArtifactKind, expectedType reflect.Type) (ModuleSpec, error) {
|
|
||||||
if kind == "" {
|
|
||||||
return ModuleSpec{}, fmt.Errorf("normalizer %q cannot be resolved without an artifact kind", key)
|
|
||||||
}
|
|
||||||
if catalog.Normalizers == nil {
|
|
||||||
return ModuleSpec{}, fmt.Errorf("module %q is not registered", key)
|
|
||||||
}
|
|
||||||
entry, ok := catalog.Normalizers.typedEntry(key, kind)
|
|
||||||
if !ok {
|
|
||||||
return ModuleSpec{}, missingArtifactVariantError("normalizer", key, kind, catalog.Normalizers.registeredKinds(key))
|
|
||||||
}
|
|
||||||
if entry.valueType != expectedType {
|
|
||||||
return ModuleSpec{}, fmt.Errorf("artifact kind %q requires Go type %s, but normalizer %q variant uses %s", kind, typeName(expectedType), key, typeName(entry.valueType))
|
|
||||||
}
|
|
||||||
return cloneModuleSpec(entry.spec), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validatorSpecForTarget(registry *ValidatorRegistry, stage ModuleStage, key string, kind contracts.ArtifactKind, expectedType reflect.Type) (ValidatorSpec, ValidatorTarget, error) {
|
func validatorSpecForTarget(registry *ValidatorRegistry, stage ModuleStage, key string, kind contracts.ArtifactKind, expectedType reflect.Type) (ValidatorSpec, ValidatorTarget, error) {
|
||||||
key = strings.TrimSpace(key)
|
key = strings.TrimSpace(key)
|
||||||
if stage == StageChunk {
|
if stage == StageChunk {
|
||||||
@@ -974,8 +916,7 @@ func validatePipelineReferenceDefaults(
|
|||||||
pipelineID string,
|
pipelineID string,
|
||||||
pipelineReferences map[string]ReferenceSource,
|
pipelineReferences map[string]ReferenceSource,
|
||||||
chunkSpec ModuleSpec,
|
chunkSpec ModuleSpec,
|
||||||
lanesByID map[string]ArtifactLaneProfile,
|
lanes []PipelineTargetLane,
|
||||||
catalog ModuleCatalog,
|
|
||||||
) error {
|
) error {
|
||||||
normalizedPipelineReferences, err := normalizeReferenceMap(pipelineReferences, fmt.Sprintf("pipeline %q reference slot", pipelineID))
|
normalizedPipelineReferences, err := normalizeReferenceMap(pipelineReferences, fmt.Sprintf("pipeline %q reference slot", pipelineID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -989,46 +930,19 @@ func validatePipelineReferenceDefaults(
|
|||||||
for _, slot := range chunkSpec.ReferenceSlots {
|
for _, slot := range chunkSpec.ReferenceSlots {
|
||||||
declaredByAnyTarget[slot.Name] = struct{}{}
|
declaredByAnyTarget[slot.Name] = struct{}{}
|
||||||
}
|
}
|
||||||
for _, laneID := range sortedArtifactLaneProfileKeys(lanesByID) {
|
for _, lane := range lanes {
|
||||||
laneProfile := lanesByID[laneID]
|
if lane.mergeType != lane.extractType {
|
||||||
extractModule := resolveModuleKey(laneProfile.Extract.Module, "")
|
return moduleLookupError(pipelineID, lane.ID, StageMerge, lane.Merge.Module, fmt.Errorf("artifact kind %q requires Go type %s, but merger %q variant uses %s", lane.ArtifactKind, typeName(lane.extractType), lane.Merge.Module, typeName(lane.mergeType)))
|
||||||
if extractModule == "" {
|
|
||||||
return fmt.Errorf("pipeline %q lane %q extract module must not be empty", pipelineID, laneID)
|
|
||||||
}
|
}
|
||||||
extractSpec, err := extractorSpec(catalog, extractModule)
|
if lane.normalizeType != lane.extractType {
|
||||||
if err != nil {
|
return moduleLookupError(pipelineID, lane.ID, StageNormalize, lane.Normalize.Module, fmt.Errorf("artifact kind %q requires Go type %s, but normalizer %q variant uses %s", lane.ArtifactKind, typeName(lane.extractType), lane.Normalize.Module, typeName(lane.normalizeType)))
|
||||||
return moduleLookupError(pipelineID, laneID, StageExtract, extractModule, err)
|
|
||||||
}
|
}
|
||||||
for _, slot := range extractSpec.ReferenceSlots {
|
for _, spec := range []ModuleSpec{lane.ExtractSpec, lane.MergeSpec, lane.NormalizeSpec} {
|
||||||
declaredByAnyTarget[slot.Name] = struct{}{}
|
for _, slot := range spec.ReferenceSlots {
|
||||||
}
|
declaredByAnyTarget[slot.Name] = struct{}{}
|
||||||
|
|
||||||
mergeModule := resolveModuleKey(laneProfile.Merge.Module, DefaultMergeModule)
|
|
||||||
var artifactType reflect.Type
|
|
||||||
artifactKind := extractSpec.ArtifactKind
|
|
||||||
if artifactKind != "" && catalog.Extractors != nil {
|
|
||||||
if entry, ok := catalog.Extractors.typedEntry(extractModule); ok {
|
|
||||||
artifactType = entry.valueType
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mergeSpec, err := mergerSpecForArtifact(catalog, mergeModule, artifactKind, artifactType)
|
|
||||||
if err != nil {
|
|
||||||
return moduleLookupError(pipelineID, laneID, StageMerge, mergeModule, err)
|
|
||||||
}
|
|
||||||
for _, slot := range mergeSpec.ReferenceSlots {
|
|
||||||
declaredByAnyTarget[slot.Name] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
normalizeModule := resolveModuleKey(laneProfile.Normalize.Module, DefaultNormalizeModule)
|
|
||||||
normalizeSpec, err := normalizerSpecForArtifact(catalog, normalizeModule, artifactKind, artifactType)
|
|
||||||
if err != nil {
|
|
||||||
return moduleLookupError(pipelineID, laneID, StageNormalize, normalizeModule, err)
|
|
||||||
}
|
|
||||||
for _, slot := range normalizeSpec.ReferenceSlots {
|
|
||||||
declaredByAnyTarget[slot.Name] = struct{}{}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, slotName := range sortedStringMapKeys(normalizedPipelineReferences) {
|
for _, slotName := range sortedStringMapKeys(normalizedPipelineReferences) {
|
||||||
if _, ok := declaredByAnyTarget[slotName]; !ok {
|
if _, ok := declaredByAnyTarget[slotName]; !ok {
|
||||||
return fmt.Errorf("pipeline %q reference slot %q is not declared by any eligible reference target", pipelineID, slotName)
|
return fmt.Errorf("pipeline %q reference slot %q is not declared by any eligible reference target", pipelineID, slotName)
|
||||||
@@ -1261,18 +1175,6 @@ func normalizeReferenceMap(values map[string]ReferenceSource, keyName string) (m
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortedArtifactLaneProfileKeys(values map[string]ArtifactLaneProfile) []string {
|
|
||||||
if len(values) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
keys := make([]string, 0, len(values))
|
|
||||||
for key := range values {
|
|
||||||
keys = append(keys, key)
|
|
||||||
}
|
|
||||||
sort.Strings(keys)
|
|
||||||
return keys
|
|
||||||
}
|
|
||||||
|
|
||||||
func sortedStringMapKeys(values map[string]ReferenceSource) []string {
|
func sortedStringMapKeys(values map[string]ReferenceSource) []string {
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
136
internal/framework/pipeline/selection.go
Normal file
136
internal/framework/pipeline/selection.go
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
package pipeline
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PipelineTargets inventories module bindings and declared slots without
|
||||||
|
// requiring reference values, constructing modules, or resolving a pipeline.
|
||||||
|
type PipelineTargets struct {
|
||||||
|
Layout PipelineLayout
|
||||||
|
Chunk ModuleBinding
|
||||||
|
ChunkSpec ModuleSpec
|
||||||
|
Steps []PipelineTargetStep
|
||||||
|
}
|
||||||
|
|
||||||
|
type PipelineTargetStep struct {
|
||||||
|
ID string
|
||||||
|
References map[string]ReferenceSource
|
||||||
|
Lanes []PipelineTargetLane
|
||||||
|
}
|
||||||
|
|
||||||
|
type PipelineTargetLane struct {
|
||||||
|
ID string
|
||||||
|
Profile ArtifactLaneProfile
|
||||||
|
Selected bool
|
||||||
|
Extract ModuleBinding
|
||||||
|
Merge ModuleBinding
|
||||||
|
Normalize ModuleBinding
|
||||||
|
ArtifactKind contracts.ArtifactKind
|
||||||
|
ExtractSpec ModuleSpec
|
||||||
|
MergeSpec ModuleSpec
|
||||||
|
NormalizeSpec ModuleSpec
|
||||||
|
extractType reflect.Type
|
||||||
|
mergeType reflect.Type
|
||||||
|
normalizeType reflect.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
// SelectPipelineTargets selects only requested lanes, except that configured
|
||||||
|
// lanes must also be inspected when their slots can declare reference defaults.
|
||||||
|
func SelectPipelineTargets(layout PipelineLayout, only []string, catalog ModuleCatalog) (PipelineTargets, error) {
|
||||||
|
if layout.ExplicitSteps && len(only) > 0 {
|
||||||
|
return PipelineTargets{}, fmt.Errorf("pipeline %q lane selection is not supported for explicit ordered steps", layout.ID)
|
||||||
|
}
|
||||||
|
chunk := CloneModuleBinding(layout.Profile.Chunk)
|
||||||
|
chunk.Module = resolveModuleKey(chunk.Module, DefaultChunkModule)
|
||||||
|
chunkSpec, err := chunkerSpec(catalog, chunk.Module)
|
||||||
|
if err != nil {
|
||||||
|
return PipelineTargets{}, moduleLookupError(layout.ID, "", StageChunk, chunk.Module, err)
|
||||||
|
}
|
||||||
|
targets := PipelineTargets{Layout: layout, Chunk: chunk, ChunkSpec: chunkSpec}
|
||||||
|
for _, step := range layout.Steps {
|
||||||
|
ids, err := selectedLayoutLaneIDs(layout.ID, step, ResolveOptions{Only: only})
|
||||||
|
if err != nil {
|
||||||
|
return PipelineTargets{}, err
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return PipelineTargets{}, fmt.Errorf("pipeline %q step %q must declare at least one artifact lane", layout.ID, step.ID)
|
||||||
|
}
|
||||||
|
selected := make(map[string]bool, len(ids))
|
||||||
|
for _, id := range ids {
|
||||||
|
selected[id] = true
|
||||||
|
}
|
||||||
|
includeConfigured := len(layout.Profile.References) > 0 || len(step.References) > 0
|
||||||
|
result := PipelineTargetStep{ID: step.ID, References: step.References}
|
||||||
|
for _, id := range step.LaneIDs {
|
||||||
|
if !selected[id] && !includeConfigured {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
lane, err := selectLaneTargets(layout.ID, id, step.Artifacts[id], catalog)
|
||||||
|
if err != nil {
|
||||||
|
return PipelineTargets{}, err
|
||||||
|
}
|
||||||
|
lane.Selected = selected[id]
|
||||||
|
result.Lanes = append(result.Lanes, lane)
|
||||||
|
}
|
||||||
|
targets.Steps = append(targets.Steps, result)
|
||||||
|
}
|
||||||
|
return targets, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func selectLaneTargets(pipelineID, laneID string, profile ArtifactLaneProfile, catalog ModuleCatalog) (PipelineTargetLane, error) {
|
||||||
|
lane := PipelineTargetLane{ID: laneID, Profile: profile, Extract: CloneModuleBinding(profile.Extract), Merge: CloneModuleBinding(profile.Merge), Normalize: CloneModuleBinding(profile.Normalize)}
|
||||||
|
lane.Extract.Module = strings.TrimSpace(lane.Extract.Module)
|
||||||
|
lane.Merge.Module = resolveModuleKey(lane.Merge.Module, DefaultMergeModule)
|
||||||
|
lane.Normalize.Module = resolveModuleKey(lane.Normalize.Module, DefaultNormalizeModule)
|
||||||
|
if lane.Extract.Module == "" {
|
||||||
|
return PipelineTargetLane{}, fmt.Errorf("pipeline %q lane %q extract module must not be empty", pipelineID, laneID)
|
||||||
|
}
|
||||||
|
extract, err := extractorSpec(catalog, lane.Extract.Module)
|
||||||
|
if err != nil {
|
||||||
|
return PipelineTargetLane{}, moduleLookupError(pipelineID, laneID, StageExtract, lane.Extract.Module, err)
|
||||||
|
}
|
||||||
|
if extract.ArtifactKind == "" {
|
||||||
|
return PipelineTargetLane{}, fmt.Errorf("pipeline %q lane %q extract module %q does not declare an artifact kind", pipelineID, laneID, lane.Extract.Module)
|
||||||
|
}
|
||||||
|
merge, mergeType, err := selectMergerVariant(catalog, lane.Merge.Module, extract.ArtifactKind)
|
||||||
|
if err != nil {
|
||||||
|
return PipelineTargetLane{}, moduleLookupError(pipelineID, laneID, StageMerge, lane.Merge.Module, err)
|
||||||
|
}
|
||||||
|
normalize, normalizeType, err := selectNormalizerVariant(catalog, lane.Normalize.Module, extract.ArtifactKind)
|
||||||
|
if err != nil {
|
||||||
|
return PipelineTargetLane{}, moduleLookupError(pipelineID, laneID, StageNormalize, lane.Normalize.Module, err)
|
||||||
|
}
|
||||||
|
lane.ArtifactKind, lane.ExtractSpec, lane.MergeSpec, lane.NormalizeSpec = extract.ArtifactKind, extract, merge, normalize
|
||||||
|
if entry, ok := catalog.Extractors.typedEntry(lane.Extract.Module); ok {
|
||||||
|
lane.extractType = entry.valueType
|
||||||
|
}
|
||||||
|
lane.mergeType, lane.normalizeType = mergeType, normalizeType
|
||||||
|
return lane, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func selectMergerVariant(catalog ModuleCatalog, key string, kind contracts.ArtifactKind) (ModuleSpec, reflect.Type, error) {
|
||||||
|
if catalog.Mergers == nil {
|
||||||
|
return ModuleSpec{}, nil, fmt.Errorf("module %q is not registered", key)
|
||||||
|
}
|
||||||
|
entry, ok := catalog.Mergers.typedEntry(key, kind)
|
||||||
|
if !ok {
|
||||||
|
return ModuleSpec{}, nil, missingArtifactVariantError("merger", key, kind, catalog.Mergers.registeredKinds(key))
|
||||||
|
}
|
||||||
|
return cloneModuleSpec(entry.spec), entry.valueType, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func selectNormalizerVariant(catalog ModuleCatalog, key string, kind contracts.ArtifactKind) (ModuleSpec, reflect.Type, error) {
|
||||||
|
if catalog.Normalizers == nil {
|
||||||
|
return ModuleSpec{}, nil, fmt.Errorf("module %q is not registered", key)
|
||||||
|
}
|
||||||
|
entry, ok := catalog.Normalizers.typedEntry(key, kind)
|
||||||
|
if !ok {
|
||||||
|
return ModuleSpec{}, nil, missingArtifactVariantError("normalizer", key, kind, catalog.Normalizers.registeredKinds(key))
|
||||||
|
}
|
||||||
|
return cloneModuleSpec(entry.spec), entry.valueType, nil
|
||||||
|
}
|
||||||
151
internal/framework/pipeline/selection_test.go
Normal file
151
internal/framework/pipeline/selection_test.go
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
package pipeline
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSelectPipelineTargetsUsesKindVariantsWithoutReferenceValues(t *testing.T) {
|
||||||
|
catalog := typedResolutionCatalog(t, completeTypedCatalogOptions())
|
||||||
|
for _, kind := range []contracts.ArtifactKind{"test/notes", "test/score"} {
|
||||||
|
slot := string(kind)
|
||||||
|
merge := ModuleSpec{Key: "variants/merge", Stage: StageMerge, ExecutionClass: contracts.ExecutionClassDeterministic, ArtifactKind: kind, ReferenceSlots: []contracts.ReferenceSlot{{Name: slot, Required: true}}}
|
||||||
|
normalize := ModuleSpec{Key: "variants/normalize", Stage: StageNormalize, ExecutionClass: contracts.ExecutionClassDeterministic, ArtifactKind: kind, ReferenceSlots: []contracts.ReferenceSlot{{Name: slot}}}
|
||||||
|
if kind == "test/notes" {
|
||||||
|
if err := RegisterMerger(catalog.Mergers, merge, func() (contracts.Merger[codecNotes], error) { return typedTestMerger[codecNotes]{key: merge.Key}, nil }); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := RegisterNormalizer(catalog.Normalizers, normalize, func() (contracts.Normalizer[codecNotes], error) {
|
||||||
|
return typedTestNormalizer[codecNotes]{key: normalize.Key}, nil
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := RegisterMerger(catalog.Mergers, merge, func() (contracts.Merger[codecScore], error) { return typedTestMerger[codecScore]{key: merge.Key}, nil }); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := RegisterNormalizer(catalog.Normalizers, normalize, func() (contracts.Normalizer[codecScore], error) {
|
||||||
|
return typedTestNormalizer[codecScore]{key: normalize.Key}, nil
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
profile := typedResolutionProfile()
|
||||||
|
for id, lane := range profile.Artifacts {
|
||||||
|
lane.Merge = Binding("variants/merge")
|
||||||
|
lane.Normalize = Binding("variants/normalize")
|
||||||
|
profile.Artifacts[id] = lane
|
||||||
|
}
|
||||||
|
layout, err := LayoutPipeline(profile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
catalog.ArtifactCodecs = nil // Inventory does not require codecs or complete binding.
|
||||||
|
targets, err := SelectPipelineTargets(layout, nil, catalog)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(targets.Steps) != 1 || len(targets.Steps[0].Lanes) != 2 {
|
||||||
|
t.Fatalf("targets = %#v", targets)
|
||||||
|
}
|
||||||
|
for _, lane := range targets.Steps[0].Lanes {
|
||||||
|
if !lane.Selected || len(lane.MergeSpec.ReferenceSlots) != 1 || lane.MergeSpec.ReferenceSlots[0].Name != string(lane.ArtifactKind) || lane.NormalizeSpec.ReferenceSlots[0].Name != string(lane.ArtifactKind) {
|
||||||
|
t.Fatalf("kind-specific target = %#v", lane)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSelectPipelineTargetsHonorsSelectionAndDefaults(t *testing.T) {
|
||||||
|
catalog := typedResolutionCatalog(t, completeTypedCatalogOptions())
|
||||||
|
profile := typedResolutionProfile()
|
||||||
|
bad := profile.Artifacts["score"]
|
||||||
|
bad.Extract.Module = "unknown/unselected"
|
||||||
|
profile.Artifacts["score"] = bad
|
||||||
|
layout, err := LayoutPipeline(profile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
targets, err := SelectPipelineTargets(layout, []string{" notes "}, catalog)
|
||||||
|
if err != nil || len(targets.Steps[0].Lanes) != 1 || targets.Steps[0].Lanes[0].ID != "notes" || len(targets.Layout.ConfiguredLaneIDs) != 2 {
|
||||||
|
t.Fatalf("targets = %#v, error = %v", targets, err)
|
||||||
|
}
|
||||||
|
if _, err := SelectPipelineTargets(layout, []string{"score"}, catalog); err == nil || !strings.Contains(err.Error(), "unknown/unselected") {
|
||||||
|
t.Fatalf("selected unknown module error = %v", err)
|
||||||
|
}
|
||||||
|
if _, err := SelectPipelineTargets(layout, []string{"missing"}, catalog); err == nil || !strings.Contains(err.Error(), "not declared") {
|
||||||
|
t.Fatalf("unknown lane error = %v", err)
|
||||||
|
}
|
||||||
|
profile.Steps = []PipelineStepProfile{{ID: "step", Artifacts: profile.Artifacts}}
|
||||||
|
profile.Artifacts = nil
|
||||||
|
layout, err = LayoutPipeline(profile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := SelectPipelineTargets(layout, []string{"notes"}, catalog); err == nil || !strings.Contains(err.Error(), "explicit ordered steps") {
|
||||||
|
t.Fatalf("explicit selection error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSelectPipelineTargetsUsesControlledModuleDefaults(t *testing.T) {
|
||||||
|
catalog := typedResolutionCatalog(t, completeTypedCatalogOptions())
|
||||||
|
if err := catalog.Chunkers.RegisterWithSpec(ModuleSpec{Key: DefaultChunkModule, Stage: StageChunk, ExecutionClass: contracts.ExecutionClassDeterministic}, func() (contracts.Chunker, error) { return &typedTestChunker{key: DefaultChunkModule}, nil }); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := RegisterMerger(catalog.Mergers, ModuleSpec{Key: DefaultMergeModule, Stage: StageMerge, ExecutionClass: contracts.ExecutionClassDeterministic, ArtifactKind: "test/notes"}, func() (contracts.Merger[codecNotes], error) {
|
||||||
|
return typedTestMerger[codecNotes]{key: DefaultMergeModule}, nil
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := RegisterNormalizer(catalog.Normalizers, ModuleSpec{Key: DefaultNormalizeModule, Stage: StageNormalize, ExecutionClass: contracts.ExecutionClassDeterministic, ArtifactKind: "test/notes"}, func() (contracts.Normalizer[codecNotes], error) {
|
||||||
|
return typedTestNormalizer[codecNotes]{key: DefaultNormalizeModule}, nil
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
profile := typedResolutionProfile()
|
||||||
|
profile.Chunk = ModuleBinding{}
|
||||||
|
lane := profile.Artifacts["notes"]
|
||||||
|
lane.Merge, lane.Normalize = ModuleBinding{}, ModuleBinding{}
|
||||||
|
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": lane}
|
||||||
|
layout, err := LayoutPipeline(profile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
targets, err := SelectPipelineTargets(layout, nil, catalog)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
selected := targets.Steps[0].Lanes[0]
|
||||||
|
if targets.Chunk.Module != DefaultChunkModule || selected.Merge.Module != DefaultMergeModule || selected.Normalize.Module != DefaultNormalizeModule {
|
||||||
|
t.Fatalf("defaults = %#v / %#v", targets.Chunk, selected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReferenceDefaultsRemainEligibleThroughUnselectedLane(t *testing.T) {
|
||||||
|
catalog := typedResolutionCatalog(t, completeTypedCatalogOptions())
|
||||||
|
spec := ModuleSpec{Key: "typed/reference-score", Stage: StageExtract, ExecutionClass: contracts.ExecutionClassDeterministic, ArtifactKind: "test/score", ReferenceSlots: []contracts.ReferenceSlot{{Name: "score_context"}}}
|
||||||
|
if err := RegisterExtractor(catalog.Extractors, spec, func() (contracts.Extractor[codecScore], error) {
|
||||||
|
return typedTestExtractor[codecScore]{key: spec.Key}, nil
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
profile := typedResolutionProfile()
|
||||||
|
score := profile.Artifacts["score"]
|
||||||
|
score.Extract.Module = spec.Key
|
||||||
|
profile.Artifacts["score"] = score
|
||||||
|
profile.References = map[string]ReferenceSource{"score_context": {Path: "context.txt"}}
|
||||||
|
layout, err := LayoutPipeline(profile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
targets, err := SelectPipelineTargets(layout, []string{"notes"}, catalog)
|
||||||
|
if err != nil || len(targets.Steps[0].Lanes) != 2 || targets.Steps[0].Lanes[1].Selected {
|
||||||
|
t.Fatalf("targets = %#v, error = %v", targets, err)
|
||||||
|
}
|
||||||
|
resolved, err := ResolvePipeline(profile, ResolveOptions{Only: []string{"notes"}}, catalog)
|
||||||
|
if err != nil || len(resolved.Steps) != 1 || len(resolved.Steps[0].ArtifactLanes) != 1 || resolved.Steps[0].ArtifactLanes[0].ID != "notes" {
|
||||||
|
t.Fatalf("resolved = %#v, error = %v", resolved, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user