Use structured keys for generated artifact producers

This commit is contained in:
2026-11-26 01:29:32 +00:00
parent 08a9bea23b
commit b6f04297d4
4 changed files with 52 additions and 6 deletions

View File

@@ -20,8 +20,8 @@ The [Core And Integration API Roadmap](../core-integration-api.md) established
the core/integration boundary. The reassessment below distinguishes its completed
work from the remaining audit remediation.
The **45 original finding entries** reduce to **27 outstanding catalog entries
and seven resolved entries**. Repeated responsibility findings are
The **45 original finding entries** reduce to **26 outstanding catalog entries
and eight resolved entries**. Repeated responsibility findings are
merged. Regression gaps are attached to the defects they protect rather than
counted as additional runtime bugs. In particular, TEST-001, TEST-002, and
TEST-004 each cover several distinct defects; TEST-003's native-fixture oracle
@@ -65,7 +65,7 @@ Original P2/P3 ratings and relative refactoring priorities are retained for
context; they are not one universal severity scale. No audit establishes a P1
incident or a measured end-to-end production speedup.
CAT-001, CAT-002, CAT-007, CAT-011, CAT-015, CAT-016, and CAT-034 are resolved;
CAT-001, CAT-002, CAT-007, CAT-011, CAT-012, CAT-015, CAT-016, and CAT-034 are resolved;
the other entries remain outstanding. The original reports and their baseline
observations are historical.
"Refactoring" denotes a maintenance opportunity, not a confirmed runtime
@@ -272,6 +272,9 @@ the existing material byte budget. Test extreme/normal radii on tiny sources.
**Assessment:** Static correctness counterexample, not executed; original P3.
**Status:** Resolved. Resolution uses structured producer keys, with real
resolution tests for colliding identifiers and both matching and mismatched kinds.
**Sources:** [BUG-001](03-complexity.md#bug-001--generated-producer-keys-can-collide),
[TEST-002](08-testing.md#test-002--identity-and-metadata-fixtures-omit-valid-representational-edge-cases).

View File

@@ -196,6 +196,11 @@ No contract change is required.
## Stage 3 — Use Structured Producer Lookup Keys
**Completed.** Resolution uses the existing structured producer key for both
insertion and lookup. Real-resolution regressions reproduced the collision and
cover each producer with matching and mismatched kinds. The specified focused
pipeline tests pass. Later resolution decomposition must preserve this behavior.
**Coverage:** CAT-012. **Prerequisites:** none.
Replace generated-binding insertion/lookup concatenation with

View File

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

View File

@@ -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},