Use shared target inventory for CLI references

This commit is contained in:
2026-11-26 02:41:42 +00:00
parent 510a079976
commit 654965d75a
6 changed files with 81 additions and 180 deletions

View File

@@ -102,6 +102,7 @@ handoff and keeps capture and publication state local to that run:
attach its local native execution group to the inherited invocation context. attach its local native execution group to the inherited invocation context.
3. Capture selected configuration, compose registries, expand reference actions, 3. Capture selected configuration, compose registries, expand reference actions,
and resolve the effective pipeline. and resolve the effective pipeline.
4. Obtain the shared engine when needed and perform offline preflight. 4. Obtain the shared engine when needed and perform offline preflight.
5. Materialize references, construct prepared typed modules, read input bytes, 5. Materialize references, construct prepared typed modules, read input bytes,
and resolve the effective session. and resolve the effective session.
@@ -112,6 +113,10 @@ handoff and keeps capture and publication state local to that run:
success, write the debug group's snapshot immediately before capture success, write the debug group's snapshot immediately before capture
finalization, then submit the native completion report. finalization, then submit the native completion report.
CLI reference grammar and precedence remain local; selector expansion uses the
pipeline's [target inventory](../../internal/framework/pipeline/selection.go)
before complete resolution checks whether required slots are bound.
Modules receive the shared engine, operation data, and explicit collaborators, Modules receive the shared engine, operation data, and explicit collaborators,
not physical roots or CommandKit reporters. Detailed worker, assessment, not physical roots or CommandKit reporters. Detailed worker, assessment,
eligibility, and cache algorithms belong in [Pipeline Internals](pipeline.md); eligibility, and cache algorithms belong in [Pipeline Internals](pipeline.md);

View File

@@ -100,6 +100,8 @@ overrides, and exact reference changes to `pipeline.ResolvePipeline`.
Structural validation uses the framework's catalog-independent layout; an omitted Structural validation uses the framework's catalog-independent layout; an omitted
profile ID is supplied from the validated map key on a detached value. Document profile ID is supplied from the validated map key on a detached value. Document
presence, map-key matching, and reference-source checks remain configuration-owned. presence, map-key matching, and reference-source checks remain configuration-owned.
CLI selector expansion and complete resolution share the framework's selected
target inventory, while required-reference validation remains in resolution.
The framework resolves module/default/validator/type/reference compatibility and The framework resolves module/default/validator/type/reference compatibility and
concrete producer controls before execution. Input slices/maps and the original concrete producer controls before execution. Input slices/maps and the original
configuration do not become mutable aliases of the effective result. configuration do not become mutable aliases of the effective result.

View File

