Share transcript envelope validation

This commit is contained in:
2026-12-02 21:34:28 +00:00
parent a623ecb518
commit 3d09745a79
10 changed files with 79 additions and 56 deletions

View File

@@ -3,6 +3,7 @@ package seriatim
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
@@ -10,6 +11,7 @@ import (
"unicode/utf8"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
"gitea.maximumdirect.net/eric/narratio/internal/contracts"
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
)
@@ -659,19 +661,12 @@ func validateJSONFileWithSegments(path string) error {
return err
}
var payload map[string]any
if err := json.Unmarshal(data, &payload); err != nil {
return fmt.Errorf("parse json: %w", err)
err = contracts.ValidateTranscriptEnvelope(data)
var decode *contracts.TranscriptDecodeError
if errors.As(err, &decode) {
return fmt.Errorf("parse json: %w", decode.Err)
}
segments, ok := payload["segments"]
if !ok {
return fmt.Errorf("top-level segments is required")
}
if _, ok := segments.([]any); !ok {
return fmt.Errorf("top-level segments must be an array")
}
return nil
return err
}
func validateNonEmptyTextFile(path string) error {