Document and verify runtime glossary workflows

This commit is contained in:
2026-11-26 18:25:43 +00:00
parent e0445abe48
commit 889ac766a5
13 changed files with 196 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
@@ -18,6 +19,7 @@ import (
"gitea.maximumdirect.net/eric/audita/v4/internal/core/schema"
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/llm"
auditaprompts "gitea.maximumdirect.net/eric/audita/v4/internal/prompts"
commandkit "go.maximumdirect.net/commandkit"
ck "go.maximumdirect.net/configkit"
pk "go.maximumdirect.net/promptkit"
)
@@ -185,3 +187,74 @@ func TestExamplePromptEditIsCapturedOnNextLoad(t *testing.T) {
t.Fatalf("before=%q after=%q", before, after)
}
}
func TestRuntimeGlossaryExampleWorkflow(t *testing.T) {
_, file, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("cannot locate examples")
}
source := filepath.Join(filepath.Dir(file), "..", "..", "examples", "service")
dir := t.TempDir()
for _, name := range []string{"config.yml", "prompts.yml", "transcript.json", "runtime-glossary.yml", "overlays/runtime-glossary.yml"} {
data, err := os.ReadFile(filepath.Join(source, name))
if err != nil {
t.Fatal(err)
}
dest := filepath.Join(dir, name)
if err := os.MkdirAll(filepath.Dir(dest), 0700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(dest, data, 0600); err != nil {
t.Fatal(err)
}
}
t.Setenv("AUDITA_EXAMPLE_KEY", "synthetic")
var seen string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var request struct {
Messages []struct {
Content string `json:"content"`
} `json:"messages"`
}
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
t.Error(err)
return
}
for _, message := range request.Messages {
seen += message.Content
}
io.WriteString(w, `{"model":"fixture","choices":[{"message":{"role":"assistant","content":"{\"corrections\":[]}"}}]}`)
}))
defer server.Close()
promptsPath := filepath.Join(dir, "prompts.yml")
promptsData, err := os.ReadFile(promptsPath)
if err != nil {
t.Fatal(err)
}
promptsData = bytes.ReplaceAll(promptsData, []byte("https://example.invalid/v1"), []byte(server.URL+"/v1"))
if err := os.WriteFile(promptsPath, promptsData, 0600); err != nil {
t.Fatal(err)
}
app, err := buildApplication()
if err != nil {
t.Fatal(err)
}
common := []string{"--config", filepath.Join(dir, "config.yml"), "--overlay", "runtime-glossary", "--glossary-file", filepath.Join(dir, "runtime-glossary.yml")}
var out, stderr bytes.Buffer
args := append([]string{"config", "show", "--scope=app"}, common...)
result := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &stderr})
if result.Status != 0 || !strings.Contains(out.String(), "Mira Chen") || !strings.Contains(out.String(), "North Observatory") || strings.Contains(out.String(), "Placeholder Speaker") {
t.Fatalf("inspection %d %s %s", result.Status, out.String(), stderr.String())
}
out.Reset()
stderr.Reset()
args = append([]string{"process"}, common...)
args = append(args, "--output", filepath.Join(dir, "output.json"), filepath.Join(dir, "transcript.json"))
result = app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &stderr})
if result.Status != 0 || !strings.Contains(seen, "Mira Chen") || !strings.Contains(seen, "North Observatory") || !strings.Contains(seen, "speaker's preferred spelling") || !strings.Contains(seen, "Preserve established place names") {
t.Fatalf("processing %d seen=%s stderr=%s", result.Status, seen, stderr.String())
}
if _, err := os.Stat(filepath.Join(dir, "output.json")); err != nil {
t.Fatal(err)
}
}

View File

@@ -16,6 +16,7 @@ import (
"gitea.maximumdirect.net/eric/audita/v4/internal/appconfig"
"gitea.maximumdirect.net/eric/audita/v4/internal/core/config"
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/contracts"
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/structuredoutput"
"gitea.maximumdirect.net/eric/audita/v4/internal/prompts"
ck "go.maximumdirect.net/configkit"
@@ -69,7 +70,14 @@ func TestRoleClientCoordinatesIndependentRepairConversations(t *testing.T) {
if err != nil {
t.Fatal(err)
}
vars := map[string]string{"TranscriptDescriptionBlock": "", "GlossaryJSON": "[]", "SectionJSON": "[]", "GlossaryInstructionsBlock": "party:\nKeep {{literal}} names"}
selected := contracts.ResolveModuleRunSpecs(&config.Config{
GlossaryCollections: map[string]config.GlossaryCollection{"party": {Instruction: "Keep {{literal}} names"}},
Pipeline: config.Pipeline{Stages: []config.Stage{{Module: "grammar", Glossaries: []string{"party"}}}},
})
if err := selected[0].PrepareGlossary(); err != nil {
t.Fatal(err)
}
vars := map[string]string{"TranscriptDescriptionBlock": "", "GlossaryJSON": "[]", "SectionJSON": "[]", "GlossaryInstructionsBlock": selected[0].GlossaryVariables.InstructionsBlock}
initial, err := proposal.CompleteStructured(context.Background(), structuredoutput.Request{PromptID: prompts.PromptIDModuleGrammarProposal, Variables: vars, CaptureExchange: true}, &map[string]any{})
if err != nil || initial.Exchange == nil {
t.Fatalf("capture: %+v %v", initial, err)