64 lines
2.5 KiB
Go
64 lines
2.5 KiB
Go
package preflight
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/config"
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/diagnostics"
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
|
)
|
|
|
|
func TestLaterEmptyGlossaryFailsBeforeOutputPreparation(t *testing.T) {
|
|
profile, id := "selected", "spells"
|
|
cfg := &config.Config{Pipeline: config.Pipeline{Stages: []config.Stage{
|
|
{Module: "grammar", LLM: config.LLM{ProposalProfile: &profile, ValidationProfile: &profile}},
|
|
{Module: "glossary", ID: &id, Glossaries: []string{"empty"}, LLM: config.LLM{ProposalProfile: &profile, ValidationProfile: &profile}},
|
|
}}}
|
|
output := filepath.Join(t.TempDir(), "transcript.json")
|
|
calls := 0
|
|
_, err := Prepare(context.Background(), Input{Config: cfg, Transcript: &schema.SourceTranscript{}, Output: diagnostics.OutputSelection{TranscriptPath: output}, InspectProfile: func(context.Context, string) error { calls++; return nil }})
|
|
if err == nil || !strings.Contains(err.Error(), "stage 2") || !strings.Contains(err.Error(), "spells") || !strings.Contains(err.Error(), "empty") {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if calls != 0 {
|
|
t.Fatal("inspected profiles before checking all glossary selections")
|
|
}
|
|
if _, err := os.Stat(output); !os.IsNotExist(err) {
|
|
t.Fatalf("output exists: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestEmptyPipelineNeedsNoProfile(t *testing.T) {
|
|
if err := CheckReadiness(context.Background(), &config.Config{}, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestCorrectionRepairReadinessDependsOnBudget(t *testing.T) {
|
|
proposal, repair := "proposal", "missing"
|
|
cfg := &config.Config{Pipeline: config.Pipeline{Stages: []config.Stage{{Module: "grammar", LLM: config.LLM{ProposalProfile: &proposal, ValidationProfile: &proposal, CorrectionRepairProfile: &repair}}}}}
|
|
inspect := func(_ context.Context, id string) error {
|
|
if id == repair {
|
|
return fmt.Errorf("unknown profile")
|
|
}
|
|
return nil
|
|
}
|
|
if err := CheckReadiness(context.Background(), cfg, inspect); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg.Pipeline.Stages[0].LLM.CorrectionRepairAttempts = 1
|
|
output := filepath.Join(t.TempDir(), "transcript.json")
|
|
_, err := Prepare(context.Background(), Input{Config: cfg, Transcript: &schema.SourceTranscript{}, Output: diagnostics.OutputSelection{TranscriptPath: output}, InspectProfile: inspect})
|
|
if err == nil || !strings.Contains(err.Error(), "correction repair") {
|
|
t.Fatalf("readiness error: %v", err)
|
|
}
|
|
if _, err := os.Stat(output); !os.IsNotExist(err) {
|
|
t.Fatalf("output exists: %v", err)
|
|
}
|
|
}
|