Define typed producer assessment and native execution dependencies
This commit is contained in:
@@ -3,23 +3,25 @@ package pipeline
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func TestProducerControlsResolvePrecedenceAndExplicitZero(t *testing.T) {
|
||||
strict, permissive := ModeStrict, ModePermissive
|
||||
auto, bypass, refresh := CacheAuto, CacheBypass, CacheRefresh
|
||||
strict, permissive := contracts.ModeStrict, contracts.ModePermissive
|
||||
auto, bypass, refresh := contracts.CacheAuto, contracts.CacheBypass, contracts.CacheRefresh
|
||||
zero, five := 0, 5
|
||||
tests := []struct {
|
||||
name string
|
||||
profile PipelineProfile
|
||||
binding ModuleBinding
|
||||
invocation *CacheMode
|
||||
want ProducerControls
|
||||
invocation *contracts.CacheMode
|
||||
want contracts.ProducerControls
|
||||
}{
|
||||
{"defaults", PipelineProfile{}, ModuleBinding{}, nil, ProducerControls{ModeStrict, 2, CacheAuto}},
|
||||
{"pipeline", PipelineProfile{Mode: &permissive, MaxAdditionalTurns: &five, Cache: &refresh}, ModuleBinding{}, nil, ProducerControls{ModePermissive, 5, CacheRefresh}},
|
||||
{"binding", PipelineProfile{Mode: &permissive, MaxAdditionalTurns: &five, Cache: &refresh}, ModuleBinding{Mode: &strict, MaxAdditionalTurns: &zero, Cache: &auto}, nil, ProducerControls{ModeStrict, 0, CacheAuto}},
|
||||
{"invocation", PipelineProfile{Cache: &refresh}, ModuleBinding{Cache: &auto}, &bypass, ProducerControls{ModeStrict, 2, CacheBypass}},
|
||||
{"defaults", PipelineProfile{}, ModuleBinding{}, nil, contracts.ProducerControls{contracts.ModeStrict, 2, contracts.CacheAuto}},
|
||||
{"pipeline", PipelineProfile{Mode: &permissive, MaxAdditionalTurns: &five, Cache: &refresh}, ModuleBinding{}, nil, contracts.ProducerControls{contracts.ModePermissive, 5, contracts.CacheRefresh}},
|
||||
{"binding", PipelineProfile{Mode: &permissive, MaxAdditionalTurns: &five, Cache: &refresh}, ModuleBinding{Mode: &strict, MaxAdditionalTurns: &zero, Cache: &auto}, nil, contracts.ProducerControls{contracts.ModeStrict, 0, contracts.CacheAuto}},
|
||||
{"invocation", PipelineProfile{Cache: &refresh}, ModuleBinding{Cache: &auto}, &bypass, contracts.ProducerControls{contracts.ModeStrict, 2, contracts.CacheBypass}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
@@ -35,7 +37,7 @@ func TestProducerControlsResolvePrecedenceAndExplicitZero(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProducerControlsRejectInvalidValuesWithoutMaximumBudgets(t *testing.T) {
|
||||
invalidMode, invalidCache := ExecutionMode("unknown"), CacheMode("unknown")
|
||||
invalidMode, invalidCache := contracts.ExecutionMode("unknown"), contracts.CacheMode("unknown")
|
||||
negative, large := -1, 1000000
|
||||
for _, binding := range []ModuleBinding{{Mode: &invalidMode}, {Cache: &invalidCache}, {MaxAdditionalTurns: &negative}} {
|
||||
if _, err := ResolveProducerControls(binding, PipelineProfile{}, nil); err == nil {
|
||||
@@ -49,7 +51,7 @@ func TestProducerControlsRejectInvalidValuesWithoutMaximumBudgets(t *testing.T)
|
||||
}
|
||||
|
||||
func TestModuleBindingRoundTripRetainsExplicitControls(t *testing.T) {
|
||||
strict, bypass, zero := ModeStrict, CacheBypass, 0
|
||||
strict, bypass, zero := contracts.ModeStrict, contracts.CacheBypass, 0
|
||||
input := ModuleBinding{Module: "fixture", Mode: &strict, Cache: &bypass, MaxAdditionalTurns: &zero}
|
||||
data, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
@@ -66,20 +68,20 @@ func TestModuleBindingRoundTripRetainsExplicitControls(t *testing.T) {
|
||||
|
||||
func TestResolvedProducerControlsApplyToEveryLaneOperation(t *testing.T) {
|
||||
profile := baselineProfile()
|
||||
permissive, bypass, zero := ModePermissive, CacheBypass, 0
|
||||
permissive, bypass, zero := contracts.ModePermissive, contracts.CacheBypass, 0
|
||||
profile.Mode = &permissive
|
||||
profile.Chunk.MaxAdditionalTurns = &zero
|
||||
resolved, err := ResolvePipeline(profile, ResolveOptions{CacheOverride: &bypass}, newProfileCatalog(t))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if resolved.ChunkControls != (ProducerControls{ModePermissive, 0, CacheBypass}) {
|
||||
if resolved.ChunkControls != (contracts.ProducerControls{contracts.ModePermissive, 0, contracts.CacheBypass}) {
|
||||
t.Fatalf("chunk controls = %#v", resolved.ChunkControls)
|
||||
}
|
||||
for _, step := range resolved.Steps {
|
||||
for _, lane := range step.ArtifactLanes {
|
||||
for _, got := range []ProducerControls{lane.ExtractControls, lane.MergeControls, lane.NormalizeControls} {
|
||||
if got != (ProducerControls{ModePermissive, 2, CacheBypass}) {
|
||||
for _, got := range []contracts.ProducerControls{lane.ExtractControls, lane.MergeControls, lane.NormalizeControls} {
|
||||
if got != (contracts.ProducerControls{contracts.ModePermissive, 2, contracts.CacheBypass}) {
|
||||
t.Fatalf("lane controls = %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user