Hand checked processing selections to execution
This commit is contained in:
@@ -2,9 +2,11 @@ package preflight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -34,7 +36,7 @@ func TestLaterEmptyGlossaryFailsBeforeOutputPreparation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEmptyPipelineNeedsNoProfile(t *testing.T) {
|
||||
if err := CheckReadiness(context.Background(), &config.Config{}, nil); err != nil {
|
||||
if _, err := ProcessingPlan(context.Background(), &config.Config{}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -48,7 +50,7 @@ func TestCorrectionRepairReadinessDependsOnBudget(t *testing.T) {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := CheckReadiness(context.Background(), cfg, inspect); err != nil {
|
||||
if _, err := ProcessingPlan(context.Background(), cfg, inspect); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg.Pipeline.Stages[0].LLM.CorrectionRepairAttempts = 1
|
||||
@@ -61,3 +63,55 @@ func TestCorrectionRepairReadinessDependsOnBudget(t *testing.T) {
|
||||
t.Fatalf("output exists: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessingPlanReusesOnlyMatchingGlossaryViews(t *testing.T) {
|
||||
profile := "selected"
|
||||
item := config.Stage{Module: "grammar", Glossaries: []string{"a", "b"}, ProtectedTerms: []string{"a"},
|
||||
LLM: config.LLM{ProposalProfile: &profile, ValidationProfile: &profile}}
|
||||
reversed := item
|
||||
reversed.Glossaries = []string{"b", "a"}
|
||||
exempt := item
|
||||
exempt.Module = "glossary"
|
||||
cfg := &config.Config{
|
||||
GlossaryCollections: map[string]config.GlossaryCollection{
|
||||
"a": {Entries: []config.GlossaryEntry{{ID: "a", Name: "A"}}},
|
||||
"b": {Entries: []config.GlossaryEntry{{ID: "b", Name: "B"}}},
|
||||
},
|
||||
Pipeline: config.Pipeline{Stages: []config.Stage{item, item, reversed, exempt}},
|
||||
}
|
||||
var inspected []string
|
||||
plan, err := ProcessingPlan(context.Background(), cfg, func(_ context.Context, id string) error {
|
||||
inspected = append(inspected, id)
|
||||
return nil
|
||||
})
|
||||
if err != nil || len(plan) != 4 || !slices.Equal(inspected, []string{profile}) {
|
||||
t.Fatalf("plan=%+v inspections=%v error=%v", plan, inspected, err)
|
||||
}
|
||||
if plan[0].GlossaryView != plan[1].GlossaryView || plan[0].GlossaryVariables != plan[1].GlossaryVariables ||
|
||||
plan[0].GlossaryView == plan[2].GlossaryView || plan[0].GlossaryView == plan[3].GlossaryView ||
|
||||
plan[2].Glossary[0].ID != "b" || plan[3].GlossaryVariables.ProtectionJSON != "[]" {
|
||||
t.Fatalf("incorrect glossary reuse or exemptions: %+v", plan)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessingPlanPreservesFirstInspectionFailureAndCause(t *testing.T) {
|
||||
proposal, validation := "proposal", "bad"
|
||||
cfg := &config.Config{Pipeline: config.Pipeline{Stages: []config.Stage{
|
||||
{Module: "grammar", LLM: config.LLM{ProposalProfile: &proposal, ValidationProfile: &validation}},
|
||||
{Module: "grammar"},
|
||||
}}}
|
||||
runtimeErr := errors.New("inspection failed")
|
||||
var checked []string
|
||||
_, err := ProcessingPlan(context.Background(), cfg, func(_ context.Context, id string) error {
|
||||
checked = append(checked, id)
|
||||
if id == validation {
|
||||
return runtimeErr
|
||||
}
|
||||
return nil
|
||||
})
|
||||
var selection *SelectionError
|
||||
if !errors.Is(err, runtimeErr) || errors.As(err, &selection) || !strings.Contains(err.Error(), "stage 1 (grammar) validation") ||
|
||||
!slices.Equal(checked, []string{proposal, validation}) {
|
||||
t.Fatalf("inspected %v, error %v", checked, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user