Complete Phase 2 Go normalization foundation

This commit is contained in:
2026-05-11 00:41:29 +00:00
parent d847168ecd
commit 10377876e4
11 changed files with 480 additions and 1241 deletions

View File

@@ -54,8 +54,8 @@ func TestParseGlossaryYAML_MalformedYAML(t *testing.T) {
t.Fatal("expected error for malformed YAML, got nil")
}
var parseErr *ParseError
if parseErr, ok := err.(*ParseError); !ok {
parseErr, ok := err.(*ParseError)
if !ok {
t.Errorf("expected *ParseError, got %T", err)
} else if parseErr.Message == "" {
t.Error("expected non-empty parse error message")
@@ -73,8 +73,8 @@ func TestParseGlossaryYAML_MissingRequiredFields(t *testing.T) {
t.Fatal("expected error for missing required fields, got nil")
}
var valErr *ValidationError
if valErr, ok := err.(*ValidationError); !ok {
valErr, ok := err.(*ValidationError)
if !ok {
t.Errorf("expected *ValidationError, got %T", err)
} else if valErr.Field == "" {
t.Error("expected non-empty validation error field")
@@ -89,8 +89,8 @@ func TestParseGlossaryYAML_EmptyGlossary(t *testing.T) {
t.Fatal("expected error for empty glossary, got nil")
}
var valErr *ValidationError
if valErr, ok := err.(*ValidationError); !ok {
valErr, ok := err.(*ValidationError)
if !ok {
t.Errorf("expected *ValidationError, got %T", err)
} else if valErr.Message != "must contain at least one entry" {
t.Errorf("expected 'must contain at least one entry', got %q", valErr.Message)
@@ -110,8 +110,8 @@ glossary:
t.Fatal("expected error for empty name, got nil")
}
var valErr *ValidationError
if valErr, ok := err.(*ValidationError); !ok {
valErr, ok := err.(*ValidationError)
if !ok {
t.Errorf("expected *ValidationError, got %T", err)
} else if valErr.Message != "must not be empty" {
t.Errorf("expected 'must not be empty', got %q", valErr.Message)
@@ -133,8 +133,8 @@ glossary:
t.Fatal("expected error for empty alias, got nil")
}
var valErr *ValidationError
if valErr, ok := err.(*ValidationError); !ok {
valErr, ok := err.(*ValidationError)
if !ok {
t.Errorf("expected *ValidationError, got %T", err)
} else if valErr.Message != "must not be empty" {
t.Errorf("expected 'must not be empty', got %q", valErr.Message)

View File

@@ -47,14 +47,13 @@ func ParseSourceTranscriptJSON(raw []byte) (*SourceTranscript, error) {
return nil, err
}
if len(segmentsRaw) == 0 {
return nil, &ParseError{Message: "transcript must contain at least one segment"}
}
var segments []SourceSegment
if err := json.Unmarshal(segmentsRaw, &segments); err != nil {
return nil, &ParseError{Message: fmt.Sprintf("failed to parse segments: %v", err)}
}
if len(segments) == 0 {
return nil, &ParseError{Message: "transcript must contain at least one segment"}
}
if err := validateSourceSegments(segments); err != nil {
return nil, err

View File

@@ -80,8 +80,8 @@ func TestParseSourceTranscriptJSON_MalformedJSON(t *testing.T) {
t.Fatal("expected error for malformed JSON, got nil")
}
var parseErr *ParseError
if parseErr, ok := err.(*ParseError); !ok {
parseErr, ok := err.(*ParseError)
if !ok {
t.Errorf("expected *ParseError, got %T", err)
} else if parseErr.Message != "transcript is not valid JSON" {
t.Errorf("expected 'transcript is not valid JSON', got %q", parseErr.Message)
@@ -155,8 +155,8 @@ func TestParseSourceTranscriptJSON_EmptyArray(t *testing.T) {
t.Fatal("expected error for empty array, got nil")
}
var parseErr *ParseError
if parseErr, ok := err.(*ParseError); !ok {
parseErr, ok := err.(*ParseError)
if !ok {
t.Errorf("expected *ParseError, got %T", err)
} else if parseErr.Message != "transcript must contain at least one segment" {
t.Errorf("expected 'transcript must contain at least one segment', got %q", parseErr.Message)
@@ -208,8 +208,8 @@ func TestParseSourceTranscriptJSON_UnsupportedTopLevelShape(t *testing.T) {
t.Fatal("expected error for unsupported top-level shape, got nil")
}
var parseErr *ParseError
if parseErr, ok := err.(*ParseError); !ok {
parseErr, ok := err.(*ParseError)
if !ok {
t.Errorf("expected *ParseError, got %T", err)
} else if parseErr.Message != "transcript must be a JSON array or an object with a segments array" {
t.Errorf("expected unsupported shape message, got %q", parseErr.Message)
@@ -224,8 +224,8 @@ func TestParseSourceTranscriptJSON_ObjectWithoutSegments(t *testing.T) {
t.Fatal("expected error for object without segments, got nil")
}
var parseErr *ParseError
if parseErr, ok := err.(*ParseError); !ok {
parseErr, ok := err.(*ParseError)
if !ok {
t.Errorf("expected *ParseError, got %T", err)
} else if parseErr.Message != "transcript object must contain a segments array" {
t.Errorf("expected 'transcript object must contain a segments array', got %q", parseErr.Message)
@@ -265,8 +265,8 @@ func TestTranscriptToJSON(t *testing.T) {
func assertValidationError(t *testing.T, err error, fieldContains, messageContains string) {
t.Helper()
var valErr *ValidationError
if valErr, ok := err.(*ValidationError); !ok {
valErr, ok := err.(*ValidationError)
if !ok {
t.Errorf("expected *ValidationError, got %T", err)
return
}
@@ -282,8 +282,8 @@ func assertValidationError(t *testing.T, err error, fieldContains, messageContai
func assertValidationErrorContains(t *testing.T, err error, fieldContains, messageContains string) {
t.Helper()
var valErr *ValidationError
if valErr, ok := err.(*ValidationError); !ok {
valErr, ok := err.(*ValidationError)
if !ok {
t.Errorf("expected *ValidationError, got %T", err)
return
}