Use structured keys for generated artifact producers
This commit is contained in:
@@ -702,14 +702,14 @@ func configuredValidatorsError(pipelineID string, laneID string) error {
|
||||
|
||||
func validateGeneratedBindings(pipelineID string, resolved ResolvedPipeline, catalog ModuleCatalog) error {
|
||||
stepIndex := make(map[string]int, len(resolved.Steps))
|
||||
laneIndex := make(map[string]ResolvedArtifactLane)
|
||||
laneIndex := make(map[generatedOutputKey]ResolvedArtifactLane)
|
||||
for index, step := range resolved.Steps {
|
||||
if _, exists := stepIndex[step.ID]; exists {
|
||||
return fmt.Errorf("pipeline %q step id %q is ambiguous", pipelineID, step.ID)
|
||||
}
|
||||
stepIndex[step.ID] = index
|
||||
for _, lane := range step.ArtifactLanes {
|
||||
laneIndex[step.ID+"\x00"+lane.ID] = lane
|
||||
laneIndex[generatedOutputKeyFor(step.ID, lane.ID)] = lane
|
||||
}
|
||||
}
|
||||
for consumerIndex, step := range resolved.Steps {
|
||||
@@ -734,7 +734,7 @@ func validateGeneratedBindings(pipelineID string, resolved ResolvedPipeline, cat
|
||||
if producerStep >= consumerIndex {
|
||||
return fmt.Errorf("pipeline %q step %q lane %q reference slot %q producer %q must be an earlier step", pipelineID, step.ID, lane.ID, binding.SlotName, binding.Artifact.Step)
|
||||
}
|
||||
producer, ok := laneIndex[strings.TrimSpace(binding.Artifact.Step)+"\x00"+strings.TrimSpace(binding.Artifact.Lane)]
|
||||
producer, ok := laneIndex[generatedOutputKeyFor(strings.TrimSpace(binding.Artifact.Step), strings.TrimSpace(binding.Artifact.Lane))]
|
||||
if !ok {
|
||||
return fmt.Errorf("pipeline %q step %q lane %q reference slot %q producer lane %q is not selected", pipelineID, step.ID, lane.ID, binding.SlotName, binding.Artifact.Lane)
|
||||
}
|
||||
|
||||
@@ -550,6 +550,44 @@ func typedResolutionProfile() PipelineProfile {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolvePipelineGeneratedProducerKeysDoNotCollide(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, step, lane string
|
||||
accepted contracts.ArtifactKind
|
||||
wantError bool
|
||||
}{
|
||||
{"first producer", "a\x00b", "c", "test/notes", false},
|
||||
{"second producer", "a", "b\x00c", "test/score", false},
|
||||
{"first mismatch", "a\x00b", "c", "test/score", true},
|
||||
{"second mismatch", "a", "b\x00c", "test/notes", true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
catalog := typedResolutionCatalog(t, completeTypedCatalogOptions())
|
||||
spec := ModuleSpec{Key: "consumer", Stage: StageExtract, ExecutionClass: contracts.ExecutionClassDeterministic,
|
||||
ArtifactKind: "test/notes", ReferenceSlots: []contracts.ReferenceSlot{{Name: "context", AcceptedArtifactKinds: []contracts.ArtifactKind{tc.accepted}}}}
|
||||
if err := RegisterExtractor(catalog.Extractors, spec, func() (contracts.Extractor[codecNotes], error) {
|
||||
return typedTestExtractor[codecNotes]{key: "consumer"}, nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lane := func(extractor string) ArtifactLaneProfile { return typedLaneProfile(extractor, ValidatorOverride{}) }
|
||||
profile := PipelineProfile{ID: "generated", Input: Binding("typed/input"), Chunk: Binding("typed/chunk"), Output: Binding("typed/output"), Steps: []PipelineStepProfile{
|
||||
{ID: "a\x00b", Artifacts: map[string]ArtifactLaneProfile{"c": lane("typed/extract-notes")}},
|
||||
{ID: "a", Artifacts: map[string]ArtifactLaneProfile{"b\x00c": lane("typed/extract-score")}},
|
||||
{ID: "consumer", References: map[string]ReferenceSource{"context": GeneratedReference(tc.step, tc.lane)}, Artifacts: map[string]ArtifactLaneProfile{"result": lane("consumer")}},
|
||||
}}
|
||||
_, err := ResolvePipeline(profile, ResolveOptions{}, catalog)
|
||||
if tc.wantError {
|
||||
if err == nil || !strings.Contains(err.Error(), "does not accept artifact kind") {
|
||||
t.Fatalf("ResolvePipeline() error = %v, want kind mismatch", err)
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Fatalf("ResolvePipeline() error = %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func typedLaneProfile(extractor string, validators ValidatorOverride) ArtifactLaneProfile {
|
||||
return ArtifactLaneProfile{
|
||||
Extract: ModuleBinding{Module: extractor, Validators: validators},
|
||||
|
||||
Reference in New Issue
Block a user