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

@@ -167,7 +167,8 @@ separate from a stage's lifecycle outcome.
Validation by content type:
- transcript JSON built-ins: JSON with top-level `segments` array;
- transcript JSON built-ins: JSON with top-level `segments` array, validated
through the shared `internal/contracts` envelope predicate;
- transcript Markdown built-ins: non-empty text file;
- bounds built-in: valid JSON;
- configured/previous-session artifact files: non-empty text file.

View File

@@ -41,10 +41,10 @@ their scope. Unless assigned otherwise, a finding remains independent audit
remediation. Shared code does not make a refactoring a prerequisite or assign
the whole finding to a roadmap.
Thirty-two entries are closed by the safety, transfer, audio discovery, S3
Thirty-three entries are closed by the safety, transfer, audio discovery, S3
planning, prerequisite-history, publication-import, CLI classification,
inspection aggregation, test maintenance, dead-code removal, and associated
documentation work; 11 remain open. **Planned** identifies
documentation work; 10 remain open. **Planned** identifies
an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
that a related feature implements the entire finding. Findings close only after their
@@ -663,7 +663,10 @@ Related: [CAT-06](#cat-06--p2-stop-known-size-downloads-before-oversized-bodies-
### CAT-22 — P3: Share the minimal transcript-envelope predicate
Status: Open
Status: Closed
**Closure.** Adapters, stage validation and artifact resolution share the minimal
transcript envelope predicate; literal shape and boundary tests pass.
Original findings: [EQ-01](10-equivalence.md#eq-01--p3-four-boundaries-repeat-the-same-minimal-transcript-shape-validator).

View File

@@ -425,7 +425,7 @@ Validation: `go test ./internal/fileops ./internal/audio ./internal/stage ./inte
## Stage 14: Share The Minimal Transcript Envelope Validator
CAT IDs: CAT-22. Status: Pending.
CAT IDs: CAT-22. Status: Complete.
Read [EQ-01](audit/10-equivalence.md#eq-01--p3-four-boundaries-repeat-the-same-minimal-transcript-shape-validator).

View File

@@ -2,7 +2,6 @@ package audita
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
@@ -11,6 +10,7 @@ import (
"time"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
"gitea.maximumdirect.net/eric/narratio/internal/contracts"
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
configkit "go.maximumdirect.net/configkit"
)
@@ -203,16 +203,10 @@ func validateProcessedOutput(path string) error {
if err != nil {
return fmt.Errorf("audita processed transcript result exceeds or cannot be read within %d-byte limit: %w", MaxProcessedOutputBytes, 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
}

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 {

View File

@@ -11,6 +11,7 @@ import (
"gitea.maximumdirect.net/eric/narratio/internal/artifactmodel"
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
"gitea.maximumdirect.net/eric/narratio/internal/contracts"
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
@@ -404,18 +405,7 @@ func validateTranscriptSegmentsJSON(path string) error {
if err != nil {
return err
}
var payload map[string]any
if err := json.Unmarshal(data, &payload); err != nil {
return fmt.Errorf("decode json: %w", 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 contracts.ValidateTranscriptEnvelope(data)
}
func validateJSONContent(path string) error {

View File

@@ -0,0 +1,28 @@
package contracts
import (
"encoding/json"
"fmt"
)
// TranscriptDecodeError identifies invalid JSON or a non-object root.
type TranscriptDecodeError struct{ Err error }
func (e *TranscriptDecodeError) Error() string { return "decode json: " + e.Err.Error() }
func (e *TranscriptDecodeError) Unwrap() error { return e.Err }
// ValidateTranscriptEnvelope checks the shared minimal transcript JSON shape.
func ValidateTranscriptEnvelope(data []byte) error {
var payload map[string]any
if err := json.Unmarshal(data, &payload); err != nil {
return &TranscriptDecodeError{Err: 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
}

View File

@@ -0,0 +1,23 @@
package contracts
import "testing"
func TestValidateTranscriptEnvelope(t *testing.T) {
for _, tc := range []struct {
name, input string
valid bool
}{
{"empty segments", `{"segments":[]}`, true},
{"other members", `{"extra":true,"segments":[null,{"anything":1}]}`, true},
{"malformed", `{`, false}, {"missing", `{}`, false}, {"null segments", `{"segments":null}`, false},
{"object segments", `{"segments":{}}`, false}, {"string segments", `{"segments":"x"}`, false},
{"null root", `null`, false}, {"array root", `[]`, false}, {"string root", `"text"`, false},
} {
t.Run(tc.name, func(t *testing.T) {
err := ValidateTranscriptEnvelope([]byte(tc.input))
if (err == nil) != tc.valid {
t.Fatalf("error = %v, valid = %t", err, tc.valid)
}
})
}
}

View File

@@ -2,13 +2,13 @@ package stage
import (
"context"
"encoding/json"
"fmt"
"path/filepath"
"strings"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/contracts"
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
)
@@ -177,16 +177,5 @@ func validateProcessedTranscriptOutput(path string) error {
return err
}
var payload map[string]any
if err := json.Unmarshal(data, &payload); err != nil {
return fmt.Errorf("decode json: %w", 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 contracts.ValidateTranscriptEnvelope(data)
}

View File

@@ -2,12 +2,12 @@ package stage
import (
"fmt"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/audio"
"path/filepath"
"sort"
"strings"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/audio"
"gitea.maximumdirect.net/eric/narratio/internal/config"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
)