Unify optional interaction capture and warnings
This commit is contained in:
@@ -2,8 +2,10 @@ package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -11,7 +13,9 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/glossary"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/llm"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/proposals"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/validators"
|
||||
validatormetadata "gitea.maximumdirect.net/eric/audita/v3/internal/validators/metadata"
|
||||
)
|
||||
@@ -99,11 +103,12 @@ func TestRevalidationArtifactsUseProposalAndAttemptCoordinates(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dir := t.TempDir()
|
||||
attempt := 1
|
||||
attempt, section := 1, 4
|
||||
sink := llm.NewDiagnosticsWriter(dir)
|
||||
var paths []string
|
||||
for _, index := range []int{2, 3} {
|
||||
candidate := proposals.EnrichedCorrectionProposal{CorrectionProposal: proposals.CorrectionProposal{TargetSegmentID: 1, OriginalText: "cat", CorrectedText: "dog"}, ProposalMetadata: proposals.ProposalMetadata{ProposalIndex: index}}
|
||||
input := validateSectionCandidatesInput{Spec: contracts.ModuleRunSpec{ModuleKey: "grammar", InstanceName: "grammar_1", Settings: config.Stage{LLM: config.LLM{CorrectionRepairAttempts: 1}}}, Policy: proposals.ReplacementPolicyRequireUnique, WorkingTranscript: &schema.Transcript{Segments: []schema.Segment{{ID: 1, Text: "cat"}}}, Validators: []contracts.Validator{validator}, SectionEnriched: []proposals.EnrichedCorrectionProposal{candidate}, ValidationLLMClient: client, DiagnosticsDir: dir, RepairProposalIndex: &index, RepairAttempt: &attempt}
|
||||
input := validateSectionCandidatesInput{Spec: contracts.ModuleRunSpec{ModuleKey: "grammar", InstanceName: "grammar_1", Settings: config.Stage{LLM: config.LLM{CorrectionRepairAttempts: 1}}}, Policy: proposals.ReplacementPolicyRequireUnique, WorkingTranscript: &schema.Transcript{Segments: []schema.Segment{{ID: 1, Text: "cat"}}}, Validators: []contracts.Validator{validator}, SectionEnriched: []proposals.EnrichedCorrectionProposal{candidate}, ValidationLLMClient: client, Interactions: sink, SectionIndex: §ion, RepairProposalIndex: &index, RepairAttempt: &attempt}
|
||||
result, err := validateSectionCandidates(context.Background(), input)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -116,10 +121,29 @@ func TestRevalidationArtifactsUseProposalAndAttemptCoordinates(t *testing.T) {
|
||||
if paths[0] == paths[1] {
|
||||
t.Fatalf("colliding paths: %v", paths)
|
||||
}
|
||||
for _, path := range paths {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
for i, path := range paths {
|
||||
base, ok := strings.CutSuffix(filepath.Base(path), "-response-payload.json")
|
||||
if !ok {
|
||||
t.Fatalf("response path: %s", path)
|
||||
}
|
||||
raw, err := os.ReadFile(filepath.Join(filepath.Dir(path), base+"-request-metadata.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var metadata struct {
|
||||
Context structuredoutput.DiagnosticContext `json:"context"`
|
||||
ProposalIndices []int `json:"proposal_indices"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &metadata); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := metadata.Context
|
||||
if c.Role != "validation" || c.ValidatorName != "editorial_review" ||
|
||||
c.BatchIndex == nil || *c.BatchIndex != 0 || c.SectionIndex == nil || *c.SectionIndex != section ||
|
||||
c.ProposalIndex == nil || *c.ProposalIndex != i+2 || c.RepairAttempt == nil || *c.RepairAttempt != attempt ||
|
||||
len(metadata.ProposalIndices) != 1 || metadata.ProposalIndices[0] != i+2 {
|
||||
t.Fatalf("revalidation metadata: %s", raw)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user