Document and verify runtime glossary workflows
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user