Share transcript envelope validation
This commit is contained in:
@@ -167,7 +167,8 @@ separate from a stage's lifecycle outcome.
|
|||||||
|
|
||||||
Validation by content type:
|
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;
|
- transcript Markdown built-ins: non-empty text file;
|
||||||
- bounds built-in: valid JSON;
|
- bounds built-in: valid JSON;
|
||||||
- configured/previous-session artifact files: non-empty text file.
|
- configured/previous-session artifact files: non-empty text 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
|
remediation. Shared code does not make a refactoring a prerequisite or assign
|
||||||
the whole finding to a roadmap.
|
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,
|
planning, prerequisite-history, publication-import, CLI classification,
|
||||||
inspection aggregation, test maintenance, dead-code removal, and associated
|
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
|
an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending
|
||||||
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
|
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
|
||||||
that a related feature implements the entire finding. Findings close only after their
|
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
|
### 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).
|
Original findings: [EQ-01](10-equivalence.md#eq-01--p3-four-boundaries-repeat-the-same-minimal-transcript-shape-validator).
|
||||||
|
|
||||||
|
|||||||
@@ -425,7 +425,7 @@ Validation: `go test ./internal/fileops ./internal/audio ./internal/stage ./inte
|
|||||||
|
|
||||||
## Stage 14: Share The Minimal Transcript Envelope Validator
|
## 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).
|
Read [EQ-01](audit/10-equivalence.md#eq-01--p3-four-boundaries-repeat-the-same-minimal-transcript-shape-validator).
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package audita
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -11,6 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/contracts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
||||||
configkit "go.maximumdirect.net/configkit"
|
configkit "go.maximumdirect.net/configkit"
|
||||||
)
|
)
|
||||||
@@ -203,16 +203,10 @@ func validateProcessedOutput(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("audita processed transcript result exceeds or cannot be read within %d-byte limit: %w", MaxProcessedOutputBytes, err)
|
return fmt.Errorf("audita processed transcript result exceeds or cannot be read within %d-byte limit: %w", MaxProcessedOutputBytes, err)
|
||||||
}
|
}
|
||||||
var payload map[string]any
|
err = contracts.ValidateTranscriptEnvelope(data)
|
||||||
if err := json.Unmarshal(data, &payload); err != nil {
|
var decode *contracts.TranscriptDecodeError
|
||||||
return fmt.Errorf("parse json: %w", err)
|
if errors.As(err, &decode) {
|
||||||
|
return fmt.Errorf("parse json: %w", decode.Err)
|
||||||
}
|
}
|
||||||
segments, ok := payload["segments"]
|
return err
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package seriatim
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/contracts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -659,19 +661,12 @@ func validateJSONFileWithSegments(path string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var payload map[string]any
|
err = contracts.ValidateTranscriptEnvelope(data)
|
||||||
if err := json.Unmarshal(data, &payload); err != nil {
|
var decode *contracts.TranscriptDecodeError
|
||||||
return fmt.Errorf("parse json: %w", err)
|
if errors.As(err, &decode) {
|
||||||
|
return fmt.Errorf("parse json: %w", decode.Err)
|
||||||
}
|
}
|
||||||
|
return 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateNonEmptyTextFile(path string) error {
|
func validateNonEmptyTextFile(path string) error {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactmodel"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifactmodel"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
"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/fileops"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
||||||
@@ -404,18 +405,7 @@ func validateTranscriptSegmentsJSON(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var payload map[string]any
|
return contracts.ValidateTranscriptEnvelope(data)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateJSONContent(path string) error {
|
func validateJSONContent(path string) error {
|
||||||
|
|||||||
28
internal/contracts/transcript.go
Normal file
28
internal/contracts/transcript.go
Normal 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
|
||||||
|
}
|
||||||
23
internal/contracts/transcript_test.go
Normal file
23
internal/contracts/transcript_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,13 +2,13 @@ package stage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/audita"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"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/fileops"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
)
|
)
|
||||||
@@ -177,16 +177,5 @@ func validateProcessedTranscriptOutput(path string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var payload map[string]any
|
return contracts.ValidateTranscriptEnvelope(data)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package stage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/audio"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"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/config"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user