Share pipeline module and reference target selection

This commit is contained in:
2026-11-26 02:39:10 +00:00
parent 39e578dc60
commit 510a079976
6 changed files with 339 additions and 138 deletions

View File

@@ -58,6 +58,10 @@ names or defaults; decoding and resolution perform their own normalization.
[LayoutPipeline](../../internal/framework/pipeline/layout.go) interprets the
catalog-independent step and lane identities and ordering. It retains empty
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
a separate composition check, not request execution or module construction.

View File

@@ -690,6 +690,13 @@ Update config/pipeline phase documentation.
## 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.
Implement target inventory with existing spec lookups, selecting defaults/kind

View File

@@ -10,6 +10,7 @@ import (
type PipelineLayout struct {
ID string
ExplicitSteps bool
Profile PipelineProfile
Steps []PipelineLayoutStep
ConfiguredLaneIDs []string
}
@@ -41,7 +42,7 @@ func LayoutPipeline(profile PipelineProfile) (PipelineLayout, error) {
if explicit && len(steps) == 0 {
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))
seenLanes := make(map[string]string)
for index, step := range steps {

View File

@@ -348,11 +348,7 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
if err != nil {
return ResolvedPipeline{}, err
}
pipelineID, explicitSteps := layout.ID, layout.ExplicitSteps
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
pipelineID := layout.ID
configuredLaneIDs := layout.ConfiguredLaneIDs
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...)
chunk, err := resolveBinding(profile.Chunk, DefaultChunkModule, fmt.Sprintf("pipeline %q chunk reference slot", pipelineID))
targets, err := SelectPipelineTargets(layout, options.Only, catalog)
if err != nil {
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 {
return ResolvedPipeline{}, moduleLookupError(pipelineID, "", StageChunk, chunk.Module, err)
return ResolvedPipeline{}, err
}
chunkSpec := targets.ChunkSpec
if missing, ok := capabilities.missing(chunkSpec.Requires); ok {
return ResolvedPipeline{}, capabilityError(pipelineID, "", StageChunk, chunk.Module, missing)
}
capabilities.add(chunkSpec.Provides...)
if !explicitSteps {
if err := validatePipelineReferenceDefaults(pipelineID, profile.References, chunkSpec, profile.Artifacts, catalog); err != nil {
return ResolvedPipeline{}, err
}
} else {
allLanes := make(map[string]ArtifactLaneProfile)
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
}
var allLanes []PipelineTargetLane
for _, step := range targets.Steps {
allLanes = append(allLanes, step.Lanes...)
}
if err := validatePipelineReferenceDefaults(pipelineID, profile.References, chunkSpec, allLanes); err != nil {
return ResolvedPipeline{}, err
}
for _, source := range profile.References {
if source.Artifact != nil {
@@ -439,31 +428,21 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
}
resolved.ValidatorChains = append(resolved.ValidatorChains, chunkValidatorChain)
outputCapabilities := capabilities.clone()
for _, step := range steps {
for _, step := range targets.Steps {
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) {
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
}
stepReferences := mergeReferenceMaps(profile.References, step.References)
resolvedStep := ResolvedPipelineStep{ID: stepID}
for _, laneID := range selectedLaneIDs {
laneProfile := lanesByID[laneID]
lane, validatorChains, laneCapabilities, err := resolveArtifactLane(pipelineID, stepID, laneID, laneProfile, stepReferences, options, capabilities, catalog)
for _, selected := range step.Lanes {
if !selected.Selected {
continue
}
lane, validatorChains, laneCapabilities, err := resolveArtifactLane(pipelineID, stepID, selected, stepReferences, options, capabilities, catalog)
if err != nil {
return ResolvedPipeline{}, err
}
@@ -506,22 +485,22 @@ func ResolvePipeline(profile PipelineProfile, options ResolveOptions, catalog Mo
func resolveArtifactLane(
pipelineID string,
stepID string,
laneID string,
profile ArtifactLaneProfile,
selected PipelineTargetLane,
pipelineReferences map[string]ReferenceSource,
options ResolveOptions,
inherited capabilitySet,
catalog ModuleCatalog,
) (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 {
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 {
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 {
return ResolvedArtifactLane{}, nil, nil, err
}
@@ -543,10 +522,7 @@ func resolveArtifactLane(
capabilities := inherited.clone()
extractSpec, err := extractorSpec(catalog, lane.Extract.Module)
if err != nil {
return ResolvedArtifactLane{}, nil, nil, moduleLookupError(pipelineID, laneID, StageExtract, lane.Extract.Module, err)
}
extractSpec := selected.ExtractSpec
if missing, ok := capabilities.missing(extractSpec.Requires); ok {
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...)
capabilities.add(extractSpec.Provides...)
mergeSpec, err := mergerSpecForArtifact(catalog, lane.Merge.Module, lane.ArtifactKind, artifactType)
if err != nil {
return ResolvedArtifactLane{}, nil, nil, moduleLookupError(pipelineID, laneID, StageMerge, lane.Merge.Module, err)
mergeSpec := selected.MergeSpec
if selected.mergeType != artifactType {
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 {
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...)
capabilities.add(mergeSpec.Provides...)
normalizeSpec, err := normalizerSpecForArtifact(catalog, lane.Normalize.Module, lane.ArtifactKind, artifactType)
if err != nil {
return ResolvedArtifactLane{}, nil, nil, moduleLookupError(pipelineID, laneID, StageNormalize, lane.Normalize.Module, err)
normalizeSpec := selected.NormalizeSpec
if selected.normalizeType != artifactType {
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 {
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
}
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) {
key = strings.TrimSpace(key)
if stage == StageChunk {
@@ -974,8 +916,7 @@ func validatePipelineReferenceDefaults(
pipelineID string,
pipelineReferences map[string]ReferenceSource,
chunkSpec ModuleSpec,
lanesByID map[string]ArtifactLaneProfile,
catalog ModuleCatalog,
lanes []PipelineTargetLane,
) error {
normalizedPipelineReferences, err := normalizeReferenceMap(pipelineReferences, fmt.Sprintf("pipeline %q reference slot", pipelineID))
if err != nil {
@@ -989,46 +930,19 @@ func validatePipelineReferenceDefaults(
for _, slot := range chunkSpec.ReferenceSlots {
declaredByAnyTarget[slot.Name] = struct{}{}
}
for _, laneID := range sortedArtifactLaneProfileKeys(lanesByID) {
laneProfile := lanesByID[laneID]
extractModule := resolveModuleKey(laneProfile.Extract.Module, "")
if extractModule == "" {
return fmt.Errorf("pipeline %q lane %q extract module must not be empty", pipelineID, laneID)
for _, lane := range lanes {
if lane.mergeType != lane.extractType {
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)))
}
extractSpec, err := extractorSpec(catalog, extractModule)
if err != nil {
return moduleLookupError(pipelineID, laneID, StageExtract, extractModule, err)
if lane.normalizeType != lane.extractType {
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)))
}
for _, slot := range extractSpec.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
for _, spec := range []ModuleSpec{lane.ExtractSpec, lane.MergeSpec, lane.NormalizeSpec} {
for _, slot := range spec.ReferenceSlots {
declaredByAnyTarget[slot.Name] = struct{}{}
}
}
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) {
if _, ok := declaredByAnyTarget[slotName]; !ok {
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
}
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 {
if len(values) == 0 {
return nil

View 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
}

View 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)
}
}