Publish domain artifacts without reporting sidecars
This commit is contained in:
@@ -103,7 +103,7 @@ func TestRunnerMaterializesAndFullyAssessesEachNativePlanRevision(t *testing.T)
|
||||
if test.wantError {
|
||||
return
|
||||
}
|
||||
if len(output.NormalizeOutputs) != 1 || (output.FallbackCount == 1) != test.wantFallback {
|
||||
if len(output.normalizeOutputs) != 1 || (output.FallbackCount == 1) != test.wantFallback {
|
||||
t.Fatalf("plan disposition=%#v", output)
|
||||
}
|
||||
for _, role := range []string{"extract", "merge", "normalize"} {
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/fileio"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
@@ -348,14 +347,6 @@ func debugFirstNonEmptyString(values ...string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (client *debugLLMClient) LLMProfileManifests() []artifacts.LLMProfileManifest {
|
||||
provider, ok := client.inner.(contracts.LLMProfileManifestProvider)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return provider.LLMProfileManifests()
|
||||
}
|
||||
|
||||
func writeDebugTimed(recorder DebugRecorder, name string, envelope debugTimedEnvelope) error {
|
||||
if recorder == nil || !recorder.Enabled() {
|
||||
return nil
|
||||
@@ -680,31 +671,6 @@ func debugValidationResultEnvelope(result contracts.ValidationResult) contracts.
|
||||
return result
|
||||
}
|
||||
|
||||
func debugRejectedOutputEnvelope(rejected contracts.RejectedOutput) contracts.RejectedOutput {
|
||||
rejected.Message = string(redactSecretBytes([]byte(rejected.Message)))
|
||||
rejected.DiagnosticArtifactPath = string(redactSecretBytes([]byte(rejected.DiagnosticArtifactPath)))
|
||||
return rejected
|
||||
}
|
||||
|
||||
func debugRejectedOutputPtr(rejected *contracts.RejectedOutput) any {
|
||||
if rejected == nil {
|
||||
return nil
|
||||
}
|
||||
out := debugRejectedOutputEnvelope(*rejected)
|
||||
return out
|
||||
}
|
||||
|
||||
func debugRejectedOutputEnvelopes(rejected []contracts.RejectedOutput) []contracts.RejectedOutput {
|
||||
if len(rejected) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make([]contracts.RejectedOutput, 0, len(rejected))
|
||||
for _, item := range rejected {
|
||||
out = append(out, debugRejectedOutputEnvelope(item))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func debugContentDigest(content []byte) string {
|
||||
sum := sha256.Sum256(content)
|
||||
return "sha256:" + hex.EncodeToString(sum[:])
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/evidencecontext"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
type capturingEvidenceOutput struct {
|
||||
@@ -91,8 +92,7 @@ func TestRunnerBuildsEvidenceContextFromSelectedNormalizedOutputs(t *testing.T)
|
||||
return nil, nil
|
||||
}
|
||||
})
|
||||
debug := newCapturedDebugRecorder()
|
||||
if _, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Debug: debug}); err != nil {
|
||||
if _, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input")}); err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
|
||||
@@ -100,40 +100,26 @@ func TestRunnerBuildsEvidenceContextFromSelectedNormalizedOutputs(t *testing.T)
|
||||
if actual := []int{value[0].ID, value[1].ID, value[2].ID}; !reflect.DeepEqual(actual, []int{1, 2, 3}) {
|
||||
t.Fatalf("evidence context = %#v, want selected union", value)
|
||||
}
|
||||
debugJSON := string(debug.json["output/evidence-context.json"])
|
||||
if strings.Contains(debugJSON, "text-1") || strings.Contains(debugJSON, "metadata") || !strings.Contains(debugJSON, `"artifact_kind":"source/evidence-context"`) || !strings.Contains(debugJSON, `"schema_id":"notarius.source.evidence_context"`) || strings.Contains(debugJSON, "context_count") || !strings.Contains(debugJSON, `"unit_count":3`) {
|
||||
t.Fatalf("evidence debug envelope = %s, want only allowlisted summary", debugJSON)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRunnerEvidenceContextOmitsAbsentAndRejectedLanes(t *testing.T) {
|
||||
prepared := preparedOrderedPipeline(t, 2, orderedLaneSpec{id: "present", profile: "notes"}, orderedLaneSpec{id: "rejected", profile: "notes"})
|
||||
encoder := &capturingEvidenceOutput{}
|
||||
prepared.output = encoder
|
||||
setNormalizedNotes(prepared, map[string]codecNotes{"present": {Items: []string{"present"}}, "rejected": {Items: []string{"rejected"}}})
|
||||
prepared.Steps[1].lanes[0].mergeValidators.validators = []preparedValidator{{
|
||||
resolved: ResolvedValidator{Binding: Binding("reject"), Target: ValidatorTargetTyped, ArtifactKind: "test/notes"},
|
||||
typedValidate: func(context.Context, any, typedValidationTarget) (contracts.ValidationResult, error) {
|
||||
return contracts.ValidationResult{Approved: false, ReasonCode: "rejected", Message: "not accepted", CorrectionGuidance: "return an acceptable candidate"}, nil
|
||||
},
|
||||
}}
|
||||
prepared.Steps[1].lanes[0].resolved.MergeValidationPolicy.SemanticRejection = SemanticRejectionRejectOutput
|
||||
installEvidencePlan(prepared, 0, []string{"absent", "present", "rejected"}, func(notes codecNotes) ([]source.SourceRef, error) {
|
||||
if len(notes.Items) > 0 && notes.Items[0] == "present" {
|
||||
return []source.SourceRef{{SourceID: "source", StartUnitID: 1, EndUnitID: 1}}, nil
|
||||
}
|
||||
return []source.SourceRef{{SourceID: "source", StartUnitID: 2, EndUnitID: 2}}, nil
|
||||
func TestEvidenceContextOmitsUnselectedAndAbsentLanes(t *testing.T) {
|
||||
prepared := preparedOrderedPipeline(t, 2, orderedLaneSpec{id: "present", profile: "notes"}, orderedLaneSpec{id: "unselected", profile: "notes"})
|
||||
doc := prepared.input.(*typedTestInput).doc
|
||||
installEvidencePlan(prepared, 0, []string{"absent", "present"}, func(codecNotes) ([]source.SourceRef, error) {
|
||||
return []source.SourceRef{{SourceID: doc.ID, StartUnitID: 1, EndUnitID: 1}}, nil
|
||||
})
|
||||
result, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input")})
|
||||
artifact, err := prepared.artifactCodecs.Encode("test/notes", codecNotes{Items: []string{"accepted"}})
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(result.Rejected) != 1 || result.Rejected[0].LaneID != "rejected" {
|
||||
t.Fatalf("rejections = %#v, want rejected lane unchanged", result.Rejected)
|
||||
result, _, err := buildOutputEvidenceContext(prepared, doc, []contracts.SerializedOutput{{LaneID: "present", SourceID: doc.ID, Artifact: artifact}, {LaneID: "unselected", SourceID: doc.ID, Artifact: artifact}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
value := decodeCapturedEvidence(t, encoder)
|
||||
if len(value) != 1 || value[0].ID != 1 {
|
||||
t.Fatalf("evidence context = %#v, want present lane only", value)
|
||||
value, err := evidencecontext.New().Decode(result.Content)
|
||||
if err != nil || len(value) != 1 || value[0].ID != 1 {
|
||||
t.Fatalf("evidence=%#v %v", value, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,8 +135,8 @@ func TestRunnerEvidenceContextFailurePreventsOutputEncoding(t *testing.T) {
|
||||
if err == nil || !strings.Contains(err.Error(), "accepted evidence references are invalid") {
|
||||
t.Fatalf("Run() error = %v, want evidence context failure", err)
|
||||
}
|
||||
if len(encoder.requests) != 0 || result.Manifest.ValidationStatus != "failed" || len(result.Rejected) != 0 {
|
||||
t.Fatalf("output requests = %#v manifest = %#v rejected = %#v, want failed run before output encoding", encoder.requests, result.Manifest, result.Rejected)
|
||||
if len(encoder.requests) != 0 || result.ArtifactCount() != 0 {
|
||||
t.Fatalf("invalid evidence was published: %#v", result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,33 +191,50 @@ func TestEvidenceContextOutputRequestOwnsArtifactBytes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerEvidenceContextRebuildsFromAcceptedCheckpoint(t *testing.T) {
|
||||
func TestRunnerEvidenceContextRebuildsFromCachedNormalizedArtifact(t *testing.T) {
|
||||
prepared := preparedConcurrentPipeline(t, 1)
|
||||
encoder := &capturingEvidenceOutput{}
|
||||
prepared.output = encoder
|
||||
doc := prepared.input.(*typedTestInput).doc
|
||||
lane := prepared.Steps[0].lanes[0]
|
||||
stored, err := checkpointArtifact(lane.typed.codec, lane.resolved.ID, lane.resolved.Normalize.Module, doc.ID, codecNotes{Items: []string{"stored"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
calls, assessments := 0, 0
|
||||
engine := nativeProducerEngine(t, producerClientFunc(func(context.Context, promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
|
||||
calls++
|
||||
return &promptkit.GenerateResponse{Content: `{"value":1}`}, nil
|
||||
}))
|
||||
lane := &prepared.Steps[0].lanes[0]
|
||||
lane.resolved.NormalizeExecutionClass = contracts.ExecutionClassLLMBacked
|
||||
lane.typed.normalize = func(ctx context.Context, _ any, request contracts.TypedNormalizeRequest[any]) (erasedTypedResult, error) {
|
||||
operation := request.Operation
|
||||
assess := operation.Assess
|
||||
operation.Assess = func(ctx context.Context, value any) (contracts.CandidateAssessment, error) {
|
||||
assessments++
|
||||
return assess(ctx, value)
|
||||
}
|
||||
value, outcome, err := RunProducer(ctx, engine, operation, nativeProducerInitial(), func(context.Context, *promptkit.RunResult) (*any, []string, error) {
|
||||
var value any = codecNotes{Items: []string{"stored"}}
|
||||
return &value, nil, nil
|
||||
}, nil, nil)
|
||||
return erasedTypedResult{Value: value, Outcome: outcome}, err
|
||||
}
|
||||
loader := newAcceptedCheckpointLoader()
|
||||
key := CheckpointLaneKey(lane.resolved.StepID, lane.resolved.ID)
|
||||
loader.accepted[key] = NormalizeCheckpoint{Output: stored}
|
||||
loader.acceptedDecision[key] = NewCheckpointDecision(CheckpointDecisionReused, CheckpointReasonAcceptedArtifactReused)
|
||||
installEvidencePlan(prepared, 0, []string{"notes"}, func(notes codecNotes) ([]source.SourceRef, error) {
|
||||
if !reflect.DeepEqual(notes.Items, []string{"stored"}) {
|
||||
return nil, errors.New("checkpoint artifact was not projected")
|
||||
return nil, errors.New("cached artifact was not projected")
|
||||
}
|
||||
return []source.SourceRef{{SourceID: doc.ID, StartUnitID: 1, EndUnitID: 1}}, nil
|
||||
})
|
||||
policy := CheckpointExecutionPolicy{RequireReusableLanes: map[string]struct{}{key: {}}}
|
||||
if _, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Checkpoint: loader, CheckpointPolicy: policy}); err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
_, store := filesystemProducerCache(t)
|
||||
for range 2 {
|
||||
encoder.requests = nil
|
||||
if _, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Cache: store, Workers: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
value := decodeCapturedEvidence(t, encoder)
|
||||
if len(value) != 1 || value[0].ID != 1 {
|
||||
t.Fatalf("evidence=%#v", value)
|
||||
}
|
||||
}
|
||||
value := decodeCapturedEvidence(t, encoder)
|
||||
if len(value) != 1 || value[0].ID != 1 {
|
||||
t.Fatalf("evidence context = %#v, want checkpointed normalized output", value)
|
||||
if calls != 1 || assessments != 1 {
|
||||
t.Fatalf("cache reuse calls=%d assessments=%d", calls, assessments)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@ func (output testEvidenceOutput) EvidenceContextPolicy() EvidenceContextPolicy {
|
||||
}
|
||||
|
||||
func TestEvidencePolicyResolutionAndPreparationSurviveLaneFiltering(t *testing.T) {
|
||||
registries, _ := constructionRegistries(t, nil, nil)
|
||||
registries := registriesFromModuleCatalog(typedResolutionCatalog(t, completeTypedCatalogOptions()))
|
||||
registries.ArtifactEvidence = NewArtifactEvidenceRegistry()
|
||||
policy := EvidenceContextPolicy{Enabled: true, WindowUnits: 2, LaneIDs: []string{"artifact", "inactive"}}
|
||||
policy := EvidenceContextPolicy{Enabled: true, WindowUnits: 2, LaneIDs: []string{"notes", "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) {
|
||||
if want := []string{"inactive", "notes"}; !reflect.DeepEqual(context.LaneIDs, want) {
|
||||
return fmt.Errorf("configured lane ids = %#v, want %#v", context.LaneIDs, want)
|
||||
}
|
||||
return nil
|
||||
@@ -38,31 +38,33 @@ func TestEvidencePolicyResolutionAndPreparationSurviveLaneFiltering(t *testing.T
|
||||
if err := RegisterArtifactEvidence(registries.ArtifactEvidence, "test/notes", func(codecNotes) []source.SourceRef { return nil }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
profile := constructionProfile()
|
||||
profile.Artifacts["inactive"] = profile.Artifacts["artifact"]
|
||||
profile := typedResolutionProfile()
|
||||
delete(profile.Artifacts, "score")
|
||||
profile.Output = Binding("output")
|
||||
profile.Artifacts["inactive"] = profile.Artifacts["notes"]
|
||||
profile.Output.Options = map[string]any{"known": true}
|
||||
resolved, err := ResolvePipeline(profile, ResolveOptions{Only: []string{"artifact"}}, registries.catalog())
|
||||
resolved, err := ResolvePipeline(profile, ResolveOptions{Only: []string{"notes"}}, registries.catalog())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !profileValidated {
|
||||
t.Fatal("output profile options were not validated")
|
||||
}
|
||||
if lanes := resolved.AllArtifactLanes(); len(lanes) != 1 || lanes[0].ID != "artifact" {
|
||||
if lanes := resolved.AllArtifactLanes(); len(lanes) != 1 || lanes[0].ID != "notes" {
|
||||
t.Fatalf("resolved lanes = %#v, want only the invocation-selected lane", lanes)
|
||||
}
|
||||
prepared, err := Prepare(resolved, registries, ModuleDependencies{})
|
||||
if err != nil {
|
||||
t.Fatalf("Prepare() error = %v, want nil", err)
|
||||
}
|
||||
if prepared.evidencePlan == nil || !reflect.DeepEqual(prepared.evidencePlan.policy.LaneIDs, []string{"artifact", "inactive"}) {
|
||||
if prepared.evidencePlan == nil || !reflect.DeepEqual(prepared.evidencePlan.policy.LaneIDs, []string{"inactive", "notes"}) {
|
||||
t.Fatalf("evidence plan = %#v, want complete configured policy", prepared.evidencePlan)
|
||||
}
|
||||
if got := prepared.evidencePlan.lanes; len(got) != 1 || got[0].laneID != "artifact" {
|
||||
if got := prepared.evidencePlan.lanes; len(got) != 1 || got[0].laneID != "notes" {
|
||||
t.Fatalf("active evidence lanes = %#v, want artifact only", got)
|
||||
}
|
||||
prepared.evidencePlan.policy.LaneIDs[0] = "mutated"
|
||||
if policy := prepared.output.(EvidenceContextPolicyProvider).EvidenceContextPolicy(); policy.LaneIDs[0] != "artifact" {
|
||||
if policy := prepared.output.(EvidenceContextPolicyProvider).EvidenceContextPolicy(); policy.LaneIDs[0] != "notes" {
|
||||
t.Fatalf("prepared plan mutated provider policy: %#v", policy)
|
||||
}
|
||||
}
|
||||
@@ -82,11 +84,13 @@ func TestPrepareEvidencePlanRejectsMissingAndMismatchedCapabilities(t *testing.T
|
||||
}, want: "requires Go type"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
registries, _ := constructionRegistries(t, nil, nil)
|
||||
registries := registriesFromModuleCatalog(typedResolutionCatalog(t, completeTypedCatalogOptions()))
|
||||
registries.ArtifactEvidence = NewArtifactEvidenceRegistry()
|
||||
registerTestEvidenceOutput(t, ®istries, EvidenceContextPolicy{Enabled: true, LaneIDs: []string{"artifact"}})
|
||||
registerTestEvidenceOutput(t, ®istries, EvidenceContextPolicy{Enabled: true, LaneIDs: []string{"notes"}})
|
||||
test.configure(®istries)
|
||||
profile := constructionProfile()
|
||||
profile := typedResolutionProfile()
|
||||
delete(profile.Artifacts, "score")
|
||||
profile.Output = Binding("output")
|
||||
profile.Output.Options = map[string]any{"known": true}
|
||||
resolved, err := ResolvePipeline(profile, ResolveOptions{}, registries.catalog())
|
||||
if err != nil {
|
||||
@@ -108,7 +112,7 @@ func registerTestEvidenceOutput(t *testing.T, registries *Registries, policy Evi
|
||||
func registerTestEvidenceOutputWithProfileValidation(t *testing.T, registries *Registries, policy EvidenceContextPolicy, validateProfile OutputProfileOptionValidator) {
|
||||
t.Helper()
|
||||
registry := NewOutputEncoderRegistry()
|
||||
if err := registry.RegisterBuilderWithProfileValidation(testModuleSpec("output", StageOutput), func(options map[string]any) error {
|
||||
if err := registry.RegisterBuilderWithProfileValidation(ModuleSpec{Key: "output", Stage: StageOutput, ExecutionClass: contracts.ExecutionClassDeterministic}, func(options map[string]any) error {
|
||||
return RejectUnknownOptions(options, "known")
|
||||
}, validateProfile, func(BuildRequest) (contracts.OutputEncoder, error) {
|
||||
return testEvidenceOutput{policy: cloneEvidenceContextPolicy(policy)}, nil
|
||||
|
||||
@@ -2,10 +2,8 @@ package pipeline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
@@ -89,12 +87,11 @@ func buildStepReferenceReuseEligibility(step PreparedPipelineStep, outputs map[g
|
||||
// buildStepReferenceSets resolves every generated binding for a step before
|
||||
// any lane in that step is allowed to start. Each returned set is a fresh
|
||||
// operation-time view; prepared reference sets are never modified.
|
||||
func buildStepReferenceSets(input RunInput, step PreparedPipelineStep, outputs []contracts.SerializedOutput) (map[referenceTargetKey]contracts.ReferenceSet, []artifacts.ReferenceProvenance, error) {
|
||||
func buildStepReferenceSets(input RunInput, step PreparedPipelineStep, outputs []contracts.SerializedOutput) (map[referenceTargetKey]contracts.ReferenceSet, error) {
|
||||
if len(step.lanes) == 0 {
|
||||
return nil, nil, nil
|
||||
return nil, nil
|
||||
}
|
||||
sets := make(map[referenceTargetKey]contracts.ReferenceSet)
|
||||
var provenance []artifacts.ReferenceProvenance
|
||||
outputsByProducer := indexGeneratedOutputs(outputs)
|
||||
canonical := make(map[generatedOutputKey]contracts.ReferenceItem)
|
||||
for _, prepared := range step.lanes {
|
||||
@@ -109,24 +106,24 @@ func buildStepReferenceSets(input RunInput, step PreparedPipelineStep, outputs [
|
||||
generated = true
|
||||
item, err := generatedReferenceItem(input, binding, outputsByProducer, canonical)
|
||||
if err != nil {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, err)
|
||||
return nil, contextualHandoffError(input, target, binding, err)
|
||||
}
|
||||
slotName := strings.TrimSpace(binding.SlotName)
|
||||
slot, ok := resolved.Slots[slotName]
|
||||
if !ok {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q has no resolved declaration", slotName))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q has no resolved declaration", slotName))
|
||||
}
|
||||
if len(slot.Items) > 0 {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q already contains materialized items", slotName))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q already contains materialized items", slotName))
|
||||
}
|
||||
if len(slot.Slot.AcceptedArtifactKinds) == 0 || !containsArtifactKind(slot.Slot.AcceptedArtifactKinds, item.ArtifactKind) {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q does not accept artifact kind %q", slotName, item.ArtifactKind))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q does not accept artifact kind %q", slotName, item.ArtifactKind))
|
||||
}
|
||||
if !referenceMediaTypeAccepted(item.MediaType, slot.Slot.AcceptedMediaTypes) {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q does not accept media type %q", slotName, item.MediaType))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q does not accept media type %q", slotName, item.MediaType))
|
||||
}
|
||||
if slot.Slot.MaxBytes > 0 && item.SizeBytes > slot.Slot.MaxBytes {
|
||||
return nil, nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q is %d bytes, limit %d", slotName, item.SizeBytes, slot.Slot.MaxBytes))
|
||||
return nil, contextualHandoffError(input, target, binding, fmt.Errorf("reference slot %q is %d bytes, limit %d", slotName, item.SizeBytes, slot.Slot.MaxBytes))
|
||||
}
|
||||
slot.Items = []contracts.ReferenceItem{contracts.CloneReferenceItem(item)}
|
||||
resolved.Slots[slotName] = slot
|
||||
@@ -136,12 +133,9 @@ func buildStepReferenceSets(input RunInput, step PreparedPipelineStep, outputs [
|
||||
}
|
||||
key := keyForReferenceTarget(target)
|
||||
sets[key] = resolved
|
||||
for _, item := range generatedItems(resolved) {
|
||||
provenance = append(provenance, referenceProvenanceForItem(target, item))
|
||||
}
|
||||
}
|
||||
}
|
||||
return sets, provenance, nil
|
||||
return sets, nil
|
||||
}
|
||||
|
||||
func containsArtifactKind(kinds []contracts.ArtifactKind, want contracts.ArtifactKind) bool {
|
||||
@@ -257,44 +251,3 @@ func findResolvedLane(pipeline ResolvedPipeline, stepID, laneID string) (Resolve
|
||||
}
|
||||
return ResolvedArtifactLane{}, false
|
||||
}
|
||||
|
||||
func generatedItems(set contracts.ReferenceSet) []contracts.ReferenceItem {
|
||||
var items []contracts.ReferenceItem
|
||||
keys := make([]string, 0, len(set.Slots))
|
||||
for key := range set.Slots {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
for _, item := range set.Slots[key].Items {
|
||||
if item.Origin.Type == "generated" {
|
||||
items = append(items, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func referenceProvenanceForItem(target ResolvedReferenceTarget, item contracts.ReferenceItem) artifacts.ReferenceProvenance {
|
||||
return artifacts.ReferenceProvenance{
|
||||
Stage: string(target.Stage),
|
||||
StepID: target.StepID,
|
||||
LaneID: target.LaneID,
|
||||
SlotName: item.SlotName,
|
||||
OriginType: item.Origin.Type,
|
||||
OriginURI: item.Origin.URI,
|
||||
Digest: item.Digest,
|
||||
MediaType: item.MediaType,
|
||||
SizeBytes: item.SizeBytes,
|
||||
BindingSource: item.BindingSource,
|
||||
ArtifactKind: string(item.ArtifactKind),
|
||||
SchemaID: item.ArtifactSchema.ID,
|
||||
SchemaName: item.ArtifactSchema.Name,
|
||||
SchemaVersion: item.ArtifactSchema.Version,
|
||||
SchemaDigest: contracts.DigestArtifactSchema(item.ArtifactSchema),
|
||||
ProducerPipeline: item.Producer.PipelineID,
|
||||
ProducerStep: item.Producer.StepID,
|
||||
ProducerLane: item.Producer.LaneID,
|
||||
ProducerModule: item.Producer.ModuleKey,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@ func TestRunnerWorkersAndNativeBackendAdmissionAreIndependent(t *testing.T) {
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: limits.workers})
|
||||
if err == nil && len(output.NormalizeOutputs) != 2 {
|
||||
err = fmt.Errorf("got %d lane outputs", len(output.NormalizeOutputs))
|
||||
if err == nil && len(output.normalizeOutputs) != 2 {
|
||||
err = fmt.Errorf("got %d lane outputs", len(output.normalizeOutputs))
|
||||
}
|
||||
done <- err
|
||||
}()
|
||||
@@ -251,8 +251,8 @@ func TestRunnerNativeCapacityFailureUsesOperationModeWithoutAnotherQueue(t *test
|
||||
if !errors.As(err, &capacity) || output.FallbackCount != 0 || len(output.OutputFiles) != 0 {
|
||||
t.Fatalf("strict capacity failure = %v, fallbacks %d", err, output.FallbackCount)
|
||||
}
|
||||
} else if err != nil || output.FallbackCount != 2 || len(output.NormalizeOutputs) != 2 {
|
||||
t.Fatalf("permissive capacity failure = %v, fallbacks %d, outputs %d", err, output.FallbackCount, len(output.NormalizeOutputs))
|
||||
} else if err != nil || output.FallbackCount != 2 || len(output.normalizeOutputs) != 2 {
|
||||
t.Fatalf("permissive capacity failure = %v, fallbacks %d, outputs %d", err, output.FallbackCount, len(output.normalizeOutputs))
|
||||
}
|
||||
if calls.Load() != 1 {
|
||||
t.Fatalf("capacity handling invoked provider %d times", calls.Load())
|
||||
@@ -288,7 +288,7 @@ func TestRunnerCancellationDrainsNativeWorkAndReleasesAdmission(t *testing.T) {
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 3})
|
||||
if output.FallbackCount != 0 || len(output.NormalizeOutputs) != 0 {
|
||||
if output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 {
|
||||
err = fmt.Errorf("cancellation delivered output: %v", err)
|
||||
}
|
||||
done <- err
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
@@ -379,61 +378,3 @@ func CloneReferenceTarget(in ResolvedReferenceTarget) ResolvedReferenceTarget {
|
||||
out.ReferenceSet = CloneReferenceSet(in.ReferenceSet)
|
||||
return out
|
||||
}
|
||||
|
||||
func ReferenceProvenance(resolved ResolvedPipeline) []artifacts.ReferenceProvenance {
|
||||
provenance := []artifacts.ReferenceProvenance{}
|
||||
provenance = append(provenance, referenceTargetProvenance(resolved.ChunkReferences)...)
|
||||
if len(resolved.Steps) > 0 {
|
||||
for _, step := range resolved.Steps {
|
||||
for _, lane := range step.ArtifactLanes {
|
||||
provenance = append(provenance, referenceTargetProvenance(lane.ExtractReferences)...)
|
||||
provenance = append(provenance, referenceTargetProvenance(lane.MergeReferences)...)
|
||||
provenance = append(provenance, referenceTargetProvenance(lane.NormalizeReferences)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
return provenance
|
||||
}
|
||||
|
||||
func referenceTargetProvenance(target ResolvedReferenceTarget) []artifacts.ReferenceProvenance {
|
||||
if len(target.ReferenceSet.Slots) == 0 {
|
||||
return nil
|
||||
}
|
||||
provenance := []artifacts.ReferenceProvenance{}
|
||||
slotNames := make([]string, 0, len(target.ReferenceSet.Slots))
|
||||
for slotName := range target.ReferenceSet.Slots {
|
||||
slotNames = append(slotNames, slotName)
|
||||
}
|
||||
sort.Strings(slotNames)
|
||||
for _, slotName := range slotNames {
|
||||
slot := target.ReferenceSet.Slots[slotName]
|
||||
for _, item := range slot.Items {
|
||||
schemaDigest := ""
|
||||
if item.ArtifactSchema.ID != "" || item.ArtifactSchema.Name != "" || item.ArtifactSchema.Version != "" || len(item.ArtifactSchema.JSONSchema) > 0 {
|
||||
schemaDigest = contracts.DigestArtifactSchema(item.ArtifactSchema)
|
||||
}
|
||||
provenance = append(provenance, artifacts.ReferenceProvenance{
|
||||
Stage: string(target.Stage),
|
||||
StepID: target.StepID,
|
||||
LaneID: target.LaneID,
|
||||
SlotName: item.SlotName,
|
||||
OriginType: item.Origin.Type,
|
||||
OriginURI: item.Origin.URI,
|
||||
Digest: item.Digest,
|
||||
MediaType: item.MediaType,
|
||||
SizeBytes: item.SizeBytes,
|
||||
BindingSource: item.BindingSource,
|
||||
ArtifactKind: string(item.ArtifactKind),
|
||||
SchemaID: item.ArtifactSchema.ID,
|
||||
SchemaName: item.ArtifactSchema.Name,
|
||||
SchemaVersion: item.ArtifactSchema.Version,
|
||||
SchemaDigest: schemaDigest,
|
||||
ProducerPipeline: item.Producer.PipelineID,
|
||||
ProducerStep: item.Producer.StepID,
|
||||
ProducerLane: item.Producer.LaneID,
|
||||
ProducerModule: item.Producer.ModuleKey,
|
||||
})
|
||||
}
|
||||
}
|
||||
return provenance
|
||||
}
|
||||
|
||||
@@ -8,11 +8,9 @@ import (
|
||||
"mime"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/chunkmap"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
@@ -53,7 +51,6 @@ type RunInput struct {
|
||||
SessionID string
|
||||
RunID string
|
||||
StartedAt time.Time
|
||||
LLMProfiles []artifacts.LLMProfileManifest
|
||||
Metadata map[string]any
|
||||
Diagnostics []contracts.ProducerDiagnostic
|
||||
|
||||
@@ -71,20 +68,22 @@ type RunInput struct {
|
||||
}
|
||||
|
||||
type RunOutput struct {
|
||||
FallbackCount int `json:"fallback_count,omitempty"`
|
||||
Manifest artifacts.RunManifest `json:"manifest"`
|
||||
FallbackCount int `json:"fallback_count,omitempty"`
|
||||
|
||||
NormalizeOutputs []contracts.SerializedOutput `json:"normalize_outputs,omitempty"`
|
||||
Rejected []contracts.RejectedOutput `json:"rejected,omitempty"`
|
||||
Diagnostics contracts.DiagnosticCollection `json:"diagnostics,omitempty"`
|
||||
OutputFiles []contracts.OutputFile `json:"-"`
|
||||
|
||||
ValidationSummaries []artifacts.ValidationSummary `json:"validation_summaries,omitempty"`
|
||||
Diagnostics contracts.DiagnosticCollection `json:"diagnostics,omitempty"`
|
||||
OutputFiles []contracts.OutputFile `json:"-"`
|
||||
|
||||
normalizeOutputs []contracts.SerializedOutput
|
||||
normalizeReuseEligibility map[generatedOutputKey]bool
|
||||
diagnosticGroups []contracts.DiagnosticGroup
|
||||
}
|
||||
|
||||
// ArtifactCount counts logical deliverables, not intermediate lane values,
|
||||
// cache entries, diagnostic records, or debug files.
|
||||
func (output RunOutput) ArtifactCount() int {
|
||||
return len(output.OutputFiles)
|
||||
}
|
||||
|
||||
func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err error) {
|
||||
if r == nil {
|
||||
return output, fmt.Errorf("runner must not be nil")
|
||||
@@ -101,12 +100,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
}
|
||||
input.pipeline = input.Prepared.resolved
|
||||
|
||||
output.Manifest = manifestFromPipeline(input)
|
||||
sessionID := strings.TrimSpace(input.SessionID)
|
||||
output.Manifest.Metadata, err = manifestMetadataWithSessionID(output.Manifest.Metadata, sessionID)
|
||||
if err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
debugRecorder := input.Debug
|
||||
if debugRecorder == nil {
|
||||
debugRecorder = NoopDebugRecorder()
|
||||
@@ -124,16 +118,13 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
Payload: map[string]any{
|
||||
"pipeline_id": input.pipeline.ID,
|
||||
"pipeline_digest": input.pipeline.Digest,
|
||||
"run_id": output.Manifest.RunID,
|
||||
"run_id": input.RunID,
|
||||
},
|
||||
}); err != nil {
|
||||
return failOutput(output), fmt.Errorf("write debug run artifact: %w", err)
|
||||
}
|
||||
|
||||
adapter := input.Prepared.input
|
||||
if err := attachModuleManifestMetadata(&output, "input", adapter); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
var doc *source.SourceDocument
|
||||
sourceStarted := time.Now().UTC()
|
||||
if err := writeDebugTimed(debugRecorder, "source/input.json", debugTimedEnvelope{
|
||||
@@ -182,12 +173,8 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
return failOutput(output), fmt.Errorf("write source debug artifact: %w", err)
|
||||
}
|
||||
sourceInput := sourceInputMaterial(input.Path, input.RawInput)
|
||||
output.Manifest.SourceDigests = []string{doc.Digest}
|
||||
|
||||
chunker := input.Prepared.chunker
|
||||
if err := attachModuleManifestMetadata(&output, "chunker", chunker); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
chunkStarted := time.Now().UTC()
|
||||
if err := writeDebugTimed(debugRecorder, "chunk/input.json", debugTimedEnvelope{
|
||||
Stage: string(StageChunk),
|
||||
@@ -264,28 +251,16 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
return failOutput(output), err
|
||||
}
|
||||
|
||||
if len(output.Rejected) > 0 {
|
||||
output.Manifest.ValidationStatus = "rejected"
|
||||
} else if output.FallbackCount > 0 || hasIncompleteValidation(output.ValidationSummaries) {
|
||||
output.Manifest.ValidationStatus = "incomplete"
|
||||
} else {
|
||||
output.Manifest.ValidationStatus = "approved"
|
||||
}
|
||||
populateOutputManifest(&output)
|
||||
output.Manifest.CompletedAt = timePtr(time.Now().UTC())
|
||||
if err := finalizeDiagnostics(&output); err != nil {
|
||||
return failOutput(output), fmt.Errorf("aggregate diagnostics: %w", err)
|
||||
}
|
||||
|
||||
encoder := input.Prepared.output
|
||||
if err := attachModuleManifestMetadata(&output, "output", encoder); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
outputStarted := time.Now().UTC()
|
||||
evidenceArtifact, evidenceSummary, err := buildOutputEvidenceContext(input.Prepared, doc, output.NormalizeOutputs)
|
||||
evidenceArtifact, evidenceSummary, err := buildOutputEvidenceContext(input.Prepared, doc, output.normalizeOutputs)
|
||||
if err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
@@ -306,9 +281,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
}
|
||||
}
|
||||
outputDebugPayload := map[string]any{
|
||||
"manifest": output.Manifest,
|
||||
"normalize_outputs": debugSerializedOutputEnvelopes(output.NormalizeOutputs),
|
||||
"rejected": debugRejectedOutputEnvelopes(output.Rejected),
|
||||
"normalize_outputs": debugSerializedOutputEnvelopes(output.normalizeOutputs),
|
||||
"options": redactSensitiveMap(input.pipeline.Output.Options),
|
||||
"metadata": redactSensitiveMap(input.Metadata),
|
||||
}
|
||||
@@ -326,20 +299,8 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
if err := ctx.Err(); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
outputMetadata, err := cloneMetadata(input.Metadata)
|
||||
if err != nil {
|
||||
return failOutput(output), fmt.Errorf("clone output encoder metadata: %w", err)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return failOutput(output), err
|
||||
}
|
||||
encoded, err := encoder.Encode(ctx, contracts.OutputRequest{
|
||||
Manifest: output.Manifest,
|
||||
NormalizeOutputs: cloneSerializedOutputs(output.NormalizeOutputs),
|
||||
Rejected: cloneRejectedOutputs(output.Rejected),
|
||||
Diagnostics: contracts.CloneDiagnosticCollection(output.Diagnostics),
|
||||
LLMProfile: input.pipeline.Output.LLMProfile,
|
||||
Metadata: outputMetadata,
|
||||
NormalizeOutputs: cloneSerializedOutputs(output.normalizeOutputs),
|
||||
ChunkMap: contracts.CloneSerializedArtifactPointer(acceptedChunkMap),
|
||||
EvidenceContext: contracts.CloneSerializedArtifactPointer(evidenceArtifact),
|
||||
})
|
||||
@@ -371,30 +332,18 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func hasIncompleteValidation(summaries []artifacts.ValidationSummary) bool {
|
||||
for _, summary := range summaries {
|
||||
if summary.Status == "incomplete" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *Runner) runPreparedSteps(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk, output *RunOutput) error {
|
||||
for _, step := range input.Prepared.Steps {
|
||||
stepInput := input
|
||||
stepInput.stepID = step.ID
|
||||
stepReferences, referenceProvenance, err := buildStepReferenceSets(input, step, output.NormalizeOutputs)
|
||||
stepReferences, err := buildStepReferenceSets(input, step, output.normalizeOutputs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("prepare generated references for pipeline step %q: %w", step.ID, err)
|
||||
}
|
||||
stepInput.references = stepReferences
|
||||
stepInput.referenceReuseEligibility = buildStepReferenceReuseEligibility(step, output.normalizeReuseEligibility)
|
||||
output.Manifest.References = append(output.Manifest.References, referenceProvenance...)
|
||||
laneOutput, laneErr := r.runLanes(ctx, stepInput, step, doc, sourceInput, sessionID, chunks)
|
||||
if err := mergeLaneOutput(output, laneOutput); err != nil {
|
||||
return err
|
||||
}
|
||||
mergeLaneOutput(output, laneOutput)
|
||||
if laneErr != nil {
|
||||
return fmt.Errorf("execute pipeline step %q: %w", step.ID, laneErr)
|
||||
}
|
||||
@@ -486,174 +435,14 @@ func startedTime(t time.Time) time.Time {
|
||||
return t.UTC()
|
||||
}
|
||||
|
||||
func manifestFromPipeline(input RunInput) artifacts.RunManifest {
|
||||
startedAt := input.StartedAt
|
||||
if startedAt.IsZero() {
|
||||
startedAt = time.Now().UTC()
|
||||
}
|
||||
runID := strings.TrimSpace(input.RunID)
|
||||
if runID == "" {
|
||||
runID = fmt.Sprintf("run-%d", startedAt.UnixNano())
|
||||
}
|
||||
|
||||
pipeline := input.pipeline
|
||||
manifest := artifacts.RunManifest{
|
||||
PipelineID: pipeline.ID,
|
||||
PipelineDigest: pipeline.Digest,
|
||||
InputModule: pipeline.Input.Module,
|
||||
Chunker: pipeline.Chunk.Module,
|
||||
ChunkPlan: &artifacts.ChunkPlanManifest{
|
||||
Mode: string(pipeline.ChunkControls.Cache),
|
||||
RequestedModule: pipeline.Chunk.Module,
|
||||
},
|
||||
OutputEncoder: pipeline.Output.Module,
|
||||
ArtifactLanes: make([]artifacts.ArtifactLaneManifest, 0, len(pipeline.AllArtifactLanes())),
|
||||
ValidatorChains: validatorChainManifests(pipeline.ValidatorChains),
|
||||
RunID: runID,
|
||||
StartedAt: timePtr(startedAt),
|
||||
References: ReferenceProvenance(pipeline),
|
||||
LLMProfiles: cloneLLMProfiles(input.LLMProfiles),
|
||||
}
|
||||
for _, lane := range pipeline.AllArtifactLanes() {
|
||||
laneManifest := artifacts.ArtifactLaneManifest{
|
||||
StepID: lane.StepID,
|
||||
ID: lane.ID,
|
||||
Extractor: lane.Extract.Module,
|
||||
Merger: lane.Merge.Module,
|
||||
Normalizer: lane.Normalize.Module,
|
||||
}
|
||||
manifest.ArtifactLanes = append(manifest.ArtifactLanes, laneManifest)
|
||||
}
|
||||
return manifest
|
||||
}
|
||||
|
||||
func validatorChainManifests(chains []ResolvedValidatorChain) []artifacts.ValidatorChainManifest {
|
||||
if len(chains) == 0 {
|
||||
return nil
|
||||
}
|
||||
manifests := make([]artifacts.ValidatorChainManifest, 0, len(chains))
|
||||
for _, chain := range chains {
|
||||
manifest := artifacts.ValidatorChainManifest{
|
||||
Stage: string(chain.Stage),
|
||||
LaneID: chain.LaneID,
|
||||
ModuleKey: chain.ModuleKey,
|
||||
Validators: make([]artifacts.ValidatorManifest, 0, len(chain.Validators)),
|
||||
}
|
||||
for _, validator := range chain.Validators {
|
||||
manifest.Validators = append(manifest.Validators, artifacts.ValidatorManifest{
|
||||
Key: validator.Binding.Module,
|
||||
ExecutionClass: string(validator.ExecutionClass),
|
||||
})
|
||||
}
|
||||
manifests = append(manifests, manifest)
|
||||
}
|
||||
return manifests
|
||||
}
|
||||
|
||||
func failOutput(output RunOutput) RunOutput {
|
||||
// Preserve any diagnostics already accepted by the pipeline when a later
|
||||
// operation fails. Producers and validators validate each diagnostic before
|
||||
// it is appended, so finalization here cannot introduce a new failure path.
|
||||
_ = finalizeDiagnostics(&output)
|
||||
if output.Manifest.PipelineID != "" {
|
||||
populateOutputManifest(&output)
|
||||
output.Manifest.ValidationStatus = "failed"
|
||||
output.Manifest.CompletedAt = timePtr(time.Now().UTC())
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func populateOutputManifest(output *RunOutput) {
|
||||
if output == nil {
|
||||
return
|
||||
}
|
||||
output.Manifest.NormalizedOutputs = normalizedOutputManifests(output.NormalizeOutputs)
|
||||
output.Manifest.RejectedOutputs = rejectedOutputManifests(output.Rejected)
|
||||
if len(output.ValidationSummaries) > 0 {
|
||||
output.Manifest.ValidationSummaries = cloneValidationSummaries(output.ValidationSummaries)
|
||||
}
|
||||
}
|
||||
|
||||
func normalizedOutputManifests(outputs []contracts.SerializedOutput) []artifacts.NormalizedOutputManifest {
|
||||
if len(outputs) == 0 {
|
||||
return nil
|
||||
}
|
||||
manifests := make([]artifacts.NormalizedOutputManifest, 0, len(outputs))
|
||||
for _, output := range outputs {
|
||||
manifests = append(manifests, artifacts.NormalizedOutputManifest{
|
||||
StepID: output.StepID,
|
||||
LaneID: output.LaneID,
|
||||
ModuleKey: output.NormalizerKey,
|
||||
SourceID: output.SourceID,
|
||||
MediaType: output.Artifact.MediaType,
|
||||
Schema: artifacts.OutputSchemaProvenance{
|
||||
ID: output.Artifact.Schema.ID,
|
||||
Name: output.Artifact.Schema.Name,
|
||||
Version: output.Artifact.Schema.Version,
|
||||
},
|
||||
})
|
||||
}
|
||||
return manifests
|
||||
}
|
||||
|
||||
func rejectedOutputManifests(rejected []contracts.RejectedOutput) []artifacts.RejectedOutputManifest {
|
||||
if len(rejected) == 0 {
|
||||
return nil
|
||||
}
|
||||
manifests := make([]artifacts.RejectedOutputManifest, 0, len(rejected))
|
||||
for _, output := range rejected {
|
||||
manifests = append(manifests, artifacts.RejectedOutputManifest{
|
||||
Stage: output.Stage,
|
||||
StepID: output.StepID,
|
||||
LaneID: output.LaneID,
|
||||
ModuleKey: output.ModuleKey,
|
||||
ChunkID: output.ChunkID,
|
||||
ChunkIndex: output.ChunkIndex,
|
||||
ValidatorName: output.ValidatorName,
|
||||
ReasonCode: output.ReasonCode,
|
||||
Message: output.Message,
|
||||
AttemptCount: output.AttemptCount,
|
||||
DiagnosticArtifactPath: output.DiagnosticArtifactPath,
|
||||
Validation: cloneValidationSummaryPtr(output.Validation),
|
||||
})
|
||||
}
|
||||
return manifests
|
||||
}
|
||||
|
||||
func attachModuleManifestMetadata(output *RunOutput, moduleKey string, module any) error {
|
||||
if output == nil {
|
||||
return nil
|
||||
}
|
||||
metadata, ok, err := moduleManifestMetadata(module)
|
||||
if err != nil {
|
||||
return fmt.Errorf("clone manifest metadata for module %q: %w", moduleKey, err)
|
||||
}
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if output.Manifest.ModuleMetadata == nil {
|
||||
output.Manifest.ModuleMetadata = make(map[string]map[string]any)
|
||||
}
|
||||
output.Manifest.ModuleMetadata[moduleKey] = metadata
|
||||
return nil
|
||||
}
|
||||
|
||||
func moduleManifestMetadata(module any) (map[string]any, bool, error) {
|
||||
provider, ok := module.(contracts.ManifestMetadataProvider)
|
||||
if !ok {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
moduleMetadata, err := cloneMetadata(provider.ManifestMetadata())
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if len(moduleMetadata) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
return moduleMetadata, true, nil
|
||||
}
|
||||
|
||||
func outputFilesFromResult(result contracts.OutputResult) ([]contracts.OutputFile, error) {
|
||||
out := make([]contracts.OutputFile, 0, len(result.Files))
|
||||
for _, file := range result.Files {
|
||||
@@ -693,48 +482,6 @@ func cloneMetadata(metadata map[string]any) (map[string]any, error) {
|
||||
return source.CloneMetadata(metadata)
|
||||
}
|
||||
|
||||
func cloneLLMProfiles(profiles []artifacts.LLMProfileManifest) []artifacts.LLMProfileManifest {
|
||||
if len(profiles) == 0 {
|
||||
return nil
|
||||
}
|
||||
return append([]artifacts.LLMProfileManifest(nil), profiles...)
|
||||
}
|
||||
|
||||
func llmProfileManifests(client contracts.StructuredLLMClient) []artifacts.LLMProfileManifest {
|
||||
provider, ok := client.(contracts.LLMProfileManifestProvider)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return provider.LLMProfileManifests()
|
||||
}
|
||||
|
||||
func mergeLLMProfileManifests(sources ...[]artifacts.LLMProfileManifest) []artifacts.LLMProfileManifest {
|
||||
merged := make(map[string]artifacts.LLMProfileManifest)
|
||||
for _, source := range sources {
|
||||
for _, profile := range source {
|
||||
profile = profile.Normalized()
|
||||
key := profile.IdentityKey()
|
||||
if _, exists := merged[key]; exists {
|
||||
continue
|
||||
}
|
||||
merged[key] = profile
|
||||
}
|
||||
}
|
||||
if len(merged) == 0 {
|
||||
return nil
|
||||
}
|
||||
keys := make([]string, 0, len(merged))
|
||||
for key := range merged {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
out := make([]artifacts.LLMProfileManifest, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
out = append(out, merged[key])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func sourceInputMaterial(inputPath string, content []byte) contracts.LLMInputMaterial {
|
||||
return contracts.NewLLMInputMaterial(
|
||||
"source",
|
||||
@@ -779,21 +526,6 @@ func sourceInputOriginURI(inputPath string) string {
|
||||
return fileURI(inputPath)
|
||||
}
|
||||
|
||||
func manifestMetadataWithSessionID(metadata map[string]any, sessionID string) (map[string]any, error) {
|
||||
out, err := cloneMetadata(metadata)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("clone run manifest metadata: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(sessionID) == "" {
|
||||
return out, nil
|
||||
}
|
||||
if out == nil {
|
||||
out = make(map[string]any)
|
||||
}
|
||||
out["session_id"] = sessionID
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func cloneSourceChunkPtr(chunk *source.Chunk) (*source.Chunk, error) {
|
||||
if chunk == nil {
|
||||
return nil, nil
|
||||
@@ -861,38 +593,3 @@ func cloneSerializedOutputs(outputs []contracts.SerializedOutput) []contracts.Se
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func cloneRejectedOutputs(rejected []contracts.RejectedOutput) []contracts.RejectedOutput {
|
||||
if len(rejected) == 0 {
|
||||
return nil
|
||||
}
|
||||
cloned := make([]contracts.RejectedOutput, len(rejected))
|
||||
for index, item := range rejected {
|
||||
cloned[index] = item
|
||||
cloned[index].Validation = cloneValidationSummaryPtr(item.Validation)
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
func cloneValidationSummaryPtr(summary *artifacts.ValidationSummary) *artifacts.ValidationSummary {
|
||||
if summary == nil {
|
||||
return nil
|
||||
}
|
||||
cloned := artifacts.CloneValidationSummary(*summary)
|
||||
return &cloned
|
||||
}
|
||||
|
||||
func cloneValidationSummaries(summaries []artifacts.ValidationSummary) []artifacts.ValidationSummary {
|
||||
if len(summaries) == 0 {
|
||||
return nil
|
||||
}
|
||||
cloned := make([]artifacts.ValidationSummary, len(summaries))
|
||||
for index, summary := range summaries {
|
||||
cloned[index] = artifacts.CloneValidationSummary(summary)
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
func timePtr(t time.Time) *time.Time {
|
||||
return &t
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ func TestRunnerReusesAcceptedPredecessorAfterDownstreamFailure(t *testing.T) {
|
||||
}
|
||||
first = false
|
||||
output, err := New().Run(context.Background(), input)
|
||||
if err != nil || len(output.NormalizeOutputs) != 2 || calls != 1 || store.reads != 2 || store.writes != 1 || output.FallbackCount != 0 {
|
||||
t.Fatalf("rerun=%v outputs=%d calls=%d cache=%d/%d", err, len(output.NormalizeOutputs), calls, store.reads, store.writes)
|
||||
if err != nil || len(output.normalizeOutputs) != 2 || calls != 1 || store.reads != 2 || store.writes != 1 || output.FallbackCount != 0 {
|
||||
t.Fatalf("rerun=%v outputs=%d calls=%d cache=%d/%d", err, len(output.normalizeOutputs), calls, store.reads, store.writes)
|
||||
}
|
||||
var decisions []string
|
||||
for _, observation := range observations {
|
||||
@@ -86,8 +86,8 @@ func TestRunnerCacheWarningsDoNotFailSuccessfulPublication(t *testing.T) {
|
||||
profile := typedResolutionProfile()
|
||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "native", probe: newRunnerProbe(), native: true})}
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, engine), RawInput: []byte("input"), Cache: store, Workers: 1})
|
||||
if err != nil || len(output.NormalizeOutputs) != 1 || output.FallbackCount != 0 {
|
||||
t.Fatalf("cache warnings failed successful work: %v, outputs=%d", err, len(output.NormalizeOutputs))
|
||||
if err != nil || len(output.normalizeOutputs) != 1 || output.FallbackCount != 0 {
|
||||
t.Fatalf("cache warnings failed successful work: %v, outputs=%d", err, len(output.normalizeOutputs))
|
||||
}
|
||||
projection, err := contracts.ProjectDiagnosticCollection(output.Diagnostics)
|
||||
if err != nil || projection.WarningOccurrenceCount != 2 {
|
||||
@@ -237,10 +237,10 @@ func TestRunnerCachesAppliedMergeAndNormalizationArtifacts(t *testing.T) {
|
||||
}
|
||||
for range 2 {
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, Cache: store, RawInput: []byte("input"), Workers: 1})
|
||||
if err != nil || len(output.NormalizeOutputs) != 2 {
|
||||
t.Fatalf("cached %s execution: %v, outputs %d", role, err, len(output.NormalizeOutputs))
|
||||
if err != nil || len(output.normalizeOutputs) != 2 {
|
||||
t.Fatalf("cached %s execution: %v, outputs %d", role, err, len(output.normalizeOutputs))
|
||||
}
|
||||
value, err := notesCodec().Decode(output.NormalizeOutputs[0].Artifact.Content)
|
||||
value, err := notesCodec().Decode(output.normalizeOutputs[0].Artifact.Content)
|
||||
if err != nil || !reflect.DeepEqual(value.Items, []string{"applied"}) {
|
||||
t.Fatalf("applied artifact changed on reuse: %#v, %v", value, err)
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ func TestRunnerExecutesOrderedStepsWithHardBarriers(t *testing.T) {
|
||||
if want := []string{"first-normalize-done", "second-extract-started"}; !reflect.DeepEqual(gotEvents, want) {
|
||||
t.Fatalf("ordered events = %#v, want %#v", gotEvents, want)
|
||||
}
|
||||
if got := []string{output.NormalizeOutputs[0].LaneID, output.NormalizeOutputs[1].LaneID}; !reflect.DeepEqual(got, []string{"notes", "score"}) {
|
||||
if got := []string{output.normalizeOutputs[0].LaneID, output.normalizeOutputs[1].LaneID}; !reflect.DeepEqual(got, []string{"notes", "score"}) {
|
||||
t.Fatalf("normalized lane order = %#v, want notes then score", got)
|
||||
}
|
||||
}
|
||||
@@ -290,8 +290,8 @@ func TestRunnerStopsLaterOrderedStepsAfterFailure(t *testing.T) {
|
||||
if err == nil || !strings.Contains(err.Error(), `execute pipeline step "step-2"`) {
|
||||
t.Fatalf("Run() error = %v, want step-scoped failure", err)
|
||||
}
|
||||
if len(output.NormalizeOutputs) != 1 || output.NormalizeOutputs[0].LaneID != "first" {
|
||||
t.Fatalf("completed outputs = %#v, want only the first step output", output.NormalizeOutputs)
|
||||
if len(output.normalizeOutputs) != 1 || output.normalizeOutputs[0].LaneID != "first" {
|
||||
t.Fatalf("completed outputs = %#v, want only the first step output", output.normalizeOutputs)
|
||||
}
|
||||
if got := thirdCalls.Load(); got != 0 {
|
||||
t.Fatalf("later step extract calls = %d, want zero", got)
|
||||
@@ -436,8 +436,8 @@ func TestRunnerBoundsConcurrentLaneContinuations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
if len(output.NormalizeOutputs) != len(lanes) {
|
||||
t.Fatalf("normalize outputs = %d, want %d", len(output.NormalizeOutputs), len(lanes))
|
||||
if len(output.normalizeOutputs) != len(lanes) {
|
||||
t.Fatalf("normalize outputs = %d, want %d", len(output.normalizeOutputs), len(lanes))
|
||||
}
|
||||
if got := maximum.Load(); got != 2 {
|
||||
t.Fatalf("maximum concurrent lane continuations = %d, want 2", got)
|
||||
|
||||
@@ -61,8 +61,8 @@ type orderedRunError struct {
|
||||
}
|
||||
|
||||
func (r *Runner) runLanes(parent context.Context, input RunInput, step PreparedPipelineStep, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk) (RunOutput, error) {
|
||||
output := RunOutput{Manifest: manifestFromPipeline(input)}
|
||||
states, err := initializeLaneStates(input, step, chunks, &output)
|
||||
output := RunOutput{}
|
||||
states, err := initializeLaneStates(input, step, chunks)
|
||||
if err != nil {
|
||||
return output, err
|
||||
}
|
||||
@@ -70,24 +70,19 @@ func (r *Runner) runLanes(parent context.Context, input RunInput, step PreparedP
|
||||
input: input, doc: doc,
|
||||
sourceInput: sourceInput, sessionID: sessionID, chunks: chunks, states: states,
|
||||
})
|
||||
if err := mergeCompletedLanes(&output, completedOutputs); err != nil {
|
||||
return output, err
|
||||
}
|
||||
mergeCompletedLanes(&output, completedOutputs)
|
||||
if err := selectRunError(parent, runErrors); err != nil {
|
||||
return output, err
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func initializeLaneStates(input RunInput, step PreparedPipelineStep, chunks []source.Chunk, output *RunOutput) ([]*laneExtractState, error) {
|
||||
func initializeLaneStates(input RunInput, step PreparedPipelineStep, chunks []source.Chunk) ([]*laneExtractState, error) {
|
||||
states := make([]*laneExtractState, len(step.lanes))
|
||||
for i, prepared := range step.lanes {
|
||||
if prepared.typed == nil {
|
||||
return nil, fmt.Errorf("typed lane %q executor is not prepared", prepared.resolved.ID)
|
||||
}
|
||||
if err := setTypedLaneManifestMetadata(output, prepared.resolved.ID, prepared.typed.extractor, prepared.typed.merger, prepared.typed.normalizer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
states[i] = &laneExtractState{index: i, prepared: prepared, reuseEligible: !input.reuseIneligible && referenceTargetReuseEligible(input, prepared.resolved.ExtractReferences), remaining: len(chunks), results: make(map[int]extractJobResult, len(chunks))}
|
||||
}
|
||||
return states, nil
|
||||
@@ -263,13 +258,10 @@ func (e *laneEngine) handleCompletion(completion laneCompletion) {
|
||||
}
|
||||
}
|
||||
|
||||
func mergeCompletedLanes(output *RunOutput, completedOutputs []RunOutput) error {
|
||||
func mergeCompletedLanes(output *RunOutput, completedOutputs []RunOutput) {
|
||||
for i := range completedOutputs {
|
||||
if err := mergeLaneOutput(output, completedOutputs[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
mergeLaneOutput(output, completedOutputs[i])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Runner) runExtractJob(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, job extractJob) extractJobResult {
|
||||
@@ -349,7 +341,7 @@ func finalizeLaneExtract(state *laneExtractState) {
|
||||
|
||||
func (r *Runner) continueLane(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk, state *laneExtractState) (RunOutput, error) {
|
||||
lane := state.prepared.resolved
|
||||
local := RunOutput{Manifest: manifestFromPipeline(input), FallbackCount: state.fallbackCount}
|
||||
local := RunOutput{FallbackCount: state.fallbackCount}
|
||||
results := finalizedExtractResults{
|
||||
accepted: state.values,
|
||||
diagnostics: state.diagnostics,
|
||||
@@ -426,15 +418,13 @@ func selectRunError(parent context.Context, values []orderedRunError) error {
|
||||
return filtered[0].err
|
||||
}
|
||||
|
||||
func mergeLaneOutput(dst *RunOutput, src RunOutput) error {
|
||||
func mergeLaneOutput(dst *RunOutput, src RunOutput) {
|
||||
if dst == nil {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
dst.FallbackCount += src.FallbackCount
|
||||
dst.NormalizeOutputs = append(dst.NormalizeOutputs, cloneSerializedOutputs(src.NormalizeOutputs)...)
|
||||
dst.Rejected = append(dst.Rejected, cloneRejectedOutputs(src.Rejected)...)
|
||||
dst.normalizeOutputs = append(dst.normalizeOutputs, cloneSerializedOutputs(src.normalizeOutputs)...)
|
||||
appendDiagnosticGroups(dst, src.diagnosticGroups)
|
||||
dst.ValidationSummaries = append(dst.ValidationSummaries, cloneValidationSummaries(src.ValidationSummaries)...)
|
||||
if len(src.normalizeReuseEligibility) > 0 {
|
||||
if dst.normalizeReuseEligibility == nil {
|
||||
dst.normalizeReuseEligibility = make(map[generatedOutputKey]bool, len(src.normalizeReuseEligibility))
|
||||
@@ -443,16 +433,4 @@ func mergeLaneOutput(dst *RunOutput, src RunOutput) error {
|
||||
dst.normalizeReuseEligibility[key] = eligible
|
||||
}
|
||||
}
|
||||
for i := range dst.Manifest.ArtifactLanes {
|
||||
for j := range src.Manifest.ArtifactLanes {
|
||||
if dst.Manifest.ArtifactLanes[i].ID == src.Manifest.ArtifactLanes[j].ID && dst.Manifest.ArtifactLanes[i].StepID == src.Manifest.ArtifactLanes[j].StepID && src.Manifest.ArtifactLanes[j].Metadata != nil {
|
||||
metadata, err := cloneMetadata(src.Manifest.ArtifactLanes[j].Metadata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("clone lane %q manifest metadata: %w", dst.Manifest.ArtifactLanes[i].ID, err)
|
||||
}
|
||||
dst.Manifest.ArtifactLanes[i].Metadata = metadata
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -177,8 +177,8 @@ func TestRunnerPropagatesLaneFallbackWithoutCountingDependents(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if output.FallbackCount != 1 || len(output.NormalizeOutputs) != 2 {
|
||||
t.Fatalf("fallback count=%d, outputs=%d", output.FallbackCount, len(output.NormalizeOutputs))
|
||||
if output.FallbackCount != 1 || len(output.normalizeOutputs) != 2 {
|
||||
t.Fatalf("fallback count=%d, outputs=%d", output.FallbackCount, len(output.normalizeOutputs))
|
||||
}
|
||||
after := false
|
||||
for _, role := range []ModuleStage{StageExtract, StageMerge, StageNormalize} {
|
||||
@@ -245,7 +245,7 @@ func TestRunnerAssessesNativeRevisionsWithoutOuterRevalidation(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if providerCalls != 2 || output.FallbackCount != 0 || len(output.NormalizeOutputs) != 1 {
|
||||
if providerCalls != 2 || output.FallbackCount != 0 || len(output.normalizeOutputs) != 1 {
|
||||
t.Fatalf("native calls=%d, output=%#v", providerCalls, output)
|
||||
}
|
||||
for _, key := range []string{"first/0", "second/0", "first/1", "second/1", "native/extract", "native/merge", "native/normalize"} {
|
||||
@@ -276,8 +276,8 @@ func TestRunnerGeneratedFallbackReferencesTaintOnlyActualConsumers(t *testing.T)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if output.FallbackCount != 1 || len(output.NormalizeOutputs) != 4 || probe.calls["consumer/reference"] != 1 {
|
||||
t.Fatalf("handoff failed: count=%d outputs=%d observations=%#v", output.FallbackCount, len(output.NormalizeOutputs), probe.calls)
|
||||
if output.FallbackCount != 1 || len(output.normalizeOutputs) != 4 || probe.calls["consumer/reference"] != 1 {
|
||||
t.Fatalf("handoff failed: count=%d outputs=%d observations=%#v", output.FallbackCount, len(output.normalizeOutputs), probe.calls)
|
||||
}
|
||||
for _, key := range []string{"earlier/extract", "earlier/merge", "earlier/normalize", "later/extract", "later/merge", "later/normalize", "consumer/extract"} {
|
||||
if !reflect.DeepEqual(probe.eligible[key], []bool{true}) {
|
||||
@@ -318,7 +318,7 @@ func TestRunnerChunkFallbackTaintsEveryDerivedOperation(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if output.FallbackCount != 1 || len(output.NormalizeOutputs) != 1 {
|
||||
if output.FallbackCount != 1 || len(output.normalizeOutputs) != 1 {
|
||||
t.Fatalf("chunk fallback = %#v", output)
|
||||
}
|
||||
for _, role := range []string{"extract", "merge", "normalize"} {
|
||||
@@ -353,7 +353,7 @@ func TestRunnerDoesNotAcceptModuleFallbackUnderStrictControls(t *testing.T) {
|
||||
profile.Chunk = Binding("fallback-chunk")
|
||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "notes", probe: probe})}
|
||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
||||
if err == nil || output.FallbackCount != 0 || len(output.NormalizeOutputs) != 0 || probe.calls["notes/extract"] != 0 {
|
||||
if err == nil || output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 || probe.calls["notes/extract"] != 0 {
|
||||
t.Fatalf("strict controls accepted module fallback: %#v %v", output, err)
|
||||
}
|
||||
}
|
||||
@@ -367,7 +367,7 @@ func TestRunnerDiscardsDeterministicOutputReturnedAfterCancellation(t *testing.T
|
||||
profile := typedResolutionProfile()
|
||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": lane}
|
||||
output, err := New().Run(ctx, RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
||||
if !errors.Is(err, context.Canceled) || output.FallbackCount != 0 || len(output.NormalizeOutputs) != 0 || probe.calls["notes/merge"] != 0 || probe.calls["notes/extract/fallback"] != 0 {
|
||||
if !errors.Is(err, context.Canceled) || output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 || probe.calls["notes/merge"] != 0 || probe.calls["notes/extract/fallback"] != 0 {
|
||||
t.Fatalf("cancellation = %#v %v, calls %#v", output, err, probe.calls)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,9 +56,6 @@ func (r *Runner) continueTypedLane(ctx context.Context, input RunInput, doc *sou
|
||||
if prepared.typed == nil {
|
||||
return fmt.Errorf("typed lane %q executor is not prepared", lane.ID)
|
||||
}
|
||||
if err := setTypedLaneManifestMetadata(output, lane.ID, prepared.typed.extractor, prepared.typed.merger, prepared.typed.normalizer); err != nil {
|
||||
return err
|
||||
}
|
||||
merged, err := r.runMergeStage(ctx, input, doc, sourceInput, sessionID, prepared, extracts, output)
|
||||
if err != nil {
|
||||
return &laneRunError{stage: StageMerge, err: err}
|
||||
@@ -68,7 +65,7 @@ func (r *Runner) continueTypedLane(ctx context.Context, input RunInput, doc *sou
|
||||
return &laneRunError{stage: StageNormalize, err: err}
|
||||
}
|
||||
if normalized.accepted {
|
||||
output.NormalizeOutputs = append(output.NormalizeOutputs, contracts.SerializedOutput{StepID: input.stepID, LaneID: lane.ID, NormalizerKey: lane.Normalize.Module, SourceID: doc.ID, Artifact: contracts.CloneSerializedArtifact(normalized.serialized)})
|
||||
output.normalizeOutputs = append(output.normalizeOutputs, contracts.SerializedOutput{StepID: input.stepID, LaneID: lane.ID, NormalizerKey: lane.Normalize.Module, SourceID: doc.ID, Artifact: contracts.CloneSerializedArtifact(normalized.serialized)})
|
||||
if output.normalizeReuseEligibility == nil {
|
||||
output.normalizeReuseEligibility = make(map[generatedOutputKey]bool)
|
||||
}
|
||||
@@ -184,32 +181,3 @@ func (r *Runner) runNormalizeStage(ctx context.Context, input RunInput, doc *sou
|
||||
}
|
||||
return state, nil
|
||||
}
|
||||
|
||||
func setTypedLaneManifestMetadata(output *RunOutput, laneID string, extractor, merger, normalizer any) error {
|
||||
if output == nil {
|
||||
return nil
|
||||
}
|
||||
for i := range output.Manifest.ArtifactLanes {
|
||||
if output.Manifest.ArtifactLanes[i].ID != laneID {
|
||||
continue
|
||||
}
|
||||
metadata := make(map[string]any)
|
||||
for _, item := range []struct {
|
||||
name string
|
||||
module any
|
||||
}{{"extractor", extractor}, {"merger", merger}, {"normalizer", normalizer}} {
|
||||
value, ok, err := moduleManifestMetadata(item.module)
|
||||
if err != nil {
|
||||
return fmt.Errorf("clone %s manifest metadata for lane %q: %w", item.name, laneID, err)
|
||||
}
|
||||
if ok {
|
||||
metadata[item.name] = value
|
||||
}
|
||||
}
|
||||
if len(metadata) > 0 {
|
||||
output.Manifest.ArtifactLanes[i].Metadata = metadata
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -195,8 +195,8 @@ func TestRunExecutesHeterogeneousTypedLanes(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
if len(output.NormalizeOutputs) != 2 {
|
||||
t.Fatalf("normalize outputs = %#v, want two typed lane results", output.NormalizeOutputs)
|
||||
if len(output.normalizeOutputs) != 2 {
|
||||
t.Fatalf("normalize outputs = %#v, want two typed lane results", output.normalizeOutputs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user