Clarify evidence context and test lane filtering
This commit is contained in:
@@ -81,12 +81,12 @@ evidence publishes `contexts: []`.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Each context requires `context_ref`, `evidence_refs`, and `units` arrays.
|
Each context requires a `context_ref` object and `evidence_refs` and `units`
|
||||||
`context_ref` identifies the first and last included unit. Each evidence entry
|
arrays. `context_ref` identifies the first and last included unit. Each
|
||||||
contains a selected `lane_id` and an original `source_ref`. A unit uses the
|
evidence entry contains a selected `lane_id` and an original `source_ref`. A
|
||||||
existing source-unit shape: required `id`, `kind`, `text`, and self `ref`, plus
|
unit uses the existing source-unit shape: required `id`, `kind`, `text`, and
|
||||||
optional JSON-object `metadata`. Fixed payload objects reject unknown fields;
|
self `ref`, plus optional JSON-object `metadata`. Fixed payload objects reject
|
||||||
unit metadata may contain application-defined JSON values.
|
unknown fields; unit metadata may contain application-defined JSON values.
|
||||||
|
|
||||||
## Citations And Context
|
## Citations And Context
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package pipeline
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -22,19 +23,34 @@ func (output testEvidenceOutput) EvidenceContextPolicy() EvidenceContextPolicy {
|
|||||||
return cloneEvidenceContextPolicy(output.policy)
|
return cloneEvidenceContextPolicy(output.policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrepareEvidencePlanSelectsActiveLanesAndOwnsPolicy(t *testing.T) {
|
func TestEvidencePolicyResolutionAndPreparationSurviveLaneFiltering(t *testing.T) {
|
||||||
registries, _ := constructionRegistries(t, nil, nil)
|
registries, _ := constructionRegistries(t, nil, nil)
|
||||||
registries.ArtifactEvidence = NewArtifactEvidenceRegistry()
|
registries.ArtifactEvidence = NewArtifactEvidenceRegistry()
|
||||||
registerTestEvidenceOutput(t, ®istries, EvidenceContextPolicy{Enabled: true, WindowUnits: 2, LaneIDs: []string{"artifact", "inactive"}})
|
policy := EvidenceContextPolicy{Enabled: true, WindowUnits: 2, LaneIDs: []string{"artifact", "inactive"}}
|
||||||
|
profileValidated := false
|
||||||
|
registerTestEvidenceOutputWithProfileValidation(t, ®istries, policy, func(context OutputProfileOptionContext, _ map[string]any) error {
|
||||||
|
profileValidated = true
|
||||||
|
if want := []string{"artifact", "inactive"}; !reflect.DeepEqual(context.LaneIDs, want) {
|
||||||
|
return fmt.Errorf("configured lane ids = %#v, want %#v", context.LaneIDs, want)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
if err := RegisterArtifactEvidence(registries.ArtifactEvidence, "test/notes", func(codecNotes) []source.SourceRef { return nil }); err != nil {
|
if err := RegisterArtifactEvidence(registries.ArtifactEvidence, "test/notes", func(codecNotes) []source.SourceRef { return nil }); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
profile := constructionProfile()
|
profile := constructionProfile()
|
||||||
|
profile.Artifacts["inactive"] = profile.Artifacts["artifact"]
|
||||||
profile.Output.Options = map[string]any{"known": true}
|
profile.Output.Options = map[string]any{"known": true}
|
||||||
resolved, err := ResolvePipeline(profile, ResolveOptions{}, registries.catalog())
|
resolved, err := ResolvePipeline(profile, ResolveOptions{Only: []string{"artifact"}}, registries.catalog())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if !profileValidated {
|
||||||
|
t.Fatal("output profile options were not validated")
|
||||||
|
}
|
||||||
|
if lanes := resolved.AllArtifactLanes(); len(lanes) != 1 || lanes[0].ID != "artifact" {
|
||||||
|
t.Fatalf("resolved lanes = %#v, want only the invocation-selected lane", lanes)
|
||||||
|
}
|
||||||
prepared, err := Prepare(resolved, registries, ModuleDependencies{})
|
prepared, err := Prepare(resolved, registries, ModuleDependencies{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v, want nil", err)
|
t.Fatalf("Prepare() error = %v, want nil", err)
|
||||||
@@ -85,11 +101,16 @@ func TestPrepareEvidencePlanRejectsMissingAndMismatchedCapabilities(t *testing.T
|
|||||||
}
|
}
|
||||||
|
|
||||||
func registerTestEvidenceOutput(t *testing.T, registries *Registries, policy EvidenceContextPolicy) {
|
func registerTestEvidenceOutput(t *testing.T, registries *Registries, policy EvidenceContextPolicy) {
|
||||||
|
t.Helper()
|
||||||
|
registerTestEvidenceOutputWithProfileValidation(t, registries, policy, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerTestEvidenceOutputWithProfileValidation(t *testing.T, registries *Registries, policy EvidenceContextPolicy, validateProfile OutputProfileOptionValidator) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
registry := NewOutputEncoderRegistry()
|
registry := NewOutputEncoderRegistry()
|
||||||
if err := registry.RegisterBuilderWithSpec(defaultModuleSpec("output", StageOutput), func(options map[string]any) error {
|
if err := registry.RegisterBuilderWithProfileValidation(defaultModuleSpec("output", StageOutput), func(options map[string]any) error {
|
||||||
return RejectUnknownOptions(options, "known")
|
return RejectUnknownOptions(options, "known")
|
||||||
}, func(BuildRequest) (contracts.OutputEncoder, error) {
|
}, validateProfile, func(BuildRequest) (contracts.OutputEncoder, error) {
|
||||||
return testEvidenceOutput{policy: cloneEvidenceContextPolicy(policy)}, nil
|
return testEvidenceOutput{policy: cloneEvidenceContextPolicy(policy)}, nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user