@@ -341,6 +341,12 @@ arrays or replacing copying with a JSON round trip would change the contract.
### CAT-014 — Pipeline Composition Has Three Independent Interpreters ### CAT-014 — Pipeline Composition Has Three Independent Interpreters
**Status:** Resolved. Configuration validation, resolution, and CLI reference
expansion share pipeline-owned layout and target selection. Independent tests
cover CLI-only required references, variants, precedence, generated protection,
selection errors before reads, and configuration/resolver structure. Full
resolution decomposition remains separately tracked under CAT-018.
**Assessment:** High-leverage ownership/refactoring opportunity; original high. **Assessment:** High-leverage ownership/refactoring opportunity; original high.
**Sources:** [CPLX-003](03-complexity.md#cplx-003--three-packages-independently-interpret-pipeline-structure), **Sources:** [CPLX-003](03-complexity.md#cplx-003--three-packages-independently-interpret-pipeline-structure),
@@ -358,7 +364,8 @@ Retain independent expected selections in config, resolver, and CLI tests.
**Subsequent decision:** [Discussion Item 4](discussion.md#4-one-owner-for-pipeline-interpretation-and-pure-copying) **Subsequent decision:** [Discussion Item 4](discussion.md#4-one-owner-for-pipeline-interpretation-and-pure-copying)
accepts shared layout/selection operations and pure copying in the existing accepts shared layout/selection operations and pure copying in the existing
pipeline package, with loading, CLI binding, and complete resolution remaining pipeline package, with loading, CLI binding, and complete resolution remaining
distinct phases. This also governs CAT-017/CAT-018; implementation remains pending. distinct phases. This also governs CAT-017/CAT-018; resolution decomposition
remains pending under CAT-018.
### CAT-015 — Producer Lifecycle Depends On Coupled Closure State ### CAT-015 — Producer Lifecycle Depends On Coupled Closure State

View File

@@ -714,6 +714,12 @@ Document the phase boundary, not a partial resolver.
## Stage 25 — Reuse Inventory In CLI Reference Binding ## Stage 25 — Reuse Inventory In CLI Reference Binding
**Completed.** CLI selector expansion uses the shared layout and selected target
inventory; grammar, precedence, conflicts, unbinds, and binding remain CLI-owned.
A regression supplies required references only through CLI selectors, alongside
existing variant, generated-handoff, and invalid-before-read coverage. The
specified CLI, config, pipeline, and preflight suites pass.
**Coverage:** CAT-014 completion; CAT-018 callers. **Prerequisites:** Stages 23–24. **Coverage:** CAT-014 completion; CAT-018 callers. **Prerequisites:** Stages 23–24.
Replace reference_selectors.go's target/default/spec interpreter with inventory; Replace reference_selectors.go's target/default/spec interpreter with inventory;

View File

@@ -86,6 +86,44 @@ func TestReferenceSelectorSpecificityAndFinalOccurrenceChooseConcreteBindings(t
} }
} }
func TestRequiredReferencesCanBeSuppliedOnlyByCLI(t *testing.T) {
cfg := referenceContractConfig()
profile := cfg.Pipelines["demo"]
profile.Chunk.References = nil
alpha := profile.Artifacts["alpha"]
alpha.References = nil
alpha.Extract.References = nil
alpha.Merge.References = nil
alpha.Normalize.References = nil
profile.Artifacts["alpha"] = alpha
cfg.Pipelines["demo"] = profile
catalog := referenceContractCatalog(t, true, true)
var requests []cliReferenceRequest
for _, selector := range []string{"chunk.required-chunk", "alpha.extract.required-extract", "alpha.merge.required-merge", "alpha.normalize.required-normalize"} {
requests = append(requests, cliReferenceRequest{Selector: mustParseReferenceSelector(t, selector, "--reference"), Source: "cli.txt"})
}
bindings, unbinds, err := resolveCLIReferenceRequests(cfg, "demo", nil, catalog, requests, nil)
if err != nil {
t.Fatalf("discover required slots: %v", err)
}
effective, err := cfg.Resolve(config.ResolveInput{PipelineID: "demo", Catalog: catalog, ReferenceOverrides: bindings, ReferenceUnbinds: unbinds})
if err != nil {
t.Fatalf("resolve with CLI-only required references: %v", err)
}
lane := referenceContractLane(t, effective.ResolvedPipeline, "alpha")
for _, target := range []pipeline.ResolvedReferenceTarget{effective.ResolvedPipeline.ChunkReferences, lane.ExtractReferences, lane.MergeReferences, lane.NormalizeReferences} {
found := false
for _, binding := range target.Bindings {
if binding.Source == "cli.txt" && binding.BindingSource == contracts.ReferenceBindingSourceCLI {
found = true
}
}
if !found {
t.Fatalf("target does not contain CLI required reference: %#v", target)
}
}
}
func TestReferenceSelectorsRejectInvalidOrUnselectedScopesBeforeMaterialization(t *testing.T) { func TestReferenceSelectorsRejectInvalidOrUnselectedScopesBeforeMaterialization(t *testing.T) {
cfg := referenceContractConfig() cfg := referenceContractConfig()
catalog := referenceContractCatalog(t, true, true) catalog := referenceContractCatalog(t, true, true)

View File

@@ -290,125 +290,31 @@ func selectedReferenceTargets(cfg config.Config, pipelineID string, only []strin
if !ok { if !ok {
return nil, fmt.Errorf("pipeline %q is not configured", strings.TrimSpace(pipelineID)) return nil, fmt.Errorf("pipeline %q is not configured", strings.TrimSpace(pipelineID))
} }
if profile.Steps != nil && len(only) > 0 { profile.ID = strings.TrimSpace(pipelineID)
return nil, fmt.Errorf("pipeline %q lane selection is not supported for explicit ordered steps", strings.TrimSpace(pipelineID)) layout, err := pipeline.LayoutPipeline(profile)
}
lanesByID := make(map[string]pipeline.ArtifactLaneProfile, len(profile.Artifacts))
addLanes := func(values map[string]pipeline.ArtifactLaneProfile) error {
for rawLaneID, lane := range values {
laneID := strings.TrimSpace(rawLaneID)
if laneID == "" {
return fmt.Errorf("pipeline %q artifact lane id must not be empty", strings.TrimSpace(pipelineID))
}
if _, ok := lanesByID[laneID]; ok {
return fmt.Errorf("pipeline %q artifact lane %q is duplicated after trimming", strings.TrimSpace(pipelineID), laneID)
}
lanesByID[laneID] = lane
}
return nil
}
if profile.Steps == nil {
if err := addLanes(profile.Artifacts); err != nil {
return nil, err
}
} else {
for _, step := range profile.Steps {
if err := addLanes(step.Artifacts); err != nil {
return nil, err
}
}
}
selectedIDs := make([]string, 0, len(lanesByID))
if len(only) == 0 {
for laneID := range lanesByID {
selectedIDs = append(selectedIDs, laneID)
}
} else {
seen := make(map[string]struct{}, len(only))
for _, rawLaneID := range only {
laneID := strings.TrimSpace(rawLaneID)
if laneID == "" {
return nil, fmt.Errorf("pipeline %q selected artifact lane id must not be empty", strings.TrimSpace(pipelineID))
}
if _, ok := lanesByID[laneID]; !ok {
return nil, fmt.Errorf("pipeline %q selected artifact lane %q is not declared", strings.TrimSpace(pipelineID), laneID)
}
if _, ok := seen[laneID]; !ok {
selectedIDs = append(selectedIDs, laneID)
seen[laneID] = struct{}{}
}
}
}
sort.Strings(selectedIDs)
targets := make([]selectedReferenceTarget, 0, 1+len(selectedIDs)*3)
chunk := pipeline.Binding(profile.Chunk.Module)
chunk.Module = strings.TrimSpace(profile.Chunk.Module)
if chunk.Module == "" {
chunk.Module = pipeline.DefaultChunkModule
}
chunkSpec, err := cliReferenceChunkerSpec(catalog, chunk.Module)
if err != nil { if err != nil {
return nil, fmt.Errorf("pipeline %q chunk module %q: %w", strings.TrimSpace(pipelineID), chunk.Module, err) return nil, err
} }
targets = append(targets, selectedReferenceTarget{ inventory, err := pipeline.SelectPipelineTargets(layout, only, catalog)
stage: pipeline.StageChunk, if err != nil {
module: chunk.Module, return nil, err
slots: referenceSlotSet(chunkSpec.ReferenceSlots), }
}) targets := []selectedReferenceTarget{{stage: pipeline.StageChunk, module: inventory.Chunk.Module, slots: referenceSlotSet(inventory.ChunkSpec.ReferenceSlots)}}
var lanes []pipeline.PipelineTargetLane
for _, laneID := range selectedIDs { for _, step := range inventory.Steps {
lane := lanesByID[laneID] for _, lane := range step.Lanes {
extractModule := strings.TrimSpace(lane.Extract.Module) if lane.Selected {
if extractModule == "" { lanes = append(lanes, lane)
return nil, fmt.Errorf("pipeline %q lane %q extract module must not be empty", strings.TrimSpace(pipelineID), laneID) }
} }
extractSpec, err := cliReferenceExtractorSpec(catalog, extractModule) }
if err != nil { sort.Slice(lanes, func(i, j int) bool { return lanes[i].ID < lanes[j].ID })
return nil, fmt.Errorf("pipeline %q lane %q extract module %q: %w", strings.TrimSpace(pipelineID), laneID, extractModule, err) for _, lane := range lanes {
} targets = append(targets,
artifactKind := extractSpec.ArtifactKind selectedReferenceTarget{laneID: lane.ID, stage: pipeline.StageExtract, module: lane.Extract.Module, slots: referenceSlotSet(lane.ExtractSpec.ReferenceSlots)},
if artifactKind == "" { selectedReferenceTarget{laneID: lane.ID, stage: pipeline.StageMerge, module: lane.Merge.Module, slots: referenceSlotSet(lane.MergeSpec.ReferenceSlots)},
return nil, fmt.Errorf("pipeline %q lane %q extract module %q does not declare an artifact kind", strings.TrimSpace(pipelineID), laneID, extractModule) selectedReferenceTarget{laneID: lane.ID, stage: pipeline.StageNormalize, module: lane.Normalize.Module, slots: referenceSlotSet(lane.NormalizeSpec.ReferenceSlots)},
} )
targets = append(targets, selectedReferenceTarget{
laneID: laneID,
stage: pipeline.StageExtract,
module: extractModule,
slots: referenceSlotSet(extractSpec.ReferenceSlots),
})
mergeModule := strings.TrimSpace(lane.Merge.Module)
if mergeModule == "" {
mergeModule = pipeline.DefaultMergeModule
}
mergeSpec, err := cliReferenceMergerSpec(catalog, mergeModule, artifactKind)
if err != nil {
return nil, fmt.Errorf("pipeline %q lane %q merge module %q: %w", strings.TrimSpace(pipelineID), laneID, mergeModule, err)
}
targets = append(targets, selectedReferenceTarget{
laneID: laneID,
stage: pipeline.StageMerge,
module: mergeModule,
slots: referenceSlotSet(mergeSpec.ReferenceSlots),
})
normalizeModule := strings.TrimSpace(lane.Normalize.Module)
if normalizeModule == "" {
normalizeModule = pipeline.DefaultNormalizeModule
}
normalizeSpec, err := cliReferenceNormalizerSpec(catalog, normalizeModule, artifactKind)
if err != nil {
return nil, fmt.Errorf("pipeline %q lane %q normalize module %q: %w", strings.TrimSpace(pipelineID), laneID, normalizeModule, err)
}
targets = append(targets, selectedReferenceTarget{
laneID: laneID,
stage: pipeline.StageNormalize,
module: normalizeModule,
slots: referenceSlotSet(normalizeSpec.ReferenceSlots),
})
} }
return targets, nil return targets, nil
} }
@@ -423,69 +329,6 @@ func lookupCLIReferencePipeline(profiles map[string]pipeline.PipelineProfile, pi
return pipeline.PipelineProfile{}, false return pipeline.PipelineProfile{}, false
} }
func cliReferenceChunkerSpec(catalog pipeline.ModuleCatalog, module string) (pipeline.ModuleSpec, error) {
if catalog.Chunkers == nil {
return pipeline.ModuleSpec{}, fmt.Errorf("module %q is not registered", module)
}
spec, ok := catalog.Chunkers.Spec(module)
if !ok {
return pipeline.ModuleSpec{}, fmt.Errorf("module %q is not registered", module)
}
return spec, nil
}
func cliReferenceExtractorSpec(catalog pipeline.ModuleCatalog, module string) (pipeline.ModuleSpec, error) {
if catalog.Extractors == nil {
return pipeline.ModuleSpec{}, fmt.Errorf("module %q is not registered", module)
}
spec, ok := catalog.Extractors.Spec(module)
if !ok {
return pipeline.ModuleSpec{}, fmt.Errorf("module %q is not registered", module)
}
return spec, nil
}
func cliReferenceMergerSpec(catalog pipeline.ModuleCatalog, module string, kind contracts.ArtifactKind) (pipeline.ModuleSpec, error) {
if catalog.Mergers == nil {
return pipeline.ModuleSpec{}, fmt.Errorf("module %q is not registered", module)
}
registered := catalog.Mergers.RegisteredArtifactKinds(module)
if len(registered) == 0 {
return pipeline.ModuleSpec{}, fmt.Errorf("module %q is not registered", module)
}
spec, ok := catalog.Mergers.SpecForArtifact(module, kind)
if !ok {
return pipeline.ModuleSpec{}, cliReferenceArtifactVariantError("merger", module, kind, registered)
}
return spec, nil
}
func cliReferenceNormalizerSpec(catalog pipeline.ModuleCatalog, module string, kind contracts.ArtifactKind) (pipeline.ModuleSpec, error) {
if catalog.Normalizers == nil {
return pipeline.ModuleSpec{}, fmt.Errorf("module %q is not registered", module)
}
registered := catalog.Normalizers.RegisteredArtifactKinds(module)
if len(registered) == 0 {
return pipeline.ModuleSpec{}, fmt.Errorf("module %q is not registered", module)
}
spec, ok := catalog.Normalizers.SpecForArtifact(module, kind)
if !ok {
return pipeline.ModuleSpec{}, cliReferenceArtifactVariantError("normalizer", module, kind, registered)
}
return spec, nil
}
func cliReferenceArtifactVariantError(moduleType string, module string, kind contracts.ArtifactKind, registered []contracts.ArtifactKind) error {
values := make([]string, len(registered))
for i, value := range registered {
values[i] = string(value)
}
if len(values) == 0 {
return fmt.Errorf("%s %q has no typed variant for artifact kind %q", moduleType, module, kind)
}
return fmt.Errorf("%s %q has no typed variant for artifact kind %q; registered kinds: %s", moduleType, module, kind, strings.Join(values, ", "))
}
func referenceSlotSet(slots []contracts.ReferenceSlot) map[string]struct{} { func referenceSlotSet(slots []contracts.ReferenceSlot) map[string]struct{} {
slotSet := make(map[string]struct{}, len(slots)) slotSet := make(map[string]struct{}, len(slots))
for _, slot := range slots { for _, slot := range slots {