Verify shared glossary workflows and recovery

This commit is contained in:
2026-11-27 17:14:44 +00:00
parent 0de73ba25f
commit 4f27331636
8 changed files with 103 additions and 12 deletions

View File

@@ -202,7 +202,7 @@ func TestAuditaBinaryCompatibility(t *testing.T) {
}
dir := t.TempDir()
configPath := filepath.Join(dir, "config.yml")
mustWriteTestFile(t, configPath, "version: 3\nllm: {proposal_profile: proposal, validation_profile: review, correction_repair_attempts: 0}\npipeline: {stages: [{module: grammar}]}\nreporting: {enabled: false}\n")
mustWriteTestFile(t, configPath, "version: 3\nllm: {proposal_profile: proposal, validation_profile: review, correction_repair_attempts: 0}\npipeline: {stages: [{module: grammar}]}\nglossary_collections:\n spells: {instruction: Audita default., entries: [{id: stale, name: Stale, category: spell}]}\nreporting: {enabled: false}\n")
mustWriteTestFile(t, filepath.Join(dir, "prompts.yml"), fmt.Sprintf("backends:\n - {id: local, endpoint: %q}\nprofiles:\n - {id: proposal, backend: local, model: proposal-model}\n - {id: review, backend: local, model: review-model}\n", server.URL+"/v1"))
req, _, err := stage.BuildPolishRequest(paths, m, "", filepath.Join(dir, "out.json"), filepath.Join(dir, "reports"), filepath.Join(dir, "debug"))
if err != nil {
@@ -250,4 +250,29 @@ func TestAuditaBinaryCompatibility(t *testing.T) {
if err == nil || result.ExitCode != 1 || calls.Load() != 2 {
t.Fatalf("negative preflight: %+v %v calls=%d", result, err, calls.Load())
}
empty, err := glossary.Resolve(glossary.Sources{}, nil)
if err != nil {
t.Fatal(err)
}
emptyPath := filepath.Join(dir, "empty-spells.yml")
if err := os.WriteFile(emptyPath, empty["spells"], 0600); err != nil {
t.Fatal(err)
}
emptyArgs := append([]string(nil), args...)
for i := range emptyArgs {
if emptyArgs[i] == req.GlossaryFiles[3] {
emptyArgs[i] = emptyPath
}
}
output, err = exec.Command(binary, emptyArgs...).CombinedOutput()
if err != nil {
t.Fatalf("empty inspection: %v: %s", err, output)
}
if err := json.Unmarshal(output, &inspected); err != nil {
t.Fatal(err)
}
spells := inspected.Collections["spells"]
if len(spells.Entries) != 0 || spells.Instruction == nil || *spells.Instruction != "Audita default." {
t.Fatalf("empty prepared spells did not replace configured entries and retain instruction: %+v", spells)
}
}

View File

@@ -2,12 +2,14 @@ package app
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
@@ -49,6 +51,54 @@ func TestPreparedSessionPublishAndRemoteLoad(t *testing.T) {
if _, err := prepare.Run(ctx, env, m); err != nil {
t.Fatal(err)
}
preparedPaths := store.SessionPathsFor(m.Campaign, m.SessionID)
for _, descriptor := range artifactpolicy.GlossaryInputSources() {
if _, err := artifacts.ResolvePreparedInput(preparedPaths, m, descriptor.SourceID); err != nil {
t.Fatalf("downstream input %s: %v", descriptor.SourceID, err)
}
}
marker := filepath.Join(t.TempDir(), "fail-preflight")
mustWriteTestFile(t, marker, "fail")
wrapper := filepath.Join(t.TempDir(), "audita-wrapper.sh")
mustWriteTestFile(t, wrapper, fmt.Sprintf("#!/bin/sh\nif [ \"$1\" = preflight ] && [ -f %q ]; then exit 1; fi\nexec %q \"$@\"\n", marker, writeAuditaAppTestWrapper(t)))
if err := os.Chmod(wrapper, 0755); err != nil {
t.Fatal(err)
}
runner, err := audita.NewSubprocessRunner(audita.SubprocessRunnerConfig{Binary: wrapper, Timeout: time.Minute})
if err != nil {
t.Fatal(err)
}
req, _, err := stage.BuildPolishRequest(preparedPaths, m, "", filepath.Join(runRoot, "polish", "outputs", "transcripts", "polished.json"), filepath.Join(runRoot, "polish", "logs"), filepath.Join(runRoot, "polish", "debug"))
if err != nil {
t.Fatal(err)
}
if result, err := runner.Preflight(ctx, req); err == nil || result.ExitCode != 1 {
t.Fatalf("expected preflight failure: %+v %v", result, err)
}
if _, ok := m.Stages["polish"]; ok {
t.Fatal("failed preflight recorded polish completion")
}
if err := os.Remove(marker); err != nil {
t.Fatal(err)
}
if result, err := runner.Preflight(ctx, req); err != nil || result.ExitCode != 0 {
t.Fatalf("preflight retry: %+v %v", result, err)
}
base := filepath.Join(preparedPaths.TranscriptsDir, "base.json")
mustWriteTestFile(t, base, `{"segments":[]}`)
setCurrentBuiltInEvidence(t, m, "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, base)
env.Audita = runner
polish, err := stage.Select("polish")
if err != nil {
t.Fatal(err)
}
polished, err := polish.Run(ctx, env, m)
if err != nil {
t.Fatal(err)
}
if len(polished.Outputs) != 1 || polished.Metadata["glossary_evidence"] == nil {
t.Fatalf("polish result: %+v", polished)
}
for _, name := range []string{"prepare", "transcribe", "merge", "polish", "normalize", "trim", "render", "analyze"} {
m.MarkStageSucceeded(name, time.Now().UTC(), nil)
}