Wire schema validation into process command
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/internal/core/config"
|
||||
coreio "gitea.maximumdirect.net/eric/audita/internal/core/io"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/core/io"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/core/reporting"
|
||||
"gitea.maximumdirect.net/eric/audita/internal/core/schema"
|
||||
)
|
||||
|
||||
type processInvocation struct {
|
||||
@@ -22,25 +23,61 @@ type processInvocation struct {
|
||||
}
|
||||
|
||||
var processRunner = func(inv processInvocation, stdout io.Writer) error {
|
||||
transcriptBytes, err := coreio.ReadRequiredFile(inv.TranscriptPath, "transcript")
|
||||
transcriptBytes, err := io.ReadRequiredFile(inv.TranscriptPath, "transcript")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := coreio.ValidateWellFormedJSON(inv.TranscriptPath, transcriptBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := coreio.ReadRequiredFile(inv.GlossaryPath, "glossary"); err != nil {
|
||||
|
||||
glossaryBytes, err := io.ReadRequiredFile(inv.GlossaryPath, "glossary")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Parse and validate transcript using typed schema
|
||||
transcript, err := schema.ParseSourceTranscriptJSON(transcriptBytes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid transcript: %w", err)
|
||||
}
|
||||
|
||||
// Parse and validate glossary using typed schema
|
||||
glossary, err := schema.ParseGlossaryYAML(glossaryBytes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid glossary: %w", err)
|
||||
}
|
||||
|
||||
// Convert to canonical transcript format for output
|
||||
outputTranscript := &schema.Transcript{
|
||||
Segments: make([]schema.Segment, len(transcript.Segments)),
|
||||
}
|
||||
for i, s := range transcript.Segments {
|
||||
id := i + 1
|
||||
if s.ID != nil {
|
||||
id = *s.ID
|
||||
}
|
||||
outputTranscript.Segments[i] = schema.Segment{
|
||||
ID: id,
|
||||
Speaker: s.Speaker,
|
||||
Start: s.Start,
|
||||
End: s.End,
|
||||
Text: s.Text,
|
||||
Categories: s.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize output transcript to JSON
|
||||
outputBytes, err := schema.TranscriptToJSON(outputTranscript)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to serialize transcript: %w", err)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(inv.OutputPath) != "" {
|
||||
if err := coreio.WriteFile(inv.OutputPath, transcriptBytes); err != nil {
|
||||
if err := io.WriteFile(inv.OutputPath, outputBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := stdout.Write(transcriptBytes); err != nil {
|
||||
if _, err := stdout.Write(outputBytes); err != nil {
|
||||
return fmt.Errorf("failed to write transcript to stdout: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user