Files
audita/internal/framework/llm/diagnostics_test.go

43 lines
1.0 KiB
Go

package llm
import (
"encoding/json"
"os"
"path/filepath"
"testing"
)
func TestDiagnosticsWriterProducesValidJSONArtifacts(t *testing.T) {
dir := t.TempDir()
writer := NewDiagnosticsWriter(dir)
artifacts, err := writer.WriteInteraction(
"validation:batch-1",
map[string]any{"stage": "validation", "attempt": 1},
map[string]any{"messages": []map[string]any{{"role": "user", "content": "hello"}}},
map[string]any{"result": "ok"},
nil,
)
if err != nil {
t.Fatalf("WriteInteraction: %v", err)
}
if artifacts.ErrorPayloadPath != "" {
t.Fatalf("expected no error payload path, got %q", artifacts.ErrorPayloadPath)
}
assertValidJSONFile(t, artifacts.RequestMetadataPath)
assertValidJSONFile(t, artifacts.RequestPayloadPath)
assertValidJSONFile(t, artifacts.ResponsePayloadPath)
}
func assertValidJSONFile(t *testing.T, path string) {
t.Helper()
raw, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read %s: %v", path, err)
}
if !json.Valid(raw) {
t.Fatalf("invalid json in %s", filepath.Base(path))
}
}